changeset 10790:2591ffdeb4bb

8181660: Help ReadPixelsHelper Reviewed-by: kcr, serb, mschoene, rhalade
author prr
date Mon, 12 Jun 2017 12:42:19 -0700
parents 1c6936f98909
children 0f9bfa68845a
files modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc modules/javafx.graphics/src/main/native-prism-d3d/D3DResourceFactory.cc
diffstat 2 files changed, 37 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc	Mon May 22 16:12:54 2017 -0700
+++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc	Mon Jun 12 12:42:19 2017 -0700
@@ -217,19 +217,27 @@
     D3DMesh *mesh = (D3DMesh *) jlong_to_ptr(nativeMesh);
     RETURN_STATUS_IF_NULL(mesh, JNI_FALSE);
 
-    UINT vertexBufferSize = env->GetArrayLength(vb);
-    float *vertexBuffer = (float *) (env->GetPrimitiveArrayCritical(vb, NULL));
-    UINT indexBufferSize = env->GetArrayLength(ib);
-    USHORT *indexBuffer = (USHORT *) (env->GetPrimitiveArrayCritical(ib, NULL));
-
     if (vbSize < 0 || ibSize < 0) {
         return JNI_FALSE;
     }
 
     UINT uvbSize = (UINT) vbSize;
     UINT uibSize = (UINT) ibSize;
-    if (vertexBuffer == NULL || indexBuffer == NULL
-            || uvbSize > vertexBufferSize || uibSize > indexBufferSize) {
+    UINT vertexBufferSize = env->GetArrayLength(vb);
+    UINT indexBufferSize = env->GetArrayLength(ib);
+
+    if (uvbSize > vertexBufferSize || uibSize > indexBufferSize) {
+        return JNI_FALSE;
+    }
+
+    float *vertexBuffer = (float *) (env->GetPrimitiveArrayCritical(vb, NULL));
+    if (vertexBuffer == NULL) {
+        return JNI_FALSE;
+    }
+
+    USHORT *indexBuffer = (USHORT *) (env->GetPrimitiveArrayCritical(ib, NULL));
+    if (indexBuffer == NULL) {
+        env->ReleasePrimitiveArrayCritical(vb, vertexBuffer, 0);
         return JNI_FALSE;
     }
 
@@ -252,19 +260,26 @@
     D3DMesh *mesh = (D3DMesh *) jlong_to_ptr(nativeMesh);
     RETURN_STATUS_IF_NULL(mesh, JNI_FALSE);
 
-    UINT vertexBufferSize = env->GetArrayLength(vb);
-    float *vertexBuffer = (float *) (env->GetPrimitiveArrayCritical(vb, NULL));
-    UINT indexBufferSize = env->GetArrayLength(ib);
-    UINT *indexBuffer = (UINT *) (env->GetPrimitiveArrayCritical(ib, NULL));
-
     if (vbSize < 0 || ibSize < 0) {
         return JNI_FALSE;
     }
 
     UINT uvbSize = (UINT) vbSize;
     UINT uibSize = (UINT) ibSize;
-    if (vertexBuffer == NULL || indexBuffer == NULL
-            || uvbSize > vertexBufferSize || uibSize > indexBufferSize) {
+    UINT vertexBufferSize = env->GetArrayLength(vb);
+    UINT indexBufferSize = env->GetArrayLength(ib);
+    if (uvbSize > vertexBufferSize || uibSize > indexBufferSize) {
+        return JNI_FALSE;
+    }
+
+    float *vertexBuffer = (float *) (env->GetPrimitiveArrayCritical(vb, NULL));
+    if (vertexBuffer == NULL) {
+        return JNI_FALSE;
+    }
+
+    UINT *indexBuffer = (UINT *) (env->GetPrimitiveArrayCritical(ib, NULL));
+    if (indexBuffer == NULL) {
+        env->ReleasePrimitiveArrayCritical(vb, vertexBuffer, 0);
         return JNI_FALSE;
     }
 
--- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DResourceFactory.cc	Mon May 22 16:12:54 2017 -0700
+++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DResourceFactory.cc	Mon Jun 12 12:42:19 2017 -0700
@@ -472,11 +472,11 @@
     JNIEnv *env, jlong context, jlong resource, jlong length,
     jobject buf, jarray pixelArray, jint cntW, jint cntH)
 {
-    BYTE *pixels = PBYTE( pixelArray ?
-            env->GetPrimitiveArrayCritical(pixelArray, 0) :
-            env->GetDirectBufferAddress(buf));
+    D3DContext *pCtx = (D3DContext*)jlong_to_ptr(context);
+    RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
 
-    RETURN_STATUS_IF_NULL(pixels, E_OUTOFMEMORY);
+    D3DResource *pResource = (D3DResource*)jlong_to_ptr(resource);
+    RETURN_STATUS_IF_NULL(pResource, E_FAIL);
 
     // sanity check about we have enought memory
     // Since we are certain cntW and cntH are positive numbers
@@ -487,11 +487,11 @@
         return E_OUTOFMEMORY;
     }
 
-    D3DContext *pCtx = (D3DContext*)jlong_to_ptr(context);
-    RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
+    BYTE *pixels = PBYTE( pixelArray ?
+            env->GetPrimitiveArrayCritical(pixelArray, 0) :
+            env->GetDirectBufferAddress(buf));
 
-    D3DResource *pResource = (D3DResource*)jlong_to_ptr(resource);
-    RETURN_STATUS_IF_NULL(pResource, E_FAIL);
+    RETURN_STATUS_IF_NULL(pixels, E_OUTOFMEMORY);
 
     HRESULT res = D3DResourceFactory_nReadPixels(pCtx, pResource, pixels, cntW, cntH);