changeset 2840:ca8641b9b0f4

SW pipeline: checking input parametrs in Pisces surfaces
author Martin Soch <Martin.Soch@oracle.com>
date Tue, 12 Mar 2013 17:12:43 +0100
parents d45b7c33204d
children 9f21025a5563 fe5a6223ed42 0b173965941a
files prism-sw-native/src/JJavaSurface.c prism-sw-native/src/JNativeSurface.c prism-sw/src/com/sun/pisces/AbstractSurface.java prism-sw/src/com/sun/pisces/JavaSurface.java prism-sw/src/com/sun/pisces/NativeSurface.java
diffstat 5 files changed, 24 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/prism-sw-native/src/JJavaSurface.c	Tue Mar 12 12:15:28 2013 +0100
+++ b/prism-sw-native/src/JJavaSurface.c	Tue Mar 12 17:12:43 2013 +0100
@@ -32,9 +32,7 @@
 
 #define SURFACE_NATIVE_PTR 0
 #define SURFACE_DATA_INT 1
-#define SURFACE_DATA_SHORT 2
-#define SURFACE_DATA_BYTE 3 
-#define SURFACE_LAST SURFACE_DATA_BYTE
+#define SURFACE_LAST SURFACE_DATA_INT
 
 static jfieldID fieldIds[SURFACE_LAST + 1];
 static jboolean fieldIdsInitialized = JNI_FALSE;
@@ -48,7 +46,6 @@
 typedef struct _JavaSurface {
     AbstractSurface super;
     jfieldID javaArrayFieldID;
-    jint javaArrayFieldSize;
     jobject dataHandle;
 } JavaSurface;
 
@@ -83,7 +80,6 @@
                 case TYPE_INT_ARGB:
                 case TYPE_INT_ARGB_PRE:
                     jSurface->javaArrayFieldID = fieldIds[SURFACE_DATA_INT];
-                    jSurface->javaArrayFieldSize = sizeof(jint);            
                     break;
                 default: //errorneous - should never happen
                     jSurface->javaArrayFieldID = NULL;
--- a/prism-sw-native/src/JNativeSurface.c	Tue Mar 12 12:15:28 2013 +0100
+++ b/prism-sw-native/src/JNativeSurface.c	Tue Mar 12 17:12:43 2013 +0100
@@ -52,21 +52,19 @@
             && initializeSurfaceFieldIds(env, objectHandle)) {
         surface = my_malloc(AbstractSurface, 1);
         if (surface != NULL) {
-            jint size;
+            size_t size;
             void* data;
             switch (dataType) {
             case TYPE_INT_ARGB:
             case TYPE_INT_ARGB_PRE:
-                size = width * height * sizeof(jint);
+                size = width * height;
                 break;
             default: //errorneous - should never happen
                 size = 0;
                 break;
             }
-            data = PISCESmalloc(size);
+            data = my_malloc(jint, size);
             if (data != NULL) {
-                memset(data, 0, size);
-
                 surface->super.width = width;
                 surface->super.height = height;
                 surface->super.offset = 0;
--- a/prism-sw/src/com/sun/pisces/AbstractSurface.java	Tue Mar 12 12:15:28 2013 +0100
+++ b/prism-sw/src/com/sun/pisces/AbstractSurface.java	Tue Mar 12 17:12:43 2013 +0100
@@ -27,11 +27,24 @@
 
 public abstract class AbstractSurface implements Surface {
     
-    long nativePtr = 0L;
-    int width;
-    int height;
+    private long nativePtr = 0L;
+    private int width;
+    private int height;
 
-    protected AbstractSurface() { }
+    AbstractSurface(int width, int height) {
+        if (width < 0) {
+            throw new IllegalArgumentException("WIDTH must be positive");
+        }
+        if (height < 0) {
+            throw new IllegalArgumentException("HEIGHT must be positive");
+        }
+        final int nbits = 32-Integer.numberOfLeadingZeros(width) + 32-Integer.numberOfLeadingZeros(height);
+        if (nbits > 31) {
+            throw new IllegalArgumentException("WIDTH * HEIGHT is too large");
+        }
+        this.width = width;
+        this.height = height;
+    }
         
     public native void getRGB(int[] argb, int offset, int scanLength,
             int x, int y, int width, int height);
@@ -51,5 +64,5 @@
         return height;
     }
 
-    public native void nativeFinalize();
+    private native void nativeFinalize();
 }
--- a/prism-sw/src/com/sun/pisces/JavaSurface.java	Tue Mar 12 12:15:28 2013 +0100
+++ b/prism-sw/src/com/sun/pisces/JavaSurface.java	Tue Mar 12 17:12:43 2013 +0100
@@ -34,10 +34,8 @@
     private int[] dataInt;
 
     public JavaSurface(int[] dataInt, int dataType, int width, int height) {
+        super(width, height);
         this.dataInt = dataInt;
-        this.width = width;
-        this.height = height;
-
         this.dataBuffer = IntBuffer.wrap(this.dataInt);
 
         initialize(dataType, width, height);
--- a/prism-sw/src/com/sun/pisces/NativeSurface.java	Tue Mar 12 12:15:28 2013 +0100
+++ b/prism-sw/src/com/sun/pisces/NativeSurface.java	Tue Mar 12 17:12:43 2013 +0100
@@ -28,6 +28,7 @@
 public final class NativeSurface extends AbstractSurface {
 
     public NativeSurface(int dataType, int width, int height) {
+        super(width, height);
         switch (dataType) {
             case RendererBase.TYPE_INT_ARGB:
                 break;
@@ -37,9 +38,6 @@
         }
         
         initialize(dataType, width, height);
-        
-        this.width = width;
-        this.height = height;
     }
 
     private native void initialize(int dataType, int width, int height);