diff options
Diffstat (limited to 'src/share/classes/java/awt/Component.java')
-rw-r--r-- | src/share/classes/java/awt/Component.java | 99 |
1 files changed, 83 insertions, 16 deletions
diff --git a/src/share/classes/java/awt/Component.java b/src/share/classes/java/awt/Component.java index 6d3a74970..c3e076983 100644 --- a/src/share/classes/java/awt/Component.java +++ b/src/share/classes/java/awt/Component.java @@ -74,7 +74,11 @@ import sun.awt.dnd.SunDropTargetEvent; import sun.awt.im.CompositionArea; import sun.java2d.SunGraphics2D; import sun.java2d.pipe.Region; +import sun.awt.image.VSyncedBSManager; +import sun.java2d.pipe.hw.ExtendedBufferCapabilities; +import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*; import sun.awt.RequestFocusController; +import sun.java2d.SunGraphicsEnvironment; /** * A <em>component</em> is an object having a graphical representation @@ -3522,6 +3526,11 @@ public abstract class Component implements ImageObserver, MenuContainer, if (numBuffers == 1) { bufferStrategy = new SingleBufferStrategy(caps); } else { + SunGraphicsEnvironment sge = (SunGraphicsEnvironment) + GraphicsEnvironment.getLocalGraphicsEnvironment(); + if (!caps.isPageFlipping() && sge.isFlipStrategyPreferred(peer)) { + caps = new ProxyCapabilities(caps); + } // assert numBuffers > 1; if (caps.isPageFlipping()) { bufferStrategy = new FlipSubRegionBufferStrategy(numBuffers, caps); @@ -3532,6 +3541,25 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * This is a proxy capabilities class used when a FlipBufferStrategy + * is created instead of the requested Blit strategy. + * + * @see sun.awt.SunGraphicsEnvironment#isFlipStrategyPreferred(ComponentPeer) + */ + private class ProxyCapabilities extends ExtendedBufferCapabilities { + private BufferCapabilities orig; + private ProxyCapabilities(BufferCapabilities orig) { + super(orig.getFrontBufferCapabilities(), + orig.getBackBufferCapabilities(), + orig.getFlipContents() == + BufferCapabilities.FlipContents.BACKGROUND ? + BufferCapabilities.FlipContents.BACKGROUND : + BufferCapabilities.FlipContents.COPIED); + this.orig = orig; + } + } + + /** * @return the buffer strategy used by this component * @see Window#createBufferStrategy * @see Canvas#createBufferStrategy @@ -3660,16 +3688,30 @@ public abstract class Component implements ImageObserver, MenuContainer, width = getWidth(); height = getHeight(); - if (drawBuffer == null) { - peer.createBuffers(numBuffers, caps); - } else { + if (drawBuffer != null) { // dispose the existing backbuffers drawBuffer = null; drawVBuffer = null; destroyBuffers(); // ... then recreate the backbuffers - peer.createBuffers(numBuffers, caps); } + + if (caps instanceof ExtendedBufferCapabilities) { + ExtendedBufferCapabilities ebc = + (ExtendedBufferCapabilities)caps; + if (ebc.getVSync() == VSYNC_ON) { + // if this buffer strategy is not allowed to be v-synced, + // change the caps that we pass to the peer but keep on + // trying to create v-synced buffers; + // do not throw IAE here in case it is disallowed, see + // ExtendedBufferCapabilities for more info + if (!VSyncedBSManager.vsyncAllowed(this)) { + caps = ebc.derive(VSYNC_DEFAULT); + } + } + } + + peer.createBuffers(numBuffers, caps); updateInternalBuffers(); } @@ -3714,7 +3756,23 @@ public abstract class Component implements ImageObserver, MenuContainer, */ protected void flip(BufferCapabilities.FlipContents flipAction) { if (peer != null) { - peer.flip(flipAction); + Image backBuffer = getBackBuffer(); + if (backBuffer != null) { + peer.flip(0, 0, + backBuffer.getWidth(null), + backBuffer.getHeight(null), flipAction); + } + } else { + throw new IllegalStateException( + "Component must have a valid peer"); + } + } + + void flipSubRegion(int x1, int y1, int x2, int y2, + BufferCapabilities.FlipContents flipAction) + { + if (peer != null) { + peer.flip(x1, y1, x2, y2, flipAction); } else { throw new IllegalStateException( "Component must have a valid peer"); @@ -3725,6 +3783,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * Destroys the buffers created through this object */ protected void destroyBuffers() { + VSyncedBSManager.releaseVsync(this); if (peer != null) { peer.destroyBuffers(); } else { @@ -3737,7 +3796,11 @@ public abstract class Component implements ImageObserver, MenuContainer, * @return the buffering capabilities of this strategy */ public BufferCapabilities getCapabilities() { - return caps; + if (caps instanceof ProxyCapabilities) { + return ((ProxyCapabilities)caps).orig; + } else { + return caps; + } } /** @@ -3825,6 +3888,14 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * Makes specified region of the the next available buffer visible + * by either blitting or flipping. + */ + void showSubRegion(int x1, int y1, int x2, int y2) { + flipSubRegion(x1, y1, x2, y2, caps.getFlipContents()); + } + + /** * {@inheritDoc} * @since 1.6 */ @@ -4094,8 +4165,6 @@ public abstract class Component implements ImageObserver, MenuContainer, /** * Private class to perform sub-region flipping. - * REMIND: this subclass currently punts on subregions and - * flips the entire buffer. */ private class FlipSubRegionBufferStrategy extends FlipBufferStrategy implements SubRegionShowable @@ -4109,14 +4178,13 @@ public abstract class Component implements ImageObserver, MenuContainer, } public void show(int x1, int y1, int x2, int y2) { - show(); + showSubRegion(x1, y1, x2, y2); } // This is invoked by Swing on the toolkit thread. - public boolean validateAndShow(int x1, int y1, int x2, int y2) { - revalidate(false); - if (!contentsRestored() && !contentsLost()) { - show(); + public boolean showIfNotLost(int x1, int y1, int x2, int y2) { + if (!contentsLost()) { + showSubRegion(x1, y1, x2, y2); return !contentsLost(); } return false; @@ -4144,9 +4212,8 @@ public abstract class Component implements ImageObserver, MenuContainer, } // This method is called by Swing on the toolkit thread. - public boolean validateAndShow(int x1, int y1, int x2, int y2) { - revalidate(false); - if (!contentsRestored() && !contentsLost()) { + public boolean showIfNotLost(int x1, int y1, int x2, int y2) { + if (!contentsLost()) { showSubRegion(x1, y1, x2, y2); return !contentsLost(); } |