12047
|
1 |
/*
|
|
2 |
* Copyright (c) 2011, 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
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
#import <stdlib.h>
|
|
27 |
#import <JavaNativeFoundation/JavaNativeFoundation.h>
|
|
28 |
|
|
29 |
#import "sun_java2d_opengl_CGLSurfaceData.h"
|
|
30 |
|
|
31 |
#import "jni.h"
|
|
32 |
#import "jni_util.h"
|
|
33 |
#import "OGLRenderQueue.h"
|
|
34 |
#import "CGLGraphicsConfig.h"
|
|
35 |
#import "CGLSurfaceData.h"
|
|
36 |
#import "CGLLayer.h"
|
|
37 |
#import "ThreadUtilities.h"
|
|
38 |
|
|
39 |
/* JDK's glext.h is already included and will prevent the Apple glext.h
|
|
40 |
* being included, so define the externs directly
|
|
41 |
*/
|
|
42 |
extern void glBindFramebufferEXT(GLenum target, GLuint framebuffer);
|
|
43 |
extern CGLError CGLTexImageIOSurface2D(
|
|
44 |
CGLContextObj ctx, GLenum target, GLenum internal_format,
|
|
45 |
GLsizei width, GLsizei height, GLenum format, GLenum type,
|
|
46 |
IOSurfaceRef ioSurface, GLuint plane);
|
|
47 |
|
|
48 |
/**
|
|
49 |
* The methods in this file implement the native windowing system specific
|
|
50 |
* layer (CGL) for the OpenGL-based Java 2D pipeline.
|
|
51 |
*/
|
|
52 |
|
|
53 |
#pragma mark -
|
|
54 |
#pragma mark "--- Mac OS X specific methods for GL pipeline ---"
|
|
55 |
|
|
56 |
// TODO: hack that's called from OGLRenderQueue to test out unlockFocus behavior
|
|
57 |
#if 0
|
|
58 |
void
|
|
59 |
OGLSD_UnlockFocus(OGLContext *oglc, OGLSDOps *dstOps)
|
|
60 |
{
|
|
61 |
CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
|
|
62 |
CGLSDOps *cglsdo = (CGLSDOps *)dstOps->privOps;
|
|
63 |
fprintf(stderr, "about to unlock focus: %p %p\n",
|
|
64 |
cglsdo->peerData, ctxinfo->context);
|
|
65 |
|
|
66 |
NSOpenGLView *nsView = cglsdo->peerData;
|
|
67 |
if (nsView != NULL) {
|
|
68 |
JNF_COCOA_ENTER(env);
|
|
69 |
[nsView unlockFocus];
|
|
70 |
JNF_COCOA_EXIT(env);
|
|
71 |
}
|
|
72 |
}
|
|
73 |
#endif
|
|
74 |
|
|
75 |
/**
|
|
76 |
* Makes the given context current to its associated "scratch" surface. If
|
|
77 |
* the operation is successful, this method will return JNI_TRUE; otherwise,
|
|
78 |
* returns JNI_FALSE.
|
|
79 |
*/
|
|
80 |
static jboolean
|
|
81 |
CGLSD_MakeCurrentToScratch(JNIEnv *env, OGLContext *oglc)
|
|
82 |
{
|
|
83 |
J2dTraceLn(J2D_TRACE_INFO, "CGLSD_MakeCurrentToScratch");
|
|
84 |
|
|
85 |
if (oglc == NULL) {
|
|
86 |
J2dRlsTraceLn(J2D_TRACE_ERROR,
|
|
87 |
"CGLSD_MakeCurrentToScratch: context is null");
|
|
88 |
return JNI_FALSE;
|
|
89 |
}
|
|
90 |
|
|
91 |
JNF_COCOA_ENTER(env);
|
|
92 |
|
|
93 |
CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
|
|
94 |
#if USE_NSVIEW_FOR_SCRATCH
|
|
95 |
[ctxinfo->context makeCurrentContext];
|
|
96 |
[ctxinfo->context setView: ctxinfo->scratchSurface];
|
|
97 |
#else
|
|
98 |
[ctxinfo->context clearDrawable];
|
|
99 |
[ctxinfo->context makeCurrentContext];
|
|
100 |
[ctxinfo->context setPixelBuffer: ctxinfo->scratchSurface
|
|
101 |
cubeMapFace: 0
|
|
102 |
mipMapLevel: 0
|
|
103 |
currentVirtualScreen: [ctxinfo->context currentVirtualScreen]];
|
|
104 |
#endif
|
|
105 |
|
|
106 |
JNF_COCOA_EXIT(env);
|
|
107 |
|
|
108 |
return JNI_TRUE;
|
|
109 |
}
|
|
110 |
|
|
111 |
/**
|
|
112 |
* This function disposes of any native windowing system resources associated
|
|
113 |
* with this surface. For instance, if the given OGLSDOps is of type
|
|
114 |
* OGLSD_PBUFFER, this method implementation will destroy the actual pbuffer
|
|
115 |
* surface.
|
|
116 |
*/
|
|
117 |
void
|
|
118 |
OGLSD_DestroyOGLSurface(JNIEnv *env, OGLSDOps *oglsdo)
|
|
119 |
{
|
|
120 |
J2dTraceLn(J2D_TRACE_INFO, "OGLSD_DestroyOGLSurface");
|
|
121 |
|
|
122 |
JNF_COCOA_ENTER(env);
|
|
123 |
|
|
124 |
CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps;
|
|
125 |
if (oglsdo->drawableType == OGLSD_PBUFFER) {
|
|
126 |
if (oglsdo->textureID != 0) {
|
|
127 |
j2d_glDeleteTextures(1, &oglsdo->textureID);
|
|
128 |
oglsdo->textureID = 0;
|
|
129 |
}
|
|
130 |
if (cglsdo->pbuffer != NULL) {
|
|
131 |
[cglsdo->pbuffer release];
|
|
132 |
cglsdo->pbuffer = NULL;
|
|
133 |
}
|
|
134 |
} else if (oglsdo->drawableType == OGLSD_WINDOW) {
|
|
135 |
// detach the NSView from the NSOpenGLContext
|
|
136 |
CGLGraphicsConfigInfo *cglInfo = cglsdo->configInfo;
|
|
137 |
OGLContext *oglc = cglInfo->context;
|
|
138 |
CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
|
|
139 |
[ctxinfo->context clearDrawable];
|
|
140 |
}
|
|
141 |
|
|
142 |
oglsdo->drawableType = OGLSD_UNDEFINED;
|
|
143 |
|
|
144 |
JNF_COCOA_EXIT(env);
|
|
145 |
}
|
|
146 |
|
|
147 |
/**
|
|
148 |
* Returns a pointer (as a jlong) to the native CGLGraphicsConfigInfo
|
|
149 |
* associated with the given OGLSDOps. This method can be called from
|
|
150 |
* shared code to retrieve the native GraphicsConfig data in a platform-
|
|
151 |
* independent manner.
|
|
152 |
*/
|
|
153 |
jlong
|
|
154 |
OGLSD_GetNativeConfigInfo(OGLSDOps *oglsdo)
|
|
155 |
{
|
|
156 |
J2dTraceLn(J2D_TRACE_INFO, "OGLSD_GetNativeConfigInfo");
|
|
157 |
|
|
158 |
if (oglsdo == NULL) {
|
|
159 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_GetNativeConfigInfo: ops are null");
|
|
160 |
return 0L;
|
|
161 |
}
|
|
162 |
|
|
163 |
CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps;
|
|
164 |
if (cglsdo == NULL) {
|
|
165 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_GetNativeConfigInfo: cgl ops are null");
|
|
166 |
return 0L;
|
|
167 |
}
|
|
168 |
|
|
169 |
return ptr_to_jlong(cglsdo->configInfo);
|
|
170 |
}
|
|
171 |
|
|
172 |
/**
|
|
173 |
* Makes the given GraphicsConfig's context current to its associated
|
|
174 |
* "scratch" surface. If there is a problem making the context current,
|
|
175 |
* this method will return NULL; otherwise, returns a pointer to the
|
|
176 |
* OGLContext that is associated with the given GraphicsConfig.
|
|
177 |
*/
|
|
178 |
OGLContext *
|
|
179 |
OGLSD_SetScratchSurface(JNIEnv *env, jlong pConfigInfo)
|
|
180 |
{
|
|
181 |
J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SetScratchContext");
|
|
182 |
|
|
183 |
CGLGraphicsConfigInfo *cglInfo = (CGLGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
|
|
184 |
if (cglInfo == NULL) {
|
|
185 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_SetScratchContext: cgl config info is null");
|
|
186 |
return NULL;
|
|
187 |
}
|
|
188 |
|
|
189 |
OGLContext *oglc = cglInfo->context;
|
|
190 |
CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
|
|
191 |
|
|
192 |
JNF_COCOA_ENTER(env);
|
|
193 |
|
|
194 |
// avoid changing the context's target view whenever possible, since
|
|
195 |
// calling setView causes flickering; as long as our context is current
|
|
196 |
// to some view, it's not necessary to switch to the scratch surface
|
|
197 |
if ([ctxinfo->context view] == nil) {
|
|
198 |
// it seems to be necessary to explicitly flush between context changes
|
|
199 |
OGLContext *currentContext = OGLRenderQueue_GetCurrentContext();
|
|
200 |
if (currentContext != NULL) {
|
|
201 |
j2d_glFlush();
|
|
202 |
}
|
|
203 |
|
|
204 |
if (!CGLSD_MakeCurrentToScratch(env, oglc)) {
|
|
205 |
return NULL;
|
|
206 |
}
|
|
207 |
} else if ([NSOpenGLContext currentContext] == nil) {
|
|
208 |
[ctxinfo->context makeCurrentContext];
|
|
209 |
}
|
|
210 |
|
|
211 |
if (OGLC_IS_CAP_PRESENT(oglc, CAPS_EXT_FBOBJECT)) {
|
|
212 |
// the GL_EXT_framebuffer_object extension is present, so this call
|
|
213 |
// will ensure that we are bound to the scratch surface (and not
|
|
214 |
// some other framebuffer object)
|
|
215 |
j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
|
216 |
}
|
|
217 |
|
|
218 |
JNF_COCOA_EXIT(env);
|
|
219 |
|
|
220 |
return oglc;
|
|
221 |
}
|
|
222 |
|
|
223 |
/**
|
|
224 |
* Makes a context current to the given source and destination
|
|
225 |
* surfaces. If there is a problem making the context current, this method
|
|
226 |
* will return NULL; otherwise, returns a pointer to the OGLContext that is
|
|
227 |
* associated with the destination surface.
|
|
228 |
*/
|
|
229 |
OGLContext *
|
|
230 |
OGLSD_MakeOGLContextCurrent(JNIEnv *env, OGLSDOps *srcOps, OGLSDOps *dstOps)
|
|
231 |
{
|
|
232 |
J2dTraceLn(J2D_TRACE_INFO, "OGLSD_MakeOGLContextCurrent");
|
|
233 |
|
|
234 |
CGLSDOps *dstCGLOps = (CGLSDOps *)dstOps->privOps;
|
|
235 |
|
|
236 |
J2dTraceLn4(J2D_TRACE_VERBOSE, " src: %d %p dst: %d %p", srcOps->drawableType, srcOps, dstOps->drawableType, dstOps);
|
|
237 |
|
|
238 |
OGLContext *oglc = dstCGLOps->configInfo->context;
|
|
239 |
if (oglc == NULL) {
|
|
240 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_MakeOGLContextCurrent: context is null");
|
|
241 |
return NULL;
|
|
242 |
}
|
|
243 |
|
|
244 |
CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
|
|
245 |
|
|
246 |
// it seems to be necessary to explicitly flush between context changes
|
|
247 |
OGLContext *currentContext = OGLRenderQueue_GetCurrentContext();
|
|
248 |
if (currentContext != NULL) {
|
|
249 |
j2d_glFlush();
|
|
250 |
}
|
|
251 |
|
|
252 |
if (dstOps->drawableType == OGLSD_FBOBJECT) {
|
|
253 |
// first make sure we have a current context (if the context isn't
|
|
254 |
// already current to some drawable, we will make it current to
|
|
255 |
// its scratch surface)
|
|
256 |
if (oglc != currentContext) {
|
|
257 |
if (!CGLSD_MakeCurrentToScratch(env, oglc)) {
|
|
258 |
return NULL;
|
|
259 |
}
|
|
260 |
}
|
|
261 |
|
|
262 |
// now bind to the fbobject associated with the destination surface;
|
|
263 |
// this means that all rendering will go into the fbobject destination
|
|
264 |
// (note that we unbind the currently bound texture first; this is
|
|
265 |
// recommended procedure when binding an fbobject)
|
|
266 |
j2d_glBindTexture(GL_TEXTURE_2D, 0);
|
|
267 |
j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, dstOps->fbobjectID);
|
|
268 |
|
|
269 |
return oglc;
|
|
270 |
}
|
|
271 |
|
|
272 |
JNF_COCOA_ENTER(env);
|
|
273 |
|
|
274 |
// set the current surface
|
|
275 |
if (dstOps->drawableType == OGLSD_PBUFFER) {
|
|
276 |
// REMIND: pbuffers are not fully tested yet...
|
|
277 |
[ctxinfo->context clearDrawable];
|
|
278 |
[ctxinfo->context makeCurrentContext];
|
|
279 |
[ctxinfo->context setPixelBuffer: dstCGLOps->pbuffer
|
|
280 |
cubeMapFace: 0
|
|
281 |
mipMapLevel: 0
|
|
282 |
currentVirtualScreen: [ctxinfo->context currentVirtualScreen]];
|
|
283 |
} else {
|
|
284 |
CGLSDOps *cglsdo = (CGLSDOps *)dstOps->privOps;
|
|
285 |
NSView *nsView = (NSView *)cglsdo->peerData;
|
|
286 |
|
|
287 |
if ([ctxinfo->context view] != nsView) {
|
|
288 |
[ctxinfo->context makeCurrentContext];
|
|
289 |
[ctxinfo->context setView: nsView];
|
|
290 |
}
|
|
291 |
}
|
|
292 |
|
|
293 |
if (OGLC_IS_CAP_PRESENT(oglc, CAPS_EXT_FBOBJECT)) {
|
|
294 |
// the GL_EXT_framebuffer_object extension is present, so we
|
|
295 |
// must bind to the default (windowing system provided)
|
|
296 |
// framebuffer
|
|
297 |
j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
|
298 |
}
|
|
299 |
|
|
300 |
if ((srcOps != dstOps) && (srcOps->drawableType == OGLSD_PBUFFER)) {
|
|
301 |
// bind pbuffer to the render texture object (since we are preparing
|
|
302 |
// to copy from the pbuffer)
|
|
303 |
CGLSDOps *srcCGLOps = (CGLSDOps *)srcOps->privOps;
|
|
304 |
j2d_glBindTexture(GL_TEXTURE_2D, srcOps->textureID);
|
|
305 |
[ctxinfo->context
|
|
306 |
setTextureImageToPixelBuffer: srcCGLOps->pbuffer
|
|
307 |
colorBuffer: GL_FRONT];
|
|
308 |
}
|
|
309 |
|
|
310 |
JNF_COCOA_EXIT(env);
|
|
311 |
|
|
312 |
return oglc;
|
|
313 |
}
|
|
314 |
|
|
315 |
/**
|
|
316 |
* This function initializes a native window surface and caches the window
|
|
317 |
* bounds in the given OGLSDOps. Returns JNI_TRUE if the operation was
|
|
318 |
* successful; JNI_FALSE otherwise.
|
|
319 |
*/
|
|
320 |
jboolean
|
|
321 |
OGLSD_InitOGLWindow(JNIEnv *env, OGLSDOps *oglsdo)
|
|
322 |
{
|
|
323 |
J2dTraceLn(J2D_TRACE_INFO, "OGLSD_InitOGLWindow");
|
|
324 |
|
|
325 |
if (oglsdo == NULL) {
|
|
326 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_InitOGLWindow: ops are null");
|
|
327 |
return JNI_FALSE;
|
|
328 |
}
|
|
329 |
|
|
330 |
CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps;
|
|
331 |
if (cglsdo == NULL) {
|
|
332 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_InitOGLWindow: cgl ops are null");
|
|
333 |
return JNI_FALSE;
|
|
334 |
}
|
|
335 |
|
|
336 |
AWTView *v = cglsdo->peerData;
|
|
337 |
if (v == NULL) {
|
|
338 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_InitOGLWindow: view is invalid");
|
|
339 |
return JNI_FALSE;
|
|
340 |
}
|
|
341 |
|
|
342 |
JNF_COCOA_ENTER(env);
|
|
343 |
NSRect surfaceBounds = [v bounds];
|
|
344 |
oglsdo->drawableType = OGLSD_WINDOW;
|
|
345 |
oglsdo->isOpaque = JNI_TRUE;
|
|
346 |
oglsdo->width = surfaceBounds.size.width;
|
|
347 |
oglsdo->height = surfaceBounds.size.height;
|
|
348 |
JNF_COCOA_EXIT(env);
|
|
349 |
|
|
350 |
J2dTraceLn2(J2D_TRACE_VERBOSE, " created window: w=%d h=%d", oglsdo->width, oglsdo->height);
|
|
351 |
|
|
352 |
return JNI_TRUE;
|
|
353 |
}
|
|
354 |
|
|
355 |
void
|
|
356 |
OGLSD_SwapBuffers(JNIEnv *env, jlong pPeerData)
|
|
357 |
{
|
|
358 |
J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SwapBuffers");
|
|
359 |
|
|
360 |
JNF_COCOA_ENTER(env);
|
|
361 |
[[NSOpenGLContext currentContext] flushBuffer];
|
|
362 |
JNF_COCOA_EXIT(env);
|
|
363 |
}
|
|
364 |
|
|
365 |
void
|
|
366 |
OGLSD_Flush(JNIEnv *env)
|
|
367 |
{
|
|
368 |
OGLSDOps *dstOps = OGLRenderQueue_GetCurrentDestination();
|
|
369 |
if (dstOps != NULL) {
|
|
370 |
CGLSDOps *dstCGLOps = (CGLSDOps *)dstOps->privOps;
|
|
371 |
CGLLayer *layer = (CGLLayer*)dstCGLOps->layer;
|
|
372 |
if (layer != NULL) {
|
|
373 |
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
|
|
374 |
AWT_ASSERT_APPKIT_THREAD;
|
|
375 |
[layer setNeedsDisplay];
|
|
376 |
|
|
377 |
#ifdef REMOTELAYER
|
|
378 |
/* If there's a remote layer (being used for testing)
|
|
379 |
* then we want to have that also receive the texture.
|
|
380 |
* First sync. up its dimensions with that of the layer
|
|
381 |
* we have attached to the local window and tell it that
|
|
382 |
* it also needs to copy the texture.
|
|
383 |
*/
|
|
384 |
if (layer.remoteLayer != nil) {
|
|
385 |
CGLLayer* remoteLayer = layer.remoteLayer;
|
|
386 |
remoteLayer.target = GL_TEXTURE_2D;
|
|
387 |
remoteLayer.textureID = layer.textureID;
|
|
388 |
remoteLayer.textureWidth = layer.textureWidth;
|
|
389 |
remoteLayer.textureHeight = layer.textureHeight;
|
|
390 |
[remoteLayer setNeedsDisplay];
|
|
391 |
}
|
|
392 |
#endif /* REMOTELAYER */
|
|
393 |
}];
|
|
394 |
}
|
|
395 |
}
|
|
396 |
}
|
|
397 |
|
|
398 |
#pragma mark -
|
|
399 |
#pragma mark "--- CGLSurfaceData methods ---"
|
|
400 |
|
|
401 |
extern LockFunc OGLSD_Lock;
|
|
402 |
extern GetRasInfoFunc OGLSD_GetRasInfo;
|
|
403 |
extern UnlockFunc OGLSD_Unlock;
|
|
404 |
extern DisposeFunc OGLSD_Dispose;
|
|
405 |
|
|
406 |
JNIEXPORT void JNICALL
|
|
407 |
Java_sun_java2d_opengl_CGLSurfaceData_initOps
|
|
408 |
(JNIEnv *env, jobject cglsd,
|
|
409 |
jlong pConfigInfo, jlong pPeerData, jlong layerPtr,
|
|
410 |
jint xoff, jint yoff, jboolean isOpaque)
|
|
411 |
{
|
|
412 |
J2dTraceLn(J2D_TRACE_INFO, "CGLSurfaceData_initOps");
|
|
413 |
J2dTraceLn1(J2D_TRACE_INFO, " pPeerData=%p", jlong_to_ptr(pPeerData));
|
|
414 |
J2dTraceLn2(J2D_TRACE_INFO, " xoff=%d, yoff=%d", (int)xoff, (int)yoff);
|
|
415 |
|
|
416 |
OGLSDOps *oglsdo = (OGLSDOps *)
|
|
417 |
SurfaceData_InitOps(env, cglsd, sizeof(OGLSDOps));
|
|
418 |
CGLSDOps *cglsdo = (CGLSDOps *)malloc(sizeof(CGLSDOps));
|
|
419 |
if (cglsdo == NULL) {
|
|
420 |
JNU_ThrowOutOfMemoryError(env, "creating native cgl ops");
|
|
421 |
return;
|
|
422 |
}
|
|
423 |
|
|
424 |
oglsdo->privOps = cglsdo;
|
|
425 |
|
|
426 |
oglsdo->sdOps.Lock = OGLSD_Lock;
|
|
427 |
oglsdo->sdOps.GetRasInfo = OGLSD_GetRasInfo;
|
|
428 |
oglsdo->sdOps.Unlock = OGLSD_Unlock;
|
|
429 |
oglsdo->sdOps.Dispose = OGLSD_Dispose;
|
|
430 |
|
|
431 |
oglsdo->drawableType = OGLSD_UNDEFINED;
|
|
432 |
oglsdo->activeBuffer = GL_FRONT;
|
|
433 |
oglsdo->needsInit = JNI_TRUE;
|
|
434 |
oglsdo->xOffset = xoff;
|
|
435 |
oglsdo->yOffset = yoff;
|
|
436 |
oglsdo->isOpaque = isOpaque;
|
|
437 |
|
|
438 |
cglsdo->peerData = (AWTView *)jlong_to_ptr(pPeerData);
|
|
439 |
cglsdo->layer = (CGLLayer *)jlong_to_ptr(layerPtr);
|
|
440 |
cglsdo->configInfo = (CGLGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
|
|
441 |
|
|
442 |
if (cglsdo->configInfo == NULL) {
|
|
443 |
free(cglsdo);
|
|
444 |
JNU_ThrowNullPointerException(env, "Config info is null in initOps");
|
|
445 |
}
|
|
446 |
}
|
|
447 |
|
|
448 |
JNIEXPORT void JNICALL
|
|
449 |
Java_sun_java2d_opengl_CGLSurfaceData_clearWindow
|
|
450 |
(JNIEnv *env, jobject cglsd)
|
|
451 |
{
|
|
452 |
J2dTraceLn(J2D_TRACE_INFO, "CGLSurfaceData_clearWindow");
|
|
453 |
|
|
454 |
OGLSDOps *oglsdo = (OGLSDOps*) SurfaceData_GetOps(env, cglsd);
|
|
455 |
CGLSDOps *cglsdo = (CGLSDOps*) oglsdo->privOps;
|
|
456 |
|
|
457 |
cglsdo->peerData = NULL;
|
|
458 |
cglsdo->layer = NULL;
|
|
459 |
}
|
|
460 |
|
|
461 |
JNIEXPORT jboolean JNICALL
|
|
462 |
Java_sun_java2d_opengl_CGLSurfaceData_initPbuffer
|
|
463 |
(JNIEnv *env, jobject cglsd,
|
|
464 |
jlong pData, jlong pConfigInfo, jboolean isOpaque,
|
|
465 |
jint width, jint height)
|
|
466 |
{
|
|
467 |
J2dTraceLn3(J2D_TRACE_INFO, "CGLSurfaceData_initPbuffer: w=%d h=%d opq=%d", width, height, isOpaque);
|
|
468 |
|
|
469 |
OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
|
|
470 |
if (oglsdo == NULL) {
|
|
471 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLSurfaceData_initPbuffer: ops are null");
|
|
472 |
return JNI_FALSE;
|
|
473 |
}
|
|
474 |
|
|
475 |
CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps;
|
|
476 |
if (cglsdo == NULL) {
|
|
477 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLSurfaceData_initPbuffer: cgl ops are null");
|
|
478 |
return JNI_FALSE;
|
|
479 |
}
|
|
480 |
|
|
481 |
CGLGraphicsConfigInfo *cglInfo = (CGLGraphicsConfigInfo *)
|
|
482 |
jlong_to_ptr(pConfigInfo);
|
|
483 |
if (cglInfo == NULL) {
|
|
484 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLSurfaceData_initPbuffer: cgl config info is null");
|
|
485 |
return JNI_FALSE;
|
|
486 |
}
|
|
487 |
|
|
488 |
// find the maximum allowable texture dimensions (this value ultimately
|
|
489 |
// determines our maximum pbuffer size)
|
|
490 |
int pbMax = 0;
|
|
491 |
j2d_glGetIntegerv(GL_MAX_TEXTURE_SIZE, &pbMax);
|
|
492 |
|
|
493 |
int pbWidth = 0;
|
|
494 |
int pbHeight = 0;
|
|
495 |
if (OGLC_IS_CAP_PRESENT(cglInfo->context, CAPS_TEXNONPOW2)) {
|
|
496 |
// use non-power-of-two dimensions directly
|
|
497 |
pbWidth = (width <= pbMax) ? width : 0;
|
|
498 |
pbHeight = (height <= pbMax) ? height : 0;
|
|
499 |
} else {
|
|
500 |
// find the appropriate power-of-two dimensions
|
|
501 |
pbWidth = OGLSD_NextPowerOfTwo(width, pbMax);
|
|
502 |
pbHeight = OGLSD_NextPowerOfTwo(height, pbMax);
|
|
503 |
}
|
|
504 |
|
|
505 |
J2dTraceLn3(J2D_TRACE_VERBOSE, " desired pbuffer dimensions: w=%d h=%d max=%d", pbWidth, pbHeight, pbMax);
|
|
506 |
|
|
507 |
// if either dimension is 0, we cannot allocate a pbuffer/texture with the
|
|
508 |
// requested dimensions
|
|
509 |
if (pbWidth == 0 || pbHeight == 0) {
|
|
510 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLSurfaceData_initPbuffer: dimensions too large");
|
|
511 |
return JNI_FALSE;
|
|
512 |
}
|
|
513 |
|
|
514 |
int format = isOpaque ? GL_RGB : GL_RGBA;
|
|
515 |
|
|
516 |
JNF_COCOA_ENTER(env);
|
|
517 |
|
|
518 |
cglsdo->pbuffer =
|
|
519 |
[[NSOpenGLPixelBuffer alloc]
|
|
520 |
initWithTextureTarget: GL_TEXTURE_2D
|
|
521 |
textureInternalFormat: format
|
|
522 |
textureMaxMipMapLevel: 0
|
|
523 |
pixelsWide: pbWidth
|
|
524 |
pixelsHigh: pbHeight];
|
|
525 |
if (cglsdo->pbuffer == nil) {
|
|
526 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLSurfaceData_initPbuffer: could not create pbuffer");
|
|
527 |
return JNI_FALSE;
|
|
528 |
}
|
|
529 |
|
|
530 |
// make sure the actual dimensions match those that we requested
|
|
531 |
GLsizei actualWidth = [cglsdo->pbuffer pixelsWide];
|
|
532 |
GLsizei actualHeight = [cglsdo->pbuffer pixelsHigh];
|
|
533 |
if (actualWidth != pbWidth || actualHeight != pbHeight) {
|
|
534 |
J2dRlsTraceLn2(J2D_TRACE_ERROR, "CGLSurfaceData_initPbuffer: actual (w=%d h=%d) != requested", actualWidth, actualHeight);
|
|
535 |
[cglsdo->pbuffer release];
|
|
536 |
return JNI_FALSE;
|
|
537 |
}
|
|
538 |
|
|
539 |
GLuint texID = 0;
|
|
540 |
j2d_glGenTextures(1, &texID);
|
|
541 |
j2d_glBindTexture(GL_TEXTURE_2D, texID);
|
|
542 |
|
|
543 |
oglsdo->drawableType = OGLSD_PBUFFER;
|
|
544 |
oglsdo->isOpaque = isOpaque;
|
|
545 |
oglsdo->width = width;
|
|
546 |
oglsdo->height = height;
|
|
547 |
oglsdo->textureID = texID;
|
|
548 |
oglsdo->textureWidth = pbWidth;
|
|
549 |
oglsdo->textureHeight = pbHeight;
|
|
550 |
oglsdo->activeBuffer = GL_FRONT;
|
|
551 |
oglsdo->needsInit = JNI_TRUE;
|
|
552 |
|
|
553 |
OGLSD_INIT_TEXTURE_FILTER(oglsdo, GL_NEAREST);
|
|
554 |
|
|
555 |
JNF_COCOA_EXIT(env);
|
|
556 |
|
|
557 |
return JNI_TRUE;
|
|
558 |
}
|
|
559 |
|
|
560 |
#pragma mark -
|
|
561 |
#pragma mark "--- CGLSurfaceData methods - Mac OS X specific ---"
|
|
562 |
|
|
563 |
// Must be called on the QFT...
|
|
564 |
JNIEXPORT void JNICALL
|
|
565 |
Java_sun_java2d_opengl_CGLSurfaceData_validate
|
|
566 |
(JNIEnv *env, jobject jsurfacedata,
|
|
567 |
jint xoff, jint yoff, jint width, jint height, jboolean isOpaque)
|
|
568 |
{
|
|
569 |
J2dTraceLn2(J2D_TRACE_INFO, "CGLSurfaceData_validate: w=%d h=%d", width, height);
|
|
570 |
|
|
571 |
OGLSDOps *oglsdo = (OGLSDOps*)SurfaceData_GetOps(env, jsurfacedata);
|
|
572 |
oglsdo->needsInit = JNI_TRUE;
|
|
573 |
oglsdo->xOffset = xoff;
|
|
574 |
oglsdo->yOffset = yoff;
|
|
575 |
|
|
576 |
oglsdo->width = width;
|
|
577 |
oglsdo->height = height;
|
|
578 |
oglsdo->isOpaque = isOpaque;
|
|
579 |
|
|
580 |
if (oglsdo->drawableType == OGLSD_WINDOW) {
|
|
581 |
OGLContext_SetSurfaces(env, ptr_to_jlong(oglsdo), ptr_to_jlong(oglsdo));
|
|
582 |
|
|
583 |
// we have to explicitly tell the NSOpenGLContext that its target
|
|
584 |
// drawable has changed size
|
|
585 |
CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps;
|
|
586 |
OGLContext *oglc = cglsdo->configInfo->context;
|
|
587 |
CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
|
|
588 |
|
|
589 |
JNF_COCOA_ENTER(env);
|
|
590 |
[ctxinfo->context update];
|
|
591 |
JNF_COCOA_EXIT(env);
|
|
592 |
}
|
|
593 |
}
|