src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java
Print this page
*** 25,35 ****
package sun.java2d.opengl;
import java.awt.AWTException;
import java.awt.BufferCapabilities;
- import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
--- 25,34 ----
*** 46,90 ****
import java.awt.image.VolatileImage;
import java.awt.image.WritableRaster;
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;
import sun.java2d.pipe.hw.AccelSurface;
import sun.java2d.pipe.hw.AccelTypedVolatileImage;
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.macosx.CPlatformView;
! public class CGLGraphicsConfig extends CGraphicsConfig
! implements OGLGraphicsConfig, TextureSizeConstraining
{
! //private static final int kOpenGLSwapInterval = RuntimeOptions.getCurrentOptions().OpenGLSwapInterval;
private static final int kOpenGLSwapInterval = 0; // TODO
! protected static boolean cglAvailable;
private static ImageCapabilities imageCaps = new CGLImageCaps();
private int pixfmt;
private BufferCapabilities bufferCaps;
private long pConfigInfo;
private ContextCapabilities oglCaps;
private OGLContext context;
! private Object disposerReferent = new Object();
public static native int getDefaultPixFmt(int screennum);
private static native boolean initCGL();
private static native long getCGLConfigInfo(int screennum, int visualnum,
int swapInterval);
--- 45,87 ----
import java.awt.image.VolatileImage;
import java.awt.image.WritableRaster;
import sun.awt.CGraphicsConfig;
import sun.awt.CGraphicsDevice;
import sun.awt.image.OffScreenImage;
import sun.awt.image.SunVolatileImage;
import sun.java2d.Disposer;
import sun.java2d.DisposerRecord;
import sun.java2d.Surface;
import sun.java2d.SurfaceData;
import sun.java2d.opengl.OGLContext.OGLContextCaps;
import sun.java2d.pipe.hw.AccelSurface;
import sun.java2d.pipe.hw.AccelTypedVolatileImage;
import sun.java2d.pipe.hw.ContextCapabilities;
import static sun.java2d.opengl.OGLSurfaceData.*;
import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
import sun.java2d.pipe.hw.AccelDeviceEventListener;
import sun.java2d.pipe.hw.AccelDeviceEventNotifier;
+ import sun.lwawt.LWComponentPeer;
import sun.lwawt.macosx.CPlatformView;
! public final class CGLGraphicsConfig extends CGraphicsConfig
! implements OGLGraphicsConfig
{
! //private static final int kOpenGLSwapInterval =
! // RuntimeOptions.getCurrentOptions().OpenGLSwapInterval;
private static final int kOpenGLSwapInterval = 0; // TODO
! private static boolean cglAvailable;
private static ImageCapabilities imageCaps = new CGLImageCaps();
private int pixfmt;
private BufferCapabilities bufferCaps;
private long pConfigInfo;
private ContextCapabilities oglCaps;
private OGLContext context;
! private final Object disposerReferent = new Object();
public static native int getDefaultPixFmt(int screennum);
private static native boolean initCGL();
private static native long getCGLConfigInfo(int screennum, int visualnum,
int swapInterval);
*** 92,102 ****
static {
cglAvailable = initCGL();
}
! protected CGLGraphicsConfig(CGraphicsDevice device, int pixfmt,
long configInfo, ContextCapabilities oglCaps)
{
super(device);
this.pixfmt = pixfmt;
--- 89,99 ----
static {
cglAvailable = initCGL();
}
! private CGLGraphicsConfig(CGraphicsDevice device, int pixfmt,
long configInfo, ContextCapabilities oglCaps)
{
super(device);
this.pixfmt = pixfmt;
*** 168,191 ****
/**
* 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) {
return ((oglCaps.getCaps() & cap) != 0);
}
! public final long getNativeConfigInfo() {
return pConfigInfo;
}
/**
* {@inheritDoc}
*
* @see sun.java2d.pipe.hw.BufferedContextProvider#getContext
*/
! public final OGLContext getContext() {
return context;
}
@Override
public BufferedImage createCompatibleImage(int width, int height) {
--- 165,191 ----
/**
* Returns true if the provided capability bit is present for this config.
* See OGLContext.java for a list of supported capabilities.
*/
! @Override
! public boolean isCapPresent(int cap) {
return ((oglCaps.getCaps() & cap) != 0);
}
! @Override
! public long getNativeConfigInfo() {
return pConfigInfo;
}
/**
* {@inheritDoc}
*
* @see sun.java2d.pipe.hw.BufferedContextProvider#getContext
*/
! @Override
! public OGLContext getContext() {
return context;
}
@Override
public BufferedImage createCompatibleImage(int width, int height) {
*** 255,403 ****
public String toString() {
int screen = getDevice().getCoreGraphicsScreen();
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);
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");
}
! 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);
}
- /**
- * 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();
!
! 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) {
! Graphics g = xBackBuffer.getGraphics();
try {
! g.setColor(target.getBackground());
! g.fillRect(0, 0,
! xBackBuffer.getWidth(),
! xBackBuffer.getHeight());
} finally {
! g.dispose();
}
}
}
private static class CGLBufferCaps extends BufferCapabilities {
--- 255,341 ----
public String toString() {
int screen = getDevice().getCoreGraphicsScreen();
return ("CGLGraphicsConfig[dev="+screen+",pixfmt="+pixfmt+"]");
}
@Override
public SurfaceData createSurfaceData(CPlatformView pView) {
return CGLSurfaceData.createData(pView);
}
@Override
public SurfaceData createSurfaceData(CGLLayer layer) {
return CGLSurfaceData.createData(layer);
}
@Override
public Image createAcceleratedImage(Component target,
int width, int height)
{
ColorModel model = getColorModel(Transparency.OPAQUE);
! WritableRaster wr = model.createCompatibleWritableRaster(width, height);
return new OffScreenImage(target, model, wr,
model.isAlphaPremultiplied());
}
@Override
! 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");
}
! 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");
}
}
@Override
! 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);
}
@Override
! public void destroyBackBuffer(final Image backBuffer) {
! if (backBuffer != null) {
! backBuffer.flush();
! }
}
@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();
}
if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
! final Graphics2D bg = (Graphics2D) backBuffer.getGraphics();
try {
! bg.setBackground(peer.getBackground());
! bg.clearRect(0, 0, backBuffer.getWidth(null),
! backBuffer.getHeight(null));
} finally {
! bg.dispose();
}
}
}
private static class CGLBufferCaps extends BufferCapabilities {
*** 427,445 ****
@Override
public ImageCapabilities getImageCapabilities() {
return imageCaps;
}
! /**
! * {@inheritDoc}
! *
! * @see sun.java2d.pipe.hw.AccelGraphicsConfig#createCompatibleVolatileImage
! */
! public VolatileImage
! createCompatibleVolatileImage(int width, int height,
! int transparency, int type)
! {
if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED ||
transparency == Transparency.BITMASK)
{
return null;
}
--- 365,378 ----
@Override
public ImageCapabilities getImageCapabilities() {
return imageCaps;
}
! @Override
! public VolatileImage createCompatibleVolatileImage(int width, int height,
! int transparency,
! int type) {
if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED ||
transparency == Transparency.BITMASK)
{
return null;
}
*** 471,489 ****
--- 404,425 ----
/**
* {@inheritDoc}
*
* @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);
}
private static final Rectangle totalDisplayBounds = new Rectangle();