Revision: 2118
          http://vexi.svn.sourceforge.net/vexi/?rev=2118&view=rev
Author:   clrg
Date:     2007-09-04 05:02:50 -0700 (Tue, 04 Sep 2007)

Log Message:
-----------
Micro-optimizations for dirty region handling

Modified Paths:
--------------
    trunk/core/org.vexi.core/src/org/vexi/core/Surface.java
    trunk/core/org.vexi.core/src/org/vexi/util/DirtyList.java

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Surface.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Surface.java     2007-09-03 
17:27:39 UTC (rev 2117)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Surface.java     2007-09-04 
12:02:50 UTC (rev 2118)
@@ -376,10 +376,11 @@
             root.reflow();
         } while(abort);
 
+        int numregions = dirtyRegions.num();
         int[][] dirt = dirtyRegions.flush();
 
         PixelBuffer buff = getPixelBuffer();
-        for(int i = 0; dirt != null && i < dirt.length; i++) {
+        for(int i = 0; dirt != null && i < numregions; i++) {
             if (dirt[i] == null) continue;
             int x = dirt[i][0], y = dirt[i][1], w = dirt[i][2], h = dirt[i][3];
             if (x < 0) x = 0;
@@ -399,7 +400,7 @@
                 // x,y,w,h is only partially reconstructed, so we must be 
careful not to re-blit it
                 dirtyRegions.dirty(x, y, w, h);
                 // put back all the dirty regions we haven't yet processed 
(including the current one)
-                for(int j=i; j<dirt.length; j++)
+                for(int j=i; j<numregions; j++)
                     if (dirt[j] != null)
                         dirtyRegions.dirty(dirt[j][0], dirt[j][1], dirt[j][2], 
dirt[j][3]);
                 return;
@@ -499,8 +500,9 @@
         public void render() {
             super.render();
             if (abort) return;
+            int numregions = screenDirtyRegions.num();
             int[][] dirt = screenDirtyRegions.flush();
-            for(int i = 0; dirt != null && i < dirt.length; i++) {
+            for(int i = 0; dirt != null && i < numregions; i++) {
                 if (dirt[i] == null) continue;
                 int x = dirt[i][0];
                 int y = dirt[i][1];

Modified: trunk/core/org.vexi.core/src/org/vexi/util/DirtyList.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/util/DirtyList.java   2007-09-03 
17:27:39 UTC (rev 2117)
+++ trunk/core/org.vexi.core/src/org/vexi/util/DirtyList.java   2007-09-04 
12:02:50 UTC (rev 2118)
@@ -35,11 +35,9 @@
 
     /** Add a new rectangle to the dirty list; returns false if the
      *  region fell completely within an existing rectangle or set of
-     *  rectangles (ie did not expand the dirty area)
+     *  rectangles (i.e. did not expand the dirty area)
      */
     private synchronized void dirty(int x, int y, int w, int h, int ind) {
-        if (numdirties == dirties.length) grow();
-
         for(int i=ind; i<numdirties; i++) {
             if (dirties[i]==null) continue;
             int[] cur = dirties[i];
@@ -51,7 +49,7 @@
             // new region starts to the left of existing region
             if (x < cur[0]) {
 
-                // new region overlaps at least the topleft corner of existing 
region
+                // new region overlaps at least the top-left corner of 
existing region
                 if (y < cur[1]) {
 
                     // new region overlaps entire width of existing region
@@ -75,7 +73,7 @@
                             dirties[i][0] = x + w;
                             dirties[i][2] = cur[0] + cur[2] - (x + w);
 
-                        // new region overlaps topleft corner of existing 
region
+                        // new region overlaps top-left corner of existing 
region
                         } else {
                             dirty(x, y, w, cur[1]-y, i+1);
                             dirty(x, cur[1], cur[0]-x, h-(cur[1]-y), i+1);
@@ -103,7 +101,7 @@
                     // new region ends within horizontal range of existing 
region
                     } else {
 
-                        // new region overlaps bottomleft corner of existing 
region
+                        // new region overlaps bottom-left corner of existing 
region
                         if (y + h > cur[1] + cur[3]) {
                             dirty(x, y, cur[0]-x, h, i+1);
                             dirty(cur[0], cur[1]+cur[3], x+w-cur[0], 
y+h-(cur[1]+cur[3]), i+1);
@@ -121,14 +119,14 @@
                 // new region starts above existing region
                 if (y < cur[1]) {
 
-                    // new region overlaps at least top right of existing 
region
+                    // new region overlaps at least top-right of existing 
region
                     if (x + w > cur[0] + cur[2]) {
 
                         // new region contains the right of existing region
                         if (y + h > cur[1] + cur[3]) {
                             dirties[i][2] = x - cur[0];
 
-                        // new region overlaps top right of existing region
+                        // new region overlaps top-right of existing region
                         } else {
                             dirty(x, y, w, cur[1]-y, i+1);
                             dirty(cur[0]+cur[2], cur[1], x+w-(cur[0]+cur[2]), 
y+h-cur[1], i+1);
@@ -155,7 +153,7 @@
                     // new region overlaps at least to the right of existing 
region
                     if (x + w > cur[0] + cur[2]) {
 
-                        // new region overlaps bottomright corner of existing 
region
+                        // new region overlaps bottom-right corner of existing 
region
                         if (y + h > cur[1] + cur[3]) {
                             dirty(x, cur[1]+cur[3], w, y+h-(cur[1]+cur[3]), 
i+1);
                             dirty(cur[0]+cur[2], y, x+w-(cur[0]+cur[2]), 
cur[1]+cur[3]-y, i+1);
@@ -181,6 +179,7 @@
             }
         }
 
+        if (numdirties == dirties.length) grow();
         dirties[numdirties++] = new int[] { x, y, w, h };
     }
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to