1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 #define WGL_WGLEXT_PROTOTYPES
33 #include <GL/wglext.h>
35 #include "pipe/p_defines.h"
36 #include "pipe/p_screen.h"
38 #include "stw_device.h"
39 #include "stw_pixelformat.h"
40 #include "stw_framebuffer.h"
43 #define LARGE_WINDOW_SIZE 60000
46 static LRESULT CALLBACK
47 WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
51 case WM_GETMINMAXINFO:
52 // Allow to create a window bigger than the desktop
53 pMMI = (MINMAXINFO *)lParam;
54 pMMI->ptMaxSize.x = LARGE_WINDOW_SIZE;
55 pMMI->ptMaxSize.y = LARGE_WINDOW_SIZE;
56 pMMI->ptMaxTrackSize.x = LARGE_WINDOW_SIZE;
57 pMMI->ptMaxTrackSize.y = LARGE_WINDOW_SIZE;
63 return DefWindowProc(hWnd, uMsg, wParam, lParam);
68 wglCreatePbufferARB(HDC _hDC,
72 const int *piAttribList)
74 static boolean first = TRUE;
77 const struct stw_pixelformat_info *info;
78 struct stw_framebuffer *fb;
85 info = stw_pixelformat_get_info(iPixelFormat);
87 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
91 if (iWidth <= 0 || iHeight <= 0) {
92 SetLastError(ERROR_INVALID_DATA);
96 for (piAttrib = piAttribList; *piAttrib; piAttrib++) {
98 case WGL_PBUFFER_LARGEST_ARB:
100 useLargest = *piAttrib;
103 SetLastError(ERROR_INVALID_DATA);
108 if (iWidth > stw_dev->max_2d_length) {
110 iWidth = stw_dev->max_2d_length;
112 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
117 if (iHeight > stw_dev->max_2d_length) {
119 iHeight = stw_dev->max_2d_length;
121 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
127 * Implement pbuffers through invisible windows
132 memset(&wc, 0, sizeof wc);
133 wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
134 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
135 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
136 wc.lpfnWndProc = WndProc;
137 wc.lpszClassName = "wglpbuffer";
138 wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
144 dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
148 * Don't hide the window -- useful for debugging what the application is
152 dwStyle |= WS_VISIBLE | WS_OVERLAPPEDWINDOW;
154 dwStyle |= WS_POPUPWINDOW;
159 rect.right = rect.left + iWidth;
160 rect.bottom = rect.top + iHeight;
163 * The CreateWindowEx parameters are the total (outside) dimensions of the
164 * window, which can vary with Windows version and user settings. Use
165 * AdjustWindowRect to get the required total area for the given client area.
167 * AdjustWindowRectEx does not accept WS_OVERLAPPED style (which is defined
168 * as 0), which means we need to use some other style instead, e.g.,
169 * WS_OVERLAPPEDWINDOW or WS_POPUPWINDOW as above.
172 AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
174 hWnd = CreateWindowEx(dwExStyle,
175 "wglpbuffer", /* wc.lpszClassName */
178 CW_USEDEFAULT, /* x */
179 CW_USEDEFAULT, /* y */
180 rect.right - rect.left, /* width */
181 rect.bottom - rect.top, /* height */
192 * Verify the client area size matches the specified size.
195 GetClientRect(hWnd, &rect);
196 assert(rect.left == 0);
197 assert(rect.top == 0);
198 assert(rect.right - rect.left == iWidth);
199 assert(rect.bottom - rect.top == iHeight);
207 SetPixelFormat(hDC, iPixelFormat, &info->pfd);
209 fb = stw_framebuffer_create(hDC, iPixelFormat);
211 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
214 return (HPBUFFERARB)fb;
219 wglGetPbufferDCARB(HPBUFFERARB hPbuffer)
221 struct stw_framebuffer *fb;
224 fb = (struct stw_framebuffer *)hPbuffer;
226 hDC = GetDC(fb->hWnd);
227 SetPixelFormat(hDC, fb->iPixelFormat, &fb->pfi->pfd);
234 wglReleasePbufferDCARB(HPBUFFERARB hPbuffer,
237 struct stw_framebuffer *fb;
239 fb = (struct stw_framebuffer *)hPbuffer;
241 return ReleaseDC(fb->hWnd, hDC);
246 wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
248 struct stw_framebuffer *fb;
250 fb = (struct stw_framebuffer *)hPbuffer;
252 /* This will destroy all our data */
253 return DestroyWindow(fb->hWnd);
258 wglQueryPbufferARB(HPBUFFERARB hPbuffer,
262 struct stw_framebuffer *fb;
264 fb = (struct stw_framebuffer *)hPbuffer;
266 switch (iAttribute) {
267 case WGL_PBUFFER_WIDTH_ARB:
268 *piValue = fb->width;
270 case WGL_PBUFFER_HEIGHT_ARB:
271 *piValue = fb->height;
273 case WGL_PBUFFER_LOST_ARB:
274 /* We assume that no content is ever lost due to display mode change */
278 SetLastError(ERROR_INVALID_DATA);