libbluray | branch: master | hpi1 <[email protected]> | Tue Apr 30 12:39:27 2013 +0300| [78f5d6a82f9d279206a77e758ef24161d6c0ea2a] | committer: hpi1
Implement Area class for dirty area (hide differences between J2ME and J2SE Rectangle implementations) > http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=78f5d6a82f9d279206a77e758ef24161d6c0ea2a --- .../bdj/java-j2me/java/awt/BDGraphics.java | 6 +- .../bdj/java-j2se/java/awt/BDGraphics.java | 6 +- src/libbluray/bdj/java/java/awt/Area.java | 73 ++++++++++++++++++++ src/libbluray/bdj/java/java/awt/BDImageBase.java | 6 +- src/libbluray/bdj/java/java/awt/BDRootWindow.java | 15 ++-- 5 files changed, 90 insertions(+), 16 deletions(-) diff --git a/src/libbluray/bdj/java-j2me/java/awt/BDGraphics.java b/src/libbluray/bdj/java-j2me/java/awt/BDGraphics.java index c55af5d..169474f 100644 --- a/src/libbluray/bdj/java-j2me/java/awt/BDGraphics.java +++ b/src/libbluray/bdj/java-j2me/java/awt/BDGraphics.java @@ -40,7 +40,7 @@ class BDGraphics extends Graphics2D implements ConstrainableGraphics { private int width; private int height; private int[] backBuffer; - private Rectangle dirty; + private Area dirty; private GraphicsConfiguration gc; private Color foreground; private Color background; @@ -90,7 +90,7 @@ class BDGraphics extends Graphics2D implements ConstrainableGraphics { width = window.getWidth(); height = window.getHeight(); backBuffer = window.getBdBackBuffer(); - dirty = window.getDirtyRect(); + dirty = window.getDirtyArea(); gc = window.getGraphicsConfiguration(); foreground = window.getForeground(); background = window.getBackground(); @@ -110,7 +110,7 @@ class BDGraphics extends Graphics2D implements ConstrainableGraphics { width = image.getWidth(); height = image.getHeight(); backBuffer = image.getBdBackBuffer(); - dirty = image.getDirtyRect(); + dirty = image.getDirtyArea(); gc = image.getGraphicsConfiguration(); Component component = image.getComponent(); if (component != null) { diff --git a/src/libbluray/bdj/java-j2se/java/awt/BDGraphics.java b/src/libbluray/bdj/java-j2se/java/awt/BDGraphics.java index 4fb9005..4c61d68 100644 --- a/src/libbluray/bdj/java-j2se/java/awt/BDGraphics.java +++ b/src/libbluray/bdj/java-j2se/java/awt/BDGraphics.java @@ -44,7 +44,7 @@ class BDGraphics extends Graphics2D implements ConstrainableGraphics { private int width; private int height; private int[] backBuffer; - private Rectangle dirty; + private Area dirty; private GraphicsConfiguration gc; private Color foreground; private Color background; @@ -97,7 +97,7 @@ class BDGraphics extends Graphics2D implements ConstrainableGraphics { width = window.getWidth(); height = window.getHeight(); backBuffer = window.getBdBackBuffer(); - dirty = window.getDirtyRect(); + dirty = window.getDirtyArea(); gc = window.getGraphicsConfiguration(); foreground = window.getForeground(); background = window.getBackground(); @@ -124,7 +124,7 @@ class BDGraphics extends Graphics2D implements ConstrainableGraphics { width = image.getWidth(); height = image.getHeight(); backBuffer = image.getBdBackBuffer(); - dirty = image.getDirtyRect(); + dirty = image.getDirtyArea(); gc = image.getGraphicsConfiguration(); Component component = image.getComponent(); diff --git a/src/libbluray/bdj/java/java/awt/Area.java b/src/libbluray/bdj/java/java/awt/Area.java new file mode 100644 index 0000000..8c3561b --- /dev/null +++ b/src/libbluray/bdj/java/java/awt/Area.java @@ -0,0 +1,73 @@ + /* + * This file is part of libbluray + * Copyright (C) 2013 Petri Hintukainen <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +package java.awt; + +class Area { + public int x0; + public int y0; + public int x1; + public int y1; + + public Area() { + clear(); + } + + public Area(int width, int height) { + this(0, 0, width - 1, height - 1); + } + + public Area(int x0, int y0, int x1, int y1) { + this.x0 = x0; + this.y0 = y0; + this.x1 = x1; + this.y1 = y1; + } + + public void clear() { + x0 = Integer.MAX_VALUE; + y0 = Integer.MAX_VALUE; + x1 = -1; + y1 = -1; + } + + public 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) { + 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); + y0 = Math.min(y0, r.y); + y1 = Math.max(y1, r.y + r.height - 1); + } + } + + public boolean isEmpty() { + return (x1 < x0) || (y1 < y0); + } + + public Area getBounds() { + return new Area(x0, y0, x1, y1); + } +} diff --git a/src/libbluray/bdj/java/java/awt/BDImageBase.java b/src/libbluray/bdj/java/java/awt/BDImageBase.java index 15ff1e0..95c5de4 100644 --- a/src/libbluray/bdj/java/java/awt/BDImageBase.java +++ b/src/libbluray/bdj/java/java/awt/BDImageBase.java @@ -39,7 +39,7 @@ class BDImageBase extends Image { private Component component; protected int width, height; protected int[] backBuffer; - protected Rectangle dirty; + protected Area dirty; private GraphicsConfiguration gc; private Vector observers = new Vector(); @@ -77,7 +77,7 @@ class BDImageBase extends Image { if (width > 0 && height > 0) backBuffer = new int[width * height]; - dirty = new Rectangle(width, height); + dirty = new Area(width, height); } public void flush() { @@ -148,7 +148,7 @@ class BDImageBase extends Image { return backBuffer; } - public Rectangle getDirtyRect() { + public Area getDirtyArea() { return dirty; } diff --git a/src/libbluray/bdj/java/java/awt/BDRootWindow.java b/src/libbluray/bdj/java/java/awt/BDRootWindow.java index 7ac35b9..c30a305 100644 --- a/src/libbluray/bdj/java/java/awt/BDRootWindow.java +++ b/src/libbluray/bdj/java/java/awt/BDRootWindow.java @@ -34,7 +34,7 @@ public class BDRootWindow extends Frame { BDToolkit.setFocusedWindow(this); } - public Rectangle getDirtyRect() { + public Area getDirtyArea() { return dirty; } @@ -50,7 +50,7 @@ public class BDRootWindow extends Frame { Libbluray.updateGraphic(width, height, null); - dirty.setBounds(0, 0, width - 1, height - 1); + dirty.add(new Rectangle(0, 0, width - 1, height - 1)); } } @@ -86,11 +86,12 @@ public class BDRootWindow extends Frame { } changeCount = 0; - if ((dirty.width | dirty.height) >= 0) { - Libbluray.updateGraphic(getWidth(), getHeight(), backBuffer, dirty.x, dirty.y, - dirty.x + dirty.width - 1, dirty.y + dirty.height - 1); + Area a = dirty.getBounds(); + dirty.clear(); + + if (!a.isEmpty()) { + Libbluray.updateGraphic(getWidth(), getHeight(), backBuffer, a.x0, a.y0, a.x1, a.y1); } - dirty.setSize(-1, -1); } } @@ -133,7 +134,7 @@ public class BDRootWindow extends Frame { } private int[] backBuffer = null; - private Rectangle dirty = new Rectangle(); + private Area dirty = new Area(); private int changeCount = 0; private Timer timer = new Timer(); private TimerTask timerTask = null; _______________________________________________ libbluray-devel mailing list [email protected] http://mailman.videolan.org/listinfo/libbluray-devel
