11b5d61b8Smrg/*
21b5d61b8Smrg * Copyright © 2014 Jon Turney
31b5d61b8Smrg *
41b5d61b8Smrg * Permission is hereby granted, free of charge, to any person obtaining a
51b5d61b8Smrg * copy of this software and associated documentation files (the "Software"),
61b5d61b8Smrg * to deal in the Software without restriction, including without limitation
71b5d61b8Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
81b5d61b8Smrg * and/or sell copies of the Software, and to permit persons to whom the
91b5d61b8Smrg * Software is furnished to do so, subject to the following conditions:
101b5d61b8Smrg *
111b5d61b8Smrg * The above copyright notice and this permission notice (including the next
121b5d61b8Smrg * paragraph) shall be included in all copies or substantial portions of the
131b5d61b8Smrg * Software.
141b5d61b8Smrg *
151b5d61b8Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161b5d61b8Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171b5d61b8Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
181b5d61b8Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
191b5d61b8Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
201b5d61b8Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
211b5d61b8Smrg * IN THE SOFTWARE.
221b5d61b8Smrg */
231b5d61b8Smrg
241b5d61b8Smrg#ifdef HAVE_XWIN_CONFIG_H
251b5d61b8Smrg#include <xwin-config.h>
261b5d61b8Smrg#endif
271b5d61b8Smrg
281b5d61b8Smrg#include <glx/glxserver.h>
291b5d61b8Smrg#include <glx/glxutil.h>
301b5d61b8Smrg#include <X11/extensions/windowsdriconst.h>
311b5d61b8Smrg
321b5d61b8Smrg#include "indirect.h"
331b5d61b8Smrg#include "winpriv.h"
341b5d61b8Smrg#include "dri_helpers.h"
351b5d61b8Smrg#include "win.h"
361b5d61b8Smrg
371b5d61b8Smrgint
381b5d61b8SmrgglxWinQueryDrawable(ClientPtr client, XID drawId, unsigned int *type, unsigned int *handle)
391b5d61b8Smrg{
401b5d61b8Smrg    __GLXWinDrawable *pDrawable;
411b5d61b8Smrg    int err;
421b5d61b8Smrg
431b5d61b8Smrg    if (validGlxDrawable(client, drawId, GLX_DRAWABLE_ANY,
441b5d61b8Smrg                         DixReadAccess, (__GLXdrawable **)&pDrawable, &err)) {
451b5d61b8Smrg
461b5d61b8Smrg        switch (pDrawable->base.type)
471b5d61b8Smrg            {
481b5d61b8Smrg            case GLX_DRAWABLE_WINDOW:
491b5d61b8Smrg                {
501b5d61b8Smrg                    HWND h = winGetWindowInfo((WindowPtr)(pDrawable->base.pDraw));
511b5d61b8Smrg                    *handle = (uintptr_t)h;
521b5d61b8Smrg                    *type = WindowsDRIDrawableWindow;
531b5d61b8Smrg                }
541b5d61b8Smrg                break;
551b5d61b8Smrg
561b5d61b8Smrg            case GLX_DRAWABLE_PIXMAP:
571b5d61b8Smrg                glxWinDeferredCreateDrawable(pDrawable, pDrawable->base.config);
581b5d61b8Smrg                *handle = pDrawable->base.pDraw->id;
591b5d61b8Smrg                // The XID is used to create a unique name for a file mapping
601b5d61b8Smrg                // shared with the requesting process
611b5d61b8Smrg                //
621b5d61b8Smrg                // XXX: Alternatively, we could use an anonymous file mapping
631b5d61b8Smrg                // and use DuplicateHandle to make pDrawable->hSection available
641b5d61b8Smrg                // to the requesting process... ?
651b5d61b8Smrg                *type = WindowsDRIDrawablePixmap;
661b5d61b8Smrg                break;
671b5d61b8Smrg
681b5d61b8Smrg            case GLX_DRAWABLE_PBUFFER:
691b5d61b8Smrg                glxWinDeferredCreateDrawable(pDrawable, pDrawable->base.config);
701b5d61b8Smrg                *handle = (uintptr_t)(pDrawable->hPbuffer);
711b5d61b8Smrg                *type = WindowsDRIDrawablePbuffer;
721b5d61b8Smrg                break;
731b5d61b8Smrg
741b5d61b8Smrg            default:
751b5d61b8Smrg                assert(FALSE);
761b5d61b8Smrg                *handle = 0;
771b5d61b8Smrg            }
781b5d61b8Smrg    }
791b5d61b8Smrg    else {
801b5d61b8Smrg        HWND h;
811b5d61b8Smrg        /* The drawId XID doesn't identify a GLX drawable.  The only other valid
821b5d61b8Smrg           alternative is that it is the XID of a window drawable that is being
831b5d61b8Smrg           used by the pre-GLX 1.3 interface */
841b5d61b8Smrg        DrawablePtr pDraw;
851b5d61b8Smrg        int rc = dixLookupDrawable(&pDraw, drawId, client, 0, DixGetAttrAccess);
861b5d61b8Smrg        if (rc != Success || pDraw->type != DRAWABLE_WINDOW) {
871b5d61b8Smrg            return err;
881b5d61b8Smrg        }
891b5d61b8Smrg
901b5d61b8Smrg        h = winGetWindowInfo((WindowPtr)(pDraw));
911b5d61b8Smrg        *handle = (uintptr_t)h;
921b5d61b8Smrg        *type = WindowsDRIDrawableWindow;
931b5d61b8Smrg    }
941b5d61b8Smrg
951b5d61b8Smrg    winDebug("glxWinQueryDrawable: type %d, handle %p\n", *type, (void *)(uintptr_t)*handle);
961b5d61b8Smrg    return Success;
971b5d61b8Smrg}
981b5d61b8Smrg
991b5d61b8Smrgint
1001b5d61b8SmrgglxWinFBConfigIDToPixelFormatIndex(int scr, int fbConfigID)
1011b5d61b8Smrg{
1021b5d61b8Smrg    __GLXscreen *screen = glxGetScreen(screenInfo.screens[scr]);
1031b5d61b8Smrg    __GLXconfig *c;
1041b5d61b8Smrg
1051b5d61b8Smrg    for (c = screen->fbconfigs;
1061b5d61b8Smrg         c != NULL;
1071b5d61b8Smrg         c = c->next) {
1081b5d61b8Smrg        if (c->fbconfigID == fbConfigID)
1091b5d61b8Smrg            return ((GLXWinConfig *)c)->pixelFormatIndex;
1101b5d61b8Smrg    }
1111b5d61b8Smrg
1121b5d61b8Smrg    return 0;
1131b5d61b8Smrg}
1141b5d61b8Smrg
1151b5d61b8SmrgBool
1161b5d61b8SmrgglxWinGetScreenAiglxIsActive(ScreenPtr pScreen)
1171b5d61b8Smrg{
1181b5d61b8Smrg    winPrivScreenPtr pWinScreen = winGetScreenPriv(pScreen);
1191b5d61b8Smrg    return pWinScreen->fNativeGlActive;
1201b5d61b8Smrg}
121