/**************************************************************************
- *
+ *
* Copyright 2008 VMware, Inc.
* All Rights Reserved.
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
- *
+ *
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
+ *
**************************************************************************/
#include "pipe/p_format.h"
#include "pipe/p_defines.h"
#include "pipe/p_screen.h"
-#include "util/u_format.h"
+#include "util/format/u_format.h"
#include "util/u_debug.h"
#include "util/u_memory.h"
static const struct stw_pf_color_info
stw_pf_color_extended[] = {
- { PIPE_FORMAT_R32G32B32A32_FLOAT, { 32, 32, 32, 32}, { 0, 32, 64, 96} }
+ { PIPE_FORMAT_R32G32B32A32_FLOAT, {32, 32, 32, 32}, {0, 32, 64, 96} }
};
-static const struct stw_pf_depth_info
+static const struct stw_pf_depth_info
stw_pf_depth_stencil[] = {
/* pure depth */
{ PIPE_FORMAT_Z32_UNORM, {32, 0} },
};
-static const boolean
+static const boolean
stw_pf_doublebuffer[] = {
FALSE,
TRUE,
};
-const unsigned
+const unsigned
stw_pf_multisample[] = {
0,
4,
static void
-stw_pixelformat_add(
- struct stw_device *stw_dev,
- boolean extended,
- const struct stw_pf_color_info *color,
- const struct stw_pf_depth_info *depth,
- unsigned accum,
- boolean doublebuffer,
- unsigned samples )
+stw_pixelformat_add(struct stw_device *stw_dev,
+ boolean extended,
+ const struct stw_pf_color_info *color,
+ const struct stw_pf_depth_info *depth,
+ unsigned accum,
+ boolean doublebuffer,
+ unsigned samples)
{
struct stw_pixelformat_info *pfi;
-
+
assert(stw_dev->pixelformat_extended_count < STW_MAX_PIXELFORMATS);
- if(stw_dev->pixelformat_extended_count >= STW_MAX_PIXELFORMATS)
+ if (stw_dev->pixelformat_extended_count >= STW_MAX_PIXELFORMATS)
return;
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, 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];
-
+
memset(pfi, 0, sizeof *pfi);
-
+
pfi->pfd.nSize = sizeof pfi->pfd;
pfi->pfd.nVersion = 1;
pfi->pfd.dwFlags = PFD_SUPPORT_OPENGL;
-
+
/* TODO: also support non-native pixel formats */
if (!extended) {
pfi->pfd.dwFlags |= PFD_DRAW_TO_WINDOW;
if (doublebuffer)
pfi->pfd.dwFlags |= PFD_DOUBLEBUFFER | PFD_SWAP_EXCHANGE;
-
+
pfi->pfd.iPixelType = PFD_TYPE_RGBA;
- pfi->pfd.cColorBits = color->bits.red + color->bits.green + color->bits.blue + color->bits.alpha;
+ pfi->pfd.cColorBits =
+ color->bits.red + color->bits.green + color->bits.blue + color->bits.alpha;
pfi->pfd.cRedBits = color->bits.red;
pfi->pfd.cRedShift = color->shift.red;
pfi->pfd.cGreenBits = color->bits.green;
pfi->stvis.samples = samples;
pfi->stvis.render_buffer = ST_ATTACHMENT_INVALID;
-
+
/* WGL_ARB_render_texture */
if (color->bits.alpha)
pfi->bindToTextureRGBA = TRUE;
- else
- pfi->bindToTextureRGB = TRUE;
+
+ pfi->bindToTextureRGB = TRUE;
++stw_dev->pixelformat_extended_count;
-
- if(!extended) {
+
+ if (!extended) {
++stw_dev->pixelformat_count;
assert(stw_dev->pixelformat_count == stw_dev->pixelformat_extended_count);
}
*/
static unsigned
add_color_format_variants(const struct stw_pf_color_info *color_formats,
- unsigned num_color_formats,
- boolean extended)
+ unsigned num_color_formats, boolean extended)
{
struct pipe_screen *screen = stw_dev->screen;
unsigned cfmt, ms, db, ds, acc;
bind_flags |= PIPE_BIND_DISPLAY_TARGET;
}
- for (ms = 0; ms < Elements(stw_pf_multisample); ms++) {
+ for (ms = 0; ms < ARRAY_SIZE(stw_pf_multisample); ms++) {
unsigned samples = stw_pf_multisample[ms];
if (force_samples && samples != force_samples)
for (cfmt = 0; cfmt < num_color_formats; cfmt++) {
if (!screen->is_format_supported(screen, color_formats[cfmt].format,
- PIPE_TEXTURE_2D, samples,
+ PIPE_TEXTURE_2D, samples, samples,
bind_flags)) {
continue;
}
- for (db = 0; db < Elements(stw_pf_doublebuffer); db++) {
+ for (db = 0; db < ARRAY_SIZE(stw_pf_doublebuffer); db++) {
unsigned doublebuffer = stw_pf_doublebuffer[db];
- for (ds = 0; ds < Elements(stw_pf_depth_stencil); ds++) {
+ for (ds = 0; ds < ARRAY_SIZE(stw_pf_depth_stencil); ds++) {
const struct stw_pf_depth_info *depth = &stw_pf_depth_stencil[ds];
if (!screen->is_format_supported(screen, depth->format,
PIPE_TEXTURE_2D, samples,
+ samples,
PIPE_BIND_DEPTH_STENCIL)) {
continue;
}
void
-stw_pixelformat_init( void )
+stw_pixelformat_init(void)
{
unsigned num_formats;
- assert( !stw_dev->pixelformat_count );
- assert( !stw_dev->pixelformat_extended_count );
+ assert(!stw_dev->pixelformat_count);
+ assert(!stw_dev->pixelformat_extended_count);
/* normal, displayable formats */
num_formats = add_color_format_variants(stw_pf_color,
- Elements(stw_pf_color), FALSE);
+ ARRAY_SIZE(stw_pf_color), FALSE);
assert(num_formats > 0);
/* extended, pbuffer-only formats */
add_color_format_variants(stw_pf_color_extended,
- Elements(stw_pf_color_extended), TRUE);
+ ARRAY_SIZE(stw_pf_color_extended), TRUE);
- assert( stw_dev->pixelformat_count <= stw_dev->pixelformat_extended_count );
- assert( stw_dev->pixelformat_extended_count <= STW_MAX_PIXELFORMATS );
+ assert(stw_dev->pixelformat_count <= stw_dev->pixelformat_extended_count);
+ assert(stw_dev->pixelformat_extended_count <= STW_MAX_PIXELFORMATS);
}
+
uint
-stw_pixelformat_get_count( void )
+stw_pixelformat_get_count(void)
{
return stw_dev->pixelformat_count;
}
+
uint
-stw_pixelformat_get_extended_count( void )
+stw_pixelformat_get_extended_count(void)
{
return stw_dev->pixelformat_extended_count;
}
+
const struct stw_pixelformat_info *
-stw_pixelformat_get_info( int iPixelFormat )
+stw_pixelformat_get_info(int iPixelFormat)
{
unsigned index;
LONG APIENTRY
-DrvDescribePixelFormat(
- HDC hdc,
- INT iPixelFormat,
- ULONG cjpfd,
- PIXELFORMATDESCRIPTOR *ppfd )
+DrvDescribePixelFormat(HDC hdc, INT iPixelFormat, ULONG cjpfd,
+ PIXELFORMATDESCRIPTOR *ppfd)
{
uint count;
const struct stw_pixelformat_info *pfi;
if (ppfd == NULL)
return count;
- if (cjpfd != sizeof( PIXELFORMATDESCRIPTOR ))
+
+ if (cjpfd != sizeof(PIXELFORMATDESCRIPTOR))
return 0;
- pfi = stw_pixelformat_get_info( iPixelFormat );
+ pfi = stw_pixelformat_get_info(iPixelFormat);
if (!pfi) {
return 0;
}
-
- memcpy(ppfd, &pfi->pfd, sizeof( PIXELFORMATDESCRIPTOR ));
+
+ memcpy(ppfd, &pfi->pfd, sizeof(PIXELFORMATDESCRIPTOR));
return count;
}
+
BOOL APIENTRY
-DrvDescribeLayerPlane(
- HDC hdc,
- INT iPixelFormat,
- INT iLayerPlane,
- UINT nBytes,
- LPLAYERPLANEDESCRIPTOR plpd )
+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 )
+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 )
+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 )
+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.
*/
-int stw_pixelformat_choose( HDC hdc,
- CONST PIXELFORMATDESCRIPTOR *ppfd )
+int
+stw_pixelformat_choose(HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd)
{
uint count;
uint index;
for (index = 1; index <= count; index++) {
uint delta = 0;
- const struct stw_pixelformat_info *pfi = stw_pixelformat_get_info( index );
+ const struct stw_pixelformat_info *pfi = stw_pixelformat_get_info(index);
if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) &&
!!(ppfd->dwFlags & PFD_DOUBLEBUFFER) !=
!!(pfi->pfd.dwFlags & PFD_DOUBLEBUFFER))
continue;
- /* FIXME: Take in account individual channel bits */
- if (ppfd->cColorBits != pfi->pfd.cColorBits)
- delta += 8;
+ /* Selection logic:
+ * - Enabling a feature (depth, stencil...) is given highest priority.
+ * - Giving as many bits as requested is given medium priority.
+ * - Giving no more bits than requested is given lowest priority.
+ */
- if (ppfd->cDepthBits != pfi->pfd.cDepthBits)
- delta += 4;
+ /* FIXME: Take in account individual channel bits */
+ if (ppfd->cColorBits && !pfi->pfd.cColorBits)
+ delta += 10000;
+ else if (ppfd->cColorBits > pfi->pfd.cColorBits)
+ delta += 100;
+ else if (ppfd->cColorBits < pfi->pfd.cColorBits)
+ delta++;
- if (ppfd->cStencilBits != pfi->pfd.cStencilBits)
+ if (ppfd->cDepthBits && !pfi->pfd.cDepthBits)
+ delta += 10000;
+ else if (ppfd->cDepthBits > pfi->pfd.cDepthBits)
+ delta += 200;
+ else if (ppfd->cDepthBits < pfi->pfd.cDepthBits)
delta += 2;
- if (ppfd->cAlphaBits != pfi->pfd.cAlphaBits)
+ if (ppfd->cStencilBits && !pfi->pfd.cStencilBits)
+ delta += 10000;
+ else if (ppfd->cStencilBits > pfi->pfd.cStencilBits)
+ delta += 400;
+ else if (ppfd->cStencilBits < pfi->pfd.cStencilBits)
+ delta++;
+
+ if (ppfd->cAlphaBits && !pfi->pfd.cAlphaBits)
+ delta += 10000;
+ else if (ppfd->cAlphaBits > pfi->pfd.cAlphaBits)
+ delta += 100;
+ else if (ppfd->cAlphaBits < pfi->pfd.cAlphaBits)
delta++;
if (delta < bestdelta) {