aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xwin/glx/winpriv.c
blob: 671d81a5be106291c2cebfea43e8bf886f388362 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
 * Export window information for the Windows-OpenGL GLX implementation.
 *
 * Authors: Alexander Gottwald
 */

#ifdef HAVE_XWIN_CONFIG_H
#include <xwin-config.h>
#endif
#include "win.h"
#include "winpriv.h"
#include "winwindow.h"

extern Bool			g_fXdmcpEnabled;

void
winCreateWindowsWindow (WindowPtr pWin);
/**
 * Return size and handles of a window.
 * If pWin is NULL, then the information for the root window is requested.
 */
void winGetWindowInfo(WindowPtr pWin, winWindowInfoPtr pWinInfo)
{
    /* Sanity check */
    if (pWinInfo == NULL)
        return;

    winDebug("%s:%d pWin=%p\n", __FUNCTION__, __LINE__, pWin);

    /* a real window was requested */
    if (pWin != NULL)
    {
        /* Initialize the size information */
        RECT rect = {
            pWin->drawable.x,
            pWin->drawable.y,
            pWin->drawable.x + pWin->drawable.width,
            pWin->drawable.y + pWin->drawable.height
        }, rect_extends;
        /* Get the window and screen privates */
        ScreenPtr pScreen = pWin->drawable.pScreen;
        winPrivScreenPtr pWinScreen = winGetScreenPriv(pScreen);
        winScreenInfoPtr pScreenInfo = NULL;

        rect_extends = rect;
        OffsetRect(&rect_extends, -pWin->drawable.x, -pWin->drawable.y);

        if (pWinScreen == NULL) 
        {
            ErrorF("winGetWindowInfo: screen has no privates\n");
            return;
        }

        pWinInfo->hwnd = pWinScreen->hwndScreen;
        pWinInfo->hrgn = NULL;
        pWinInfo->rect = rect;


        pScreenInfo = pWinScreen->pScreenInfo;
#ifdef XWIN_MULTIWINDOW
        /* check for multiwindow mode */
        if (pScreenInfo->fMultiWindow)
        {
            winWindowPriv(pWin);

            if (pWinPriv == NULL)
            {
                ErrorF("winGetWindowInfo: window has no privates\n");
                return;
            }

            if (pWinPriv->hWnd == NULL)
            {
              winCreateWindowsWindow(pWin);
              ErrorF("winGetWindowInfo: forcing window to exist...\n");
            }
            if (pWinPriv->hWnd != NULL)
            { 
                /* copy size and window handle */
                pWinInfo->rect = rect_extends;
                pWinInfo->hwnd = pWinPriv->hWnd;

                /* Copy window region */
                if (pWinPriv->hRgn)
                {
                  if (!pWinInfo->hrgn)
                  {
                    pWinInfo->hrgn = CreateRectRgn(0,0,0,0);
                  }
                  CombineRgn(pWinInfo->hrgn, pWinPriv->hRgn, pWinPriv->hRgn, 
                          RGN_COPY);
                }
                else if (pWinInfo->hrgn)
                {
                  DeleteObject(pWinInfo->hrgn);
                  pWinInfo->hrgn=NULL;
                }

            }
            
            return;
        }
        else if (g_fXdmcpEnabled)
        {
            winWindowPriv(pWin);

            if (pWinPriv == NULL)
            {
                ErrorF("winGetWindowInfo: window has no privates\n");
                return;
            }
            if (pWinPriv->hWnd == NULL)
            {
              if (!((pWin->drawable.x==0) &&
                     (pWin->drawable.y==0) &&
                     (pWin->drawable.width==pScreen->width) &&
                     (pWin->drawable.height==pScreen->height)
                    )
                  )
              {
                int ExtraClass=(pWin->realized)?WS_VISIBLE:0;
                pWinPriv->hWnd=CreateWindowExA(WS_EX_TRANSPARENT,
                             WIN_GL_WINDOW_CLASS,
                             "",
                             WS_CHILD |WS_CLIPSIBLINGS | WS_CLIPCHILDREN  | ExtraClass,
                             pWin->drawable.x,
                             pWin->drawable.y,
                             pWin->drawable.width,
                             pWin->drawable.height,
                             pWinScreen->hwndScreen,
                             NULL,
                             GetModuleHandle(NULL),
                             NULL);
                pWinPriv->GlCtxWnd=TRUE;
                /* copy size and window handle */
                pWinInfo->hwnd = pWinPriv->hWnd;
              }
              else
              {
                pWinInfo->hwnd = pWinScreen->hwndScreen;
              }
              pWinInfo->rect = rect_extends;
              if (pWinInfo->hrgn)
              {
                DeleteObject(pWinInfo->hrgn);
                pWinInfo->hrgn = NULL;
              }
            }
            else
            {
              pWinInfo->rect = rect_extends;
              pWinInfo->hwnd = pWinPriv->hWnd;
              pWinInfo->hrgn = NULL;
            }
        }
#endif
#ifdef XWIN_MULTIWINDOWEXTWM
        /* check for multiwindow external wm mode */
        if (pScreenInfo->fMWExtWM)
        {
            win32RootlessWindowPtr pRLWinPriv
                = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin, FALSE);

            if (pRLWinPriv == NULL) {
                ErrorF("winGetWindowInfo: window has no privates\n");
                return;
            }

            if (pRLWinPriv->hWnd != NULL)
            {
                /* copy size and window handle */
                pWinInfo->rect = rect_extends;
                pWinInfo->hwnd = pRLWinPriv->hWnd;
            }
            return;
        }
#endif
    }
    else
    {
        RECT rect = {0, 0, 0, 0};
        ScreenPtr pScreen = g_ScreenInfo[0].pScreen;
        winPrivScreenPtr pWinScreen = winGetScreenPriv(pScreen);

        pWinInfo->hwnd = NULL;
        pWinInfo->hrgn = NULL;
        pWinInfo->rect = rect;
        
        if (pWinScreen == NULL)
        {
            ErrorF("winGetWindowInfo: screen has no privates\n");
            return;
        }

        winDebug("winGetWindowInfo: returning root window\n");

        pWinInfo->hwnd = pWinScreen->hwndScreen;
    }
    return;
}

Bool
winCheckScreenAiglxIsSupported(ScreenPtr pScreen)
{
  winPrivScreenPtr pWinScreen = winGetScreenPriv(pScreen);
  winScreenInfoPtr pScreenInfo = pWinScreen->pScreenInfo;

#ifdef XWIN_MULTIWINDOW
  if (pScreenInfo->fMultiWindow)
    return TRUE;
#endif

#ifdef XWIN_MULTIWINDOWEXTWM
  if (pScreenInfo->fMWExtWM)
    return TRUE;
#endif

  if (g_fXdmcpEnabled)
    return TRUE;

  return FALSE;
}