Mercurial > hg > icedtea7-forest > jdk
changeset 9162:295b149be8cd
7124552: [macosx] NullPointerException in getBufferStrategy()
7124219: [macosx] Unable to draw images to fullscreen
Reviewed-by: bae, anthony
author | serb |
---|---|
date | Thu, 20 Apr 2017 23:14:57 +0100 |
parents | c0e54420fccf |
children | 6e0226f8b489 |
files | src/macosx/classes/sun/awt/CGraphicsConfig.java src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java src/macosx/classes/sun/lwawt/LWCanvasPeer.java src/macosx/classes/sun/lwawt/LWComponentPeer.java src/macosx/classes/sun/lwawt/LWGraphicsConfig.java src/macosx/classes/sun/lwawt/LWWindowPeer.java src/macosx/classes/sun/lwawt/PlatformWindow.java src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java src/macosx/classes/sun/lwawt/macosx/CPlatformView.java src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java src/macosx/classes/sun/lwawt/macosx/CViewPlatformEmbeddedFrame.java src/share/classes/sun/awt/TextureSizeConstraining.java |
diffstat | 12 files changed, 237 insertions(+), 557 deletions(-) [+] |
line wrap: on
line diff
--- a/src/macosx/classes/sun/awt/CGraphicsConfig.java Thu Apr 20 22:22:02 2017 +0100 +++ b/src/macosx/classes/sun/awt/CGraphicsConfig.java Thu Apr 20 23:14:57 2017 +0100 @@ -31,13 +31,16 @@ import sun.java2d.SurfaceData; import sun.java2d.opengl.CGLLayer; +import sun.lwawt.LWGraphicsConfig; import sun.lwawt.macosx.CPlatformView; -public class CGraphicsConfig extends GraphicsConfiguration { +public abstract class CGraphicsConfig extends GraphicsConfiguration + implements LWGraphicsConfig { + private final CGraphicsDevice device; private ColorModel colorModel; - public CGraphicsConfig(CGraphicsDevice device) { + protected CGraphicsConfig(CGraphicsDevice device) { this.device = device; } @@ -84,88 +87,20 @@ return new AffineTransform(xscale, 0.0, 0.0, yscale, 0.0, 0.0); } - - /** - * The following methods are invoked from CToolkit.java and - * LWWindowPeer.java rather than having the native - * implementations hardcoded in those classes. This way the appropriate - * actions are taken based on the peer's GraphicsConfig, whether it is - * an CGLGraphicsConfig or something else. - */ - /** * Creates a new SurfaceData that will be associated with the given * LWWindowPeer. */ - public SurfaceData createSurfaceData(CPlatformView pView) { - throw new UnsupportedOperationException("not implemented"); - } + public abstract SurfaceData createSurfaceData(CPlatformView pView); /** * Creates a new SurfaceData that will be associated with the given * CGLLayer. */ - public SurfaceData createSurfaceData(CGLLayer layer) { - throw new UnsupportedOperationException("not implemented"); - } - - /** - * Creates a new hidden-acceleration image of the given width and height - * that is associated with the target Component. - */ - public Image createAcceleratedImage(Component target, - int width, int height) - { - throw new UnsupportedOperationException("not implemented"); - } - - /** - * The following methods correspond to the multibuffering methods in - * LWWindowPeer.java... - */ - - /** - * Attempts to create a native backbuffer for the given peer. If - * the requested configuration is not natively supported, an AWTException - * is thrown. Otherwise, if the backbuffer creation is successful, a - * handle to the native backbuffer is returned. - */ - public long createBackBuffer(CPlatformView pView, - int numBuffers, BufferCapabilities caps) - throws AWTException - { - throw new UnsupportedOperationException("not implemented"); - } - - public void destroyBackBuffer(long backBuffer) - throws AWTException - { - throw new UnsupportedOperationException("not implemented"); - } - - /** - * Creates a VolatileImage that essentially wraps the target Component's - * backbuffer, using the provided backbuffer handle. - */ - public VolatileImage createBackBufferImage(Component target, - long backBuffer) - { - throw new UnsupportedOperationException("not implemented"); - } - - /** - * Performs the native flip operation for the given target Component. - */ - public void flip(CPlatformView delegate, - Component target, VolatileImage xBackBuffer, - int x1, int y1, int x2, int y2, - BufferCapabilities.FlipContents flipAction) - { - throw new UnsupportedOperationException("not implemented"); - } + public abstract SurfaceData createSurfaceData(CGLLayer layer); @Override - public boolean isTranslucencyCapable() { + public final boolean isTranslucencyCapable() { //we know for sure we have capable config :) return true; }
--- a/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java Thu Apr 20 22:22:02 2017 +0100 +++ b/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java Thu Apr 20 23:14:57 2017 +0100 @@ -27,7 +27,6 @@ import java.awt.AWTException; import java.awt.BufferCapabilities; -import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import java.awt.Graphics2D; @@ -48,13 +47,10 @@ import sun.awt.CGraphicsConfig; import sun.awt.CGraphicsDevice; -import sun.awt.TextureSizeConstraining; import sun.awt.image.OffScreenImage; import sun.awt.image.SunVolatileImage; -import sun.awt.image.SurfaceManager; import sun.java2d.Disposer; import sun.java2d.DisposerRecord; -import sun.java2d.SunGraphics2D; import sun.java2d.Surface; import sun.java2d.SurfaceData; import sun.java2d.opengl.OGLContext.OGLContextCaps; @@ -63,18 +59,19 @@ import sun.java2d.pipe.hw.ContextCapabilities; import static sun.java2d.opengl.OGLSurfaceData.*; import static sun.java2d.opengl.OGLContext.OGLContextCaps.*; -import sun.java2d.opengl.CGLSurfaceData.CGLVSyncOffScreenSurfaceData; import sun.java2d.pipe.hw.AccelDeviceEventListener; import sun.java2d.pipe.hw.AccelDeviceEventNotifier; +import sun.lwawt.LWComponentPeer; import sun.lwawt.macosx.CPlatformView; -public class CGLGraphicsConfig extends CGraphicsConfig - implements OGLGraphicsConfig, TextureSizeConstraining +public final class CGLGraphicsConfig extends CGraphicsConfig + implements OGLGraphicsConfig { - //private static final int kOpenGLSwapInterval = RuntimeOptions.getCurrentOptions().OpenGLSwapInterval; + //private static final int kOpenGLSwapInterval = + // RuntimeOptions.getCurrentOptions().OpenGLSwapInterval; private static final int kOpenGLSwapInterval = 0; // TODO - protected static boolean cglAvailable; + private static boolean cglAvailable; private static ImageCapabilities imageCaps = new CGLImageCaps(); private int pixfmt; @@ -82,7 +79,7 @@ private long pConfigInfo; private ContextCapabilities oglCaps; private OGLContext context; - private Object disposerReferent = new Object(); + private final Object disposerReferent = new Object(); private final int cachedMaxTextureSize; private static native boolean initCGL(); @@ -95,7 +92,7 @@ cglAvailable = initCGL(); } - protected CGLGraphicsConfig(CGraphicsDevice device, int pixfmt, + private CGLGraphicsConfig(CGraphicsDevice device, int pixfmt, long configInfo, ContextCapabilities oglCaps) { super(device); @@ -176,11 +173,13 @@ * Returns true if the provided capability bit is present for this config. * See OGLContext.java for a list of supported capabilities. */ - public final boolean isCapPresent(int cap) { + @Override + public boolean isCapPresent(int cap) { return ((oglCaps.getCaps() & cap) != 0); } - public final long getNativeConfigInfo() { + @Override + public long getNativeConfigInfo() { return pConfigInfo; } @@ -189,7 +188,8 @@ * * @see sun.java2d.pipe.hw.BufferedContextProvider#getContext */ - public final OGLContext getContext() { + @Override + public OGLContext getContext() { return context; } @@ -263,145 +263,83 @@ return ("CGLGraphicsConfig[dev="+displayID+",pixfmt="+pixfmt+"]"); } - - /** - * The following methods are invoked from ComponentModel.java rather - * than having the Mac OS X-dependent implementations hardcoded in that - * class. This way the appropriate actions are taken based on the peer's - * GraphicsConfig, whether it is a CGraphicsConfig or a - * CGLGraphicsConfig. - */ - - /** - * Creates a new SurfaceData that will be associated with the given - * LWWindowPeer. - */ @Override public SurfaceData createSurfaceData(CPlatformView pView) { return CGLSurfaceData.createData(pView); } - /** - * Creates a new SurfaceData that will be associated with the given - * CGLLayer. - */ @Override public SurfaceData createSurfaceData(CGLLayer layer) { return CGLSurfaceData.createData(layer); } - /** - * Creates a new hidden-acceleration image of the given width and height - * that is associated with the target Component. - */ @Override public Image createAcceleratedImage(Component target, int width, int height) { ColorModel model = getColorModel(Transparency.OPAQUE); - WritableRaster wr = - model.createCompatibleWritableRaster(width, height); + WritableRaster wr = model.createCompatibleWritableRaster(width, height); return new OffScreenImage(target, model, wr, model.isAlphaPremultiplied()); } - /** - * The following methods correspond to the multibuffering methods in - * CWindowPeer.java... - */ - - /** - * Attempts to create a OGL-based backbuffer for the given peer. If - * the requested configuration is not natively supported, an AWTException - * is thrown. Otherwise, if the backbuffer creation is successful, a - * value of 1 is returned. - */ @Override - public long createBackBuffer(CPlatformView pView, - int numBuffers, BufferCapabilities caps) - throws AWTException - { - if (numBuffers > 2) { - throw new AWTException( - "Only double or single buffering is supported"); + public void assertOperationSupported(final int numBuffers, + final BufferCapabilities caps) + throws AWTException { + // Assume this method is never called with numBuffers != 2, as 0 is + // unsupported, and 1 corresponds to a SingleBufferStrategy which + // doesn't depend on the peer. Screen is considered as a separate + // "buffer". + if (numBuffers != 2) { + throw new AWTException("Only double buffering is supported"); } - BufferCapabilities configCaps = getBufferCapabilities(); + final BufferCapabilities configCaps = getBufferCapabilities(); if (!configCaps.isPageFlipping()) { throw new AWTException("Page flipping is not supported"); } if (caps.getFlipContents() == BufferCapabilities.FlipContents.PRIOR) { throw new AWTException("FlipContents.PRIOR is not supported"); } - - // non-zero return value means backbuffer creation was successful - // (checked in CPlatformWindow.flip(), etc.) - return 1; } - /** - * Destroys the backbuffer object represented by the given handle value. - */ @Override - public void destroyBackBuffer(long backBuffer) { - } - - /** - * Creates a VolatileImage that essentially wraps the target Component's - * backbuffer (the provided backbuffer handle is essentially ignored). - */ - @Override - public VolatileImage createBackBufferImage(Component target, - long backBuffer) - { - return new SunVolatileImage(target, - target.getWidth(), target.getHeight(), - Boolean.TRUE); + public Image createBackBuffer(final LWComponentPeer<?, ?> peer) { + final Rectangle r = peer.getBounds(); + // It is possible for the component to have size 0x0, adjust it to + // be at least 1x1 to avoid IAE + final int w = Math.max(1, r.width); + final int h = Math.max(1, r.height); + final int transparency = peer.isTranslucent() ? Transparency.TRANSLUCENT + : Transparency.OPAQUE; + return new SunVolatileImage(this, w, h, transparency, null); } - /** - * Performs the native OGL flip operation for the given target Component. - */ @Override - public void flip(CPlatformView pView, - Component target, VolatileImage xBackBuffer, - int x1, int y1, int x2, int y2, - BufferCapabilities.FlipContents flipAction) - { - if (flipAction == BufferCapabilities.FlipContents.COPIED) { - SurfaceManager vsm = SurfaceManager.getManager(xBackBuffer); - SurfaceData sd = vsm.getPrimarySurfaceData(); + public void destroyBackBuffer(final Image backBuffer) { + if (backBuffer != null) { + backBuffer.flush(); + } + } - if (sd instanceof CGLVSyncOffScreenSurfaceData) { - CGLVSyncOffScreenSurfaceData vsd = - (CGLVSyncOffScreenSurfaceData)sd; - SurfaceData bbsd = vsd.getFlipSurface(); - Graphics2D bbg = - new SunGraphics2D(bbsd, Color.black, Color.white, null); - try { - bbg.drawImage(xBackBuffer, 0, 0, null); - } finally { - bbg.dispose(); - } - } else { - pView.drawImageOnPeer(xBackBuffer, x1, y1, x2, y2); - return; - } - } else if (flipAction == BufferCapabilities.FlipContents.PRIOR) { - // not supported by CGL... - return; + @Override + public void flip(final LWComponentPeer<?, ?> peer, final Image backBuffer, + final int x1, final int y1, final int x2, final int y2, + final BufferCapabilities.FlipContents flipAction) { + final Graphics g = peer.getGraphics(); + try { + g.drawImage(backBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null); + } finally { + g.dispose(); } - - OGLSurfaceData.swapBuffers(pView.getAWTView()); - if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) { - Graphics g = xBackBuffer.getGraphics(); + final Graphics2D bg = (Graphics2D) backBuffer.getGraphics(); try { - g.setColor(target.getBackground()); - g.fillRect(0, 0, - xBackBuffer.getWidth(), - xBackBuffer.getHeight()); + bg.setBackground(peer.getBackground()); + bg.clearRect(0, 0, backBuffer.getWidth(null), + backBuffer.getHeight(null)); } finally { - g.dispose(); + bg.dispose(); } } } @@ -435,15 +373,10 @@ return imageCaps; } - /** - * {@inheritDoc} - * - * @see sun.java2d.pipe.hw.AccelGraphicsConfig#createCompatibleVolatileImage - */ - public VolatileImage - createCompatibleVolatileImage(int width, int height, - int transparency, int type) - { + @Override + public VolatileImage createCompatibleVolatileImage(int width, int height, + int transparency, + int type) { if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED || transparency == Transparency.BITMASK) { @@ -479,15 +412,18 @@ * * @see sun.java2d.pipe.hw.AccelGraphicsConfig#getContextCapabilities */ + @Override public ContextCapabilities getContextCapabilities() { return oglCaps; } + @Override public void addDeviceEventListener(AccelDeviceEventListener l) { int displayID = getDevice().getCGDisplayID(); AccelDeviceEventNotifier.addListener(l, displayID); } + @Override public void removeDeviceEventListener(AccelDeviceEventListener l) { AccelDeviceEventNotifier.removeListener(l); }
--- a/src/macosx/classes/sun/lwawt/LWCanvasPeer.java Thu Apr 20 22:22:02 2017 +0100 +++ b/src/macosx/classes/sun/lwawt/LWCanvasPeer.java Thu Apr 20 23:14:57 2017 +0100 @@ -26,18 +26,9 @@ package sun.lwawt; -import sun.awt.CGraphicsConfig; - -import java.awt.AWTException; -import java.awt.BufferCapabilities; -import java.awt.BufferCapabilities.FlipContents; import java.awt.Component; import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; -import java.awt.Image; -import java.awt.image.VolatileImage; import java.awt.peer.CanvasPeer; import javax.swing.JComponent; @@ -49,74 +40,13 @@ class LWCanvasPeer<T extends Component, D extends JComponent> extends LWComponentPeer<T, D> implements CanvasPeer { - /** - * The back buffer provide user with a BufferStrategy. - */ - private VolatileImage backBuffer; - LWCanvasPeer(final T target, final PlatformComponent platformComponent) { super(target, platformComponent); } @Override - public void createBuffers(int numBuffers, BufferCapabilities caps) - throws AWTException { - //TODO parameters should be used. - final CGraphicsConfig gc = (CGraphicsConfig) getGraphicsConfiguration(); - final VolatileImage buffer = gc.createBackBufferImage(getTarget(), 0); - synchronized (getStateLock()) { - backBuffer = buffer; - } - } - - @Override - public Image getBackBuffer() { - synchronized (getStateLock()) { - return backBuffer; - } - } - - @Override - public void flip(final int x1, final int y1, final int x2, final int y2, - final FlipContents flipAction) { - final VolatileImage buffer = (VolatileImage) getBackBuffer(); - if (buffer == null) { - throw new IllegalStateException("Buffers have not been created"); - } - final Graphics g = getGraphics(); - try { - g.drawImage(buffer, x1, y1, x2, y2, x1, y1, x2, y2, null); - } finally { - g.dispose(); - } - if (flipAction == FlipContents.BACKGROUND) { - final Graphics2D bg = (Graphics2D) buffer.getGraphics(); - try { - bg.setBackground(getBackground()); - bg.clearRect(0, 0, buffer.getWidth(), buffer.getHeight()); - } finally { - bg.dispose(); - } - } - } - - @Override - public void destroyBuffers() { - final Image buffer = getBackBuffer(); - if (buffer != null) { - synchronized (getStateLock()) { - if (buffer == backBuffer) { - backBuffer = null; - } - } - buffer.flush(); - } - } - - @Override public final GraphicsConfiguration getAppropriateGraphicsConfiguration( - GraphicsConfiguration gc) - { + final GraphicsConfiguration gc) { // TODO return gc; }
--- a/src/macosx/classes/sun/lwawt/LWComponentPeer.java Thu Apr 20 22:22:02 2017 +0100 +++ b/src/macosx/classes/sun/lwawt/LWComponentPeer.java Thu Apr 20 23:14:57 2017 +0100 @@ -143,6 +143,11 @@ static final char WIDE_CHAR = '0'; /** + * The back buffer provide user with a BufferStrategy. + */ + private Image backBuffer; + + /** * All Swing delegates use delegateContainer as a parent. This container * intentionally do not use parent of the peer. */ @@ -405,6 +410,7 @@ } protected void disposeImpl() { + destroyBuffers(); LWContainerPeer<?, ?> cp = getContainerPeer(); if (cp != null) { cp.removeChildPeer(this); @@ -431,6 +437,12 @@ return getWindowPeer().getGraphicsConfiguration(); } + + // Just a helper method + public final LWGraphicsConfig getLWGC() { + return (LWGraphicsConfig) getGraphicsConfiguration(); + } + /* * Overridden in LWWindowPeer to replace its surface * data and back buffer. @@ -496,31 +508,45 @@ return getGraphicsConfiguration().getColorModel(); } - @Override - public void createBuffers(int numBuffers, BufferCapabilities caps) - throws AWTException { - throw new AWTException("Back buffers are only supported for " + - "Window or Canvas components."); + public boolean isTranslucent() { + // Translucent windows of the top level are supported only + return false; } - /* - * To be overridden in LWWindowPeer and LWCanvasPeer. - */ @Override - public Image getBackBuffer() { - // Return null or throw AWTException? - return null; + public final void createBuffers(int numBuffers, BufferCapabilities caps) + throws AWTException { + getLWGC().assertOperationSupported(numBuffers, caps); + final Image buffer = getLWGC().createBackBuffer(this); + synchronized (getStateLock()) { + backBuffer = buffer; + } } @Override - public void flip(int x1, int y1, int x2, int y2, - BufferCapabilities.FlipContents flipAction) { - // Skip silently or throw AWTException? + public final Image getBackBuffer() { + synchronized (getStateLock()) { + if (backBuffer != null) { + return backBuffer; + } + } + throw new IllegalStateException("Buffers have not been created"); } @Override - public void destroyBuffers() { - // Do nothing + public final void flip(int x1, int y1, int x2, int y2, + BufferCapabilities.FlipContents flipAction) { + getLWGC().flip(this, getBackBuffer(), x1, y1, x2, y2, flipAction); + } + + @Override + public final void destroyBuffers() { + final Image oldBB; + synchronized (getStateLock()) { + oldBB = backBuffer; + backBuffer = null; + } + getLWGC().destroyBackBuffer(oldBB); } // Helper method @@ -974,19 +1000,17 @@ } @Override - public Image createImage(ImageProducer producer) { + public final Image createImage(final ImageProducer producer) { return new ToolkitImage(producer); } @Override - public Image createImage(int w, int h) { - CGraphicsConfig gc = (CGraphicsConfig)getGraphicsConfiguration(); - return gc.createAcceleratedImage(getTarget(), w, h); + public final Image createImage(final int width, final int height) { + return getLWGC().createAcceleratedImage(getTarget(), width, height); } @Override - public VolatileImage createVolatileImage(int w, int h) { - // TODO: is it a right/complete implementation? + public final VolatileImage createVolatileImage(final int w, final int h) { return new SunVolatileImage(getTarget(), w, h); } @@ -1097,8 +1121,6 @@ * of target.setLocation() or as a result of user actions (window is * dragged with mouse). * - * To be overridden in LWWindowPeer to update its GraphicsConfig. - * * This method could be called on the toolkit thread. */ protected final void handleMove(final int x, final int y, @@ -1114,13 +1136,19 @@ * Called when this peer's size has been changed either as a result of * target.setSize() or as a result of user actions (window is resized). * - * To be overridden in LWWindowPeer to update its SurfaceData and - * GraphicsConfig. - * * This method could be called on the toolkit thread. */ protected final void handleResize(final int w, final int h, final boolean updateTarget) { + Image oldBB = null; + synchronized (getStateLock()) { + if (backBuffer != null) { + oldBB = backBuffer; + backBuffer = getLWGC().createBackBuffer(this); + } + } + getLWGC().destroyBackBuffer(oldBB); + if (updateTarget) { AWTAccessor.getComponentAccessor().setSize(getTarget(), w, h); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/macosx/classes/sun/lwawt/LWGraphicsConfig.java Thu Apr 20 23:14:57 2017 +0100 @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package sun.lwawt; + +import java.awt.AWTException; +import java.awt.BufferCapabilities; +import java.awt.Component; +import java.awt.Image; + +/** + * As lwawt can be used on different platforms with different graphic + * configurations, the general set of methods is necessary. This interface + * collects the methods that should be provided by GraphicsConfiguration, + * simplifying use by the LWAWT. + * + * @author Sergey Bylokhov + */ +public interface LWGraphicsConfig { + + /* + * A GraphicsConfiguration must implements following methods to indicate + * that it imposes certain limitations on the maximum size of supported + * textures. + */ + + /** + * Returns the maximum width of any texture image. By default return {@code + * Integer.MAX_VALUE}. + */ + int getMaxTextureWidth(); + + /** + * Returns the maximum height of any texture image. By default return {@code + * Integer.MAX_VALUE}. + */ + int getMaxTextureHeight(); + + /* + * The following methods correspond to the multi-buffering methods in + * LWComponentPeer.java. + */ + + /** + * Checks that the requested configuration is natively supported; if not, an + * AWTException is thrown. + */ + void assertOperationSupported(int numBuffers, BufferCapabilities caps) + throws AWTException; + + /** + * Creates a back buffer for the given peer and returns the image wrapper. + */ + Image createBackBuffer(LWComponentPeer<?, ?> peer); + + /** + * Destroys the back buffer object. + */ + void destroyBackBuffer(Image backBuffer); + + /** + * Performs the native flip operation for the given target Component. Our + * flip is implemented through normal drawImage() to the graphic object, + * because of our components uses a graphic object of the container(in this + * case we also apply necessary constrains) + */ + void flip(LWComponentPeer<?, ?> peer, Image backBuffer, int x1, int y1, + int x2, int y2, BufferCapabilities.FlipContents flipAction); + + /** + * Creates a new hidden-acceleration image of the given width and height + * that is associated with the target Component. + */ + Image createAcceleratedImage(Component target, int width, int height); +}
--- a/src/macosx/classes/sun/lwawt/LWWindowPeer.java Thu Apr 20 22:22:02 2017 +0100 +++ b/src/macosx/classes/sun/lwawt/LWWindowPeer.java Thu Apr 20 23:14:57 2017 +0100 @@ -27,7 +27,6 @@ import java.awt.*; import java.awt.event.*; -import java.awt.image.BufferedImage; import java.awt.peer.*; import java.util.List; @@ -76,17 +75,6 @@ private SurfaceData surfaceData; private final Object surfaceDataLock = new Object(); - private int backBufferCount; - private BufferCapabilities backBufferCaps; - - // The back buffer is used for two purposes: - // 1. To render all the lightweight peers - // 2. To provide user with a BufferStrategy - // Need to check if a single back buffer can be used for both -// TODO: VolatileImage -// private VolatileImage backBuffer; - private volatile BufferedImage backBuffer; - private volatile int windowState = Frame.NORMAL; // check that the mouse is over the window @@ -252,7 +240,6 @@ if (warningWindow != null) { warningWindow.dispose(); } - destroyBuffers(); platformWindow.dispose(); super.disposeImpl(); } @@ -286,8 +273,10 @@ } @Override - public GraphicsConfiguration getGraphicsConfiguration() { - return graphicsConfig; + public final GraphicsConfiguration getGraphicsConfiguration() { + synchronized (getStateLock()) { + return graphicsConfig; + } } @Override @@ -313,66 +302,6 @@ } @Override - public void createBuffers(int numBuffers, BufferCapabilities caps) - throws AWTException - { - try { - // Assume this method is never called with numBuffers <= 1, as 0 is - // unsupported, and 1 corresponds to a SingleBufferStrategy which - // doesn't depend on the peer. Screen is considered as a separate - // "buffer", that's why numBuffers - 1 - assert numBuffers > 1; - - replaceSurfaceData(numBuffers - 1, caps, false); - } catch (InvalidPipeException z) { - throw new AWTException(z.toString()); - } - } - - @Override - public final Image getBackBuffer() { - synchronized (getStateLock()) { - return backBuffer; - } - } - - @Override - public void flip(int x1, int y1, int x2, int y2, - BufferCapabilities.FlipContents flipAction) - { - final BufferedImage buffer = (BufferedImage)getBackBuffer(); - if (buffer == null) { - throw new IllegalStateException("Buffers have not been created"); - } - final Graphics g = getGraphics(); - try { - g.drawImage(buffer, x1, y1, x2, y2, x1, y1, x2, y2, null); - } finally { - g.dispose(); - } - if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) { - final Graphics2D bg = (Graphics2D) buffer.getGraphics(); - try { - bg.setBackground(getBackground()); - bg.clearRect(0, 0, buffer.getWidth(), buffer.getHeight()); - } finally { - bg.dispose(); - } - } - } - - @Override - public final void destroyBuffers() { - final Image oldBB = getBackBuffer(); - synchronized (getStateLock()) { - backBuffer = null; - } - if (oldBB != null) { - oldBB.flush(); - } - } - - @Override public void setBounds(int x, int y, int w, int h, int op) { if((op & NO_EMBEDDED_CHECK) == 0 && getPeerType() == PeerType.VIEW_EMBEDDED_FRAME) { @@ -410,16 +339,14 @@ h = MINIMUM_HEIGHT; } - if (graphicsConfig instanceof TextureSizeConstraining) { - final int maxW = ((TextureSizeConstraining)graphicsConfig).getMaxTextureWidth(); - final int maxH = ((TextureSizeConstraining)graphicsConfig).getMaxTextureHeight(); + final int maxW = getLWGC().getMaxTextureWidth(); + final int maxH = getLWGC().getMaxTextureHeight(); - if (w > maxW) { - w = maxW; - } - if (h > maxH) { - h = maxH; - } + if (w > maxW) { + w = maxW; + } + if (h > maxH) { + h = maxH; } return new Rectangle(x, y, w, h); @@ -497,21 +424,14 @@ min = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT); } - final int maxW, maxH; - if (graphicsConfig instanceof TextureSizeConstraining) { - maxW = ((TextureSizeConstraining)graphicsConfig).getMaxTextureWidth(); - maxH = ((TextureSizeConstraining)graphicsConfig).getMaxTextureHeight(); - } else { - maxW = maxH = Integer.MAX_VALUE; - } - final Dimension max; if (getTarget().isMaximumSizeSet()) { max = getTarget().getMaximumSize(); - max.width = Math.min(max.width, maxW); - max.height = Math.min(max.height, maxH); + max.width = Math.min(max.width, getLWGC().getMaxTextureWidth()); + max.height = Math.min(max.height, getLWGC().getMaxTextureHeight()); } else { - max = new Dimension(maxW, maxH); + max = new Dimension(getLWGC().getMaxTextureWidth(), + getLWGC().getMaxTextureHeight()); } platformWindow.setSizeConstraints(min.width, min.height, max.width, max.height); @@ -1139,21 +1059,10 @@ replaceSurfaceData(true); } - private void replaceSurfaceData(boolean blit) { - replaceSurfaceData(backBufferCount, backBufferCaps, blit); - } - - private void replaceSurfaceData(int newBackBufferCount, - BufferCapabilities newBackBufferCaps, - boolean blit) { + private void replaceSurfaceData(final boolean blit) { synchronized (surfaceDataLock) { final SurfaceData oldData = getSurfaceData(); surfaceData = platformWindow.replaceSurfaceData(); - // TODO: volatile image - // VolatileImage oldBB = backBuffer; - BufferedImage oldBB = backBuffer; - backBufferCount = newBackBufferCount; - backBufferCaps = newBackBufferCaps; final Rectangle size = getSize(); if (getSurfaceData() != null && oldData != getSurfaceData()) { clearBackground(size.width, size.height); @@ -1168,35 +1077,6 @@ // This can only happen when this peer is being created oldData.flush(); } - - // TODO: volatile image - // backBuffer = (VolatileImage)delegate.createBackBuffer(); - backBuffer = (BufferedImage) platformWindow.createBackBuffer(); - if (backBuffer != null) { - Graphics g = backBuffer.getGraphics(); - try { - Rectangle r = getBounds(); - if (g instanceof Graphics2D) { - ((Graphics2D) g).setComposite(AlphaComposite.Src); - } - g.setColor(nonOpaqueBackground); - g.fillRect(0, 0, r.width, r.height); - if (g instanceof SunGraphics2D) { - ((SunGraphics2D) g).constrain(0, 0, r.width, r.height, getRegion()); - } - if (!isTextured()) { - g.setColor(getBackground()); - g.fillRect(0, 0, r.width, r.height); - } - if (oldBB != null) { - // Draw the old back buffer to the new one - g.drawImage(oldBB, 0, 0, null); - oldBB.flush(); - } - } finally { - g.dispose(); - } - } } flushOnscreenGraphics(); } @@ -1219,14 +1099,6 @@ } } - public int getBackBufferCount() { - return backBufferCount; - } - - public BufferCapabilities getBackBufferCaps() { - return backBufferCaps; - } - /** * Request the window insets from the delegate and compares it with the * current one. This method is mostly called by the delegate, e.g. when the
--- a/src/macosx/classes/sun/lwawt/PlatformWindow.java Thu Apr 20 22:22:02 2017 +0100 +++ b/src/macosx/classes/sun/lwawt/PlatformWindow.java Thu Apr 20 23:14:57 2017 +0100 @@ -97,17 +97,6 @@ */ public SurfaceData replaceSurfaceData(); - /* - * Creates a new image to serve as a back buffer. - */ - public Image createBackBuffer(); - - /* - * Move the given part of the back buffer to the front buffer. - */ - public void flip(int x1, int y1, int x2, int y2, - BufferCapabilities.FlipContents flipAction); - public void setModalBlocked(boolean blocked); public void toFront();
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java Thu Apr 20 22:22:02 2017 +0100 +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java Thu Apr 20 23:14:57 2017 +0100 @@ -31,12 +31,9 @@ import sun.java2d.opengl.CGLLayer; import sun.java2d.SurfaceData; -import sun.awt.CGraphicsConfig; -import sun.awt.CGraphicsDevice; import sun.awt.CausedFocusEvent; import java.awt.*; -import java.awt.BufferCapabilities.FlipContents; import sun.util.logging.PlatformLogger; @@ -113,22 +110,6 @@ } @Override - public Image createBackBuffer() { - Rectangle r = peer.getBounds(); - Image im = null; - if (!r.isEmpty()) { - int transparency = peer.isTranslucent() ? Transparency.TRANSLUCENT : Transparency.OPAQUE; - im = peer.getGraphicsConfiguration().createCompatibleImage(r.width, r.height, transparency); - } - return im; - } - - @Override - public void flip(int x1, int y1, int x2, int y2, FlipContents flipAction) { - throw new RuntimeException("Not implemented"); - } - - @Override public void setVisible(boolean visible) {} @Override
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java Thu Apr 20 22:22:02 2017 +0100 +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java Thu Apr 20 23:14:57 2017 +0100 @@ -28,7 +28,6 @@ import java.awt.*; import java.awt.event.*; import java.awt.geom.Rectangle2D; -import java.awt.image.VolatileImage; import sun.awt.CGraphicsConfig; import sun.awt.CGraphicsEnvironment; @@ -100,26 +99,6 @@ // ---------------------------------------------------------------------- // PAINTING METHODS // ---------------------------------------------------------------------- - - public void drawImageOnPeer(VolatileImage xBackBuffer, int x1, int y1, int x2, int y2) { - Graphics g = peer.getGraphics(); - try { - g.drawImage(xBackBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null); - } finally { - g.dispose(); - } - } - - public Image createBackBuffer() { - Rectangle r = getBounds(); - Image im = null; - if (!r.isEmpty()) { - int transparency = (isOpaque() ? Transparency.OPAQUE : Transparency.TRANSLUCENT); - im = getGraphicsConfiguration().createCompatibleImage(r.width, r.height, transparency); - } - return im; - } - public SurfaceData replaceSurfaceData() { if (!LWCToolkit.getSunAwtDisableCALayers()) { surfaceData = windowLayer.replaceSurfaceData();
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Thu Apr 20 22:22:02 2017 +0100 +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Thu Apr 20 23:14:57 2017 +0100 @@ -25,7 +25,6 @@ package sun.lwawt.macosx; -import java.awt.BufferCapabilities.FlipContents; import java.awt.*; import java.awt.Dialog.ModalityType; import java.awt.event.*; @@ -431,11 +430,6 @@ } @Override // PlatformWindow - public Image createBackBuffer() { - return contentView.createBackBuffer(); - } - - @Override // PlatformWindow public void dispose() { if (owner != null) { CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), getNSWindowPtr()); @@ -446,12 +440,6 @@ } @Override // PlatformWindow - public void flip(int x1, int y1, int x2, int y2, FlipContents flipAction) { - // TODO: not implemented - (new RuntimeException("unimplemented")).printStackTrace(); - } - - @Override // PlatformWindow public FontMetrics getFontMetrics(Font f) { // TODO: not implemented (new RuntimeException("unimplemented")).printStackTrace();
--- a/src/macosx/classes/sun/lwawt/macosx/CViewPlatformEmbeddedFrame.java Thu Apr 20 22:22:02 2017 +0100 +++ b/src/macosx/classes/sun/lwawt/macosx/CViewPlatformEmbeddedFrame.java Thu Apr 20 23:14:57 2017 +0100 @@ -212,14 +212,4 @@ public boolean isUnderMouse() { return view.isUnderMouse(); } - - @Override - public Image createBackBuffer() { - return view.createBackBuffer(); - } - - @Override - public void flip(int x1, int y1, int x2, int y2, FlipContents flipAction) { - throw new RuntimeException("Not implemented"); - } }
--- a/src/share/classes/sun/awt/TextureSizeConstraining.java Thu Apr 20 22:22:02 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code 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 General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package sun.awt; - -/** - * A GraphicsConfiguration implements the TextureSizeConstraining - * interface to indicate that it imposes certain limitations on the - * maximum size of supported textures. - */ -public interface TextureSizeConstraining { - - /** - * Returns the maximum width of any texture image. - */ - public int getMaxTextureWidth(); - - /** - * Returns the maximum height of any texture image. - */ - public int getMaxTextureHeight(); - -}