Hi,

I send you two patches:

1. A patch improving performance of ShadowDecorator. The problem with ShadowDecorator is that when I repaint the content of a small frame that drops shadow, the frame shadow gets repainted, although it is hidden behind the window. And because shadow uses translucent image copying, it is quite slow on Linux. This patch adds code for checking whether the shadow should be repainted or not, basing on the current clip. Additionally I added memoization of BufferedImage in ApplicationContext. Well, again. Don't know why my previous proposition of memoizing the buffer has been applied only to VolatileImage and not also to BufferedImage. :(

2. A patch fixing frame resizing issue I've written some time ago - that sometimes it ignores the LMB down event, although the cursor is set to "resize window" icon.

Best regards and Happy New Year!
Piotr


Index: wtk/src/org/apache/pivot/wtk/effects/DropShadowDecorator.java
===================================================================
--- wtk/src/org/apache/pivot/wtk/effects/DropShadowDecorator.java	(wersja 1225867)
+++ wtk/src/org/apache/pivot/wtk/effects/DropShadowDecorator.java	(kopia robocza)
@@ -16,8 +16,7 @@
  */
 package org.apache.pivot.wtk.effects;
 
-import java.awt.Color;
-import java.awt.Graphics2D;
+import java.awt.*;
 import java.awt.geom.AffineTransform;
 import java.awt.image.BufferedImage;
 import java.awt.image.Raster;
@@ -178,16 +177,19 @@
                 || shadowImage.getWidth() != width + 2 * blurRadius
                 || shadowImage.getHeight() != height + 2 * blurRadius) {
                 // Recreate the shadow
-                BufferedImage rectangleImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+                BufferedImage rectangleImage =
+                    graphics.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.OPAQUE);
                 Graphics2D rectangleImageGraphics = rectangleImage.createGraphics();
                 rectangleImageGraphics.setColor(Color.BLACK);
                 rectangleImageGraphics.fillRect(0, 0, width, height);
                 rectangleImageGraphics.dispose();
-
                 shadowImage = createShadow(rectangleImage);
             }
 
-            graphics.drawImage(shadowImage, xOffset - blurRadius, yOffset - blurRadius, null);
+            // Avoid drawing shadow if it will be covered by the component itself:
+            Bounds paintBounds = new Bounds(0, 0, width, height);
+            if (!component.isOpaque() || !paintBounds.contains(new Bounds(graphics.getClipBounds())))
+                graphics.drawImage(shadowImage, xOffset - blurRadius, yOffset - blurRadius, null);
         } else {
             shadowImage = null;
         }
@@ -247,9 +249,11 @@
 
         int aSum;
 
-        BufferedImage dst = new BufferedImage(dstWidth, dstHeight,
-            BufferedImage.TYPE_INT_ARGB);
-
+        Graphics2D srcGraphics = src.createGraphics();
+        BufferedImage dst = srcGraphics.getDeviceConfiguration()
+                .createCompatibleImage(dstWidth, dstHeight, Transparency.TRANSLUCENT);
+        srcGraphics.dispose();
+                
         int[] dstBuffer = new int[dstWidth * dstHeight];
         int[] srcBuffer = new int[srcWidth * srcHeight];
 
Index: wtk/src/org/apache/pivot/wtk/ApplicationContext.java
===================================================================
--- wtk/src/org/apache/pivot/wtk/ApplicationContext.java	(wersja 1225867)
+++ wtk/src/org/apache/pivot/wtk/ApplicationContext.java	(kopia robocza)
@@ -42,6 +42,7 @@
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseWheelEvent;
+import java.awt.image.BufferedImage;
 import java.awt.print.PrinterGraphics;
 import java.io.IOException;
 import java.io.InputStream;
@@ -92,11 +93,14 @@
         private double scale = 1;
 
         private boolean paintPending = false;
-        private boolean disableVolatileBuffer = false;
+        private boolean disableVolatileBuffer = true;
         private boolean debugPaint = false;
         private java.awt.image.VolatileImage volatileImage = null;
         private GraphicsConfiguration volatileImageGC = null;
 
+        private BufferedImage bufferedImage = null;
+        private GraphicsConfiguration bufferedImageGC = null;
+
         private Random random = null;
 
         private transient DropTargetListener dropTargetListener = new DropTargetListener() {
@@ -288,11 +292,13 @@
                 // No-op
             }
 
+            /*
             try {
                 disableVolatileBuffer = Boolean.parseBoolean(System.getProperty("org.apache.pivot.wtk.disablevolatilebuffer"));
             } catch (SecurityException ex) {
                 // No-op
             }
+            */
 
             try {
                 debugPaint = Boolean.parseBoolean(System.getProperty("org.apache.pivot.wtk.debugpaint"));
@@ -503,9 +509,16 @@
             // Paint the display into an offscreen buffer
             GraphicsConfiguration gc = graphics.getDeviceConfiguration();
             java.awt.Rectangle clipBounds = graphics.getClipBounds();
-            java.awt.image.BufferedImage bufferedImage =
-                gc.createCompatibleImage(clipBounds.width, clipBounds.height,
-                    Transparency.OPAQUE);
+            
+            if (bufferedImageGC == null || 
+                    bufferedImage == null ||
+                    bufferedImageGC != gc ||
+                    bufferedImage.getWidth() < clipBounds.width || 
+                    bufferedImage.getHeight() < clipBounds.height) {
+                
+                bufferedImage = gc.createCompatibleImage(clipBounds.width, clipBounds.height, Transparency.OPAQUE);
+                bufferedImageGC = gc;
+            }
 
             if (bufferedImage != null) {
                 Graphics2D bufferedImageGraphics = (Graphics2D)bufferedImage.getGraphics();
Index: wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFrameSkin.java
===================================================================
--- wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFrameSkin.java	(wersja 1225867)
+++ wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFrameSkin.java	(kopia robocza)
@@ -789,9 +789,9 @@
                 dragOffset = new Point(x, y);
                 Mouse.capture(component);
             } else {
-                Bounds resizeHandleBounds = resizeHandle.getBounds();
-
-                if (resizable && resizeHandleBounds.contains(x, y)) {
+                if (resizable
+                        && x > resizeHandle.getX()
+                        && y > resizeHandle.getY()) {
                     resizeOffset = new Point(getWidth() - x, getHeight() - y);
                     Mouse.capture(component);
                 }

Reply via email to