aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun/opengl/impl
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2008-12-07 21:00:31 +0000
committerKenneth Russel <[email protected]>2008-12-07 21:00:31 +0000
commit98df81306243ff09b0a60229c34381c04b86a02f (patch)
treee1ff2c097cdeb528dbbfb143d5cfb2a4446ba263 /src/classes/com/sun/opengl/impl
parent0361321d7e49587e9bcb17b1c90243692f126b55 (diff)
Made compaction support optional in BackingStoreManager, and therefore
RectanglePacker, to make it easier for clients to get up and running; note that this also disallows expansion. Changed additionFailed to return a boolean. Updated GL2TextRenderer appropriately. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1814 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/impl')
-rwxr-xr-xsrc/classes/com/sun/opengl/impl/packrect/BackingStoreManager.java18
-rwxr-xr-xsrc/classes/com/sun/opengl/impl/packrect/RectanglePacker.java27
2 files changed, 35 insertions, 10 deletions
diff --git a/src/classes/com/sun/opengl/impl/packrect/BackingStoreManager.java b/src/classes/com/sun/opengl/impl/packrect/BackingStoreManager.java
index 0c4636063..2ca5a5a7b 100755
--- a/src/classes/com/sun/opengl/impl/packrect/BackingStoreManager.java
+++ b/src/classes/com/sun/opengl/impl/packrect/BackingStoreManager.java
@@ -49,6 +49,16 @@ public interface BackingStoreManager {
public Object allocateBackingStore(int w, int h);
public void deleteBackingStore(Object backingStore);
+ /** Indication whether this BackingStoreManager supports compaction;
+ in other words, the allocation of a new backing store and
+ movement of the contents of the backing store from the old to
+ the new one. If it does not, then RectanglePacker.add() may
+ throw an exception if additionFailed() can not make enough room
+ available. If an implementation returns false, this also implies
+ that the backing store can not grow, so that preExpand() will
+ never be called. */
+ public boolean canCompact();
+
/** Notification that expansion of the backing store is about to be
done due to addition of the given rectangle. Gives the manager a
chance to do some compaction and potentially remove old entries
@@ -64,8 +74,12 @@ public interface BackingStoreManager {
/** Notification that addition of the given Rect failed because a
maximum size was set in the RectanglePacker and the backing
- store could not be expanded. */
- public void additionFailed(Rect cause, int attemptNumber);
+ store could not be expanded, or because compaction (and,
+ therefore, implicitly expansion) was not supported. Should
+ return false if the manager can do nothing more to handle the
+ failed addition, which will cause a RuntimeException to be
+ thrown from the RectanglePacker. */
+ public boolean additionFailed(Rect cause, int attemptNumber);
/** Notification that movement is starting. */
public void beginMovement(Object oldBackingStore, Object newBackingStore);
diff --git a/src/classes/com/sun/opengl/impl/packrect/RectanglePacker.java b/src/classes/com/sun/opengl/impl/packrect/RectanglePacker.java
index 3a77b3bd1..8520484cf 100755
--- a/src/classes/com/sun/opengl/impl/packrect/RectanglePacker.java
+++ b/src/classes/com/sun/opengl/impl/packrect/RectanglePacker.java
@@ -102,8 +102,12 @@ public class RectanglePacker {
/** Decides upon an (x, y) position for the given rectangle (leaving
its width and height unchanged) and places it on the backing
- store. May provoke re-layout of other Rects already added. */
- public void add(Rect rect) {
+ store. May provoke re-layout of other Rects already added. If
+ the BackingStoreManager does not support compaction, and {@link
+ BackingStoreManager#preExpand BackingStoreManager.preExpand}
+ does not clear enough space for the incoming rectangle, then
+ this method will throw a RuntimeException. */
+ public void add(Rect rect) throws RuntimeException {
// Allocate backing store if we don't have any yet
if (backingStore == null)
backingStore = manager.allocateBackingStore(levels.w(), levels.h());
@@ -116,14 +120,21 @@ public class RectanglePacker {
if (levels.add(rect))
return;
- // Try to allocate with horizontal compaction
- if (levels.compactAndAdd(rect, backingStore, manager))
- return;
-
- // Let the manager have a chance at potentially evicting some entries
- tryAgain = manager.preExpand(rect, attemptNumber++);
+ if (manager.canCompact()) {
+ // Try to allocate with horizontal compaction
+ if (levels.compactAndAdd(rect, backingStore, manager))
+ return;
+ // Let the manager have a chance at potentially evicting some entries
+ tryAgain = manager.preExpand(rect, attemptNumber++);
+ } else {
+ tryAgain = manager.additionFailed(rect, attemptNumber++);
+ }
} while (tryAgain);
+ if (!manager.canCompact()) {
+ throw new RuntimeException("BackingStoreManager does not support compaction or expansion, and didn't clear space for new rectangle");
+ }
+
compactImpl(rect);
// Retry the addition of the incoming rectangle