Exemplo n.º 1
0
/*
 * Class:     jogamp_newt_driver_x11_RandR13
 * Method:    setMonitorMode0
 * Signature: (JJJIIIII)Z
 */
JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_RandR13_setMonitorMode0
  (JNIEnv *env, jclass clazz, jlong display, jlong screenResources, jlong monitorInfo, jint crt_idx, jint modeId, jint rotation, jint x, jint y)
{
    Display * dpy = (Display *) (intptr_t) display;
    XRRScreenResources *resources = (XRRScreenResources *) (intptr_t) screenResources;
    XRRCrtcInfo *xrrCrtcInfo = (XRRCrtcInfo *) (intptr_t) monitorInfo;
    jboolean res = JNI_FALSE;

    if( NULL == resources || NULL == xrrCrtcInfo || crt_idx >= resources->ncrtc ) {
        // n/a
        return res;
    }

    if( None == xrrCrtcInfo->mode || 0 == xrrCrtcInfo->noutput ) {
        // disabled
        return res;
    }

    if( 0 >= modeId ) {
        // oops ..
        return res;
    }

    if( 0 > x || 0 > y ) {
        x = xrrCrtcInfo->x;
        y = xrrCrtcInfo->y;
    }

    Status status = XRRSetCrtcConfig( dpy, resources, resources->crtcs[crt_idx], CurrentTime, 
                                      x, y, modeId, NewtScreen_Degree2XRotation(env, rotation),
                                      xrrCrtcInfo->outputs, xrrCrtcInfo->noutput );
    res = status == RRSetConfigSuccess;

    return res;
}
Exemplo n.º 2
0
/*
 * Class:     jogamp_newt_driver_x11_RandR13
 * Method:    setMonitorMode0
 * Signature: (JJJIIIII)Z
 */
JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_RandR13_setMonitorMode0
  (JNIEnv *env, jclass clazz, jlong display, jint screen_idx, jlong screenResources, 
                              jlong monitorInfo, jint crt_id, 
                              jint jmode_id, jint rotation, jint x, jint y)
{
    jboolean res = JNI_FALSE;
    Display * dpy = (Display *) (intptr_t) display;
    Window root = RootWindow(dpy, (int)screen_idx);
    XRRScreenResources *resources = (XRRScreenResources *) (intptr_t) screenResources;
    RRCrtc crtc = findRRCrtc( resources, (RRCrtc)(intptr_t)crt_id );
    if( 0 == crtc ) {
        // n/a
        DBG_PRINT("RandR13_setMonitorMode0.0: n/a: resources %p (%d), crt_id %#lx \n", 
            resources, (NULL == resources ? 0 : resources->ncrtc), (RRCrtc)(intptr_t)crt_id);
        return res;
    }
    XRRCrtcInfo *xrrCrtcInfo = (XRRCrtcInfo *) (intptr_t) monitorInfo;
    if( NULL == xrrCrtcInfo ) {
        // n/a
        DBG_PRINT("RandR13_setMonitorMode0.1: n/a: resources %p (%d), xrrCrtcInfo %p, crtc %#lx\n", 
            resources, (NULL == resources ? 0 : resources->ncrtc), xrrCrtcInfo, crtc);
        return res;
    }
    if( None == xrrCrtcInfo->mode || 0 == xrrCrtcInfo->noutput ) {
        // disabled
        DBG_PRINT("RandR13_setMonitorMode0: disabled: mode %d, noutput %d\n", xrrCrtcInfo->mode, xrrCrtcInfo->noutput);
        return res;
    }
    if( 0 >= jmode_id ) {
        // oops ..
        DBG_PRINT("RandR13_setMonitorMode0: inv. modeId: modeId %d\n", jmode_id);
        return res;
    }

    RRMode mode_id = (RRMode)(intptr_t)jmode_id;
    XRRModeInfo *mode_info = findMode(resources, mode_id);
    if( NULL == mode_info ) {
        // oops ..
        DBG_PRINT("RandR13_setMonitorMode0: inv. mode_id: mode_id %#lx\n", mode_id);
        return res;
    }
    if( 0 > x || 0 > y ) {
        x = xrrCrtcInfo->x;
        y = xrrCrtcInfo->y;
    }

    Rotation xrotation = NewtScreen_Degree2XRotation(env, rotation);
    int rot_change = xrrCrtcInfo->rotation != xrotation;
    DBG_PRINT("RandR13_setMonitorMode0: crt %#lx, noutput %d -> 0x%X, mode %#lx -> %#lx, pos %d / %d, rotation %d -> %d (change %d)\n", 
        crtc, xrrCrtcInfo->noutput, xrrCrtcInfo->outputs[0], xrrCrtcInfo->mode, mode_id,
        x, y, (int)xrrCrtcInfo->rotation, (int)xrotation, rot_change);

    XRRSelectInput (dpy, root, RRScreenChangeNotifyMask);
    Status status = RRSetConfigSuccess;
    int pre_fb_width=0, pre_fb_height=0;
    int fb_width=0, fb_height=0;
    int fb_width_mm=0, fb_height_mm=0;

    crtc_t *root_crtc = get_screen_size1(dpy, root, &fb_width, &fb_height,
                                         resources, crtc, xrrCrtcInfo, xrotation, x, y, mode_info);

    Bool fb_change = get_screen_sizemm(dpy, screen_idx, fb_width, fb_height,
                                       &fb_width_mm, &fb_height_mm,
                                       &pre_fb_width, &pre_fb_height);

    DBG_PRINT("RandR13_setMonitorMode0: crt %#lx, fb[change %d: %d x %d -> %d x %d [%d x %d mm]\n", 
        crtc, fb_change, pre_fb_width, pre_fb_height, fb_width, fb_height, fb_width_mm, fb_height_mm);
    if(fb_change) {
        // Disable CRTC first, since new size differs from current
        // and we shall avoid invalid intermediate configuration (see spec)!
        #if 0
        {
            // Disable all CRTCs (Not required!)
            crtc_t * iter_crtc;
            for(iter_crtc=root_crtc; RRSetConfigSuccess == status && NULL!=iter_crtc; iter_crtc=iter_crtc->next) {
                if( None == iter_crtc->mode_id || NULL == iter_crtc->mode_info || 0 == iter_crtc->crtc_info->noutput ) {
                    // disabled
                    continue;
                }
                status = XRRSetCrtcConfig (dpy, resources, iter_crtc->crtc_id, CurrentTime,
                                           0, 0, None, RR_Rotate_0, NULL, 0);
            }
        }
        #else
        status = XRRSetCrtcConfig (dpy, resources, crtc, CurrentTime,
                                   0, 0, None, RR_Rotate_0, NULL, 0);
        #endif
        DBG_PRINT("RandR13_setMonitorMode0: crt %#lx disable: %d -> %d\n", crtc, status, RRSetConfigSuccess == status);
        if( RRSetConfigSuccess == status ) {
            XRRSetScreenSize (dpy, root, fb_width, fb_height,
                              fb_width_mm, fb_height_mm);
            DBG_PRINT("RandR13_setMonitorMode0: crt %#lx screen-size\n", crtc);
        }
    }
    if( RRSetConfigSuccess == status ) {
        #if 0
        {
            // Enable/Set all CRTCs (Not required!)
            crtc_t * iter_crtc;
            for(iter_crtc=root_crtc; RRSetConfigSuccess == status && NULL!=iter_crtc; iter_crtc=iter_crtc->next) {
                if( None == iter_crtc->mode_id || NULL == iter_crtc->mode_info || 0 == iter_crtc->crtc_info->noutput ) {
                    // disabled
                    continue;
                }
                status = XRRSetCrtcConfig( dpy, resources, iter_crtc->crtc_id, CurrentTime, 
                                           iter_crtc->x, iter_crtc->y, iter_crtc->mode_id, iter_crtc->rotation,
                                           iter_crtc->crtc_info->outputs, iter_crtc->crtc_info->noutput );
            }
        }
        #else
        status = XRRSetCrtcConfig( dpy, resources, crtc, CurrentTime, 
                                   x, y, mode_id, xrotation,
                                   xrrCrtcInfo->outputs, xrrCrtcInfo->noutput );
        #endif
        DBG_PRINT("RandR13_setMonitorMode0: crt %#lx set-config: %d -> %d\n", crtc, status, RRSetConfigSuccess == status);
    }

    res = status == RRSetConfigSuccess;
    DBG_PRINT("RandR13_setMonitorMode0: FIN: %d -> ok %d\n", status, res);

    destroyCrtcChain(root_crtc, crtc);
    root_crtc=NULL;

    return res;
}