8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt.image;
27
28 import java.awt.Color;
29 import java.awt.Graphics;
30 import java.awt.GraphicsConfiguration;
31 import java.awt.GraphicsEnvironment;
32 import java.awt.ImageCapabilities;
33 import java.awt.image.BufferedImage;
34 import java.awt.image.VolatileImage;
35 import sun.awt.DisplayChangedListener;
36 import sun.awt.image.SunVolatileImage;
37 import sun.java2d.SunGraphicsEnvironment;
38 import sun.java2d.SurfaceData;
39 import sun.java2d.loops.CompositeType;
40 import static sun.java2d.pipe.hw.AccelSurface.*;
41
42 /**
43 * This SurfaceManager variant manages an accelerated volatile surface, if it
44 * is possible to create that surface. If there is limited accelerated
45 * memory, or if the volatile surface disappears due to an operating system
46 * event, the VolatileSurfaceManager will attempt to restore the
47 * accelerated surface. If that fails, a system memory surface will be
48 * created in its place.
49 */
50 public abstract class VolatileSurfaceManager
51 extends SurfaceManager
52 implements DisplayChangedListener
53 {
54 /**
55 * A reference to the VolatileImage whose contents are being managed.
56 */
57 protected SunVolatileImage vImg;
58
59 /**
243 /**
244 * Creates a new accelerated surface that is compatible with the
245 * current GraphicsConfiguration. Returns the new accelerated
246 * SurfaceData object, or null if the surface creation was not successful.
247 *
248 * Platform-specific subclasses should initialize an accelerated
249 * surface (e.g. a DirectDraw surface on Windows, an OpenGL FBO,
250 * or an X11 pixmap).
251 */
252 protected abstract SurfaceData initAcceleratedSurface();
253
254 /**
255 * Creates a software-based surface (of type BufImgSurfaceData).
256 * The software representation is only created when needed, which
257 * is only during some situation in which the hardware surface
258 * cannot be allocated. This allows apps to at least run,
259 * albeit more slowly than they would otherwise.
260 */
261 protected SurfaceData getBackupSurface() {
262 if (sdBackup == null) {
263 BufferedImage bImg = vImg.getBackupImage();
264 // Sabotage the acceleration capabilities of the BufImg surface
265 SunWritableRaster.stealTrackable(bImg
266 .getRaster()
267 .getDataBuffer()).setUntrackable();
268 sdBackup = BufImgSurfaceData.createData(bImg);
269 }
270 return sdBackup;
271 }
272
273 /**
274 * Set contents of the current SurfaceData to default state (i.e. clear
275 * the background).
276 */
277 public void initContents() {
278 // images with forced acceleration type may have a null sdCurrent
279 // because we do not create a backup surface for them
280 if (sdCurrent != null) {
281 Graphics g = vImg.createGraphics();
282 g.clearRect(0, 0, vImg.getWidth(), vImg.getHeight());
283 g.dispose();
284 }
285 }
286
287 /**
288 * Called from a SurfaceData object, indicating that our
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt.image;
27
28 import java.awt.Graphics;
29 import java.awt.GraphicsConfiguration;
30 import java.awt.GraphicsEnvironment;
31 import java.awt.ImageCapabilities;
32 import java.awt.geom.AffineTransform;
33 import java.awt.image.BufferedImage;
34 import java.awt.image.VolatileImage;
35 import sun.awt.DisplayChangedListener;
36 import sun.java2d.SunGraphicsEnvironment;
37 import sun.java2d.SurfaceData;
38 import static sun.java2d.pipe.hw.AccelSurface.*;
39
40 /**
41 * This SurfaceManager variant manages an accelerated volatile surface, if it
42 * is possible to create that surface. If there is limited accelerated
43 * memory, or if the volatile surface disappears due to an operating system
44 * event, the VolatileSurfaceManager will attempt to restore the
45 * accelerated surface. If that fails, a system memory surface will be
46 * created in its place.
47 */
48 public abstract class VolatileSurfaceManager
49 extends SurfaceManager
50 implements DisplayChangedListener
51 {
52 /**
53 * A reference to the VolatileImage whose contents are being managed.
54 */
55 protected SunVolatileImage vImg;
56
57 /**
241 /**
242 * Creates a new accelerated surface that is compatible with the
243 * current GraphicsConfiguration. Returns the new accelerated
244 * SurfaceData object, or null if the surface creation was not successful.
245 *
246 * Platform-specific subclasses should initialize an accelerated
247 * surface (e.g. a DirectDraw surface on Windows, an OpenGL FBO,
248 * or an X11 pixmap).
249 */
250 protected abstract SurfaceData initAcceleratedSurface();
251
252 /**
253 * Creates a software-based surface (of type BufImgSurfaceData).
254 * The software representation is only created when needed, which
255 * is only during some situation in which the hardware surface
256 * cannot be allocated. This allows apps to at least run,
257 * albeit more slowly than they would otherwise.
258 */
259 protected SurfaceData getBackupSurface() {
260 if (sdBackup == null) {
261 GraphicsConfiguration gc = vImg.getGraphicsConfig();
262 AffineTransform tx = gc.getDefaultTransform();
263 double scaleX = tx.getScaleX();
264 double scaleY = tx.getScaleY();
265 BufferedImage bImg = vImg.getBackupImage(scaleX, scaleY);
266 // Sabotage the acceleration capabilities of the BufImg surface
267 SunWritableRaster.stealTrackable(bImg
268 .getRaster()
269 .getDataBuffer()).setUntrackable();
270 sdBackup = BufImgSurfaceData.createData(bImg, scaleX, scaleY);
271 }
272 return sdBackup;
273 }
274
275 /**
276 * Set contents of the current SurfaceData to default state (i.e. clear
277 * the background).
278 */
279 public void initContents() {
280 // images with forced acceleration type may have a null sdCurrent
281 // because we do not create a backup surface for them
282 if (sdCurrent != null) {
283 Graphics g = vImg.createGraphics();
284 g.clearRect(0, 0, vImg.getWidth(), vImg.getHeight());
285 g.dispose();
286 }
287 }
288
289 /**
290 * Called from a SurfaceData object, indicating that our
|