175 pthread_t jrsRemoteThread;
176 pthread_create(&jrsRemoteThread, NULL, JRSRemoteThreadFn, NULL);
177 #endif
178 return JNI_TRUE;
179 }
180
181
182 /**
183 * Determines whether the CGL pipeline can be used for a given GraphicsConfig
184 * provided its screen number and visual ID. If the minimum requirements are
185 * met, the native CGLGraphicsConfigInfo structure is initialized for this
186 * GraphicsConfig with the necessary information (pixel format, etc.)
187 * and a pointer to this structure is returned as a jlong. If
188 * initialization fails at any point, zero is returned, indicating that CGL
189 * cannot be used for this GraphicsConfig (we should fallback on an existing
190 * 2D pipeline).
191 */
192 JNIEXPORT jlong JNICALL
193 Java_sun_java2d_opengl_CGLGraphicsConfig_getCGLConfigInfo
194 (JNIEnv *env, jclass cglgc,
195 jint screennum, jint pixfmt, jint swapInterval)
196 {
197 jlong ret = 0L;
198 JNF_COCOA_ENTER(env);
199 NSMutableArray * retArray = [NSMutableArray arrayWithCapacity:3];
200 [retArray addObject: [NSNumber numberWithInt: (int)screennum]];
201 [retArray addObject: [NSNumber numberWithInt: (int)pixfmt]];
202 [retArray addObject: [NSNumber numberWithInt: (int)swapInterval]];
203 if ([NSThread isMainThread]) {
204 [GraphicsConfigUtil _getCGLConfigInfo: retArray];
205 } else {
206 [GraphicsConfigUtil performSelectorOnMainThread: @selector(_getCGLConfigInfo:) withObject: retArray waitUntilDone: YES];
207 }
208 NSNumber * num = (NSNumber *)[retArray objectAtIndex: 0];
209 ret = (jlong)[num longValue];
210 JNF_COCOA_EXIT(env);
211 return ret;
212 }
213
214
215
216 @implementation GraphicsConfigUtil
217 + (void) _getCGLConfigInfo: (NSMutableArray *)argValue {
218 AWT_ASSERT_APPKIT_THREAD;
219
220 jint screennum = (jint)[(NSNumber *)[argValue objectAtIndex: 0] intValue];
221 jint pixfmt = (jint)[(NSNumber *)[argValue objectAtIndex: 1] intValue];
222 jint swapInterval = (jint)[(NSNumber *)[argValue objectAtIndex: 2] intValue];
223 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
224 [argValue removeAllObjects];
225
226 J2dRlsTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_getCGLConfigInfo");
227
228 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
229
230 CGOpenGLDisplayMask glMask = (CGOpenGLDisplayMask)pixfmt;
231 if (sharedContext == NULL) {
232 if (glMask == 0) {
233 CGDirectDisplayID id =
234 FindCGDirectDisplayIDForScreenIndex(screennum);
235 glMask = CGDisplayIDToOpenGLDisplayMask(id);
236 }
237
238 NSOpenGLPixelFormatAttribute attrs[] = {
239 NSOpenGLPFAClosestPolicy,
240 NSOpenGLPFANoRecovery,
241 NSOpenGLPFAAccelerated,
242 NSOpenGLPFAFullScreen,
243 NSOpenGLPFAWindow,
244 NSOpenGLPFAPixelBuffer,
245 NSOpenGLPFADoubleBuffer,
246 NSOpenGLPFAColorSize, 32,
247 NSOpenGLPFAAlphaSize, 8,
248 NSOpenGLPFADepthSize, 16,
249 NSOpenGLPFAScreenMask, glMask,
250 0
251 };
252
253 sharedPixelFormat =
254 [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
255 if (sharedPixelFormat == nil) {
256 J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: shared NSOpenGLPixelFormat is NULL");
257 [argValue addObject: [NSNumber numberWithLong: 0L]];
258 return;
259 }
260
261 sharedContext =
262 [[NSOpenGLContext alloc]
395 [NSOpenGLContext clearCurrentContext];
396 free(ctxinfo);
397 [argValue addObject: [NSNumber numberWithLong: 0L]];
398 return;
399 }
400 memset(oglc, 0, sizeof(OGLContext));
401 oglc->ctxInfo = ctxinfo;
402 oglc->caps = caps;
403
404 // create the CGLGraphicsConfigInfo record for this config
405 CGLGraphicsConfigInfo *cglinfo = (CGLGraphicsConfigInfo *)malloc(sizeof(CGLGraphicsConfigInfo));
406 if (cglinfo == NULL) {
407 J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: could not allocate memory for cglinfo");
408 [NSOpenGLContext clearCurrentContext];
409 free(oglc);
410 free(ctxinfo);
411 [argValue addObject: [NSNumber numberWithLong: 0L]];
412 return;
413 }
414 memset(cglinfo, 0, sizeof(CGLGraphicsConfigInfo));
415 cglinfo->screen = screennum;
416 cglinfo->pixfmt = sharedPixelFormat;
417 cglinfo->context = oglc;
418
419 [NSOpenGLContext clearCurrentContext];
420 [argValue addObject: [NSNumber numberWithLong:ptr_to_jlong(cglinfo)]];
421 [pool drain];
422 }
423 @end //GraphicsConfigUtil
424
425
426 JNIEXPORT jint JNICALL
427 Java_sun_java2d_opengl_CGLGraphicsConfig_getDefaultPixFmt
428 (JNIEnv *env, jclass cglgc, jint screennum)
429 {
430 J2dTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_getDefaultPixFmt");
431
432 CGDirectDisplayID id = FindCGDirectDisplayIDForScreenIndex(screennum);
433 return (jint)CGDisplayIDToOpenGLDisplayMask(id);
434 }
435
436 JNIEXPORT jint JNICALL
437 Java_sun_java2d_opengl_CGLGraphicsConfig_getOGLCapabilities
438 (JNIEnv *env, jclass cglgc, jlong configInfo)
439 {
440 J2dTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_getOGLCapabilities");
441
442 CGLGraphicsConfigInfo *cglinfo =
443 (CGLGraphicsConfigInfo *)jlong_to_ptr(configInfo);
444 if ((cglinfo == NULL) || (cglinfo->context == NULL)) {
445 return CAPS_EMPTY;
446 } else {
447 return cglinfo->context->caps;
448 }
449 }
450
451 JNIEXPORT jint JNICALL
452 Java_sun_java2d_opengl_CGLGraphicsConfig_getMaxTextureSize
453 (JNIEnv *env, jclass cglgc)
454 {
|
175 pthread_t jrsRemoteThread;
176 pthread_create(&jrsRemoteThread, NULL, JRSRemoteThreadFn, NULL);
177 #endif
178 return JNI_TRUE;
179 }
180
181
182 /**
183 * Determines whether the CGL pipeline can be used for a given GraphicsConfig
184 * provided its screen number and visual ID. If the minimum requirements are
185 * met, the native CGLGraphicsConfigInfo structure is initialized for this
186 * GraphicsConfig with the necessary information (pixel format, etc.)
187 * and a pointer to this structure is returned as a jlong. If
188 * initialization fails at any point, zero is returned, indicating that CGL
189 * cannot be used for this GraphicsConfig (we should fallback on an existing
190 * 2D pipeline).
191 */
192 JNIEXPORT jlong JNICALL
193 Java_sun_java2d_opengl_CGLGraphicsConfig_getCGLConfigInfo
194 (JNIEnv *env, jclass cglgc,
195 jint displayID, jint pixfmt, jint swapInterval)
196 {
197 jlong ret = 0L;
198 JNF_COCOA_ENTER(env);
199 NSMutableArray * retArray = [NSMutableArray arrayWithCapacity:3];
200 [retArray addObject: [NSNumber numberWithInt: (int)displayID]];
201 [retArray addObject: [NSNumber numberWithInt: (int)pixfmt]];
202 [retArray addObject: [NSNumber numberWithInt: (int)swapInterval]];
203 if ([NSThread isMainThread]) {
204 [GraphicsConfigUtil _getCGLConfigInfo: retArray];
205 } else {
206 [GraphicsConfigUtil performSelectorOnMainThread: @selector(_getCGLConfigInfo:) withObject: retArray waitUntilDone: YES];
207 }
208 NSNumber * num = (NSNumber *)[retArray objectAtIndex: 0];
209 ret = (jlong)[num longValue];
210 JNF_COCOA_EXIT(env);
211 return ret;
212 }
213
214
215
216 @implementation GraphicsConfigUtil
217 + (void) _getCGLConfigInfo: (NSMutableArray *)argValue {
218 AWT_ASSERT_APPKIT_THREAD;
219
220 jint displayID = (jint)[(NSNumber *)[argValue objectAtIndex: 0] intValue];
221 jint pixfmt = (jint)[(NSNumber *)[argValue objectAtIndex: 1] intValue];
222 jint swapInterval = (jint)[(NSNumber *)[argValue objectAtIndex: 2] intValue];
223 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
224 [argValue removeAllObjects];
225
226 J2dRlsTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_getCGLConfigInfo");
227
228 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
229
230 CGOpenGLDisplayMask glMask = (CGOpenGLDisplayMask)pixfmt;
231 if (sharedContext == NULL) {
232 if (glMask == 0) {
233 glMask = CGDisplayIDToOpenGLDisplayMask(displayID);
234 }
235
236 NSOpenGLPixelFormatAttribute attrs[] = {
237 NSOpenGLPFAClosestPolicy,
238 NSOpenGLPFAWindow,
239 NSOpenGLPFAPixelBuffer,
240 NSOpenGLPFADoubleBuffer,
241 NSOpenGLPFAColorSize, 32,
242 NSOpenGLPFAAlphaSize, 8,
243 NSOpenGLPFADepthSize, 16,
244 NSOpenGLPFAScreenMask, glMask,
245 0
246 };
247
248 sharedPixelFormat =
249 [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
250 if (sharedPixelFormat == nil) {
251 J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: shared NSOpenGLPixelFormat is NULL");
252 [argValue addObject: [NSNumber numberWithLong: 0L]];
253 return;
254 }
255
256 sharedContext =
257 [[NSOpenGLContext alloc]
390 [NSOpenGLContext clearCurrentContext];
391 free(ctxinfo);
392 [argValue addObject: [NSNumber numberWithLong: 0L]];
393 return;
394 }
395 memset(oglc, 0, sizeof(OGLContext));
396 oglc->ctxInfo = ctxinfo;
397 oglc->caps = caps;
398
399 // create the CGLGraphicsConfigInfo record for this config
400 CGLGraphicsConfigInfo *cglinfo = (CGLGraphicsConfigInfo *)malloc(sizeof(CGLGraphicsConfigInfo));
401 if (cglinfo == NULL) {
402 J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: could not allocate memory for cglinfo");
403 [NSOpenGLContext clearCurrentContext];
404 free(oglc);
405 free(ctxinfo);
406 [argValue addObject: [NSNumber numberWithLong: 0L]];
407 return;
408 }
409 memset(cglinfo, 0, sizeof(CGLGraphicsConfigInfo));
410 cglinfo->screen = displayID;
411 cglinfo->pixfmt = sharedPixelFormat;
412 cglinfo->context = oglc;
413
414 [NSOpenGLContext clearCurrentContext];
415 [argValue addObject: [NSNumber numberWithLong:ptr_to_jlong(cglinfo)]];
416 [pool drain];
417 }
418 @end //GraphicsConfigUtil
419
420 JNIEXPORT jint JNICALL
421 Java_sun_java2d_opengl_CGLGraphicsConfig_getOGLCapabilities
422 (JNIEnv *env, jclass cglgc, jlong configInfo)
423 {
424 J2dTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_getOGLCapabilities");
425
426 CGLGraphicsConfigInfo *cglinfo =
427 (CGLGraphicsConfigInfo *)jlong_to_ptr(configInfo);
428 if ((cglinfo == NULL) || (cglinfo->context == NULL)) {
429 return CAPS_EMPTY;
430 } else {
431 return cglinfo->context->caps;
432 }
433 }
434
435 JNIEXPORT jint JNICALL
436 Java_sun_java2d_opengl_CGLGraphicsConfig_getMaxTextureSize
437 (JNIEnv *env, jclass cglgc)
438 {
|