Revision: 4031
          http://vexi.svn.sourceforge.net/vexi/?rev=4031&view=rev
Author:   clrg
Date:     2011-02-09 23:39:56 +0000 (Wed, 09 Feb 2011)

Log Message:
-----------
A hack w/ explanation around a blit race condition (fix pending)

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

Modified: trunk/org.vexi-core.main/src/main/java/org/vexi/core/Surface.java
===================================================================
--- trunk/org.vexi-core.main/src/main/java/org/vexi/core/Surface.java   
2011-02-09 14:46:56 UTC (rev 4030)
+++ trunk/org.vexi-core.main/src/main/java/org/vexi/core/Surface.java   
2011-02-09 23:39:56 UTC (rev 4031)
@@ -751,6 +751,7 @@
                 continue;
             }
 
+//            System.out.println("render: "+x+","+y+" -> "+w+","+h);
             root.render(0, 0, x, y, w, h, buf);
             if (scarImage != null) {
                 if (scarImage.width > x && scar_y < h) {
@@ -759,6 +760,7 @@
             }
 
             if (abort) {
+                //System.out.println("abort");
                 // x,y,w,h is only partially reconstructed, so we must be 
careful not to re-blit it
                 dirty(x, y, w, h);
                 // put back all the dirty regions we haven't yet processed 
(including the current one)
@@ -818,12 +820,34 @@
         }
 
         public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int 
y2, int color) {
+//            System.out.println("fillTrapezoid: "+x1+"|"+x2+","+y1+" -> 
"+x3+"|"+x4+","+y2+" - "+Color.colorToString(color));
             backbuffer.fillTrapezoid(x1, x2, y1, x3, x4, y2, color);
         }
 
-        public RenderedRegions render() {
+        // FIXME: this hack is to cover up a race condition whereby the 
backbuffer
+        // and the window image get somehow out of sync under 
tough-to-reproduce
+        // circumstances i.e. fairly complex applications.  The backbuffer is 
valid,
+        // it is actually correctly (briefly) painted to the window before the
+        // _previous_ state of the backbuffer is then painted back over it (!!)
+        // because asynchronize blits seem to occur first-in last-out - that 
is,
+        // blit from render is called after a refresh, but refresh happens 
last.
+        // To test without the blithack, set disable_blithack to true; it also
+        // adds a 1/4s pause before blitting so you can see the blit 
progression.
+        private boolean blithack = true;
+        private boolean disable_blithack = false;
+        
+        /** renders the surface display with changes made to the backbuffer */
+        public synchronized RenderedRegions render() {
             RenderedRegions r = super.render();
-            if (r==null) return null;
+            if (r==null) {
+                if (blithack && !disable_blithack) {
+                    blithack = false;
+                    blit(backbuffer, 0, 0, 0, 0, root.width, root.height);
+                }
+                return null;
+            }
+            blithack = true;
+            
             int numregions = r.numregions;
             int[] regions = r.regions;
             
@@ -854,7 +878,14 @@
             if (w > rwidth) w = rwidth;
             if (h > rheight) h = rheight;
             if (w > x && h > y) {
+                if (disable_blithack) {
+                    System.out.println("render blit: "+x+","+y+" -> 
"+w+","+h+")");
+                    try {
+                        Thread.sleep(250);
+                    } catch(InterruptedException e) { }
+                }
                 blit(backbuffer, x, y, x, y, w, h);
+//                refreshFromBackbuffer(x, y, w-x, h-y);
             }
             return r;
         }
@@ -863,6 +894,9 @@
         public final void refreshFromBackbuffer(int x, int y, int w, int h) {
             blit(backbuffer, x, y, x, y, x + w, y + h);
         }
+//        public final synchronized void refreshFromBackbuffer(int x, int y, 
int w, int h) {
+//            blit(x, y, w, h);
+//        }
 
 //        public void dirty(int x, int y, int w, int h) {
 //            screenDirtyRegions.dirty(x, y, w, h);


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

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to