/*
 * Create and display a new frame.
 */
static Bool
xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
               int newX, int newY, RegionPtr pShape)
{
    WindowPtr pWin = pFrame->win;
    xp_window_changes wc;
    unsigned int mask = 0;
    xp_error err;

    wc.x = newX;
    wc.y = newY;
    wc.width = pFrame->width;
    wc.height = pFrame->height;
    wc.bit_gravity = XP_GRAVITY_NONE;
    mask |= XP_BOUNDS;

    if (pWin->drawable.depth == 8) {
        wc.depth = XP_DEPTH_INDEX8;
        wc.colormap = xprColormapCallback;
        wc.colormap_data = pScreen;
        mask |= XP_COLORMAP;
    }
    else if (pWin->drawable.depth == 15)
        wc.depth = XP_DEPTH_RGB555;
    else if (pWin->drawable.depth == 24)
        wc.depth = XP_DEPTH_ARGB8888;
    else
        wc.depth = XP_DEPTH_NIL;
    mask |= XP_DEPTH;

    if (pShape != NULL) {
        wc.shape_nrects = RegionNumRects(pShape);
        wc.shape_rects = RegionRects(pShape);
        wc.shape_tx = wc.shape_ty = 0;
        mask |= XP_SHAPE;
    }

    pFrame->level =
        !IsRoot(pWin) ? AppleWMWindowLevelNormal : AppleWMNumWindowLevels;

    if (XQuartzIsRootless)
        wc.window_level = normal_window_levels[pFrame->level];
    else if (XQuartzShieldingWindowLevel)
        wc.window_level = XQuartzShieldingWindowLevel + 1;
    else
        wc.window_level = rooted_window_levels[pFrame->level];
    mask |= XP_WINDOW_LEVEL;

    err = xp_create_window(mask, &wc, (xp_window_id *)&pFrame->wid);

    if (err != Success) {
        return FALSE;
    }

#ifdef HAVE_LIBDISPATCH
    dispatch_async(window_hash_serial_q, ^ {
                       x_hash_table_insert(window_hash, pFrame->wid, pFrame);
                   });
Example #2
0
Bool
DRICreateSurface(ScreenPtr pScreen, Drawable id,
                 DrawablePtr pDrawable, xp_client_id client_id,
                 xp_surface_id *surface_id, unsigned int ret_key[2],
                 void (*notify) (void *arg, void *data), void *notify_data)
{
    DRIScreenPrivPtr    pDRIPriv = DRI_SCREEN_PRIV(pScreen);
    DRIDrawablePrivPtr  pDRIDrawablePriv;
    xp_window_id        wid = 0;

    if (pDrawable->type == DRAWABLE_WINDOW) {
        WindowPtr pWin = (WindowPtr)pDrawable;

        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
        if (pDRIDrawablePriv == NULL) {
            xp_error err;
            xp_window_changes wc;

            /* allocate a DRI Window Private record */
            if (!(pDRIDrawablePriv = xalloc(sizeof(DRIDrawablePrivRec)))) {
                return FALSE;
            }

            pDRIDrawablePriv->pDraw = pDrawable;
            pDRIDrawablePriv->pScreen = pScreen;
            pDRIDrawablePriv->refCount = 0;
            pDRIDrawablePriv->drawableIndex = -1;
            pDRIDrawablePriv->notifiers = NULL;

            /* find the physical window */
            wid = (xp_window_id) RootlessFrameForWindow(pWin, TRUE);
            if (wid == 0) {
                xfree(pDRIDrawablePriv);
                return FALSE;
            }

            /* allocate the physical surface */
            err = xp_create_surface(wid, &pDRIDrawablePriv->sid);
            if (err != Success) {
                xfree(pDRIDrawablePriv);
                return FALSE;
            }

            /* Make it visible */
            wc.stack_mode = XP_MAPPED_ABOVE;
            wc.sibling = 0;
            err = xp_configure_surface(pDRIDrawablePriv->sid, XP_STACKING, &wc);
            if (err != Success)
            {
                xp_destroy_surface(pDRIDrawablePriv->sid);
                xfree(pDRIDrawablePriv);
                return FALSE;
            }

            /* save private off of preallocated index */
            pWin->devPrivates[DRIWindowPrivIndex].ptr = (pointer)pDRIDrawablePriv;
        }
    }

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
    else if (pDrawable->type == DRAWABLE_PIXMAP) {
        PixmapPtr pPix = (PixmapPtr)pDrawable;

        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix);
        if (pDRIDrawablePriv == NULL) {
            xp_error err;

            /* allocate a DRI Window Private record */
            if (!(pDRIDrawablePriv = xcalloc(1, sizeof(DRIDrawablePrivRec)))) {
                return FALSE;
            }

            pDRIDrawablePriv->pDraw = pDrawable;
            pDRIDrawablePriv->pScreen = pScreen;
            pDRIDrawablePriv->refCount = 0;
            pDRIDrawablePriv->drawableIndex = -1;
            pDRIDrawablePriv->notifiers = NULL;

            /* Passing a null window id to Xplugin in 10.3+ asks for
               an accelerated offscreen surface. */

            err = xp_create_surface(0, &pDRIDrawablePriv->sid);
            if (err != Success) {
                xfree(pDRIDrawablePriv);
                return FALSE;
            }

            /* save private off of preallocated index */
            pPix->devPrivates[DRIPixmapPrivIndex].ptr = (pointer)pDRIDrawablePriv;
        }
    }
#endif

    else { /* for GLX 1.3, a PBuffer */
        /* NOT_DONE */
        return FALSE;
    }

    /* Finish initialization of new surfaces */
    if (pDRIDrawablePriv->refCount == 0) {
        unsigned int key[2] = {0};
        xp_error err;

        /* try to give the client access to the surface */
        if (client_id != 0 && wid != 0)
        {
            err = xp_export_surface(wid, pDRIDrawablePriv->sid,
                                    client_id, key);
            if (err != Success) {
                xp_destroy_surface(pDRIDrawablePriv->sid);
                xfree(pDRIDrawablePriv);
                return FALSE;
            }
        }

        pDRIDrawablePriv->key[0] = key[0];
        pDRIDrawablePriv->key[1] = key[1];

        ++pDRIPriv->nrWindows;

        /* and stash it by surface id */
        if (surface_hash == NULL)
            surface_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
        x_hash_table_insert(surface_hash,
                            (void *) pDRIDrawablePriv->sid, pDRIDrawablePriv);

        /* track this in case this window is destroyed */
        AddResource(id, DRIDrawablePrivResType, (pointer)pDrawable);

        /* Initialize shape */
        DRIUpdateSurface(pDRIDrawablePriv, pDrawable);
    }

    pDRIDrawablePriv->refCount++;

    *surface_id = pDRIDrawablePriv->sid;

    if (ret_key != NULL) {
        ret_key[0] = pDRIDrawablePriv->key[0];
        ret_key[1] = pDRIDrawablePriv->key[1];
    }

    if (notify != NULL) {
        pDRIDrawablePriv->notifiers = x_hook_add(pDRIDrawablePriv->notifiers,
                                                 notify, notify_data);
    }

    return TRUE;
}
Example #3
0
File: dri.c Project: L3oV1nc3/VMGL
Bool
DRICreateSurface(ScreenPtr pScreen, Drawable id,
                 DrawablePtr pDrawable, xp_client_id client_id,
                 xp_surface_id *surface_id, unsigned int ret_key[2],
                 void (*notify) (void *arg, void *data), void *notify_data)
{
    DRIScreenPrivPtr    pDRIPriv = DRI_SCREEN_PRIV(pScreen);
    xp_window_id        wid = 0;
    DRIDrawablePrivPtr  pDRIDrawablePriv;

    if (pDrawable->type == DRAWABLE_WINDOW) {
	pDRIDrawablePriv = CreateSurfaceForWindow(pScreen, 
						  (WindowPtr)pDrawable, &wid);

	if(NULL == pDRIDrawablePriv)
	    return FALSE; /*error*/
    }
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
    else if (pDrawable->type == DRAWABLE_PIXMAP) {
	pDRIDrawablePriv = CreateSurfaceForPixmap(pScreen, 
						  (PixmapPtr)pDrawable);

	if(NULL == pDRIDrawablePriv)
	    return FALSE; /*error*/
    }
#endif
    else { /* for GLX 1.3, a PBuffer */
        /* NOT_DONE */
        return FALSE;
    }
    
    
    /* Finish initialization of new surfaces */
    if (pDRIDrawablePriv->refCount == 0) {
        unsigned int key[2] = {0};
        xp_error err;

        /* try to give the client access to the surface */
        if (client_id != 0) {
	    /*
	     * Xplugin accepts a 0 wid if the surface id is offscreen, such 
	     * as for a pixmap.
	     */
            err = xp_export_surface(wid, pDRIDrawablePriv->sid,
                                    client_id, key);
            if (err != Success) {
                xp_destroy_surface(pDRIDrawablePriv->sid);
                xfree(pDRIDrawablePriv);
		
		/* 
		 * Now set the dix privates to NULL that were previously set.
		 * This prevents reusing an invalid pointer.
		 */
		if(pDrawable->type == DRAWABLE_WINDOW) {
		    WindowPtr pWin = (WindowPtr)pDrawable;
		    
		    dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey, NULL);
		} else if(pDrawable->type == DRAWABLE_PIXMAP) {
		    PixmapPtr pPix = (PixmapPtr)pDrawable;
		    
		    dixSetPrivate(&pPix->devPrivates, DRIPixmapPrivKey, NULL);
		}
		
                return FALSE;
            }
        }

        pDRIDrawablePriv->key[0] = key[0];
        pDRIDrawablePriv->key[1] = key[1];

        ++pDRIPriv->nrWindows;

        /* and stash it by surface id */
        if (surface_hash == NULL)
            surface_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
        x_hash_table_insert(surface_hash,
                            x_cvt_uint_to_vptr(pDRIDrawablePriv->sid), pDRIDrawablePriv);

        /* track this in case this window is destroyed */
        AddResource(id, DRIDrawablePrivResType, (pointer)pDrawable);

        /* Initialize shape */
        DRIUpdateSurface(pDRIDrawablePriv, pDrawable);
    }

    pDRIDrawablePriv->refCount++;

    *surface_id = pDRIDrawablePriv->sid;

    if (ret_key != NULL) {
        ret_key[0] = pDRIDrawablePriv->key[0];
        ret_key[1] = pDRIDrawablePriv->key[1];
    }

    if (notify != NULL) {
        pDRIDrawablePriv->notifiers = x_hook_add(pDRIDrawablePriv->notifiers,
                                                 notify, notify_data);
    }

    return TRUE;
}
Example #4
0
/*
 * Create and display a new frame.
 */
Bool
xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
               int newX, int newY, RegionPtr pShape)
{
    WindowPtr pWin = pFrame->win;
    xp_window_changes wc;
    unsigned int mask = 0;
    xp_error err;

    wc.x = newX;
    wc.y = newY;
    wc.width = pFrame->width;
    wc.height = pFrame->height;
    wc.bit_gravity = XP_GRAVITY_NONE;
    mask |= XP_BOUNDS;

    if (pWin->drawable.depth == 8)
    {
        wc.depth = XP_DEPTH_INDEX8;
#if 0
        wc.colormap = xprColormapCallback;
        wc.colormap_data = pScreen;
        mask |= XP_COLORMAP;
#endif
    }
    else if (pWin->drawable.depth == 15)
        wc.depth = XP_DEPTH_RGB555;
    else if (pWin->drawable.depth == 24)
        wc.depth = XP_DEPTH_ARGB8888;
    else
        wc.depth = XP_DEPTH_NIL;
    mask |= XP_DEPTH;

    if (pShape != NULL)
    {
        wc.shape_nrects = REGION_NUM_RECTS(pShape);
        wc.shape_rects = REGION_RECTS(pShape);
        wc.shape_tx = wc.shape_ty = 0;
        mask |= XP_SHAPE;
    }

    err = xp_create_window(mask, &wc, (xp_window_id *) &pFrame->wid);

    if (err != Success)
    {
        return FALSE;
    }

    if (window_hash == NULL)
    {
        window_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
        pthread_mutex_init(&window_hash_mutex, NULL);
    }

    pthread_mutex_lock(&window_hash_mutex);
    x_hash_table_insert(window_hash, pFrame->wid, pFrame);
    pthread_mutex_unlock(&window_hash_mutex);

    xprSetNativeProperty(pFrame);

    return TRUE;
}