xref: /OK3568_Linux_fs/external/xserver/hw/xwin/glx/dri_helpers.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright © 2014 Jon Turney
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #ifdef HAVE_XWIN_CONFIG_H
25 #include <xwin-config.h>
26 #endif
27 
28 #include <glx/glxserver.h>
29 #include <glx/glxutil.h>
30 #include <X11/extensions/windowsdriconst.h>
31 
32 #include "indirect.h"
33 #include "winpriv.h"
34 #include "dri_helpers.h"
35 #include "win.h"
36 
37 int
glxWinQueryDrawable(ClientPtr client,XID drawId,unsigned int * type,unsigned int * handle)38 glxWinQueryDrawable(ClientPtr client, XID drawId, unsigned int *type, unsigned int *handle)
39 {
40     __GLXWinDrawable *pDrawable;
41     int err;
42 
43     if (validGlxDrawable(client, drawId, GLX_DRAWABLE_ANY,
44                          DixReadAccess, (__GLXdrawable **)&pDrawable, &err)) {
45 
46         switch (pDrawable->base.type)
47             {
48             case GLX_DRAWABLE_WINDOW:
49                 {
50                     HWND h = winGetWindowInfo((WindowPtr)(pDrawable->base.pDraw));
51                     *handle = (uintptr_t)h;
52                     *type = WindowsDRIDrawableWindow;
53                 }
54                 break;
55 
56             case GLX_DRAWABLE_PIXMAP:
57                 glxWinDeferredCreateDrawable(pDrawable, pDrawable->base.config);
58                 *handle = pDrawable->base.pDraw->id;
59                 // The XID is used to create a unique name for a file mapping
60                 // shared with the requesting process
61                 //
62                 // XXX: Alternatively, we could use an anonymous file mapping
63                 // and use DuplicateHandle to make pDrawable->hSection available
64                 // to the requesting process... ?
65                 *type = WindowsDRIDrawablePixmap;
66                 break;
67 
68             case GLX_DRAWABLE_PBUFFER:
69                 glxWinDeferredCreateDrawable(pDrawable, pDrawable->base.config);
70                 *handle = (uintptr_t)(pDrawable->hPbuffer);
71                 *type = WindowsDRIDrawablePbuffer;
72                 break;
73 
74             default:
75                 assert(FALSE);
76                 *handle = 0;
77             }
78     }
79     else {
80         HWND h;
81         /* The drawId XID doesn't identify a GLX drawable.  The only other valid
82            alternative is that it is the XID of a window drawable that is being
83            used by the pre-GLX 1.3 interface */
84         DrawablePtr pDraw;
85         int rc = dixLookupDrawable(&pDraw, drawId, client, 0, DixGetAttrAccess);
86         if (rc != Success || pDraw->type != DRAWABLE_WINDOW) {
87             return err;
88         }
89 
90         h = winGetWindowInfo((WindowPtr)(pDraw));
91         *handle = (uintptr_t)h;
92         *type = WindowsDRIDrawableWindow;
93     }
94 
95     winDebug("glxWinQueryDrawable: type %d, handle %p\n", *type, (void *)(uintptr_t)*handle);
96     return Success;
97 }
98 
99 int
glxWinFBConfigIDToPixelFormatIndex(int scr,int fbConfigID)100 glxWinFBConfigIDToPixelFormatIndex(int scr, int fbConfigID)
101 {
102     __GLXscreen *screen = glxGetScreen(screenInfo.screens[scr]);
103     __GLXconfig *c;
104 
105     for (c = screen->fbconfigs;
106          c != NULL;
107          c = c->next) {
108         if (c->fbconfigID == fbConfigID)
109             return ((GLXWinConfig *)c)->pixelFormatIndex;
110     }
111 
112     return 0;
113 }
114 
115 Bool
glxWinGetScreenAiglxIsActive(ScreenPtr pScreen)116 glxWinGetScreenAiglxIsActive(ScreenPtr pScreen)
117 {
118     winPrivScreenPtr pWinScreen = winGetScreenPriv(pScreen);
119     return pWinScreen->fNativeGlActive;
120 }
121