changeset 3806:cb35abdbc183

SW pipeline: fix for SWTexture.update(..) methods (RT-30633)
author Martin Soch <Martin.Soch@oracle.com>
date Tue, 04 Jun 2013 10:55:10 +0200
parents aee1e049522e
children 1dd4bb7090a2 411a75a54143
files prism-sw/src/com/sun/prism/sw/SWArgbPreTexture.java prism-sw/src/com/sun/prism/sw/SWMaskTexture.java prism-sw/src/com/sun/prism/sw/SWTexture.java
diffstat 3 files changed, 77 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/prism-sw/src/com/sun/prism/sw/SWArgbPreTexture.java	Tue Jun 04 10:09:31 2013 +0200
+++ b/prism-sw/src/com/sun/prism/sw/SWArgbPreTexture.java	Tue Jun 04 10:55:10 2013 +0200
@@ -33,7 +33,6 @@
 import com.sun.javafx.image.impl.ByteGray;
 import com.sun.javafx.image.impl.ByteRgb;
 import com.sun.javafx.image.impl.IntArgbPre;
-import com.sun.prism.Image;
 import com.sun.prism.MediaFrame;
 import com.sun.prism.PixelFormat;
 import com.sun.prism.Texture;
@@ -46,15 +45,20 @@
 class SWArgbPreTexture extends SWTexture {
 
     private int data[];
+    private int stride, offset;
     private boolean hasAlpha = true;
 
     SWArgbPreTexture(SWResourceFactory factory, WrapMode wrapMode, int w, int h) {
         super(factory, wrapMode, w, h);
+        stride = w;
+        offset = 0;
     }
 
     SWArgbPreTexture(SWArgbPreTexture sharedTex, WrapMode altMode) {
         super(sharedTex, altMode);
         this.data = sharedTex.data;
+        this.stride = sharedTex.stride;
+        this.offset = sharedTex.offset;
         this.hasAlpha = sharedTex.hasAlpha;
     }
 
@@ -62,6 +66,14 @@
         return data;
     }
 
+    int getStride() {
+        return stride;
+    }
+
+    int getOffset() {
+        return offset;
+    }
+
     boolean hasAlpha() {
         return hasAlpha;
     }
@@ -72,53 +84,47 @@
     }
 
     @Override
-    public void update(Image img, int dstx, int dsty, int srcw, int srch, boolean skipFlush) {
+    public void update(Buffer buffer, PixelFormat format, int dstx, int dsty,
+                       int srcx, int srcy, int srcw, int srch, int srcscan, boolean skipFlush)
+    {
         if (PrismSettings.debug) {
-            System.out.println("Image format: " + img.getPixelFormat());
-            System.out.println("Bytes per pixel: " + img.getBytesPerPixelUnit());
-            System.out.println("dstx:" + dstx + " dsty:" + dsty + " srcw:" + srcw + " srch:" + srch);
+            System.out.println("ARGB_PRE TEXTURE, Pixel format: " + format + ", buffer: " + buffer);
+            System.out.println("dstx:" + dstx + " dsty:" + dsty);
+            System.out.println("srcx:" + srcx + " srcy:" + srcy + " srcw:" + srcw + " srch:" + srch + " srcscan: " + srcscan);
         }
 
-        this.checkAllocation(srcw, srch);
-        this.width = srcw;
-        this.height = srch;
+        this.checkDimensions(dstx+srcw, dsty+srch);
         this.allocate();
 
         final PixelGetter getter;
-        final int elementsPerPixel;
-        switch (img.getPixelFormat()) {
+        switch (format) {
             case BYTE_RGB:
                 getter = ByteRgb.getter;
-                elementsPerPixel = img.getBytesPerPixelUnit();
                 this.hasAlpha = false;
                 break;
             case INT_ARGB_PRE:
                 getter = IntArgbPre.getter;
-                elementsPerPixel = 1;
+                // original srcscan parameter is in bytes, but PixelConverter.convert
+                // requires srcscan to be in elements (INTs in this case)
+                srcscan = srcscan >> 2;
                 this.hasAlpha = true;
                 break;
             case BYTE_BGRA_PRE:
                 getter = ByteBgraPre.getter;
-                elementsPerPixel = img.getBytesPerPixelUnit();
                 this.hasAlpha = true;
                 break;
             case BYTE_GRAY:
                 getter = ByteGray.getter;
-                elementsPerPixel = img.getBytesPerPixelUnit();
                 this.hasAlpha = false;
                 break;
             default:
-                throw new UnsupportedOperationException("!!! UNSUPPORTED PIXEL FORMAT: " + img.getPixelFormat());
+                throw new UnsupportedOperationException("!!! UNSUPPORTED PIXEL FORMAT: " + format);
         }
 
         PixelConverter converter = PixelUtils.getConverter(getter, IntArgbPre.setter);
-        converter.convert(img.getPixelBuffer(), 0, srcw * elementsPerPixel,
-                IntBuffer.wrap(this.data), (dsty * width) + dstx, width, srcw, srch);
-    }
-
-    @Override
-    public void update(Buffer buffer, PixelFormat format, int dstx, int dsty, int srcx, int srcy, int srcw, int srch, int srcscan, boolean skipFlush) {
-        throw new UnsupportedOperationException("update5:unimp");
+        buffer.position(0);
+        converter.convert(buffer, (srcy * srcscan) + srcx, srcscan,
+                          IntBuffer.wrap(this.data), (dsty * width) + dstx, width, srcw, srch);
     }
 
     @Override
@@ -149,6 +155,21 @@
         frame.releaseFrame();
     }
 
+    void checkDimensions(int srcw, int srch) {
+        if (srcw < 0) {
+            throw new IllegalArgumentException("srcw must be >=0");
+        }
+        if (srch < 0) {
+            throw new IllegalArgumentException("srch must be >=0");
+        }
+        if (srcw > this.width) {
+            throw new IllegalArgumentException("srcw exceeds WIDTH");
+        }
+        if (srch > this.height) {
+            throw new IllegalArgumentException("srch exceeds HEIGHT");
+        }
+    }
+
     void applyCompositeAlpha(float alpha) {
         if (allocated) {
             int finalAlpha;
@@ -162,10 +183,6 @@
         }
     }
 
-    int getBufferLength() {
-        return (data == null) ? 0 : data.length;
-    }
-
     void allocateBuffer() {
         this.data = new int[width * height];
     }
--- a/prism-sw/src/com/sun/prism/sw/SWMaskTexture.java	Tue Jun 04 10:09:31 2013 +0200
+++ b/prism-sw/src/com/sun/prism/sw/SWMaskTexture.java	Tue Jun 04 10:55:10 2013 +0200
@@ -27,7 +27,6 @@
 
 import java.nio.Buffer;
 import java.nio.ByteBuffer;
-import com.sun.prism.Image;
 import com.sun.prism.MediaFrame;
 import com.sun.prism.PixelFormat;
 import com.sun.prism.Texture;
@@ -56,16 +55,13 @@
     }
 
     @Override
-    public void update(Image img, int dstx, int dsty, int srcw, int srch, boolean skipFlush) {
-        throw new UnsupportedOperationException("update4:unimp");
-    }
-
-    @Override
-    public void update(Buffer buffer, PixelFormat format, int dstx, int dsty, int srcx, int srcy, int srcw, int srch, int srcscan, boolean skipFlush) {
+    public void update(Buffer buffer, PixelFormat format, int dstx, int dsty,
+                       int srcx, int srcy, int srcw, int srch, int srcscan, boolean skipFlush)
+    {
         if (PrismSettings.debug) {
-            System.out.println("+ SWMaskTexture.update pixelFormat: " + format);
-            System.out.println("dstx:" + dstx + " dsty:" + dsty + " srcx:" + srcx + " srcy:" + srcy +
-                               " srcw:" + srcw + " srch:" + srch);
+            System.out.println("MASK TEXTURE, Pixel format: " + format + ", buffer: " + buffer);
+            System.out.println("dstx:" + dstx + " dsty:" + dsty);
+            System.out.println("srcx:" + srcx + " srcy:" + srcy + " srcw:" + srcw + " srch:" + srch + " srcscan: " + srcscan);
         }
 
         if (format != PixelFormat.BYTE_ALPHA) {
@@ -76,8 +72,11 @@
         this.height = srch;
         this.allocate();
 
-        ByteBuffer bb = (ByteBuffer)buffer.position(0);
-        bb.get(this.data, 0, this.width * this.height);
+        ByteBuffer bb = (ByteBuffer)buffer;
+        for (int i = 0; i < srch; i++) {
+            bb.position((srcy + i)*srcscan + srcx);
+            bb.get(this.data, i*this.width, srcw);
+        }
     }
 
     @Override
@@ -85,8 +84,13 @@
         throw new UnsupportedOperationException("update6:unimp");
     }
 
-    int getBufferLength() {
-        return (data == null) ? 0 : data.length;
+    void checkAllocation(int srcw, int srch) {
+        if (allocated) {
+            final int nlen = srcw * srch;
+            if (nlen > this.data.length) {
+                throw new IllegalArgumentException("SRCW * SRCH exceeds buffer length");
+            }
+        }
     }
 
     void allocateBuffer() {
--- a/prism-sw/src/com/sun/prism/sw/SWTexture.java	Tue Jun 04 10:09:31 2013 +0200
+++ b/prism-sw/src/com/sun/prism/sw/SWTexture.java	Tue Jun 04 10:55:10 2013 +0200
@@ -43,7 +43,6 @@
 
     boolean allocated = false;
     int width, height;
-    int stride, offset;
     private SWResourceFactory factory;
     private int lastImageSerial;
     private final WrapMode wrapMode;
@@ -53,8 +52,6 @@
         this.wrapMode = wrapMode;
         width = w;
         height = h;
-        stride = w;
-        offset = 0;
         lock();
     }
 
@@ -74,11 +71,11 @@
     }
 
     int getStride() {
-        return stride;
+        return width;
     }
-    
+
     int getOffset() {
-        return offset;
+        return 0;
     }
 
     private int lockcount;
@@ -170,17 +167,27 @@
 
     @Override
     public void update(Image img) {
-        throw new UnsupportedOperationException("update1:unimp");
+        this.update(img, 0, 0);
     }
 
     @Override
     public void update(Image img, int dstx, int dsty) {
-        throw new UnsupportedOperationException("update2:unimp");
+        this.update(img, dstx, dsty, img.getWidth(), img.getHeight());
     }
 
     @Override
     public void update(Image img, int dstx, int dsty, int srcw, int srch) {
-        throw new UnsupportedOperationException("update3:unimp");
+        this.update(img, dstx, dsty, srcw, srch, false);
+    }
+
+    @Override
+    public void update(Image img, int dstx, int dsty, int srcw, int srch, boolean skipFlush) {
+        if (PrismSettings.debug) {
+            System.out.println("IMG.Bytes per pixel: " + img.getBytesPerPixelUnit());
+            System.out.println("IMG.scanline: " + img.getScanlineStride());
+        }
+        this.update(img.getPixelBuffer(), img.getPixelFormat(), dstx, dsty,
+                    0, 0, srcw, srch, img.getScanlineStride(), skipFlush);
     }
 
     @Override
@@ -219,15 +226,6 @@
     @Override
     public void setLinearFiltering(boolean linear) { }
 
-    void checkAllocation(int srcw, int srch) {
-        if (allocated) {
-            final int nlen = srcw * srch;
-            if (nlen > this.getBufferLength()) {
-                throw new IllegalArgumentException("SRCW * SRCH exceeds buffer length");
-            }
-        }
-    }
-
     void allocate() {
         if (allocated) {
             return;
@@ -239,8 +237,6 @@
         allocated = true;
     }
 
-    abstract int getBufferLength();
-
     abstract void allocateBuffer();
 
     /**