1 /*
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. 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. Oracle designates this
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
74 * to an OpenGLTexture object via glTexSubImage2D(). One can also copy a
75 * surface of type OpenGLTexture to an OpenGLSurface by binding the texture
76 * to a quad and then rendering it to the destination surface (this process
77 * is known as "texture mapping").
78 *
79 * OpenGLSurfaceRTT
80 * This kind of surface can be thought of as a sort of hybrid between
81 * OpenGLSurface and OpenGLTexture, in that one can render to this kind of
82 * surface as if it were of type OpenGLSurface, but the process of copying
83 * this kind of surface to another is more like an OpenGLTexture. (Note that
84 * "RTT" stands for "render-to-texture".)
85 *
86 * In addition to these SurfaceType variants, we have also defined some
87 * constants that describe in more detail the type of underlying OpenGL
88 * surface. This table helps explain the relationships between those
89 * "type" constants and their corresponding SurfaceType:
90 *
91 * OGL Type Corresponding SurfaceType
92 * -------- -------------------------
93 * WINDOW OpenGLSurface
94 * PBUFFER OpenGLSurface
95 * TEXTURE OpenGLTexture
96 * FLIP_BACKBUFFER OpenGLSurface
97 * FBOBJECT OpenGLSurfaceRTT
98 */
99 public abstract class OGLSurfaceData extends SurfaceData
100 implements AccelSurface {
101
102 /**
103 * OGL-specific surface types
104 *
105 * @see sun.java2d.pipe.hw.AccelSurface
106 */
107 public static final int PBUFFER = RT_PLAIN;
108 public static final int FBOBJECT = RT_TEXTURE;
109
110 /**
111 * Pixel formats
112 */
113 public static final int PF_INT_ARGB = 0;
114 public static final int PF_INT_ARGB_PRE = 1;
115 public static final int PF_INT_RGB = 2;
116 public static final int PF_INT_RGBX = 3;
117 public static final int PF_INT_BGR = 4;
118 public static final int PF_INT_BGRX = 5;
119 public static final int PF_USHORT_565_RGB = 6;
120 public static final int PF_USHORT_555_RGB = 7;
121 public static final int PF_USHORT_555_RGBX = 8;
122 public static final int PF_BYTE_GRAY = 9;
123 public static final int PF_USHORT_GRAY = 10;
124 public static final int PF_3BYTE_BGR = 11;
125
126 /**
127 * SurfaceTypes
155 protected int type;
156 // these fields are set from the native code when the surface is
157 // initialized
158 private int nativeWidth, nativeHeight;
159
160 protected static OGLRenderer oglRenderPipe;
161 protected static PixelToParallelogramConverter oglTxRenderPipe;
162 protected static ParallelogramPipe oglAAPgramPipe;
163 protected static OGLTextRenderer oglTextPipe;
164 protected static OGLDrawImage oglImagePipe;
165
166 protected native boolean initTexture(long pData,
167 boolean isOpaque, boolean texNonPow2,
168 boolean texRect,
169 int width, int height);
170 protected native boolean initFBObject(long pData,
171 boolean isOpaque, boolean texNonPow2,
172 boolean texRect,
173 int width, int height);
174 protected native boolean initFlipBackbuffer(long pData);
175 protected abstract boolean initPbuffer(long pData, long pConfigInfo,
176 boolean isOpaque,
177 int width, int height);
178
179 private native int getTextureTarget(long pData);
180 private native int getTextureID(long pData);
181
182 static {
183 if (!GraphicsEnvironment.isHeadless()) {
184 // fbobject currently enabled by default; use "false" to disable
185 String fbo = java.security.AccessController.doPrivileged(
186 new sun.security.action.GetPropertyAction(
187 "sun.java2d.opengl.fbobject"));
188 isFBObjectEnabled = !"false".equals(fbo);
189
190 // lcdshader currently enabled by default; use "false" to disable
191 String lcd = java.security.AccessController.doPrivileged(
192 new sun.security.action.GetPropertyAction(
193 "sun.java2d.opengl.lcdshader"));
194 isLCDShaderEnabled = !"false".equals(lcd);
195
196 // biopshader currently enabled by default; use "false" to disable
197 String biop = java.security.AccessController.doPrivileged(
233 this.graphicsConfig = gc;
234 this.type = type;
235 setBlitProxyKey(gc.getProxyKey());
236 }
237
238 @Override
239 public SurfaceDataProxy makeProxyFor(SurfaceData srcData) {
240 return OGLSurfaceDataProxy.createProxy(srcData, graphicsConfig);
241 }
242
243 /**
244 * Returns the appropriate SurfaceType corresponding to the given OpenGL
245 * surface type constant (e.g. TEXTURE -> OpenGLTexture).
246 */
247 private static SurfaceType getCustomSurfaceType(int oglType) {
248 switch (oglType) {
249 case TEXTURE:
250 return OpenGLTexture;
251 case FBOBJECT:
252 return OpenGLSurfaceRTT;
253 case PBUFFER:
254 default:
255 return OpenGLSurface;
256 }
257 }
258
259 /**
260 * Note: This should only be called from the QFT under the AWT lock.
261 * This method is kept separate from the initSurface() method below just
262 * to keep the code a bit cleaner.
263 */
264 private void initSurfaceNow(int width, int height) {
265 boolean isOpaque = (getTransparency() == Transparency.OPAQUE);
266 boolean success = false;
267
268 switch (type) {
269 case PBUFFER:
270 success = initPbuffer(getNativeOps(),
271 graphicsConfig.getNativeConfigInfo(),
272 isOpaque,
273 width, height);
274 break;
275
276 case TEXTURE:
277 success = initTexture(getNativeOps(),
278 isOpaque, isTexNonPow2Available(),
279 isTexRectAvailable(),
280 width, height);
281 break;
282
283 case FBOBJECT:
284 success = initFBObject(getNativeOps(),
285 isOpaque, isTexNonPow2Available(),
286 isTexRectAvailable(),
287 width, height);
288 break;
289
290 case FLIP_BACKBUFFER:
291 success = initFlipBackbuffer(getNativeOps());
292 break;
293
294 default:
295 break;
296 }
297
298 if (!success) {
299 throw new OutOfMemoryError("can't create offscreen surface");
300 }
301 }
302
303 /**
304 * Initializes the appropriate OpenGL offscreen surface based on the value
305 * of the type parameter. If the surface creation fails for any reason,
306 * an OutOfMemoryError will be thrown.
307 */
308 protected void initSurface(final int width, final int height) {
309 OGLRenderQueue rq = OGLRenderQueue.getInstance();
310 rq.lock();
311 try {
312 switch (type) {
313 case TEXTURE:
314 case PBUFFER:
315 case FBOBJECT:
316 // need to make sure the context is current before
317 // creating the texture (or pbuffer, or fbobject)
318 OGLContext.setScratchSurface(graphicsConfig);
319 break;
320 default:
321 break;
322 }
323 rq.flushAndInvokeNow(new Runnable() {
324 public void run() {
325 initSurfaceNow(width, height);
326 }
327 });
328 } finally {
329 rq.unlock();
330 }
331 }
332
333 /**
334 * Returns the OGLContext for the GraphicsConfig associated with this
335 * surface.
336 */
337 public final OGLContext getContext() {
|
1 /*
2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. 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. Oracle designates this
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
74 * to an OpenGLTexture object via glTexSubImage2D(). One can also copy a
75 * surface of type OpenGLTexture to an OpenGLSurface by binding the texture
76 * to a quad and then rendering it to the destination surface (this process
77 * is known as "texture mapping").
78 *
79 * OpenGLSurfaceRTT
80 * This kind of surface can be thought of as a sort of hybrid between
81 * OpenGLSurface and OpenGLTexture, in that one can render to this kind of
82 * surface as if it were of type OpenGLSurface, but the process of copying
83 * this kind of surface to another is more like an OpenGLTexture. (Note that
84 * "RTT" stands for "render-to-texture".)
85 *
86 * In addition to these SurfaceType variants, we have also defined some
87 * constants that describe in more detail the type of underlying OpenGL
88 * surface. This table helps explain the relationships between those
89 * "type" constants and their corresponding SurfaceType:
90 *
91 * OGL Type Corresponding SurfaceType
92 * -------- -------------------------
93 * WINDOW OpenGLSurface
94 * TEXTURE OpenGLTexture
95 * FLIP_BACKBUFFER OpenGLSurface
96 * FBOBJECT OpenGLSurfaceRTT
97 */
98 public abstract class OGLSurfaceData extends SurfaceData
99 implements AccelSurface {
100
101 /**
102 * OGL-specific surface types
103 *
104 * @see sun.java2d.pipe.hw.AccelSurface
105 */
106 public static final int FBOBJECT = RT_TEXTURE;
107
108 /**
109 * Pixel formats
110 */
111 public static final int PF_INT_ARGB = 0;
112 public static final int PF_INT_ARGB_PRE = 1;
113 public static final int PF_INT_RGB = 2;
114 public static final int PF_INT_RGBX = 3;
115 public static final int PF_INT_BGR = 4;
116 public static final int PF_INT_BGRX = 5;
117 public static final int PF_USHORT_565_RGB = 6;
118 public static final int PF_USHORT_555_RGB = 7;
119 public static final int PF_USHORT_555_RGBX = 8;
120 public static final int PF_BYTE_GRAY = 9;
121 public static final int PF_USHORT_GRAY = 10;
122 public static final int PF_3BYTE_BGR = 11;
123
124 /**
125 * SurfaceTypes
153 protected int type;
154 // these fields are set from the native code when the surface is
155 // initialized
156 private int nativeWidth, nativeHeight;
157
158 protected static OGLRenderer oglRenderPipe;
159 protected static PixelToParallelogramConverter oglTxRenderPipe;
160 protected static ParallelogramPipe oglAAPgramPipe;
161 protected static OGLTextRenderer oglTextPipe;
162 protected static OGLDrawImage oglImagePipe;
163
164 protected native boolean initTexture(long pData,
165 boolean isOpaque, boolean texNonPow2,
166 boolean texRect,
167 int width, int height);
168 protected native boolean initFBObject(long pData,
169 boolean isOpaque, boolean texNonPow2,
170 boolean texRect,
171 int width, int height);
172 protected native boolean initFlipBackbuffer(long pData);
173
174 private native int getTextureTarget(long pData);
175 private native int getTextureID(long pData);
176
177 static {
178 if (!GraphicsEnvironment.isHeadless()) {
179 // fbobject currently enabled by default; use "false" to disable
180 String fbo = java.security.AccessController.doPrivileged(
181 new sun.security.action.GetPropertyAction(
182 "sun.java2d.opengl.fbobject"));
183 isFBObjectEnabled = !"false".equals(fbo);
184
185 // lcdshader currently enabled by default; use "false" to disable
186 String lcd = java.security.AccessController.doPrivileged(
187 new sun.security.action.GetPropertyAction(
188 "sun.java2d.opengl.lcdshader"));
189 isLCDShaderEnabled = !"false".equals(lcd);
190
191 // biopshader currently enabled by default; use "false" to disable
192 String biop = java.security.AccessController.doPrivileged(
228 this.graphicsConfig = gc;
229 this.type = type;
230 setBlitProxyKey(gc.getProxyKey());
231 }
232
233 @Override
234 public SurfaceDataProxy makeProxyFor(SurfaceData srcData) {
235 return OGLSurfaceDataProxy.createProxy(srcData, graphicsConfig);
236 }
237
238 /**
239 * Returns the appropriate SurfaceType corresponding to the given OpenGL
240 * surface type constant (e.g. TEXTURE -> OpenGLTexture).
241 */
242 private static SurfaceType getCustomSurfaceType(int oglType) {
243 switch (oglType) {
244 case TEXTURE:
245 return OpenGLTexture;
246 case FBOBJECT:
247 return OpenGLSurfaceRTT;
248 default:
249 return OpenGLSurface;
250 }
251 }
252
253 /**
254 * Note: This should only be called from the QFT under the AWT lock.
255 * This method is kept separate from the initSurface() method below just
256 * to keep the code a bit cleaner.
257 */
258 private void initSurfaceNow(int width, int height) {
259 boolean isOpaque = (getTransparency() == Transparency.OPAQUE);
260 boolean success = false;
261
262 switch (type) {
263 case TEXTURE:
264 success = initTexture(getNativeOps(),
265 isOpaque, isTexNonPow2Available(),
266 isTexRectAvailable(),
267 width, height);
268 break;
269
270 case FBOBJECT:
271 success = initFBObject(getNativeOps(),
272 isOpaque, isTexNonPow2Available(),
273 isTexRectAvailable(),
274 width, height);
275 break;
276
277 case FLIP_BACKBUFFER:
278 success = initFlipBackbuffer(getNativeOps());
279 break;
280
281 default:
282 break;
283 }
284
285 if (!success) {
286 throw new OutOfMemoryError("can't create offscreen surface");
287 }
288 }
289
290 /**
291 * Initializes the appropriate OpenGL offscreen surface based on the value
292 * of the type parameter. If the surface creation fails for any reason,
293 * an OutOfMemoryError will be thrown.
294 */
295 protected void initSurface(final int width, final int height) {
296 OGLRenderQueue rq = OGLRenderQueue.getInstance();
297 rq.lock();
298 try {
299 switch (type) {
300 case TEXTURE:
301 case FBOBJECT:
302 // need to make sure the context is current before
303 // creating the texture or fbobject
304 OGLContext.setScratchSurface(graphicsConfig);
305 break;
306 default:
307 break;
308 }
309 rq.flushAndInvokeNow(new Runnable() {
310 public void run() {
311 initSurfaceNow(width, height);
312 }
313 });
314 } finally {
315 rq.unlock();
316 }
317 }
318
319 /**
320 * Returns the OGLContext for the GraphicsConfig associated with this
321 * surface.
322 */
323 public final OGLContext getContext() {
|