提交 5a8ab9f5 编写于 作者: S serb

7124552: [macosx] NullPointerException in getBufferStrategy()

7124219: [macosx] Unable to draw images to fullscreen
Reviewed-by: bae, anthony
上级 5346462b
...@@ -31,13 +31,16 @@ import java.awt.image.*; ...@@ -31,13 +31,16 @@ import java.awt.image.*;
import sun.java2d.SurfaceData; import sun.java2d.SurfaceData;
import sun.java2d.opengl.CGLLayer; import sun.java2d.opengl.CGLLayer;
import sun.lwawt.LWGraphicsConfig;
import sun.lwawt.macosx.CPlatformView; import sun.lwawt.macosx.CPlatformView;
public class CGraphicsConfig extends GraphicsConfiguration { public abstract class CGraphicsConfig extends GraphicsConfiguration
implements LWGraphicsConfig {
private final CGraphicsDevice device; private final CGraphicsDevice device;
private ColorModel colorModel; private ColorModel colorModel;
public CGraphicsConfig(CGraphicsDevice device) { protected CGraphicsConfig(CGraphicsDevice device) {
this.device = device; this.device = device;
} }
...@@ -84,88 +87,20 @@ public class CGraphicsConfig extends GraphicsConfiguration { ...@@ -84,88 +87,20 @@ public class CGraphicsConfig extends GraphicsConfiguration {
return new AffineTransform(xscale, 0.0, 0.0, yscale, 0.0, 0.0); 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 * Creates a new SurfaceData that will be associated with the given
* LWWindowPeer. * LWWindowPeer.
*/ */
public SurfaceData createSurfaceData(CPlatformView pView) { public abstract SurfaceData createSurfaceData(CPlatformView pView);
throw new UnsupportedOperationException("not implemented");
}
/** /**
* Creates a new SurfaceData that will be associated with the given * Creates a new SurfaceData that will be associated with the given
* CGLLayer. * CGLLayer.
*/ */
public SurfaceData createSurfaceData(CGLLayer layer) { public abstract 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");
}
@Override @Override
public boolean isTranslucencyCapable() { public final boolean isTranslucencyCapable() {
//we know for sure we have capable config :) //we know for sure we have capable config :)
return true; return true;
} }
......
...@@ -27,7 +27,6 @@ package sun.java2d.opengl; ...@@ -27,7 +27,6 @@ package sun.java2d.opengl;
import java.awt.AWTException; import java.awt.AWTException;
import java.awt.BufferCapabilities; import java.awt.BufferCapabilities;
import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
...@@ -48,13 +47,10 @@ import java.awt.image.WritableRaster; ...@@ -48,13 +47,10 @@ import java.awt.image.WritableRaster;
import sun.awt.CGraphicsConfig; import sun.awt.CGraphicsConfig;
import sun.awt.CGraphicsDevice; import sun.awt.CGraphicsDevice;
import sun.awt.TextureSizeConstraining;
import sun.awt.image.OffScreenImage; import sun.awt.image.OffScreenImage;
import sun.awt.image.SunVolatileImage; import sun.awt.image.SunVolatileImage;
import sun.awt.image.SurfaceManager;
import sun.java2d.Disposer; import sun.java2d.Disposer;
import sun.java2d.DisposerRecord; import sun.java2d.DisposerRecord;
import sun.java2d.SunGraphics2D;
import sun.java2d.Surface; import sun.java2d.Surface;
import sun.java2d.SurfaceData; import sun.java2d.SurfaceData;
import sun.java2d.opengl.OGLContext.OGLContextCaps; import sun.java2d.opengl.OGLContext.OGLContextCaps;
...@@ -63,18 +59,19 @@ import sun.java2d.pipe.hw.AccelTypedVolatileImage; ...@@ -63,18 +59,19 @@ import sun.java2d.pipe.hw.AccelTypedVolatileImage;
import sun.java2d.pipe.hw.ContextCapabilities; import sun.java2d.pipe.hw.ContextCapabilities;
import static sun.java2d.opengl.OGLSurfaceData.*; import static sun.java2d.opengl.OGLSurfaceData.*;
import static sun.java2d.opengl.OGLContext.OGLContextCaps.*; import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
import sun.java2d.opengl.CGLSurfaceData.CGLVSyncOffScreenSurfaceData;
import sun.java2d.pipe.hw.AccelDeviceEventListener; import sun.java2d.pipe.hw.AccelDeviceEventListener;
import sun.java2d.pipe.hw.AccelDeviceEventNotifier; import sun.java2d.pipe.hw.AccelDeviceEventNotifier;
import sun.lwawt.LWComponentPeer;
import sun.lwawt.macosx.CPlatformView; import sun.lwawt.macosx.CPlatformView;
public class CGLGraphicsConfig extends CGraphicsConfig public final class CGLGraphicsConfig extends CGraphicsConfig
implements OGLGraphicsConfig, TextureSizeConstraining 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 private static final int kOpenGLSwapInterval = 0; // TODO
protected static boolean cglAvailable; private static boolean cglAvailable;
private static ImageCapabilities imageCaps = new CGLImageCaps(); private static ImageCapabilities imageCaps = new CGLImageCaps();
private int pixfmt; private int pixfmt;
...@@ -82,7 +79,7 @@ public class CGLGraphicsConfig extends CGraphicsConfig ...@@ -82,7 +79,7 @@ public class CGLGraphicsConfig extends CGraphicsConfig
private long pConfigInfo; private long pConfigInfo;
private ContextCapabilities oglCaps; private ContextCapabilities oglCaps;
private OGLContext context; private OGLContext context;
private Object disposerReferent = new Object(); private final Object disposerReferent = new Object();
public static native int getDefaultPixFmt(int screennum); public static native int getDefaultPixFmt(int screennum);
private static native boolean initCGL(); private static native boolean initCGL();
...@@ -94,7 +91,7 @@ public class CGLGraphicsConfig extends CGraphicsConfig ...@@ -94,7 +91,7 @@ public class CGLGraphicsConfig extends CGraphicsConfig
cglAvailable = initCGL(); cglAvailable = initCGL();
} }
protected CGLGraphicsConfig(CGraphicsDevice device, int pixfmt, private CGLGraphicsConfig(CGraphicsDevice device, int pixfmt,
long configInfo, ContextCapabilities oglCaps) long configInfo, ContextCapabilities oglCaps)
{ {
super(device); super(device);
...@@ -170,11 +167,13 @@ public class CGLGraphicsConfig extends CGraphicsConfig ...@@ -170,11 +167,13 @@ public class CGLGraphicsConfig extends CGraphicsConfig
* Returns true if the provided capability bit is present for this config. * Returns true if the provided capability bit is present for this config.
* See OGLContext.java for a list of supported capabilities. * 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); return ((oglCaps.getCaps() & cap) != 0);
} }
public final long getNativeConfigInfo() { @Override
public long getNativeConfigInfo() {
return pConfigInfo; return pConfigInfo;
} }
...@@ -183,7 +182,8 @@ public class CGLGraphicsConfig extends CGraphicsConfig ...@@ -183,7 +182,8 @@ public class CGLGraphicsConfig extends CGraphicsConfig
* *
* @see sun.java2d.pipe.hw.BufferedContextProvider#getContext * @see sun.java2d.pipe.hw.BufferedContextProvider#getContext
*/ */
public final OGLContext getContext() { @Override
public OGLContext getContext() {
return context; return context;
} }
...@@ -257,145 +257,83 @@ public class CGLGraphicsConfig extends CGraphicsConfig ...@@ -257,145 +257,83 @@ public class CGLGraphicsConfig extends CGraphicsConfig
return ("CGLGraphicsConfig[dev="+screen+",pixfmt="+pixfmt+"]"); 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 @Override
public SurfaceData createSurfaceData(CPlatformView pView) { public SurfaceData createSurfaceData(CPlatformView pView) {
return CGLSurfaceData.createData(pView); return CGLSurfaceData.createData(pView);
} }
/**
* Creates a new SurfaceData that will be associated with the given
* CGLLayer.
*/
@Override @Override
public SurfaceData createSurfaceData(CGLLayer layer) { public SurfaceData createSurfaceData(CGLLayer layer) {
return CGLSurfaceData.createData(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 @Override
public Image createAcceleratedImage(Component target, public Image createAcceleratedImage(Component target,
int width, int height) int width, int height)
{ {
ColorModel model = getColorModel(Transparency.OPAQUE); ColorModel model = getColorModel(Transparency.OPAQUE);
WritableRaster wr = WritableRaster wr = model.createCompatibleWritableRaster(width, height);
model.createCompatibleWritableRaster(width, height);
return new OffScreenImage(target, model, wr, return new OffScreenImage(target, model, wr,
model.isAlphaPremultiplied()); 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 @Override
public long createBackBuffer(CPlatformView pView, public void assertOperationSupported(final int numBuffers,
int numBuffers, BufferCapabilities caps) final BufferCapabilities caps)
throws AWTException throws AWTException {
{ // Assume this method is never called with numBuffers != 2, as 0 is
if (numBuffers > 2) { // unsupported, and 1 corresponds to a SingleBufferStrategy which
throw new AWTException( // doesn't depend on the peer. Screen is considered as a separate
"Only double or single buffering is supported"); // "buffer".
if (numBuffers != 2) {
throw new AWTException("Only double buffering is supported");
} }
BufferCapabilities configCaps = getBufferCapabilities(); final BufferCapabilities configCaps = getBufferCapabilities();
if (!configCaps.isPageFlipping()) { if (!configCaps.isPageFlipping()) {
throw new AWTException("Page flipping is not supported"); throw new AWTException("Page flipping is not supported");
} }
if (caps.getFlipContents() == BufferCapabilities.FlipContents.PRIOR) { if (caps.getFlipContents() == BufferCapabilities.FlipContents.PRIOR) {
throw new AWTException("FlipContents.PRIOR is not supported"); 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 @Override
public void destroyBackBuffer(long backBuffer) { 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);
} }
/**
* Creates a VolatileImage that essentially wraps the target Component's
* backbuffer (the provided backbuffer handle is essentially ignored).
*/
@Override @Override
public VolatileImage createBackBufferImage(Component target, public void destroyBackBuffer(final Image backBuffer) {
long backBuffer) if (backBuffer != null) {
{ backBuffer.flush();
return new SunVolatileImage(target, }
target.getWidth(), target.getHeight(),
Boolean.TRUE);
} }
/**
* Performs the native OGL flip operation for the given target Component.
*/
@Override @Override
public void flip(CPlatformView pView, public void flip(final LWComponentPeer<?, ?> peer, final Image backBuffer,
Component target, VolatileImage xBackBuffer, final int x1, final int y1, final int x2, final int y2,
int x1, int y1, int x2, int y2, final BufferCapabilities.FlipContents flipAction) {
BufferCapabilities.FlipContents flipAction) final Graphics g = peer.getGraphics();
{ try {
if (flipAction == BufferCapabilities.FlipContents.COPIED) { g.drawImage(backBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
SurfaceManager vsm = SurfaceManager.getManager(xBackBuffer); } finally {
SurfaceData sd = vsm.getPrimarySurfaceData(); g.dispose();
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;
} }
OGLSurfaceData.swapBuffers(pView.getAWTView());
if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) { if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
Graphics g = xBackBuffer.getGraphics(); final Graphics2D bg = (Graphics2D) backBuffer.getGraphics();
try { try {
g.setColor(target.getBackground()); bg.setBackground(peer.getBackground());
g.fillRect(0, 0, bg.clearRect(0, 0, backBuffer.getWidth(null),
xBackBuffer.getWidth(), backBuffer.getHeight(null));
xBackBuffer.getHeight());
} finally { } finally {
g.dispose(); bg.dispose();
} }
} }
} }
...@@ -429,15 +367,10 @@ public class CGLGraphicsConfig extends CGraphicsConfig ...@@ -429,15 +367,10 @@ public class CGLGraphicsConfig extends CGraphicsConfig
return imageCaps; return imageCaps;
} }
/** @Override
* {@inheritDoc} public VolatileImage createCompatibleVolatileImage(int width, int height,
* int transparency,
* @see sun.java2d.pipe.hw.AccelGraphicsConfig#createCompatibleVolatileImage int type) {
*/
public VolatileImage
createCompatibleVolatileImage(int width, int height,
int transparency, int type)
{
if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED || if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED ||
transparency == Transparency.BITMASK) transparency == Transparency.BITMASK)
{ {
...@@ -473,15 +406,18 @@ public class CGLGraphicsConfig extends CGraphicsConfig ...@@ -473,15 +406,18 @@ public class CGLGraphicsConfig extends CGraphicsConfig
* *
* @see sun.java2d.pipe.hw.AccelGraphicsConfig#getContextCapabilities * @see sun.java2d.pipe.hw.AccelGraphicsConfig#getContextCapabilities
*/ */
@Override
public ContextCapabilities getContextCapabilities() { public ContextCapabilities getContextCapabilities() {
return oglCaps; return oglCaps;
} }
@Override
public void addDeviceEventListener(AccelDeviceEventListener l) { public void addDeviceEventListener(AccelDeviceEventListener l) {
int screen = getDevice().getCoreGraphicsScreen(); int screen = getDevice().getCoreGraphicsScreen();
AccelDeviceEventNotifier.addListener(l, screen); AccelDeviceEventNotifier.addListener(l, screen);
} }
@Override
public void removeDeviceEventListener(AccelDeviceEventListener l) { public void removeDeviceEventListener(AccelDeviceEventListener l) {
AccelDeviceEventNotifier.removeListener(l); AccelDeviceEventNotifier.removeListener(l);
} }
......
...@@ -26,12 +26,9 @@ ...@@ -26,12 +26,9 @@
package sun.lwawt; package sun.lwawt;
import java.awt.AWTException;
import java.awt.BufferCapabilities;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.GraphicsConfiguration; import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.peer.CanvasPeer; import java.awt.peer.CanvasPeer;
import javax.swing.JComponent; import javax.swing.JComponent;
...@@ -42,35 +39,10 @@ class LWCanvasPeer<T extends Component, D extends JComponent> ...@@ -42,35 +39,10 @@ class LWCanvasPeer<T extends Component, D extends JComponent>
LWCanvasPeer(final T target, final PlatformComponent platformComponent) { LWCanvasPeer(final T target, final PlatformComponent platformComponent) {
super(target, 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 @Override
public final GraphicsConfiguration getAppropriateGraphicsConfiguration( public final GraphicsConfiguration getAppropriateGraphicsConfiguration(
GraphicsConfiguration gc) final GraphicsConfiguration gc) {
{
// TODO // TODO
return gc; return gc;
} }
......
...@@ -138,6 +138,11 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -138,6 +138,11 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
*/ */
static final char WIDE_CHAR = '0'; static final char WIDE_CHAR = '0';
/**
* The back buffer provide user with a BufferStrategy.
*/
private Image backBuffer;
private final class DelegateContainer extends Container { private final class DelegateContainer extends Container {
{ {
enableEvents(0xFFFFFFFF); enableEvents(0xFFFFFFFF);
...@@ -389,6 +394,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -389,6 +394,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
} }
protected void disposeImpl() { protected void disposeImpl() {
destroyBuffers();
LWContainerPeer cp = getContainerPeer(); LWContainerPeer cp = getContainerPeer();
if (cp != null) { if (cp != null) {
cp.removeChildPeer(this); cp.removeChildPeer(this);
...@@ -415,6 +421,12 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -415,6 +421,12 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
return getWindowPeer().getGraphicsConfiguration(); return getWindowPeer().getGraphicsConfiguration();
} }
// Just a helper method
public final LWGraphicsConfig getLWGC() {
return (LWGraphicsConfig) getGraphicsConfiguration();
}
/* /*
* Overridden in LWWindowPeer to replace its surface * Overridden in LWWindowPeer to replace its surface
* data and back buffer. * data and back buffer.
...@@ -506,31 +518,45 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -506,31 +518,45 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
return getGraphicsConfiguration().getColorModel(); return getGraphicsConfiguration().getColorModel();
} }
public boolean isTranslucent() {
// Translucent windows of the top level are supported only
return false;
}
@Override @Override
public void createBuffers(int numBuffers, BufferCapabilities caps) public final void createBuffers(int numBuffers, BufferCapabilities caps)
throws AWTException { throws AWTException {
throw new AWTException("Back buffers are only supported for " + getLWGC().assertOperationSupported(numBuffers, caps);
"Window or Canvas components."); final Image buffer = getLWGC().createBackBuffer(this);
synchronized (getStateLock()) {
backBuffer = buffer;
}
} }
/*
* To be overridden in LWWindowPeer and LWCanvasPeer.
*/
@Override @Override
public Image getBackBuffer() { public final Image getBackBuffer() {
// Return null or throw AWTException? synchronized (getStateLock()) {
return null; if (backBuffer != null) {
return backBuffer;
}
}
throw new IllegalStateException("Buffers have not been created");
} }
@Override @Override
public void flip(int x1, int y1, int x2, int y2, public final void flip(int x1, int y1, int x2, int y2,
BufferCapabilities.FlipContents flipAction) { BufferCapabilities.FlipContents flipAction) {
// Skip silently or throw AWTException? getLWGC().flip(this, getBackBuffer(), x1, y1, x2, y2, flipAction);
} }
@Override @Override
public void destroyBuffers() { public final void destroyBuffers() {
// Do nothing final Image oldBB;
synchronized (getStateLock()) {
oldBB = backBuffer;
backBuffer = null;
}
getLWGC().destroyBackBuffer(oldBB);
} }
// Helper method // Helper method
...@@ -642,7 +668,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -642,7 +668,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
} }
} }
protected final Color getBackground() { public final Color getBackground() {
synchronized (getStateLock()) { synchronized (getStateLock()) {
return background; return background;
} }
...@@ -982,19 +1008,17 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -982,19 +1008,17 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
} }
@Override @Override
public Image createImage(ImageProducer producer) { public final Image createImage(final ImageProducer producer) {
return new ToolkitImage(producer); return new ToolkitImage(producer);
} }
@Override @Override
public Image createImage(int w, int h) { public final Image createImage(final int width, final int height) {
CGraphicsConfig gc = (CGraphicsConfig)getGraphicsConfiguration(); return getLWGC().createAcceleratedImage(getTarget(), width, height);
return gc.createAcceleratedImage(getTarget(), w, h);
} }
@Override @Override
public VolatileImage createVolatileImage(int w, int h) { public final VolatileImage createVolatileImage(final int w, final int h) {
// TODO: is it a right/complete implementation?
return new SunVolatileImage(getTarget(), w, h); return new SunVolatileImage(getTarget(), w, h);
} }
...@@ -1105,8 +1129,6 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -1105,8 +1129,6 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
* of target.setLocation() or as a result of user actions (window is * of target.setLocation() or as a result of user actions (window is
* dragged with mouse). * dragged with mouse).
* *
* To be overridden in LWWindowPeer to update its GraphicsConfig.
*
* This method could be called on the toolkit thread. * This method could be called on the toolkit thread.
*/ */
protected final void handleMove(final int x, final int y, protected final void handleMove(final int x, final int y,
...@@ -1122,13 +1144,19 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -1122,13 +1144,19 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
* Called when this peer's size has been changed either as a result of * 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). * 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. * This method could be called on the toolkit thread.
*/ */
protected final void handleResize(final int w, final int h, protected final void handleResize(final int w, final int h,
final boolean updateTarget) { final boolean updateTarget) {
Image oldBB = null;
synchronized (getStateLock()) {
if (backBuffer != null) {
oldBB = backBuffer;
backBuffer = getLWGC().createBackBuffer(this);
}
}
getLWGC().destroyBackBuffer(oldBB);
if (updateTarget) { if (updateTarget) {
AWTAccessor.getComponentAccessor().setSize(getTarget(), w, h); AWTAccessor.getComponentAccessor().setSize(getTarget(), w, h);
} }
......
...@@ -23,23 +23,75 @@ ...@@ -23,23 +23,75 @@
* questions. * questions.
*/ */
package sun.awt; package sun.lwawt;
import java.awt.AWTException;
import java.awt.BufferCapabilities;
import java.awt.Component;
import java.awt.Image;
/** /**
* A GraphicsConfiguration implements the TextureSizeConstraining * As lwawt can be used on different platforms with different graphic
* interface to indicate that it imposes certain limitations on the * configurations, the general set of methods is necessary. This interface
* maximum size of supported textures. * collects the methods that should be provided by GraphicsConfiguration,
* simplifying use by the LWAWT.
*
* @author Sergey Bylokhov
*/ */
public interface TextureSizeConstraining { 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;
/** /**
* Returns the maximum width of any texture image. * Creates a back buffer for the given peer and returns the image wrapper.
*/ */
public int getMaxTextureWidth(); Image createBackBuffer(LWComponentPeer<?, ?> peer);
/** /**
* Returns the maximum height of any texture image. * Destroys the back buffer object.
*/ */
public int getMaxTextureHeight(); 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);
} }
...@@ -27,7 +27,6 @@ package sun.lwawt; ...@@ -27,7 +27,6 @@ package sun.lwawt;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.awt.peer.*; import java.awt.peer.*;
import java.util.List; import java.util.List;
...@@ -75,17 +74,6 @@ public class LWWindowPeer ...@@ -75,17 +74,6 @@ public class LWWindowPeer
private SurfaceData surfaceData; private SurfaceData surfaceData;
private final Object surfaceDataLock = new Object(); 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; private volatile int windowState = Frame.NORMAL;
// check that the mouse is over the window // check that the mouse is over the window
...@@ -227,7 +215,6 @@ public class LWWindowPeer ...@@ -227,7 +215,6 @@ public class LWWindowPeer
if (isGrabbing()) { if (isGrabbing()) {
ungrab(); ungrab();
} }
destroyBuffers();
platformWindow.dispose(); platformWindow.dispose();
super.disposeImpl(); super.disposeImpl();
} }
...@@ -258,8 +245,10 @@ public class LWWindowPeer ...@@ -258,8 +245,10 @@ public class LWWindowPeer
} }
@Override @Override
public GraphicsConfiguration getGraphicsConfiguration() { public final GraphicsConfiguration getGraphicsConfiguration() {
return graphicsConfig; synchronized (getStateLock()) {
return graphicsConfig;
}
} }
@Override @Override
...@@ -284,48 +273,6 @@ public class LWWindowPeer ...@@ -284,48 +273,6 @@ public class LWWindowPeer
return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f)); return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f));
} }
@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 @Override
public void setBounds(int x, int y, int w, int h, int op) { public void setBounds(int x, int y, int w, int h, int op) {
if ((op & SET_CLIENT_SIZE) != 0) { if ((op & SET_CLIENT_SIZE) != 0) {
...@@ -343,16 +290,14 @@ public class LWWindowPeer ...@@ -343,16 +290,14 @@ public class LWWindowPeer
h = MINIMUM_HEIGHT; h = MINIMUM_HEIGHT;
} }
if (graphicsConfig instanceof TextureSizeConstraining) { final int maxW = getLWGC().getMaxTextureWidth();
final int maxW = ((TextureSizeConstraining)graphicsConfig).getMaxTextureWidth(); final int maxH = getLWGC().getMaxTextureHeight();
final int maxH = ((TextureSizeConstraining)graphicsConfig).getMaxTextureHeight();
if (w > maxW) { if (w > maxW) {
w = maxW; w = maxW;
} }
if (h > maxH) { if (h > maxH) {
h = maxH; h = maxH;
}
} }
// Don't post ComponentMoved/Resized and Paint events // Don't post ComponentMoved/Resized and Paint events
...@@ -431,21 +376,14 @@ public class LWWindowPeer ...@@ -431,21 +376,14 @@ public class LWWindowPeer
min = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT); 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; final Dimension max;
if (getTarget().isMaximumSizeSet()) { if (getTarget().isMaximumSizeSet()) {
max = getTarget().getMaximumSize(); max = getTarget().getMaximumSize();
max.width = Math.min(max.width, maxW); max.width = Math.min(max.width, getLWGC().getMaxTextureWidth());
max.height = Math.min(max.height, maxH); max.height = Math.min(max.height, getLWGC().getMaxTextureHeight());
} else { } else {
max = new Dimension(maxW, maxH); max = new Dimension(getLWGC().getMaxTextureWidth(),
getLWGC().getMaxTextureHeight());
} }
platformWindow.setSizeConstraints(min.width, min.height, max.width, max.height); platformWindow.setSizeConstraints(min.width, min.height, max.width, max.height);
...@@ -1014,21 +952,10 @@ public class LWWindowPeer ...@@ -1014,21 +952,10 @@ public class LWWindowPeer
replaceSurfaceData(true); replaceSurfaceData(true);
} }
private void replaceSurfaceData(boolean blit) { private void replaceSurfaceData(final boolean blit) {
replaceSurfaceData(backBufferCount, backBufferCaps, blit);
}
private void replaceSurfaceData(int newBackBufferCount,
BufferCapabilities newBackBufferCaps,
boolean blit) {
synchronized (surfaceDataLock) { synchronized (surfaceDataLock) {
final SurfaceData oldData = getSurfaceData(); final SurfaceData oldData = getSurfaceData();
surfaceData = platformWindow.replaceSurfaceData(); surfaceData = platformWindow.replaceSurfaceData();
// TODO: volatile image
// VolatileImage oldBB = backBuffer;
BufferedImage oldBB = backBuffer;
backBufferCount = newBackBufferCount;
backBufferCaps = newBackBufferCaps;
final Rectangle size = getSize(); final Rectangle size = getSize();
if (getSurfaceData() != null && oldData != getSurfaceData()) { if (getSurfaceData() != null && oldData != getSurfaceData()) {
clearBackground(size.width, size.height); clearBackground(size.width, size.height);
...@@ -1043,35 +970,6 @@ public class LWWindowPeer ...@@ -1043,35 +970,6 @@ public class LWWindowPeer
// This can only happen when this peer is being created // This can only happen when this peer is being created
oldData.flush(); 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 class LWWindowPeer ...@@ -1092,14 +990,6 @@ public class LWWindowPeer
} }
} }
public int getBackBufferCount() {
return backBufferCount;
}
public BufferCapabilities getBackBufferCaps() {
return backBufferCaps;
}
/* /*
* Request the window insets from the delegate and compares it * Request the window insets from the delegate and compares it
* with the current one. This method is mostly called by the * with the current one. This method is mostly called by the
......
...@@ -97,17 +97,6 @@ public interface PlatformWindow { ...@@ -97,17 +97,6 @@ public interface PlatformWindow {
*/ */
public SurfaceData replaceSurfaceData(); 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 setModalBlocked(boolean blocked);
public void toFront(); public void toFront();
......
...@@ -31,12 +31,9 @@ import sun.lwawt.LWWindowPeer; ...@@ -31,12 +31,9 @@ import sun.lwawt.LWWindowPeer;
import sun.java2d.opengl.CGLLayer; import sun.java2d.opengl.CGLLayer;
import sun.java2d.SurfaceData; import sun.java2d.SurfaceData;
import sun.awt.CGraphicsConfig;
import sun.awt.CGraphicsDevice;
import sun.awt.CausedFocusEvent; import sun.awt.CausedFocusEvent;
import java.awt.*; import java.awt.*;
import java.awt.BufferCapabilities.FlipContents;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
...@@ -112,22 +109,6 @@ public class CPlatformEmbeddedFrame implements PlatformWindow { ...@@ -112,22 +109,6 @@ public class CPlatformEmbeddedFrame implements PlatformWindow {
return windowLayer.replaceSurfaceData(); return windowLayer.replaceSurfaceData();
} }
@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 @Override
public void setVisible(boolean visible) {} public void setVisible(boolean visible) {}
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
package sun.lwawt.macosx; package sun.lwawt.macosx;
import java.awt.*; import java.awt.*;
import java.awt.image.VolatileImage;
import sun.awt.CGraphicsConfig; import sun.awt.CGraphicsConfig;
import sun.lwawt.LWWindowPeer; import sun.lwawt.LWWindowPeer;
...@@ -115,26 +114,6 @@ public class CPlatformView extends CFRetainedResource { ...@@ -115,26 +114,6 @@ public class CPlatformView extends CFRetainedResource {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// PAINTING METHODS // 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() { public SurfaceData replaceSurfaceData() {
if (!LWCToolkit.getSunAwtDisableCALayers()) { if (!LWCToolkit.getSunAwtDisableCALayers()) {
surfaceData = windowLayer.replaceSurfaceData(); surfaceData = windowLayer.replaceSurfaceData();
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
package sun.lwawt.macosx; package sun.lwawt.macosx;
import java.awt.BufferCapabilities.FlipContents;
import java.awt.*; import java.awt.*;
import java.awt.Dialog.ModalityType; import java.awt.Dialog.ModalityType;
import java.awt.event.*; import java.awt.event.*;
...@@ -401,11 +400,6 @@ public final class CPlatformWindow extends CFRetainedResource implements Platfor ...@@ -401,11 +400,6 @@ public final class CPlatformWindow extends CFRetainedResource implements Platfor
} }
} }
@Override // PlatformWindow
public Image createBackBuffer() {
return contentView.createBackBuffer();
}
@Override // PlatformWindow @Override // PlatformWindow
public void dispose() { public void dispose() {
if (owner != null) { if (owner != null) {
...@@ -416,12 +410,6 @@ public final class CPlatformWindow extends CFRetainedResource implements Platfor ...@@ -416,12 +410,6 @@ public final class CPlatformWindow extends CFRetainedResource implements Platfor
CPlatformWindow.super.dispose(); CPlatformWindow.super.dispose();
} }
@Override // PlatformWindow
public void flip(int x1, int y1, int x2, int y2, FlipContents flipAction) {
// TODO: not implemented
(new RuntimeException("unimplemented")).printStackTrace();
}
@Override // PlatformWindow @Override // PlatformWindow
public FontMetrics getFontMetrics(Font f) { public FontMetrics getFontMetrics(Font f) {
// TODO: not implemented // TODO: not implemented
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册