changeset 6170:3943d4344924

Fix RT-33294: Canas PixelWriter can be very slow Reviewed by Felipe and Chien
author flar <James.Graham@oracle.com>
date Wed, 22 Jan 2014 13:39:45 -0800
parents f7e4bebcf795
children a46ffa89a080
files modules/graphics/src/main/java/com/sun/javafx/sg/prism/GrowableDataBuffer.java modules/graphics/src/main/java/com/sun/javafx/sg/prism/NGCanvas.java
diffstat 2 files changed, 21 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/sg/prism/GrowableDataBuffer.java	Wed Jan 22 07:49:26 2014 -0800
+++ b/modules/graphics/src/main/java/com/sun/javafx/sg/prism/GrowableDataBuffer.java	Wed Jan 22 13:39:45 2014 -0800
@@ -49,7 +49,8 @@
  * time, but any given buffer should only be returned to the pool once.
  */
 public class GrowableDataBuffer {
-    static final int MIN_VAL_GROW = 1024;
+    static final int VAL_GROW_QUANTUM = 1024;
+    static final int MAX_VAL_GROW = 1024 * 1024;
     static final int MIN_OBJ_GROW = 32;
 
     static class WeakLink {
@@ -299,9 +300,15 @@
     }
 
     private void ensureWriteCapacity(int newbytes) {
-        if (writevalpos + newbytes > vals.length) {
-            if (newbytes < MIN_VAL_GROW) newbytes = MIN_VAL_GROW;
-            vals = Arrays.copyOf(vals, writevalpos + newbytes);
+        if (newbytes > vals.length - writevalpos) {
+            newbytes = writevalpos + newbytes - vals.length;
+            // Double in size up to MAX_VAL_GROW
+            int growbytes = Math.min(vals.length, MAX_VAL_GROW);
+            // And at least by the number of new bytes
+            if (growbytes < newbytes) growbytes = newbytes;
+            int newsize = vals.length + growbytes;
+            newsize = (newsize + (VAL_GROW_QUANTUM - 1)) & ~(VAL_GROW_QUANTUM - 1);
+            vals = Arrays.copyOf(vals, newsize);
         }
     }
 
--- a/modules/graphics/src/main/java/com/sun/javafx/sg/prism/NGCanvas.java	Wed Jan 22 07:49:26 2014 -0800
+++ b/modules/graphics/src/main/java/com/sun/javafx/sg/prism/NGCanvas.java	Wed Jan 22 13:39:45 2014 -0800
@@ -297,7 +297,6 @@
         }
     }
 
-    private static Image TMP_IMAGE = Image.fromIntArgbPreData(new int[1], 1, 1);
     private static Blend BLENDER = new MyBlend(Mode.SRC_OVER, null, null);
 
     private GrowableDataBuffer thebuf;
@@ -803,21 +802,22 @@
                     float dx1 = buf.getInt();
                     float dy1 = buf.getInt();
                     int argb = buf.getInt();
-                    TMP_IMAGE.setArgb(0, 0, argb);
                     Graphics gr = cv.g;
                     gr.setExtraAlpha(1.0f);
                     gr.setCompositeMode(CompositeMode.SRC);
                     gr.setTransform(BaseTransform.IDENTITY_TRANSFORM);
-                    ResourceFactory factory = gr.getResourceFactory();
-                    Texture tex =
-                        factory.getCachedTexture(TMP_IMAGE, Texture.WrapMode.CLAMP_TO_EDGE);
                     dx1 *= highestPixelScale;
                     dy1 *= highestPixelScale;
-                    gr.drawTexture(tex,
-                                   dx1, dy1, dx1 + highestPixelScale, dy1 + highestPixelScale,
-                                   0, 0, 1, 1);
-                    tex.contentsNotUseful();
-                    tex.unlock();
+                    float a = ((argb) >>> 24) / 255.0f;
+                    float r = (((argb) >> 16) & 0xff) / 255.0f;
+                    float g = (((argb) >>  8) & 0xff) / 255.0f;
+                    float b = (((argb)      ) & 0xff) / 255.0f;
+                    gr.setPaint(new Color(r, g, b, a));
+                    // Note that we cannot use fillRect here because SRC
+                    // mode does not interact well with antialiasing.
+                    // fillQuad does hard edges which matches the concept
+                    // of setting adjacent abutting, non-overlapping "pixels"
+                    gr.fillQuad(dx1, dy1, dx1+highestPixelScale, dy1+highestPixelScale);
                     break;
                 }
                 case PUT_ARGBPRE_BUF: