author | tdv |
Tue, 22 Jul 2008 11:24:32 -0700 | |
changeset 888 | c7009cf0001f |
parent 887 | 0aab8d3fa11a |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
888
c7009cf0001f
6728492: typo in copyrights in some files touched by the d3d pipeline port
tdv
parents:
887
diff
changeset
|
2 |
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 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 |
||
26 |
package sun.java2d.opengl; |
|
27 |
||
887 | 28 |
import java.awt.BufferCapabilities; |
29 |
import static java.awt.BufferCapabilities.FlipContents.*; |
|
2 | 30 |
import java.awt.Component; |
31 |
import java.awt.GraphicsConfiguration; |
|
32 |
import java.awt.Transparency; |
|
33 |
import java.awt.image.ColorModel; |
|
34 |
import sun.awt.X11ComponentPeer; |
|
35 |
import sun.awt.image.SunVolatileImage; |
|
36 |
import sun.awt.image.VolatileSurfaceManager; |
|
887 | 37 |
import sun.java2d.BackBufferCapsProvider; |
2 | 38 |
import sun.java2d.SurfaceData; |
887 | 39 |
import static sun.java2d.opengl.OGLContext.OGLContextCaps.*; |
40 |
import sun.java2d.pipe.hw.ExtendedBufferCapabilities; |
|
41 |
import static sun.java2d.pipe.hw.AccelSurface.*; |
|
42 |
import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*; |
|
2 | 43 |
|
44 |
public class GLXVolatileSurfaceManager extends VolatileSurfaceManager { |
|
45 |
||
46 |
private boolean accelerationEnabled; |
|
47 |
||
48 |
public GLXVolatileSurfaceManager(SunVolatileImage vImg, Object context) { |
|
49 |
super(vImg, context); |
|
50 |
||
51 |
/* |
|
52 |
* We will attempt to accelerate this image only under the |
|
53 |
* following conditions: |
|
54 |
* - the image is opaque OR |
|
55 |
* - the image is translucent AND |
|
56 |
* - the GraphicsConfig supports the FBO extension OR |
|
57 |
* - the GraphicsConfig has a stored alpha channel |
|
58 |
*/ |
|
59 |
int transparency = vImg.getTransparency(); |
|
60 |
GLXGraphicsConfig gc = (GLXGraphicsConfig)vImg.getGraphicsConfig(); |
|
61 |
accelerationEnabled = |
|
62 |
(transparency == Transparency.OPAQUE) || |
|
63 |
((transparency == Transparency.TRANSLUCENT) && |
|
887 | 64 |
(gc.isCapPresent(CAPS_EXT_FBOBJECT) || |
65 |
gc.isCapPresent(CAPS_STORED_ALPHA))); |
|
2 | 66 |
} |
67 |
||
68 |
protected boolean isAccelerationEnabled() { |
|
69 |
return accelerationEnabled; |
|
70 |
} |
|
71 |
||
72 |
/** |
|
73 |
* Create a pbuffer-based SurfaceData object (or init the backbuffer |
|
74 |
* of an existing window if this is a double buffered GraphicsConfig) |
|
75 |
*/ |
|
76 |
protected SurfaceData initAcceleratedSurface() { |
|
77 |
SurfaceData sData; |
|
78 |
Component comp = vImg.getComponent(); |
|
79 |
X11ComponentPeer peer = |
|
80 |
(comp != null) ? (X11ComponentPeer)comp.getPeer() : null; |
|
81 |
||
82 |
try { |
|
887 | 83 |
boolean createVSynced = false; |
2 | 84 |
boolean forceback = false; |
85 |
if (context instanceof Boolean) { |
|
86 |
forceback = ((Boolean)context).booleanValue(); |
|
887 | 87 |
if (forceback && peer instanceof BackBufferCapsProvider) { |
88 |
BackBufferCapsProvider provider = |
|
89 |
(BackBufferCapsProvider)peer; |
|
90 |
BufferCapabilities caps = provider.getBackBufferCaps(); |
|
91 |
if (caps instanceof ExtendedBufferCapabilities) { |
|
92 |
ExtendedBufferCapabilities ebc = |
|
93 |
(ExtendedBufferCapabilities)caps; |
|
94 |
if (ebc.getVSync() == VSYNC_ON && |
|
95 |
ebc.getFlipContents() == COPIED) |
|
96 |
{ |
|
97 |
createVSynced = true; |
|
98 |
forceback = false; |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
2 | 102 |
} |
103 |
||
104 |
if (forceback) { |
|
105 |
// peer must be non-null in this case |
|
887 | 106 |
sData = GLXSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER); |
2 | 107 |
} else { |
108 |
GLXGraphicsConfig gc = |
|
109 |
(GLXGraphicsConfig)vImg.getGraphicsConfig(); |
|
110 |
ColorModel cm = gc.getColorModel(vImg.getTransparency()); |
|
887 | 111 |
int type = vImg.getForcedAccelSurfaceType(); |
112 |
// if acceleration type is forced (type != UNDEFINED) then |
|
113 |
// use the forced type, otherwise choose one based on caps |
|
114 |
if (type == OGLSurfaceData.UNDEFINED) { |
|
115 |
type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ? |
|
116 |
OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER; |
|
117 |
} |
|
118 |
if (createVSynced) { |
|
119 |
sData = GLXSurfaceData.createData(peer, vImg, type); |
|
120 |
} else { |
|
121 |
sData = GLXSurfaceData.createData(gc, |
|
122 |
vImg.getWidth(), |
|
123 |
vImg.getHeight(), |
|
124 |
cm, vImg, type); |
|
125 |
} |
|
2 | 126 |
} |
127 |
} catch (NullPointerException ex) { |
|
128 |
sData = null; |
|
129 |
} catch (OutOfMemoryError er) { |
|
130 |
sData = null; |
|
131 |
} |
|
132 |
||
133 |
return sData; |
|
134 |
} |
|
135 |
||
887 | 136 |
@Override |
2 | 137 |
protected boolean isConfigValid(GraphicsConfiguration gc) { |
138 |
return ((gc == null) || (gc == vImg.getGraphicsConfig())); |
|
139 |
} |
|
887 | 140 |
|
141 |
@Override |
|
142 |
public void initContents() { |
|
143 |
if (vImg.getForcedAccelSurfaceType() != OGLSurfaceData.TEXTURE) { |
|
144 |
super.initContents(); |
|
145 |
} |
|
146 |
} |
|
2 | 147 |
} |