blob: bf8f63e62be380bfbd69d6d00df52aa484c3ffe6 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.java2d.opengl;
27
28import java.awt.Component;
29import java.awt.GraphicsConfiguration;
30import java.awt.ImageCapabilities;
31import java.awt.Rectangle;
32import java.awt.Transparency;
33import java.awt.image.ColorModel;
34import sun.awt.X11ComponentPeer;
35import sun.awt.image.SunVolatileImage;
36import sun.awt.image.VolatileSurfaceManager;
37import sun.java2d.SurfaceData;
38
39public class GLXVolatileSurfaceManager extends VolatileSurfaceManager {
40
41 private boolean accelerationEnabled;
42
43 public GLXVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
44 super(vImg, context);
45
46 /*
47 * We will attempt to accelerate this image only under the
48 * following conditions:
49 * - the image is opaque OR
50 * - the image is translucent AND
51 * - the GraphicsConfig supports the FBO extension OR
52 * - the GraphicsConfig has a stored alpha channel
53 */
54 int transparency = vImg.getTransparency();
55 GLXGraphicsConfig gc = (GLXGraphicsConfig)vImg.getGraphicsConfig();
56 accelerationEnabled =
57 (transparency == Transparency.OPAQUE) ||
58 ((transparency == Transparency.TRANSLUCENT) &&
59 (gc.isCapPresent(OGLContext.CAPS_EXT_FBOBJECT) ||
60 gc.isCapPresent(OGLContext.CAPS_STORED_ALPHA)));
61 }
62
63 protected boolean isAccelerationEnabled() {
64 return accelerationEnabled;
65 }
66
67 /**
68 * Create a pbuffer-based SurfaceData object (or init the backbuffer
69 * of an existing window if this is a double buffered GraphicsConfig)
70 */
71 protected SurfaceData initAcceleratedSurface() {
72 SurfaceData sData;
73 Component comp = vImg.getComponent();
74 X11ComponentPeer peer =
75 (comp != null) ? (X11ComponentPeer)comp.getPeer() : null;
76
77 try {
78 boolean forceback = false;
79 if (context instanceof Boolean) {
80 forceback = ((Boolean)context).booleanValue();
81 }
82
83 if (forceback) {
84 // peer must be non-null in this case
85 sData = GLXSurfaceData.createData(peer, vImg);
86 } else {
87 GLXGraphicsConfig gc =
88 (GLXGraphicsConfig)vImg.getGraphicsConfig();
89 ColorModel cm = gc.getColorModel(vImg.getTransparency());
90 int type = gc.isCapPresent(OGLContext.CAPS_EXT_FBOBJECT) ?
91 OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;
92 sData = GLXSurfaceData.createData(gc,
93 vImg.getWidth(),
94 vImg.getHeight(),
95 cm, vImg, type);
96 }
97 } catch (NullPointerException ex) {
98 sData = null;
99 } catch (OutOfMemoryError er) {
100 sData = null;
101 }
102
103 return sData;
104 }
105
106 protected boolean isConfigValid(GraphicsConfiguration gc) {
107 return ((gc == null) || (gc == vImg.getGraphicsConfig()));
108 }
109}