下面列出了怎么用java.awt.ImageCapabilities的API类实例代码及写法,或者点击链接到github查看源代码。
protected VolatileSurfaceManager createSurfaceManager(Object context,
ImageCapabilities caps)
{
/**
* Platform-specific SurfaceManagerFactories will return a
* manager suited to acceleration on each platform. But if
* the user is asking for a VolatileImage from a BufferedImageGC,
* then we need to return the appropriate unaccelerated manager.
* Note: this could change in the future; if some platform would
* like to accelerate BIGC volatile images, then this special-casing
* of the BIGC graphicsConfig should live in platform-specific
* code instead.
* We do the same for a Printer Device, and if user requested an
* unaccelerated VolatileImage by passing the capabilities object.
*/
if (graphicsConfig instanceof BufferedImageGraphicsConfig ||
graphicsConfig instanceof sun.print.PrinterGraphicsConfig ||
(caps != null && !caps.isAccelerated()))
{
return new BufImgVolatileSurfaceManager(this, context);
}
SurfaceManagerFactory smf = SurfaceManagerFactory.getInstance();
return smf.createVolatileManager(this, context);
}
protected VolatileSurfaceManager createSurfaceManager(Object context,
ImageCapabilities caps)
{
/**
* Platform-specific SurfaceManagerFactories will return a
* manager suited to acceleration on each platform. But if
* the user is asking for a VolatileImage from a BufferedImageGC,
* then we need to return the appropriate unaccelerated manager.
* Note: this could change in the future; if some platform would
* like to accelerate BIGC volatile images, then this special-casing
* of the BIGC graphicsConfig should live in platform-specific
* code instead.
* We do the same for a Printer Device, and if user requested an
* unaccelerated VolatileImage by passing the capabilities object.
*/
if (graphicsConfig instanceof BufferedImageGraphicsConfig ||
graphicsConfig instanceof sun.print.PrinterGraphicsConfig ||
(caps != null && !caps.isAccelerated()))
{
return new BufImgVolatileSurfaceManager(this, context);
}
SurfaceManagerFactory smf = SurfaceManagerFactory.getInstance();
return smf.createVolatileManager(this, context);
}
/**
* Creates an ExtendedBufferCapabilities instance with front/back/flip caps
* from the passed image/flip caps, and the v-sync type.
*/
public ExtendedBufferCapabilities(ImageCapabilities front,
ImageCapabilities back, FlipContents flip,
VSyncType t)
{
super(front, back, flip);
this.vsync = t;
}
@Override
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
if (isConfigValid(gc)) {
return isAccelerationEnabled() ?
new AcceleratedImageCapabilities() :
new ImageCapabilities(false);
}
return super.getCapabilities(gc);
}
@Override
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
if (isConfigValid(gc)) {
return isAccelerationEnabled() ?
new AcceleratedImageCapabilities() :
new ImageCapabilities(false);
}
return super.getCapabilities(gc);
}
/**
* Creates an ExtendedBufferCapabilities instance with front/back/flip caps
* from the passed image/flip caps, and the v-sync type.
*/
public ExtendedBufferCapabilities(ImageCapabilities front,
ImageCapabilities back, FlipContents flip,
VSyncType t)
{
super(front, back, flip);
this.vsync = t;
}
private void createBS(boolean requestVSync) {
if (bs != null && requestVSync == currentBSVSynced) {
return;
}
BufferCapabilities bc = defaultBC;
if (requestVSync) {
bc = new sun.java2d.pipe.hw.ExtendedBufferCapabilities(
new ImageCapabilities(true),
new ImageCapabilities(true),
FlipContents.COPIED,
sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_ON);
}
try {
createBufferStrategy(2, bc);
} catch (AWTException e) {
System.err.println("Warning: cap is not supported: "+bc);
e.printStackTrace();
createBufferStrategy(2);
}
currentBSVSynced = requestVSync;
bs = getBufferStrategy();
String s =
getParent() instanceof Frame ?
((Frame)getParent()).getTitle() : "parent";
System.out.println("Created BS for \"" + s + "\" frame, bs="+bs);
}
public SunVolatileImage(GraphicsConfiguration graphicsConfig,
int width, int height, int transparency,
ImageCapabilities caps)
{
this(null, graphicsConfig, width, height, null, transparency,
caps, UNDEFINED);
}
/**
* Need to override the default behavior because Pixmaps-based
* images are accelerated but not volatile.
*/
@Override
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
if (isConfigValid(gc) && isAccelerationEnabled()) {
return new ImageCapabilities(true);
}
return new ImageCapabilities(false);
}
protected SunVolatileImage(Component comp,
GraphicsConfiguration graphicsConfig,
int width, int height, Object context,
int transparency, ImageCapabilities caps,
int accType)
{
this.comp = comp;
this.graphicsConfig = graphicsConfig;
this.width = width;
this.height = height;
this.forcedAccelSurfaceType = accType;
if (!(transparency == Transparency.OPAQUE ||
transparency == Transparency.BITMASK ||
transparency == Transparency.TRANSLUCENT))
{
throw new IllegalArgumentException("Unknown transparency type:" +
transparency);
}
this.transparency = transparency;
this.volSurfaceManager = createSurfaceManager(context, caps);
SurfaceManager.setManager(this, volSurfaceManager);
// post-construction initialization of the surface manager
volSurfaceManager.initialize();
// clear the background
volSurfaceManager.initContents();
}
private void createBS(boolean requestVSync) {
if (bs != null && requestVSync == currentBSVSynced) {
return;
}
BufferCapabilities bc = defaultBC;
if (requestVSync) {
bc = new sun.java2d.pipe.hw.ExtendedBufferCapabilities(
new ImageCapabilities(true),
new ImageCapabilities(true),
FlipContents.COPIED,
sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_ON);
}
try {
createBufferStrategy(2, bc);
} catch (AWTException e) {
System.err.println("Warning: cap is not supported: "+bc);
e.printStackTrace();
createBufferStrategy(2);
}
currentBSVSynced = requestVSync;
bs = getBufferStrategy();
String s =
getParent() instanceof Frame ?
((Frame)getParent()).getTitle() : "parent";
System.out.println("Created BS for \"" + s + "\" frame, bs="+bs);
}
private void createBS(boolean requestVSync) {
if (bs != null && requestVSync == currentBSVSynced) {
return;
}
BufferCapabilities bc = defaultBC;
if (requestVSync) {
bc = new sun.java2d.pipe.hw.ExtendedBufferCapabilities(
new ImageCapabilities(true),
new ImageCapabilities(true),
FlipContents.COPIED,
sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_ON);
}
try {
createBufferStrategy(2, bc);
} catch (AWTException e) {
System.err.println("Warning: cap is not supported: "+bc);
e.printStackTrace();
createBufferStrategy(2);
}
currentBSVSynced = requestVSync;
bs = getBufferStrategy();
String s =
getParent() instanceof Frame ?
((Frame)getParent()).getTitle() : "parent";
System.out.println("Created BS for \"" + s + "\" frame, bs="+bs);
}
/**
* Creates an ExtendedBufferCapabilities instance with front/back/flip caps
* from the passed caps, and VSYNC_DEFAULT v-sync mode.
*/
public ExtendedBufferCapabilities(ImageCapabilities front,
ImageCapabilities back, FlipContents flip)
{
super(front, back, flip);
this.vsync = VSyncType.VSYNC_DEFAULT;
}
private static void testVolatileImage(GraphicsConfiguration cfg,
boolean accelerated)
{
VolatileImage dst = null;
try {
dst = cfg.createCompatibleVolatileImage(640, 480,
new ImageCapabilities(accelerated));
} catch (AWTException e) {
System.out.println("Unable to create volatile image, skip the test.");
return;
}
renderToVolatileImage(dst);
}
private static void testVolatileImage(GraphicsConfiguration cfg,
boolean accelerated)
{
VolatileImage dst = null;
try {
dst = cfg.createCompatibleVolatileImage(640, 480,
new ImageCapabilities(accelerated));
} catch (AWTException e) {
System.out.println("Unable to create volatile image, skip the test.");
return;
}
renderToVolatileImage(dst);
}
protected SunVolatileImage(Component comp,
GraphicsConfiguration graphicsConfig,
int width, int height, Object context,
int transparency, ImageCapabilities caps,
int accType)
{
this.comp = comp;
this.graphicsConfig = graphicsConfig;
if (width <= 0 || height <= 0) {
throw new IllegalArgumentException("Width (" + width + ")" +
" and height (" + height + ") cannot be <= 0");
}
this.width = width;
this.height = height;
this.forcedAccelSurfaceType = accType;
if (!(transparency == Transparency.OPAQUE ||
transparency == Transparency.BITMASK ||
transparency == Transparency.TRANSLUCENT))
{
throw new IllegalArgumentException("Unknown transparency type:" +
transparency);
}
this.transparency = transparency;
this.volSurfaceManager = createSurfaceManager(context, caps);
SurfaceManager.setManager(this, volSurfaceManager);
// post-construction initialization of the surface manager
volSurfaceManager.initialize();
// clear the background
volSurfaceManager.initContents();
}
public SunVolatileImage(GraphicsConfiguration graphicsConfig,
int width, int height, int transparency,
ImageCapabilities caps)
{
this(null, graphicsConfig, width, height, null, transparency,
caps, UNDEFINED);
}
private void createBS(boolean requestVSync) {
if (bs != null && requestVSync == currentBSVSynced) {
return;
}
BufferCapabilities bc = defaultBC;
if (requestVSync) {
bc = new sun.java2d.pipe.hw.ExtendedBufferCapabilities(
new ImageCapabilities(true),
new ImageCapabilities(true),
FlipContents.COPIED,
sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_ON);
}
try {
createBufferStrategy(2, bc);
} catch (AWTException e) {
System.err.println("Warning: cap is not supported: "+bc);
e.printStackTrace();
createBufferStrategy(2);
}
currentBSVSynced = requestVSync;
bs = getBufferStrategy();
String s =
getParent() instanceof Frame ?
((Frame)getParent()).getTitle() : "parent";
System.out.println("Created BS for \"" + s + "\" frame, bs="+bs);
}
public SunVolatileImage(GraphicsConfiguration graphicsConfig,
int width, int height, int transparency,
ImageCapabilities caps)
{
this(null, graphicsConfig, width, height, null, transparency,
caps, UNDEFINED);
}
public SunVolatileImage(GraphicsConfiguration graphicsConfig,
int width, int height, int transparency,
ImageCapabilities caps)
{
this(null, graphicsConfig, width, height, null, transparency,
caps, UNDEFINED);
}
/**
* Need to override the default behavior because Pixmaps-based
* images are accelerated but not volatile.
*/
@Override
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
if (isConfigValid(gc) && isAccelerationEnabled()) {
// accelerated but not volatile
return new ImageCapabilities(true);
}
// neither accelerated nor volatile
return new ImageCapabilities(false);
}
private static void testVolatileImage(GraphicsConfiguration cfg,
boolean accelerated)
{
VolatileImage dst = null;
try {
dst = cfg.createCompatibleVolatileImage(640, 480,
new ImageCapabilities(accelerated));
} catch (AWTException e) {
System.out.println("Unable to create volatile image, skip the test.");
return;
}
renderToVolatileImage(dst);
}
private void createBS(boolean requestVSync) {
if (bs != null && requestVSync == currentBSVSynced) {
return;
}
BufferCapabilities bc = defaultBC;
if (requestVSync) {
bc = new sun.java2d.pipe.hw.ExtendedBufferCapabilities(
new ImageCapabilities(true),
new ImageCapabilities(true),
FlipContents.COPIED,
sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_ON);
}
try {
createBufferStrategy(2, bc);
} catch (AWTException e) {
System.err.println("Warning: cap is not supported: "+bc);
e.printStackTrace();
createBufferStrategy(2);
}
currentBSVSynced = requestVSync;
bs = getBufferStrategy();
String s =
getParent() instanceof Frame ?
((Frame)getParent()).getTitle() : "parent";
System.out.println("Created BS for \"" + s + "\" frame, bs="+bs);
}
public SunVolatileImage(GraphicsConfiguration graphicsConfig,
int width, int height, int transparency,
ImageCapabilities caps)
{
this(null, graphicsConfig, width, height, null, transparency,
caps, UNDEFINED);
}
/**
* Creates an ExtendedBufferCapabilities instance with front/back/flip caps
* from the passed caps, and VSYNC_DEFAULT v-sync mode.
*/
public ExtendedBufferCapabilities(ImageCapabilities front,
ImageCapabilities back, FlipContents flip)
{
super(front, back, flip);
this.vsync = VSyncType.VSYNC_DEFAULT;
}
public SunVolatileImage(GraphicsConfiguration graphicsConfig,
int width, int height, int transparency,
ImageCapabilities caps)
{
this(null, graphicsConfig, width, height, null, transparency,
caps, UNDEFINED);
}
private void createBS(boolean requestVSync) {
if (bs != null && requestVSync == currentBSVSynced) {
return;
}
BufferCapabilities bc = defaultBC;
if (requestVSync) {
bc = new sun.java2d.pipe.hw.ExtendedBufferCapabilities(
new ImageCapabilities(true),
new ImageCapabilities(true),
FlipContents.COPIED,
sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_ON);
}
try {
createBufferStrategy(2, bc);
} catch (AWTException e) {
System.err.println("Warning: cap is not supported: "+bc);
e.printStackTrace();
createBufferStrategy(2);
}
currentBSVSynced = requestVSync;
bs = getBufferStrategy();
String s =
getParent() instanceof Frame ?
((Frame)getParent()).getTitle() : "parent";
System.out.println("Created BS for \"" + s + "\" frame, bs="+bs);
}
/**
* Need to override the default behavior because Pixmaps-based
* images are accelerated but not volatile.
*/
@Override
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
if (isConfigValid(gc) && isAccelerationEnabled()) {
return new ImageCapabilities(true);
}
return new ImageCapabilities(false);
}
/**
* Need to override the default behavior because Pixmaps-based
* images are accelerated but not volatile.
*/
@Override
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
if (isConfigValid(gc) && isAccelerationEnabled()) {
// accelerated but not volatile
return new ImageCapabilities(true);
}
// neither accelerated nor volatile
return new ImageCapabilities(false);
}
private SunVolatileImage(Component comp,
GraphicsConfiguration graphicsConfig,
int width, int height, Object context,
ImageCapabilities caps)
{
this(comp, graphicsConfig,
width, height, context, Transparency.OPAQUE, caps, UNDEFINED);
}