[committed] Adding option for expanding dirty region in ImageGraphics

There is a code expanding dirty region by 2*2 and it says to prevent antialiasing problem.

I think it's good to have option to disable this.

Please tell me if it is useless or method name is ugly.  :oops:



Index: src/com/jmex/awt/swingui/ImageGraphics.java
===================================================================
--- src/com/jmex/awt/swingui/ImageGraphics.java   (revision 4337)
+++ src/com/jmex/awt/swingui/ImageGraphics.java   (working copy)
@@ -44,6 +44,11 @@
  * This abstract class provides methods to paint on a {@link com.jme.image.Image} via the awt {@link Graphics2D}.
  */
 public abstract class ImageGraphics extends Graphics2D {
+   
+   /**
+    * if true, dirty region grow by 2x2 to prevent antialiasing problem
+    */
+   private boolean expandDirtyRegion = true;
 
     /**
      * @param width of the image
@@ -117,4 +122,19 @@
      * @return true if image/texture needs update
      */
     public abstract boolean isDirty();
+   
+   
+    /**
+     * @param expand if true, dirty region grow by 2x2 to prevent antialiasing problem
+     */
+    public void setExpandDirtyRegion(boolean expand) {
+       expandDirtyRegion = expand;
+    }
+   
+    /**
+     * @return if true, dirty region grow by 2x2 to prevent antialiasing problem
+     */
+    public boolean isExpandDirtyRegion() {
+       return expandDirtyRegion;
+    }
 }
Index: src/com/jmex/awt/swingui/LWJGLImageGraphics.java
===================================================================
--- src/com/jmex/awt/swingui/LWJGLImageGraphics.java   (revision 4337)
+++ src/com/jmex/awt/swingui/LWJGLImageGraphics.java   (working copy)
@@ -83,7 +83,7 @@
     public void update( Texture texture, boolean clean ) {
         boolean updateChildren = false;
         synchronized ( dirty ) {
-            if ( !dirty.isEmpty() ) {
+            if ( !dirty.isEmpty() && isExpandDirtyRegion() ) {
                 dirty.grow( 2, 2 ); // to prevent antialiasing problems
             }
             Rectangle2D.intersect( dirty, getImageBounds(), dirty );
Index: src/com/jmex/awt/swingui/JOGLImageGraphics.java
===================================================================
--- src/com/jmex/awt/swingui/JOGLImageGraphics.java   (revision 4337)
+++ src/com/jmex/awt/swingui/JOGLImageGraphics.java   (working copy)
@@ -83,7 +83,7 @@
         final GLU glu = new GLU();
         boolean updateChildren = false;
         synchronized ( dirty ) {
-            if ( !dirty.isEmpty() ) {
+            if ( !dirty.isEmpty() && isExpandDirtyRegion()) {
                 dirty.grow( 2, 2 ); // to prevent antialiasing problems
             }
             Rectangle2D.intersect( dirty, getImageBounds(), dirty );

Expanding by 2x2 won't do much… Are you experiencing any issues with it that you find this patch necessary?

Unlocked this… dunno why it was locked?


llama said:

Unlocked this.. dunno why it was locked?

Thanks. :)

Momoko_Fan said:

Expanding by 2x2 won't do much.. Are you experiencing any issues with it that you find this patch necessary?

In my project, ImageGraphics.update() is called often and I found this method may be performance bottleneck.
So I just wanted to reduce the burden somewhat.