23 * questions.
24 */
25
26 package sun.awt.image;
27
28 import java.awt.AlphaComposite;
29 import java.awt.Color;
30 import java.awt.Component;
31 import java.awt.Font;
32 import java.awt.Graphics2D;
33 import java.awt.GraphicsConfiguration;
34 import java.awt.ImageCapabilities;
35 import java.awt.Transparency;
36 import java.awt.image.BufferedImage;
37 import java.awt.image.ImageObserver;
38 import java.awt.image.VolatileImage;
39 import sun.java2d.SunGraphics2D;
40 import sun.java2d.SurfaceManagerFactory;
41 import sun.java2d.DestSurfaceProvider;
42 import sun.java2d.Surface;
43 import static sun.java2d.pipe.hw.AccelSurface.*;
44
45 /**
46 * This class is the base implementation of the VolatileImage
47 * abstract class. The class implements most of the standard Image
48 * methods (width, height, etc.) but delegates all surface management
49 * issues to a platform-specific VolatileSurfaceManager. When a new instance
50 * of SunVolatileImage is created, it automatically creates an
51 * appropriate VolatileSurfaceManager for the GraphicsConfiguration
52 * under which this SunVolatileImage was created.
53 */
54 public class SunVolatileImage extends VolatileImage
55 implements DestSurfaceProvider
56 {
57
58 protected VolatileSurfaceManager volSurfaceManager;
59 protected Component comp;
60 private GraphicsConfiguration graphicsConfig;
61 private Font defaultFont;
62 private int width, height;
228 return getWidth();
229 }
230
231 public int getHeight(ImageObserver observer) {
232 return getHeight();
233 }
234
235 /**
236 * This method creates a BufferedImage intended for use as a "snapshot"
237 * or a backup surface.
238 */
239 public BufferedImage getBackupImage() {
240 return getBackupImage(1, 1);
241 }
242
243 /**
244 * This method creates a BufferedImage intended for use as a "snapshot"
245 * or a backup surface with the given horizontal and vertical scale factors.
246 */
247 public BufferedImage getBackupImage(double scaleX, double scaleY) {
248 int w = (int) Math.ceil(getWidth() * scaleX);
249 int h = (int) Math.ceil(getHeight() * scaleY);
250 return graphicsConfig.createCompatibleImage(w, h, getTransparency());
251 }
252
253 public BufferedImage getSnapshot() {
254 BufferedImage bi = getBackupImage();
255 Graphics2D g = bi.createGraphics();
256 g.setComposite(AlphaComposite.Src);
257 g.drawImage(this, 0, 0, null);
258 g.dispose();
259 return bi;
260 }
261
262 public int validate(GraphicsConfiguration gc) {
263 return volSurfaceManager.validate(gc);
264 }
265
266 public boolean contentsLost() {
267 return volSurfaceManager.contentsLost();
268 }
269
|
23 * questions.
24 */
25
26 package sun.awt.image;
27
28 import java.awt.AlphaComposite;
29 import java.awt.Color;
30 import java.awt.Component;
31 import java.awt.Font;
32 import java.awt.Graphics2D;
33 import java.awt.GraphicsConfiguration;
34 import java.awt.ImageCapabilities;
35 import java.awt.Transparency;
36 import java.awt.image.BufferedImage;
37 import java.awt.image.ImageObserver;
38 import java.awt.image.VolatileImage;
39 import sun.java2d.SunGraphics2D;
40 import sun.java2d.SurfaceManagerFactory;
41 import sun.java2d.DestSurfaceProvider;
42 import sun.java2d.Surface;
43 import sun.java2d.pipe.Region;
44 import static sun.java2d.pipe.hw.AccelSurface.*;
45
46 /**
47 * This class is the base implementation of the VolatileImage
48 * abstract class. The class implements most of the standard Image
49 * methods (width, height, etc.) but delegates all surface management
50 * issues to a platform-specific VolatileSurfaceManager. When a new instance
51 * of SunVolatileImage is created, it automatically creates an
52 * appropriate VolatileSurfaceManager for the GraphicsConfiguration
53 * under which this SunVolatileImage was created.
54 */
55 public class SunVolatileImage extends VolatileImage
56 implements DestSurfaceProvider
57 {
58
59 protected VolatileSurfaceManager volSurfaceManager;
60 protected Component comp;
61 private GraphicsConfiguration graphicsConfig;
62 private Font defaultFont;
63 private int width, height;
229 return getWidth();
230 }
231
232 public int getHeight(ImageObserver observer) {
233 return getHeight();
234 }
235
236 /**
237 * This method creates a BufferedImage intended for use as a "snapshot"
238 * or a backup surface.
239 */
240 public BufferedImage getBackupImage() {
241 return getBackupImage(1, 1);
242 }
243
244 /**
245 * This method creates a BufferedImage intended for use as a "snapshot"
246 * or a backup surface with the given horizontal and vertical scale factors.
247 */
248 public BufferedImage getBackupImage(double scaleX, double scaleY) {
249 int w = Region.clipRound(getWidth() * scaleX);
250 int h = Region.clipRound(getHeight() * scaleY);
251 return graphicsConfig.createCompatibleImage(w, h, getTransparency());
252 }
253
254 public BufferedImage getSnapshot() {
255 BufferedImage bi = getBackupImage();
256 Graphics2D g = bi.createGraphics();
257 g.setComposite(AlphaComposite.Src);
258 g.drawImage(this, 0, 0, null);
259 g.dispose();
260 return bi;
261 }
262
263 public int validate(GraphicsConfiguration gc) {
264 return volSurfaceManager.validate(gc);
265 }
266
267 public boolean contentsLost() {
268 return volSurfaceManager.contentsLost();
269 }
270
|