Mesa (master): st/wgl: Just pass pPixelFormat to stw_pixelformat_get_info() .

Jose Fonseca jrfonseca at kemper.freedesktop.org
Fri Feb 10 16:23:35 UTC 2012


Module: Mesa
Branch: master
Commit: 0cf554fa9b31dbac1890f496974392001e2df825
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0cf554fa9b31dbac1890f496974392001e2df825

Author: José Fonseca <jfonseca at vmware.com>
Date:   Wed Feb  8 15:58:37 2012 +0000

st/wgl: Just pass pPixelFormat to stw_pixelformat_get_info().

Avoids the likely error of forgetting to subtract one.

---

 src/gallium/state_trackers/wgl/stw_context.c       |    2 +-
 src/gallium/state_trackers/wgl/stw_ext_pbuffer.c   |    2 +-
 .../state_trackers/wgl/stw_ext_pixelformat.c       |    8 ++---
 src/gallium/state_trackers/wgl/stw_framebuffer.c   |    2 +-
 src/gallium/state_trackers/wgl/stw_pixelformat.c   |   31 ++++++++++++-------
 src/gallium/state_trackers/wgl/stw_pixelformat.h   |    2 +-
 6 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/src/gallium/state_trackers/wgl/stw_context.c b/src/gallium/state_trackers/wgl/stw_context.c
index abdcf1e..1409f24 100644
--- a/src/gallium/state_trackers/wgl/stw_context.c
+++ b/src/gallium/state_trackers/wgl/stw_context.c
@@ -154,7 +154,7 @@ stw_create_context_attribs(
    if(!iPixelFormat)
       return 0;
 
-   pfi = stw_pixelformat_get_info( iPixelFormat - 1 );
+   pfi = stw_pixelformat_get_info( iPixelFormat );
 
    if (hShareContext != 0) {
       pipe_mutex_lock( stw_dev->ctx_mutex );
diff --git a/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c b/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c
index a2224fb..252d07a 100644
--- a/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c
+++ b/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c
@@ -82,7 +82,7 @@ wglCreatePbufferARB(HDC _hDC,
    HWND hWnd;
    HDC hDC;
 
-   info = stw_pixelformat_get_info(iPixelFormat - 1);
+   info = stw_pixelformat_get_info(iPixelFormat);
    if (!info) {
       SetLastError(ERROR_INVALID_PIXEL_FORMAT);
       return 0;
diff --git a/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c b/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c
index d0a9586..52253fc 100644
--- a/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c
+++ b/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c
@@ -55,7 +55,6 @@ stw_query_attrib(
    int *pvalue )
 {
    uint count;
-   uint index;
    const struct stw_pixelformat_info *pfi;
 
    count = stw_pixelformat_get_extended_count();
@@ -65,11 +64,10 @@ stw_query_attrib(
       return TRUE;
    }
 
-   index = (uint) iPixelFormat - 1;
-   if (index >= count)
+   pfi = stw_pixelformat_get_info( iPixelFormat );
+   if (!pfi) {
       return FALSE;
-
-   pfi = stw_pixelformat_get_info( index );
+   }
 
    switch (attrib) {
    case WGL_DRAW_TO_WINDOW_ARB:
diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.c b/src/gallium/state_trackers/wgl/stw_framebuffer.c
index f595efe..71b92f0 100644
--- a/src/gallium/state_trackers/wgl/stw_framebuffer.c
+++ b/src/gallium/state_trackers/wgl/stw_framebuffer.c
@@ -262,7 +262,7 @@ stw_framebuffer_create(
    fb->hWnd = hWnd;
    fb->iPixelFormat = iPixelFormat;
 
-   fb->pfi = pfi = stw_pixelformat_get_info( iPixelFormat - 1 );
+   fb->pfi = pfi = stw_pixelformat_get_info( iPixelFormat );
    fb->stfb = stw_st_create_framebuffer( fb );
    if (!fb->stfb) {
       FREE( fb );
diff --git a/src/gallium/state_trackers/wgl/stw_pixelformat.c b/src/gallium/state_trackers/wgl/stw_pixelformat.c
index ec04431..ffb7488 100644
--- a/src/gallium/state_trackers/wgl/stw_pixelformat.c
+++ b/src/gallium/state_trackers/wgl/stw_pixelformat.c
@@ -262,9 +262,18 @@ stw_pixelformat_get_extended_count( void )
 }
 
 const struct stw_pixelformat_info *
-stw_pixelformat_get_info( uint index )
+stw_pixelformat_get_info( int iPixelFormat )
 {
-   assert( index < stw_dev->pixelformat_extended_count );
+   int index;
+
+   if (iPixelFormat <= 0) {
+      return NULL;
+   }
+
+   index = iPixelFormat - 1;
+   if (index >= stw_dev->pixelformat_extended_count) {
+      return NULL;
+   }
 
    return &stw_dev->pixelformats[index];
 }
@@ -278,7 +287,6 @@ DrvDescribePixelFormat(
    PIXELFORMATDESCRIPTOR *ppfd )
 {
    uint count;
-   uint index;
    const struct stw_pixelformat_info *pfi;
 
    (void) hdc;
@@ -287,14 +295,16 @@ DrvDescribePixelFormat(
       return 0;
 
    count = stw_pixelformat_get_extended_count();
-   index = (uint) iPixelFormat - 1;
 
    if (ppfd == NULL)
       return count;
-   if (index >= count || cjpfd != sizeof( PIXELFORMATDESCRIPTOR ))
+   if (cjpfd != sizeof( PIXELFORMATDESCRIPTOR ))
       return 0;
 
-   pfi = stw_pixelformat_get_info( index );
+   pfi = stw_pixelformat_get_info( iPixelFormat );
+   if (!pfi) {
+      return 0;
+   }
    
    memcpy(ppfd, &pfi->pfd, sizeof( PIXELFORMATDESCRIPTOR ));
 
@@ -361,10 +371,10 @@ int stw_pixelformat_choose( HDC hdc,
    (void) hdc;
 
    count = stw_pixelformat_get_count();
-   bestindex = count;
+   bestindex = 0;
    bestdelta = ~0U;
 
-   for (index = 0; index < count; index++) {
+   for (index = 1; index <= count; index++) {
       uint delta = 0;
       const struct stw_pixelformat_info *pfi = stw_pixelformat_get_info( index );
 
@@ -394,8 +404,5 @@ int stw_pixelformat_choose( HDC hdc,
       }
    }
 
-   if (bestindex == count)
-      return 0;
-
-   return bestindex + 1;
+   return bestindex;
 }
diff --git a/src/gallium/state_trackers/wgl/stw_pixelformat.h b/src/gallium/state_trackers/wgl/stw_pixelformat.h
index 282c9f6..dae9c3f 100644
--- a/src/gallium/state_trackers/wgl/stw_pixelformat.h
+++ b/src/gallium/state_trackers/wgl/stw_pixelformat.h
@@ -55,7 +55,7 @@ uint
 stw_pixelformat_get_extended_count( void );
 
 const struct stw_pixelformat_info *
-stw_pixelformat_get_info( uint index );
+stw_pixelformat_get_info( int iPixelFormat );
 
 int
 stw_pixelformat_choose( HDC hdc,




More information about the mesa-commit mailing list