/** * Fetches the OGLContext associated with the given destination surface, * makes the context current for those surfaces, updates the destination * viewport, and then returns a pointer to the OGLContext. */ OGLContext * OGLContext_SetSurfaces(JNIEnv *env, jlong pSrc, jlong pDst) { OGLSDOps *srcOps = (OGLSDOps *)jlong_to_ptr(pSrc); OGLSDOps *dstOps = (OGLSDOps *)jlong_to_ptr(pDst); OGLContext *oglc = NULL; J2dTraceLn(J2D_TRACE_INFO, "OGLContext_SetSurfaces"); if (srcOps == NULL || dstOps == NULL) { J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLContext_SetSurfaces: ops are null"); return NULL; } J2dTraceLn2(J2D_TRACE_VERBOSE, " srctype=%d dsttype=%d", srcOps->drawableType, dstOps->drawableType); if (dstOps->drawableType == OGLSD_TEXTURE) { J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLContext_SetSurfaces: texture cannot be used as destination"); return NULL; } if (dstOps->drawableType == OGLSD_UNDEFINED) { // initialize the surface as an OGLSD_WINDOW if (!OGLSD_InitOGLWindow(env, dstOps)) { J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLContext_SetSurfaces: could not init OGL window"); return NULL; } } // make the context current oglc = OGLSD_MakeOGLContextCurrent(env, srcOps, dstOps); if (oglc == NULL) { J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLContext_SetSurfaces: could not make context current"); return NULL; } // update the viewport OGLContext_SetViewport(srcOps, dstOps); // perform additional one-time initialization, if necessary if (dstOps->needsInit) { if (dstOps->isOpaque) { // in this case we are treating the destination as opaque, but // to do so, first we need to ensure that the alpha channel // is filled with fully opaque values (see 6319663) OGLContext_InitAlphaChannel(); } dstOps->needsInit = JNI_FALSE; } return oglc; }
/** * Initializes a surface in the backbuffer of a given double-buffered * onscreen window for use in a BufferStrategy.Flip situation. The bounds of * the backbuffer surface should always be kept in sync with the bounds of * the underlying native window. */ JNIEXPORT jboolean JNICALL Java_sun_java2d_opengl_OGLSurfaceData_initFlipBackbuffer (JNIEnv *env, jobject oglsd, jlong pData) { OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData); J2dTraceLn(J2D_TRACE_INFO, "OGLSurfaceData_initFlipBackbuffer"); if (oglsdo == NULL) { J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSurfaceData_initFlipBackbuffer: ops are null"); return JNI_FALSE; } if (oglsdo->drawableType == OGLSD_UNDEFINED) { if (!OGLSD_InitOGLWindow(env, oglsdo)) { J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSurfaceData_initFlipBackbuffer: could not init window"); return JNI_FALSE; } } if (oglsdo->drawableType != OGLSD_WINDOW) { J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSurfaceData_initFlipBackbuffer: drawable is not a window"); return JNI_FALSE; } oglsdo->drawableType = OGLSD_FLIP_BACKBUFFER; // x/yOffset have already been set in OGLSD_InitOGLWindow()... // REMIND: for some reason, flipping won't work properly on IFB unless we // explicitly use BACK_LEFT rather than BACK... oglsdo->activeBuffer = GL_BACK_LEFT; OGLSD_SetNativeDimensions(env, oglsdo, oglsdo->width, oglsdo->height); return JNI_TRUE; }