summaryrefslogtreecommitdiff
path: root/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/state_trackers/wgl/shared/stw_framebuffer.c')
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_framebuffer.c223
1 files changed, 185 insertions, 38 deletions
diff --git a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c
index f66f429542..45ac3477e8 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c
+++ b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c
@@ -94,32 +94,16 @@ stw_call_window_proc(
}
-/* Create a new framebuffer object which will correspond to the given HDC.
+/**
+ * Create a new framebuffer object which will correspond to the given HDC.
*/
struct stw_framebuffer *
-stw_framebuffer_create(
+stw_framebuffer_create_locked(
HDC hdc,
- GLvisual *visual,
- const struct stw_pixelformat_info *pfi,
- GLuint width,
- GLuint height )
+ int iPixelFormat )
{
- enum pipe_format colorFormat, depthFormat, stencilFormat;
struct stw_framebuffer *fb;
-
- colorFormat = pfi->color_format;
-
- assert(pf_layout( pfi->depth_stencil_format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
-
- if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_Z ))
- depthFormat = pfi->depth_stencil_format;
- else
- depthFormat = PIPE_FORMAT_NONE;
-
- if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_S ))
- stencilFormat = pfi->depth_stencil_format;
- else
- stencilFormat = PIPE_FORMAT_NONE;
+ const struct stw_pixelformat_info *pfi;
fb = CALLOC_STRUCT( stw_framebuffer );
if (fb == NULL)
@@ -127,31 +111,102 @@ stw_framebuffer_create(
fb->hDC = hdc;
fb->hWnd = WindowFromDC( hdc );
+ fb->iPixelFormat = iPixelFormat;
- pipe_mutex_init( fb->mutex );
+ fb->pfi = pfi = stw_pixelformat_get_info( iPixelFormat - 1 );
- fb->stfb = st_create_framebuffer(
- visual,
- colorFormat,
- depthFormat,
- stencilFormat,
- width,
- height,
- (void *) fb );
- if(!fb->stfb) {
- FREE(fb);
- return NULL;
- }
+ stw_pixelformat_visual(&fb->visual, pfi);
+
+ pipe_mutex_init( fb->mutex );
- pipe_mutex_lock( stw_dev->mutex );
fb->next = stw_dev->fb_head;
stw_dev->fb_head = fb;
- pipe_mutex_unlock( stw_dev->mutex );
return fb;
}
+
+static void
+stw_framebuffer_get_size( struct stw_framebuffer *fb, GLuint *pwidth, GLuint *pheight )
+{
+ GLuint width, height;
+
+ if (fb->hWnd) {
+ RECT rect;
+ GetClientRect( fb->hWnd, &rect );
+ width = rect.right - rect.left;
+ height = rect.bottom - rect.top;
+ }
+ else {
+ width = GetDeviceCaps( fb->hDC, HORZRES );
+ height = GetDeviceCaps( fb->hDC, VERTRES );
+ }
+
+ if(width < 1)
+ width = 1;
+ if(height < 1)
+ height = 1;
+
+ *pwidth = width;
+ *pheight = height;
+}
+
+
+BOOL
+stw_framebuffer_allocate(
+ struct stw_framebuffer *fb)
+{
+ pipe_mutex_lock( fb->mutex );
+
+ if(!fb->stfb) {
+ const struct stw_pixelformat_info *pfi = fb->pfi;
+ enum pipe_format colorFormat, depthFormat, stencilFormat;
+ GLuint width, height;
+
+ colorFormat = pfi->color_format;
+
+ assert(pf_layout( pfi->depth_stencil_format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
+
+ if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_Z ))
+ depthFormat = pfi->depth_stencil_format;
+ else
+ depthFormat = PIPE_FORMAT_NONE;
+
+ if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_S ))
+ stencilFormat = pfi->depth_stencil_format;
+ else
+ stencilFormat = PIPE_FORMAT_NONE;
+
+ stw_framebuffer_get_size(fb, &width, &height);
+
+ fb->stfb = st_create_framebuffer(
+ &fb->visual,
+ colorFormat,
+ depthFormat,
+ stencilFormat,
+ width,
+ height,
+ (void *) fb );
+ }
+
+ pipe_mutex_unlock( fb->mutex );
+
+ return fb->stfb ? TRUE : FALSE;
+}
+
+
void
+stw_framebuffer_resize(
+ struct stw_framebuffer *fb)
+{
+ GLuint width, height;
+ assert(fb->stfb);
+ stw_framebuffer_get_size(fb, &width, &height);
+ st_resize_framebuffer(fb->stfb, width, height);
+}
+
+
+static INLINE void
stw_framebuffer_destroy(
struct stw_framebuffer *fb )
{
@@ -176,19 +231,55 @@ stw_framebuffer_destroy(
FREE( fb );
}
+
+void
+stw_framebuffer_cleanup( void )
+{
+ struct stw_framebuffer *fb;
+ struct stw_framebuffer *next;
+
+ pipe_mutex_lock( stw_dev->mutex );
+
+ fb = stw_dev->fb_head;
+ while (fb) {
+ next = fb->next;
+ stw_framebuffer_destroy(fb);
+ fb = next;
+ }
+ stw_dev->fb_head = NULL;
+
+ pipe_mutex_unlock( stw_dev->mutex );
+}
+
+
/**
* Given an hdc, return the corresponding stw_framebuffer.
*/
struct stw_framebuffer *
-stw_framebuffer_from_hdc(
+stw_framebuffer_from_hdc_locked(
HDC hdc )
{
struct stw_framebuffer *fb;
- pipe_mutex_lock( stw_dev->mutex );
for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next)
if (fb->hDC == hdc)
break;
+
+ return fb;
+}
+
+
+/**
+ * Given an hdc, return the corresponding stw_framebuffer.
+ */
+struct stw_framebuffer *
+stw_framebuffer_from_hdc(
+ HDC hdc )
+{
+ struct stw_framebuffer *fb;
+
+ pipe_mutex_lock( stw_dev->mutex );
+ fb = stw_framebuffer_from_hdc_locked(hdc);
pipe_mutex_unlock( stw_dev->mutex );
return fb;
@@ -196,6 +287,62 @@ stw_framebuffer_from_hdc(
BOOL
+stw_pixelformat_set(
+ HDC hdc,
+ int iPixelFormat )
+{
+ uint count;
+ uint index;
+ struct stw_framebuffer *fb;
+
+ index = (uint) iPixelFormat - 1;
+ count = stw_pixelformat_get_extended_count();
+ if (index >= count)
+ return FALSE;
+
+ pipe_mutex_lock( stw_dev->mutex );
+
+ fb = stw_framebuffer_from_hdc_locked(hdc);
+ if(fb) {
+ /* SetPixelFormat must be called only once */
+ pipe_mutex_unlock( stw_dev->mutex );
+ return FALSE;
+ }
+
+ fb = stw_framebuffer_create_locked(hdc, iPixelFormat);
+ if(!fb) {
+ pipe_mutex_unlock( stw_dev->mutex );
+ return FALSE;
+ }
+
+ pipe_mutex_unlock( stw_dev->mutex );
+
+ /* Some applications mistakenly use the undocumented wglSetPixelFormat
+ * function instead of SetPixelFormat, so we call SetPixelFormat here to
+ * avoid opengl32.dll's wglCreateContext to fail */
+ if (GetPixelFormat(hdc) == 0) {
+ SetPixelFormat(hdc, iPixelFormat, NULL);
+ }
+
+ return TRUE;
+}
+
+
+int
+stw_pixelformat_get(
+ HDC hdc )
+{
+ struct stw_framebuffer *fb;
+
+ fb = stw_framebuffer_from_hdc(hdc);
+ if(!fb)
+ return 0;
+
+ return fb->iPixelFormat;
+}
+
+
+BOOL
stw_swap_buffers(
HDC hdc )
{