[libbluray-devel] BDRootWindow: fix possible race conditions in dirty area handling

hpi1 git at videolan.org
Fri Aug 19 17:36:18 CEST 2016


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Fri Aug 19 18:30:44 2016 +0300| [539ec3b73f78d0051bd2c23e9256908d0c57d8b4] | committer: hpi1

BDRootWindow: fix possible race conditions in dirty area handling

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

 src/libbluray/bdj/java/java/awt/Area.java         | 16 +++++++++++-----
 src/libbluray/bdj/java/java/awt/BDRootWindow.java |  5 ++---
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/libbluray/bdj/java/java/awt/Area.java b/src/libbluray/bdj/java/java/awt/Area.java
index 9f40442..27bde88 100644
--- a/src/libbluray/bdj/java/java/awt/Area.java
+++ b/src/libbluray/bdj/java/java/awt/Area.java
@@ -40,21 +40,21 @@ class Area {
         this.y1 = y1;
     }
 
-    public void clear() {
+    private void clear() {
         x0 = Integer.MAX_VALUE;
         y0 = Integer.MAX_VALUE;
         x1 = -1;
         y1 = -1;
     }
 
-    public void add(int newx, int newy) {
+    public synchronized void add(int newx, int newy) {
         x0 = Math.min(x0, newx);
         x1 = Math.max(x1, newx);
         y0 = Math.min(y0, newy);
         y1 = Math.max(y1, newy);
     }
 
-    public void add(Rectangle r) {
+    public synchronized void add(Rectangle r) {
         if ((r.x | r.width | r.y | r.height) >= 0) {
             x0 = Math.min(x0, r.x);
             x1 = Math.max(x1, r.x + r.width - 1);
@@ -63,14 +63,20 @@ class Area {
         }
     }
 
-    public boolean isEmpty() {
+    public synchronized boolean isEmpty() {
         return (x1 < x0) || (y1 < y0);
     }
 
-    public Area getBounds() {
+    private synchronized Area getBounds() {
         return new Area(x0, y0, x1, y1);
     }
 
+    protected synchronized Area getBoundsAndClear() {
+        Area a = getBounds();
+        clear();
+        return a;
+    }
+
     public String toString() {
         return getClass().getName() + "[" + x0 + "," + y0 + "-" + x1 + "," + y1 + "]";
     }
diff --git a/src/libbluray/bdj/java/java/awt/BDRootWindow.java b/src/libbluray/bdj/java/java/awt/BDRootWindow.java
index 4c4f815..f34da83 100644
--- a/src/libbluray/bdj/java/java/awt/BDRootWindow.java
+++ b/src/libbluray/bdj/java/java/awt/BDRootWindow.java
@@ -124,8 +124,7 @@ public class BDRootWindow extends Frame {
                 return;
             }
 
-            Area a = dirty.getBounds();
-            dirty.clear();
+            Area a = dirty.getBoundsAndClear();
 
             if (!a.isEmpty()) {
                 if (!overlay_open) {
@@ -188,8 +187,8 @@ public class BDRootWindow extends Frame {
             if (overlay_open) {
                 logger.error("clearOverlay() ignored (overlay is visible)");
             } else {
+                dirty.getBoundsAndClear();
                 Arrays.fill(backBuffer, 0);
-                dirty.clear();
             }
         }
     }



More information about the libbluray-devel mailing list