7124552: [macosx] NullPointerException in getBufferStrategy()
authorserb
Wed, 21 Nov 2012 15:50:34 +0400
changeset 14647 bacc2d4f4b27
parent 14499 3f36647a27f4
child 14648 2ef7c7edb4b0
7124552: [macosx] NullPointerException in getBufferStrategy() 7124219: [macosx] Unable to draw images to fullscreen Reviewed-by: bae, anthony
jdk/src/macosx/classes/sun/awt/CGraphicsConfig.java
jdk/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java
jdk/src/macosx/classes/sun/lwawt/LWCanvasPeer.java
jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java
jdk/src/macosx/classes/sun/lwawt/LWGraphicsConfig.java
jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java
jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java
jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java
jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java
jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
jdk/src/share/classes/sun/awt/TextureSizeConstraining.java
--- a/jdk/src/macosx/classes/sun/awt/CGraphicsConfig.java	Tue Nov 20 18:56:01 2012 +0400
+++ b/jdk/src/macosx/classes/sun/awt/CGraphicsConfig.java	Wed Nov 21 15:50:34 2012 +0400
@@ -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/jdk/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java	Tue Nov 20 18:56:01 2012 +0400
+++ b/jdk/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java	Wed Nov 21 15:50:34 2012 +0400
@@ -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();
 
     public static native int getDefaultPixFmt(int screennum);
     private static native boolean initCGL();
@@ -94,7 +91,7 @@
         cglAvailable = initCGL();
     }
 
-    protected CGLGraphicsConfig(CGraphicsDevice device, int pixfmt,
+    private CGLGraphicsConfig(CGraphicsDevice device, int pixfmt,
                                 long configInfo, ContextCapabilities oglCaps)
     {
         super(device);
@@ -170,11 +167,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;
     }
 
@@ -183,7 +182,8 @@
      *
      * @see sun.java2d.pipe.hw.BufferedContextProvider#getContext
      */
-    public final OGLContext getContext() {
+    @Override
+    public OGLContext getContext() {
         return context;
     }
 
@@ -257,145 +257,83 @@
         return ("CGLGraphicsConfig[dev="+screen+",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();
             }
         }
     }
@@ -429,15 +367,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)
         {
@@ -473,15 +406,18 @@
      *
      * @see sun.java2d.pipe.hw.AccelGraphicsConfig#getContextCapabilities
      */
+    @Override
     public ContextCapabilities getContextCapabilities() {
         return oglCaps;
     }
 
+    @Override
     public void addDeviceEventListener(AccelDeviceEventListener l) {
         int screen = getDevice().getCoreGraphicsScreen();
         AccelDeviceEventNotifier.addListener(l, screen);
     }
 
+    @Override
     public void removeDeviceEventListener(AccelDeviceEventListener l) {
         AccelDeviceEventNotifier.removeListener(l);
     }
--- a/jdk/src/macosx/classes/sun/lwawt/LWCanvasPeer.java	Tue Nov 20 18:56:01 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWCanvasPeer.java	Wed Nov 21 15:50:34 2012 +0400
@@ -26,12 +26,9 @@
 
 package sun.lwawt;
 
-import java.awt.AWTException;
-import java.awt.BufferCapabilities;
 import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.GraphicsConfiguration;
-import java.awt.Image;
 import java.awt.peer.CanvasPeer;
 
 import javax.swing.JComponent;
@@ -42,35 +39,10 @@
     LWCanvasPeer(final T target, final PlatformComponent platformComponent) {
         super(target, platformComponent);
     }
-    // ---- PEER METHODS ---- //
-
-    @Override
-    public void createBuffers(int numBuffers, BufferCapabilities caps)
-            throws AWTException {
-        // TODO
-    }
-
-    @Override
-    public Image getBackBuffer() {
-        // TODO
-        return null;
-    }
-
-    @Override
-    public void flip(int x1, int y1, int x2, int y2,
-                     BufferCapabilities.FlipContents flipAction) {
-        // TODO
-    }
-
-    @Override
-    public void destroyBuffers() {
-        // TODO
-    }
 
     @Override
     public final GraphicsConfiguration getAppropriateGraphicsConfiguration(
-            GraphicsConfiguration gc)
-    {
+            final GraphicsConfiguration gc) {
         // TODO
         return gc;
     }
--- a/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java	Tue Nov 20 18:56:01 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java	Wed Nov 21 15:50:34 2012 +0400
@@ -138,6 +138,11 @@
      */
     static final char WIDE_CHAR = '0';
 
+    /**
+     * The back buffer provide user with a BufferStrategy.
+     */
+    private Image backBuffer;
+
     private final class DelegateContainer extends Container {
         {
             enableEvents(0xFFFFFFFF);
@@ -389,6 +394,7 @@
     }
 
     protected void disposeImpl() {
+        destroyBuffers();
         LWContainerPeer cp = getContainerPeer();
         if (cp != null) {
             cp.removeChildPeer(this);
@@ -415,6 +421,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.
@@ -506,31 +518,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
@@ -642,7 +668,7 @@
         }
     }
 
-    protected final Color getBackground() {
+    public final Color getBackground() {
         synchronized (getStateLock()) {
             return background;
         }
@@ -982,19 +1008,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);
     }
 
@@ -1105,8 +1129,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,
@@ -1122,13 +1144,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/jdk/src/macosx/classes/sun/lwawt/LWGraphicsConfig.java	Wed Nov 21 15:50:34 2012 +0400
@@ -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/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Tue Nov 20 18:56:01 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Wed Nov 21 15:50:34 2012 +0400
@@ -27,7 +27,6 @@
 
 import java.awt.*;
 import java.awt.event.*;
-import java.awt.image.BufferedImage;
 import java.awt.peer.*;
 import java.util.List;
 
@@ -75,17 +74,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
@@ -227,7 +215,6 @@
         if (isGrabbing()) {
             ungrab();
         }
-        destroyBuffers();
         platformWindow.dispose();
         super.disposeImpl();
     }
@@ -258,8 +245,10 @@
     }
 
     @Override
-    public GraphicsConfiguration getGraphicsConfiguration() {
-        return graphicsConfig;
+    public final GraphicsConfiguration getGraphicsConfiguration() {
+        synchronized (getStateLock()) {
+            return graphicsConfig;
+        }
     }
 
     @Override
@@ -285,48 +274,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)
-    {
-        platformWindow.flip(x1, y1, x2, y2, flipAction);
-    }
-
-    @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 & SET_CLIENT_SIZE) != 0) {
             // SET_CLIENT_SIZE is only applicable to window peers, so handle it here
@@ -343,16 +290,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;
         }
 
         // Don't post ComponentMoved/Resized and Paint events
@@ -431,21 +376,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);
@@ -1014,21 +952,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);
@@ -1043,35 +970,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) {
-                        SG2DConstraint((SunGraphics2D) g, 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();
-                }
-            }
         }
     }
 
@@ -1092,14 +990,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
--- a/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java	Tue Nov 20 18:56:01 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java	Wed Nov 21 15:50:34 2012 +0400
@@ -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/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java	Tue Nov 20 18:56:01 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java	Wed Nov 21 15:50:34 2012 +0400
@@ -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/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java	Tue Nov 20 18:56:01 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformView.java	Wed Nov 21 15:50:34 2012 +0400
@@ -26,7 +26,6 @@
 package sun.lwawt.macosx;
 
 import java.awt.*;
-import java.awt.image.VolatileImage;
 
 import sun.awt.CGraphicsConfig;
 import sun.lwawt.LWWindowPeer;
@@ -115,26 +114,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 = peer.getBounds();
-        Image im = null;
-        if (!r.isEmpty()) {
-            int transparency = (isOpaque() ? Transparency.OPAQUE : Transparency.TRANSLUCENT);
-            im = peer.getGraphicsConfiguration().createCompatibleImage(r.width, r.height, transparency);
-        }
-        return im;
-    }
-
     public SurfaceData replaceSurfaceData() {
         if (!LWCToolkit.getSunAwtDisableCALayers()) {
             surfaceData = windowLayer.replaceSurfaceData();
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Tue Nov 20 18:56:01 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Wed Nov 21 15:50:34 2012 +0400
@@ -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.*;
@@ -402,11 +401,6 @@
     }
 
     @Override // PlatformWindow
-    public Image createBackBuffer() {
-        return contentView.createBackBuffer();
-    }
-
-    @Override // PlatformWindow
     public void dispose() {
         if (owner != null) {
             CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), getNSWindowPtr());
@@ -417,12 +411,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/jdk/src/share/classes/sun/awt/TextureSizeConstraining.java	Tue Nov 20 18:56:01 2012 +0400
+++ /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();
-
-}