1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 #include "main/context.h"
31 #include "pipe/p_format.h"
32 #include "state_tracker/st_context.h"
33 #include "state_tracker/st_public.h"
34 #include "stw_framebuffer.h"
38 struct stw_framebuffer
*fb
,
42 if (fb
->hbmDIB
== NULL
|| fb
->stfb
->Base
.Width
!= width
|| fb
->stfb
->Base
.Height
!= height
) {
44 DeleteObject( fb
->hbmDIB
);
46 fb
->hbmDIB
= CreateCompatibleBitmap(
52 st_resize_framebuffer( fb
->stfb
, width
, height
);
55 static struct stw_framebuffer
*fb_head
= NULL
;
57 static LRESULT CALLBACK
64 struct stw_framebuffer
*fb
;
66 for (fb
= fb_head
; fb
!= NULL
; fb
= fb
->next
)
71 if (uMsg
== WM_SIZE
&& wParam
!= SIZE_MINIMIZED
)
72 framebuffer_resize( fb
, LOWORD( lParam
), HIWORD( lParam
) );
74 return CallWindowProc( fb
->WndProc
, hWnd
, uMsg
, wParam
, lParam
);
77 /* Create a new framebuffer object which will correspond to the given HDC.
79 struct stw_framebuffer
*
86 struct stw_framebuffer
*fb
;
87 enum pipe_format colorFormat
, depthFormat
, stencilFormat
;
89 fb
= CALLOC_STRUCT( stw_framebuffer
);
93 /* Determine PIPE_FORMATs for buffers.
95 colorFormat
= PIPE_FORMAT_A8R8G8B8_UNORM
;
97 if (visual
->depthBits
== 0)
98 depthFormat
= PIPE_FORMAT_NONE
;
99 else if (visual
->depthBits
<= 16)
100 depthFormat
= PIPE_FORMAT_Z16_UNORM
;
101 else if (visual
->depthBits
<= 24)
102 depthFormat
= PIPE_FORMAT_S8Z24_UNORM
;
104 depthFormat
= PIPE_FORMAT_Z32_UNORM
;
106 if (visual
->stencilBits
== 8) {
107 if (depthFormat
== PIPE_FORMAT_S8Z24_UNORM
)
108 stencilFormat
= depthFormat
;
110 stencilFormat
= PIPE_FORMAT_S8_UNORM
;
113 stencilFormat
= PIPE_FORMAT_NONE
;
116 fb
->stfb
= st_create_framebuffer(
125 fb
->cColorBits
= GetDeviceCaps( hdc
, BITSPIXEL
);
128 /* Subclass a window associated with the device context.
130 fb
->hWnd
= WindowFromDC( hdc
);
131 if (fb
->hWnd
!= NULL
) {
132 fb
->WndProc
= (WNDPROC
) SetWindowLong(
135 (LONG
) window_proc
);
145 struct stw_framebuffer
*fb
)
147 struct stw_framebuffer
**link
= &fb_head
;
148 struct stw_framebuffer
*pfb
= fb_head
;
150 while (pfb
!= NULL
) {
152 if (fb
->hWnd
!= NULL
) {
156 (LONG
) fb
->WndProc
);
169 /* Given an hdc, return the corresponding wgl_context.
171 struct stw_framebuffer
*
172 framebuffer_from_hdc(
175 struct stw_framebuffer
*fb
;
177 for (fb
= fb_head
; fb
!= NULL
; fb
= fb
->next
)