Squashed commit of the following:
[mesa.git] / src / gallium / state_trackers / wgl / stw_pixelformat.c
index c296744838bbdf257a4ee3bd0d047136700e7eea..a07de994ca16c3a676fcca88f14a36be55b48fc9 100644 (file)
 #include "pipe/p_defines.h"
 #include "pipe/p_screen.h"
 
+#include "util/u_format.h"
 #include "util/u_debug.h"
 
+#include "stw_icd.h"
 #include "stw_device.h"
 #include "stw_pixelformat.h"
-#include "stw_public.h"
 #include "stw_tls.h"
 
 
@@ -73,17 +74,17 @@ struct stw_pf_depth_info
 static const struct stw_pf_color_info
 stw_pf_color[] = {
    /* no-alpha */
-   { PIPE_FORMAT_X8R8G8B8_UNORM,    { 8,  8,  8,  0}, {16,  8,  0,  0} },
-   { PIPE_FORMAT_B8G8R8X8_UNORM,    { 8,  8,  8,  0}, { 8, 16, 24,  0} },
-   { PIPE_FORMAT_R5G6B5_UNORM,      { 5,  6,  5,  0}, {11,  5,  0,  0} },
+   { PIPE_FORMAT_B8G8R8X8_UNORM,    { 8,  8,  8,  0}, {16,  8,  0,  0} },
+   { PIPE_FORMAT_X8R8G8B8_UNORM,    { 8,  8,  8,  0}, { 8, 16, 24,  0} },
+   { PIPE_FORMAT_B5G6R5_UNORM,      { 5,  6,  5,  0}, {11,  5,  0,  0} },
    /* alpha */
-   { PIPE_FORMAT_A8R8G8B8_UNORM,    { 8,  8,  8,  8}, {16,  8,  0, 24} },
-   { PIPE_FORMAT_B8G8R8A8_UNORM,    { 8,  8,  8,  8}, { 8, 16, 24,  0} },
+   { PIPE_FORMAT_B8G8R8A8_UNORM,    { 8,  8,  8,  8}, {16,  8,  0, 24} },
+   { PIPE_FORMAT_A8R8G8B8_UNORM,    { 8,  8,  8,  8}, { 8, 16, 24,  0} },
 #if 0
-   { PIPE_FORMAT_A2B10G10R10_UNORM, {10, 10, 10,  2}, { 0, 10, 20, 30} },
+   { PIPE_FORMAT_R10G10B10A2_UNORM, {10, 10, 10,  2}, { 0, 10, 20, 30} },
 #endif
-   { PIPE_FORMAT_A1R5G5B5_UNORM,    { 5,  5,  5,  1}, {10,  5,  0, 15} },
-   { PIPE_FORMAT_A4R4G4B4_UNORM,    { 4,  4,  4,  4}, {16,  4,  0, 12} }
+   { PIPE_FORMAT_B5G5R5A1_UNORM,    { 5,  5,  5,  1}, {10,  5,  0, 15} },
+   { PIPE_FORMAT_B4G4R4A4_UNORM,    { 4,  4,  4,  4}, {16,  4,  0, 12} }
 };
 
 
@@ -91,14 +92,12 @@ static const struct stw_pf_depth_info
 stw_pf_depth_stencil[] = {
    /* pure depth */
    { PIPE_FORMAT_Z32_UNORM,   {32, 0} },
-   { PIPE_FORMAT_Z24X8_UNORM, {24, 0} },
    { PIPE_FORMAT_X8Z24_UNORM, {24, 0} },
+   { PIPE_FORMAT_Z24X8_UNORM, {24, 0} },
    { PIPE_FORMAT_Z16_UNORM,   {16, 0} },
-   /* pure stencil */
-   { PIPE_FORMAT_S8_UNORM,    { 0, 8} },
    /* combined depth-stencil */
-   { PIPE_FORMAT_S8Z24_UNORM, {24, 8} },
-   { PIPE_FORMAT_Z24S8_UNORM, {24, 8} }
+   { PIPE_FORMAT_Z24_UNORM_S8_USCALED, {24, 8} },
+   { PIPE_FORMAT_S8_USCALED_Z24_UNORM, {24, 8} }
 };
 
 
@@ -132,14 +131,12 @@ stw_pixelformat_add(
    if(stw_dev->pixelformat_extended_count >= STW_MAX_PIXELFORMATS)
       return;
 
-   assert(pf_layout( color->format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
-   assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_R ) == color->bits.red );
-   assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_G ) == color->bits.green );
-   assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_B ) == color->bits.blue );
-   assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_A ) == color->bits.alpha );
-   assert(pf_layout( depth->format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
-   assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_Z ) == depth->bits.depth );
-   assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_S ) == depth->bits.stencil );
+   assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 0) == color->bits.red);
+   assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 1) == color->bits.green);
+   assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 2) == color->bits.blue);
+   assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 3) == color->bits.alpha);
+   assert(util_format_get_component_bits(depth->format, UTIL_FORMAT_COLORSPACE_ZS, 0) == depth->bits.depth);
+   assert(util_format_get_component_bits(depth->format, UTIL_FORMAT_COLORSPACE_ZS, 1) == depth->bits.stencil);
    
    pfi = &stw_dev->pixelformats[stw_dev->pixelformat_extended_count];
    
@@ -154,8 +151,11 @@ stw_pixelformat_add(
    pfi->pfd.dwFlags = PFD_SUPPORT_OPENGL;
    
    /* TODO: also support non-native pixel formats */
-   pfi->pfd.dwFlags |= PFD_DRAW_TO_WINDOW ;
-   
+   pfi->pfd.dwFlags |= PFD_DRAW_TO_WINDOW;
+
+   /* See http://www.opengl.org/pipeline/article/vol003_7/ */
+   pfi->pfd.dwFlags |= PFD_SUPPORT_COMPOSITION;
+
    if (doublebuffer)
       pfi->pfd.dwFlags |= PFD_DOUBLEBUFFER | PFD_SWAP_COPY;
    
@@ -218,7 +218,8 @@ stw_pixelformat_init( void )
          const struct stw_pf_color_info *color = &stw_pf_color[j];
          
          if(!screen->is_format_supported(screen, color->format, PIPE_TEXTURE_2D, 
-                                         PIPE_TEXTURE_USAGE_RENDER_TARGET, 0))
+                                         PIPE_BIND_RENDER_TARGET |
+                                         PIPE_BIND_DISPLAY_TARGET, 0))
             continue;
          
          for(k = 0; k < Elements(stw_pf_doublebuffer); ++k) {
@@ -228,7 +229,7 @@ stw_pixelformat_init( void )
                const struct stw_pf_depth_info *depth = &stw_pf_depth_stencil[l];
                
                if(!screen->is_format_supported(screen, depth->format, PIPE_TEXTURE_2D, 
-                                               PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0))
+                                               PIPE_BIND_DEPTH_STENCIL, 0))
                   continue;
 
                stw_pixelformat_add( stw_dev, color, depth,  0, doublebuffer, samples );
@@ -270,14 +271,12 @@ stw_pixelformat_visual(GLvisual *visual,
    memset(visual, 0, sizeof *visual);
    _mesa_initialize_visual(
       visual,
-      (pfi->pfd.iPixelType == PFD_TYPE_RGBA) ? GL_TRUE : GL_FALSE,
       (pfi->pfd.dwFlags & PFD_DOUBLEBUFFER) ? GL_TRUE : GL_FALSE,
       (pfi->pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE,
       pfi->pfd.cRedBits,
       pfi->pfd.cGreenBits,
       pfi->pfd.cBlueBits,
       pfi->pfd.cAlphaBits,
-      (pfi->pfd.iPixelType == PFD_TYPE_COLORINDEX) ? pfi->pfd.cColorBits : 0,
       pfi->pfd.cDepthBits,
       pfi->pfd.cStencilBits,
       pfi->pfd.cAccumRedBits,
@@ -288,12 +287,12 @@ stw_pixelformat_visual(GLvisual *visual,
 }
 
 
-int
-stw_pixelformat_describe(
+LONG APIENTRY
+DrvDescribePixelFormat(
    HDC hdc,
-   int iPixelFormat,
-   UINT nBytes,
-   LPPIXELFORMATDESCRIPTOR ppfd )
+   INT iPixelFormat,
+   ULONG cjpfd,
+   PIXELFORMATDESCRIPTOR *ppfd )
 {
    uint count;
    uint index;
@@ -301,12 +300,15 @@ stw_pixelformat_describe(
 
    (void) hdc;
 
+   if (!stw_dev)
+      return 0;
+
    count = stw_pixelformat_get_extended_count();
    index = (uint) iPixelFormat - 1;
 
    if (ppfd == NULL)
       return count;
-   if (index >= count || nBytes != sizeof( PIXELFORMATDESCRIPTOR ))
+   if (index >= count || cjpfd != sizeof( PIXELFORMATDESCRIPTOR ))
       return 0;
 
    pfi = stw_pixelformat_get_info( index );
@@ -316,6 +318,52 @@ stw_pixelformat_describe(
    return count;
 }
 
+BOOL APIENTRY
+DrvDescribeLayerPlane(
+   HDC hdc,
+   INT iPixelFormat,
+   INT iLayerPlane,
+   UINT nBytes,
+   LPLAYERPLANEDESCRIPTOR plpd )
+{
+   assert(0);
+   return FALSE;
+}
+
+int APIENTRY
+DrvGetLayerPaletteEntries(
+   HDC hdc,
+   INT iLayerPlane,
+   INT iStart,
+   INT cEntries,
+   COLORREF *pcr )
+{
+   assert(0);
+   return 0;
+}
+
+int APIENTRY
+DrvSetLayerPaletteEntries(
+   HDC hdc,
+   INT iLayerPlane,
+   INT iStart,
+   INT cEntries,
+   CONST COLORREF *pcr )
+{
+   assert(0);
+   return 0;
+}
+
+BOOL APIENTRY
+DrvRealizeLayerPalette(
+   HDC hdc,
+   INT iLayerPlane,
+   BOOL bRealize )
+{
+   assert(0);
+   return FALSE;
+}
+
 /* Only used by the wgl code, but have it here to avoid exporting the
  * pixelformat.h functionality.
  */