Mesa (7.10): st/wgl: Cope with zero width/height windows.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Sun Jun 12 08:25:01 UTC 2011


Module: Mesa
Branch: 7.10
Commit: 3f3d1991219fb9b80da667b42c0ea02e7074202e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3f3d1991219fb9b80da667b42c0ea02e7074202e

Author: José Fonseca <jfonseca at vmware.com>
Date:   Mon Apr 18 16:41:25 2011 +0100

st/wgl: Cope with zero width/height windows.

While ensuring the framebuffer area is never zero.

---

 src/gallium/state_trackers/wgl/stw_framebuffer.c |   50 ++++++++++++++++-----
 1 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.c b/src/gallium/state_trackers/wgl/stw_framebuffer.c
index d8b1440..4033365 100644
--- a/src/gallium/state_trackers/wgl/stw_framebuffer.c
+++ b/src/gallium/state_trackers/wgl/stw_framebuffer.c
@@ -117,13 +117,26 @@ stw_framebuffer_get_size( struct stw_framebuffer *fb )
    RECT window_rect;
    POINT client_pos;
 
+   /*
+    * Sanity checking.
+    */
+
    assert(fb->hWnd);
-   
-   /* Get the client area size. */
-   GetClientRect( fb->hWnd, &client_rect );
+   assert(fb->width && fb->height);
+   assert(fb->client_rect.right  == fb->client_rect.left + fb->width);
+   assert(fb->client_rect.bottom == fb->client_rect.top  + fb->height);
+
+   /*
+    * Get the client area size.
+    */
+
+   if (!GetClientRect(fb->hWnd, &client_rect)) {
+      return;
+   }
+
    assert(client_rect.left == 0);
    assert(client_rect.top == 0);
-   width = client_rect.right - client_rect.left;
+   width  = client_rect.right  - client_rect.left;
    height = client_rect.bottom - client_rect.top;
 
    if (width <= 0 || height <= 0) {
@@ -138,7 +151,7 @@ stw_framebuffer_get_size( struct stw_framebuffer *fb )
       return;
    }
 
-   if(width != fb->width || height != fb->height) {
+   if (width != fb->width || height != fb->height) {
       fb->must_resize = TRUE;
       fb->width = width; 
       fb->height = height; 
@@ -146,14 +159,14 @@ stw_framebuffer_get_size( struct stw_framebuffer *fb )
 
    client_pos.x = 0;
    client_pos.y = 0;
-   ClientToScreen(fb->hWnd, &client_pos);
-
-   GetWindowRect(fb->hWnd, &window_rect);
+   if (ClientToScreen(fb->hWnd, &client_pos) &&
+       GetWindowRect(fb->hWnd, &window_rect)) {
+      fb->client_rect.left = client_pos.x - window_rect.left;
+      fb->client_rect.top  = client_pos.y - window_rect.top;
+   }
 
-   fb->client_rect.left = client_pos.x - window_rect.left;
-   fb->client_rect.top =  client_pos.y - window_rect.top;
-   fb->client_rect.right = fb->client_rect.left + fb->width;
-   fb->client_rect.bottom = fb->client_rect.top + fb->height;
+   fb->client_rect.right  = fb->client_rect.left + fb->width;
+   fb->client_rect.bottom = fb->client_rect.top  + fb->height;
 
 #if 0
    debug_printf("\n");
@@ -253,6 +266,19 @@ stw_framebuffer_create(
 
    fb->refcnt = 1;
 
+   /*
+    * Windows can be sometimes have zero width and or height, but we ensure
+    * a non-zero framebuffer size at all times.
+    */
+
+   fb->must_resize = TRUE;
+   fb->width  = 1;
+   fb->height = 1;
+   fb->client_rect.left   = 0;
+   fb->client_rect.top    = 0;
+   fb->client_rect.right  = fb->client_rect.left + fb->width;
+   fb->client_rect.bottom = fb->client_rect.top  + fb->height;
+
    stw_framebuffer_get_size(fb);
 
    pipe_mutex_init( fb->mutex );




More information about the mesa-commit mailing list