下面列出了怎么用sun.awt.image.SunVolatileImage的API类实例代码及写法,或者点击链接到github查看源代码。
public CGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
/*
* We will attempt to accelerate this image only under the
* following conditions:
* - the image is opaque OR
* - the image is translucent AND
* - the GraphicsConfig supports the FBO extension OR
* - the GraphicsConfig has a stored alpha channel
*/
int transparency = vImg.getTransparency();
CGLGraphicsConfig gc = (CGLGraphicsConfig)vImg.getGraphicsConfig();
accelerationEnabled =
(transparency == Transparency.OPAQUE) ||
((transparency == Transparency.TRANSLUCENT) &&
(gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
gc.isCapPresent(CAPS_STORED_ALPHA)));
}
public X11VolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
// We only accelerated opaque vImages currently
accelerationEnabled = X11SurfaceData.isAccelerationEnabled() &&
(vImg.getTransparency() == Transparency.OPAQUE);
if ((context != null) && !accelerationEnabled) {
// if we're wrapping a backbuffer drawable, we must ensure that
// the accelerated surface is initialized up front, regardless
// of whether acceleration is enabled. But we need to set
// the accelerationEnabled field to true to reflect that this
// SM is actually accelerated.
accelerationEnabled = true;
sdAccel = initAcceleratedSurface();
sdCurrent = sdAccel;
if (sdBackup != null) {
// release the system memory backup surface, as we won't be
// needing it in this case
sdBackup = null;
}
}
}
/**
* {@inheritDoc}
*
* @see sun.java2d.pipe.hw.AccelGraphicsConfig#createCompatibleVolatileImage
*/
@Override
public VolatileImage
createCompatibleVolatileImage(int width, int height,
int transparency, int type)
{
if ((type != FBOBJECT && type != TEXTURE)
|| transparency == Transparency.BITMASK
|| type == FBOBJECT && !isCapPresent(CAPS_EXT_FBOBJECT)) {
return null;
}
SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
transparency, type);
Surface sd = vi.getDestSurface();
if (!(sd instanceof AccelSurface) ||
((AccelSurface)sd).getType() != type)
{
vi.flush();
vi = null;
}
return vi;
}
public X11VolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
// We only accelerated opaque vImages currently
accelerationEnabled = X11SurfaceData.isAccelerationEnabled() &&
(vImg.getTransparency() == Transparency.OPAQUE);
if ((context != null) && !accelerationEnabled) {
// if we're wrapping a backbuffer drawable, we must ensure that
// the accelerated surface is initialized up front, regardless
// of whether acceleration is enabled. But we need to set
// the accelerationEnabled field to true to reflect that this
// SM is actually accelerated.
accelerationEnabled = true;
sdAccel = initAcceleratedSurface();
sdCurrent = sdAccel;
if (sdBackup != null) {
// release the system memory backup surface, as we won't be
// needing it in this case
sdBackup = null;
}
}
}
public GLXVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
/*
* We will attempt to accelerate this image only under the
* following conditions:
* - the image is opaque OR
* - the image is translucent AND
* - the GraphicsConfig supports the FBO extension OR
* - the GraphicsConfig has a stored alpha channel
*/
int transparency = vImg.getTransparency();
GLXGraphicsConfig gc = (GLXGraphicsConfig)vImg.getGraphicsConfig();
accelerationEnabled =
(transparency == Transparency.OPAQUE) ||
((transparency == Transparency.TRANSLUCENT) &&
(gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
gc.isCapPresent(CAPS_STORED_ALPHA)));
}
public GLXVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
/*
* We will attempt to accelerate this image only under the
* following conditions:
* - the image is opaque OR
* - the image is translucent AND
* - the GraphicsConfig supports the FBO extension OR
* - the GraphicsConfig has a stored alpha channel
*/
int transparency = vImg.getTransparency();
GLXGraphicsConfig gc = (GLXGraphicsConfig)vImg.getGraphicsConfig();
accelerationEnabled =
(transparency == Transparency.OPAQUE) ||
((transparency == Transparency.TRANSLUCENT) &&
(gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
gc.isCapPresent(CAPS_STORED_ALPHA)));
}
public D3DVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
/*
* We will attempt to accelerate this image only under the
* following conditions:
* - the image is opaque OR
* - the image is translucent AND
* - the GraphicsConfig supports the FBO extension OR
* - the GraphicsConfig has a stored alpha channel
*/
int transparency = vImg.getTransparency();
D3DGraphicsDevice gd = (D3DGraphicsDevice)
vImg.getGraphicsConfig().getDevice();
accelerationEnabled =
(transparency == Transparency.OPAQUE) ||
(transparency == Transparency.TRANSLUCENT &&
(gd.isCapPresent(CAPS_RT_PLAIN_ALPHA) ||
gd.isCapPresent(CAPS_RT_TEXTURE_ALPHA)));
}
public CGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
/*
* We will attempt to accelerate this image only under the
* following conditions:
* - the image is opaque OR
* - the image is translucent AND
* - the GraphicsConfig supports the FBO extension OR
* - the GraphicsConfig has a stored alpha channel
*/
int transparency = vImg.getTransparency();
CGLGraphicsConfig gc = (CGLGraphicsConfig)vImg.getGraphicsConfig();
accelerationEnabled =
(transparency == Transparency.OPAQUE) ||
((transparency == Transparency.TRANSLUCENT) &&
(gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
gc.isCapPresent(CAPS_STORED_ALPHA)));
}
public GLXVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
/*
* We will attempt to accelerate this image only under the
* following conditions:
* - the image is opaque OR
* - the image is translucent AND
* - the GraphicsConfig supports the FBO extension OR
* - the GraphicsConfig has a stored alpha channel
*/
int transparency = vImg.getTransparency();
GLXGraphicsConfig gc = (GLXGraphicsConfig)vImg.getGraphicsConfig();
accelerationEnabled =
(transparency == Transparency.OPAQUE) ||
((transparency == Transparency.TRANSLUCENT) &&
(gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
gc.isCapPresent(CAPS_STORED_ALPHA)));
}
public WGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
/*
* We will attempt to accelerate this image only under the
* following conditions:
* - the image is opaque OR
* - the image is translucent AND
* - the GraphicsConfig supports the FBO extension OR
* - the GraphicsConfig has a stored alpha channel
*/
int transparency = vImg.getTransparency();
WGLGraphicsConfig gc = (WGLGraphicsConfig)vImg.getGraphicsConfig();
accelerationEnabled =
(transparency == Transparency.OPAQUE) ||
((transparency == Transparency.TRANSLUCENT) &&
(gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
gc.isCapPresent(CAPS_STORED_ALPHA)));
}
public WGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
/*
* We will attempt to accelerate this image only under the
* following conditions:
* - the image is opaque OR
* - the image is translucent AND
* - the GraphicsConfig supports the FBO extension OR
* - the GraphicsConfig has a stored alpha channel
*/
int transparency = vImg.getTransparency();
WGLGraphicsConfig gc = (WGLGraphicsConfig)vImg.getGraphicsConfig();
accelerationEnabled =
(transparency == Transparency.OPAQUE) ||
((transparency == Transparency.TRANSLUCENT) &&
(gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
gc.isCapPresent(CAPS_STORED_ALPHA)));
}
public GLXVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
/*
* We will attempt to accelerate this image only under the
* following conditions:
* - the image is opaque OR
* - the image is translucent AND
* - the GraphicsConfig supports the FBO extension OR
* - the GraphicsConfig has a stored alpha channel
*/
int transparency = vImg.getTransparency();
GLXGraphicsConfig gc = (GLXGraphicsConfig)vImg.getGraphicsConfig();
accelerationEnabled =
(transparency == Transparency.OPAQUE) ||
((transparency == Transparency.TRANSLUCENT) &&
(gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
gc.isCapPresent(CAPS_STORED_ALPHA)));
}
public X11VolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
// We only accelerated opaque vImages currently
accelerationEnabled = X11SurfaceData.isAccelerationEnabled() &&
(vImg.getTransparency() == Transparency.OPAQUE);
if ((context != null) && !accelerationEnabled) {
// if we're wrapping a backbuffer drawable, we must ensure that
// the accelerated surface is initialized up front, regardless
// of whether acceleration is enabled. But we need to set
// the accelerationEnabled field to true to reflect that this
// SM is actually accelerated.
accelerationEnabled = true;
sdAccel = initAcceleratedSurface();
sdCurrent = sdAccel;
if (sdBackup != null) {
// release the system memory backup surface, as we won't be
// needing it in this case
sdBackup = null;
}
}
}
@Override
public VolatileImage createCompatibleVolatileImage(int width, int height,
int transparency,
int type) {
if ((type != FBOBJECT && type != TEXTURE)
|| transparency == Transparency.BITMASK
|| type == FBOBJECT && !isCapPresent(CAPS_EXT_FBOBJECT)) {
return null;
}
SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
transparency, type);
Surface sd = vi.getDestSurface();
if (!(sd instanceof AccelSurface) ||
((AccelSurface)sd).getType() != type)
{
vi.flush();
vi = null;
}
return vi;
}
public D3DVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
/*
* We will attempt to accelerate this image only under the
* following conditions:
* - the image is opaque OR
* - the image is translucent AND
* - the GraphicsConfig supports the FBO extension OR
* - the GraphicsConfig has a stored alpha channel
*/
int transparency = vImg.getTransparency();
D3DGraphicsDevice gd = (D3DGraphicsDevice)
vImg.getGraphicsConfig().getDevice();
accelerationEnabled =
(transparency == Transparency.OPAQUE) ||
(transparency == Transparency.TRANSLUCENT &&
(gd.isCapPresent(CAPS_RT_PLAIN_ALPHA) ||
gd.isCapPresent(CAPS_RT_TEXTURE_ALPHA)));
}
public CGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
super(vImg, context);
/*
* We will attempt to accelerate this image only under the
* following conditions:
* - the image is opaque OR
* - the image is translucent AND
* - the GraphicsConfig supports the FBO extension OR
* - the GraphicsConfig has a stored alpha channel
*/
int transparency = vImg.getTransparency();
CGLGraphicsConfig gc = (CGLGraphicsConfig)vImg.getGraphicsConfig();
accelerationEnabled =
(transparency == Transparency.OPAQUE) ||
((transparency == Transparency.TRANSLUCENT) &&
(gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
gc.isCapPresent(CAPS_STORED_ALPHA)));
}
/**
* 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);
}
/**
* Creates a new instance of a VolatileSurfaceManager given any
* arbitrary SunVolatileImage. An optional context Object can be supplied
* as a way for the caller to pass pipeline-specific context data to
* the VolatileSurfaceManager (such as a backbuffer handle, for example).
*
* For Windows platforms, this method returns a Windows-specific
* VolatileSurfaceManager.
*/
public VolatileSurfaceManager createVolatileManager(SunVolatileImage vImg,
Object context)
{
GraphicsConfiguration gc = vImg.getGraphicsConfig();
if (gc instanceof D3DGraphicsConfig) {
return new D3DVolatileSurfaceManager(vImg, context);
} else if (gc instanceof WGLGraphicsConfig) {
return new WGLVolatileSurfaceManager(vImg, context);
} else {
return new BufImgVolatileSurfaceManager(vImg, context);
}
}
/**
* Creates a WGL-based backbuffer for the given peer and returns the
* image wrapper.
*/
@Override
public VolatileImage createBackBuffer(WComponentPeer peer) {
Component target = (Component)peer.getTarget();
// it is possible for the component to have size 0x0, adjust it to
// be at least 1x1 to avoid IAE
int w = Math.max(1, target.getWidth());
int h = Math.max(1, target.getHeight());
return new SunVolatileImage(target,
w, h,
Boolean.TRUE);
}
@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 VolatileImage createCompatibleVolatileImage(int width, int height,
int transparency,
int type) {
if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED ||
transparency == Transparency.BITMASK)
{
return null;
}
if (type == FBOBJECT) {
if (!isCapPresent(CAPS_EXT_FBOBJECT)) {
return null;
}
} else if (type == PBUFFER) {
boolean isOpaque = transparency == Transparency.OPAQUE;
if (!isOpaque && !isCapPresent(CAPS_STORED_ALPHA)) {
return null;
}
}
SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
transparency, type);
Surface sd = vi.getDestSurface();
if (!(sd instanceof AccelSurface) ||
((AccelSurface)sd).getType() != type)
{
vi.flush();
vi = null;
}
return vi;
}
/**
* Creates a WGL-based backbuffer for the given peer and returns the
* image wrapper.
*/
@Override
public VolatileImage createBackBuffer(WComponentPeer peer) {
Component target = (Component)peer.getTarget();
// it is possible for the component to have size 0x0, adjust it to
// be at least 1x1 to avoid IAE
int w = Math.max(1, target.getWidth());
int h = Math.max(1, target.getHeight());
return new SunVolatileImage(target,
w, h,
Boolean.TRUE);
}
/**
* {@inheritDoc}
*
* @see sun.java2d.pipe.hw.AccelGraphicsConfig#createCompatibleVolatileImage
*/
@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;
}
boolean isOpaque = transparency == Transparency.OPAQUE;
if (type == RT_TEXTURE) {
int cap = isOpaque ? CAPS_RT_TEXTURE_OPAQUE : CAPS_RT_TEXTURE_ALPHA;
if (!device.isCapPresent(cap)) {
return null;
}
} else if (type == RT_PLAIN) {
if (!isOpaque && !device.isCapPresent(CAPS_RT_PLAIN_ALPHA)) {
return null;
}
}
SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
transparency, type);
Surface sd = vi.getDestSurface();
if (!(sd instanceof AccelSurface) ||
((AccelSurface)sd).getType() != type)
{
vi.flush();
vi = null;
}
return vi;
}
/**
* Creates a WGL-based backbuffer for the given peer and returns the
* image wrapper.
*/
@Override
public VolatileImage createBackBuffer(WComponentPeer peer) {
Component target = (Component)peer.getTarget();
// it is possible for the component to have size 0x0, adjust it to
// be at least 1x1 to avoid IAE
int w = Math.max(1, target.getWidth());
int h = Math.max(1, target.getHeight());
return new SunVolatileImage(target,
w, h,
Boolean.TRUE);
}
/**
* {@inheritDoc}
*
* @see sun.java2d.pipe.hw.AccelGraphicsConfig#createCompatibleVolatileImage
*/
@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;
}
if (type == FBOBJECT) {
if (!isCapPresent(CAPS_EXT_FBOBJECT)) {
return null;
}
} else if (type == PBUFFER) {
boolean isOpaque = transparency == Transparency.OPAQUE;
if (!isOpaque && !isCapPresent(CAPS_STORED_ALPHA)) {
return null;
}
}
SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
transparency, type);
Surface sd = vi.getDestSurface();
if (!(sd instanceof AccelSurface) ||
((AccelSurface)sd).getType() != type)
{
vi.flush();
vi = null;
}
return vi;
}
/**
* Creates a VolatileImage that essentially wraps the target Component's
* backbuffer, using the provided backbuffer handle.
*/
public VolatileImage createBackBufferImage(Component target,
long backBuffer)
{
// it is possible for the component to have size 0x0, adjust it to
// be at least 1x1 to avoid IAE
int w = Math.max(1, target.getWidth());
int h = Math.max(1, target.getHeight());
return new SunVolatileImage(target,
w, h,
Long.valueOf(backBuffer));
}
/**
* Creates a WGL-based backbuffer for the given peer and returns the
* image wrapper.
*/
@Override
public VolatileImage createBackBuffer(WComponentPeer peer) {
Component target = (Component)peer.getTarget();
// it is possible for the component to have size 0x0, adjust it to
// be at least 1x1 to avoid IAE
int w = Math.max(1, target.getWidth());
int h = Math.max(1, target.getHeight());
return new SunVolatileImage(target,
w, h,
Boolean.TRUE);
}
/**
* Creates a VolatileImage that essentially wraps the target Component's
* backbuffer, using the provided backbuffer handle.
*/
public VolatileImage createBackBufferImage(Component target,
long backBuffer)
{
// it is possible for the component to have size 0x0, adjust it to
// be at least 1x1 to avoid IAE
int w = Math.max(1, target.getWidth());
int h = Math.max(1, target.getHeight());
return new SunVolatileImage(target,
w, h,
Long.valueOf(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);
}
/**
* Creates a SurfaceData object representing an off-screen buffer (either
* a plain surface or Texture).
*/
public static D3DSurfaceData createData(D3DGraphicsConfig gc,
int width, int height,
ColorModel cm,
Image image, int type)
{
if (type == RT_TEXTURE) {
boolean isOpaque = cm.getTransparency() == Transparency.OPAQUE;
int cap = isOpaque ? CAPS_RT_TEXTURE_OPAQUE : CAPS_RT_TEXTURE_ALPHA;
if (!gc.getD3DDevice().isCapPresent(cap)) {
type = RT_PLAIN;
}
}
D3DSurfaceData ret = null;
try {
ret = new D3DSurfaceData(null, gc, width, height,
image, cm, 0, SWAP_DISCARD, VSYNC_DEFAULT,
type);
} catch (InvalidPipeException ipe) {
// try again - we might have ran out of vram, and rt textures
// could take up more than a plain surface, so it might succeed
if (type == RT_TEXTURE) {
// If a RT_TEXTURE was requested do not attempt to create a
// plain surface. (note that RT_TEXTURE can only be requested
// from a VI so the cast is safe)
if (((SunVolatileImage)image).getForcedAccelSurfaceType() !=
RT_TEXTURE)
{
type = RT_PLAIN;
ret = new D3DSurfaceData(null, gc, width, height,
image, cm, 0, SWAP_DISCARD,
VSYNC_DEFAULT, type);
}
}
}
return ret;
}