src/windows/native/sun/java2d/opengl/WGLSurfaceData.c
OGLContext *
OGLSD_MakeOGLContextCurrent(JNIEnv *env, OGLSDOps *srcOps, OGLSDOps *dstOps)
{
    WGLSDOps *srcWGLOps = (WGLSDOps *)srcOps->privOps;
    WGLSDOps *dstWGLOps = (WGLSDOps *)dstOps->privOps;
    OGLContext *oglc;
    WGLCtxInfo *ctxinfo;
    HDC srcHDC, dstHDC;
    BOOL success;

    J2dTraceLn(J2D_TRACE_INFO, "OGLSD_MakeOGLContextCurrent");

    J2dTraceLn4(J2D_TRACE_VERBOSE, "  src: %d %p dst: %d %p",
                srcOps->drawableType, srcOps,
                dstOps->drawableType, dstOps);

    oglc = dstWGLOps->configInfo->context;
    if (oglc == NULL) {
        J2dRlsTraceLn(J2D_TRACE_ERROR,
                      "OGLSD_MakeOGLContextCurrent: context is null");
        return NULL;
    }

    if (dstOps->drawableType == OGLSD_FBOBJECT) {
        OGLContext *currentContext = OGLRenderQueue_GetCurrentContext();

        // first make sure we have a current context (if the context isn't
        // already current to some drawable, we will make it current to
        // its scratch surface)
        if (oglc != currentContext) {
            if (!WGLSD_MakeCurrentToScratch(env, oglc)) {
                return NULL;
            }
        }

        // now bind to the fbobject associated with the destination surface;
        // this means that all rendering will go into the fbobject destination
        // (note that we unbind the currently bound texture first; this is
        // recommended procedure when binding an fbobject)
        j2d_glBindTexture(dstOps->textureTarget, 0);
        j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, dstOps->fbobjectID);

        return oglc;
    }

    ctxinfo = (WGLCtxInfo *)oglc->ctxInfo;

    // get the hdc for the destination surface
    if (dstOps->drawableType == OGLSD_PBUFFER) {
        dstHDC = dstWGLOps->pbufferDC;
    } else {
        dstHDC = GetDC(dstWGLOps->window);
    }

    // get the hdc for the source surface
    if (srcOps->drawableType == OGLSD_PBUFFER) {
        srcHDC = srcWGLOps->pbufferDC;
    } else {
        // the source will always be equal to the destination in this case
        srcHDC = dstHDC;
    }

    // REMIND: in theory we should be able to use wglMakeContextCurrentARB()
    // even when the src/dst surfaces are the same, but this causes problems
    // on ATI's drivers (see 6525997); for now we will only use it when the
    // surfaces are different, otherwise we will use the old
    // wglMakeCurrent() approach...
    if (srcHDC != dstHDC) {
        // use WGL_ARB_make_current_read extension to make context current
        success =
            j2d_wglMakeContextCurrentARB(dstHDC, srcHDC, ctxinfo->context);
    } else {
        // use the old approach for making current to the destination
        success = j2d_wglMakeCurrent(dstHDC, ctxinfo->context);
    }
    if (!success) {
        J2dRlsTraceLn(J2D_TRACE_ERROR,
                      "OGLSD_MakeOGLContextCurrent: could not make current");
        if (dstOps->drawableType != OGLSD_PBUFFER) {
            ReleaseDC(dstWGLOps->window, dstHDC);
        }
        return NULL;
    }

    if (OGLC_IS_CAP_PRESENT(oglc, CAPS_EXT_FBOBJECT)) {
        // the GL_EXT_framebuffer_object extension is present, so we
        // must bind to the default (windowing system provided)
        // framebuffer
        j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    }

    if (dstOps->drawableType != OGLSD_PBUFFER) {
        ReleaseDC(dstWGLOps->window, dstHDC);
    }

    return oglc;
}
/**
 * Makes a context current to the given source and destination
 * surfaces.  If there is a problem making the context current, this method
 * will return NULL; otherwise, returns a pointer to the OGLContext that is
 * associated with the destination surface.
 */
Makes a context current to the given source and destination
surfaces.  If there is a problem making the context current, this method
will return NULL; otherwise, returns a pointer to the OGLContext that is
associated with the destination surface.
Makes a context current to the given source and destination surfaces . If there is a problem making the context current this method will return NULL ; otherwise returns a pointer to the OGLContext that is associated with the destination surface .
OGLContext *
OGLSD_MakeOGLContextCurrent(JNIEnv *env, OGLSDOps *srcOps, OGLSDOps *dstOps)
{
    WGLSDOps *srcWGLOps = (WGLSDOps *)srcOps->privOps;
    WGLSDOps *dstWGLOps = (WGLSDOps *)dstOps->privOps;
    OGLContext *oglc;
    WGLCtxInfo *ctxinfo;
    HDC srcHDC, dstHDC;
    BOOL success;
    J2dTraceLn(J2D_TRACE_INFO, "OGLSD_MakeOGLContextCurrent");
    J2dTraceLn4(J2D_TRACE_VERBOSE, "  src: %d %p dst: %d %p",
                srcOps->drawableType, srcOps,
                dstOps->drawableType, dstOps);
    oglc = dstWGLOps->configInfo->context;
    if (oglc == NULL) {
        J2dRlsTraceLn(J2D_TRACE_ERROR,
                      "OGLSD_MakeOGLContextCurrent: context is null");
        return NULL;
    }
    if (dstOps->drawableType == OGLSD_FBOBJECT) {
        OGLContext *currentContext = OGLRenderQueue_GetCurrentContext();
        if (oglc != currentContext) {
            if (!WGLSD_MakeCurrentToScratch(env, oglc)) {
                return NULL;
            }
        }
        j2d_glBindTexture(dstOps->textureTarget, 0);
        j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, dstOps->fbobjectID);
        return oglc;
    }
    ctxinfo = (WGLCtxInfo *)oglc->ctxInfo;
    if (dstOps->drawableType == OGLSD_PBUFFER) {
        dstHDC = dstWGLOps->pbufferDC;
    } else {
        dstHDC = GetDC(dstWGLOps->window);
    }
    if (srcOps->drawableType == OGLSD_PBUFFER) {
        srcHDC = srcWGLOps->pbufferDC;
    } else {
        srcHDC = dstHDC;
    }
    if (srcHDC != dstHDC) {
        success =
            j2d_wglMakeContextCurrentARB(dstHDC, srcHDC, ctxinfo->context);
    } else {
        success = j2d_wglMakeCurrent(dstHDC, ctxinfo->context);
    }
    if (!success) {
        J2dRlsTraceLn(J2D_TRACE_ERROR,
                      "OGLSD_MakeOGLContextCurrent: could not make current");
        if (dstOps->drawableType != OGLSD_PBUFFER) {
            ReleaseDC(dstWGLOps->window, dstHDC);
        }
        return NULL;
    }
    if (OGLC_IS_CAP_PRESENT(oglc, CAPS_EXT_FBOBJECT)) {
        j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    }
    if (dstOps->drawableType != OGLSD_PBUFFER) {
        ReleaseDC(dstWGLOps->window, dstHDC);
    }
    return oglc;
}
OGLContext * OGLSD_MakeOGLContextCurrent ( JNIEnv * env , OGLSDOps * srcOps , OGLSDOps * dstOps ) { WGLSDOps * srcWGLOps = ( WGLSDOps * ) srcOps -> privOps ; WGLSDOps * dstWGLOps = ( WGLSDOps * ) dstOps -> privOps ; OGLContext * oglc ; WGLCtxInfo * ctxinfo ; HDC srcHDC , dstHDC ; BOOL success ; J2dTraceLn ( J2D_TRACE_INFO , " " ) ; J2dTraceLn4 ( J2D_TRACE_VERBOSE , " " , srcOps -> drawableType , srcOps , dstOps -> drawableType , dstOps ) ; oglc = dstWGLOps -> configInfo -> context ; if ( oglc == NULL ) { J2dRlsTraceLn ( J2D_TRACE_ERROR , " " ) ; return NULL ; } if ( dstOps -> drawableType == OGLSD_FBOBJECT ) { OGLContext * currentContext = OGLRenderQueue_GetCurrentContext ( ) ; if ( oglc != currentContext ) { if ( ! WGLSD_MakeCurrentToScratch ( env , oglc ) ) { return NULL ; } } j2d_glBindTexture ( dstOps -> textureTarget , 0 ) ; j2d_glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT , dstOps -> fbobjectID ) ; return oglc ; } ctxinfo = ( WGLCtxInfo * ) oglc -> ctxInfo ; if ( dstOps -> drawableType == OGLSD_PBUFFER ) { dstHDC = dstWGLOps -> pbufferDC ; } else { dstHDC = GetDC ( dstWGLOps -> window ) ; } if ( srcOps -> drawableType == OGLSD_PBUFFER ) { srcHDC = srcWGLOps -> pbufferDC ; } else { srcHDC = dstHDC ; } if ( srcHDC != dstHDC ) { success = j2d_wglMakeContextCurrentARB ( dstHDC , srcHDC , ctxinfo -> context ) ; } else { success = j2d_wglMakeCurrent ( dstHDC , ctxinfo -> context ) ; } if ( ! success ) { J2dRlsTraceLn ( J2D_TRACE_ERROR , " " ) ; if ( dstOps -> drawableType != OGLSD_PBUFFER ) { ReleaseDC ( dstWGLOps -> window , dstHDC ) ; } return NULL ; } if ( OGLC_IS_CAP_PRESENT ( oglc , CAPS_EXT_FBOBJECT ) ) { j2d_glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT , 0 ) ; } if ( dstOps -> drawableType != OGLSD_PBUFFER ) { ReleaseDC ( dstWGLOps -> window , dstHDC ) ; } return oglc ; }
Makes a context current to the given source and destination
 surfaces.
Makes a context current to the given source and destination surfaces .
// first make sure we have a current context (if the context isn't // already current to some drawable, we will make it current to // its scratch surface) // now bind to the fbobject associated with the destination surface; // this means that all rendering will go into the fbobject destination // (note that we unbind the currently bound texture first; this is // recommended procedure when binding an fbobject) // get the hdc for the destination surface // get the hdc for the source surface // the source will always be equal to the destination in this case // REMIND: in theory we should be able to use wglMakeContextCurrentARB() // even when the src/dst surfaces are the same, but this causes problems // on ATI's drivers (see 6525997); for now we will only use it when the // surfaces are different, otherwise we will use the old // wglMakeCurrent() approach... // use WGL_ARB_make_current_read extension to make context current // use the old approach for making current to the destination // the GL_EXT_framebuffer_object extension is present, so we // must bind to the default (windowing system provided) // framebuffer