[libbluray-devel] BDGraphics: fix race condition / image corruption in drawSpan()

hpi1 git at videolan.org
Wed Mar 26 19:29:28 CET 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Mar 26 11:02:35 2014 +0200| [03456832a3620e469b27d873adb3d9b0d9033112] | committer: hpi1

BDGraphics: fix race condition / image corruption in drawSpan()

Fixes lost changes when frame buffer is sent to application
between updating dirty area and drawing the span:
 1) dirty area is changed in drawSpan (before drawing)
 2) frame buffer is sent to application (before drawing)
    - dirty area is reset
 3) image is updated in drawSpan
    - changed area is missing from dirty area

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=03456832a3620e469b27d873adb3d9b0d9033112
---

 src/libbluray/bdj/java/java/awt/BDGraphicsBase.java |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java b/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
index 1d4a1a3..53d4d2f 100644
--- a/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
+++ b/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
@@ -302,12 +302,12 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
         x      = rect.x;
         length = rect.width;
 
-        dirty.add(rect);
-
         if (xorColor != null) {
             for (int i = 0; i < length; i++) {
                 backBuffer[y * width + x + i] ^= xorColor.getRGB() ^ rgb;
             }
+
+            dirty.add(rect);
             return;
         }
 
@@ -330,6 +330,8 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
                 }
                 break;
         }
+
+        dirty.add(rect);
     }
 
     private void drawSpanN(int x, int y, int length, int src[], int srcOffset) {
@@ -345,12 +347,12 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
         x          = rect.x;
         length     = rect.width;
 
-        dirty.add(rect);
-
         if (xorColor != null) {
             for (int i = 0; i < length; i++) {
                 backBuffer[y * width + x + i] ^= xorColor.getRGB() ^ src[srcOffset + i];
             }
+
+            dirty.add(rect);
             return;
         }
 
@@ -371,6 +373,8 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
                 }
                 break;
         }
+
+        dirty.add(rect);
     }
 
     private void drawSpan(int x, int y, int length, int rgb) {



More information about the libbluray-devel mailing list