From d03a5f20114203fd00e0004659fd2617f4c03a32 Mon Sep 17 00:00:00 2001 From: marha Date: Thu, 14 Jul 2011 09:02:09 +0200 Subject: mesa xserver git update 14 july 2011 --- mesalib/configs/autoconf.in | 6 + mesalib/configure.ac | 141 +- mesalib/src/gallium/auxiliary/util/u_format.csv | 530 +-- mesalib/src/gallium/auxiliary/util/u_format_yuv.c | 2229 +++++----- mesalib/src/gallium/auxiliary/util/u_format_yuv.h | 581 ++- mesalib/src/gallium/auxiliary/util/u_upload_mgr.c | 2 +- mesalib/src/gallium/auxiliary/util/u_video.h | 75 + mesalib/src/mesa/main/texfetch_tmp.h | 6 +- mesalib/src/mesa/state_tracker/st_cb_condrender.c | 5 + mesalib/src/mesa/state_tracker/st_cb_queryobj.c | 363 +- mesalib/src/mesa/state_tracker/st_context.c | 3 + xorg-server/glx/glxscreens.h | 331 +- xorg-server/hw/dmx/glxProxy/glxscreens.h | 1 - xorg-server/hw/xquartz/GL/indirect.c | 3 +- xorg-server/hw/xwin/glx/Makefile.am | 84 +- xorg-server/hw/xwin/glx/gen_gl_wrappers.py | 2 +- xorg-server/hw/xwin/glx/indirect.c | 4658 +++++++++++---------- xorg-server/hw/xwin/glx/wgl_ext_api.c | 147 +- xorg-server/hw/xwin/glx/winpriv.c | 5 +- xorg-server/hw/xwin/man/XWin.man | 4 + xorg-server/hw/xwin/man/XWinrc.man | 2 +- xorg-server/hw/xwin/winmultiwindowwindow.c | 27 +- xorg-server/hw/xwin/winmultiwindowwndproc.c | 14 + xorg-server/hw/xwin/winwindow.h | 3 + 24 files changed, 4892 insertions(+), 4330 deletions(-) create mode 100644 mesalib/src/gallium/auxiliary/util/u_video.h diff --git a/mesalib/configs/autoconf.in b/mesalib/configs/autoconf.in index cac4befe9..584f5fd77 100644 --- a/mesalib/configs/autoconf.in +++ b/mesalib/configs/autoconf.in @@ -183,6 +183,12 @@ DRI_DRIVER_SEARCH_DIR = @DRI_DRIVER_SEARCH_DIR@ # EGL driver install directory EGL_DRIVER_INSTALL_DIR = @EGL_DRIVER_INSTALL_DIR@ +# VDPAU library install directory +VDPAU_LIB_INSTALL_DIR=@VDPAU_LIB_INSTALL_DIR@ + +# VA library install directory +VA_LIB_INSTALL_DIR=@VA_LIB_INSTALL_DIR@ + # Xorg driver install directory (for xorg state-tracker) XORG_DRIVER_INSTALL_DIR = @XORG_DRIVER_INSTALL_DIR@ diff --git a/mesalib/configure.ac b/mesalib/configure.ac index eace790d8..c3047d622 100644 --- a/mesalib/configure.ac +++ b/mesalib/configure.ac @@ -586,6 +586,22 @@ AC_ARG_ENABLE([gbm], [enable_gbm="$enableval"], [enable_gbm=auto]) +AC_ARG_ENABLE([xvmc], + [AS_HELP_STRING([--enable-xvmc], + [enable xvmc library @<:@default=auto@:>@])], + [enable_xvmc="$enableval"], + [enable_xvmc=auto]) +AC_ARG_ENABLE([vdpau], + [AS_HELP_STRING([--enable-vdpau], + [enable vdpau library @<:@default=auto@:>@])], + [enable_vdpau="$enableval"], + [enable_vdpau=auto]) +AC_ARG_ENABLE([va], + [AS_HELP_STRING([--enable-va], + [enable va library @<:@default=auto@:>@])], + [enable_va="$enableval"], + [enable_va=auto]) + AC_ARG_ENABLE([xlib_glx], [AS_HELP_STRING([--enable-xlib-glx], [make GLX library Xlib-based instead of DRI-based @<:@default=disable@:>@])], @@ -630,7 +646,10 @@ if test "x$enable_opengl" = xno -a \ "x$enable_openvg" = xno -a \ "x$enable_xorg" = xno -a \ "x$enable_xa" = xno -a \ - "x$enable_d3d1x" = xno; then + "x$enable_d3d1x" = xno -a \ + "x$enable_xvmc" = xno -a \ + "x$enable_vdpau" = xno -a \ + "x$enable_va" = xno; then AC_MSG_ERROR([at least one API should be enabled]) fi @@ -750,7 +769,7 @@ GLU_DIRS="sgi" GALLIUM_DIRS="auxiliary drivers state_trackers" GALLIUM_TARGET_DIRS="" GALLIUM_WINSYS_DIRS="sw" -GALLIUM_DRIVERS_DIRS="softpipe failover galahad trace rbug noop identity" +GALLIUM_DRIVERS_DIRS="failover galahad trace rbug noop identity" GALLIUM_STATE_TRACKERS_DIRS="" # build shared-glapi if enabled for OpenGL or if OpenGL ES is enabled @@ -1478,6 +1497,56 @@ if test "x$enable_d3d1x" = xyes; then HAVE_ST_D3D1X=yes fi +dnl +dnl Gallium G3DVL configuration +dnl +AC_ARG_ENABLE([gallium-g3dvl], + [AS_HELP_STRING([--enable-gallium-g3dvl], + [build gallium g3dvl @<:@default=disabled@:>@])], + [enable_gallium_g3dvl="$enableval"], + [enable_gallium_g3dvl=no]) +if test "x$enable_gallium_g3dvl" = xyes; then + if test "x$with_gallium_drivers" = x; then + AC_MSG_ERROR([cannot enable G3DVL without Gallium]) + fi + + if test "x$enable_xvmc" = xauto; then + enable_xvmc=yes + fi + + if test "x$enable_vdpau" = xauto; then + enable_vdpau=yes + fi + + if test "x$enable_va" = xauto; then + enable_va=no + fi +fi + +#TODO: Check for xvmc libs/headers +if test "x$enable_xvmc" = xyes; then + GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg/xvmc" + HAVE_ST_XVMC="yes" +fi + +#TODO: Check for vdpau libs/headers +if test "x$enable_vdpau" = xyes; then + GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS vdpau" + HAVE_ST_VDPAU="yes" +fi + +#TODO: Check for va libs/headers +if test "x$enable_va" = xyes; then + GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS va" + HAVE_ST_VA="yes" +fi + +if test "x$enable_xvmc" = xyes || + test "x$enable_vdpau" = xyes || + test "x$enable_va" = xyes; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS g3dvl/dri" +fi + dnl dnl GLU configuration dnl @@ -1697,8 +1766,6 @@ AC_SUBST([LLVM_LIBS]) AC_SUBST([LLVM_LDFLAGS]) AC_SUBST([LLVM_VERSION]) - - case "x$enable_opengl$enable_gles1$enable_gles2" in x*yes*) EGL_CLIENT_APIS="$EGL_CLIENT_APIS "'$(GL_LIB)' @@ -1817,8 +1884,7 @@ if test "x$enable_gallium_llvm" = xyes; then LLVM_LIBS="`$LLVM_CONFIG --libs` -lstdc++" LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags` - GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe" - DEFINES="$DEFINES -DGALLIUM_LLVMPIPE -D__STDC_CONSTANT_MACROS" + DEFINES="$DEFINES -D__STDC_CONSTANT_MACROS" MESA_LLVM=1 else MESA_LLVM=0 @@ -1827,12 +1893,29 @@ else MESA_LLVM=0 fi +dnl Directory for VDPAU libs +AC_ARG_WITH([vdpau-libdir], + [AS_HELP_STRING([--with-vdpau-libdir=DIR], + [directory for the VDPAU libraries @<:@default=${libdir}/vdpau@:>@])], + [VDPAU_LIB_INSTALL_DIR="$withval"], + [VDPAU_LIB_INSTALL_DIR='${libdir}/vdpau']) +AC_SUBST([VDPAU_LIB_INSTALL_DIR]) + +dnl Directory for VA libs +AC_ARG_WITH([va-libdir], + [AS_HELP_STRING([--with-va-libdir=DIR], + [directory for the VA libraries @<:@default=${libdir}/va@:>@])], + [VA_LIB_INSTALL_DIR="$withval"], + [VA_LIB_INSTALL_DIR='${libdir}/va']) +AC_SUBST([VA_LIB_INSTALL_DIR]) + dnl dnl Gallium helper functions dnl gallium_check_st() { if test "x$HAVE_ST_DRI" = xyes || test "x$HAVE_ST_XORG" = xyes || - test "x$HAVE_ST_XA" = xyes; then + test "x$HAVE_ST_XA" = xyes || test "x$HAVE_ST_XVMC" = xyes || + test "x$HAVE_ST_VDPAU" = xyes || test "x$HAVE_ST_VA" = xyes; then if test "x$have_libdrm" != xyes; then AC_MSG_ERROR([DRI or Xorg DDX requires libdrm >= $LIBDRM_REQUIRED]) fi @@ -1847,6 +1930,15 @@ gallium_check_st() { if test "x$HAVE_ST_XA" = xyes && test "x$4" != x; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $4" fi + if test "x$HAVE_ST_XVMC" = xyes && test "x$5" != x; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $5" + fi + if test "x$HAVE_ST_VDPAU" = xyes && test "x$6" != x; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $6" + fi + if test "x$HAVE_ST_VA" = xyes && test "x$7" != x; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $7" + fi } gallium_require_llvm() { @@ -1858,39 +1950,60 @@ gallium_require_llvm() { } dnl Gallium drivers +dnl Duplicates in GALLIUM_DRIVERS_DIRS are removed by sorting it after this block if test "x$with_gallium_drivers" != x; then - # This is for compile-testing - GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965 r300 svga" - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw" - gallium_drivers=`IFS=', '; echo $with_gallium_drivers` for driver in $gallium_drivers; do case "x$driver" in xsvga) + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga softpipe" gallium_check_st "svga/drm" "dri-vmwgfx" "xorg-vmwgfx" "xa-vmwgfx" ;; xi915) + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 softpipe" + if test "x$MESA_LLVM" = x1; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe" + fi + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw" gallium_check_st "i915/drm" "dri-i915" "xorg-i915" ;; xi965) + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i965 softpipe" + if test "x$MESA_LLVM" = x1; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe" + fi gallium_check_st "i965/drm" "dri-i965" "xorg-i965" ;; xr300) gallium_require_llvm "Gallium R300" - gallium_check_st "radeon/drm" "dri-r300" "xorg-r300" + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" + gallium_check_st "radeon/drm" "dri-r300" "xorg-r300" "" "xvmc-r300" "vdpau-r300" "va-r300" ;; xr600) GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r600" - gallium_check_st "r600/drm" "dri-r600" + gallium_check_st "r600/drm" "dri-r600" "" "" "xvmc-r600" "vdpau-r600" "va-r600" ;; xnouveau) GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50 nvc0" - gallium_check_st "nouveau/drm" "dri-nouveau" "xorg-nouveau" + gallium_check_st "nouveau/drm" "dri-nouveau" "xorg-nouveau" "" "xvmc-nouveau" ;; xswrast) if test "x$HAVE_ST_DRI" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS softpipe" + if test "x$MESA_LLVM" = x1; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe" + fi GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-swrast" fi + if test "x$HAVE_ST_VDPAU" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS vdpau-softpipe" + fi + if test "x$HAVE_ST_XVMC" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xvmc-softpipe" + fi + if test "x$HAVE_ST_VA" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS va-softpipe" + fi ;; *) AC_MSG_ERROR([Unknown Gallium driver: $driver]) diff --git a/mesalib/src/gallium/auxiliary/util/u_format.csv b/mesalib/src/gallium/auxiliary/util/u_format.csv index 00c24cc81..347e2beb8 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format.csv +++ b/mesalib/src/gallium/auxiliary/util/u_format.csv @@ -1,261 +1,269 @@ -########################################################################### -# -# Copyright 2009-2010 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 -# without limitation the rights to use, copy, modify, merge, publish, -# 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. -# IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR -# 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. -# -########################################################################### - -# This CSV file has the input data for u_format.h's struct -# util_format_description. -# -# Each format entry contains: -# - name, per enum pipe_format -# - layout, per enum util_format_layout, in shortened lower caps -# - pixel block's width -# - pixel block's height -# - channel encoding (only meaningful for plain layout), containing for each -# channel the following information: -# - type, one of -# - 'x': void -# - 'u': unsigned -# - 's': signed -# - 'h': fixed -# - 'f': FLOAT -# - optionally followed by 'n' if it is normalized -# - number of bits -# - channel swizzle -# - color space: rgb, yub, sz -# -# See also: -# - http://msdn.microsoft.com/en-us/library/bb172558.aspx (D3D9) -# - http://msdn.microsoft.com/en-us/library/bb205073.aspx#mapping_texture_formats (D3D9 -> D3D10) -# - http://msdn.microsoft.com/en-us/library/bb173059.aspx (D3D10) -# -# Note that GL doesn't really specify the layout of internal formats. See -# OpenGL 2.1 specification, Table 3.16, on the "Correspondence of sized -# internal formats to base in- ternal formats, and desired component -# resolutions for each sized internal format." - -# None -# Described as regular uint_8 bytes, i.e. PIPE_FORMAT_R8_USCALED -PIPE_FORMAT_NONE , plain, 1, 1, u8 , , , , x001, rgb - -# Typical rendertarget formats -PIPE_FORMAT_B8G8R8A8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , zyxw, rgb -PIPE_FORMAT_B8G8R8X8_UNORM , plain, 1, 1, un8 , un8 , un8 , x8 , zyx1, rgb -PIPE_FORMAT_A8R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, rgb -PIPE_FORMAT_X8R8G8B8_UNORM , plain, 1, 1, x8 , un8 , un8 , un8 , yzw1, rgb -PIPE_FORMAT_A8B8G8R8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , wzyx, rgb -PIPE_FORMAT_X8B8G8R8_UNORM , plain, 1, 1, x8 , un8 , un8 , un8 , wzy1, rgb -# PIPE_FORMAT_R8G8B8A8_UNORM is below -PIPE_FORMAT_R8G8B8X8_UNORM , plain, 1, 1, un8 , un8 , un8 , x8 , xyz1, rgb -PIPE_FORMAT_B5G5R5X1_UNORM , plain, 1, 1, un5 , un5 , un5 , x1 , zyx1, rgb -PIPE_FORMAT_B5G5R5A1_UNORM , plain, 1, 1, un5 , un5 , un5 , un1 , zyxw, rgb -PIPE_FORMAT_B4G4R4A4_UNORM , plain, 1, 1, un4 , un4 , un4 , un4 , zyxw, rgb -PIPE_FORMAT_B4G4R4X4_UNORM , plain, 1, 1, un4 , un4 , un4 , x4 , zyx1, rgb -PIPE_FORMAT_B5G6R5_UNORM , plain, 1, 1, un5 , un6 , un5 , , zyx1, rgb -PIPE_FORMAT_R10G10B10A2_UNORM , plain, 1, 1, un10, un10, un10, un2 , xyzw, rgb -PIPE_FORMAT_B10G10R10A2_UNORM , plain, 1, 1, un10, un10, un10, un2 , zyxw, rgb -PIPE_FORMAT_B2G3R3_UNORM , plain, 1, 1, un2 , un3 , un3 , , zyx1, rgb - -# Luminance/Intensity/Alpha formats -PIPE_FORMAT_L8_UNORM , plain, 1, 1, un8 , , , , xxx1, rgb -PIPE_FORMAT_A8_UNORM , plain, 1, 1, un8 , , , , 000x, rgb -PIPE_FORMAT_I8_UNORM , plain, 1, 1, un8 , , , , xxxx, rgb -PIPE_FORMAT_L4A4_UNORM , plain, 1, 1, un4 , un4 , , , xxxy, rgb -PIPE_FORMAT_L8A8_UNORM , plain, 1, 1, un8 , un8 , , , xxxy, rgb -PIPE_FORMAT_L16_UNORM , plain, 1, 1, un16, , , , xxx1, rgb -PIPE_FORMAT_A16_UNORM , plain, 1, 1, un16, , , , 000x, rgb -PIPE_FORMAT_I16_UNORM , plain, 1, 1, un16, , , , xxxx, rgb -PIPE_FORMAT_L16A16_UNORM , plain, 1, 1, un16, un16, , , xxxy, rgb -PIPE_FORMAT_A8_SNORM , plain, 1, 1, sn8 , , , , 000x, rgb -PIPE_FORMAT_L8_SNORM , plain, 1, 1, sn8 , , , , xxx1, rgb -PIPE_FORMAT_L8A8_SNORM , plain, 1, 1, sn8 , sn8 , , , xxxy, rgb -PIPE_FORMAT_I8_SNORM , plain, 1, 1, sn8 , , , , xxxx, rgb -PIPE_FORMAT_A16_SNORM , plain, 1, 1, sn16, , , , 000x, rgb -PIPE_FORMAT_L16_SNORM , plain, 1, 1, sn16, , , , xxx1, rgb -PIPE_FORMAT_L16A16_SNORM , plain, 1, 1, sn16, sn16, , , xxxy, rgb -PIPE_FORMAT_I16_SNORM , plain, 1, 1, sn16, , , , xxxx, rgb -PIPE_FORMAT_A16_FLOAT , plain, 1, 1, f16 , , , , 000x, rgb -PIPE_FORMAT_L16_FLOAT , plain, 1, 1, f16 , , , , xxx1, rgb -PIPE_FORMAT_L16A16_FLOAT , plain, 1, 1, f16 , f16 , , , xxxy, rgb -PIPE_FORMAT_I16_FLOAT , plain, 1, 1, f16 , , , , xxxx, rgb -PIPE_FORMAT_A32_FLOAT , plain, 1, 1, f32 , , , , 000x, rgb -PIPE_FORMAT_L32_FLOAT , plain, 1, 1, f32 , , , , xxx1, rgb -PIPE_FORMAT_L32A32_FLOAT , plain, 1, 1, f32 , f32 , , , xxxy, rgb -PIPE_FORMAT_I32_FLOAT , plain, 1, 1, f32 , , , , xxxx, rgb - -# SRGB formats -PIPE_FORMAT_L8_SRGB , plain, 1, 1, un8 , , , , xxx1, srgb -PIPE_FORMAT_L8A8_SRGB , plain, 1, 1, un8 , un8 , , , xxxy, srgb -PIPE_FORMAT_R8G8B8_SRGB , plain, 1, 1, un8 , un8 , un8 , , xyz1, srgb -PIPE_FORMAT_R8G8B8A8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , xyzw, srgb -PIPE_FORMAT_A8B8G8R8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , wzyx, srgb -PIPE_FORMAT_X8B8G8R8_SRGB , plain, 1, 1, x8 , un8 , un8 , un8 , wzy1, srgb -PIPE_FORMAT_B8G8R8A8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , zyxw, srgb -PIPE_FORMAT_B8G8R8X8_SRGB , plain, 1, 1, un8 , un8 , un8 , x8 , zyx1, srgb -PIPE_FORMAT_A8R8G8B8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, srgb -PIPE_FORMAT_X8R8G8B8_SRGB , plain, 1, 1, x8 , un8 , un8 , un8 , yzw1, srgb - -# Mixed-sign formats (typically used for bump map textures) -PIPE_FORMAT_R8SG8SB8UX8U_NORM , plain, 1, 1, sn8 , sn8 , un8 , x8 , xyz1, rgb -PIPE_FORMAT_R10SG10SB10SA2U_NORM , plain, 1, 1, sn10, sn10, sn10, un2 , xyzw, rgb -PIPE_FORMAT_R5SG5SB6U_NORM , plain, 1, 1, sn5 , sn5 , un6 , , xyz1, rgb - -# Depth-stencil formats -PIPE_FORMAT_S8_USCALED , plain, 1, 1, u8 , , , , _x__, zs -PIPE_FORMAT_Z16_UNORM , plain, 1, 1, un16, , , , x___, zs -PIPE_FORMAT_Z32_UNORM , plain, 1, 1, un32, , , , x___, zs -PIPE_FORMAT_Z32_FLOAT , plain, 1, 1, f32 , , , , x___, zs -PIPE_FORMAT_Z24_UNORM_S8_USCALED , plain, 1, 1, un24, u8 , , , xy__, zs -PIPE_FORMAT_S8_USCALED_Z24_UNORM , plain, 1, 1, u8 , un24, , , yx__, zs -PIPE_FORMAT_X24S8_USCALED , plain, 1, 1, x24, u8 , , , _y__, zs -PIPE_FORMAT_S8X24_USCALED , plain, 1, 1, u8 , x24 , , , _x__, zs -PIPE_FORMAT_Z24X8_UNORM , plain, 1, 1, un24, x8 , , , x___, zs -PIPE_FORMAT_X8Z24_UNORM , plain, 1, 1, x8 , un24, , , y___, zs -PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED , plain, 1, 1, f32, u8 , x24 , , xy__, zs -PIPE_FORMAT_X32_S8X24_USCALED , plain, 1, 1, x32, u8 , x24 , , _y__, zs - -# YUV formats -# http://www.fourcc.org/yuv.php#UYVY -PIPE_FORMAT_UYVY , subsampled, 2, 1, x32 , , , , xyz1, yuv -# http://www.fourcc.org/yuv.php#YUYV (a.k.a http://www.fourcc.org/yuv.php#YUY2) -PIPE_FORMAT_YUYV , subsampled, 2, 1, x32 , , , , xyz1, yuv -# same subsampling but with rgb channels -PIPE_FORMAT_R8G8_B8G8_UNORM , subsampled, 2, 1, x32 , , , , xyz1, rgb -PIPE_FORMAT_G8R8_G8B8_UNORM , subsampled, 2, 1, x32 , , , , xyz1, rgb - -# some special formats not fitting anywhere else -PIPE_FORMAT_R10G10B10A2_USCALED , plain, 1, 1, u10 , u10 , u10 , u2 , xyzw, rgb -PIPE_FORMAT_R11G11B10_FLOAT , other, 1, 1, x32 , , , , xyz1, rgb -PIPE_FORMAT_R9G9B9E5_FLOAT , other, 1, 1, x32 , , , , xyz1, rgb -PIPE_FORMAT_R1_UNORM , other, 8, 1, x8 , , , , x001, rgb -# A.k.a. D3DFMT_CxV8U8 -PIPE_FORMAT_R8G8Bx_SNORM , other, 1, 1, sn8 , sn8 , , , xyz1, rgb - -# Compressed formats -# - http://en.wikipedia.org/wiki/S3_Texture_Compression -# - http://www.opengl.org/registry/specs/EXT/texture_compression_s3tc.txt -# - http://www.opengl.org/registry/specs/ARB/texture_compression_rgtc.txt -# - http://www.opengl.org/registry/specs/EXT/texture_compression_latc.txt -# - http://msdn.microsoft.com/en-us/library/bb694531.aspx -PIPE_FORMAT_DXT1_RGB , s3tc, 4, 4, x64 , , , , xyz1, rgb -PIPE_FORMAT_DXT1_RGBA , s3tc, 4, 4, x64 , , , , xyzw, rgb -PIPE_FORMAT_DXT3_RGBA , s3tc, 4, 4, x128, , , , xyzw, rgb -PIPE_FORMAT_DXT5_RGBA , s3tc, 4, 4, x128, , , , xyzw, rgb -PIPE_FORMAT_DXT1_SRGB , s3tc, 4, 4, x64 , , , , xyz1, srgb -PIPE_FORMAT_DXT1_SRGBA , s3tc, 4, 4, x64 , , , , xyzw, srgb -PIPE_FORMAT_DXT3_SRGBA , s3tc, 4, 4, x128, , , , xyzw, srgb -PIPE_FORMAT_DXT5_SRGBA , s3tc, 4, 4, x128, , , , xyzw, srgb - -PIPE_FORMAT_RGTC1_UNORM , rgtc, 4, 4, x64, , , , x001, rgb -PIPE_FORMAT_RGTC1_SNORM , rgtc, 4, 4, x64, , , , x001, rgb -PIPE_FORMAT_RGTC2_UNORM , rgtc, 4, 4, x128, , , , xy01, rgb -PIPE_FORMAT_RGTC2_SNORM , rgtc, 4, 4, x128, , , , xy01, rgb - -PIPE_FORMAT_LATC1_UNORM , rgtc, 4, 4, x64, , , , xxx1, rgb -PIPE_FORMAT_LATC1_SNORM , rgtc, 4, 4, x64, , , , xxx1, rgb -PIPE_FORMAT_LATC2_UNORM , rgtc, 4, 4, x128, , , , xxxy, rgb -PIPE_FORMAT_LATC2_SNORM , rgtc, 4, 4, x128, , , , xxxy, rgb - -# Straightforward D3D10-like formats (also used for -# vertex buffer element description) -# -# See also: -# - src/gallium/auxiliary/translate/translate_generic.c -# - src/mesa/state_tracker/st_draw.c -PIPE_FORMAT_R64_FLOAT , plain, 1, 1, f64 , , , , x001, rgb -PIPE_FORMAT_R64G64_FLOAT , plain, 1, 1, f64 , f64 , , , xy01, rgb -PIPE_FORMAT_R64G64B64_FLOAT , plain, 1, 1, f64 , f64 , f64 , , xyz1, rgb -PIPE_FORMAT_R64G64B64A64_FLOAT , plain, 1, 1, f64 , f64 , f64 , f64 , xyzw, rgb -PIPE_FORMAT_R32_FLOAT , plain, 1, 1, f32 , , , , x001, rgb -PIPE_FORMAT_R32G32_FLOAT , plain, 1, 1, f32 , f32 , , , xy01, rgb -PIPE_FORMAT_R32G32B32_FLOAT , plain, 1, 1, f32 , f32 , f32 , , xyz1, rgb -PIPE_FORMAT_R32G32B32A32_FLOAT , plain, 1, 1, f32 , f32 , f32 , f32 , xyzw, rgb -PIPE_FORMAT_R32_UNORM , plain, 1, 1, un32, , , , x001, rgb -PIPE_FORMAT_R32G32_UNORM , plain, 1, 1, un32, un32, , , xy01, rgb -PIPE_FORMAT_R32G32B32_UNORM , plain, 1, 1, un32, un32, un32, , xyz1, rgb -PIPE_FORMAT_R32G32B32A32_UNORM , plain, 1, 1, un32, un32, un32, un32, xyzw, rgb -PIPE_FORMAT_R32_USCALED , plain, 1, 1, u32 , , , , x001, rgb -PIPE_FORMAT_R32G32_USCALED , plain, 1, 1, u32 , u32 , , , xy01, rgb -PIPE_FORMAT_R32G32B32_USCALED , plain, 1, 1, u32 , u32 , u32 , , xyz1, rgb -PIPE_FORMAT_R32G32B32A32_USCALED , plain, 1, 1, u32 , u32 , u32 , u32 , xyzw, rgb -PIPE_FORMAT_R32_SNORM , plain, 1, 1, sn32, , , , x001, rgb -PIPE_FORMAT_R32G32_SNORM , plain, 1, 1, sn32, sn32, , , xy01, rgb -PIPE_FORMAT_R32G32B32_SNORM , plain, 1, 1, sn32, sn32, sn32, , xyz1, rgb -PIPE_FORMAT_R32G32B32A32_SNORM , plain, 1, 1, sn32, sn32, sn32, sn32, xyzw, rgb -PIPE_FORMAT_R32_SSCALED , plain, 1, 1, s32 , , , , x001, rgb -PIPE_FORMAT_R32G32_SSCALED , plain, 1, 1, s32 , s32 , , , xy01, rgb -PIPE_FORMAT_R32G32B32_SSCALED , plain, 1, 1, s32 , s32 , s32 , , xyz1, rgb -PIPE_FORMAT_R32G32B32A32_SSCALED , plain, 1, 1, s32 , s32 , s32 , s32 , xyzw, rgb -PIPE_FORMAT_R16_FLOAT , plain, 1, 1, f16 , , , , x001, rgb -PIPE_FORMAT_R16G16_FLOAT , plain, 1, 1, f16 , f16 , , , xy01, rgb -PIPE_FORMAT_R16G16B16_FLOAT , plain, 1, 1, f16 , f16 , f16 , , xyz1, rgb -PIPE_FORMAT_R16G16B16A16_FLOAT , plain, 1, 1, f16 , f16 , f16 , f16 , xyzw, rgb -PIPE_FORMAT_R16_UNORM , plain, 1, 1, un16, , , , x001, rgb -PIPE_FORMAT_R16G16_UNORM , plain, 1, 1, un16, un16, , , xy01, rgb -PIPE_FORMAT_R16G16B16_UNORM , plain, 1, 1, un16, un16, un16, , xyz1, rgb -PIPE_FORMAT_R16G16B16A16_UNORM , plain, 1, 1, un16, un16, un16, un16, xyzw, rgb -PIPE_FORMAT_R16_USCALED , plain, 1, 1, u16 , , , , x001, rgb -PIPE_FORMAT_R16G16_USCALED , plain, 1, 1, u16 , u16 , , , xy01, rgb -PIPE_FORMAT_R16G16B16_USCALED , plain, 1, 1, u16 , u16 , u16 , , xyz1, rgb -PIPE_FORMAT_R16G16B16A16_USCALED , plain, 1, 1, u16 , u16 , u16 , u16 , xyzw, rgb -PIPE_FORMAT_R16_SNORM , plain, 1, 1, sn16, , , , x001, rgb -PIPE_FORMAT_R16G16_SNORM , plain, 1, 1, sn16, sn16, , , xy01, rgb -PIPE_FORMAT_R16G16B16_SNORM , plain, 1, 1, sn16, sn16, sn16, , xyz1, rgb -PIPE_FORMAT_R16G16B16A16_SNORM , plain, 1, 1, sn16, sn16, sn16, sn16, xyzw, rgb -PIPE_FORMAT_R16_SSCALED , plain, 1, 1, s16 , , , , x001, rgb -PIPE_FORMAT_R16G16_SSCALED , plain, 1, 1, s16 , s16 , , , xy01, rgb -PIPE_FORMAT_R16G16B16_SSCALED , plain, 1, 1, s16 , s16 , s16 , , xyz1, rgb -PIPE_FORMAT_R16G16B16A16_SSCALED , plain, 1, 1, s16 , s16 , s16 , s16 , xyzw, rgb -PIPE_FORMAT_R8_UNORM , plain, 1, 1, un8 , , , , x001, rgb -PIPE_FORMAT_R8G8_UNORM , plain, 1, 1, un8 , un8 , , , xy01, rgb -PIPE_FORMAT_R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , , xyz1, rgb -PIPE_FORMAT_R8G8B8A8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , xyzw, rgb -PIPE_FORMAT_R8_USCALED , plain, 1, 1, u8 , , , , x001, rgb -PIPE_FORMAT_R8G8_USCALED , plain, 1, 1, u8 , u8 , , , xy01, rgb -PIPE_FORMAT_R8G8B8_USCALED , plain, 1, 1, u8 , u8 , u8 , , xyz1, rgb -PIPE_FORMAT_R8G8B8A8_USCALED , plain, 1, 1, u8 , u8 , u8 , u8 , xyzw, rgb -PIPE_FORMAT_R8_SNORM , plain, 1, 1, sn8 , , , , x001, rgb -PIPE_FORMAT_R8G8_SNORM , plain, 1, 1, sn8 , sn8 , , , xy01, rgb -PIPE_FORMAT_R8G8B8_SNORM , plain, 1, 1, sn8 , sn8 , sn8 , , xyz1, rgb -PIPE_FORMAT_R8G8B8A8_SNORM , plain, 1, 1, sn8 , sn8 , sn8 , sn8 , xyzw, rgb -PIPE_FORMAT_R8_SSCALED , plain, 1, 1, s8 , , , , x001, rgb -PIPE_FORMAT_R8G8_SSCALED , plain, 1, 1, s8 , s8 , , , xy01, rgb -PIPE_FORMAT_R8G8B8_SSCALED , plain, 1, 1, s8 , s8 , s8 , , xyz1, rgb -PIPE_FORMAT_R8G8B8A8_SSCALED , plain, 1, 1, s8 , s8 , s8 , s8 , xyzw, rgb - -# GL-specific vertex buffer element formats -# A.k.a. GL_FIXED -PIPE_FORMAT_R32_FIXED , plain, 1, 1, h32 , , , , x001, rgb -PIPE_FORMAT_R32G32_FIXED , plain, 1, 1, h32 , h32 , , , xy01, rgb -PIPE_FORMAT_R32G32B32_FIXED , plain, 1, 1, h32 , h32 , h32 , , xyz1, rgb -PIPE_FORMAT_R32G32B32A32_FIXED , plain, 1, 1, h32 , h32 , h32 , h32 , xyzw, rgb - -# D3D9-specific vertex buffer element formats -# See also: -# - http://msdn.microsoft.com/en-us/library/bb172533.aspx -# A.k.a. D3DDECLTYPE_UDEC3 -PIPE_FORMAT_R10G10B10X2_USCALED , plain, 1, 1, u10 , u10 , u10 , x2 , xyz1, rgb -# A.k.a. D3DDECLTYPE_DEC3N -PIPE_FORMAT_R10G10B10X2_SNORM , plain, 1, 1, sn10, sn10, sn10 , x2 , xyz1, rgb +########################################################################### +# +# Copyright 2009-2010 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 +# without limitation the rights to use, copy, modify, merge, publish, +# 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. +# IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR +# 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. +# +########################################################################### + +# This CSV file has the input data for u_format.h's struct +# util_format_description. +# +# Each format entry contains: +# - name, per enum pipe_format +# - layout, per enum util_format_layout, in shortened lower caps +# - pixel block's width +# - pixel block's height +# - channel encoding (only meaningful for plain layout), containing for each +# channel the following information: +# - type, one of +# - 'x': void +# - 'u': unsigned +# - 's': signed +# - 'h': fixed +# - 'f': FLOAT +# - optionally followed by 'n' if it is normalized +# - number of bits +# - channel swizzle +# - color space: rgb, yub, sz +# +# See also: +# - http://msdn.microsoft.com/en-us/library/bb172558.aspx (D3D9) +# - http://msdn.microsoft.com/en-us/library/bb205073.aspx#mapping_texture_formats (D3D9 -> D3D10) +# - http://msdn.microsoft.com/en-us/library/bb173059.aspx (D3D10) +# +# Note that GL doesn't really specify the layout of internal formats. See +# OpenGL 2.1 specification, Table 3.16, on the "Correspondence of sized +# internal formats to base in- ternal formats, and desired component +# resolutions for each sized internal format." + +# None +# Described as regular uint_8 bytes, i.e. PIPE_FORMAT_R8_USCALED +PIPE_FORMAT_NONE , plain, 1, 1, u8 , , , , x001, rgb + +# Typical rendertarget formats +PIPE_FORMAT_B8G8R8A8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , zyxw, rgb +PIPE_FORMAT_B8G8R8X8_UNORM , plain, 1, 1, un8 , un8 , un8 , x8 , zyx1, rgb +PIPE_FORMAT_A8R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, rgb +PIPE_FORMAT_X8R8G8B8_UNORM , plain, 1, 1, x8 , un8 , un8 , un8 , yzw1, rgb +PIPE_FORMAT_A8B8G8R8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , wzyx, rgb +PIPE_FORMAT_X8B8G8R8_UNORM , plain, 1, 1, x8 , un8 , un8 , un8 , wzy1, rgb +# PIPE_FORMAT_R8G8B8A8_UNORM is below +PIPE_FORMAT_R8G8B8X8_UNORM , plain, 1, 1, un8 , un8 , un8 , x8 , xyz1, rgb +PIPE_FORMAT_B5G5R5X1_UNORM , plain, 1, 1, un5 , un5 , un5 , x1 , zyx1, rgb +PIPE_FORMAT_B5G5R5A1_UNORM , plain, 1, 1, un5 , un5 , un5 , un1 , zyxw, rgb +PIPE_FORMAT_B4G4R4A4_UNORM , plain, 1, 1, un4 , un4 , un4 , un4 , zyxw, rgb +PIPE_FORMAT_B4G4R4X4_UNORM , plain, 1, 1, un4 , un4 , un4 , x4 , zyx1, rgb +PIPE_FORMAT_B5G6R5_UNORM , plain, 1, 1, un5 , un6 , un5 , , zyx1, rgb +PIPE_FORMAT_R10G10B10A2_UNORM , plain, 1, 1, un10, un10, un10, un2 , xyzw, rgb +PIPE_FORMAT_B10G10R10A2_UNORM , plain, 1, 1, un10, un10, un10, un2 , zyxw, rgb +PIPE_FORMAT_B2G3R3_UNORM , plain, 1, 1, un2 , un3 , un3 , , zyx1, rgb + +# Luminance/Intensity/Alpha formats +PIPE_FORMAT_L8_UNORM , plain, 1, 1, un8 , , , , xxx1, rgb +PIPE_FORMAT_A8_UNORM , plain, 1, 1, un8 , , , , 000x, rgb +PIPE_FORMAT_I8_UNORM , plain, 1, 1, un8 , , , , xxxx, rgb +PIPE_FORMAT_L4A4_UNORM , plain, 1, 1, un4 , un4 , , , xxxy, rgb +PIPE_FORMAT_L8A8_UNORM , plain, 1, 1, un8 , un8 , , , xxxy, rgb +PIPE_FORMAT_L16_UNORM , plain, 1, 1, un16, , , , xxx1, rgb +PIPE_FORMAT_A16_UNORM , plain, 1, 1, un16, , , , 000x, rgb +PIPE_FORMAT_I16_UNORM , plain, 1, 1, un16, , , , xxxx, rgb +PIPE_FORMAT_L16A16_UNORM , plain, 1, 1, un16, un16, , , xxxy, rgb +PIPE_FORMAT_A8_SNORM , plain, 1, 1, sn8 , , , , 000x, rgb +PIPE_FORMAT_L8_SNORM , plain, 1, 1, sn8 , , , , xxx1, rgb +PIPE_FORMAT_L8A8_SNORM , plain, 1, 1, sn8 , sn8 , , , xxxy, rgb +PIPE_FORMAT_I8_SNORM , plain, 1, 1, sn8 , , , , xxxx, rgb +PIPE_FORMAT_A16_SNORM , plain, 1, 1, sn16, , , , 000x, rgb +PIPE_FORMAT_L16_SNORM , plain, 1, 1, sn16, , , , xxx1, rgb +PIPE_FORMAT_L16A16_SNORM , plain, 1, 1, sn16, sn16, , , xxxy, rgb +PIPE_FORMAT_I16_SNORM , plain, 1, 1, sn16, , , , xxxx, rgb +PIPE_FORMAT_A16_FLOAT , plain, 1, 1, f16 , , , , 000x, rgb +PIPE_FORMAT_L16_FLOAT , plain, 1, 1, f16 , , , , xxx1, rgb +PIPE_FORMAT_L16A16_FLOAT , plain, 1, 1, f16 , f16 , , , xxxy, rgb +PIPE_FORMAT_I16_FLOAT , plain, 1, 1, f16 , , , , xxxx, rgb +PIPE_FORMAT_A32_FLOAT , plain, 1, 1, f32 , , , , 000x, rgb +PIPE_FORMAT_L32_FLOAT , plain, 1, 1, f32 , , , , xxx1, rgb +PIPE_FORMAT_L32A32_FLOAT , plain, 1, 1, f32 , f32 , , , xxxy, rgb +PIPE_FORMAT_I32_FLOAT , plain, 1, 1, f32 , , , , xxxx, rgb + +# SRGB formats +PIPE_FORMAT_L8_SRGB , plain, 1, 1, un8 , , , , xxx1, srgb +PIPE_FORMAT_L8A8_SRGB , plain, 1, 1, un8 , un8 , , , xxxy, srgb +PIPE_FORMAT_R8G8B8_SRGB , plain, 1, 1, un8 , un8 , un8 , , xyz1, srgb +PIPE_FORMAT_R8G8B8A8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , xyzw, srgb +PIPE_FORMAT_A8B8G8R8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , wzyx, srgb +PIPE_FORMAT_X8B8G8R8_SRGB , plain, 1, 1, x8 , un8 , un8 , un8 , wzy1, srgb +PIPE_FORMAT_B8G8R8A8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , zyxw, srgb +PIPE_FORMAT_B8G8R8X8_SRGB , plain, 1, 1, un8 , un8 , un8 , x8 , zyx1, srgb +PIPE_FORMAT_A8R8G8B8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, srgb +PIPE_FORMAT_X8R8G8B8_SRGB , plain, 1, 1, x8 , un8 , un8 , un8 , yzw1, srgb + +# Mixed-sign formats (typically used for bump map textures) +PIPE_FORMAT_R8SG8SB8UX8U_NORM , plain, 1, 1, sn8 , sn8 , un8 , x8 , xyz1, rgb +PIPE_FORMAT_R10SG10SB10SA2U_NORM , plain, 1, 1, sn10, sn10, sn10, un2 , xyzw, rgb +PIPE_FORMAT_R5SG5SB6U_NORM , plain, 1, 1, sn5 , sn5 , un6 , , xyz1, rgb + +# Depth-stencil formats +PIPE_FORMAT_S8_USCALED , plain, 1, 1, u8 , , , , _x__, zs +PIPE_FORMAT_Z16_UNORM , plain, 1, 1, un16, , , , x___, zs +PIPE_FORMAT_Z32_UNORM , plain, 1, 1, un32, , , , x___, zs +PIPE_FORMAT_Z32_FLOAT , plain, 1, 1, f32 , , , , x___, zs +PIPE_FORMAT_Z24_UNORM_S8_USCALED , plain, 1, 1, un24, u8 , , , xy__, zs +PIPE_FORMAT_S8_USCALED_Z24_UNORM , plain, 1, 1, u8 , un24, , , yx__, zs +PIPE_FORMAT_X24S8_USCALED , plain, 1, 1, x24, u8 , , , _y__, zs +PIPE_FORMAT_S8X24_USCALED , plain, 1, 1, u8 , x24 , , , _x__, zs +PIPE_FORMAT_Z24X8_UNORM , plain, 1, 1, un24, x8 , , , x___, zs +PIPE_FORMAT_X8Z24_UNORM , plain, 1, 1, x8 , un24, , , y___, zs +PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED , plain, 1, 1, f32, u8 , x24 , , xy__, zs +PIPE_FORMAT_X32_S8X24_USCALED , plain, 1, 1, x32, u8 , x24 , , _y__, zs + +# YUV formats +# http://www.fourcc.org/yuv.php#UYVY +PIPE_FORMAT_UYVY , subsampled, 2, 1, x32 , , , , xyz1, yuv +# http://www.fourcc.org/yuv.php#YUYV (a.k.a http://www.fourcc.org/yuv.php#YUY2) +PIPE_FORMAT_YUYV , subsampled, 2, 1, x32 , , , , xyz1, yuv +# same subsampling but with rgb channels +PIPE_FORMAT_R8G8_B8G8_UNORM , subsampled, 2, 1, x32 , , , , xyz1, rgb +PIPE_FORMAT_G8R8_G8B8_UNORM , subsampled, 2, 1, x32 , , , , xyz1, rgb + +# some special formats not fitting anywhere else +PIPE_FORMAT_R10G10B10A2_USCALED , plain, 1, 1, u10 , u10 , u10 , u2 , xyzw, rgb +PIPE_FORMAT_R11G11B10_FLOAT , other, 1, 1, x32 , , , , xyz1, rgb +PIPE_FORMAT_R9G9B9E5_FLOAT , other, 1, 1, x32 , , , , xyz1, rgb +PIPE_FORMAT_R1_UNORM , other, 8, 1, x8 , , , , x001, rgb +# A.k.a. D3DFMT_CxV8U8 +PIPE_FORMAT_R8G8Bx_SNORM , other, 1, 1, sn8 , sn8 , , , xyz1, rgb + +# Compressed formats +# - http://en.wikipedia.org/wiki/S3_Texture_Compression +# - http://www.opengl.org/registry/specs/EXT/texture_compression_s3tc.txt +# - http://www.opengl.org/registry/specs/ARB/texture_compression_rgtc.txt +# - http://www.opengl.org/registry/specs/EXT/texture_compression_latc.txt +# - http://msdn.microsoft.com/en-us/library/bb694531.aspx +PIPE_FORMAT_DXT1_RGB , s3tc, 4, 4, x64 , , , , xyz1, rgb +PIPE_FORMAT_DXT1_RGBA , s3tc, 4, 4, x64 , , , , xyzw, rgb +PIPE_FORMAT_DXT3_RGBA , s3tc, 4, 4, x128, , , , xyzw, rgb +PIPE_FORMAT_DXT5_RGBA , s3tc, 4, 4, x128, , , , xyzw, rgb +PIPE_FORMAT_DXT1_SRGB , s3tc, 4, 4, x64 , , , , xyz1, srgb +PIPE_FORMAT_DXT1_SRGBA , s3tc, 4, 4, x64 , , , , xyzw, srgb +PIPE_FORMAT_DXT3_SRGBA , s3tc, 4, 4, x128, , , , xyzw, srgb +PIPE_FORMAT_DXT5_SRGBA , s3tc, 4, 4, x128, , , , xyzw, srgb + +PIPE_FORMAT_RGTC1_UNORM , rgtc, 4, 4, x64, , , , x001, rgb +PIPE_FORMAT_RGTC1_SNORM , rgtc, 4, 4, x64, , , , x001, rgb +PIPE_FORMAT_RGTC2_UNORM , rgtc, 4, 4, x128, , , , xy01, rgb +PIPE_FORMAT_RGTC2_SNORM , rgtc, 4, 4, x128, , , , xy01, rgb + +PIPE_FORMAT_LATC1_UNORM , rgtc, 4, 4, x64, , , , xxx1, rgb +PIPE_FORMAT_LATC1_SNORM , rgtc, 4, 4, x64, , , , xxx1, rgb +PIPE_FORMAT_LATC2_UNORM , rgtc, 4, 4, x128, , , , xxxy, rgb +PIPE_FORMAT_LATC2_SNORM , rgtc, 4, 4, x128, , , , xxxy, rgb + +# Straightforward D3D10-like formats (also used for +# vertex buffer element description) +# +# See also: +# - src/gallium/auxiliary/translate/translate_generic.c +# - src/mesa/state_tracker/st_draw.c +PIPE_FORMAT_R64_FLOAT , plain, 1, 1, f64 , , , , x001, rgb +PIPE_FORMAT_R64G64_FLOAT , plain, 1, 1, f64 , f64 , , , xy01, rgb +PIPE_FORMAT_R64G64B64_FLOAT , plain, 1, 1, f64 , f64 , f64 , , xyz1, rgb +PIPE_FORMAT_R64G64B64A64_FLOAT , plain, 1, 1, f64 , f64 , f64 , f64 , xyzw, rgb +PIPE_FORMAT_R32_FLOAT , plain, 1, 1, f32 , , , , x001, rgb +PIPE_FORMAT_R32G32_FLOAT , plain, 1, 1, f32 , f32 , , , xy01, rgb +PIPE_FORMAT_R32G32B32_FLOAT , plain, 1, 1, f32 , f32 , f32 , , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_FLOAT , plain, 1, 1, f32 , f32 , f32 , f32 , xyzw, rgb +PIPE_FORMAT_R32_UNORM , plain, 1, 1, un32, , , , x001, rgb +PIPE_FORMAT_R32G32_UNORM , plain, 1, 1, un32, un32, , , xy01, rgb +PIPE_FORMAT_R32G32B32_UNORM , plain, 1, 1, un32, un32, un32, , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_UNORM , plain, 1, 1, un32, un32, un32, un32, xyzw, rgb +PIPE_FORMAT_R32_USCALED , plain, 1, 1, u32 , , , , x001, rgb +PIPE_FORMAT_R32G32_USCALED , plain, 1, 1, u32 , u32 , , , xy01, rgb +PIPE_FORMAT_R32G32B32_USCALED , plain, 1, 1, u32 , u32 , u32 , , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_USCALED , plain, 1, 1, u32 , u32 , u32 , u32 , xyzw, rgb +PIPE_FORMAT_R32_SNORM , plain, 1, 1, sn32, , , , x001, rgb +PIPE_FORMAT_R32G32_SNORM , plain, 1, 1, sn32, sn32, , , xy01, rgb +PIPE_FORMAT_R32G32B32_SNORM , plain, 1, 1, sn32, sn32, sn32, , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_SNORM , plain, 1, 1, sn32, sn32, sn32, sn32, xyzw, rgb +PIPE_FORMAT_R32_SSCALED , plain, 1, 1, s32 , , , , x001, rgb +PIPE_FORMAT_R32G32_SSCALED , plain, 1, 1, s32 , s32 , , , xy01, rgb +PIPE_FORMAT_R32G32B32_SSCALED , plain, 1, 1, s32 , s32 , s32 , , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_SSCALED , plain, 1, 1, s32 , s32 , s32 , s32 , xyzw, rgb +PIPE_FORMAT_R16_FLOAT , plain, 1, 1, f16 , , , , x001, rgb +PIPE_FORMAT_R16G16_FLOAT , plain, 1, 1, f16 , f16 , , , xy01, rgb +PIPE_FORMAT_R16G16B16_FLOAT , plain, 1, 1, f16 , f16 , f16 , , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_FLOAT , plain, 1, 1, f16 , f16 , f16 , f16 , xyzw, rgb +PIPE_FORMAT_R16_UNORM , plain, 1, 1, un16, , , , x001, rgb +PIPE_FORMAT_R16G16_UNORM , plain, 1, 1, un16, un16, , , xy01, rgb +PIPE_FORMAT_R16G16B16_UNORM , plain, 1, 1, un16, un16, un16, , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_UNORM , plain, 1, 1, un16, un16, un16, un16, xyzw, rgb +PIPE_FORMAT_R16_USCALED , plain, 1, 1, u16 , , , , x001, rgb +PIPE_FORMAT_R16G16_USCALED , plain, 1, 1, u16 , u16 , , , xy01, rgb +PIPE_FORMAT_R16G16B16_USCALED , plain, 1, 1, u16 , u16 , u16 , , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_USCALED , plain, 1, 1, u16 , u16 , u16 , u16 , xyzw, rgb +PIPE_FORMAT_R16_SNORM , plain, 1, 1, sn16, , , , x001, rgb +PIPE_FORMAT_R16G16_SNORM , plain, 1, 1, sn16, sn16, , , xy01, rgb +PIPE_FORMAT_R16G16B16_SNORM , plain, 1, 1, sn16, sn16, sn16, , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_SNORM , plain, 1, 1, sn16, sn16, sn16, sn16, xyzw, rgb +PIPE_FORMAT_R16_SSCALED , plain, 1, 1, s16 , , , , x001, rgb +PIPE_FORMAT_R16G16_SSCALED , plain, 1, 1, s16 , s16 , , , xy01, rgb +PIPE_FORMAT_R16G16B16_SSCALED , plain, 1, 1, s16 , s16 , s16 , , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_SSCALED , plain, 1, 1, s16 , s16 , s16 , s16 , xyzw, rgb +PIPE_FORMAT_R8_UNORM , plain, 1, 1, un8 , , , , x001, rgb +PIPE_FORMAT_R8G8_UNORM , plain, 1, 1, un8 , un8 , , , xy01, rgb +PIPE_FORMAT_R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , , xyz1, rgb +PIPE_FORMAT_R8G8B8A8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , xyzw, rgb +PIPE_FORMAT_R8_USCALED , plain, 1, 1, u8 , , , , x001, rgb +PIPE_FORMAT_R8G8_USCALED , plain, 1, 1, u8 , u8 , , , xy01, rgb +PIPE_FORMAT_R8G8B8_USCALED , plain, 1, 1, u8 , u8 , u8 , , xyz1, rgb +PIPE_FORMAT_R8G8B8A8_USCALED , plain, 1, 1, u8 , u8 , u8 , u8 , xyzw, rgb +PIPE_FORMAT_R8_SNORM , plain, 1, 1, sn8 , , , , x001, rgb +PIPE_FORMAT_R8G8_SNORM , plain, 1, 1, sn8 , sn8 , , , xy01, rgb +PIPE_FORMAT_R8G8B8_SNORM , plain, 1, 1, sn8 , sn8 , sn8 , , xyz1, rgb +PIPE_FORMAT_R8G8B8A8_SNORM , plain, 1, 1, sn8 , sn8 , sn8 , sn8 , xyzw, rgb +PIPE_FORMAT_R8_SSCALED , plain, 1, 1, s8 , , , , x001, rgb +PIPE_FORMAT_R8G8_SSCALED , plain, 1, 1, s8 , s8 , , , xy01, rgb +PIPE_FORMAT_R8G8B8_SSCALED , plain, 1, 1, s8 , s8 , s8 , , xyz1, rgb +PIPE_FORMAT_R8G8B8A8_SSCALED , plain, 1, 1, s8 , s8 , s8 , s8 , xyzw, rgb + +# GL-specific vertex buffer element formats +# A.k.a. GL_FIXED +PIPE_FORMAT_R32_FIXED , plain, 1, 1, h32 , , , , x001, rgb +PIPE_FORMAT_R32G32_FIXED , plain, 1, 1, h32 , h32 , , , xy01, rgb +PIPE_FORMAT_R32G32B32_FIXED , plain, 1, 1, h32 , h32 , h32 , , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_FIXED , plain, 1, 1, h32 , h32 , h32 , h32 , xyzw, rgb + +# D3D9-specific vertex buffer element formats +# See also: +# - http://msdn.microsoft.com/en-us/library/bb172533.aspx +# A.k.a. D3DDECLTYPE_UDEC3 +PIPE_FORMAT_R10G10B10X2_USCALED , plain, 1, 1, u10 , u10 , u10 , x2 , xyz1, rgb +# A.k.a. D3DDECLTYPE_DEC3N +PIPE_FORMAT_R10G10B10X2_SNORM , plain, 1, 1, sn10, sn10, sn10 , x2 , xyz1, rgb + +PIPE_FORMAT_YV12 , subsampled, 1, 1, x8 , x8 , x8 , x8 , xyzw, yuv +PIPE_FORMAT_YV16 , subsampled, 1, 1, x8 , x8 , x8 , x8 , xyzw, yuv +PIPE_FORMAT_IYUV , subsampled, 1, 1, x8 , x8 , x8 , x8 , xyzw, yuv +PIPE_FORMAT_NV12 , subsampled, 1, 1, x8 , x8 , x8 , x8 , xyzw, yuv +PIPE_FORMAT_NV21 , subsampled, 1, 1, x8 , x8 , x8 , x8 , xyzw, yuv +PIPE_FORMAT_IA44 , subsampled, 1, 1, x8 , x8 , x8 , x8 , xyzw, yuv +PIPE_FORMAT_AI44 , subsampled, 1, 1, x8 , x8 , x8 , x8 , xyzw, yuv diff --git a/mesalib/src/gallium/auxiliary/util/u_format_yuv.c b/mesalib/src/gallium/auxiliary/util/u_format_yuv.c index d1852af2d..64ea0b353 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format_yuv.c +++ b/mesalib/src/gallium/auxiliary/util/u_format_yuv.c @@ -1,1047 +1,1182 @@ -/************************************************************************** - * - * Copyright 2010 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 - * without limitation the rights to use, copy, modify, merge, publish, - * 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 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. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - **************************************************************************/ - - -/** - * @file - * YUV and RGB subsampled formats conversion. - * - * @author Jose Fonseca - */ - - -#include "util/u_format_yuv.h" - - -void -util_format_r8g8_b8g8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - float *dst = dst_row; - const uint32_t *src = (const uint32_t *)src_row; - uint32_t value; - float r, g0, g1, b; - - for (x = 0; x + 1 < width; x += 2) { - value = *src++; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - r = ubyte_to_float((value >> 0) & 0xff); - g0 = ubyte_to_float((value >> 8) & 0xff); - b = ubyte_to_float((value >> 16) & 0xff); - g1 = ubyte_to_float((value >> 24) & 0xff); - - dst[0] = r; /* r */ - dst[1] = g0; /* g */ - dst[2] = b; /* b */ - dst[3] = 1.0f; /* a */ - dst += 4; - - dst[0] = r; /* r */ - dst[1] = g1; /* g */ - dst[2] = b; /* b */ - dst[3] = 1.0f; /* a */ - dst += 4; - } - - if (x < width) { - value = *src; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - r = ubyte_to_float((value >> 0) & 0xff); - g0 = ubyte_to_float((value >> 8) & 0xff); - b = ubyte_to_float((value >> 16) & 0xff); - g1 = ubyte_to_float((value >> 24) & 0xff); - - dst[0] = r; /* r */ - dst[1] = g0; /* g */ - dst[2] = b; /* b */ - dst[3] = 1.0f; /* a */ - } - - src_row += src_stride/sizeof(*src_row); - dst_row += dst_stride/sizeof(*dst_row); - } -} - - -void -util_format_r8g8_b8g8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - uint8_t *dst = dst_row; - const uint32_t *src = (const uint32_t *)src_row; - uint32_t value; - uint8_t r, g0, g1, b; - - for (x = 0; x + 1 < width; x += 2) { - value = *src++; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - r = (value >> 0) & 0xff; - g0 = (value >> 8) & 0xff; - b = (value >> 16) & 0xff; - g1 = (value >> 24) & 0xff; - - dst[0] = r; /* r */ - dst[1] = g0; /* g */ - dst[2] = b; /* b */ - dst[3] = 0xff; /* a */ - dst += 4; - - dst[0] = r; /* r */ - dst[1] = g1; /* g */ - dst[2] = b; /* b */ - dst[3] = 0xff; /* a */ - dst += 4; - } - - if (x < width) { - value = *src; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - r = (value >> 0) & 0xff; - g0 = (value >> 8) & 0xff; - b = (value >> 16) & 0xff; - g1 = (value >> 24) & 0xff; - - dst[0] = r; /* r */ - dst[1] = g0; /* g */ - dst[2] = b; /* b */ - dst[3] = 0xff; /* a */ - } - - src_row += src_stride/sizeof(*src_row); - dst_row += dst_stride/sizeof(*dst_row); - } -} - - -void -util_format_r8g8_b8g8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, - const float *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - const float *src = src_row; - uint32_t *dst = (uint32_t *)dst_row; - float r, g0, g1, b; - uint32_t value; - - for (x = 0; x + 1 < width; x += 2) { - r = 0.5f*(src[0] + src[4]); - g0 = src[1]; - g1 = src[5]; - b = 0.5f*(src[2] + src[6]); - - value = float_to_ubyte(r); - value |= float_to_ubyte(g0) << 8; - value |= float_to_ubyte(b) << 16; - value |= float_to_ubyte(g1) << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst++ = value; - - src += 8; - } - - if (x < width) { - r = src[0]; - g0 = src[1]; - g1 = 0; - b = src[2]; - - value = float_to_ubyte(r); - value |= float_to_ubyte(g0) << 8; - value |= float_to_ubyte(b) << 16; - value |= float_to_ubyte(g1) << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst = value; - } - - dst_row += dst_stride/sizeof(*dst_row); - src_row += src_stride/sizeof(*src_row); - } -} - - -void -util_format_r8g8_b8g8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - const uint8_t *src = src_row; - uint32_t *dst = (uint32_t *)dst_row; - uint32_t r, g0, g1, b; - uint32_t value; - - for (x = 0; x + 1 < width; x += 2) { - r = (src[0] + src[4] + 1) >> 1; - g0 = src[1]; - g1 = src[5]; - b = (src[2] + src[6] + 1) >> 1; - - value = r; - value |= g0 << 8; - value |= b << 16; - value |= g1 << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst++ = value; - - src += 8; - } - - if (x < width) { - r = src[0]; - g0 = src[1]; - g1 = 0; - b = src[2]; - - value = r; - value |= g0 << 8; - value |= b << 16; - value |= g1 << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst = value; - } - - dst_row += dst_stride/sizeof(*dst_row); - src_row += src_stride/sizeof(*src_row); - } -} - - -void -util_format_r8g8_b8g8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, - unsigned i, unsigned j) -{ - assert(i < 2); - assert(j < 1); - - dst[0] = ubyte_to_float(src[0]); /* r */ - dst[1] = ubyte_to_float(src[1 + 2*i]); /* g */ - dst[2] = ubyte_to_float(src[2]); /* b */ - dst[3] = 1.0f; /* a */ -} - - -void -util_format_g8r8_g8b8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - float *dst = dst_row; - const uint32_t *src = (const uint32_t *)src_row; - uint32_t value; - float r, g0, g1, b; - - for (x = 0; x + 1 < width; x += 2) { - value = *src++; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - g0 = ubyte_to_float((value >> 0) & 0xff); - r = ubyte_to_float((value >> 8) & 0xff); - g1 = ubyte_to_float((value >> 16) & 0xff); - b = ubyte_to_float((value >> 24) & 0xff); - - dst[0] = r; /* r */ - dst[1] = g0; /* g */ - dst[2] = b; /* b */ - dst[3] = 1.0f; /* a */ - dst += 4; - - dst[0] = r; /* r */ - dst[1] = g1; /* g */ - dst[2] = b; /* b */ - dst[3] = 1.0f; /* a */ - dst += 4; - } - - if (x < width) { - value = *src; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - g0 = ubyte_to_float((value >> 0) & 0xff); - r = ubyte_to_float((value >> 8) & 0xff); - g1 = ubyte_to_float((value >> 16) & 0xff); - b = ubyte_to_float((value >> 24) & 0xff); - - dst[0] = r; /* r */ - dst[1] = g0; /* g */ - dst[2] = b; /* b */ - dst[3] = 1.0f; /* a */ - } - - src_row += src_stride/sizeof(*src_row); - dst_row += dst_stride/sizeof(*dst_row); - } -} - - -void -util_format_g8r8_g8b8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - uint8_t *dst = dst_row; - const uint32_t *src = (const uint32_t *)src_row; - uint32_t value; - uint8_t r, g0, g1, b; - - for (x = 0; x + 1 < width; x += 2) { - value = *src++; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - g0 = (value >> 0) & 0xff; - r = (value >> 8) & 0xff; - g1 = (value >> 16) & 0xff; - b = (value >> 24) & 0xff; - - dst[0] = r; /* r */ - dst[1] = g0; /* g */ - dst[2] = b; /* b */ - dst[3] = 0xff; /* a */ - dst += 4; - - dst[0] = r; /* r */ - dst[1] = g1; /* g */ - dst[2] = b; /* b */ - dst[3] = 0xff; /* a */ - dst += 4; - } - - if (x < width) { - value = *src; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - g0 = (value >> 0) & 0xff; - r = (value >> 8) & 0xff; - g1 = (value >> 16) & 0xff; - b = (value >> 24) & 0xff; - - dst[0] = r; /* r */ - dst[1] = g0; /* g */ - dst[2] = b; /* b */ - dst[3] = 0xff; /* a */ - } - - src_row += src_stride/sizeof(*src_row); - dst_row += dst_stride/sizeof(*dst_row); - } -} - - -void -util_format_g8r8_g8b8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, - const float *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - const float *src = src_row; - uint32_t *dst = (uint32_t *)dst_row; - float r, g0, g1, b; - uint32_t value; - - for (x = 0; x + 1 < width; x += 2) { - r = 0.5f*(src[0] + src[4]); - g0 = src[1]; - g1 = src[5]; - b = 0.5f*(src[2] + src[6]); - - value = float_to_ubyte(g0); - value |= float_to_ubyte(r) << 8; - value |= float_to_ubyte(g1) << 16; - value |= float_to_ubyte(b) << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst++ = value; - - src += 8; - } - - if (x < width) { - r = src[0]; - g0 = src[1]; - g1 = 0; - b = src[2]; - - value = float_to_ubyte(g0); - value |= float_to_ubyte(r) << 8; - value |= float_to_ubyte(g1) << 16; - value |= float_to_ubyte(b) << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst = value; - } - - dst_row += dst_stride/sizeof(*dst_row); - src_row += src_stride/sizeof(*src_row); - } -} - - -void -util_format_g8r8_g8b8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - const uint8_t *src = src_row; - uint32_t *dst = (uint32_t *)dst_row; - uint32_t r, g0, g1, b; - uint32_t value; - - for (x = 0; x + 1 < width; x += 2) { - r = (src[0] + src[4] + 1) >> 1; - g0 = src[1]; - g1 = src[5]; - b = (src[2] + src[6] + 1) >> 1; - - value = g0; - value |= r << 8; - value |= g1 << 16; - value |= b << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst++ = value; - - src += 8; - } - - if (x < width) { - r = src[0]; - g0 = src[1]; - g1 = 0; - b = src[2]; - - value = g0; - value |= r << 8; - value |= g1 << 16; - value |= b << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst = value; - } - - dst_row += dst_stride/sizeof(*dst_row); - src_row += src_stride/sizeof(*src_row); - } -} - - -void -util_format_g8r8_g8b8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, - unsigned i, unsigned j) -{ - assert(i < 2); - assert(j < 1); - - dst[0] = ubyte_to_float(src[1]); /* r */ - dst[1] = ubyte_to_float(src[0 + 2*i]); /* g */ - dst[2] = ubyte_to_float(src[3]); /* b */ - dst[3] = 1.0f; /* a */ -} - - -void -util_format_uyvy_unpack_rgba_float(float *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - float *dst = dst_row; - const uint32_t *src = (const uint32_t *)src_row; - uint32_t value; - uint8_t y0, y1, u, v; - - for (x = 0; x + 1 < width; x += 2) { - value = *src++; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - u = (value >> 0) & 0xff; - y0 = (value >> 8) & 0xff; - v = (value >> 16) & 0xff; - y1 = (value >> 24) & 0xff; - - util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]); - dst[3] = 1.0f; /* a */ - dst += 4; - - util_format_yuv_to_rgb_float(y1, u, v, &dst[0], &dst[1], &dst[2]); - dst[3] = 1.0f; /* a */ - dst += 4; - } - - if (x < width) { - value = *src; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - u = (value >> 0) & 0xff; - y0 = (value >> 8) & 0xff; - v = (value >> 16) & 0xff; - y1 = (value >> 24) & 0xff; - - util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]); - dst[3] = 1.0f; /* a */ - } - - src_row += src_stride/sizeof(*src_row); - dst_row += dst_stride/sizeof(*dst_row); - } -} - - -void -util_format_uyvy_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - uint8_t *dst = dst_row; - const uint32_t *src = (const uint32_t *)src_row; - uint32_t value; - uint8_t y0, y1, u, v; - - for (x = 0; x + 1 < width; x += 2) { - value = *src++; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - u = (value >> 0) & 0xff; - y0 = (value >> 8) & 0xff; - v = (value >> 16) & 0xff; - y1 = (value >> 24) & 0xff; - - util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]); - dst[3] = 0xff; /* a */ - dst += 4; - - util_format_yuv_to_rgb_8unorm(y1, u, v, &dst[0], &dst[1], &dst[2]); - dst[3] = 0xff; /* a */ - dst += 4; - } - - if (x < width) { - value = *src; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - u = (value >> 0) & 0xff; - y0 = (value >> 8) & 0xff; - v = (value >> 16) & 0xff; - y1 = (value >> 24) & 0xff; - - util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]); - dst[3] = 0xff; /* a */ - } - - src_row += src_stride/sizeof(*src_row); - dst_row += dst_stride/sizeof(*dst_row); - } -} - - -void -util_format_uyvy_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, - const float *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - const float *src = src_row; - uint32_t *dst = (uint32_t *)dst_row; - uint8_t y0, y1, u, v; - uint32_t value; - - for (x = 0; x + 1 < width; x += 2) { - uint8_t y0, y1, u0, u1, v0, v1, u, v; - - util_format_rgb_float_to_yuv(src[0], src[1], src[2], - &y0, &u0, &v0); - util_format_rgb_float_to_yuv(src[4], src[5], src[6], - &y1, &u1, &v1); - - u = (u0 + u1 + 1) >> 1; - v = (v0 + v1 + 1) >> 1; - - value = u; - value |= y0 << 8; - value |= v << 16; - value |= y1 << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst++ = value; - - src += 8; - } - - if (x < width) { - util_format_rgb_float_to_yuv(src[0], src[1], src[2], - &y0, &u, &v); - y1 = 0; - - value = u; - value |= y0 << 8; - value |= v << 16; - value |= y1 << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst = value; - } - - dst_row += dst_stride/sizeof(*dst_row); - src_row += src_stride/sizeof(*src_row); - } -} - - -void -util_format_uyvy_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - const uint8_t *src = src_row; - uint32_t *dst = (uint32_t *)dst_row; - uint8_t y0, y1, u, v; - uint32_t value; - - for (x = 0; x + 1 < width; x += 2) { - uint8_t y0, y1, u0, u1, v0, v1, u, v; - - util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2], - &y0, &u0, &v0); - util_format_rgb_8unorm_to_yuv(src[4], src[5], src[6], - &y1, &u1, &v1); - - u = (u0 + u1 + 1) >> 1; - v = (v0 + v1 + 1) >> 1; - - value = u; - value |= y0 << 8; - value |= v << 16; - value |= y1 << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst++ = value; - - src += 8; - } - - if (x < width) { - util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2], - &y0, &u, &v); - y1 = 0; - - value = u; - value |= y0 << 8; - value |= v << 16; - value |= y1 << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst = value; - } - - dst_row += dst_stride/sizeof(*dst_row); - src_row += src_stride/sizeof(*src_row); - } -} - - -void -util_format_uyvy_fetch_rgba_float(float *dst, const uint8_t *src, - unsigned i, unsigned j) -{ - uint8_t y, u, v; - - assert(i < 2); - assert(j < 1); - - y = src[1 + i*2]; - u = src[0]; - v = src[2]; - - util_format_yuv_to_rgb_float(y, u, v, &dst[0], &dst[1], &dst[2]); - - dst[3] = 1.0f; -} - - -void -util_format_yuyv_unpack_rgba_float(float *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - float *dst = dst_row; - const uint32_t *src = (const uint32_t *)src_row; - uint32_t value; - uint8_t y0, y1, u, v; - - for (x = 0; x + 1 < width; x += 2) { - value = *src++; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - y0 = (value >> 0) & 0xff; - u = (value >> 8) & 0xff; - y1 = (value >> 16) & 0xff; - v = (value >> 24) & 0xff; - - util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]); - dst[3] = 1.0f; /* a */ - dst += 4; - - util_format_yuv_to_rgb_float(y1, u, v, &dst[0], &dst[1], &dst[2]); - dst[3] = 1.0f; /* a */ - dst += 4; - } - - if (x < width) { - value = *src; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - y0 = (value >> 0) & 0xff; - u = (value >> 8) & 0xff; - y1 = (value >> 16) & 0xff; - v = (value >> 24) & 0xff; - - util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]); - dst[3] = 1.0f; /* a */ - } - - src_row += src_stride/sizeof(*src_row); - dst_row += dst_stride/sizeof(*dst_row); - } -} - - -void -util_format_yuyv_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - uint8_t *dst = dst_row; - const uint32_t *src = (const uint32_t *)src_row; - uint32_t value; - uint8_t y0, y1, u, v; - - for (x = 0; x + 1 < width; x += 2) { - value = *src++; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - y0 = (value >> 0) & 0xff; - u = (value >> 8) & 0xff; - y1 = (value >> 16) & 0xff; - v = (value >> 24) & 0xff; - - util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]); - dst[3] = 0xff; /* a */ - dst += 4; - - util_format_yuv_to_rgb_8unorm(y1, u, v, &dst[0], &dst[1], &dst[2]); - dst[3] = 0xff; /* a */ - dst += 4; - } - - if (x < width) { - value = *src; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - y0 = (value >> 0) & 0xff; - u = (value >> 8) & 0xff; - y1 = (value >> 16) & 0xff; - v = (value >> 24) & 0xff; - - util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]); - dst[3] = 0xff; /* a */ - } - - src_row += src_stride/sizeof(*src_row); - dst_row += dst_stride/sizeof(*dst_row); - } -} - - -void -util_format_yuyv_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, - const float *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - const float *src = src_row; - uint32_t *dst = (uint32_t *)dst_row; - uint8_t y0, y1, u, v; - uint32_t value; - - for (x = 0; x + 1 < width; x += 2) { - uint8_t y0, y1, u0, u1, v0, v1, u, v; - - util_format_rgb_float_to_yuv(src[0], src[1], src[2], - &y0, &u0, &v0); - util_format_rgb_float_to_yuv(src[4], src[5], src[6], - &y1, &u1, &v1); - - u = (u0 + u1 + 1) >> 1; - v = (v0 + v1 + 1) >> 1; - - value = y0; - value |= u << 8; - value |= y1 << 16; - value |= v << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst++ = value; - - src += 8; - } - - if (x < width) { - util_format_rgb_float_to_yuv(src[0], src[1], src[2], - &y0, &u, &v); - y1 = 0; - - value = y0; - value |= u << 8; - value |= y1 << 16; - value |= v << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst = value; - } - - dst_row += dst_stride/sizeof(*dst_row); - src_row += src_stride/sizeof(*src_row); - } -} - - -void -util_format_yuyv_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height) -{ - unsigned x, y; - - for (y = 0; y < height; y += 1) { - const uint8_t *src = src_row; - uint32_t *dst = (uint32_t *)dst_row; - uint8_t y0, y1, u, v; - uint32_t value; - - for (x = 0; x + 1 < width; x += 2) { - uint8_t y0, y1, u0, u1, v0, v1, u, v; - - util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2], - &y0, &u0, &v0); - util_format_rgb_8unorm_to_yuv(src[4], src[5], src[6], - &y1, &u1, &v1); - - u = (u0 + u1 + 1) >> 1; - v = (v0 + v1 + 1) >> 1; - - value = y0; - value |= u << 8; - value |= y1 << 16; - value |= v << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst++ = value; - - src += 8; - } - - if (x < width) { - util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2], - &y0, &u, &v); - y1 = 0; - - value = y0; - value |= u << 8; - value |= y1 << 16; - value |= v << 24; - -#ifdef PIPE_ARCH_BIG_ENDIAN - value = util_bswap32(value); -#endif - - *dst = value; - } - - dst_row += dst_stride/sizeof(*dst_row); - src_row += src_stride/sizeof(*src_row); - } -} - - -void -util_format_yuyv_fetch_rgba_float(float *dst, const uint8_t *src, - unsigned i, unsigned j) -{ - uint8_t y, u, v; - - assert(i < 2); - assert(j < 1); - - y = src[0 + i*2]; - u = src[1]; - v = src[3]; - - util_format_yuv_to_rgb_float(y, u, v, &dst[0], &dst[1], &dst[2]); - - dst[3] = 1.0f; -} +/************************************************************************** + * + * Copyright 2010 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 + * without limitation the rights to use, copy, modify, merge, publish, + * 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 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. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + + +/** + * @file + * YUV and RGB subsampled formats conversion. + * + * @author Jose Fonseca + */ + + +#include "util/u_format_yuv.h" + + +void +util_format_r8g8_b8g8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + float *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + float r, g0, g1, b; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = ubyte_to_float((value >> 0) & 0xff); + g0 = ubyte_to_float((value >> 8) & 0xff); + b = ubyte_to_float((value >> 16) & 0xff); + g1 = ubyte_to_float((value >> 24) & 0xff); + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 1.0f; /* a */ + dst += 4; + + dst[0] = r; /* r */ + dst[1] = g1; /* g */ + dst[2] = b; /* b */ + dst[3] = 1.0f; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = ubyte_to_float((value >> 0) & 0xff); + g0 = ubyte_to_float((value >> 8) & 0xff); + b = ubyte_to_float((value >> 16) & 0xff); + g1 = ubyte_to_float((value >> 24) & 0xff); + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 1.0f; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_r8g8_b8g8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + uint8_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + uint8_t r, g0, g1, b; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = (value >> 0) & 0xff; + g0 = (value >> 8) & 0xff; + b = (value >> 16) & 0xff; + g1 = (value >> 24) & 0xff; + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 0xff; /* a */ + dst += 4; + + dst[0] = r; /* r */ + dst[1] = g1; /* g */ + dst[2] = b; /* b */ + dst[3] = 0xff; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = (value >> 0) & 0xff; + g0 = (value >> 8) & 0xff; + b = (value >> 16) & 0xff; + g1 = (value >> 24) & 0xff; + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 0xff; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_r8g8_b8g8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const float *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + float r, g0, g1, b; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + r = 0.5f*(src[0] + src[4]); + g0 = src[1]; + g1 = src[5]; + b = 0.5f*(src[2] + src[6]); + + value = float_to_ubyte(r); + value |= float_to_ubyte(g0) << 8; + value |= float_to_ubyte(b) << 16; + value |= float_to_ubyte(g1) << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + r = src[0]; + g0 = src[1]; + g1 = 0; + b = src[2]; + + value = float_to_ubyte(r); + value |= float_to_ubyte(g0) << 8; + value |= float_to_ubyte(b) << 16; + value |= float_to_ubyte(g1) << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_r8g8_b8g8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const uint8_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + uint32_t r, g0, g1, b; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + r = (src[0] + src[4] + 1) >> 1; + g0 = src[1]; + g1 = src[5]; + b = (src[2] + src[6] + 1) >> 1; + + value = r; + value |= g0 << 8; + value |= b << 16; + value |= g1 << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + r = src[0]; + g0 = src[1]; + g1 = 0; + b = src[2]; + + value = r; + value |= g0 << 8; + value |= b << 16; + value |= g1 << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_r8g8_b8g8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + assert(i < 2); + assert(j < 1); + + dst[0] = ubyte_to_float(src[0]); /* r */ + dst[1] = ubyte_to_float(src[1 + 2*i]); /* g */ + dst[2] = ubyte_to_float(src[2]); /* b */ + dst[3] = 1.0f; /* a */ +} + + +void +util_format_g8r8_g8b8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + float *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + float r, g0, g1, b; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + g0 = ubyte_to_float((value >> 0) & 0xff); + r = ubyte_to_float((value >> 8) & 0xff); + g1 = ubyte_to_float((value >> 16) & 0xff); + b = ubyte_to_float((value >> 24) & 0xff); + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 1.0f; /* a */ + dst += 4; + + dst[0] = r; /* r */ + dst[1] = g1; /* g */ + dst[2] = b; /* b */ + dst[3] = 1.0f; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + g0 = ubyte_to_float((value >> 0) & 0xff); + r = ubyte_to_float((value >> 8) & 0xff); + g1 = ubyte_to_float((value >> 16) & 0xff); + b = ubyte_to_float((value >> 24) & 0xff); + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 1.0f; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_g8r8_g8b8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + uint8_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + uint8_t r, g0, g1, b; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + g0 = (value >> 0) & 0xff; + r = (value >> 8) & 0xff; + g1 = (value >> 16) & 0xff; + b = (value >> 24) & 0xff; + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 0xff; /* a */ + dst += 4; + + dst[0] = r; /* r */ + dst[1] = g1; /* g */ + dst[2] = b; /* b */ + dst[3] = 0xff; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + g0 = (value >> 0) & 0xff; + r = (value >> 8) & 0xff; + g1 = (value >> 16) & 0xff; + b = (value >> 24) & 0xff; + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 0xff; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_g8r8_g8b8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const float *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + float r, g0, g1, b; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + r = 0.5f*(src[0] + src[4]); + g0 = src[1]; + g1 = src[5]; + b = 0.5f*(src[2] + src[6]); + + value = float_to_ubyte(g0); + value |= float_to_ubyte(r) << 8; + value |= float_to_ubyte(g1) << 16; + value |= float_to_ubyte(b) << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + r = src[0]; + g0 = src[1]; + g1 = 0; + b = src[2]; + + value = float_to_ubyte(g0); + value |= float_to_ubyte(r) << 8; + value |= float_to_ubyte(g1) << 16; + value |= float_to_ubyte(b) << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_g8r8_g8b8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const uint8_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + uint32_t r, g0, g1, b; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + r = (src[0] + src[4] + 1) >> 1; + g0 = src[1]; + g1 = src[5]; + b = (src[2] + src[6] + 1) >> 1; + + value = g0; + value |= r << 8; + value |= g1 << 16; + value |= b << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + r = src[0]; + g0 = src[1]; + g1 = 0; + b = src[2]; + + value = g0; + value |= r << 8; + value |= g1 << 16; + value |= b << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_g8r8_g8b8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + assert(i < 2); + assert(j < 1); + + dst[0] = ubyte_to_float(src[1]); /* r */ + dst[1] = ubyte_to_float(src[0 + 2*i]); /* g */ + dst[2] = ubyte_to_float(src[3]); /* b */ + dst[3] = 1.0f; /* a */ +} + + +void +util_format_uyvy_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + float *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + uint8_t y0, y1, u, v; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + u = (value >> 0) & 0xff; + y0 = (value >> 8) & 0xff; + v = (value >> 16) & 0xff; + y1 = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 1.0f; /* a */ + dst += 4; + + util_format_yuv_to_rgb_float(y1, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 1.0f; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + u = (value >> 0) & 0xff; + y0 = (value >> 8) & 0xff; + v = (value >> 16) & 0xff; + y1 = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 1.0f; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_uyvy_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + uint8_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + uint8_t y0, y1, u, v; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + u = (value >> 0) & 0xff; + y0 = (value >> 8) & 0xff; + v = (value >> 16) & 0xff; + y1 = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 0xff; /* a */ + dst += 4; + + util_format_yuv_to_rgb_8unorm(y1, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 0xff; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + u = (value >> 0) & 0xff; + y0 = (value >> 8) & 0xff; + v = (value >> 16) & 0xff; + y1 = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 0xff; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_uyvy_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const float *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + uint8_t y0, y1, u, v; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + uint8_t y0, y1, u0, u1, v0, v1, u, v; + + util_format_rgb_float_to_yuv(src[0], src[1], src[2], + &y0, &u0, &v0); + util_format_rgb_float_to_yuv(src[4], src[5], src[6], + &y1, &u1, &v1); + + u = (u0 + u1 + 1) >> 1; + v = (v0 + v1 + 1) >> 1; + + value = u; + value |= y0 << 8; + value |= v << 16; + value |= y1 << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + util_format_rgb_float_to_yuv(src[0], src[1], src[2], + &y0, &u, &v); + y1 = 0; + + value = u; + value |= y0 << 8; + value |= v << 16; + value |= y1 << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_uyvy_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const uint8_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + uint8_t y0, y1, u, v; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + uint8_t y0, y1, u0, u1, v0, v1, u, v; + + util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2], + &y0, &u0, &v0); + util_format_rgb_8unorm_to_yuv(src[4], src[5], src[6], + &y1, &u1, &v1); + + u = (u0 + u1 + 1) >> 1; + v = (v0 + v1 + 1) >> 1; + + value = u; + value |= y0 << 8; + value |= v << 16; + value |= y1 << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2], + &y0, &u, &v); + y1 = 0; + + value = u; + value |= y0 << 8; + value |= v << 16; + value |= y1 << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_uyvy_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + uint8_t y, u, v; + + assert(i < 2); + assert(j < 1); + + y = src[1 + i*2]; + u = src[0]; + v = src[2]; + + util_format_yuv_to_rgb_float(y, u, v, &dst[0], &dst[1], &dst[2]); + + dst[3] = 1.0f; +} + + +void +util_format_yuyv_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + float *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + uint8_t y0, y1, u, v; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + y0 = (value >> 0) & 0xff; + u = (value >> 8) & 0xff; + y1 = (value >> 16) & 0xff; + v = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 1.0f; /* a */ + dst += 4; + + util_format_yuv_to_rgb_float(y1, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 1.0f; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + y0 = (value >> 0) & 0xff; + u = (value >> 8) & 0xff; + y1 = (value >> 16) & 0xff; + v = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 1.0f; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_yuyv_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + uint8_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + uint8_t y0, y1, u, v; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + y0 = (value >> 0) & 0xff; + u = (value >> 8) & 0xff; + y1 = (value >> 16) & 0xff; + v = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 0xff; /* a */ + dst += 4; + + util_format_yuv_to_rgb_8unorm(y1, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 0xff; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + y0 = (value >> 0) & 0xff; + u = (value >> 8) & 0xff; + y1 = (value >> 16) & 0xff; + v = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 0xff; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_yuyv_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const float *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + uint8_t y0, y1, u, v; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + uint8_t y0, y1, u0, u1, v0, v1, u, v; + + util_format_rgb_float_to_yuv(src[0], src[1], src[2], + &y0, &u0, &v0); + util_format_rgb_float_to_yuv(src[4], src[5], src[6], + &y1, &u1, &v1); + + u = (u0 + u1 + 1) >> 1; + v = (v0 + v1 + 1) >> 1; + + value = y0; + value |= u << 8; + value |= y1 << 16; + value |= v << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + util_format_rgb_float_to_yuv(src[0], src[1], src[2], + &y0, &u, &v); + y1 = 0; + + value = y0; + value |= u << 8; + value |= y1 << 16; + value |= v << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_yuyv_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const uint8_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + uint8_t y0, y1, u, v; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + uint8_t y0, y1, u0, u1, v0, v1, u, v; + + util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2], + &y0, &u0, &v0); + util_format_rgb_8unorm_to_yuv(src[4], src[5], src[6], + &y1, &u1, &v1); + + u = (u0 + u1 + 1) >> 1; + v = (v0 + v1 + 1) >> 1; + + value = y0; + value |= u << 8; + value |= y1 << 16; + value |= v << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2], + &y0, &u, &v); + y1 = 0; + + value = y0; + value |= u << 8; + value |= y1 << 16; + value |= v << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_yuyv_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + uint8_t y, u, v; + + assert(i < 2); + assert(j < 1); + + y = src[0 + i*2]; + u = src[1]; + v = src[3]; + + util_format_yuv_to_rgb_float(y, u, v, &dst[0], &dst[1], &dst[2]); + + dst[3] = 1.0f; +} + +/* XXX: Stubbed for now */ +void +util_format_yv12_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_yv12_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_yv12_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_yv12_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_yv12_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) {} +void +util_format_yv16_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_yv16_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_yv16_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_yv16_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_yv16_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) {} +void +util_format_iyuv_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_iyuv_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_iyuv_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_iyuv_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_iyuv_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) {} +void +util_format_nv12_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_nv12_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_nv12_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_nv12_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_nv12_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) {} +void +util_format_nv21_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_nv21_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_nv21_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_nv21_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_nv21_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) {} +void +util_format_ia44_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_ia44_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_ia44_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_ia44_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_ia44_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) {} +void +util_format_ai44_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_ai44_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_ai44_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_ai44_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) {} +void +util_format_ai44_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) {} diff --git a/mesalib/src/gallium/auxiliary/util/u_format_yuv.h b/mesalib/src/gallium/auxiliary/util/u_format_yuv.h index d2c403ded..9f2365a52 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format_yuv.h +++ b/mesalib/src/gallium/auxiliary/util/u_format_yuv.h @@ -1,223 +1,358 @@ -/************************************************************************** - * - * Copyright 2010 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 - * without limitation the rights to use, copy, modify, merge, publish, - * 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 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. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - **************************************************************************/ - - -/** - * @file - * YUV colorspace conversion. - * - * @author Brian Paul - * @author Michal Krol - * @author Jose Fonseca - * - * See also: - * - http://www.fourcc.org/fccyvrgb.php - * - http://msdn.microsoft.com/en-us/library/ms893078 - * - http://en.wikipedia.org/wiki/YUV - */ - - -#ifndef U_FORMAT_YUV_H_ -#define U_FORMAT_YUV_H_ - - -#include "pipe/p_compiler.h" -#include "u_math.h" - - -/* - * TODO: Ensure we use consistent and right floating formulas, with enough - * precision in the coefficients. - */ - -static INLINE void -util_format_rgb_float_to_yuv(float r, float g, float b, - uint8_t *y, uint8_t *u, uint8_t *v) -{ - const float _r = CLAMP(r, 0.0f, 1.0f); - const float _g = CLAMP(g, 0.0f, 1.0f); - const float _b = CLAMP(b, 0.0f, 1.0f); - - const float scale = 255.0f; - - const int _y = scale * ( (0.257f * _r) + (0.504f * _g) + (0.098f * _b)); - const int _u = scale * (-(0.148f * _r) - (0.291f * _g) + (0.439f * _b)); - const int _v = scale * ( (0.439f * _r) - (0.368f * _g) - (0.071f * _b)); - - *y = _y + 16; - *u = _u + 128; - *v = _v + 128; -} - - -static INLINE void -util_format_yuv_to_rgb_float(uint8_t y, uint8_t u, uint8_t v, - float *r, float *g, float *b) -{ - const int _y = y - 16; - const int _u = u - 128; - const int _v = v - 128; - - const float y_factor = 255.0f / 219.0f; - - const float scale = 1.0f / 255.0f; - - *r = scale * (y_factor * _y + 1.596f * _v); - *g = scale * (y_factor * _y - 0.391f * _u - 0.813f * _v); - *b = scale * (y_factor * _y + 2.018f * _u ); -} - - -static INLINE void -util_format_rgb_8unorm_to_yuv(uint8_t r, uint8_t g, uint8_t b, - uint8_t *y, uint8_t *u, uint8_t *v) -{ - *y = (( 66 * r + 129 * g + 25 * b + 128) >> 8) + 16; - *u = (( -38 * r - 74 * g + 112 * b + 128) >> 8) + 128; - *v = (( 112 * r - 94 * g - 18 * b + 128) >> 8) + 128; -} - - -static INLINE void -util_format_yuv_to_rgb_8unorm(uint8_t y, uint8_t u, uint8_t v, - uint8_t *r, uint8_t *g, uint8_t *b) -{ - const int _y = y - 16; - const int _u = u - 128; - const int _v = v - 128; - - const int _r = (298 * _y + 409 * _v + 128) >> 8; - const int _g = (298 * _y - 100 * _u - 208 * _v + 128) >> 8; - const int _b = (298 * _y + 516 * _u + 128) >> 8; - - *r = CLAMP(_r, 0, 255); - *g = CLAMP(_g, 0, 255); - *b = CLAMP(_b, 0, 255); -} - - - -void -util_format_uyvy_unpack_rgba_float(float *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_uyvy_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_uyvy_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, - const float *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_uyvy_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_uyvy_fetch_rgba_float(float *dst, const uint8_t *src, - unsigned i, unsigned j); - -void -util_format_yuyv_unpack_rgba_float(float *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_yuyv_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_yuyv_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, - const float *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_yuyv_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_yuyv_fetch_rgba_float(float *dst, const uint8_t *src, - unsigned i, unsigned j); - - -void -util_format_r8g8_b8g8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_r8g8_b8g8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_r8g8_b8g8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, - const float *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_r8g8_b8g8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_r8g8_b8g8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, - unsigned i, unsigned j); - -void -util_format_g8r8_g8b8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_g8r8_g8b8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_g8r8_g8b8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, - const float *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_g8r8_g8b8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, - const uint8_t *src_row, unsigned src_stride, - unsigned width, unsigned height); - -void -util_format_g8r8_g8b8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, - unsigned i, unsigned j); - - - -#endif /* U_FORMAT_YUV_H_ */ +/************************************************************************** + * + * Copyright 2010 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 + * without limitation the rights to use, copy, modify, merge, publish, + * 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 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. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + + +/** + * @file + * YUV colorspace conversion. + * + * @author Brian Paul + * @author Michal Krol + * @author Jose Fonseca + * + * See also: + * - http://www.fourcc.org/fccyvrgb.php + * - http://msdn.microsoft.com/en-us/library/ms893078 + * - http://en.wikipedia.org/wiki/YUV + */ + + +#ifndef U_FORMAT_YUV_H_ +#define U_FORMAT_YUV_H_ + + +#include "pipe/p_compiler.h" +#include "u_math.h" + + +/* + * TODO: Ensure we use consistent and right floating formulas, with enough + * precision in the coefficients. + */ + +static INLINE void +util_format_rgb_float_to_yuv(float r, float g, float b, + uint8_t *y, uint8_t *u, uint8_t *v) +{ + const float _r = CLAMP(r, 0.0f, 1.0f); + const float _g = CLAMP(g, 0.0f, 1.0f); + const float _b = CLAMP(b, 0.0f, 1.0f); + + const float scale = 255.0f; + + const int _y = scale * ( (0.257f * _r) + (0.504f * _g) + (0.098f * _b)); + const int _u = scale * (-(0.148f * _r) - (0.291f * _g) + (0.439f * _b)); + const int _v = scale * ( (0.439f * _r) - (0.368f * _g) - (0.071f * _b)); + + *y = _y + 16; + *u = _u + 128; + *v = _v + 128; +} + + +static INLINE void +util_format_yuv_to_rgb_float(uint8_t y, uint8_t u, uint8_t v, + float *r, float *g, float *b) +{ + const int _y = y - 16; + const int _u = u - 128; + const int _v = v - 128; + + const float y_factor = 255.0f / 219.0f; + + const float scale = 1.0f / 255.0f; + + *r = scale * (y_factor * _y + 1.596f * _v); + *g = scale * (y_factor * _y - 0.391f * _u - 0.813f * _v); + *b = scale * (y_factor * _y + 2.018f * _u ); +} + + +static INLINE void +util_format_rgb_8unorm_to_yuv(uint8_t r, uint8_t g, uint8_t b, + uint8_t *y, uint8_t *u, uint8_t *v) +{ + *y = (( 66 * r + 129 * g + 25 * b + 128) >> 8) + 16; + *u = (( -38 * r - 74 * g + 112 * b + 128) >> 8) + 128; + *v = (( 112 * r - 94 * g - 18 * b + 128) >> 8) + 128; +} + + +static INLINE void +util_format_yuv_to_rgb_8unorm(uint8_t y, uint8_t u, uint8_t v, + uint8_t *r, uint8_t *g, uint8_t *b) +{ + const int _y = y - 16; + const int _u = u - 128; + const int _v = v - 128; + + const int _r = (298 * _y + 409 * _v + 128) >> 8; + const int _g = (298 * _y - 100 * _u - 208 * _v + 128) >> 8; + const int _b = (298 * _y + 516 * _u + 128) >> 8; + + *r = CLAMP(_r, 0, 255); + *g = CLAMP(_g, 0, 255); + *b = CLAMP(_b, 0, 255); +} + + + +void +util_format_uyvy_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_uyvy_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_uyvy_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_uyvy_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_uyvy_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + +void +util_format_yuyv_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_yuyv_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_yuyv_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_yuyv_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_yuyv_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + +/* XXX: Stubbed for now */ +void +util_format_yv12_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_yv12_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_yv12_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_yv12_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_yv12_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); +void +util_format_yv16_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_yv16_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_yv16_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_yv16_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_yv16_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); +void +util_format_iyuv_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_iyuv_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_iyuv_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_iyuv_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_iyuv_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); +void +util_format_nv12_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_nv12_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_nv12_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_nv12_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_nv12_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); +void +util_format_nv21_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_nv21_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_nv21_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_nv21_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_nv21_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); +void +util_format_ia44_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_ia44_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_ia44_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_ia44_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_ia44_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); +void +util_format_ai44_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_ai44_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_ai44_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_ai44_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_ai44_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + + +void +util_format_r8g8_b8g8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8_b8g8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8_b8g8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8_b8g8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8_b8g8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + +void +util_format_g8r8_g8b8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_g8r8_g8b8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_g8r8_g8b8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_g8r8_g8b8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_g8r8_g8b8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + + + +#endif /* U_FORMAT_YUV_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_upload_mgr.c b/mesalib/src/gallium/auxiliary/util/u_upload_mgr.c index e50db6d67..71fe53e3a 100644 --- a/mesalib/src/gallium/auxiliary/util/u_upload_mgr.c +++ b/mesalib/src/gallium/auxiliary/util/u_upload_mgr.c @@ -257,7 +257,7 @@ enum pipe_error u_upload_buffer( struct u_upload_mgr *upload, ret = u_upload_data( upload, min_out_offset, size, - map, + map + offset, out_offset, outbuf, flushed ); diff --git a/mesalib/src/gallium/auxiliary/util/u_video.h b/mesalib/src/gallium/auxiliary/util/u_video.h new file mode 100644 index 000000000..46da13610 --- /dev/null +++ b/mesalib/src/gallium/auxiliary/util/u_video.h @@ -0,0 +1,75 @@ +/************************************************************************** + * + * Copyright 2009 Younes Manton. + * 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 + * without limitation the rights to use, copy, modify, merge, publish, + * 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. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * 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. + * + **************************************************************************/ + +#ifndef U_VIDEO_H +#define U_VIDEO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* u_reduce_video_profile() needs these */ +#include +#include + +static INLINE enum pipe_video_codec +u_reduce_video_profile(enum pipe_video_profile profile) +{ + switch (profile) + { + case PIPE_VIDEO_PROFILE_MPEG1: + case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE: + case PIPE_VIDEO_PROFILE_MPEG2_MAIN: + return PIPE_VIDEO_CODEC_MPEG12; + + case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE: + case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE: + return PIPE_VIDEO_CODEC_MPEG4; + + case PIPE_VIDEO_PROFILE_VC1_SIMPLE: + case PIPE_VIDEO_PROFILE_VC1_MAIN: + case PIPE_VIDEO_PROFILE_VC1_ADVANCED: + return PIPE_VIDEO_CODEC_VC1; + + case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE: + case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN: + case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH: + return PIPE_VIDEO_CODEC_MPEG4_AVC; + + default: + assert(0); + return PIPE_VIDEO_CODEC_UNKNOWN; + } +} + +#ifdef __cplusplus +} +#endif + +#endif /* U_VIDEO_H */ diff --git a/mesalib/src/mesa/main/texfetch_tmp.h b/mesalib/src/mesa/main/texfetch_tmp.h index 3b1eedf39..d170adf2e 100644 --- a/mesalib/src/mesa/main/texfetch_tmp.h +++ b/mesalib/src/mesa/main/texfetch_tmp.h @@ -2287,7 +2287,8 @@ static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage, const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1); const GLfloat scale = 1.0F / (GLfloat) 0xffffff; texel[0] = ((*src) >> 8) * scale; - ASSERT(texImage->TexFormat == MESA_FORMAT_Z24_S8); + ASSERT(texImage->TexFormat == MESA_FORMAT_Z24_S8 || + texImage->TexFormat == MESA_FORMAT_Z24_X8); ASSERT(texel[0] >= 0.0F); ASSERT(texel[0] <= 1.0F); } @@ -2314,7 +2315,8 @@ static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage, const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1); const GLfloat scale = 1.0F / (GLfloat) 0xffffff; texel[0] = ((*src) & 0x00ffffff) * scale; - ASSERT(texImage->TexFormat == MESA_FORMAT_S8_Z24); + ASSERT(texImage->TexFormat == MESA_FORMAT_S8_Z24 || + texImage->TexFormat == MESA_FORMAT_X8_Z24); ASSERT(texel[0] >= 0.0F); ASSERT(texel[0] <= 1.0F); } diff --git a/mesalib/src/mesa/state_tracker/st_cb_condrender.c b/mesalib/src/mesa/state_tracker/st_cb_condrender.c index 64c6c117f..1ced560e1 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_condrender.c +++ b/mesalib/src/mesa/state_tracker/st_cb_condrender.c @@ -41,6 +41,7 @@ #include "st_context.h" #include "st_cb_queryobj.h" #include "st_cb_condrender.h" +#include "st_cb_bitmap.h" /** @@ -55,6 +56,8 @@ st_BeginConditionalRender(struct gl_context *ctx, struct gl_query_object *q, struct pipe_context *pipe = st->pipe; uint m; + st_flush_bitmap_cache(st); + switch (mode) { case GL_QUERY_WAIT: m = PIPE_RENDER_COND_WAIT; @@ -90,6 +93,8 @@ st_EndConditionalRender(struct gl_context *ctx, struct gl_query_object *q) struct pipe_context *pipe = st->pipe; (void) q; + st_flush_bitmap_cache(st); + pipe->render_condition(pipe, NULL, 0); st->render_condition = NULL; } diff --git a/mesalib/src/mesa/state_tracker/st_cb_queryobj.c b/mesalib/src/mesa/state_tracker/st_cb_queryobj.c index 1efcaf593..057499615 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_queryobj.c +++ b/mesalib/src/mesa/state_tracker/st_cb_queryobj.c @@ -1,179 +1,184 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 - * without limitation the rights to use, copy, modify, merge, publish, - * 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. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * 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. - * - **************************************************************************/ - - -/** - * glBegin/EndQuery interface to pipe - * - * \author Brian Paul - */ - - -#include "main/imports.h" -#include "main/context.h" -#include "main/mfeatures.h" - -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "st_context.h" -#include "st_cb_queryobj.h" - - -#if FEATURE_queryobj - -static struct gl_query_object * -st_NewQueryObject(struct gl_context *ctx, GLuint id) -{ - struct st_query_object *stq = ST_CALLOC_STRUCT(st_query_object); - if (stq) { - stq->base.Id = id; - stq->base.Ready = GL_TRUE; - stq->pq = NULL; - stq->type = PIPE_QUERY_TYPES; /* an invalid value */ - return &stq->base; - } - return NULL; -} - - - -static void -st_DeleteQuery(struct gl_context *ctx, struct gl_query_object *q) -{ - struct pipe_context *pipe = st_context(ctx)->pipe; - struct st_query_object *stq = st_query_object(q); - - if (stq->pq) { - pipe->destroy_query(pipe, stq->pq); - stq->pq = NULL; - } - - free(stq); -} - - -static void -st_BeginQuery(struct gl_context *ctx, struct gl_query_object *q) -{ - struct pipe_context *pipe = st_context(ctx)->pipe; - struct st_query_object *stq = st_query_object(q); - unsigned type; - - /* convert GL query type to Gallium query type */ - switch (q->Target) { - case GL_ANY_SAMPLES_PASSED: - /* fall-through */ - case GL_SAMPLES_PASSED_ARB: - type = PIPE_QUERY_OCCLUSION_COUNTER; - break; - case GL_PRIMITIVES_GENERATED: - type = PIPE_QUERY_PRIMITIVES_GENERATED; - break; - case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: - type = PIPE_QUERY_PRIMITIVES_EMITTED; - break; - case GL_TIME_ELAPSED_EXT: - type = PIPE_QUERY_TIME_ELAPSED; - break; - default: - assert(0 && "unexpected query target in st_BeginQuery()"); - return; - } - - if (stq->pq && stq->type != type) { - /* free old query of different type */ - pipe->destroy_query(pipe, stq->pq); - stq->pq = NULL; - stq->type = PIPE_QUERY_TYPES; /* an invalid value */ - } - - if (!stq->pq) { - stq->pq = pipe->create_query(pipe, type); - stq->type = type; - } - - assert(stq->type == type); - - pipe->begin_query(pipe, stq->pq); -} - - -static void -st_EndQuery(struct gl_context *ctx, struct gl_query_object *q) -{ - struct pipe_context *pipe = st_context(ctx)->pipe; - struct st_query_object *stq = st_query_object(q); - - pipe->end_query(pipe, stq->pq); -} - - -static void -st_WaitQuery(struct gl_context *ctx, struct gl_query_object *q) -{ - struct pipe_context *pipe = st_context(ctx)->pipe; - struct st_query_object *stq = st_query_object(q); - - /* this function should only be called if we don't have a ready result */ - assert(!stq->base.Ready); - - while (!stq->base.Ready && - !pipe->get_query_result(pipe, - stq->pq, - TRUE, - &q->Result)) - { - /* nothing */ - } - - q->Ready = GL_TRUE; -} - - -static void -st_CheckQuery(struct gl_context *ctx, struct gl_query_object *q) -{ - struct pipe_context *pipe = st_context(ctx)->pipe; - struct st_query_object *stq = st_query_object(q); - assert(!q->Ready); /* we should not get called if Ready is TRUE */ - q->Ready = pipe->get_query_result(pipe, stq->pq, FALSE, &q->Result); -} - - - - -void st_init_query_functions(struct dd_function_table *functions) -{ - functions->NewQueryObject = st_NewQueryObject; - functions->DeleteQuery = st_DeleteQuery; - functions->BeginQuery = st_BeginQuery; - functions->EndQuery = st_EndQuery; - functions->WaitQuery = st_WaitQuery; - functions->CheckQuery = st_CheckQuery; -} - -#endif /* FEATURE_queryobj */ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 + * without limitation the rights to use, copy, modify, merge, publish, + * 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. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * 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. + * + **************************************************************************/ + + +/** + * glBegin/EndQuery interface to pipe + * + * \author Brian Paul + */ + + +#include "main/imports.h" +#include "main/context.h" +#include "main/mfeatures.h" + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "st_context.h" +#include "st_cb_queryobj.h" +#include "st_cb_bitmap.h" + + +#if FEATURE_queryobj + +static struct gl_query_object * +st_NewQueryObject(struct gl_context *ctx, GLuint id) +{ + struct st_query_object *stq = ST_CALLOC_STRUCT(st_query_object); + if (stq) { + stq->base.Id = id; + stq->base.Ready = GL_TRUE; + stq->pq = NULL; + stq->type = PIPE_QUERY_TYPES; /* an invalid value */ + return &stq->base; + } + return NULL; +} + + + +static void +st_DeleteQuery(struct gl_context *ctx, struct gl_query_object *q) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_query_object *stq = st_query_object(q); + + if (stq->pq) { + pipe->destroy_query(pipe, stq->pq); + stq->pq = NULL; + } + + free(stq); +} + + +static void +st_BeginQuery(struct gl_context *ctx, struct gl_query_object *q) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_query_object *stq = st_query_object(q); + unsigned type; + + st_flush_bitmap_cache(st_context(ctx)); + + /* convert GL query type to Gallium query type */ + switch (q->Target) { + case GL_ANY_SAMPLES_PASSED: + /* fall-through */ + case GL_SAMPLES_PASSED_ARB: + type = PIPE_QUERY_OCCLUSION_COUNTER; + break; + case GL_PRIMITIVES_GENERATED: + type = PIPE_QUERY_PRIMITIVES_GENERATED; + break; + case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: + type = PIPE_QUERY_PRIMITIVES_EMITTED; + break; + case GL_TIME_ELAPSED_EXT: + type = PIPE_QUERY_TIME_ELAPSED; + break; + default: + assert(0 && "unexpected query target in st_BeginQuery()"); + return; + } + + if (stq->pq && stq->type != type) { + /* free old query of different type */ + pipe->destroy_query(pipe, stq->pq); + stq->pq = NULL; + stq->type = PIPE_QUERY_TYPES; /* an invalid value */ + } + + if (!stq->pq) { + stq->pq = pipe->create_query(pipe, type); + stq->type = type; + } + + assert(stq->type == type); + + pipe->begin_query(pipe, stq->pq); +} + + +static void +st_EndQuery(struct gl_context *ctx, struct gl_query_object *q) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_query_object *stq = st_query_object(q); + + st_flush_bitmap_cache(st_context(ctx)); + + pipe->end_query(pipe, stq->pq); +} + + +static void +st_WaitQuery(struct gl_context *ctx, struct gl_query_object *q) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_query_object *stq = st_query_object(q); + + /* this function should only be called if we don't have a ready result */ + assert(!stq->base.Ready); + + while (!stq->base.Ready && + !pipe->get_query_result(pipe, + stq->pq, + TRUE, + &q->Result)) + { + /* nothing */ + } + + q->Ready = GL_TRUE; +} + + +static void +st_CheckQuery(struct gl_context *ctx, struct gl_query_object *q) +{ + struct pipe_context *pipe = st_context(ctx)->pipe; + struct st_query_object *stq = st_query_object(q); + assert(!q->Ready); /* we should not get called if Ready is TRUE */ + q->Ready = pipe->get_query_result(pipe, stq->pq, FALSE, &q->Result); +} + + + + +void st_init_query_functions(struct dd_function_table *functions) +{ + functions->NewQueryObject = st_NewQueryObject; + functions->DeleteQuery = st_DeleteQuery; + functions->BeginQuery = st_BeginQuery; + functions->EndQuery = st_EndQuery; + functions->WaitQuery = st_WaitQuery; + functions->CheckQuery = st_CheckQuery; +} + +#endif /* FEATURE_queryobj */ diff --git a/mesalib/src/mesa/state_tracker/st_context.c b/mesalib/src/mesa/state_tracker/st_context.c index 6eddbfc88..6d4bc544d 100644 --- a/mesalib/src/mesa/state_tracker/st_context.c +++ b/mesalib/src/mesa/state_tracker/st_context.c @@ -179,6 +179,9 @@ struct st_context *st_create_context(gl_api api, struct pipe_context *pipe, st_init_driver_functions(&funcs); ctx = _mesa_create_context(api, visual, shareCtx, &funcs, NULL); + if (!ctx) { + return NULL; + } /* XXX: need a capability bit in gallium to query if the pipe * driver prefers DP4 or MUL/MAD for vertex transformation. diff --git a/xorg-server/glx/glxscreens.h b/xorg-server/glx/glxscreens.h index 0fb0fd17d..eb2926045 100644 --- a/xorg-server/glx/glxscreens.h +++ b/xorg-server/glx/glxscreens.h @@ -1,166 +1,165 @@ -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifndef _GLX_screens_h_ -#define _GLX_screens_h_ - -/* - * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) - * Copyright (C) 1991-2000 Silicon Graphics, 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 without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * 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 including the dates of first publication and - * either this permission notice or a reference to - * http://oss.sgi.com/projects/FreeB/ - * 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 NONINFRINGEMENT. IN NO EVENT SHALL - * SILICON GRAPHICS, INC. BE LIABLE FOR 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. - * - * Except as contained in this notice, the name of Silicon Graphics, Inc. - * shall not be used in advertising or otherwise to promote the sale, use or - * other dealings in this Software without prior written authorization from - * Silicon Graphics, Inc. - */ - -typedef struct __GLXconfig __GLXconfig; -struct __GLXconfig { - __GLXconfig *next; - GLuint doubleBufferMode; - GLuint stereoMode; - - GLint redBits, greenBits, blueBits, alphaBits; /* bits per comp */ - GLuint redMask, greenMask, blueMask, alphaMask; - GLint rgbBits; /* total bits for rgb */ - GLint indexBits; /* total bits for colorindex */ - - GLint accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits; - GLint depthBits; - GLint stencilBits; - - GLint numAuxBuffers; - - GLint level; - - GLint pixmapMode; - - /* GLX */ - GLint visualID; - GLint visualType; /**< One of the GLX X visual types. (i.e., - * \c GLX_TRUE_COLOR, etc.) - */ - - /* EXT_visual_rating / GLX 1.2 */ - GLint visualRating; - - /* EXT_visual_info / GLX 1.2 */ - GLint transparentPixel; - /* colors are floats scaled to ints */ - GLint transparentRed, transparentGreen, transparentBlue, transparentAlpha; - GLint transparentIndex; - - /* ARB_multisample / SGIS_multisample */ - GLint sampleBuffers; - GLint samples; - - /* SGIX_fbconfig / GLX 1.3 */ - GLint drawableType; - GLint renderType; - GLint xRenderable; - GLint fbconfigID; - - /* SGIX_pbuffer / GLX 1.3 */ - GLint maxPbufferWidth; - GLint maxPbufferHeight; - GLint maxPbufferPixels; - GLint optimalPbufferWidth; /* Only for SGIX_pbuffer. */ - GLint optimalPbufferHeight; /* Only for SGIX_pbuffer. */ - - /* SGIX_visual_select_group */ - GLint visualSelectGroup; - - /* OML_swap_method */ - GLint swapMethod; - - GLint screen; - - /* EXT_texture_from_pixmap */ - GLint bindToTextureRgb; - GLint bindToTextureRgba; - GLint bindToMipmapTexture; - GLint bindToTextureTargets; - GLint yInverted; -}; - -GLint glxConvertToXVisualType(int visualType); - -/* -** Screen dependent data. These methods are the interface between the DIX -** and DDX layers of the GLX server extension. The methods provide an -** interface for context management on a screen. -*/ -typedef struct __GLXscreen __GLXscreen; -struct __GLXscreen { - void (*destroy) (__GLXscreen *screen); - - __GLXcontext *(*createContext) (__GLXscreen *screen, - __GLXconfig *modes, - __GLXcontext *shareContext); - - __GLXdrawable *(*createDrawable)(ClientPtr client, - __GLXscreen *context, - DrawablePtr pDraw, - XID drawId, - int type, - XID glxDrawId, - __GLXconfig *modes); - int (*swapInterval) (__GLXdrawable *drawable, - int interval); - - ScreenPtr pScreen; - - /* Linked list of valid fbconfigs for this screen. */ - __GLXconfig *fbconfigs; - int numFBConfigs; - - /* Subset of fbconfigs that are exposed as GLX visuals. */ - __GLXconfig **visuals; - GLint numVisuals; - - char *GLextensions; - - char *GLXvendor; - char *GLXversion; - char *GLXextensions; - - /** - * \name GLX version supported by this screen. - * - * Since the GLX version advertised by the server is for the whole server, - * the GLX protocol code uses the minimum version supported on all screens. - */ - /*@{*/ - unsigned GLXmajor; - unsigned GLXminor; - /*@}*/ - - Bool (*CloseScreen)(int index, ScreenPtr pScreen); -}; - - -void __glXScreenInit(__GLXscreen *screen, ScreenPtr pScreen); -void __glXScreenDestroy(__GLXscreen *screen); - -#endif /* !__GLX_screens_h__ */ +#ifdef HAVE_DIX_CONFIG_H +#include +#endif + +#ifndef _GLX_screens_h_ +#define _GLX_screens_h_ + +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 NONINFRINGEMENT. IN NO EVENT SHALL + * SILICON GRAPHICS, INC. BE LIABLE FOR 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. + * + * Except as contained in this notice, the name of Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +typedef struct __GLXconfig __GLXconfig; +struct __GLXconfig { + __GLXconfig *next; + GLuint doubleBufferMode; + GLuint stereoMode; + + GLint redBits, greenBits, blueBits, alphaBits; /* bits per comp */ + GLuint redMask, greenMask, blueMask, alphaMask; + GLint rgbBits; /* total bits for rgb */ + GLint indexBits; /* total bits for colorindex */ + + GLint accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits; + GLint depthBits; + GLint stencilBits; + + GLint numAuxBuffers; + + GLint level; + + GLint pixmapMode; + + /* GLX */ + GLint visualID; + GLint visualType; /**< One of the GLX X visual types. (i.e., + * \c GLX_TRUE_COLOR, etc.) + */ + + /* EXT_visual_rating / GLX 1.2 */ + GLint visualRating; + + /* EXT_visual_info / GLX 1.2 */ + GLint transparentPixel; + /* colors are floats scaled to ints */ + GLint transparentRed, transparentGreen, transparentBlue, transparentAlpha; + GLint transparentIndex; + + /* ARB_multisample / SGIS_multisample */ + GLint sampleBuffers; + GLint samples; + + /* SGIX_fbconfig / GLX 1.3 */ + GLint drawableType; + GLint renderType; + GLint xRenderable; + GLint fbconfigID; + + /* SGIX_pbuffer / GLX 1.3 */ + GLint maxPbufferWidth; + GLint maxPbufferHeight; + GLint maxPbufferPixels; + GLint optimalPbufferWidth; /* Only for SGIX_pbuffer. */ + GLint optimalPbufferHeight; /* Only for SGIX_pbuffer. */ + + /* SGIX_visual_select_group */ + GLint visualSelectGroup; + + /* OML_swap_method */ + GLint swapMethod; + + GLint screen; + + /* EXT_texture_from_pixmap */ + GLint bindToTextureRgb; + GLint bindToTextureRgba; + GLint bindToMipmapTexture; + GLint bindToTextureTargets; + GLint yInverted; +}; + +GLint glxConvertToXVisualType(int visualType); + +/* +** Screen dependent data. These methods are the interface between the DIX +** and DDX layers of the GLX server extension. The methods provide an +** interface for context management on a screen. +*/ +typedef struct __GLXscreen __GLXscreen; +struct __GLXscreen { + void (*destroy) (__GLXscreen *screen); + + __GLXcontext *(*createContext) (__GLXscreen *screen, + __GLXconfig *modes, + __GLXcontext *shareContext); + + __GLXdrawable *(*createDrawable)(ClientPtr client, + __GLXscreen *context, + DrawablePtr pDraw, + XID drawId, + int type, + XID glxDrawId, + __GLXconfig *modes); + int (*swapInterval) (__GLXdrawable *drawable, + int interval); + + ScreenPtr pScreen; + + /* Linked list of valid fbconfigs for this screen. */ + __GLXconfig *fbconfigs; + int numFBConfigs; + + /* Subset of fbconfigs that are exposed as GLX visuals. */ + __GLXconfig **visuals; + GLint numVisuals; + + char *GLextensions; + + char *GLXvendor; + char *GLXextensions; + + /** + * \name GLX version supported by this screen. + * + * Since the GLX version advertised by the server is for the whole server, + * the GLX protocol code uses the minimum version supported on all screens. + */ + /*@{*/ + unsigned GLXmajor; + unsigned GLXminor; + /*@}*/ + + Bool (*CloseScreen)(int index, ScreenPtr pScreen); +}; + + +void __glXScreenInit(__GLXscreen *screen, ScreenPtr pScreen); +void __glXScreenDestroy(__GLXscreen *screen); + +#endif /* !__GLX_screens_h__ */ diff --git a/xorg-server/hw/dmx/glxProxy/glxscreens.h b/xorg-server/hw/dmx/glxProxy/glxscreens.h index a57c387fe..da50bdc85 100644 --- a/xorg-server/hw/dmx/glxProxy/glxscreens.h +++ b/xorg-server/hw/dmx/glxProxy/glxscreens.h @@ -43,7 +43,6 @@ typedef struct { GLint *isGLXvis; char *GLXvendor; - char *GLXversion; char *GLXextensions; } __GLXscreenInfo; diff --git a/xorg-server/hw/xquartz/GL/indirect.c b/xorg-server/hw/xquartz/GL/indirect.c index 41168729f..4876ab992 100644 --- a/xorg-server/hw/xquartz/GL/indirect.c +++ b/xorg-server/hw/xquartz/GL/indirect.c @@ -477,7 +477,8 @@ static __GLXscreen * __glXAquaScreenProbe(ScreenPtr pScreen) { __glXScreenInit(&screen->base, pScreen); - screen->base.GLXversion = strdup("1.4"); + screen->base.GLXmajor = 1; + screen->base.GLXminor = 4; screen->base.GLXextensions = strdup("GLX_SGIX_fbconfig " "GLX_SGIS_multisample " "GLX_ARB_multisample " diff --git a/xorg-server/hw/xwin/glx/Makefile.am b/xorg-server/hw/xwin/glx/Makefile.am index 61463f635..6b840bacb 100644 --- a/xorg-server/hw/xwin/glx/Makefile.am +++ b/xorg-server/hw/xwin/glx/Makefile.am @@ -1,40 +1,44 @@ -noinst_LTLIBRARIES = libXwinGLX.la - -libXwinGLX_la_SOURCES = \ - winpriv.c \ - winpriv.h \ - glwindows.h \ - glwrap.c \ - indirect.c \ - wgl_ext_api.c - -if XWIN_MULTIWINDOW -DEFS_MULTIWINDOW = -DXWIN_MULTIWINDOW -endif - -if XWIN_MULTIWINDOWEXTWM -DEFS_MULTIWINDOWEXTWM = -DXWIN_MULTIWINDOWEXTWM -endif - -DEFS = $(DEFS_MULTIWINDOW) $(DEFS_MULTIWINDOWEXTWM) - -INCLUDES = -I$(top_srcdir)/miext/rootless - -AM_CFLAGS = -DHAVE_XWIN_CONFIG_H $(DIX_CFLAGS) \ - $(XWINMODULES_CFLAGS) \ - -I$(top_srcdir) \ - -I$(top_srcdir)/hw/xwin/ - -if XWIN_GLX_WINDOWS - -generated_gl_wrappers.c: gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/gl.spec $(KHRONOS_SPEC_DIR)/gl.tm - $(srcdir)/gen_gl_wrappers.py --spec=$(KHRONOS_SPEC_DIR)/gl.spec --typemap=$(KHRONOS_SPEC_DIR)/gl.tm --dispatch-header=$(top_srcdir)/glx/dispatch.h --staticwrappers >generated_gl_wrappers.c - -generated_wgl_wrappers.c: gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/wglext.spec $(KHRONOS_SPEC_DIR)/wgl.tm - $(srcdir)/gen_gl_wrappers.py --spec=$(KHRONOS_SPEC_DIR)/wglext.spec --typemap=$(KHRONOS_SPEC_DIR)/wgl.tm --prefix=wgl --preresolve >generated_wgl_wrappers.c -endif - -BUILT_SOURCES = generated_gl_wrappers.c generated_wgl_wrappers.c -CLEANFILES = $(BUILT_SOURCES) - -EXTRA_DIST = gen_gl_wrappers.py +noinst_LTLIBRARIES = libXwinGLX.la + +libXwinGLX_la_SOURCES = \ + winpriv.c \ + winpriv.h \ + glwindows.h \ + glwrap.c \ + indirect.c \ + wgl_ext_api.c + +if XWIN_MULTIWINDOW +DEFS_MULTIWINDOW = -DXWIN_MULTIWINDOW +endif + +if XWIN_MULTIWINDOWEXTWM +DEFS_MULTIWINDOWEXTWM = -DXWIN_MULTIWINDOWEXTWM +endif + +if XWIN_GLX_WINDOWS +DEFS_GLX_WINDOWS = -DXWIN_GLX_WINDOWS +endif + +DEFS = $(DEFS_MULTIWINDOW) $(DEFS_MULTIWINDOWEXTWM) $(DEFS_GLX_WINDOWS) + +INCLUDES = -I$(top_srcdir)/miext/rootless + +AM_CFLAGS = -DHAVE_XWIN_CONFIG_H $(DIX_CFLAGS) \ + $(XWINMODULES_CFLAGS) \ + -I$(top_srcdir) \ + -I$(top_srcdir)/hw/xwin/ + +if XWIN_GLX_WINDOWS + +generated_gl_wrappers.c: gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/gl.spec $(KHRONOS_SPEC_DIR)/gl.tm + $(srcdir)/gen_gl_wrappers.py --spec=$(KHRONOS_SPEC_DIR)/gl.spec --typemap=$(KHRONOS_SPEC_DIR)/gl.tm --dispatch-header=$(top_srcdir)/glx/dispatch.h --staticwrappers >generated_gl_wrappers.c + +generated_wgl_wrappers.c: gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/wglext.spec $(KHRONOS_SPEC_DIR)/wgl.tm + $(srcdir)/gen_gl_wrappers.py --spec=$(KHRONOS_SPEC_DIR)/wglext.spec --typemap=$(KHRONOS_SPEC_DIR)/wgl.tm --prefix=wgl --preresolve >generated_wgl_wrappers.c +endif + +BUILT_SOURCES = generated_gl_wrappers.c generated_wgl_wrappers.c +CLEANFILES = $(BUILT_SOURCES) + +EXTRA_DIST = gen_gl_wrappers.py diff --git a/xorg-server/hw/xwin/glx/gen_gl_wrappers.py b/xorg-server/hw/xwin/glx/gen_gl_wrappers.py index d7fe98dec..e2d960ec6 100644 --- a/xorg-server/hw/xwin/glx/gen_gl_wrappers.py +++ b/xorg-server/hw/xwin/glx/gen_gl_wrappers.py @@ -312,7 +312,7 @@ if dispatchheader : for d in sorted(dispatch.keys()) : if wrappers.has_key(d) : - print ' SET_'+ d + '(disp, ' + prefix + d + 'Wrapper);' + print ' SET_'+ d + '(disp, (void *)' + prefix + d + 'Wrapper);' else : print '#warning No wrapper for ' + prefix + d + ' !' diff --git a/xorg-server/hw/xwin/glx/indirect.c b/xorg-server/hw/xwin/glx/indirect.c index 357029aa9..86fef55d1 100644 --- a/xorg-server/hw/xwin/glx/indirect.c +++ b/xorg-server/hw/xwin/glx/indirect.c @@ -1,2304 +1,2354 @@ -/* - * File: indirect.c - * Purpose: A GLX implementation that uses Windows OpenGL library - * - * Authors: Alexander Gottwald - * Jon TURNEY - * - * Copyright (c) Jon TURNEY 2009 - * Copyright (c) Alexander Gottwald 2004 - * - * Portions of this file are copied from GL/apple/indirect.c, - * which contains the following copyright: - * - * Copyright (c) 2007, 2008, 2009 Apple Inc. - * Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved. - * Copyright (c) 2002 Greg Parker. All Rights Reserved. - * - * Portions of this file are copied from Mesa's xf86glx.c, - * which contains the following copyright: - * - * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. - * 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 without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL - * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR 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. - */ - -/* - TODO: - - hook up remaining unimplemented extensions - - research what guarantees glXWaitX, glXWaitGL are supposed to offer, and implement then - using GdiFlush and/or glFinish - - pbuffer clobbering: we don't get async notification, but can we arrange to emit the - event when we notice it's been clobbered? at the very least, check if it's been clobbered - before using it? - - are the __GLXConfig * we get handed back ones we are made (so we can extend the structure - with privates?) Or are they created inside the GLX core as well? -*/ - -/* - MSDN clarifications: - - It says SetPixelFormat()'s PIXELFORMATDESCRIPTOR pointer argument has no effect - except on metafiles, this seems to mean that as it's ok to supply NULL if the DC - is not for a metafile - - wglMakeCurrent ignores the hdc if hglrc is NULL, so wglMakeCurrent(NULL, NULL) - is used to make no context current - -*/ - -#ifdef HAVE_XWIN_CONFIG_H -#include -#endif - -#include "glwindows.h" -#include -#include -#include -#include - -#include -#include - -#define NUM_ELEMENTS(x) (sizeof(x)/ sizeof(x[1])) - -/* ---------------------------------------------------------------------- */ -/* - * structure definitions - */ - -typedef struct __GLXWinContext __GLXWinContext; -typedef struct __GLXWinDrawable __GLXWinDrawable; -typedef struct __GLXWinScreen glxWinScreen; -typedef struct __GLXWinConfig GLXWinConfig; - -struct __GLXWinContext { - __GLXcontext base; - HGLRC ctx; /* Windows GL Context */ - __GLXWinContext *shareContext; /* Context with which we will share display lists and textures */ - HWND hwnd; /* For detecting when HWND has changed */ -}; - -struct __GLXWinDrawable -{ - __GLXdrawable base; - __GLXWinContext *drawContext; - __GLXWinContext *readContext; - - /* If this drawable is GLX_DRAWABLE_PBUFFER */ - HPBUFFERARB hPbuffer; - - /* If this drawable is GLX_DRAWABLE_PIXMAP */ - HDC dibDC; - HBITMAP hDIB; - HBITMAP hOldDIB; /* original DIB for DC */ - void *pOldBits; /* original pBits for this drawable's pixmap */ -}; - -struct __GLXWinScreen -{ - __GLXscreen base; - - /* Supported GLX extensions */ - unsigned char glx_enable_bits[__GLX_EXT_BYTES]; - - Bool has_WGL_ARB_multisample; - Bool has_WGL_ARB_pixel_format; - Bool has_WGL_ARB_pbuffer; - Bool has_WGL_ARB_render_texture; - - /* wrapped screen functions */ - RealizeWindowProcPtr RealizeWindow; - UnrealizeWindowProcPtr UnrealizeWindow; - CopyWindowProcPtr CopyWindow; -}; - -struct __GLXWinConfig -{ - __GLXconfig base; - int pixelFormatIndex; -}; - -/* ---------------------------------------------------------------------- */ -/* - * Various debug helpers - */ - -#define GLWIN_DEBUG_HWND(hwnd) \ - if (glxWinDebugSettings.dumpHWND) { \ - char buffer[1024]; \ - if (GetWindowText(hwnd, buffer, sizeof(buffer))==0) *buffer=0; \ - GLWIN_DEBUG_MSG("Got HWND %p for window '%s'", hwnd, buffer); \ - } - -glxWinDebugSettingsRec glxWinDebugSettings = { 0, 0, 0, 0, 0, 0}; - -static void glxWinInitDebugSettings(void) -{ - char *envptr; - - envptr = getenv("GLWIN_ENABLE_DEBUG"); - if (envptr != NULL) - glxWinDebugSettings.enableDebug = (atoi(envptr) == 1); - - envptr = getenv("GLWIN_ENABLE_TRACE"); - if (envptr != NULL) - glxWinDebugSettings.enableTrace = (atoi(envptr) == 1); - - envptr = getenv("GLWIN_DUMP_PFD"); - if (envptr != NULL) - glxWinDebugSettings.dumpPFD = (atoi(envptr) == 1); - - envptr = getenv("GLWIN_DUMP_HWND"); - if (envptr != NULL) - glxWinDebugSettings.dumpHWND = (atoi(envptr) == 1); - - envptr = getenv("GLWIN_DUMP_DC"); - if (envptr != NULL) - glxWinDebugSettings.dumpDC = (atoi(envptr) == 1); - - envptr = getenv("GLWIN_ENABLE_GLCALL_TRACE"); - if (envptr != NULL) - glxWinDebugSettings.enableGLcallTrace = (atoi(envptr) == 1); - - envptr = getenv("GLWIN_ENABLE_WGLCALL_TRACE"); - if (envptr != NULL) - glxWinDebugSettings.enableWGLcallTrace = (atoi(envptr) == 1); - - envptr = getenv("GLWIN_DEBUG_ALL"); - if (envptr != NULL) - { - glxWinDebugSettings.enableDebug = 1; - glxWinDebugSettings.enableTrace = 1; - glxWinDebugSettings.dumpPFD = 1; - glxWinDebugSettings.dumpHWND = 1; - glxWinDebugSettings.dumpDC = 1; - glxWinDebugSettings.enableGLcallTrace = 1; - glxWinDebugSettings.enableWGLcallTrace = 1; - } -} - -static -const char *glxWinErrorMessage(void) -{ - static char errorbuffer[1024]; - - if (!FormatMessage( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &errorbuffer, - sizeof(errorbuffer), - NULL )) - { - snprintf(errorbuffer, sizeof(errorbuffer), "Unknown error in FormatMessage: %08x!", (unsigned)GetLastError()); - } - - if (errorbuffer[strlen(errorbuffer)-1] == '\n') - errorbuffer[strlen(errorbuffer)-1] = 0; - - return errorbuffer; -} - -static void pfdOut(const PIXELFORMATDESCRIPTOR *pfd); - -#define DUMP_PFD_FLAG(flag) \ - if (pfd->dwFlags & flag) { \ - ErrorF("%s%s", pipesym, #flag); \ - pipesym = " | "; \ - } - -static void pfdOut(const PIXELFORMATDESCRIPTOR *pfd) -{ - const char *pipesym = ""; /* will be set after first flag dump */ - ErrorF("PIXELFORMATDESCRIPTOR:\n"); - ErrorF("nSize = %u\n", pfd->nSize); - ErrorF("nVersion = %u\n", pfd->nVersion); - ErrorF("dwFlags = %lu = {", pfd->dwFlags); - DUMP_PFD_FLAG(PFD_DOUBLEBUFFER); - DUMP_PFD_FLAG(PFD_STEREO); - DUMP_PFD_FLAG(PFD_DRAW_TO_WINDOW); - DUMP_PFD_FLAG(PFD_DRAW_TO_BITMAP); - DUMP_PFD_FLAG(PFD_SUPPORT_GDI); - DUMP_PFD_FLAG(PFD_SUPPORT_OPENGL); - DUMP_PFD_FLAG(PFD_GENERIC_FORMAT); - DUMP_PFD_FLAG(PFD_NEED_PALETTE); - DUMP_PFD_FLAG(PFD_NEED_SYSTEM_PALETTE); - DUMP_PFD_FLAG(PFD_SWAP_EXCHANGE); - DUMP_PFD_FLAG(PFD_SWAP_COPY); - DUMP_PFD_FLAG(PFD_SWAP_LAYER_BUFFERS); - DUMP_PFD_FLAG(PFD_GENERIC_ACCELERATED); - DUMP_PFD_FLAG(PFD_DEPTH_DONTCARE); - DUMP_PFD_FLAG(PFD_DOUBLEBUFFER_DONTCARE); - DUMP_PFD_FLAG(PFD_STEREO_DONTCARE); - ErrorF("}\n"); - - ErrorF("iPixelType = %hu = %s\n", pfd->iPixelType, - (pfd->iPixelType == PFD_TYPE_RGBA ? "PFD_TYPE_RGBA" : "PFD_TYPE_COLORINDEX")); - ErrorF("cColorBits = %hhu\n", pfd->cColorBits); - ErrorF("cRedBits = %hhu\n", pfd->cRedBits); - ErrorF("cRedShift = %hhu\n", pfd->cRedShift); - ErrorF("cGreenBits = %hhu\n", pfd->cGreenBits); - ErrorF("cGreenShift = %hhu\n", pfd->cGreenShift); - ErrorF("cBlueBits = %hhu\n", pfd->cBlueBits); - ErrorF("cBlueShift = %hhu\n", pfd->cBlueShift); - ErrorF("cAlphaBits = %hhu\n", pfd->cAlphaBits); - ErrorF("cAlphaShift = %hhu\n", pfd->cAlphaShift); - ErrorF("cAccumBits = %hhu\n", pfd->cAccumBits); - ErrorF("cAccumRedBits = %hhu\n", pfd->cAccumRedBits); - ErrorF("cAccumGreenBits = %hhu\n", pfd->cAccumGreenBits); - ErrorF("cAccumBlueBits = %hhu\n", pfd->cAccumBlueBits); - ErrorF("cAccumAlphaBits = %hhu\n", pfd->cAccumAlphaBits); - ErrorF("cDepthBits = %hhu\n", pfd->cDepthBits); - ErrorF("cStencilBits = %hhu\n", pfd->cStencilBits); - ErrorF("cAuxBuffers = %hhu\n", pfd->cAuxBuffers); - ErrorF("iLayerType = %hhu\n", pfd->iLayerType); - ErrorF("bReserved = %hhu\n", pfd->bReserved); - ErrorF("dwLayerMask = %lu\n", pfd->dwLayerMask); - ErrorF("dwVisibleMask = %lu\n", pfd->dwVisibleMask); - ErrorF("dwDamageMask = %lu\n", pfd->dwDamageMask); - ErrorF("\n"); -} - -static const char * -visual_class_name(int cls) -{ - switch (cls) { - case GLX_STATIC_COLOR: - return "StaticColor"; - case GLX_PSEUDO_COLOR: - return "PseudoColor"; - case GLX_STATIC_GRAY: - return "StaticGray"; - case GLX_GRAY_SCALE: - return "GrayScale"; - case GLX_TRUE_COLOR: - return "TrueColor"; - case GLX_DIRECT_COLOR: - return "DirectColor"; - default: - return "-none-"; - } -} - -static const char * -swap_method_name(int mthd) -{ - switch (mthd) - { - case GLX_SWAP_EXCHANGE_OML: - return "xchg"; - case GLX_SWAP_COPY_OML: - return "copy"; - case GLX_SWAP_UNDEFINED_OML: - return " "; - default: - return "????"; - } -} - -static void -fbConfigsDump(unsigned int n, __GLXconfig *c) -{ - ErrorF("%d fbConfigs\n", n); - ErrorF("pxf vis fb render Ste aux accum MS drawable Group/\n"); - ErrorF("idx ID ID VisualType Depth Lvl RGB CI DB Swap reo R G B A Z S buf AR AG AB AA bufs num W P Pb Float Trans Caveat\n"); - ErrorF("-----------------------------------------------------------------------------------------------------------------------------\n"); - - while (c != NULL) - { - unsigned int i = ((GLXWinConfig *)c)->pixelFormatIndex; - - ErrorF("%3d %2x %2x " - "%-11s" - " %3d %3d %s %s %s %s %s " - "%2d %2d %2d %2d " - "%2d %2d " - "%2d " - "%2d %2d %2d %2d" - " %2d %2d" - " %s %s %s " - " %s " - " %s " - " %d %s" - "\n", - i, c->visualID, c->fbconfigID, - visual_class_name(c->visualType), - c->rgbBits ? c->rgbBits : c->indexBits, - c->level, - (c->renderType & GLX_RGBA_BIT) ? "y" : ".", - (c->renderType & GLX_COLOR_INDEX_BIT) ? "y" : ".", - c->doubleBufferMode ? "y" : ".", - swap_method_name(c->swapMethod), - c->stereoMode ? "y" : ".", - c->redBits, c->greenBits, c->blueBits, c->alphaBits, - c->depthBits, c->stencilBits, - c->numAuxBuffers, - c->accumRedBits, c->accumGreenBits, c->accumBlueBits, c->accumAlphaBits, - c->sampleBuffers, c->samples, - (c->drawableType & GLX_WINDOW_BIT) ? "y" : ".", - (c->drawableType & GLX_PIXMAP_BIT) ? "y" : ".", - (c->drawableType & GLX_PBUFFER_BIT) ? "y" : ".", - ".", - (c->transparentPixel != GLX_NONE_EXT) ? "y" : ".", - c->visualSelectGroup, (c->visualRating == GLX_SLOW_VISUAL_EXT) ? "*" : " "); - - c = c->next; - } -} - -/* ---------------------------------------------------------------------- */ -/* - * Forward declarations - */ - -static __GLXscreen *glxWinScreenProbe(ScreenPtr pScreen); -static __GLXcontext *glxWinCreateContext(__GLXscreen *screen, - __GLXconfig *modes, - __GLXcontext *baseShareContext); -static __GLXdrawable *glxWinCreateDrawable(ClientPtr client, - __GLXscreen *screen, - DrawablePtr pDraw, - XID drawId, - int type, - XID glxDrawId, - __GLXconfig *conf); - -static Bool glxWinRealizeWindow(WindowPtr pWin); -static Bool glxWinUnrealizeWindow(WindowPtr pWin); -static void glxWinCopyWindow(WindowPtr pWindow, DDXPointRec ptOldOrg, RegionPtr prgnSrc); - -static HDC glxWinMakeDC(__GLXWinContext *gc, __GLXWinDrawable *draw, HDC *hdc, HWND *hwnd); -static void glxWinReleaseDC(HWND hwnd, HDC hdc, __GLXWinDrawable *draw); - -static void glxWinCreateConfigs(HDC dc, glxWinScreen *screen); -static void glxWinCreateConfigsExt(HDC hdc, glxWinScreen *screen); -static int fbConfigToPixelFormat(__GLXconfig *mode, PIXELFORMATDESCRIPTOR *pfdret, int drawableTypeOverride); -static int fbConfigToPixelFormatIndex(HDC hdc, __GLXconfig *mode, int drawableTypeOverride, glxWinScreen *winScreen); - -/* ---------------------------------------------------------------------- */ -/* - * The GLX provider - */ - -__GLXprovider __glXWGLProvider = { - glxWinScreenProbe, - "Win32 native WGL", - NULL -}; - -void -glxWinPushNativeProvider(void) -{ - GlxPushProvider(&__glXWGLProvider); -} - -/* ---------------------------------------------------------------------- */ -/* - * Screen functions - */ - -static void -glxWinScreenDestroy(__GLXscreen *screen) -{ - GLWIN_DEBUG_MSG("glxWinScreenDestroy(%p)", screen); - __glXScreenDestroy(screen); - free(screen); -} - -static int -glxWinScreenSwapInterval(__GLXdrawable *drawable, int interval) -{ - BOOL ret = wglSwapIntervalEXTWrapper(interval); - if (!ret) - { - ErrorF("wglSwapIntervalEXT interval %d failed:%s\n", interval, glxWinErrorMessage()); - } - return ret; -} - -/* - Report the extensions split and formatted to avoid overflowing a line - */ -static void -glxLogExtensions(const char *prefix, const char *extensions) -{ - int length = 0; - char *strl; - char *str = strdup(extensions); - - if (str == NULL) - { - ErrorF("glxLogExtensions: xalloc error\n"); - return; - } - - strl = strtok(str, " "); - ErrorF("%s%s", prefix, strl); - length = strlen(prefix) + strlen(strl); - - while (1) - { - strl = strtok(NULL, " "); - if (strl == NULL) break; - - if (length + strlen(strl) + 1 > 120) - { - ErrorF("\n"); - ErrorF("%s",prefix); - length = strlen(prefix); - } - else - { - ErrorF(" "); - length++; - } - - ErrorF("%s", strl); - length = length + strlen(strl); - } - - ErrorF("\n"); - - free(str); -} - -/* This is called by GlxExtensionInit() asking the GLX provider if it can handle the screen... */ -static __GLXscreen * -glxWinScreenProbe(ScreenPtr pScreen) -{ - glxWinScreen *screen; - const char *gl_extensions; - const char *wgl_extensions; - HWND hwnd; - HDC hdc; - HGLRC hglrc; - - GLWIN_DEBUG_MSG("glxWinScreenProbe"); - - glxWinInitDebugSettings(); - - if (pScreen == NULL) - return NULL; - - if (!winCheckScreenAiglxIsSupported(pScreen)) - { - LogMessage(X_ERROR,"AIGLX: No native OpenGL in modes with a root window\n"); - return NULL; - } - - screen = calloc(1, sizeof(glxWinScreen)); - - if (NULL == screen) - return NULL; - - /* Wrap RealizeWindow, UnrealizeWindow and CopyWindow on this screen */ - screen->RealizeWindow = pScreen->RealizeWindow; - pScreen->RealizeWindow = glxWinRealizeWindow; - screen->UnrealizeWindow = pScreen->UnrealizeWindow; - pScreen->UnrealizeWindow = glxWinUnrealizeWindow; - screen->CopyWindow = pScreen->CopyWindow; - pScreen->CopyWindow = glxWinCopyWindow; - - /* Dump out some useful information about the native renderer */ - - // create window class -#define WIN_GL_TEST_WINDOW_CLASS "XWinGLTest" - { - static wATOM glTestWndClass = 0; - if (glTestWndClass == 0) - { - WNDCLASSEX wc; - wc.cbSize = sizeof(WNDCLASSEX); - wc.style = CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = DefWindowProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = GetModuleHandle(NULL); - wc.hIcon = 0; - wc.hCursor = 0; - wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); - wc.lpszMenuName = NULL; - wc.lpszClassName = WIN_GL_TEST_WINDOW_CLASS; - wc.hIconSm = 0; - RegisterClassEx (&wc); - } - } - - // create an invisible window for a scratch DC - hwnd = CreateWindowExA(0, - WIN_GL_TEST_WINDOW_CLASS, - "XWin GL Renderer Capabilities Test Window", - 0, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL); - if (hwnd == NULL) - LogMessage(X_ERROR,"AIGLX: Couldn't create a window for render capabilities testing\n"); - - hdc = GetDC(hwnd); - - // we must set a pixel format before we can create a context, just use the first one... - SetPixelFormat(hdc, 1, NULL); - hglrc = wglCreateContext(hdc); - wglMakeCurrent(hdc, hglrc); - - // initialize wgl extension proc pointers (don't call them before here...) - // (but we need to have a current context for them to be resolvable) - wglResolveExtensionProcs(); - - ErrorF("GL_VERSION: %s\n", glGetStringWrapperNonstatic(GL_VERSION)); - ErrorF("GL_VENDOR: %s\n", glGetStringWrapperNonstatic(GL_VENDOR)); - ErrorF("GL_RENDERER: %s\n", glGetStringWrapperNonstatic(GL_RENDERER)); - gl_extensions = (const char *)glGetStringWrapperNonstatic(GL_EXTENSIONS); - glxLogExtensions("GL_EXTENSIONS: ", gl_extensions); - wgl_extensions = wglGetExtensionsStringARBWrapper(hdc); - if (!wgl_extensions) wgl_extensions = ""; - glxLogExtensions("WGL_EXTENSIONS: ", wgl_extensions); - - // Can you see the problem here? The extensions string is DC specific - // Different DCs for windows on a multimonitor system driven by multiple cards - // might have completely different capabilities. Of course, good luck getting - // those screens to be accelerated in XP and earlier... - - { - // testing facility to not use any WGL extensions - char *envptr = getenv("GLWIN_NO_WGL_EXTENSIONS"); - if ((envptr != NULL) && (atoi(envptr) != 0)) - { - ErrorF("GLWIN_NO_WGL_EXTENSIONS is set, ignoring WGL_EXTENSIONS\n"); - wgl_extensions = ""; - } - } - - { - Bool glx_sgi_make_current_read = FALSE; - - // - // Based on the WGL extensions available, enable various GLX extensions - // XXX: make this table-driven ? - // - memset(screen->glx_enable_bits, 0, __GLX_EXT_BYTES); - - __glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_visual_info"); - __glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_visual_rating"); - __glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_import_context"); - __glXEnableExtension(screen->glx_enable_bits, "GLX_OML_swap_method"); - __glXEnableExtension(screen->glx_enable_bits, "GLX_SGIX_fbconfig"); - - if (strstr(wgl_extensions, "WGL_ARB_make_current_read")) - { - __glXEnableExtension(screen->glx_enable_bits, "GLX_SGI_make_current_read"); - LogMessage(X_INFO, "AIGLX: enabled GLX_SGI_make_current_read\n"); - glx_sgi_make_current_read = TRUE; - } - - if (strstr(gl_extensions, "GL_WIN_swap_hint")) - { - __glXEnableExtension(screen->glx_enable_bits, "GLX_MESA_copy_sub_buffer"); - LogMessage(X_INFO, "AIGLX: enabled GLX_MESA_copy_sub_buffer\n"); - } - - if (strstr(wgl_extensions, "WGL_EXT_swap_control")) - { - __glXEnableExtension(screen->glx_enable_bits, "GLX_SGI_swap_control"); - __glXEnableExtension(screen->glx_enable_bits, "GLX_MESA_swap_control"); - LogMessage(X_INFO, "AIGLX: enabled GLX_SGI_swap_control and GLX_MESA_swap_control\n"); - } - -/* // Hmm? screen->texOffset */ -/* if (strstr(wgl_extensions, "WGL_ARB_render_texture")) */ -/* { */ -/* __glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_texture_from_pixmap"); */ -/* LogMessage(X_INFO, "AIGLX: GLX_EXT_texture_from_pixmap backed by buffer objects\n"); */ -/* screen->has_WGL_ARB_render_texture = TRUE; */ -/* } */ - - if (strstr(wgl_extensions, "WGL_ARB_pbuffer")) - { - __glXEnableExtension(screen->glx_enable_bits, "GLX_SGIX_pbuffer"); - LogMessage(X_INFO, "AIGLX: enabled GLX_SGIX_pbuffer\n"); - screen->has_WGL_ARB_pbuffer = TRUE; - } - - if (strstr(wgl_extensions, "WGL_ARB_multisample")) - { - __glXEnableExtension(screen->glx_enable_bits, "GLX_ARB_multisample"); - __glXEnableExtension(screen->glx_enable_bits, "GLX_SGIS_multisample"); - LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_multisample and GLX_SGIS_multisample\n"); - screen->has_WGL_ARB_multisample = TRUE; - } - - screen->base.destroy = glxWinScreenDestroy; - screen->base.createContext = glxWinCreateContext; - screen->base.createDrawable = glxWinCreateDrawable; - screen->base.swapInterval = glxWinScreenSwapInterval; - screen->base.pScreen = pScreen; - - if (strstr(wgl_extensions, "WGL_ARB_pixel_format")) - { - glxWinCreateConfigsExt(hdc, screen); - screen->has_WGL_ARB_pixel_format = TRUE; - } - else - { - glxWinCreateConfigs(hdc, screen); - screen->has_WGL_ARB_pixel_format = FALSE; - } - // Initializes screen->base.fbconfigs and screen->base.numFBConfigs - - /* These will be set by __glXScreenInit */ - screen->base.visuals = NULL; - screen->base.numVisuals = 0; - - __glXScreenInit(&screen->base, pScreen); - - // dump out fbConfigs now fbConfigIds and visualIDs have been assigned - fbConfigsDump(screen->base.numFBConfigs, screen->base.fbconfigs); - - // Override the GL extensions string set by __glXScreenInit() - screen->base.GLextensions = strdup(gl_extensions); - - // Generate the GLX extensions string (overrides that set by __glXScreenInit()) - { - unsigned int buffer_size = __glXGetExtensionString(screen->glx_enable_bits, NULL); - if (buffer_size > 0) - { - free(screen->base.GLXextensions); - - screen->base.GLXextensions = xnfalloc(buffer_size); - __glXGetExtensionString(screen->glx_enable_bits, screen->base.GLXextensions); - } - } - - // - // Override the GLX version (__glXScreenInit() sets it to "1.2") - // if we have all the needed extensionsto operate as a higher version - // - // SGIX_fbconfig && SGIX_pbuffer && SGI_make_current_read -> 1.3 - // ARB_multisample -> 1.4 - // - if (screen->has_WGL_ARB_pbuffer && glx_sgi_make_current_read) - { - free(screen->base.GLXversion); - - if (screen->has_WGL_ARB_multisample) - { - screen->base.GLXversion = strdup("1.4"); - screen->base.GLXmajor = 1; - screen->base.GLXminor = 4; - } - else - { - screen->base.GLXversion = strdup("1.3"); - screen->base.GLXmajor = 1; - screen->base.GLXminor = 3; - } - LogMessage(X_INFO, "AIGLX: Set GLX version to %s\n", screen->base.GLXversion); - } - } - - wglMakeCurrent(NULL, NULL); - wglDeleteContext(hglrc); - ReleaseDC(hwnd, hdc); - DestroyWindow(hwnd); - - return &screen->base; -} - -/* ---------------------------------------------------------------------- */ -/* - * Window functions - */ - -static Bool -glxWinRealizeWindow(WindowPtr pWin) -{ - Bool result; - ScreenPtr pScreen = pWin->drawable.pScreen; - glxWinScreen *screenPriv = (glxWinScreen *) glxGetScreen(pScreen); - - GLWIN_DEBUG_MSG("glxWinRealizeWindow"); - - /* Allow the window to be created (RootlessRealizeWindow is inside our wrap) */ - pScreen->RealizeWindow = screenPriv->RealizeWindow; - result = pScreen->RealizeWindow(pWin); - pScreen->RealizeWindow = glxWinRealizeWindow; - - return result; -} - - -static void -glxWinCopyWindow(WindowPtr pWindow, DDXPointRec ptOldOrg, RegionPtr prgnSrc) -{ - __GLXWinDrawable *pGlxDraw; - ScreenPtr pScreen = pWindow->drawable.pScreen; - glxWinScreen *screenPriv = (glxWinScreen *) glxGetScreen(pScreen); - - GLWIN_TRACE_MSG("glxWinCopyWindow pWindow %p", pWindow); - - dixLookupResourceByType((pointer) &pGlxDraw, pWindow->drawable.id, __glXDrawableRes, - NullClient, DixUnknownAccess); - - - /* - Discard any CopyWindow requests if a GL drawing context is pointing at the window - - For regions which are being drawn by GL, the shadow framebuffer doesn't have the - correct bits, so we wish to avoid shadow framebuffer damage occuring, which will - cause those incorrect bits to be transferred to the display.... - */ - if (pGlxDraw && pGlxDraw->drawContext) - { - GLWIN_DEBUG_MSG("glxWinCopyWindow: discarding"); - return; - } - - GLWIN_DEBUG_MSG("glxWinCopyWindow - passing to hw layer"); - - pScreen->CopyWindow = screenPriv->CopyWindow; - pScreen->CopyWindow(pWindow, ptOldOrg, prgnSrc); - pScreen->CopyWindow = glxWinCopyWindow; -} - -static Bool -glxWinUnrealizeWindow(WindowPtr pWin) -{ - Bool result; - ScreenPtr pScreen = pWin->drawable.pScreen; - glxWinScreen *screenPriv = (glxWinScreen *)glxGetScreen(pScreen); - - GLWIN_DEBUG_MSG("glxWinUnrealizeWindow"); - - pScreen->UnrealizeWindow = screenPriv->UnrealizeWindow; - result = pScreen->UnrealizeWindow(pWin); - pScreen->UnrealizeWindow = glxWinUnrealizeWindow; - - return result; -} - -/* ---------------------------------------------------------------------- */ -/* - * Drawable functions - */ - -static GLboolean -glxWinDrawableSwapBuffers(ClientPtr client, __GLXdrawable *base) -{ - HDC dc; - HWND hwnd; - BOOL ret; - __GLXWinDrawable *draw = (__GLXWinDrawable *)base; - - /* Swap buffers on the last active context for drawing on the drawable */ - if (draw->drawContext == NULL) - { - GLWIN_TRACE_MSG("glxWinSwapBuffers - no context for drawable"); - return GL_FALSE; - } - - GLWIN_TRACE_MSG("glxWinSwapBuffers on drawable %p, last context %p (native ctx %p)", base, draw->drawContext, draw->drawContext->ctx); - - /* - draw->drawContext->base.drawPriv will not be set if the context is not current anymore, - but if it is, it should point to this drawable.... - */ - assert((draw->drawContext->base.drawPriv == NULL) || (draw->drawContext->base.drawPriv == base)); - - dc = glxWinMakeDC(draw->drawContext, draw, &dc, &hwnd); - if (dc == NULL) - return GL_FALSE; - - ret = wglSwapLayerBuffers(dc, WGL_SWAP_MAIN_PLANE); - - glxWinReleaseDC(hwnd, dc, draw); - - if (!ret) - { - ErrorF("wglSwapBuffers failed: %s\n", glxWinErrorMessage()); - return GL_FALSE; - } - - return GL_TRUE; -} - -static void -glxWinDrawableCopySubBuffer(__GLXdrawable *drawable, - int x, int y, int w, int h) -{ - glAddSwapHintRectWINWrapperNonstatic(x, y, w, h); - glxWinDrawableSwapBuffers(NULL, drawable); -} - -static void -glxWinDrawableDestroy(__GLXdrawable *base) -{ - __GLXWinDrawable *glxPriv = (__GLXWinDrawable *)base; - - if (glxPriv->drawContext && (__glXLastContext == &((glxPriv->drawContext)->base))) - { - // if this context is current and has unflushed commands, say we have flushed them - // (don't actually flush them, the window is going away anyhow, and an implict flush occurs - // on the next context change) - // (GLX core considers it an error when we try to select a new current context if the old one - // has unflushed commands, but the window has disappeared..) - __glXLastContext->hasUnflushedCommands = FALSE; - __glXLastContext = NULL; - } - - if (glxPriv->hPbuffer) - if (!wglDestroyPbufferARBWrapper(glxPriv->hPbuffer)) - { - ErrorF("wglDestroyPbufferARB failed: %s\n", glxWinErrorMessage()); - } - - if (glxPriv->dibDC) - { - // restore the default DIB - SelectObject(glxPriv->dibDC, glxPriv->hOldDIB); - - if (!DeleteDC(glxPriv->dibDC)) - { - ErrorF("DeleteDC failed: %s\n", glxWinErrorMessage()); - } - } - - if (glxPriv->hDIB) - { - if (!DeleteObject(glxPriv->hDIB)) - { - ErrorF("DeleteObject failed: %s\n", glxWinErrorMessage()); - } - - ((PixmapPtr)glxPriv->base.pDraw)->devPrivate.ptr = glxPriv->pOldBits; - } - - GLWIN_DEBUG_MSG("glxWinDestroyDrawable"); - free(glxPriv); -} - -static __GLXdrawable * -glxWinCreateDrawable(ClientPtr client, - __GLXscreen *screen, - DrawablePtr pDraw, - XID drawId, - int type, - XID glxDrawId, - __GLXconfig *conf) -{ - __GLXWinDrawable *glxPriv; - - glxPriv = malloc(sizeof *glxPriv); - - if (glxPriv == NULL) - return NULL; - - memset(glxPriv, 0, sizeof *glxPriv); - - if(!__glXDrawableInit(&glxPriv->base, screen, pDraw, type, glxDrawId, conf)) { - free(glxPriv); - return NULL; - } - - glxPriv->base.destroy = glxWinDrawableDestroy; - glxPriv->base.swapBuffers = glxWinDrawableSwapBuffers; - glxPriv->base.copySubBuffer = glxWinDrawableCopySubBuffer; - // glxPriv->base.waitX what are these for? - // glxPriv->base.waitGL - - GLWIN_DEBUG_MSG("glxWinCreateDrawable %p", glxPriv); - - return &glxPriv->base; -} - -/* ---------------------------------------------------------------------- */ -/* - * Texture functions - */ - -static -int glxWinBindTexImage(__GLXcontext *baseContext, - int buffer, - __GLXdrawable *pixmap) -{ - ErrorF("glxWinBindTexImage: not implemented\n"); - return FALSE; -} - -static -int glxWinReleaseTexImage(__GLXcontext *baseContext, - int buffer, - __GLXdrawable *pixmap) -{ - ErrorF(" glxWinReleaseTexImage: not implemented\n"); - return FALSE; -} - -/* ---------------------------------------------------------------------- */ -/* - * Lazy update context implementation - * - * WGL contexts are created for a specific HDC, so we cannot create the WGL - * context in glxWinCreateContext(), we must defer creation until the context - * is actually used on a specifc drawable which is connected to a native window, - * pbuffer or DIB - * - * The WGL context may be used on other, compatible HDCs, so we don't need to - * recreate it for every new native window - * - * XXX: I wonder why we can't create the WGL context on the screen HDC ? - * Basically we assume all HDCs are compatible at the moment: if they are not - * we are in a muddle, there was some code in the old implementation to attempt - * to transparently migrate a context to a new DC by copying state and sharing - * lists with the old one... - */ - -static void -glxWinSetPixelFormat(__GLXWinContext *gc, HDC hdc, int bppOverride, int drawableTypeOverride) -{ - __GLXscreen *screen = gc->base.pGlxScreen; - glxWinScreen *winScreen = (glxWinScreen *)screen; - - __GLXconfig *config = gc->base.config; - GLXWinConfig *winConfig = (GLXWinConfig *)config; - - GLWIN_DEBUG_MSG("glxWinSetPixelFormat: pixelFormatIndex %d", winConfig->pixelFormatIndex); - - /* - Normally, we can just use the the pixelFormatIndex corresponding - to the fbconfig which has been specified by the client - */ - - if (!((bppOverride && (bppOverride != (config->redBits + config->greenBits + config->blueBits) )) - || ((config->drawableType & drawableTypeOverride) == 0))) - { - if (!SetPixelFormat(hdc, winConfig->pixelFormatIndex, NULL)) - { - ErrorF("SetPixelFormat error: %s\n", glxWinErrorMessage()); - return; - } - - return; - } - - /* - However, in certain special cases this pixel format will be incompatible with the - use we are going to put it to, so we need to re-evaluate the pixel format to use: - - 1) When PFD_DRAW_TO_BITMAP is set, ChoosePixelFormat() always returns a format with - the cColorBits we asked for, so we need to ensure it matches the bpp of the bitmap - - 2) Applications may assume that visuals selected with glXChooseVisual() work with - pixmap drawables (there is no attribute to explicitly query for pixmap drawable - support as there is for glXChooseFBConfig()) - (it's arguable this is an error in the application, but we try to make it work) - - pixmap rendering is always slow for us, so we don't want to choose those visuals - by default, but if the actual drawable type we're trying to select the context - on (drawableTypeOverride) isn't supported by the selected fbConfig, reconsider - and see if we can find a suitable one... - */ - ErrorF("glxWinSetPixelFormat: having second thoughts: cColorbits %d, bppOveride %d; config->drawableType %d, drawableTypeOverride %d\n", - (config->redBits + config->greenBits + config->blueBits), bppOverride, config->drawableType, drawableTypeOverride); - - if (!winScreen->has_WGL_ARB_pixel_format) - { - PIXELFORMATDESCRIPTOR pfd; - int pixelFormat; - - /* convert fbConfig to PFD */ - if (fbConfigToPixelFormat(gc->base.config, &pfd, drawableTypeOverride)) - { - ErrorF("glxWinSetPixelFormat: fbConfigToPixelFormat failed\n"); - return; - } - - if (glxWinDebugSettings.dumpPFD) - pfdOut(&pfd); - - if (bppOverride) - { - GLWIN_DEBUG_MSG("glxWinSetPixelFormat: Forcing bpp from %d to %d\n", pfd.cColorBits, bppOverride); - pfd.cColorBits = bppOverride; - } - - pixelFormat = ChoosePixelFormat(hdc, &pfd); - if (pixelFormat == 0) - { - ErrorF("ChoosePixelFormat error: %s\n", glxWinErrorMessage()); - return; - } - - GLWIN_DEBUG_MSG("ChoosePixelFormat: chose pixelFormatIndex %d", pixelFormat); - ErrorF("ChoosePixelFormat: chose pixelFormatIndex %d (rather than %d as originally planned)\n", pixelFormat, winConfig->pixelFormatIndex); - - if (!SetPixelFormat(hdc, pixelFormat, &pfd)) - { - ErrorF("SetPixelFormat error: %s\n", glxWinErrorMessage()); - return; - } - } - else - { - int pixelFormat = fbConfigToPixelFormatIndex(hdc, gc->base.config, drawableTypeOverride, winScreen); - if (pixelFormat == 0) - { - ErrorF("wglChoosePixelFormat error: %s\n", glxWinErrorMessage()); - return; - } - - GLWIN_DEBUG_MSG("wglChoosePixelFormat: chose pixelFormatIndex %d", pixelFormat); - ErrorF("wglChoosePixelFormat: chose pixelFormatIndex %d (rather than %d as originally planned)\n", pixelFormat, winConfig->pixelFormatIndex); - - if (!SetPixelFormat(hdc, pixelFormat, NULL)) - { - ErrorF("SetPixelFormat error: %s\n", glxWinErrorMessage()); - return; - } - } -} - -static HDC -glxWinMakeDC(__GLXWinContext *gc, __GLXWinDrawable *draw, HDC *hdc, HWND *hwnd) -{ - *hdc = NULL; - *hwnd = NULL; - - if (draw == NULL) - { - GLWIN_TRACE_MSG("No drawable for context %p (native ctx %p)", gc, gc->ctx); - return NULL; - } - - switch (draw->base.type) - { - case GLX_DRAWABLE_WINDOW: - { - WindowPtr pWin; - - pWin = (WindowPtr) draw->base.pDraw; - if (pWin == NULL) - { - GLWIN_TRACE_MSG("for drawable %p, no WindowPtr", pWin); - return NULL; - } - - *hwnd = winGetWindowInfo(pWin); - - if (*hwnd == NULL) - { - ErrorF("No HWND error: %s\n", glxWinErrorMessage()); - return NULL; - } - - *hdc = GetDC(*hwnd); - - if (*hdc == NULL) - ErrorF("GetDC error: %s\n", glxWinErrorMessage()); - - /* Check if the hwnd has changed... */ - if (*hwnd != gc->hwnd) - { - if (glxWinDebugSettings.enableTrace) - GLWIN_DEBUG_HWND(*hwnd); - - GLWIN_TRACE_MSG("for context %p (native ctx %p), hWnd changed from %p to %p", gc, gc->ctx, gc->hwnd, *hwnd); - gc->hwnd = *hwnd; - - /* We must select a pixelformat, but SetPixelFormat can only be called once for a window... */ - glxWinSetPixelFormat(gc, *hdc, 0, GLX_WINDOW_BIT); - } - } - break; - - case GLX_DRAWABLE_PBUFFER: - { - *hdc = wglGetPbufferDCARBWrapper(draw->hPbuffer); - - if (*hdc == NULL) - ErrorF("GetDC (pbuffer) error: %s\n", glxWinErrorMessage()); - } - break; - - case GLX_DRAWABLE_PIXMAP: - { - *hdc = draw->dibDC; - } - break; - - default: - { - ErrorF("glxWinMakeDC: tried to makeDC for unhandled drawable type %d\n", draw->base.type); - } - } - - if (glxWinDebugSettings.dumpDC) - GLWIN_DEBUG_MSG("Got HDC %p", *hdc); - - return *hdc; -} - -static void -glxWinReleaseDC(HWND hwnd, HDC hdc,__GLXWinDrawable *draw) -{ - switch (draw->base.type) - { - case GLX_DRAWABLE_WINDOW: - { - ReleaseDC(hwnd, hdc); - } - break; - - case GLX_DRAWABLE_PBUFFER: - { - if (!wglReleasePbufferDCARBWrapper(draw->hPbuffer, hdc)) - { - ErrorF("wglReleasePbufferDCARB error: %s\n", glxWinErrorMessage()); - } - } - break; - - case GLX_DRAWABLE_PIXMAP: - { - // don't release DC, the memory DC lives as long as the bitmap - - // We must ensure that all GDI drawing into the bitmap has completed - // in case we subsequently access the bits from it - GdiFlush(); - } - break; - - default: - { - ErrorF("glxWinReleaseDC: tried to releaseDC for unhandled drawable type %d\n", draw->base.type); - } - } -} - -static void -glxWinDeferredCreateContext(__GLXWinContext *gc, __GLXWinDrawable *draw) -{ - HDC dc; - HWND hwnd; - GLWIN_DEBUG_MSG("glxWinDeferredCreateContext: attach context %p to drawable %p", gc, draw); - - switch (draw->base.type) - { - case GLX_DRAWABLE_WINDOW: - { - WindowPtr pWin = (WindowPtr) draw->base.pDraw; - - if (!(gc->base.config->drawableType & GLX_WINDOW_BIT)) - { - ErrorF("glxWinDeferredCreateContext: tried to attach a context whose fbConfig doesn't have drawableType GLX_WINDOW_BIT to a GLX_DRAWABLE_WINDOW drawable\n"); - } - - if (pWin == NULL) - { - GLWIN_DEBUG_MSG("Deferring until X window is created"); - return; - } - - GLWIN_DEBUG_MSG("glxWinDeferredCreateContext: pWin %p", pWin); - - if (winGetWindowInfo(pWin) == NULL) - { - GLWIN_DEBUG_MSG("Deferring until native window is created"); - return; - } - } - break; - - case GLX_DRAWABLE_PBUFFER: - { - if (draw->hPbuffer == NULL) - { - __GLXscreen *screen; - glxWinScreen *winScreen; - int pixelFormat; - // XXX: which DC are supposed to use??? - HDC screenDC = GetDC(NULL); - - if (!(gc->base.config->drawableType & GLX_PBUFFER_BIT)) - { - ErrorF("glxWinDeferredCreateContext: tried to attach a context whose fbConfig doesn't have drawableType GLX_PBUFFER_BIT to a GLX_DRAWABLE_PBUFFER drawable\n"); - } - - screen = gc->base.pGlxScreen; - winScreen = (glxWinScreen *)screen; - - pixelFormat = fbConfigToPixelFormatIndex(screenDC, gc->base.config, GLX_DRAWABLE_PBUFFER, winScreen); - if (pixelFormat == 0) - { - ErrorF("wglChoosePixelFormat error: %s\n", glxWinErrorMessage()); - return; - } - - draw->hPbuffer = wglCreatePbufferARBWrapper(screenDC, pixelFormat, draw->base.pDraw->width, draw->base.pDraw->height, NULL); - ReleaseDC(NULL, screenDC); - - if (draw->hPbuffer == NULL) - { - ErrorF("wglCreatePbufferARBWrapper error: %s\n", glxWinErrorMessage()); - return; - } - - GLWIN_DEBUG_MSG("glxWinDeferredCreateContext: pBuffer %p created for drawable %p", draw->hPbuffer, draw); - } - } - break; - - case GLX_DRAWABLE_PIXMAP: - { - if (draw->dibDC == NULL) - { - BITMAPINFOHEADER bmpHeader; - void *pBits; - - memset (&bmpHeader, 0, sizeof(BITMAPINFOHEADER)); - bmpHeader.biSize = sizeof(BITMAPINFOHEADER); - bmpHeader.biWidth = draw->base.pDraw->width; - bmpHeader.biHeight = draw->base.pDraw->height; - bmpHeader.biPlanes = 1; - bmpHeader.biBitCount = draw->base.pDraw->bitsPerPixel; - bmpHeader.biCompression = BI_RGB; - - if (!(gc->base.config->drawableType & GLX_PIXMAP_BIT)) - { - ErrorF("glxWinDeferredCreateContext: tried to attach a context whose fbConfig doesn't have drawableType GLX_PIXMAP_BIT to a GLX_DRAWABLE_PIXMAP drawable\n"); - } - - draw->dibDC = CreateCompatibleDC(NULL); - if (draw->dibDC == NULL) - { - ErrorF("CreateCompatibleDC error: %s\n", glxWinErrorMessage()); - return; - } - - draw->hDIB = CreateDIBSection(draw->dibDC, (BITMAPINFO *)&bmpHeader, DIB_RGB_COLORS, &pBits, 0, 0); - if (draw->dibDC == NULL) - { - ErrorF("CreateDIBSection error: %s\n", glxWinErrorMessage()); - return; - } - - // XXX: CreateDIBSection insists on allocating the bitmap memory for us, so we're going to - // need some jiggery pokery to point the underlying X Drawable's bitmap at the same set of bits - // so that they can be read with XGetImage as well as glReadPixels, assuming the formats are - // even compatible ... - draw->pOldBits = ((PixmapPtr)draw->base.pDraw)->devPrivate.ptr; - ((PixmapPtr)draw->base.pDraw)->devPrivate.ptr = pBits; - - // Select the DIB into the DC - draw->hOldDIB = SelectObject(draw->dibDC, draw->hDIB); - if (!draw->hOldDIB) - { - ErrorF("SelectObject error: %s\n", glxWinErrorMessage()); - } - - // Set the pixel format of the bitmap - glxWinSetPixelFormat(gc, draw->dibDC, draw->base.pDraw->bitsPerPixel, GLX_PIXMAP_BIT); - - GLWIN_DEBUG_MSG("glxWinDeferredCreateContext: DIB bitmap %p created for drawable %p", draw->hDIB, draw); - } - } - break; - - default: - { - ErrorF("glxWinDeferredCreateContext: tried to attach unhandled drawable type %d\n", draw->base.type); - return; - } - } - - dc = glxWinMakeDC(gc, draw, &dc, &hwnd); - gc->ctx = wglCreateContext(dc); - glxWinReleaseDC(hwnd, dc, draw); - - if (gc->ctx == NULL) - { - ErrorF("wglCreateContext error: %s\n", glxWinErrorMessage()); - return; - } - - GLWIN_DEBUG_MSG("glxWinDeferredCreateContext: attached context %p to native context %p drawable %p", gc, gc->ctx, draw); - - // if the native context was created successfully, shareLists if needed - if (gc->ctx && gc->shareContext) - { - GLWIN_DEBUG_MSG("glxWinCreateContextReal shareLists with context %p (native ctx %p)", gc->shareContext, gc->shareContext->ctx); - - if (!wglShareLists(gc->shareContext->ctx, gc->ctx)) - { - ErrorF("wglShareLists error: %s\n", glxWinErrorMessage()); - } - } -} - -/* ---------------------------------------------------------------------- */ -/* - * Context functions - */ - - -/* Context manipulation routines should return TRUE on success, FALSE on failure */ -static int -glxWinContextMakeCurrent(__GLXcontext *base) -{ - __GLXWinContext *gc = (__GLXWinContext *)base; - BOOL ret; - HDC drawDC; - HDC readDC = NULL; - __GLXdrawable *drawPriv; - __GLXdrawable *readPriv = NULL; - HWND hDrawWnd; - HWND hReadWnd; - - GLWIN_TRACE_MSG("glxWinContextMakeCurrent context %p (native ctx %p)", gc, gc->ctx); - glWinCallDelta(); - - /* Keep a note of the last active context in the drawable */ - drawPriv = gc->base.drawPriv; - ((__GLXWinDrawable *)drawPriv)->drawContext = gc; - - if (gc->ctx == NULL) - { - glxWinDeferredCreateContext(gc, (__GLXWinDrawable *)drawPriv); - } - - if (gc->ctx == NULL) - { - ErrorF("glxWinContextMakeCurrent: Native context is NULL\n"); - return FALSE; - } - - drawDC = glxWinMakeDC(gc, (__GLXWinDrawable *)drawPriv, &drawDC, &hDrawWnd); - if (drawDC == NULL) - { - ErrorF("glxWinMakeDC failed for drawDC\n"); - return FALSE; - } - - if ((gc->base.readPriv != NULL) && (gc->base.readPriv != gc->base.drawPriv)) - { - // XXX: should only occur with WGL_ARB_make_current_read - /* - If there is a separate read drawable, create a separate read DC, and - use the wglMakeContextCurrent extension to make the context current drawing - to one DC and reading from the other - */ - readPriv = gc->base.readPriv; - readDC = glxWinMakeDC(gc, (__GLXWinDrawable *)readPriv, &readDC, &hReadWnd); - if (readDC == NULL) - { - ErrorF("glxWinMakeDC failed for readDC\n"); - glxWinReleaseDC(hDrawWnd, drawDC, (__GLXWinDrawable *)drawPriv); - return FALSE; - } - - ret = wglMakeContextCurrentARBWrapper(drawDC, readDC, gc->ctx); - if (!ret) - { - ErrorF("wglMakeContextCurrentARBWrapper error: %s\n", glxWinErrorMessage()); - } - } - else - { - /* Otherwise, just use wglMakeCurrent */ - ret = wglMakeCurrent(drawDC, gc->ctx); - if (!ret) - { - ErrorF("wglMakeCurrent error: %s\n", glxWinErrorMessage()); - } - } - - // apparently make current could fail if the context is current in a different thread, - // but that shouldn't be able to happen in the current server... - - glxWinReleaseDC(hDrawWnd, drawDC, (__GLXWinDrawable *)drawPriv); - if (readDC) - glxWinReleaseDC(hReadWnd, readDC, (__GLXWinDrawable *)readPriv); - - return ret; -} - -static int -glxWinContextLoseCurrent(__GLXcontext *base) -{ - BOOL ret; - __GLXWinContext *gc = (__GLXWinContext *)base; - - GLWIN_TRACE_MSG("glxWinContextLoseCurrent context %p (native ctx %p)", gc, gc->ctx); - glWinCallDelta(); - - /* - An error seems to be reported if we try to make no context current - if there is already no current context, so avoid doing that... - */ - if (__glXLastContext != NULL) - { - ret = wglMakeCurrent(NULL, NULL); /* We don't need a DC when setting no current context */ - if (!ret) - ErrorF("glxWinContextLoseCurrent error: %s\n", glxWinErrorMessage()); - } - - return TRUE; -} - -static int -glxWinContextCopy(__GLXcontext *dst_base, __GLXcontext *src_base, unsigned long mask) -{ - __GLXWinContext *dst = (__GLXWinContext *)dst_base; - __GLXWinContext *src = (__GLXWinContext *)src_base; - BOOL ret; - - GLWIN_DEBUG_MSG("glxWinContextCopy"); - - ret = wglCopyContext(src->ctx, dst->ctx, mask); - if (!ret) - { - ErrorF("wglCopyContext error: %s\n", glxWinErrorMessage()); - } - - return ret; -} - -static void -glxWinContextDestroy(__GLXcontext *base) -{ - __GLXWinContext *gc = (__GLXWinContext *)base; - - if (gc != NULL) - { - GLWIN_DEBUG_MSG("GLXcontext %p destroyed (native ctx %p)", base, gc->ctx); - - if (gc->ctx) - { - /* It's bad style to delete the context while it's still current */ - if (wglGetCurrentContext() == gc->ctx) - { - wglMakeCurrent(NULL, NULL); - } - - { - BOOL ret = wglDeleteContext(gc->ctx); - if (!ret) - ErrorF("wglDeleteContext error: %s\n", glxWinErrorMessage()); - } - - gc->ctx = NULL; - } - - free(gc); - } -} - -static __GLXcontext * -glxWinCreateContext(__GLXscreen *screen, - __GLXconfig *modes, - __GLXcontext *baseShareContext) -{ - __GLXWinContext *context; - __GLXWinContext *shareContext = (__GLXWinContext *)baseShareContext; - - static __GLXtextureFromPixmap glxWinTextureFromPixmap = - { - glxWinBindTexImage, - glxWinReleaseTexImage - }; - - context = (__GLXWinContext *)calloc(1, sizeof(__GLXWinContext)); - - if (!context) - return NULL; - - memset(context, 0, sizeof *context); - context->base.destroy = glxWinContextDestroy; - context->base.makeCurrent = glxWinContextMakeCurrent; - context->base.loseCurrent = glxWinContextLoseCurrent; - context->base.copy = glxWinContextCopy; - context->base.textureFromPixmap = &glxWinTextureFromPixmap; - context->base.config = modes; - context->base.pGlxScreen = screen; - - // actual native GL context creation is deferred until attach() - context->ctx = NULL; - context->shareContext = shareContext; - - glWinSetupDispatchTable(); - - GLWIN_DEBUG_MSG("GLXcontext %p created", context); - - return &(context->base); -} - -/* ---------------------------------------------------------------------- */ -/* - * Utility functions - */ - -static int -fbConfigToPixelFormat(__GLXconfig *mode, PIXELFORMATDESCRIPTOR *pfdret, int drawableTypeOverride) -{ - PIXELFORMATDESCRIPTOR pfd = { - sizeof(PIXELFORMATDESCRIPTOR), /* size of this pfd */ - 1, /* version number */ - PFD_SUPPORT_OPENGL, /* support OpenGL */ - PFD_TYPE_RGBA, /* RGBA type */ - 24, /* 24-bit color depth */ - 0, 0, 0, 0, 0, 0, /* color bits ignored */ - 0, /* no alpha buffer */ - 0, /* shift bit ignored */ - 0, /* no accumulation buffer */ - 0, 0, 0, 0, /* accum bits ignored */ - 32, /* 32-bit z-buffer */ - 0, /* no stencil buffer */ - 0, /* no auxiliary buffer */ - PFD_MAIN_PLANE, /* main layer */ - 0, /* reserved */ - 0, 0, 0 /* layer masks ignored */ - }; - - if ((mode->drawableType | drawableTypeOverride) & GLX_WINDOW_BIT) - pfd.dwFlags |= PFD_DRAW_TO_WINDOW; /* support window */ - - if ((mode->drawableType | drawableTypeOverride) & GLX_PIXMAP_BIT) - pfd.dwFlags |= (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI); /* supports software rendering to bitmap */ - - if (mode->stereoMode) { - pfd.dwFlags |= PFD_STEREO; - } - if (mode->doubleBufferMode) { - pfd.dwFlags |= PFD_DOUBLEBUFFER; - } - - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.cColorBits = mode->redBits + mode->greenBits + mode->blueBits; - pfd.cRedBits = mode->redBits; - pfd.cRedShift = 0; /* FIXME */ - pfd.cGreenBits = mode->greenBits; - pfd.cGreenShift = 0; /* FIXME */ - pfd.cBlueBits = mode->blueBits; - pfd.cBlueShift = 0; /* FIXME */ - pfd.cAlphaBits = mode->alphaBits; - pfd.cAlphaShift = 0; /* FIXME */ - - pfd.cAccumBits = mode->accumRedBits + mode->accumGreenBits + mode->accumBlueBits + mode->accumAlphaBits; - pfd.cAccumRedBits = mode->accumRedBits; - pfd.cAccumGreenBits = mode->accumGreenBits; - pfd.cAccumBlueBits = mode->accumBlueBits; - pfd.cAccumAlphaBits = mode->accumAlphaBits; - - pfd.cDepthBits = mode->depthBits; - pfd.cStencilBits = mode->stencilBits; - pfd.cAuxBuffers = mode->numAuxBuffers; - - /* mode->level ? */ - /* mode->pixmapMode ? */ - - *pfdret = pfd; - - return 0; -} - -#define SET_ATTR_VALUE(attr, value) { attribList[i++] = attr; attribList[i++] = value; assert(i < NUM_ELEMENTS(attribList)); } - -static int -fbConfigToPixelFormatIndex(HDC hdc, __GLXconfig *mode, int drawableTypeOverride, glxWinScreen *winScreen) -{ - UINT numFormats; - unsigned int i = 0; - - /* convert fbConfig to attr-value list */ - int attribList[60]; - - SET_ATTR_VALUE(WGL_SUPPORT_OPENGL_ARB, TRUE); - SET_ATTR_VALUE(WGL_PIXEL_TYPE_ARB, (mode->visualType == GLX_TRUE_COLOR) ? WGL_TYPE_RGBA_ARB : WGL_TYPE_COLORINDEX_ARB); - SET_ATTR_VALUE(WGL_COLOR_BITS_ARB, (mode->visualType == GLX_TRUE_COLOR) ? mode->rgbBits : mode->indexBits); - SET_ATTR_VALUE(WGL_RED_BITS_ARB, mode->redBits); - SET_ATTR_VALUE(WGL_GREEN_BITS_ARB, mode->greenBits); - SET_ATTR_VALUE(WGL_BLUE_BITS_ARB, mode->blueBits); - SET_ATTR_VALUE(WGL_ALPHA_BITS_ARB, mode->alphaBits); - SET_ATTR_VALUE(WGL_ACCUM_RED_BITS_ARB, mode->accumRedBits); - SET_ATTR_VALUE(WGL_ACCUM_GREEN_BITS_ARB, mode->accumGreenBits); - SET_ATTR_VALUE(WGL_ACCUM_BLUE_BITS_ARB, mode->accumBlueBits); - SET_ATTR_VALUE(WGL_ACCUM_ALPHA_BITS_ARB, mode->accumAlphaBits); - SET_ATTR_VALUE(WGL_DEPTH_BITS_ARB, mode->depthBits); - SET_ATTR_VALUE(WGL_STENCIL_BITS_ARB, mode->stencilBits); - SET_ATTR_VALUE(WGL_AUX_BUFFERS_ARB, mode->numAuxBuffers); - - if (mode->doubleBufferMode) - SET_ATTR_VALUE(WGL_DOUBLE_BUFFER_ARB, TRUE); - - if (mode->stereoMode) - SET_ATTR_VALUE(WGL_STEREO_ARB, TRUE); - - // Some attributes are only added to the list if the value requested is not 'don't care', as exactly matching that is daft.. - if (mode->swapMethod == GLX_SWAP_EXCHANGE_OML) - SET_ATTR_VALUE(WGL_SWAP_METHOD_ARB, WGL_SWAP_EXCHANGE_ARB); - - if (mode->swapMethod == GLX_SWAP_COPY_OML) - SET_ATTR_VALUE(WGL_SWAP_COPY_ARB, TRUE); - - // XXX: this should probably be the other way around, but that messes up drawableTypeOverride - if (mode->visualRating == GLX_SLOW_VISUAL_EXT) - SET_ATTR_VALUE(WGL_ACCELERATION_ARB, WGL_NO_ACCELERATION_ARB); - - // must support all the drawable types the mode supports - if ((mode->drawableType | drawableTypeOverride) & GLX_WINDOW_BIT) - SET_ATTR_VALUE(WGL_DRAW_TO_WINDOW_ARB,TRUE); - - // XXX: this is a horrible hacky heuristic, in fact this whole drawableTypeOverride thing is a bad idea - // try to avoid asking for formats which don't exist (by not asking for all when adjusting the config to include the drawableTypeOverride) - if (drawableTypeOverride == GLX_WINDOW_BIT) - { - if (mode->drawableType & GLX_PIXMAP_BIT) - SET_ATTR_VALUE(WGL_DRAW_TO_BITMAP_ARB, TRUE); - - if (mode->drawableType & GLX_PBUFFER_BIT) - if (winScreen->has_WGL_ARB_pbuffer) - SET_ATTR_VALUE(WGL_DRAW_TO_PBUFFER_ARB, TRUE); - } - else - { - if (drawableTypeOverride & GLX_PIXMAP_BIT) - SET_ATTR_VALUE(WGL_DRAW_TO_BITMAP_ARB, TRUE); - - if (drawableTypeOverride & GLX_PBUFFER_BIT) - if (winScreen->has_WGL_ARB_pbuffer) - SET_ATTR_VALUE(WGL_DRAW_TO_PBUFFER_ARB, TRUE); - } - - SET_ATTR_VALUE(0, 0); // terminator - - /* choose the first match */ - { - int pixelFormatIndex; - - if (!wglChoosePixelFormatARBWrapper(hdc, attribList, NULL, 1, &pixelFormatIndex, &numFormats)) - { - ErrorF("wglChoosePixelFormat error: %s\n", glxWinErrorMessage()); - } - else - { - if (numFormats > 0) - { - GLWIN_DEBUG_MSG("wglChoosePixelFormat: chose pixelFormatIndex %d)", pixelFormatIndex); - return pixelFormatIndex; - } - else - ErrorF("wglChoosePixelFormat couldn't decide\n"); - } - } - - return 0; -} - -/* ---------------------------------------------------------------------- */ - -#define BITS_AND_SHIFT_TO_MASK(bits,mask) (((1<<(bits))-1) << (mask)) - -// -// Create the GLXconfigs using DescribePixelFormat() -// -static void -glxWinCreateConfigs(HDC hdc, glxWinScreen *screen) -{ - GLXWinConfig *c, *result, *prev = NULL; - int numConfigs = 0; - int i = 0; - int n = 0; - PIXELFORMATDESCRIPTOR pfd; - - GLWIN_DEBUG_MSG("glxWinCreateConfigs"); - - screen->base.numFBConfigs = 0; - screen->base.fbconfigs = NULL; - - // get the number of pixelformats - numConfigs = DescribePixelFormat(hdc, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL); - GLWIN_DEBUG_MSG("DescribePixelFormat says %d possible pixel formats", numConfigs); - - /* alloc */ - result = malloc(sizeof(GLXWinConfig) * numConfigs); - - if (NULL == result) - { - return; - } - - memset(result, 0, sizeof(GLXWinConfig) * numConfigs); - n = 0; - - /* fill in configs */ - for (i = 0; i < numConfigs; i++) - { - int rc; - - c = &(result[i]); - c->base.next = NULL; - c->pixelFormatIndex = i+1; - - rc = DescribePixelFormat(hdc, i+1, sizeof(PIXELFORMATDESCRIPTOR), &pfd); - - if (!rc) - { - ErrorF("DescribePixelFormat failed for index %d, error %s\n", i+1, glxWinErrorMessage()); - break; - } - - if (glxWinDebugSettings.dumpPFD) - pfdOut(&pfd); - - if (!(pfd.dwFlags & (PFD_DRAW_TO_WINDOW | PFD_DRAW_TO_BITMAP)) || !(pfd.dwFlags & PFD_SUPPORT_OPENGL)) - { - GLWIN_DEBUG_MSG("pixelFormat %d has unsuitable flags 0x%08lx, skipping", i+1, pfd.dwFlags); - continue; - } - - c->base.doubleBufferMode = (pfd.dwFlags & PFD_DOUBLEBUFFER) ? GL_TRUE : GL_FALSE; - c->base.stereoMode = (pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE; - - c->base.redBits = pfd.cRedBits; - c->base.greenBits = pfd.cGreenBits; - c->base.blueBits = pfd.cBlueBits; - c->base.alphaBits = pfd.cAlphaBits; - - c->base.redMask = BITS_AND_SHIFT_TO_MASK(pfd.cRedBits, pfd.cRedShift); - c->base.greenMask = BITS_AND_SHIFT_TO_MASK(pfd.cGreenBits, pfd.cGreenShift); - c->base.blueMask = BITS_AND_SHIFT_TO_MASK(pfd.cBlueBits, pfd.cBlueShift); - c->base.alphaMask = BITS_AND_SHIFT_TO_MASK(pfd.cAlphaBits, pfd.cAlphaShift); - - c->base.rgbBits = pfd.cColorBits; - - if (pfd.iPixelType == PFD_TYPE_COLORINDEX) - { - c->base.indexBits = pfd.cColorBits; - } - else - { - c->base.indexBits = 0; - } - - c->base.accumRedBits = pfd.cAccumRedBits; - c->base.accumGreenBits = pfd.cAccumGreenBits; - c->base.accumBlueBits = pfd.cAccumBlueBits; - c->base.accumAlphaBits = pfd.cAccumAlphaBits; - // pfd.cAccumBits; - - c->base.depthBits = pfd.cDepthBits; - c->base.stencilBits = pfd.cStencilBits; - c->base.numAuxBuffers = pfd.cAuxBuffers; - - // pfd.iLayerType; // ignored - c->base.level = 0; - // pfd.dwLayerMask; // ignored - // pfd.dwDamageMask; // ignored - - c->base.pixmapMode = 0; - c->base.visualID = -1; // will be set by __glXScreenInit() - - /* EXT_visual_rating / GLX 1.2 */ - if (pfd.dwFlags & PFD_GENERIC_FORMAT) - { - c->base.visualRating = GLX_SLOW_VISUAL_EXT; - } - else - { - // PFD_GENERIC_ACCELERATED is not considered, so this may be MCD or ICD acclerated... - c->base.visualRating = GLX_NONE_EXT; - } - - /* EXT_visual_info / GLX 1.2 */ - if (pfd.iPixelType == PFD_TYPE_COLORINDEX) - { - c->base.visualType = GLX_STATIC_COLOR; - - if (!getenv("GLWIN_ENABLE_COLORINDEX_FBCONFIGS")) - { - GLWIN_DEBUG_MSG("pixelFormat %d is PFD_TYPE_COLORINDEX, skipping", i+1); - continue; - } - } - else - { - c->base.visualType = GLX_TRUE_COLOR; - } - - // pfd.dwVisibleMask; ??? - c->base.transparentPixel = GLX_NONE; - c->base.transparentRed = GLX_NONE; - c->base.transparentGreen = GLX_NONE; - c->base.transparentBlue = GLX_NONE; - c->base.transparentAlpha = GLX_NONE; - c->base.transparentIndex = GLX_NONE; - - /* ARB_multisample / SGIS_multisample */ - c->base.sampleBuffers = 0; - c->base.samples = 0; - - /* SGIX_fbconfig / GLX 1.3 */ - c->base.drawableType = (((pfd.dwFlags & PFD_DRAW_TO_WINDOW) ? GLX_WINDOW_BIT : 0) - | ((pfd.dwFlags & PFD_DRAW_TO_BITMAP) ? GLX_PIXMAP_BIT : 0)); - - if (pfd.iPixelType == PFD_TYPE_COLORINDEX) - { - c->base.renderType = GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT; - } - else - { - c->base.renderType = GLX_RGBA_BIT; - } - - c->base.xRenderable = GL_TRUE; - c->base.fbconfigID = -1; // will be set by __glXScreenInit() - - /* SGIX_pbuffer / GLX 1.3 */ - // XXX: How can we find these values out ??? - c->base.maxPbufferWidth = -1; - c->base.maxPbufferHeight = -1; - c->base.maxPbufferPixels = -1; - c->base.optimalPbufferWidth = 0; // there is no optimal value - c->base.optimalPbufferHeight = 0; - - /* SGIX_visual_select_group */ - // arrange for visuals with the best acceleration to be preferred in selection - switch (pfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED)) - { - case 0: - c->base.visualSelectGroup = 2; - break; - - case PFD_GENERIC_ACCELERATED: - c->base.visualSelectGroup = 1; - break; - - case PFD_GENERIC_FORMAT: - c->base.visualSelectGroup = 0; - break; - - default: - ; - // "can't happen" - } - - /* OML_swap_method */ - if (pfd.dwFlags & PFD_SWAP_EXCHANGE) - c->base.swapMethod = GLX_SWAP_EXCHANGE_OML; - else if (pfd.dwFlags & PFD_SWAP_COPY) - c->base.swapMethod = GLX_SWAP_COPY_OML; - else - c->base.swapMethod = GLX_SWAP_UNDEFINED_OML; - - /* EXT_import_context */ - c->base.screen = screen->base.pScreen->myNum; - - /* EXT_texture_from_pixmap */ - c->base.bindToTextureRgb = -1; - c->base.bindToTextureRgba = -1; - c->base.bindToMipmapTexture = -1; - c->base.bindToTextureTargets = -1; - c->base.yInverted = -1; - - n++; - - // update previous config to point to this config - if (prev) - prev->base.next = &(c->base); - - prev = c; - } - - GLWIN_DEBUG_MSG("found %d pixelFormats suitable for conversion to fbConfigs", n); - - screen->base.numFBConfigs = n; - screen->base.fbconfigs = &(result->base); -} - -// helper function to access an attribute value from an attribute value array by attribute -static -int getAttrValue(const int attrs[], int values[], unsigned int num, int attr, int fallback) -{ - unsigned int i; - for (i = 0; i < num; i++) - { - if (attrs[i] == attr) - { - GLWIN_TRACE_MSG("getAttrValue attr 0x%x, value %d", attr, values[i]); - return values[i]; - } - } - - ErrorF("getAttrValue failed to find attr 0x%x, using default value %d\n", attr, fallback); - return fallback; -} - -// -// Create the GLXconfigs using wglGetPixelFormatAttribfvARB() extension -// -static void -glxWinCreateConfigsExt(HDC hdc, glxWinScreen *screen) -{ - GLXWinConfig *c, *result, *prev = NULL; - int i = 0; - int n = 0; - - const int attr = WGL_NUMBER_PIXEL_FORMATS_ARB; - int numConfigs; - - int attrs[50]; - unsigned int num_attrs = 0; - - GLWIN_DEBUG_MSG("glxWinCreateConfigsExt"); - - screen->base.numFBConfigs = 0; - screen->base.fbconfigs = NULL; - - if (!wglGetPixelFormatAttribivARBWrapper(hdc, 0, 0, 1, &attr, &numConfigs)) - { - ErrorF("wglGetPixelFormatAttribivARB failed for WGL_NUMBER_PIXEL_FORMATS_ARB: %s\n", glxWinErrorMessage()); - return; - } - - GLWIN_DEBUG_MSG("wglGetPixelFormatAttribivARB says %d possible pixel formats", numConfigs); - - /* alloc */ - result = malloc(sizeof(GLXWinConfig) * numConfigs); - - if (NULL == result) - { - return; - } - - memset(result, 0, sizeof(GLXWinConfig) * numConfigs); - n = 0; - -#define ADD_ATTR(a) { attrs[num_attrs++] = a; assert(num_attrs < NUM_ELEMENTS(attrs)); } - - ADD_ATTR(WGL_DRAW_TO_WINDOW_ARB); - ADD_ATTR(WGL_DRAW_TO_BITMAP_ARB); - ADD_ATTR(WGL_ACCELERATION_ARB); - ADD_ATTR(WGL_SWAP_LAYER_BUFFERS_ARB); - ADD_ATTR(WGL_NUMBER_OVERLAYS_ARB); - ADD_ATTR(WGL_NUMBER_UNDERLAYS_ARB); - ADD_ATTR(WGL_TRANSPARENT_ARB); - ADD_ATTR(WGL_TRANSPARENT_RED_VALUE_ARB); - ADD_ATTR(WGL_TRANSPARENT_GREEN_VALUE_ARB); - ADD_ATTR(WGL_TRANSPARENT_GREEN_VALUE_ARB); - ADD_ATTR(WGL_TRANSPARENT_ALPHA_VALUE_ARB); - ADD_ATTR(WGL_SUPPORT_OPENGL_ARB); - ADD_ATTR(WGL_DOUBLE_BUFFER_ARB); - ADD_ATTR(WGL_STEREO_ARB); - ADD_ATTR(WGL_PIXEL_TYPE_ARB); - ADD_ATTR(WGL_COLOR_BITS_ARB); - ADD_ATTR(WGL_RED_BITS_ARB); - ADD_ATTR(WGL_RED_SHIFT_ARB); - ADD_ATTR(WGL_GREEN_BITS_ARB); - ADD_ATTR(WGL_GREEN_SHIFT_ARB); - ADD_ATTR(WGL_BLUE_BITS_ARB); - ADD_ATTR(WGL_BLUE_SHIFT_ARB); - ADD_ATTR(WGL_ALPHA_BITS_ARB); - ADD_ATTR(WGL_ALPHA_SHIFT_ARB); - ADD_ATTR(WGL_ACCUM_RED_BITS_ARB); - ADD_ATTR(WGL_ACCUM_GREEN_BITS_ARB); - ADD_ATTR(WGL_ACCUM_BLUE_BITS_ARB); - ADD_ATTR(WGL_ACCUM_ALPHA_BITS_ARB); - ADD_ATTR(WGL_DEPTH_BITS_ARB); - ADD_ATTR(WGL_STENCIL_BITS_ARB); - ADD_ATTR(WGL_AUX_BUFFERS_ARB); - ADD_ATTR(WGL_SWAP_METHOD_ARB); - - if (screen->has_WGL_ARB_multisample) - { - // we may not query these attrs if WGL_ARB_multisample is not offered - ADD_ATTR(WGL_SAMPLE_BUFFERS_ARB); - ADD_ATTR(WGL_SAMPLES_ARB); - } - - if (screen->has_WGL_ARB_render_texture) - { - // we may not query these attrs if WGL_ARB_render_texture is not offered - ADD_ATTR(WGL_BIND_TO_TEXTURE_RGB_ARB); - ADD_ATTR(WGL_BIND_TO_TEXTURE_RGBA_ARB); - } - - if (screen->has_WGL_ARB_pbuffer) - { - // we may not query these attrs if WGL_ARB_pbuffer is not offered - ADD_ATTR(WGL_DRAW_TO_PBUFFER_ARB); - ADD_ATTR(WGL_MAX_PBUFFER_PIXELS_ARB); - ADD_ATTR(WGL_MAX_PBUFFER_WIDTH_ARB); - ADD_ATTR(WGL_MAX_PBUFFER_HEIGHT_ARB); - } - - /* fill in configs */ - for (i = 0; i < numConfigs; i++) - { - int values[num_attrs]; - - c = &(result[i]); - c->base.next = NULL; - c->pixelFormatIndex = i+1; - - if (!wglGetPixelFormatAttribivARBWrapper(hdc, i+1, 0, num_attrs, attrs, values)) - { - ErrorF("wglGetPixelFormatAttribivARB failed for index %d, error %s\n", i+1, glxWinErrorMessage()); - break; - } - -#define ATTR_VALUE(a, d) getAttrValue(attrs, values, num_attrs, (a), (d)) - - if (!ATTR_VALUE(WGL_SUPPORT_OPENGL_ARB, 0)) - { - GLWIN_DEBUG_MSG("pixelFormat %d isn't WGL_SUPPORT_OPENGL_ARB, skipping", i+1); - continue; - } - - c->base.doubleBufferMode = ATTR_VALUE(WGL_DOUBLE_BUFFER_ARB, 0) ? GL_TRUE : GL_FALSE; - c->base.stereoMode = ATTR_VALUE(WGL_STEREO_ARB, 0) ? GL_TRUE : GL_FALSE; - - c->base.redBits = ATTR_VALUE(WGL_RED_BITS_ARB, 0); - c->base.greenBits = ATTR_VALUE(WGL_GREEN_BITS_ARB, 0); - c->base.blueBits = ATTR_VALUE(WGL_BLUE_BITS_ARB, 0); - c->base.alphaBits = ATTR_VALUE(WGL_ALPHA_BITS_ARB, 0); - - c->base.redMask = BITS_AND_SHIFT_TO_MASK(c->base.redBits, ATTR_VALUE(WGL_RED_SHIFT_ARB, 0)); - c->base.greenMask = BITS_AND_SHIFT_TO_MASK(c->base.greenBits, ATTR_VALUE(WGL_GREEN_SHIFT_ARB, 0)); - c->base.blueMask = BITS_AND_SHIFT_TO_MASK(c->base.blueBits, ATTR_VALUE(WGL_BLUE_SHIFT_ARB, 0)); - c->base.alphaMask = BITS_AND_SHIFT_TO_MASK(c->base.alphaBits, ATTR_VALUE(WGL_ALPHA_SHIFT_ARB, 0)); - - switch (ATTR_VALUE(WGL_PIXEL_TYPE_ARB, 0)) - { - case WGL_TYPE_COLORINDEX_ARB: - c->base.indexBits = ATTR_VALUE(WGL_COLOR_BITS_ARB, 0); - c->base.rgbBits = 0; - c->base.visualType = GLX_STATIC_COLOR; - - if (!getenv("GLWIN_ENABLE_COLORINDEX_FBCONFIGS")) - { - GLWIN_DEBUG_MSG("pixelFormat %d is WGL_TYPE_COLORINDEX_ARB, skipping", i+1); - continue; - } - - break; - - case WGL_TYPE_RGBA_FLOAT_ARB: - GLWIN_DEBUG_MSG("pixelFormat %d is WGL_TYPE_RGBA_FLOAT_ARB, skipping", i+1); - continue; - - case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: - GLWIN_DEBUG_MSG("pixelFormat %d is WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT, skipping", i+1); - continue; - - case WGL_TYPE_RGBA_ARB: - c->base.indexBits = 0; - c->base.rgbBits = ATTR_VALUE(WGL_COLOR_BITS_ARB, 0); - c->base.visualType = GLX_TRUE_COLOR; - break; - - default: - ErrorF("wglGetPixelFormatAttribivARB returned unknown value 0x%x for WGL_PIXEL_TYPE_ARB\n", ATTR_VALUE(WGL_PIXEL_TYPE_ARB, 0)); - continue; - } - - c->base.accumRedBits = ATTR_VALUE(WGL_ACCUM_RED_BITS_ARB, 0); - c->base.accumGreenBits = ATTR_VALUE(WGL_ACCUM_GREEN_BITS_ARB, 0); - c->base.accumBlueBits = ATTR_VALUE(WGL_ACCUM_BLUE_BITS_ARB, 0); - c->base.accumAlphaBits = ATTR_VALUE(WGL_ACCUM_ALPHA_BITS_ARB, 0); - - c->base.depthBits = ATTR_VALUE(WGL_DEPTH_BITS_ARB, 0); - c->base.stencilBits = ATTR_VALUE(WGL_STENCIL_BITS_ARB, 0); - c->base.numAuxBuffers = ATTR_VALUE(WGL_AUX_BUFFERS_ARB, 0); - - { - int layers = ATTR_VALUE(WGL_NUMBER_OVERLAYS_ARB,0) + ATTR_VALUE(WGL_NUMBER_UNDERLAYS_ARB, 0); - - if (layers > 0) - { - ErrorF("pixelFormat %d: has %d overlay, %d underlays which aren't currently handled", i, ATTR_VALUE(WGL_NUMBER_OVERLAYS_ARB,0), ATTR_VALUE(WGL_NUMBER_UNDERLAYS_ARB, 0)); - // XXX: need to iterate over layers? - } - } - c->base.level = 0; - - c->base.pixmapMode = 0; // ??? - c->base.visualID = -1; // will be set by __glXScreenInit() - - /* EXT_visual_rating / GLX 1.2 */ - switch (ATTR_VALUE(WGL_ACCELERATION_ARB, 0)) - { - default: - ErrorF("wglGetPixelFormatAttribivARB returned unknown value 0x%x for WGL_ACCELERATION_ARB\n", ATTR_VALUE(WGL_ACCELERATION_ARB, 0)); - - case WGL_NO_ACCELERATION_ARB: - c->base.visualRating = GLX_SLOW_VISUAL_EXT; - break; - - case WGL_GENERIC_ACCELERATION_ARB: - case WGL_FULL_ACCELERATION_ARB: - c->base.visualRating = GLX_NONE_EXT; - break; - } - - /* EXT_visual_info / GLX 1.2 */ - // c->base.visualType is set above - if (ATTR_VALUE(WGL_TRANSPARENT_ARB, 0)) - { - c->base.transparentPixel = (c->base.visualType == GLX_TRUE_COLOR) ? GLX_TRANSPARENT_RGB_EXT : GLX_TRANSPARENT_INDEX_EXT; - c->base.transparentRed = ATTR_VALUE(WGL_TRANSPARENT_RED_VALUE_ARB, 0); - c->base.transparentGreen = ATTR_VALUE(WGL_TRANSPARENT_GREEN_VALUE_ARB, 0); - c->base.transparentBlue = ATTR_VALUE(WGL_TRANSPARENT_BLUE_VALUE_ARB, 0); - c->base.transparentAlpha = ATTR_VALUE(WGL_TRANSPARENT_ALPHA_VALUE_ARB, 0); - c->base.transparentIndex = ATTR_VALUE(WGL_TRANSPARENT_INDEX_VALUE_ARB, 0); - } - else - { - c->base.transparentPixel = GLX_NONE_EXT; - c->base.transparentRed = GLX_NONE; - c->base.transparentGreen = GLX_NONE; - c->base.transparentBlue = GLX_NONE; - c->base.transparentAlpha = GLX_NONE; - c->base.transparentIndex = GLX_NONE; - } - - /* ARB_multisample / SGIS_multisample */ - if (screen->has_WGL_ARB_multisample) - { - c->base.sampleBuffers = ATTR_VALUE(WGL_SAMPLE_BUFFERS_ARB, 0); - c->base.samples = ATTR_VALUE(WGL_SAMPLES_ARB, 0); - } - else - { - c->base.sampleBuffers = 0; - c->base.samples = 0; - } - - /* SGIX_fbconfig / GLX 1.3 */ - c->base.drawableType = ((ATTR_VALUE(WGL_DRAW_TO_WINDOW_ARB, 0) ? GLX_WINDOW_BIT : 0) - | (ATTR_VALUE(WGL_DRAW_TO_BITMAP_ARB, 0) ? GLX_PIXMAP_BIT : 0) - | (ATTR_VALUE(WGL_DRAW_TO_PBUFFER_ARB, 0) ? GLX_PBUFFER_BIT : 0)); - - /* - Assume OpenGL RGBA rendering is available on all visuals - (it is specified to render to red component in single-channel visuals, - if supported, but there doesn't seem to be any mechanism to check if it - is supported) - - Color index rendering is only supported on single-channel visuals - */ - if (c->base.visualType == GLX_STATIC_COLOR) - { - c->base.renderType = GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT; - } - else - { - c->base.renderType = GLX_RGBA_BIT; - } - - c->base.xRenderable = GL_TRUE; - c->base.fbconfigID = -1; // will be set by __glXScreenInit() - - /* SGIX_pbuffer / GLX 1.3 */ - if (screen->has_WGL_ARB_pbuffer) - { - c->base.maxPbufferWidth = ATTR_VALUE(WGL_MAX_PBUFFER_WIDTH_ARB, -1); - c->base.maxPbufferHeight = ATTR_VALUE(WGL_MAX_PBUFFER_HEIGHT_ARB, -1); - c->base.maxPbufferPixels = ATTR_VALUE(WGL_MAX_PBUFFER_PIXELS_ARB, -1); - } - else - { - c->base.maxPbufferWidth = -1; - c->base.maxPbufferHeight = -1; - c->base.maxPbufferPixels = -1; - } - c->base.optimalPbufferWidth = 0; // there is no optimal value - c->base.optimalPbufferHeight = 0; - - /* SGIX_visual_select_group */ - // arrange for visuals with the best acceleration to be preferred in selection - switch (ATTR_VALUE(WGL_ACCELERATION_ARB, 0)) - { - case WGL_FULL_ACCELERATION_ARB: - c->base.visualSelectGroup = 2; - break; - - case WGL_GENERIC_ACCELERATION_ARB: - c->base.visualSelectGroup = 1; - break; - - default: - case WGL_NO_ACCELERATION_ARB: - c->base.visualSelectGroup = 0; - break; - } - - /* OML_swap_method */ - switch (ATTR_VALUE(WGL_SWAP_METHOD_ARB, 0)) - { - case WGL_SWAP_EXCHANGE_ARB: - c->base.swapMethod = GLX_SWAP_EXCHANGE_OML; - break; - - case WGL_SWAP_COPY_ARB: - c->base.swapMethod = GLX_SWAP_COPY_OML; - break; - - default: - ErrorF("wglGetPixelFormatAttribivARB returned unknown value 0x%x for WGL_SWAP_METHOD_ARB\n", ATTR_VALUE(WGL_SWAP_METHOD_ARB, 0)); - - case WGL_SWAP_UNDEFINED_ARB: - c->base.swapMethod = GLX_SWAP_UNDEFINED_OML; - } - - /* EXT_import_context */ - c->base.screen = screen->base.pScreen->myNum; - - /* EXT_texture_from_pixmap */ - /* - Mesa's DRI configs always have bindToTextureRgb/Rgba TRUE (see driCreateConfigs(), so setting - bindToTextureRgb/bindToTextureRgba to FALSE means that swrast can't find any fbConfigs to use, - so setting these to 0, even if we know bindToTexture isn't available, isn't a good idea... - */ - if (screen->has_WGL_ARB_render_texture) - { - c->base.bindToTextureRgb = ATTR_VALUE(WGL_BIND_TO_TEXTURE_RGB_ARB, -1); - c->base.bindToTextureRgba = ATTR_VALUE(WGL_BIND_TO_TEXTURE_RGBA_ARB, -1); - } - else - { - c->base.bindToTextureRgb = -1; - c->base.bindToTextureRgba = -1; - } - c->base.bindToMipmapTexture = -1; - c->base.bindToTextureTargets = GLX_TEXTURE_1D_BIT_EXT | GLX_TEXTURE_2D_BIT_EXT | GLX_TEXTURE_RECTANGLE_BIT_EXT; - c->base.yInverted = -1; - - n++; - - // update previous config to point to this config - if (prev) - prev->base.next = &(c->base); - - prev = c; - } - - screen->base.numFBConfigs = n; - screen->base.fbconfigs = &(result->base); -} +/* + * File: indirect.c + * Purpose: A GLX implementation that uses Windows OpenGL library + * + * Authors: Alexander Gottwald + * Jon TURNEY + * + * Copyright (c) Jon TURNEY 2009 + * Copyright (c) Alexander Gottwald 2004 + * + * Portions of this file are copied from GL/apple/indirect.c, + * which contains the following copyright: + * + * Copyright (c) 2007, 2008, 2009 Apple Inc. + * Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved. + * Copyright (c) 2002 Greg Parker. All Rights Reserved. + * + * Portions of this file are copied from Mesa's xf86glx.c, + * which contains the following copyright: + * + * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. + * 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 without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR 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. + */ + +/* + TODO: + - hook up remaining unimplemented extensions + - research what guarantees glXWaitX, glXWaitGL are supposed to offer, and implement then + using GdiFlush and/or glFinish + - pbuffer clobbering: we don't get async notification, but can we arrange to emit the + event when we notice it's been clobbered? at the very least, check if it's been clobbered + before using it? + - XGetImage() doesn't work on pixmaps; need to do more work to make the format and location + of the native pixmap compatible + - implement GLX_EXT_texture_from_pixmap in terms of WGL_ARB_render_texture + (not quite straightforward as we will have to create a pbuffer and copy the pixmap texture + into it) +*/ + +/* + Assumptions: + - the __GLXConfig * we get handed back ones we are made (so we can extend the structure + with privates) and never get created inside the GLX core +*/ + +/* + MSDN clarifications: + + It says SetPixelFormat()'s PIXELFORMATDESCRIPTOR pointer argument has no effect + except on metafiles, this seems to mean that as it's ok to supply NULL if the DC + is not for a metafile + + wglMakeCurrent ignores the hdc if hglrc is NULL, so wglMakeCurrent(NULL, NULL) + is used to make no context current + +*/ + +#ifdef HAVE_XWIN_CONFIG_H +#include +#endif + +#include "glwindows.h" +#include +#include +#include +#include + +#include +#include + +#define NUM_ELEMENTS(x) (sizeof(x)/ sizeof(x[1])) + +/* Not yet in w32api */ +#ifndef PFD_SUPPORT_DIRECTDRAW +#define PFD_SUPPORT_DIRECTDRAW 0x00002000 +#endif +#ifndef PFD_DIRECT3D_ACCELERATED +#define PFD_DIRECT3D_ACCELERATED 0x00004000 +#endif +#ifndef PFD_SUPPORT_COMPOSITION +#define PFD_SUPPORT_COMPOSITION 0x00008000 +#endif + +/* ---------------------------------------------------------------------- */ +/* + * structure definitions + */ + +typedef struct __GLXWinContext __GLXWinContext; +typedef struct __GLXWinDrawable __GLXWinDrawable; +typedef struct __GLXWinScreen glxWinScreen; +typedef struct __GLXWinConfig GLXWinConfig; + +struct __GLXWinContext { + __GLXcontext base; + HGLRC ctx; /* Windows GL Context */ + __GLXWinContext *shareContext; /* Context with which we will share display lists and textures */ + HWND hwnd; /* For detecting when HWND has changed */ +}; + +struct __GLXWinDrawable +{ + __GLXdrawable base; + __GLXWinContext *drawContext; + __GLXWinContext *readContext; + + /* If this drawable is GLX_DRAWABLE_PBUFFER */ + HPBUFFERARB hPbuffer; + + /* If this drawable is GLX_DRAWABLE_PIXMAP */ + HDC dibDC; + HBITMAP hDIB; + HBITMAP hOldDIB; /* original DIB for DC */ + void *pOldBits; /* original pBits for this drawable's pixmap */ +}; + +struct __GLXWinScreen +{ + __GLXscreen base; + + /* Supported GLX extensions */ + unsigned char glx_enable_bits[__GLX_EXT_BYTES]; + + Bool has_WGL_ARB_multisample; + Bool has_WGL_ARB_pixel_format; + Bool has_WGL_ARB_pbuffer; + Bool has_WGL_ARB_render_texture; + + /* wrapped screen functions */ + RealizeWindowProcPtr RealizeWindow; + UnrealizeWindowProcPtr UnrealizeWindow; + CopyWindowProcPtr CopyWindow; +}; + +struct __GLXWinConfig +{ + __GLXconfig base; + int pixelFormatIndex; +}; + +/* ---------------------------------------------------------------------- */ +/* + * Various debug helpers + */ + +#define GLWIN_DEBUG_HWND(hwnd) \ + if (glxWinDebugSettings.dumpHWND) { \ + char buffer[1024]; \ + if (GetWindowText(hwnd, buffer, sizeof(buffer))==0) *buffer=0; \ + GLWIN_DEBUG_MSG("Got HWND %p for window '%s'", hwnd, buffer); \ + } + +glxWinDebugSettingsRec glxWinDebugSettings = { 0, 0, 0, 0, 0, 0}; + +static void glxWinInitDebugSettings(void) +{ + char *envptr; + + envptr = getenv("GLWIN_ENABLE_DEBUG"); + if (envptr != NULL) + glxWinDebugSettings.enableDebug = (atoi(envptr) == 1); + + envptr = getenv("GLWIN_ENABLE_TRACE"); + if (envptr != NULL) + glxWinDebugSettings.enableTrace = (atoi(envptr) == 1); + + envptr = getenv("GLWIN_DUMP_PFD"); + if (envptr != NULL) + glxWinDebugSettings.dumpPFD = (atoi(envptr) == 1); + + envptr = getenv("GLWIN_DUMP_HWND"); + if (envptr != NULL) + glxWinDebugSettings.dumpHWND = (atoi(envptr) == 1); + + envptr = getenv("GLWIN_DUMP_DC"); + if (envptr != NULL) + glxWinDebugSettings.dumpDC = (atoi(envptr) == 1); + + envptr = getenv("GLWIN_ENABLE_GLCALL_TRACE"); + if (envptr != NULL) + glxWinDebugSettings.enableGLcallTrace = (atoi(envptr) == 1); + + envptr = getenv("GLWIN_ENABLE_WGLCALL_TRACE"); + if (envptr != NULL) + glxWinDebugSettings.enableWGLcallTrace = (atoi(envptr) == 1); + + envptr = getenv("GLWIN_DEBUG_ALL"); + if (envptr != NULL) + { + glxWinDebugSettings.enableDebug = 1; + glxWinDebugSettings.enableTrace = 1; + glxWinDebugSettings.dumpPFD = 1; + glxWinDebugSettings.dumpHWND = 1; + glxWinDebugSettings.dumpDC = 1; + glxWinDebugSettings.enableGLcallTrace = 1; + glxWinDebugSettings.enableWGLcallTrace = 1; + } +} + +static +const char *glxWinErrorMessage(void) +{ + static char errorbuffer[1024]; + unsigned int last_error = GetLastError(); + + if (!FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, + NULL, + last_error, + 0, + (LPTSTR) &errorbuffer, + sizeof(errorbuffer), + NULL )) + { + snprintf(errorbuffer, sizeof(errorbuffer), "Unknown error"); + } + + if ((errorbuffer[strlen(errorbuffer)-1] == '\n') || (errorbuffer[strlen(errorbuffer)-1] == '\r')) + errorbuffer[strlen(errorbuffer)-1] = 0; + + sprintf(errorbuffer + strlen(errorbuffer), " (%08x)", last_error); + + return errorbuffer; +} + +static void pfdOut(const PIXELFORMATDESCRIPTOR *pfd); + +#define DUMP_PFD_FLAG(flag) \ + if (pfd->dwFlags & flag) { \ + ErrorF("%s%s", pipesym, #flag); \ + pipesym = " | "; \ + } + +static void pfdOut(const PIXELFORMATDESCRIPTOR *pfd) +{ + const char *pipesym = ""; /* will be set after first flag dump */ + ErrorF("PIXELFORMATDESCRIPTOR:\n"); + ErrorF("nSize = %u\n", pfd->nSize); + ErrorF("nVersion = %u\n", pfd->nVersion); + ErrorF("dwFlags = %lu = {", pfd->dwFlags); + DUMP_PFD_FLAG(PFD_DOUBLEBUFFER); + DUMP_PFD_FLAG(PFD_STEREO); + DUMP_PFD_FLAG(PFD_DRAW_TO_WINDOW); + DUMP_PFD_FLAG(PFD_DRAW_TO_BITMAP); + DUMP_PFD_FLAG(PFD_SUPPORT_GDI); + DUMP_PFD_FLAG(PFD_SUPPORT_OPENGL); + DUMP_PFD_FLAG(PFD_GENERIC_FORMAT); + DUMP_PFD_FLAG(PFD_NEED_PALETTE); + DUMP_PFD_FLAG(PFD_NEED_SYSTEM_PALETTE); + DUMP_PFD_FLAG(PFD_SWAP_EXCHANGE); + DUMP_PFD_FLAG(PFD_SWAP_COPY); + DUMP_PFD_FLAG(PFD_SWAP_LAYER_BUFFERS); + DUMP_PFD_FLAG(PFD_GENERIC_ACCELERATED); + DUMP_PFD_FLAG(PFD_SUPPORT_DIRECTDRAW); + DUMP_PFD_FLAG(PFD_DIRECT3D_ACCELERATED); + DUMP_PFD_FLAG(PFD_SUPPORT_COMPOSITION); + DUMP_PFD_FLAG(PFD_DEPTH_DONTCARE); + DUMP_PFD_FLAG(PFD_DOUBLEBUFFER_DONTCARE); + DUMP_PFD_FLAG(PFD_STEREO_DONTCARE); + ErrorF("}\n"); + + ErrorF("iPixelType = %hu = %s\n", pfd->iPixelType, + (pfd->iPixelType == PFD_TYPE_RGBA ? "PFD_TYPE_RGBA" : "PFD_TYPE_COLORINDEX")); + ErrorF("cColorBits = %hhu\n", pfd->cColorBits); + ErrorF("cRedBits = %hhu\n", pfd->cRedBits); + ErrorF("cRedShift = %hhu\n", pfd->cRedShift); + ErrorF("cGreenBits = %hhu\n", pfd->cGreenBits); + ErrorF("cGreenShift = %hhu\n", pfd->cGreenShift); + ErrorF("cBlueBits = %hhu\n", pfd->cBlueBits); + ErrorF("cBlueShift = %hhu\n", pfd->cBlueShift); + ErrorF("cAlphaBits = %hhu\n", pfd->cAlphaBits); + ErrorF("cAlphaShift = %hhu\n", pfd->cAlphaShift); + ErrorF("cAccumBits = %hhu\n", pfd->cAccumBits); + ErrorF("cAccumRedBits = %hhu\n", pfd->cAccumRedBits); + ErrorF("cAccumGreenBits = %hhu\n", pfd->cAccumGreenBits); + ErrorF("cAccumBlueBits = %hhu\n", pfd->cAccumBlueBits); + ErrorF("cAccumAlphaBits = %hhu\n", pfd->cAccumAlphaBits); + ErrorF("cDepthBits = %hhu\n", pfd->cDepthBits); + ErrorF("cStencilBits = %hhu\n", pfd->cStencilBits); + ErrorF("cAuxBuffers = %hhu\n", pfd->cAuxBuffers); + ErrorF("iLayerType = %hhu\n", pfd->iLayerType); + ErrorF("bReserved = %hhu\n", pfd->bReserved); + ErrorF("dwLayerMask = %lu\n", pfd->dwLayerMask); + ErrorF("dwVisibleMask = %lu\n", pfd->dwVisibleMask); + ErrorF("dwDamageMask = %lu\n", pfd->dwDamageMask); + ErrorF("\n"); +} + +static const char * +visual_class_name(int cls) +{ + switch (cls) { + case GLX_STATIC_COLOR: + return "StaticColor"; + case GLX_PSEUDO_COLOR: + return "PseudoColor"; + case GLX_STATIC_GRAY: + return "StaticGray"; + case GLX_GRAY_SCALE: + return "GrayScale"; + case GLX_TRUE_COLOR: + return "TrueColor"; + case GLX_DIRECT_COLOR: + return "DirectColor"; + default: + return "-none-"; + } +} + +static const char * +swap_method_name(int mthd) +{ + switch (mthd) + { + case GLX_SWAP_EXCHANGE_OML: + return "xchg"; + case GLX_SWAP_COPY_OML: + return "copy"; + case GLX_SWAP_UNDEFINED_OML: + return " "; + default: + return "????"; + } +} + +static void +fbConfigsDump(unsigned int n, __GLXconfig *c) +{ + ErrorF("%d fbConfigs\n", n); + ErrorF("pxf vis fb render Ste aux accum MS drawable Group/\n"); + ErrorF("idx ID ID VisualType Depth Lvl RGB CI DB Swap reo R G B A Z S buf AR AG AB AA bufs num W P Pb Float Trans Caveat\n"); + ErrorF("-----------------------------------------------------------------------------------------------------------------------------\n"); + + while (c != NULL) + { + unsigned int i = ((GLXWinConfig *)c)->pixelFormatIndex; + + ErrorF("%3d %3x %3x " + "%-11s" + " %3d %3d %s %s %s %s %s " + "%2d %2d %2d %2d " + "%2d %2d " + "%2d " + "%2d %2d %2d %2d" + " %2d %2d" + " %s %s %s " + " %s " + " %s " + " %d %s" + "\n", + i, c->visualID, c->fbconfigID, + visual_class_name(c->visualType), + c->rgbBits ? c->rgbBits : c->indexBits, + c->level, + (c->renderType & GLX_RGBA_BIT) ? "y" : ".", + (c->renderType & GLX_COLOR_INDEX_BIT) ? "y" : ".", + c->doubleBufferMode ? "y" : ".", + swap_method_name(c->swapMethod), + c->stereoMode ? "y" : ".", + c->redBits, c->greenBits, c->blueBits, c->alphaBits, + c->depthBits, c->stencilBits, + c->numAuxBuffers, + c->accumRedBits, c->accumGreenBits, c->accumBlueBits, c->accumAlphaBits, + c->sampleBuffers, c->samples, + (c->drawableType & GLX_WINDOW_BIT) ? "y" : ".", + (c->drawableType & GLX_PIXMAP_BIT) ? "y" : ".", + (c->drawableType & GLX_PBUFFER_BIT) ? "y" : ".", + ".", + (c->transparentPixel != GLX_NONE_EXT) ? "y" : ".", + c->visualSelectGroup, (c->visualRating == GLX_SLOW_VISUAL_EXT) ? "*" : " "); + + c = c->next; + } +} + +/* ---------------------------------------------------------------------- */ +/* + * Forward declarations + */ + +static __GLXscreen *glxWinScreenProbe(ScreenPtr pScreen); +static __GLXcontext *glxWinCreateContext(__GLXscreen *screen, + __GLXconfig *modes, + __GLXcontext *baseShareContext); +static __GLXdrawable *glxWinCreateDrawable(ClientPtr client, + __GLXscreen *screen, + DrawablePtr pDraw, + XID drawId, + int type, + XID glxDrawId, + __GLXconfig *conf); + +static Bool glxWinRealizeWindow(WindowPtr pWin); +static Bool glxWinUnrealizeWindow(WindowPtr pWin); +static void glxWinCopyWindow(WindowPtr pWindow, DDXPointRec ptOldOrg, RegionPtr prgnSrc); + +static HDC glxWinMakeDC(__GLXWinContext *gc, __GLXWinDrawable *draw, HDC *hdc, HWND *hwnd); +static void glxWinReleaseDC(HWND hwnd, HDC hdc, __GLXWinDrawable *draw); + +static void glxWinCreateConfigs(HDC dc, glxWinScreen *screen); +static void glxWinCreateConfigsExt(HDC hdc, glxWinScreen *screen); +static int fbConfigToPixelFormat(__GLXconfig *mode, PIXELFORMATDESCRIPTOR *pfdret, int drawableTypeOverride); +static int fbConfigToPixelFormatIndex(HDC hdc, __GLXconfig *mode, int drawableTypeOverride, glxWinScreen *winScreen); + +/* ---------------------------------------------------------------------- */ +/* + * The GLX provider + */ + +__GLXprovider __glXWGLProvider = { + glxWinScreenProbe, + "Win32 native WGL", + NULL +}; + +void +glxWinPushNativeProvider(void) +{ + GlxPushProvider(&__glXWGLProvider); +} + +/* ---------------------------------------------------------------------- */ +/* + * Screen functions + */ + +static void +glxWinScreenDestroy(__GLXscreen *screen) +{ + GLWIN_DEBUG_MSG("glxWinScreenDestroy(%p)", screen); + __glXScreenDestroy(screen); + free(screen); +} + +static int +glxWinScreenSwapInterval(__GLXdrawable *drawable, int interval) +{ + BOOL ret = wglSwapIntervalEXTWrapper(interval); + if (!ret) + { + ErrorF("wglSwapIntervalEXT interval %d failed:%s\n", interval, glxWinErrorMessage()); + } + return ret; +} + +/* + Report the extensions split and formatted to avoid overflowing a line + */ +static void +glxLogExtensions(const char *prefix, const char *extensions) +{ + int length = 0; + char *strl; + char *str = strdup(extensions); + + if (str == NULL) + { + ErrorF("glxLogExtensions: xalloc error\n"); + return; + } + + strl = strtok(str, " "); + ErrorF("%s%s", prefix, strl); + length = strlen(prefix) + strlen(strl); + + while (1) + { + strl = strtok(NULL, " "); + if (strl == NULL) break; + + if (length + strlen(strl) + 1 > 120) + { + ErrorF("\n"); + ErrorF("%s",prefix); + length = strlen(prefix); + } + else + { + ErrorF(" "); + length++; + } + + ErrorF("%s", strl); + length = length + strlen(strl); + } + + ErrorF("\n"); + + free(str); +} + +/* This is called by GlxExtensionInit() asking the GLX provider if it can handle the screen... */ +static __GLXscreen * +glxWinScreenProbe(ScreenPtr pScreen) +{ + glxWinScreen *screen; + const char *gl_extensions; + const char *wgl_extensions; + HWND hwnd; + HDC hdc; + HGLRC hglrc; + + GLWIN_DEBUG_MSG("glxWinScreenProbe"); + + glxWinInitDebugSettings(); + + if (pScreen == NULL) + return NULL; + + if (!winCheckScreenAiglxIsSupported(pScreen)) + { + LogMessage(X_ERROR,"AIGLX: No native OpenGL in modes with a root window\n"); + return NULL; + } + + screen = calloc(1, sizeof(glxWinScreen)); + + if (NULL == screen) + return NULL; + + /* Wrap RealizeWindow, UnrealizeWindow and CopyWindow on this screen */ + screen->RealizeWindow = pScreen->RealizeWindow; + pScreen->RealizeWindow = glxWinRealizeWindow; + screen->UnrealizeWindow = pScreen->UnrealizeWindow; + pScreen->UnrealizeWindow = glxWinUnrealizeWindow; + screen->CopyWindow = pScreen->CopyWindow; + pScreen->CopyWindow = glxWinCopyWindow; + + /* Dump out some useful information about the native renderer */ + + // create window class +#define WIN_GL_TEST_WINDOW_CLASS "XWinGLTest" + { + static wATOM glTestWndClass = 0; + if (glTestWndClass == 0) + { + WNDCLASSEX wc; + wc.cbSize = sizeof(WNDCLASSEX); + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = DefWindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = GetModuleHandle(NULL); + wc.hIcon = 0; + wc.hCursor = 0; + wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); + wc.lpszMenuName = NULL; + wc.lpszClassName = WIN_GL_TEST_WINDOW_CLASS; + wc.hIconSm = 0; + RegisterClassEx (&wc); + } + } + + // create an invisible window for a scratch DC + hwnd = CreateWindowExA(0, + WIN_GL_TEST_WINDOW_CLASS, + "XWin GL Renderer Capabilities Test Window", + 0, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL); + if (hwnd == NULL) + LogMessage(X_ERROR,"AIGLX: Couldn't create a window for render capabilities testing\n"); + + hdc = GetDC(hwnd); + + // we must set a pixel format before we can create a context, just use the first one... + SetPixelFormat(hdc, 1, NULL); + hglrc = wglCreateContext(hdc); + wglMakeCurrent(hdc, hglrc); + + // initialize wgl extension proc pointers (don't call them before here...) + // (but we need to have a current context for them to be resolvable) + wglResolveExtensionProcs(); + + ErrorF("GL_VERSION: %s\n", glGetStringWrapperNonstatic(GL_VERSION)); + ErrorF("GL_VENDOR: %s\n", glGetStringWrapperNonstatic(GL_VENDOR)); + ErrorF("GL_RENDERER: %s\n", glGetStringWrapperNonstatic(GL_RENDERER)); + gl_extensions = (const char *)glGetStringWrapperNonstatic(GL_EXTENSIONS); + glxLogExtensions("GL_EXTENSIONS: ", gl_extensions); + wgl_extensions = wglGetExtensionsStringARBWrapper(hdc); + if (!wgl_extensions) wgl_extensions = ""; + glxLogExtensions("WGL_EXTENSIONS: ", wgl_extensions); + + // Can you see the problem here? The extensions string is DC specific + // Different DCs for windows on a multimonitor system driven by multiple cards + // might have completely different capabilities. Of course, good luck getting + // those screens to be accelerated in XP and earlier... + + { + // testing facility to not use any WGL extensions + char *envptr = getenv("GLWIN_NO_WGL_EXTENSIONS"); + if ((envptr != NULL) && (atoi(envptr) != 0)) + { + ErrorF("GLWIN_NO_WGL_EXTENSIONS is set, ignoring WGL_EXTENSIONS\n"); + wgl_extensions = ""; + } + } + + { + Bool glx_sgi_make_current_read = FALSE; + + // + // Based on the WGL extensions available, enable various GLX extensions + // XXX: make this table-driven ? + // + memset(screen->glx_enable_bits, 0, __GLX_EXT_BYTES); + + __glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_visual_info"); + __glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_visual_rating"); + __glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_import_context"); + __glXEnableExtension(screen->glx_enable_bits, "GLX_OML_swap_method"); + __glXEnableExtension(screen->glx_enable_bits, "GLX_SGIX_fbconfig"); + + if (strstr(wgl_extensions, "WGL_ARB_make_current_read")) + { + __glXEnableExtension(screen->glx_enable_bits, "GLX_SGI_make_current_read"); + LogMessage(X_INFO, "AIGLX: enabled GLX_SGI_make_current_read\n"); + glx_sgi_make_current_read = TRUE; + } + + if (strstr(gl_extensions, "GL_WIN_swap_hint")) + { + __glXEnableExtension(screen->glx_enable_bits, "GLX_MESA_copy_sub_buffer"); + LogMessage(X_INFO, "AIGLX: enabled GLX_MESA_copy_sub_buffer\n"); + } + + if (strstr(wgl_extensions, "WGL_EXT_swap_control")) + { + __glXEnableExtension(screen->glx_enable_bits, "GLX_SGI_swap_control"); + __glXEnableExtension(screen->glx_enable_bits, "GLX_MESA_swap_control"); + LogMessage(X_INFO, "AIGLX: enabled GLX_SGI_swap_control and GLX_MESA_swap_control\n"); + } + +/* // Hmm? screen->texOffset */ +/* if (strstr(wgl_extensions, "WGL_ARB_render_texture")) */ +/* { */ +/* __glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_texture_from_pixmap"); */ +/* LogMessage(X_INFO, "AIGLX: GLX_EXT_texture_from_pixmap backed by buffer objects\n"); */ +/* screen->has_WGL_ARB_render_texture = TRUE; */ +/* } */ + + if (strstr(wgl_extensions, "WGL_ARB_pbuffer")) + { + __glXEnableExtension(screen->glx_enable_bits, "GLX_SGIX_pbuffer"); + LogMessage(X_INFO, "AIGLX: enabled GLX_SGIX_pbuffer\n"); + screen->has_WGL_ARB_pbuffer = TRUE; + } + + if (strstr(wgl_extensions, "WGL_ARB_multisample")) + { + __glXEnableExtension(screen->glx_enable_bits, "GLX_ARB_multisample"); + __glXEnableExtension(screen->glx_enable_bits, "GLX_SGIS_multisample"); + LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_multisample and GLX_SGIS_multisample\n"); + screen->has_WGL_ARB_multisample = TRUE; + } + + screen->base.destroy = glxWinScreenDestroy; + screen->base.createContext = glxWinCreateContext; + screen->base.createDrawable = glxWinCreateDrawable; + screen->base.swapInterval = glxWinScreenSwapInterval; + screen->base.pScreen = pScreen; + + // Creating the fbConfigs initializes screen->base.fbconfigs and screen->base.numFBConfigs + if (strstr(wgl_extensions, "WGL_ARB_pixel_format")) + { + glxWinCreateConfigsExt(hdc, screen); + + /* + Some graphics drivers appear to advertise WGL_ARB_pixel_format, + but it doesn't work usefully, so we have to be prepared for it + to fail and fall back to using DescribePixelFormat() + */ + if (screen->base.numFBConfigs > 0) + { + screen->has_WGL_ARB_pixel_format = TRUE; + } + } + + if (screen->base.numFBConfigs <= 0) + { + glxWinCreateConfigs(hdc, screen); + screen->has_WGL_ARB_pixel_format = FALSE; + } + + /* + If we still didn't get any fbConfigs, we can't provide GLX for this screen + */ + if (screen->base.numFBConfigs <= 0) + { + free(screen); + LogMessage(X_ERROR,"AIGLX: No fbConfigs could be made from native OpenGL pixel formats\n"); + return NULL; + } + + /* These will be set by __glXScreenInit */ + screen->base.visuals = NULL; + screen->base.numVisuals = 0; + + __glXScreenInit(&screen->base, pScreen); + + // dump out fbConfigs now fbConfigIds and visualIDs have been assigned + fbConfigsDump(screen->base.numFBConfigs, screen->base.fbconfigs); + + // Override the GL extensions string set by __glXScreenInit() + screen->base.GLextensions = strdup(gl_extensions); + + // Generate the GLX extensions string (overrides that set by __glXScreenInit()) + { + unsigned int buffer_size = __glXGetExtensionString(screen->glx_enable_bits, NULL); + if (buffer_size > 0) + { + free(screen->base.GLXextensions); + + screen->base.GLXextensions = xnfalloc(buffer_size); + __glXGetExtensionString(screen->glx_enable_bits, screen->base.GLXextensions); + } + } + + // + // Override the GLX version (__glXScreenInit() sets it to "1.2") + // if we have all the needed extensions to operate as a higher version + // + // SGIX_fbconfig && SGIX_pbuffer && SGI_make_current_read -> 1.3 + // ARB_multisample -> 1.4 + // + if (screen->has_WGL_ARB_pbuffer && glx_sgi_make_current_read) + { + if (screen->has_WGL_ARB_multisample) + { + screen->base.GLXmajor = 1; + screen->base.GLXminor = 4; + } + else + { + screen->base.GLXmajor = 1; + screen->base.GLXminor = 3; + } + } + } + LogMessage(X_INFO, "AIGLX: Set GLX version to %d.%d\n", screen->base.GLXmajor, screen->base.GLXminor); + + wglMakeCurrent(NULL, NULL); + wglDeleteContext(hglrc); + ReleaseDC(hwnd, hdc); + DestroyWindow(hwnd); + + return &screen->base; +} + +/* ---------------------------------------------------------------------- */ +/* + * Window functions + */ + +static Bool +glxWinRealizeWindow(WindowPtr pWin) +{ + Bool result; + ScreenPtr pScreen = pWin->drawable.pScreen; + glxWinScreen *screenPriv = (glxWinScreen *) glxGetScreen(pScreen); + + GLWIN_DEBUG_MSG("glxWinRealizeWindow"); + + /* Allow the window to be created (RootlessRealizeWindow is inside our wrap) */ + pScreen->RealizeWindow = screenPriv->RealizeWindow; + result = pScreen->RealizeWindow(pWin); + pScreen->RealizeWindow = glxWinRealizeWindow; + + return result; +} + + +static void +glxWinCopyWindow(WindowPtr pWindow, DDXPointRec ptOldOrg, RegionPtr prgnSrc) +{ + __GLXWinDrawable *pGlxDraw; + ScreenPtr pScreen = pWindow->drawable.pScreen; + glxWinScreen *screenPriv = (glxWinScreen *) glxGetScreen(pScreen); + + GLWIN_TRACE_MSG("glxWinCopyWindow pWindow %p", pWindow); + + dixLookupResourceByType((pointer) &pGlxDraw, pWindow->drawable.id, __glXDrawableRes, + NullClient, DixUnknownAccess); + + + /* + Discard any CopyWindow requests if a GL drawing context is pointing at the window + + For regions which are being drawn by GL, the shadow framebuffer doesn't have the + correct bits, so we wish to avoid shadow framebuffer damage occuring, which will + cause those incorrect bits to be transferred to the display.... + */ + if (pGlxDraw && pGlxDraw->drawContext) + { + GLWIN_DEBUG_MSG("glxWinCopyWindow: discarding"); + return; + } + + GLWIN_DEBUG_MSG("glxWinCopyWindow - passing to hw layer"); + + pScreen->CopyWindow = screenPriv->CopyWindow; + pScreen->CopyWindow(pWindow, ptOldOrg, prgnSrc); + pScreen->CopyWindow = glxWinCopyWindow; +} + +static Bool +glxWinUnrealizeWindow(WindowPtr pWin) +{ + Bool result; + ScreenPtr pScreen = pWin->drawable.pScreen; + glxWinScreen *screenPriv = (glxWinScreen *)glxGetScreen(pScreen); + + GLWIN_DEBUG_MSG("glxWinUnrealizeWindow"); + + pScreen->UnrealizeWindow = screenPriv->UnrealizeWindow; + result = pScreen->UnrealizeWindow(pWin); + pScreen->UnrealizeWindow = glxWinUnrealizeWindow; + + return result; +} + +/* ---------------------------------------------------------------------- */ +/* + * Drawable functions + */ + +static GLboolean +glxWinDrawableSwapBuffers(ClientPtr client, __GLXdrawable *base) +{ + HDC dc; + HWND hwnd; + BOOL ret; + __GLXWinDrawable *draw = (__GLXWinDrawable *)base; + + /* Swap buffers on the last active context for drawing on the drawable */ + if (draw->drawContext == NULL) + { + GLWIN_TRACE_MSG("glxWinSwapBuffers - no context for drawable"); + return GL_FALSE; + } + + GLWIN_TRACE_MSG("glxWinSwapBuffers on drawable %p, last context %p (native ctx %p)", base, draw->drawContext, draw->drawContext->ctx); + + /* + draw->drawContext->base.drawPriv will not be set if the context is not current anymore, + but if it is, it should point to this drawable.... + */ + assert((draw->drawContext->base.drawPriv == NULL) || (draw->drawContext->base.drawPriv == base)); + + dc = glxWinMakeDC(draw->drawContext, draw, &dc, &hwnd); + if (dc == NULL) + return GL_FALSE; + + ret = wglSwapLayerBuffers(dc, WGL_SWAP_MAIN_PLANE); + + glxWinReleaseDC(hwnd, dc, draw); + + if (!ret) + { + ErrorF("wglSwapBuffers failed: %s\n", glxWinErrorMessage()); + return GL_FALSE; + } + + return GL_TRUE; +} + +static void +glxWinDrawableCopySubBuffer(__GLXdrawable *drawable, + int x, int y, int w, int h) +{ + glAddSwapHintRectWINWrapperNonstatic(x, y, w, h); + glxWinDrawableSwapBuffers(NULL, drawable); +} + +static void +glxWinDrawableDestroy(__GLXdrawable *base) +{ + __GLXWinDrawable *glxPriv = (__GLXWinDrawable *)base; + + if (glxPriv->drawContext && (__glXLastContext == &((glxPriv->drawContext)->base))) + { + // if this context is current and has unflushed commands, say we have flushed them + // (don't actually flush them, the window is going away anyhow, and an implict flush occurs + // on the next context change) + // (GLX core considers it an error when we try to select a new current context if the old one + // has unflushed commands, but the window has disappeared..) + __glXLastContext->hasUnflushedCommands = FALSE; + __glXLastContext = NULL; + } + + if (glxPriv->hPbuffer) + if (!wglDestroyPbufferARBWrapper(glxPriv->hPbuffer)) + { + ErrorF("wglDestroyPbufferARB failed: %s\n", glxWinErrorMessage()); + } + + if (glxPriv->dibDC) + { + // restore the default DIB + SelectObject(glxPriv->dibDC, glxPriv->hOldDIB); + + if (!DeleteDC(glxPriv->dibDC)) + { + ErrorF("DeleteDC failed: %s\n", glxWinErrorMessage()); + } + } + + if (glxPriv->hDIB) + { + if (!DeleteObject(glxPriv->hDIB)) + { + ErrorF("DeleteObject failed: %s\n", glxWinErrorMessage()); + } + + ((PixmapPtr)glxPriv->base.pDraw)->devPrivate.ptr = glxPriv->pOldBits; + } + + GLWIN_DEBUG_MSG("glxWinDestroyDrawable"); + free(glxPriv); +} + +static __GLXdrawable * +glxWinCreateDrawable(ClientPtr client, + __GLXscreen *screen, + DrawablePtr pDraw, + XID drawId, + int type, + XID glxDrawId, + __GLXconfig *conf) +{ + __GLXWinDrawable *glxPriv; + + glxPriv = malloc(sizeof *glxPriv); + + if (glxPriv == NULL) + return NULL; + + memset(glxPriv, 0, sizeof *glxPriv); + + if(!__glXDrawableInit(&glxPriv->base, screen, pDraw, type, glxDrawId, conf)) { + free(glxPriv); + return NULL; + } + + glxPriv->base.destroy = glxWinDrawableDestroy; + glxPriv->base.swapBuffers = glxWinDrawableSwapBuffers; + glxPriv->base.copySubBuffer = glxWinDrawableCopySubBuffer; + // glxPriv->base.waitX what are these for? + // glxPriv->base.waitGL + + GLWIN_DEBUG_MSG("glxWinCreateDrawable %p", glxPriv); + + return &glxPriv->base; +} + +/* ---------------------------------------------------------------------- */ +/* + * Texture functions + */ + +static +int glxWinBindTexImage(__GLXcontext *baseContext, + int buffer, + __GLXdrawable *pixmap) +{ + ErrorF("glxWinBindTexImage: not implemented\n"); + return FALSE; +} + +static +int glxWinReleaseTexImage(__GLXcontext *baseContext, + int buffer, + __GLXdrawable *pixmap) +{ + ErrorF(" glxWinReleaseTexImage: not implemented\n"); + return FALSE; +} + +/* ---------------------------------------------------------------------- */ +/* + * Lazy update context implementation + * + * WGL contexts are created for a specific HDC, so we cannot create the WGL + * context in glxWinCreateContext(), we must defer creation until the context + * is actually used on a specifc drawable which is connected to a native window, + * pbuffer or DIB + * + * The WGL context may be used on other, compatible HDCs, so we don't need to + * recreate it for every new native window + * + * XXX: I wonder why we can't create the WGL context on the screen HDC ? + * Basically we assume all HDCs are compatible at the moment: if they are not + * we are in a muddle, there was some code in the old implementation to attempt + * to transparently migrate a context to a new DC by copying state and sharing + * lists with the old one... + */ + +static Bool +glxWinSetPixelFormat(__GLXWinContext *gc, HDC hdc, int bppOverride, int drawableTypeOverride) +{ + __GLXscreen *screen = gc->base.pGlxScreen; + glxWinScreen *winScreen = (glxWinScreen *)screen; + + __GLXconfig *config = gc->base.config; + GLXWinConfig *winConfig = (GLXWinConfig *)config; + + GLWIN_DEBUG_MSG("glxWinSetPixelFormat: pixelFormatIndex %d", winConfig->pixelFormatIndex); + + /* + Normally, we can just use the the pixelFormatIndex corresponding + to the fbconfig which has been specified by the client + */ + + if (!((bppOverride && (bppOverride != (config->redBits + config->greenBits + config->blueBits) )) + || ((config->drawableType & drawableTypeOverride) == 0))) + { + if (!SetPixelFormat(hdc, winConfig->pixelFormatIndex, NULL)) + { + ErrorF("SetPixelFormat error: %s\n", glxWinErrorMessage()); + return FALSE; + } + + return TRUE; + } + + /* + However, in certain special cases this pixel format will be incompatible with the + use we are going to put it to, so we need to re-evaluate the pixel format to use: + + 1) When PFD_DRAW_TO_BITMAP is set, ChoosePixelFormat() always returns a format with + the cColorBits we asked for, so we need to ensure it matches the bpp of the bitmap + + 2) Applications may assume that visuals selected with glXChooseVisual() work with + pixmap drawables (there is no attribute to explicitly query for pixmap drawable + support as there is for glXChooseFBConfig()) + (it's arguable this is an error in the application, but we try to make it work) + + pixmap rendering is always slow for us, so we don't want to choose those visuals + by default, but if the actual drawable type we're trying to select the context + on (drawableTypeOverride) isn't supported by the selected fbConfig, reconsider + and see if we can find a suitable one... + */ + ErrorF("glxWinSetPixelFormat: having second thoughts: cColorbits %d, bppOveride %d; config->drawableType %d, drawableTypeOverride %d\n", + (config->redBits + config->greenBits + config->blueBits), bppOverride, config->drawableType, drawableTypeOverride); + + if (!winScreen->has_WGL_ARB_pixel_format) + { + PIXELFORMATDESCRIPTOR pfd; + int pixelFormat; + + /* convert fbConfig to PFD */ + if (fbConfigToPixelFormat(gc->base.config, &pfd, drawableTypeOverride)) + { + ErrorF("glxWinSetPixelFormat: fbConfigToPixelFormat failed\n"); + return FALSE; + } + + if (glxWinDebugSettings.dumpPFD) + pfdOut(&pfd); + + if (bppOverride) + { + GLWIN_DEBUG_MSG("glxWinSetPixelFormat: Forcing bpp from %d to %d\n", pfd.cColorBits, bppOverride); + pfd.cColorBits = bppOverride; + } + + pixelFormat = ChoosePixelFormat(hdc, &pfd); + if (pixelFormat == 0) + { + ErrorF("ChoosePixelFormat error: %s\n", glxWinErrorMessage()); + return FALSE; + } + + GLWIN_DEBUG_MSG("ChoosePixelFormat: chose pixelFormatIndex %d", pixelFormat); + ErrorF("ChoosePixelFormat: chose pixelFormatIndex %d (rather than %d as originally planned)\n", pixelFormat, winConfig->pixelFormatIndex); + + if (!SetPixelFormat(hdc, pixelFormat, &pfd)) + { + ErrorF("SetPixelFormat error: %s\n", glxWinErrorMessage()); + return FALSE; + } + } + else + { + int pixelFormat = fbConfigToPixelFormatIndex(hdc, gc->base.config, drawableTypeOverride, winScreen); + if (pixelFormat == 0) + { + ErrorF("wglChoosePixelFormat error: %s\n", glxWinErrorMessage()); + return FALSE; + } + + GLWIN_DEBUG_MSG("wglChoosePixelFormat: chose pixelFormatIndex %d", pixelFormat); + ErrorF("wglChoosePixelFormat: chose pixelFormatIndex %d (rather than %d as originally planned)\n", pixelFormat, winConfig->pixelFormatIndex); + + if (!SetPixelFormat(hdc, pixelFormat, NULL)) + { + ErrorF("SetPixelFormat error: %s\n", glxWinErrorMessage()); + return FALSE; + } + } + + return TRUE; +} + +static HDC +glxWinMakeDC(__GLXWinContext *gc, __GLXWinDrawable *draw, HDC *hdc, HWND *hwnd) +{ + *hdc = NULL; + *hwnd = NULL; + + if (draw == NULL) + { + GLWIN_TRACE_MSG("No drawable for context %p (native ctx %p)", gc, gc->ctx); + return NULL; + } + + switch (draw->base.type) + { + case GLX_DRAWABLE_WINDOW: + { + WindowPtr pWin; + + pWin = (WindowPtr) draw->base.pDraw; + if (pWin == NULL) + { + GLWIN_TRACE_MSG("for drawable %p, no WindowPtr", pWin); + return NULL; + } + + *hwnd = winGetWindowInfo(pWin); + + if (*hwnd == NULL) + { + ErrorF("No HWND error: %s\n", glxWinErrorMessage()); + return NULL; + } + + *hdc = GetDC(*hwnd); + + if (*hdc == NULL) + ErrorF("GetDC error: %s\n", glxWinErrorMessage()); + + /* Check if the hwnd has changed... */ + if (*hwnd != gc->hwnd) + { + if (glxWinDebugSettings.enableTrace) + GLWIN_DEBUG_HWND(*hwnd); + + GLWIN_TRACE_MSG("for context %p (native ctx %p), hWnd changed from %p to %p", gc, gc->ctx, gc->hwnd, *hwnd); + gc->hwnd = *hwnd; + + /* We must select a pixelformat, but SetPixelFormat can only be called once for a window... */ + if (!glxWinSetPixelFormat(gc, *hdc, 0, GLX_WINDOW_BIT)) + { + ErrorF("glxWinSetPixelFormat error: %s\n", glxWinErrorMessage()); + ReleaseDC(*hwnd, *hdc); + *hdc = NULL; + return NULL; + } + } + } + break; + + case GLX_DRAWABLE_PBUFFER: + { + *hdc = wglGetPbufferDCARBWrapper(draw->hPbuffer); + + if (*hdc == NULL) + ErrorF("GetDC (pbuffer) error: %s\n", glxWinErrorMessage()); + } + break; + + case GLX_DRAWABLE_PIXMAP: + { + *hdc = draw->dibDC; + } + break; + + default: + { + ErrorF("glxWinMakeDC: tried to makeDC for unhandled drawable type %d\n", draw->base.type); + } + } + + if (glxWinDebugSettings.dumpDC) + GLWIN_DEBUG_MSG("Got HDC %p", *hdc); + + return *hdc; +} + +static void +glxWinReleaseDC(HWND hwnd, HDC hdc,__GLXWinDrawable *draw) +{ + switch (draw->base.type) + { + case GLX_DRAWABLE_WINDOW: + { + ReleaseDC(hwnd, hdc); + } + break; + + case GLX_DRAWABLE_PBUFFER: + { + if (!wglReleasePbufferDCARBWrapper(draw->hPbuffer, hdc)) + { + ErrorF("wglReleasePbufferDCARB error: %s\n", glxWinErrorMessage()); + } + } + break; + + case GLX_DRAWABLE_PIXMAP: + { + // don't release DC, the memory DC lives as long as the bitmap + + // We must ensure that all GDI drawing into the bitmap has completed + // in case we subsequently access the bits from it + GdiFlush(); + } + break; + + default: + { + ErrorF("glxWinReleaseDC: tried to releaseDC for unhandled drawable type %d\n", draw->base.type); + } + } +} + +static void +glxWinDeferredCreateContext(__GLXWinContext *gc, __GLXWinDrawable *draw) +{ + HDC dc; + HWND hwnd; + GLWIN_DEBUG_MSG("glxWinDeferredCreateContext: attach context %p to drawable %p", gc, draw); + + switch (draw->base.type) + { + case GLX_DRAWABLE_WINDOW: + { + WindowPtr pWin = (WindowPtr) draw->base.pDraw; + + if (!(gc->base.config->drawableType & GLX_WINDOW_BIT)) + { + ErrorF("glxWinDeferredCreateContext: tried to attach a context whose fbConfig doesn't have drawableType GLX_WINDOW_BIT to a GLX_DRAWABLE_WINDOW drawable\n"); + } + + if (pWin == NULL) + { + GLWIN_DEBUG_MSG("Deferring until X window is created"); + return; + } + + GLWIN_DEBUG_MSG("glxWinDeferredCreateContext: pWin %p", pWin); + + if (winGetWindowInfo(pWin) == NULL) + { + GLWIN_DEBUG_MSG("Deferring until native window is created"); + return; + } + } + break; + + case GLX_DRAWABLE_PBUFFER: + { + if (draw->hPbuffer == NULL) + { + __GLXscreen *screen; + glxWinScreen *winScreen; + int pixelFormat; + // XXX: which DC are supposed to use??? + HDC screenDC = GetDC(NULL); + + if (!(gc->base.config->drawableType & GLX_PBUFFER_BIT)) + { + ErrorF("glxWinDeferredCreateContext: tried to attach a context whose fbConfig doesn't have drawableType GLX_PBUFFER_BIT to a GLX_DRAWABLE_PBUFFER drawable\n"); + } + + screen = gc->base.pGlxScreen; + winScreen = (glxWinScreen *)screen; + + pixelFormat = fbConfigToPixelFormatIndex(screenDC, gc->base.config, GLX_DRAWABLE_PBUFFER, winScreen); + if (pixelFormat == 0) + { + ErrorF("wglChoosePixelFormat error: %s\n", glxWinErrorMessage()); + return; + } + + draw->hPbuffer = wglCreatePbufferARBWrapper(screenDC, pixelFormat, draw->base.pDraw->width, draw->base.pDraw->height, NULL); + ReleaseDC(NULL, screenDC); + + if (draw->hPbuffer == NULL) + { + ErrorF("wglCreatePbufferARBWrapper error: %s\n", glxWinErrorMessage()); + return; + } + + GLWIN_DEBUG_MSG("glxWinDeferredCreateContext: pBuffer %p created for drawable %p", draw->hPbuffer, draw); + } + } + break; + + case GLX_DRAWABLE_PIXMAP: + { + if (draw->dibDC == NULL) + { + BITMAPINFOHEADER bmpHeader; + void *pBits; + + memset (&bmpHeader, 0, sizeof(BITMAPINFOHEADER)); + bmpHeader.biSize = sizeof(BITMAPINFOHEADER); + bmpHeader.biWidth = draw->base.pDraw->width; + bmpHeader.biHeight = draw->base.pDraw->height; + bmpHeader.biPlanes = 1; + bmpHeader.biBitCount = draw->base.pDraw->bitsPerPixel; + bmpHeader.biCompression = BI_RGB; + + if (!(gc->base.config->drawableType & GLX_PIXMAP_BIT)) + { + ErrorF("glxWinDeferredCreateContext: tried to attach a context whose fbConfig doesn't have drawableType GLX_PIXMAP_BIT to a GLX_DRAWABLE_PIXMAP drawable\n"); + } + + draw->dibDC = CreateCompatibleDC(NULL); + if (draw->dibDC == NULL) + { + ErrorF("CreateCompatibleDC error: %s\n", glxWinErrorMessage()); + return; + } + + draw->hDIB = CreateDIBSection(draw->dibDC, (BITMAPINFO *)&bmpHeader, DIB_RGB_COLORS, &pBits, 0, 0); + if (draw->dibDC == NULL) + { + ErrorF("CreateDIBSection error: %s\n", glxWinErrorMessage()); + return; + } + + // XXX: CreateDIBSection insists on allocating the bitmap memory for us, so we're going to + // need some jiggery pokery to point the underlying X Drawable's bitmap at the same set of bits + // so that they can be read with XGetImage as well as glReadPixels, assuming the formats are + // even compatible ... + draw->pOldBits = ((PixmapPtr)draw->base.pDraw)->devPrivate.ptr; + ((PixmapPtr)draw->base.pDraw)->devPrivate.ptr = pBits; + + // Select the DIB into the DC + draw->hOldDIB = SelectObject(draw->dibDC, draw->hDIB); + if (!draw->hOldDIB) + { + ErrorF("SelectObject error: %s\n", glxWinErrorMessage()); + } + + // Set the pixel format of the bitmap + glxWinSetPixelFormat(gc, draw->dibDC, draw->base.pDraw->bitsPerPixel, GLX_PIXMAP_BIT); + + GLWIN_DEBUG_MSG("glxWinDeferredCreateContext: DIB bitmap %p created for drawable %p", draw->hDIB, draw); + } + } + break; + + default: + { + ErrorF("glxWinDeferredCreateContext: tried to attach unhandled drawable type %d\n", draw->base.type); + return; + } + } + + dc = glxWinMakeDC(gc, draw, &dc, &hwnd); + gc->ctx = wglCreateContext(dc); + glxWinReleaseDC(hwnd, dc, draw); + + if (gc->ctx == NULL) + { + ErrorF("wglCreateContext error: %s\n", glxWinErrorMessage()); + return; + } + + GLWIN_DEBUG_MSG("glxWinDeferredCreateContext: attached context %p to native context %p drawable %p", gc, gc->ctx, draw); + + // if the native context was created successfully, shareLists if needed + if (gc->ctx && gc->shareContext) + { + GLWIN_DEBUG_MSG("glxWinCreateContextReal shareLists with context %p (native ctx %p)", gc->shareContext, gc->shareContext->ctx); + + if (!wglShareLists(gc->shareContext->ctx, gc->ctx)) + { + ErrorF("wglShareLists error: %s\n", glxWinErrorMessage()); + } + } +} + +/* ---------------------------------------------------------------------- */ +/* + * Context functions + */ + + +/* Context manipulation routines should return TRUE on success, FALSE on failure */ +static int +glxWinContextMakeCurrent(__GLXcontext *base) +{ + __GLXWinContext *gc = (__GLXWinContext *)base; + BOOL ret; + HDC drawDC; + HDC readDC = NULL; + __GLXdrawable *drawPriv; + __GLXdrawable *readPriv = NULL; + HWND hDrawWnd; + HWND hReadWnd; + + GLWIN_TRACE_MSG("glxWinContextMakeCurrent context %p (native ctx %p)", gc, gc->ctx); + glWinCallDelta(); + + /* Keep a note of the last active context in the drawable */ + drawPriv = gc->base.drawPriv; + ((__GLXWinDrawable *)drawPriv)->drawContext = gc; + + if (gc->ctx == NULL) + { + glxWinDeferredCreateContext(gc, (__GLXWinDrawable *)drawPriv); + } + + if (gc->ctx == NULL) + { + ErrorF("glxWinContextMakeCurrent: Native context is NULL\n"); + return FALSE; + } + + drawDC = glxWinMakeDC(gc, (__GLXWinDrawable *)drawPriv, &drawDC, &hDrawWnd); + if (drawDC == NULL) + { + ErrorF("glxWinMakeDC failed for drawDC\n"); + return FALSE; + } + + if ((gc->base.readPriv != NULL) && (gc->base.readPriv != gc->base.drawPriv)) + { + // XXX: should only occur with WGL_ARB_make_current_read + /* + If there is a separate read drawable, create a separate read DC, and + use the wglMakeContextCurrent extension to make the context current drawing + to one DC and reading from the other + */ + readPriv = gc->base.readPriv; + readDC = glxWinMakeDC(gc, (__GLXWinDrawable *)readPriv, &readDC, &hReadWnd); + if (readDC == NULL) + { + ErrorF("glxWinMakeDC failed for readDC\n"); + glxWinReleaseDC(hDrawWnd, drawDC, (__GLXWinDrawable *)drawPriv); + return FALSE; + } + + ret = wglMakeContextCurrentARBWrapper(drawDC, readDC, gc->ctx); + if (!ret) + { + ErrorF("wglMakeContextCurrentARBWrapper error: %s\n", glxWinErrorMessage()); + } + } + else + { + /* Otherwise, just use wglMakeCurrent */ + ret = wglMakeCurrent(drawDC, gc->ctx); + if (!ret) + { + ErrorF("wglMakeCurrent error: %s\n", glxWinErrorMessage()); + } + } + + // apparently make current could fail if the context is current in a different thread, + // but that shouldn't be able to happen in the current server... + + glxWinReleaseDC(hDrawWnd, drawDC, (__GLXWinDrawable *)drawPriv); + if (readDC) + glxWinReleaseDC(hReadWnd, readDC, (__GLXWinDrawable *)readPriv); + + return ret; +} + +static int +glxWinContextLoseCurrent(__GLXcontext *base) +{ + BOOL ret; + __GLXWinContext *gc = (__GLXWinContext *)base; + + GLWIN_TRACE_MSG("glxWinContextLoseCurrent context %p (native ctx %p)", gc, gc->ctx); + glWinCallDelta(); + + /* + An error seems to be reported if we try to make no context current + if there is already no current context, so avoid doing that... + */ + if (__glXLastContext != NULL) + { + ret = wglMakeCurrent(NULL, NULL); /* We don't need a DC when setting no current context */ + if (!ret) + ErrorF("glxWinContextLoseCurrent error: %s\n", glxWinErrorMessage()); + } + + return TRUE; +} + +static int +glxWinContextCopy(__GLXcontext *dst_base, __GLXcontext *src_base, unsigned long mask) +{ + __GLXWinContext *dst = (__GLXWinContext *)dst_base; + __GLXWinContext *src = (__GLXWinContext *)src_base; + BOOL ret; + + GLWIN_DEBUG_MSG("glxWinContextCopy"); + + ret = wglCopyContext(src->ctx, dst->ctx, mask); + if (!ret) + { + ErrorF("wglCopyContext error: %s\n", glxWinErrorMessage()); + } + + return ret; +} + +static void +glxWinContextDestroy(__GLXcontext *base) +{ + __GLXWinContext *gc = (__GLXWinContext *)base; + + if (gc != NULL) + { + GLWIN_DEBUG_MSG("GLXcontext %p destroyed (native ctx %p)", base, gc->ctx); + + if (gc->ctx) + { + /* It's bad style to delete the context while it's still current */ + if (wglGetCurrentContext() == gc->ctx) + { + wglMakeCurrent(NULL, NULL); + } + + { + BOOL ret = wglDeleteContext(gc->ctx); + if (!ret) + ErrorF("wglDeleteContext error: %s\n", glxWinErrorMessage()); + } + + gc->ctx = NULL; + } + + free(gc); + } +} + +static __GLXcontext * +glxWinCreateContext(__GLXscreen *screen, + __GLXconfig *modes, + __GLXcontext *baseShareContext) +{ + __GLXWinContext *context; + __GLXWinContext *shareContext = (__GLXWinContext *)baseShareContext; + + static __GLXtextureFromPixmap glxWinTextureFromPixmap = + { + glxWinBindTexImage, + glxWinReleaseTexImage + }; + + context = (__GLXWinContext *)calloc(1, sizeof(__GLXWinContext)); + + if (!context) + return NULL; + + memset(context, 0, sizeof *context); + context->base.destroy = glxWinContextDestroy; + context->base.makeCurrent = glxWinContextMakeCurrent; + context->base.loseCurrent = glxWinContextLoseCurrent; + context->base.copy = glxWinContextCopy; + context->base.textureFromPixmap = &glxWinTextureFromPixmap; + context->base.config = modes; + context->base.pGlxScreen = screen; + + // actual native GL context creation is deferred until attach() + context->ctx = NULL; + context->shareContext = shareContext; + + glWinSetupDispatchTable(); + + GLWIN_DEBUG_MSG("GLXcontext %p created", context); + + return &(context->base); +} + +/* ---------------------------------------------------------------------- */ +/* + * Utility functions + */ + +static int +fbConfigToPixelFormat(__GLXconfig *mode, PIXELFORMATDESCRIPTOR *pfdret, int drawableTypeOverride) +{ + PIXELFORMATDESCRIPTOR pfd = { + sizeof(PIXELFORMATDESCRIPTOR), /* size of this pfd */ + 1, /* version number */ + PFD_SUPPORT_OPENGL, /* support OpenGL */ + PFD_TYPE_RGBA, /* RGBA type */ + 24, /* 24-bit color depth */ + 0, 0, 0, 0, 0, 0, /* color bits ignored */ + 0, /* no alpha buffer */ + 0, /* shift bit ignored */ + 0, /* no accumulation buffer */ + 0, 0, 0, 0, /* accum bits ignored */ + 32, /* 32-bit z-buffer */ + 0, /* no stencil buffer */ + 0, /* no auxiliary buffer */ + PFD_MAIN_PLANE, /* main layer */ + 0, /* reserved */ + 0, 0, 0 /* layer masks ignored */ + }; + + if ((mode->drawableType | drawableTypeOverride) & GLX_WINDOW_BIT) + pfd.dwFlags |= PFD_DRAW_TO_WINDOW; /* support window */ + + if ((mode->drawableType | drawableTypeOverride) & GLX_PIXMAP_BIT) + pfd.dwFlags |= (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI); /* supports software rendering to bitmap */ + + if (mode->stereoMode) { + pfd.dwFlags |= PFD_STEREO; + } + if (mode->doubleBufferMode) { + pfd.dwFlags |= PFD_DOUBLEBUFFER; + } + + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.cColorBits = mode->redBits + mode->greenBits + mode->blueBits; + pfd.cRedBits = mode->redBits; + pfd.cRedShift = 0; /* FIXME */ + pfd.cGreenBits = mode->greenBits; + pfd.cGreenShift = 0; /* FIXME */ + pfd.cBlueBits = mode->blueBits; + pfd.cBlueShift = 0; /* FIXME */ + pfd.cAlphaBits = mode->alphaBits; + pfd.cAlphaShift = 0; /* FIXME */ + + pfd.cAccumBits = mode->accumRedBits + mode->accumGreenBits + mode->accumBlueBits + mode->accumAlphaBits; + pfd.cAccumRedBits = mode->accumRedBits; + pfd.cAccumGreenBits = mode->accumGreenBits; + pfd.cAccumBlueBits = mode->accumBlueBits; + pfd.cAccumAlphaBits = mode->accumAlphaBits; + + pfd.cDepthBits = mode->depthBits; + pfd.cStencilBits = mode->stencilBits; + pfd.cAuxBuffers = mode->numAuxBuffers; + + /* mode->level ? */ + /* mode->pixmapMode ? */ + + *pfdret = pfd; + + return 0; +} + +#define SET_ATTR_VALUE(attr, value) { attribList[i++] = attr; attribList[i++] = value; assert(i < NUM_ELEMENTS(attribList)); } + +static int +fbConfigToPixelFormatIndex(HDC hdc, __GLXconfig *mode, int drawableTypeOverride, glxWinScreen *winScreen) +{ + UINT numFormats; + unsigned int i = 0; + + /* convert fbConfig to attr-value list */ + int attribList[60]; + + SET_ATTR_VALUE(WGL_SUPPORT_OPENGL_ARB, TRUE); + SET_ATTR_VALUE(WGL_PIXEL_TYPE_ARB, (mode->visualType == GLX_TRUE_COLOR) ? WGL_TYPE_RGBA_ARB : WGL_TYPE_COLORINDEX_ARB); + SET_ATTR_VALUE(WGL_COLOR_BITS_ARB, (mode->visualType == GLX_TRUE_COLOR) ? mode->rgbBits : mode->indexBits); + SET_ATTR_VALUE(WGL_RED_BITS_ARB, mode->redBits); + SET_ATTR_VALUE(WGL_GREEN_BITS_ARB, mode->greenBits); + SET_ATTR_VALUE(WGL_BLUE_BITS_ARB, mode->blueBits); + SET_ATTR_VALUE(WGL_ALPHA_BITS_ARB, mode->alphaBits); + SET_ATTR_VALUE(WGL_ACCUM_RED_BITS_ARB, mode->accumRedBits); + SET_ATTR_VALUE(WGL_ACCUM_GREEN_BITS_ARB, mode->accumGreenBits); + SET_ATTR_VALUE(WGL_ACCUM_BLUE_BITS_ARB, mode->accumBlueBits); + SET_ATTR_VALUE(WGL_ACCUM_ALPHA_BITS_ARB, mode->accumAlphaBits); + SET_ATTR_VALUE(WGL_DEPTH_BITS_ARB, mode->depthBits); + SET_ATTR_VALUE(WGL_STENCIL_BITS_ARB, mode->stencilBits); + SET_ATTR_VALUE(WGL_AUX_BUFFERS_ARB, mode->numAuxBuffers); + + if (mode->doubleBufferMode) + SET_ATTR_VALUE(WGL_DOUBLE_BUFFER_ARB, TRUE); + + if (mode->stereoMode) + SET_ATTR_VALUE(WGL_STEREO_ARB, TRUE); + + // Some attributes are only added to the list if the value requested is not 'don't care', as exactly matching that is daft.. + if (mode->swapMethod == GLX_SWAP_EXCHANGE_OML) + SET_ATTR_VALUE(WGL_SWAP_METHOD_ARB, WGL_SWAP_EXCHANGE_ARB); + + if (mode->swapMethod == GLX_SWAP_COPY_OML) + SET_ATTR_VALUE(WGL_SWAP_COPY_ARB, TRUE); + + // XXX: this should probably be the other way around, but that messes up drawableTypeOverride + if (mode->visualRating == GLX_SLOW_VISUAL_EXT) + SET_ATTR_VALUE(WGL_ACCELERATION_ARB, WGL_NO_ACCELERATION_ARB); + + // must support all the drawable types the mode supports + if ((mode->drawableType | drawableTypeOverride) & GLX_WINDOW_BIT) + SET_ATTR_VALUE(WGL_DRAW_TO_WINDOW_ARB,TRUE); + + // XXX: this is a horrible hacky heuristic, in fact this whole drawableTypeOverride thing is a bad idea + // try to avoid asking for formats which don't exist (by not asking for all when adjusting the config to include the drawableTypeOverride) + if (drawableTypeOverride == GLX_WINDOW_BIT) + { + if (mode->drawableType & GLX_PIXMAP_BIT) + SET_ATTR_VALUE(WGL_DRAW_TO_BITMAP_ARB, TRUE); + + if (mode->drawableType & GLX_PBUFFER_BIT) + if (winScreen->has_WGL_ARB_pbuffer) + SET_ATTR_VALUE(WGL_DRAW_TO_PBUFFER_ARB, TRUE); + } + else + { + if (drawableTypeOverride & GLX_PIXMAP_BIT) + SET_ATTR_VALUE(WGL_DRAW_TO_BITMAP_ARB, TRUE); + + if (drawableTypeOverride & GLX_PBUFFER_BIT) + if (winScreen->has_WGL_ARB_pbuffer) + SET_ATTR_VALUE(WGL_DRAW_TO_PBUFFER_ARB, TRUE); + } + + SET_ATTR_VALUE(0, 0); // terminator + + /* choose the first match */ + { + int pixelFormatIndex; + + if (!wglChoosePixelFormatARBWrapper(hdc, attribList, NULL, 1, &pixelFormatIndex, &numFormats)) + { + ErrorF("wglChoosePixelFormat error: %s\n", glxWinErrorMessage()); + } + else + { + if (numFormats > 0) + { + GLWIN_DEBUG_MSG("wglChoosePixelFormat: chose pixelFormatIndex %d)", pixelFormatIndex); + return pixelFormatIndex; + } + else + ErrorF("wglChoosePixelFormat couldn't decide\n"); + } + } + + return 0; +} + +/* ---------------------------------------------------------------------- */ + +#define BITS_AND_SHIFT_TO_MASK(bits,mask) (((1<<(bits))-1) << (mask)) + +// +// Create the GLXconfigs using DescribePixelFormat() +// +static void +glxWinCreateConfigs(HDC hdc, glxWinScreen *screen) +{ + GLXWinConfig *c, *result, *prev = NULL; + int numConfigs = 0; + int i = 0; + int n = 0; + PIXELFORMATDESCRIPTOR pfd; + + GLWIN_DEBUG_MSG("glxWinCreateConfigs"); + + screen->base.numFBConfigs = 0; + screen->base.fbconfigs = NULL; + + // get the number of pixelformats + numConfigs = DescribePixelFormat(hdc, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL); + GLWIN_DEBUG_MSG("DescribePixelFormat says %d possible pixel formats", numConfigs); + + /* alloc */ + result = malloc(sizeof(GLXWinConfig) * numConfigs); + + if (NULL == result) + { + return; + } + + memset(result, 0, sizeof(GLXWinConfig) * numConfigs); + n = 0; + + /* fill in configs */ + for (i = 0; i < numConfigs; i++) + { + int rc; + + c = &(result[i]); + c->base.next = NULL; + c->pixelFormatIndex = i+1; + + rc = DescribePixelFormat(hdc, i+1, sizeof(PIXELFORMATDESCRIPTOR), &pfd); + + if (!rc) + { + ErrorF("DescribePixelFormat failed for index %d, error %s\n", i+1, glxWinErrorMessage()); + break; + } + + if (glxWinDebugSettings.dumpPFD) + pfdOut(&pfd); + + if (!(pfd.dwFlags & (PFD_DRAW_TO_WINDOW | PFD_DRAW_TO_BITMAP)) || !(pfd.dwFlags & PFD_SUPPORT_OPENGL)) + { + GLWIN_DEBUG_MSG("pixelFormat %d has unsuitable flags 0x%08lx, skipping", i+1, pfd.dwFlags); + continue; + } + + c->base.doubleBufferMode = (pfd.dwFlags & PFD_DOUBLEBUFFER) ? GL_TRUE : GL_FALSE; + c->base.stereoMode = (pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE; + + c->base.redBits = pfd.cRedBits; + c->base.greenBits = pfd.cGreenBits; + c->base.blueBits = pfd.cBlueBits; + c->base.alphaBits = pfd.cAlphaBits; + + c->base.redMask = BITS_AND_SHIFT_TO_MASK(pfd.cRedBits, pfd.cRedShift); + c->base.greenMask = BITS_AND_SHIFT_TO_MASK(pfd.cGreenBits, pfd.cGreenShift); + c->base.blueMask = BITS_AND_SHIFT_TO_MASK(pfd.cBlueBits, pfd.cBlueShift); + c->base.alphaMask = BITS_AND_SHIFT_TO_MASK(pfd.cAlphaBits, pfd.cAlphaShift); + + c->base.rgbBits = pfd.cColorBits; + + if (pfd.iPixelType == PFD_TYPE_COLORINDEX) + { + c->base.indexBits = pfd.cColorBits; + } + else + { + c->base.indexBits = 0; + } + + c->base.accumRedBits = pfd.cAccumRedBits; + c->base.accumGreenBits = pfd.cAccumGreenBits; + c->base.accumBlueBits = pfd.cAccumBlueBits; + c->base.accumAlphaBits = pfd.cAccumAlphaBits; + // pfd.cAccumBits; + + c->base.depthBits = pfd.cDepthBits; + c->base.stencilBits = pfd.cStencilBits; + c->base.numAuxBuffers = pfd.cAuxBuffers; + + // pfd.iLayerType; // ignored + c->base.level = 0; + // pfd.dwLayerMask; // ignored + // pfd.dwDamageMask; // ignored + + c->base.pixmapMode = 0; + c->base.visualID = -1; // will be set by __glXScreenInit() + + /* EXT_visual_rating / GLX 1.2 */ + if (pfd.dwFlags & PFD_GENERIC_FORMAT) + { + c->base.visualRating = GLX_SLOW_VISUAL_EXT; + } + else + { + // PFD_GENERIC_ACCELERATED is not considered, so this may be MCD or ICD acclerated... + c->base.visualRating = GLX_NONE_EXT; + } + + /* EXT_visual_info / GLX 1.2 */ + if (pfd.iPixelType == PFD_TYPE_COLORINDEX) + { + c->base.visualType = GLX_STATIC_COLOR; + + if (!getenv("GLWIN_ENABLE_COLORINDEX_FBCONFIGS")) + { + GLWIN_DEBUG_MSG("pixelFormat %d is PFD_TYPE_COLORINDEX, skipping", i+1); + continue; + } + } + else + { + c->base.visualType = GLX_TRUE_COLOR; + } + + // pfd.dwVisibleMask; ??? + c->base.transparentPixel = GLX_NONE; + c->base.transparentRed = GLX_NONE; + c->base.transparentGreen = GLX_NONE; + c->base.transparentBlue = GLX_NONE; + c->base.transparentAlpha = GLX_NONE; + c->base.transparentIndex = GLX_NONE; + + /* ARB_multisample / SGIS_multisample */ + c->base.sampleBuffers = 0; + c->base.samples = 0; + + /* SGIX_fbconfig / GLX 1.3 */ + c->base.drawableType = (((pfd.dwFlags & PFD_DRAW_TO_WINDOW) ? GLX_WINDOW_BIT : 0) + | ((pfd.dwFlags & PFD_DRAW_TO_BITMAP) ? GLX_PIXMAP_BIT : 0)); + + if (pfd.iPixelType == PFD_TYPE_COLORINDEX) + { + c->base.renderType = GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT; + } + else + { + c->base.renderType = GLX_RGBA_BIT; + } + + c->base.xRenderable = GL_TRUE; + c->base.fbconfigID = -1; // will be set by __glXScreenInit() + + /* SGIX_pbuffer / GLX 1.3 */ + // XXX: How can we find these values out ??? + c->base.maxPbufferWidth = -1; + c->base.maxPbufferHeight = -1; + c->base.maxPbufferPixels = -1; + c->base.optimalPbufferWidth = 0; // there is no optimal value + c->base.optimalPbufferHeight = 0; + + /* SGIX_visual_select_group */ + // arrange for visuals with the best acceleration to be preferred in selection + switch (pfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED)) + { + case 0: + c->base.visualSelectGroup = 2; + break; + + case PFD_GENERIC_ACCELERATED: + c->base.visualSelectGroup = 1; + break; + + case PFD_GENERIC_FORMAT: + c->base.visualSelectGroup = 0; + break; + + default: + ; + // "can't happen" + } + + /* OML_swap_method */ + if (pfd.dwFlags & PFD_SWAP_EXCHANGE) + c->base.swapMethod = GLX_SWAP_EXCHANGE_OML; + else if (pfd.dwFlags & PFD_SWAP_COPY) + c->base.swapMethod = GLX_SWAP_COPY_OML; + else + c->base.swapMethod = GLX_SWAP_UNDEFINED_OML; + + /* EXT_import_context */ + c->base.screen = screen->base.pScreen->myNum; + + /* EXT_texture_from_pixmap */ + c->base.bindToTextureRgb = -1; + c->base.bindToTextureRgba = -1; + c->base.bindToMipmapTexture = -1; + c->base.bindToTextureTargets = -1; + c->base.yInverted = -1; + + n++; + + // update previous config to point to this config + if (prev) + prev->base.next = &(c->base); + + prev = c; + } + + GLWIN_DEBUG_MSG("found %d pixelFormats suitable for conversion to fbConfigs", n); + + screen->base.numFBConfigs = n; + screen->base.fbconfigs = &(result->base); +} + +// helper function to access an attribute value from an attribute value array by attribute +static +int getAttrValue(const int attrs[], int values[], unsigned int num, int attr, int fallback) +{ + unsigned int i; + for (i = 0; i < num; i++) + { + if (attrs[i] == attr) + { + GLWIN_TRACE_MSG("getAttrValue attr 0x%x, value %d", attr, values[i]); + return values[i]; + } + } + + ErrorF("getAttrValue failed to find attr 0x%x, using default value %d\n", attr, fallback); + return fallback; +} + +// +// Create the GLXconfigs using wglGetPixelFormatAttribfvARB() extension +// +static void +glxWinCreateConfigsExt(HDC hdc, glxWinScreen *screen) +{ + GLXWinConfig *c, *result, *prev = NULL; + int i = 0; + int n = 0; + + const int attr = WGL_NUMBER_PIXEL_FORMATS_ARB; + int numConfigs; + + int attrs[50]; + unsigned int num_attrs = 0; + + GLWIN_DEBUG_MSG("glxWinCreateConfigsExt"); + + screen->base.numFBConfigs = 0; + screen->base.fbconfigs = NULL; + + if (!wglGetPixelFormatAttribivARBWrapper(hdc, 0, 0, 1, &attr, &numConfigs)) + { + ErrorF("wglGetPixelFormatAttribivARB failed for WGL_NUMBER_PIXEL_FORMATS_ARB: %s\n", glxWinErrorMessage()); + return; + } + + GLWIN_DEBUG_MSG("wglGetPixelFormatAttribivARB says %d possible pixel formats", numConfigs); + + /* alloc */ + result = malloc(sizeof(GLXWinConfig) * numConfigs); + + if (NULL == result) + { + return; + } + + memset(result, 0, sizeof(GLXWinConfig) * numConfigs); + n = 0; + +#define ADD_ATTR(a) { attrs[num_attrs++] = a; assert(num_attrs < NUM_ELEMENTS(attrs)); } + + ADD_ATTR(WGL_DRAW_TO_WINDOW_ARB); + ADD_ATTR(WGL_DRAW_TO_BITMAP_ARB); + ADD_ATTR(WGL_ACCELERATION_ARB); + ADD_ATTR(WGL_SWAP_LAYER_BUFFERS_ARB); + ADD_ATTR(WGL_NUMBER_OVERLAYS_ARB); + ADD_ATTR(WGL_NUMBER_UNDERLAYS_ARB); + ADD_ATTR(WGL_TRANSPARENT_ARB); + ADD_ATTR(WGL_TRANSPARENT_RED_VALUE_ARB); + ADD_ATTR(WGL_TRANSPARENT_GREEN_VALUE_ARB); + ADD_ATTR(WGL_TRANSPARENT_GREEN_VALUE_ARB); + ADD_ATTR(WGL_TRANSPARENT_ALPHA_VALUE_ARB); + ADD_ATTR(WGL_SUPPORT_OPENGL_ARB); + ADD_ATTR(WGL_DOUBLE_BUFFER_ARB); + ADD_ATTR(WGL_STEREO_ARB); + ADD_ATTR(WGL_PIXEL_TYPE_ARB); + ADD_ATTR(WGL_COLOR_BITS_ARB); + ADD_ATTR(WGL_RED_BITS_ARB); + ADD_ATTR(WGL_RED_SHIFT_ARB); + ADD_ATTR(WGL_GREEN_BITS_ARB); + ADD_ATTR(WGL_GREEN_SHIFT_ARB); + ADD_ATTR(WGL_BLUE_BITS_ARB); + ADD_ATTR(WGL_BLUE_SHIFT_ARB); + ADD_ATTR(WGL_ALPHA_BITS_ARB); + ADD_ATTR(WGL_ALPHA_SHIFT_ARB); + ADD_ATTR(WGL_ACCUM_RED_BITS_ARB); + ADD_ATTR(WGL_ACCUM_GREEN_BITS_ARB); + ADD_ATTR(WGL_ACCUM_BLUE_BITS_ARB); + ADD_ATTR(WGL_ACCUM_ALPHA_BITS_ARB); + ADD_ATTR(WGL_DEPTH_BITS_ARB); + ADD_ATTR(WGL_STENCIL_BITS_ARB); + ADD_ATTR(WGL_AUX_BUFFERS_ARB); + ADD_ATTR(WGL_SWAP_METHOD_ARB); + + if (screen->has_WGL_ARB_multisample) + { + // we may not query these attrs if WGL_ARB_multisample is not offered + ADD_ATTR(WGL_SAMPLE_BUFFERS_ARB); + ADD_ATTR(WGL_SAMPLES_ARB); + } + + if (screen->has_WGL_ARB_render_texture) + { + // we may not query these attrs if WGL_ARB_render_texture is not offered + ADD_ATTR(WGL_BIND_TO_TEXTURE_RGB_ARB); + ADD_ATTR(WGL_BIND_TO_TEXTURE_RGBA_ARB); + } + + if (screen->has_WGL_ARB_pbuffer) + { + // we may not query these attrs if WGL_ARB_pbuffer is not offered + ADD_ATTR(WGL_DRAW_TO_PBUFFER_ARB); + ADD_ATTR(WGL_MAX_PBUFFER_PIXELS_ARB); + ADD_ATTR(WGL_MAX_PBUFFER_WIDTH_ARB); + ADD_ATTR(WGL_MAX_PBUFFER_HEIGHT_ARB); + } + + /* fill in configs */ + for (i = 0; i < numConfigs; i++) + { + int values[num_attrs]; + + c = &(result[i]); + c->base.next = NULL; + c->pixelFormatIndex = i+1; + + if (!wglGetPixelFormatAttribivARBWrapper(hdc, i+1, 0, num_attrs, attrs, values)) + { + ErrorF("wglGetPixelFormatAttribivARB failed for index %d, error %s\n", i+1, glxWinErrorMessage()); + break; + } + +#define ATTR_VALUE(a, d) getAttrValue(attrs, values, num_attrs, (a), (d)) + + if (!ATTR_VALUE(WGL_SUPPORT_OPENGL_ARB, 0)) + { + GLWIN_DEBUG_MSG("pixelFormat %d isn't WGL_SUPPORT_OPENGL_ARB, skipping", i+1); + continue; + } + + c->base.doubleBufferMode = ATTR_VALUE(WGL_DOUBLE_BUFFER_ARB, 0) ? GL_TRUE : GL_FALSE; + c->base.stereoMode = ATTR_VALUE(WGL_STEREO_ARB, 0) ? GL_TRUE : GL_FALSE; + + c->base.redBits = ATTR_VALUE(WGL_RED_BITS_ARB, 0); + c->base.greenBits = ATTR_VALUE(WGL_GREEN_BITS_ARB, 0); + c->base.blueBits = ATTR_VALUE(WGL_BLUE_BITS_ARB, 0); + c->base.alphaBits = ATTR_VALUE(WGL_ALPHA_BITS_ARB, 0); + + c->base.redMask = BITS_AND_SHIFT_TO_MASK(c->base.redBits, ATTR_VALUE(WGL_RED_SHIFT_ARB, 0)); + c->base.greenMask = BITS_AND_SHIFT_TO_MASK(c->base.greenBits, ATTR_VALUE(WGL_GREEN_SHIFT_ARB, 0)); + c->base.blueMask = BITS_AND_SHIFT_TO_MASK(c->base.blueBits, ATTR_VALUE(WGL_BLUE_SHIFT_ARB, 0)); + c->base.alphaMask = BITS_AND_SHIFT_TO_MASK(c->base.alphaBits, ATTR_VALUE(WGL_ALPHA_SHIFT_ARB, 0)); + + switch (ATTR_VALUE(WGL_PIXEL_TYPE_ARB, 0)) + { + case WGL_TYPE_COLORINDEX_ARB: + c->base.indexBits = ATTR_VALUE(WGL_COLOR_BITS_ARB, 0); + c->base.rgbBits = 0; + c->base.visualType = GLX_STATIC_COLOR; + + if (!getenv("GLWIN_ENABLE_COLORINDEX_FBCONFIGS")) + { + GLWIN_DEBUG_MSG("pixelFormat %d is WGL_TYPE_COLORINDEX_ARB, skipping", i+1); + continue; + } + + break; + + case WGL_TYPE_RGBA_FLOAT_ARB: + GLWIN_DEBUG_MSG("pixelFormat %d is WGL_TYPE_RGBA_FLOAT_ARB, skipping", i+1); + continue; + + case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: + GLWIN_DEBUG_MSG("pixelFormat %d is WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT, skipping", i+1); + continue; + + case WGL_TYPE_RGBA_ARB: + c->base.indexBits = 0; + c->base.rgbBits = ATTR_VALUE(WGL_COLOR_BITS_ARB, 0); + c->base.visualType = GLX_TRUE_COLOR; + break; + + default: + ErrorF("wglGetPixelFormatAttribivARB returned unknown value 0x%x for WGL_PIXEL_TYPE_ARB\n", ATTR_VALUE(WGL_PIXEL_TYPE_ARB, 0)); + continue; + } + + c->base.accumRedBits = ATTR_VALUE(WGL_ACCUM_RED_BITS_ARB, 0); + c->base.accumGreenBits = ATTR_VALUE(WGL_ACCUM_GREEN_BITS_ARB, 0); + c->base.accumBlueBits = ATTR_VALUE(WGL_ACCUM_BLUE_BITS_ARB, 0); + c->base.accumAlphaBits = ATTR_VALUE(WGL_ACCUM_ALPHA_BITS_ARB, 0); + + c->base.depthBits = ATTR_VALUE(WGL_DEPTH_BITS_ARB, 0); + c->base.stencilBits = ATTR_VALUE(WGL_STENCIL_BITS_ARB, 0); + c->base.numAuxBuffers = ATTR_VALUE(WGL_AUX_BUFFERS_ARB, 0); + + { + int layers = ATTR_VALUE(WGL_NUMBER_OVERLAYS_ARB,0) + ATTR_VALUE(WGL_NUMBER_UNDERLAYS_ARB, 0); + + if (layers > 0) + { + ErrorF("pixelFormat %d: has %d overlay, %d underlays which aren't currently handled", i, ATTR_VALUE(WGL_NUMBER_OVERLAYS_ARB,0), ATTR_VALUE(WGL_NUMBER_UNDERLAYS_ARB, 0)); + // XXX: need to iterate over layers? + } + } + c->base.level = 0; + + c->base.pixmapMode = 0; // ??? + c->base.visualID = -1; // will be set by __glXScreenInit() + + /* EXT_visual_rating / GLX 1.2 */ + switch (ATTR_VALUE(WGL_ACCELERATION_ARB, 0)) + { + default: + ErrorF("wglGetPixelFormatAttribivARB returned unknown value 0x%x for WGL_ACCELERATION_ARB\n", ATTR_VALUE(WGL_ACCELERATION_ARB, 0)); + + case WGL_NO_ACCELERATION_ARB: + c->base.visualRating = GLX_SLOW_VISUAL_EXT; + break; + + case WGL_GENERIC_ACCELERATION_ARB: + case WGL_FULL_ACCELERATION_ARB: + c->base.visualRating = GLX_NONE_EXT; + break; + } + + /* EXT_visual_info / GLX 1.2 */ + // c->base.visualType is set above + if (ATTR_VALUE(WGL_TRANSPARENT_ARB, 0)) + { + c->base.transparentPixel = (c->base.visualType == GLX_TRUE_COLOR) ? GLX_TRANSPARENT_RGB_EXT : GLX_TRANSPARENT_INDEX_EXT; + c->base.transparentRed = ATTR_VALUE(WGL_TRANSPARENT_RED_VALUE_ARB, 0); + c->base.transparentGreen = ATTR_VALUE(WGL_TRANSPARENT_GREEN_VALUE_ARB, 0); + c->base.transparentBlue = ATTR_VALUE(WGL_TRANSPARENT_BLUE_VALUE_ARB, 0); + c->base.transparentAlpha = ATTR_VALUE(WGL_TRANSPARENT_ALPHA_VALUE_ARB, 0); + c->base.transparentIndex = ATTR_VALUE(WGL_TRANSPARENT_INDEX_VALUE_ARB, 0); + } + else + { + c->base.transparentPixel = GLX_NONE_EXT; + c->base.transparentRed = GLX_NONE; + c->base.transparentGreen = GLX_NONE; + c->base.transparentBlue = GLX_NONE; + c->base.transparentAlpha = GLX_NONE; + c->base.transparentIndex = GLX_NONE; + } + + /* ARB_multisample / SGIS_multisample */ + if (screen->has_WGL_ARB_multisample) + { + c->base.sampleBuffers = ATTR_VALUE(WGL_SAMPLE_BUFFERS_ARB, 0); + c->base.samples = ATTR_VALUE(WGL_SAMPLES_ARB, 0); + } + else + { + c->base.sampleBuffers = 0; + c->base.samples = 0; + } + + /* SGIX_fbconfig / GLX 1.3 */ + c->base.drawableType = ((ATTR_VALUE(WGL_DRAW_TO_WINDOW_ARB, 0) ? GLX_WINDOW_BIT : 0) + | (ATTR_VALUE(WGL_DRAW_TO_BITMAP_ARB, 0) ? GLX_PIXMAP_BIT : 0) + | (ATTR_VALUE(WGL_DRAW_TO_PBUFFER_ARB, 0) ? GLX_PBUFFER_BIT : 0)); + + /* + Assume OpenGL RGBA rendering is available on all visuals + (it is specified to render to red component in single-channel visuals, + if supported, but there doesn't seem to be any mechanism to check if it + is supported) + + Color index rendering is only supported on single-channel visuals + */ + if (c->base.visualType == GLX_STATIC_COLOR) + { + c->base.renderType = GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT; + } + else + { + c->base.renderType = GLX_RGBA_BIT; + } + + c->base.xRenderable = GL_TRUE; + c->base.fbconfigID = -1; // will be set by __glXScreenInit() + + /* SGIX_pbuffer / GLX 1.3 */ + if (screen->has_WGL_ARB_pbuffer) + { + c->base.maxPbufferWidth = ATTR_VALUE(WGL_MAX_PBUFFER_WIDTH_ARB, -1); + c->base.maxPbufferHeight = ATTR_VALUE(WGL_MAX_PBUFFER_HEIGHT_ARB, -1); + c->base.maxPbufferPixels = ATTR_VALUE(WGL_MAX_PBUFFER_PIXELS_ARB, -1); + } + else + { + c->base.maxPbufferWidth = -1; + c->base.maxPbufferHeight = -1; + c->base.maxPbufferPixels = -1; + } + c->base.optimalPbufferWidth = 0; // there is no optimal value + c->base.optimalPbufferHeight = 0; + + /* SGIX_visual_select_group */ + // arrange for visuals with the best acceleration to be preferred in selection + switch (ATTR_VALUE(WGL_ACCELERATION_ARB, 0)) + { + case WGL_FULL_ACCELERATION_ARB: + c->base.visualSelectGroup = 2; + break; + + case WGL_GENERIC_ACCELERATION_ARB: + c->base.visualSelectGroup = 1; + break; + + default: + case WGL_NO_ACCELERATION_ARB: + c->base.visualSelectGroup = 0; + break; + } + + /* OML_swap_method */ + switch (ATTR_VALUE(WGL_SWAP_METHOD_ARB, 0)) + { + case WGL_SWAP_EXCHANGE_ARB: + c->base.swapMethod = GLX_SWAP_EXCHANGE_OML; + break; + + case WGL_SWAP_COPY_ARB: + c->base.swapMethod = GLX_SWAP_COPY_OML; + break; + + default: + ErrorF("wglGetPixelFormatAttribivARB returned unknown value 0x%x for WGL_SWAP_METHOD_ARB\n", ATTR_VALUE(WGL_SWAP_METHOD_ARB, 0)); + + case WGL_SWAP_UNDEFINED_ARB: + c->base.swapMethod = GLX_SWAP_UNDEFINED_OML; + } + + /* EXT_import_context */ + c->base.screen = screen->base.pScreen->myNum; + + /* EXT_texture_from_pixmap */ + /* + Mesa's DRI configs always have bindToTextureRgb/Rgba TRUE (see driCreateConfigs(), so setting + bindToTextureRgb/bindToTextureRgba to FALSE means that swrast can't find any fbConfigs to use, + so setting these to 0, even if we know bindToTexture isn't available, isn't a good idea... + */ + if (screen->has_WGL_ARB_render_texture) + { + c->base.bindToTextureRgb = ATTR_VALUE(WGL_BIND_TO_TEXTURE_RGB_ARB, -1); + c->base.bindToTextureRgba = ATTR_VALUE(WGL_BIND_TO_TEXTURE_RGBA_ARB, -1); + } + else + { + c->base.bindToTextureRgb = -1; + c->base.bindToTextureRgba = -1; + } + c->base.bindToMipmapTexture = -1; + c->base.bindToTextureTargets = GLX_TEXTURE_1D_BIT_EXT | GLX_TEXTURE_2D_BIT_EXT | GLX_TEXTURE_RECTANGLE_BIT_EXT; + c->base.yInverted = -1; + + n++; + + // update previous config to point to this config + if (prev) + prev->base.next = &(c->base); + + prev = c; + } + + screen->base.numFBConfigs = n; + screen->base.fbconfigs = &(result->base); +} diff --git a/xorg-server/hw/xwin/glx/wgl_ext_api.c b/xorg-server/hw/xwin/glx/wgl_ext_api.c index b301ed567..78b6e2a02 100644 --- a/xorg-server/hw/xwin/glx/wgl_ext_api.c +++ b/xorg-server/hw/xwin/glx/wgl_ext_api.c @@ -1,75 +1,72 @@ -/* - * File: wgl_ext_api.c - * Purpose: Wrapper functions for Win32 OpenGL wgl extension functions - * - * Authors: Jon TURNEY - * - * Copyright (c) Jon TURNEY 2009 - * - * - * 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 without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL - * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR 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. - */ - -#ifdef HAVE_XWIN_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "glwindows.h" - -#define RESOLVE_DECL(type) \ - static type type##proc = NULL; - -#define PRERESOLVE(type, symbol) \ - type##proc = (type)wglGetProcAddress(symbol); \ - if (type##proc == NULL) \ - ErrorF("wglwrap: Can't resolve \"%s\"\n", symbol); \ - else \ - ErrorF("wglwrap: Resolved \"%s\"\n", symbol); - -#define RESOLVE_RET(type, symbol, retval) \ - if (type##proc == NULL) { \ - __glXErrorCallBack(0); \ - return retval; \ - } - -#define RESOLVE(procname, symbol) RESOLVE_RET(procname, symbol,) - -#define RESOLVED_PROC(type) type##proc - -/* - * Include generated cdecl wrappers for stdcall WGL functions - * - * There are extensions to the wgl*() API as well; again we call - * these functions by using wglGetProcAddress() to get a pointer - * to the function, and wrapping it for cdecl/stdcall conversion - * - * We arrange to resolve the functions up front, as they need a - * context to work, as we like to use them to be able to select - * a context. Again, this assumption fails badly on multimontor - * systems... - */ - -#include "generated_wgl_wrappers.c" +/* + * File: wgl_ext_api.c + * Purpose: Wrapper functions for Win32 OpenGL wgl extension functions + * + * Authors: Jon TURNEY + * + * Copyright (c) Jon TURNEY 2009 + * + * + * 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 without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR 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. + */ + +#ifdef HAVE_XWIN_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include "glwindows.h" + +#define RESOLVE_DECL(type) \ + static type type##proc = NULL; + +#define PRERESOLVE(type, symbol) \ + type##proc = (type)wglGetProcAddress(symbol); + +#define RESOLVE_RET(type, symbol, retval) \ + if (type##proc == NULL) { \ + ErrorF("wglwrap: Can't resolve \"%s\"\n", symbol); \ + __glXErrorCallBack(0); \ + return retval; \ + } + +#define RESOLVE(procname, symbol) RESOLVE_RET(procname, symbol,) + +#define RESOLVED_PROC(type) type##proc + +/* + * Include generated cdecl wrappers for stdcall WGL functions + * + * There are extensions to the wgl*() API as well; again we call + * these functions by using wglGetProcAddress() to get a pointer + * to the function, and wrapping it for cdecl/stdcall conversion + * + * We arrange to resolve the functions up front, as they need a + * context to work, as we like to use them to be able to select + * a context. Again, this assumption fails badly on multimontor + * systems... + */ + +#include "generated_wgl_wrappers.c" diff --git a/xorg-server/hw/xwin/glx/winpriv.c b/xorg-server/hw/xwin/glx/winpriv.c index a35392b26..460973730 100644 --- a/xorg-server/hw/xwin/glx/winpriv.c +++ b/xorg-server/hw/xwin/glx/winpriv.c @@ -19,7 +19,7 @@ winCreateWindowsWindow (WindowPtr pWin); */ HWND winGetWindowInfo(WindowPtr pWin) { - winDebug("%s: pWin=%p\n", __FUNCTION__, pWin); + winTrace("%s: pWin %p XID 0x%x\n", __FUNCTION__, pWin, pWin->drawable.id); /* a real window was requested */ if (pWin != NULL) @@ -61,6 +61,9 @@ HWND winGetWindowInfo(WindowPtr pWin) { /* copy window handle */ hwnd = pWinPriv->hWnd; + + /* mark GLX active on that hwnd */ + pWinPriv->fWglUsed = TRUE; } return hwnd; diff --git a/xorg-server/hw/xwin/man/XWin.man b/xorg-server/hw/xwin/man/XWin.man index 7975fd30d..6e69a185d 100644 --- a/xorg-server/hw/xwin/man/XWin.man +++ b/xorg-server/hw/xwin/man/XWin.man @@ -208,6 +208,10 @@ Enable or disable the \fICtrl-Alt-Backspace\fP key combination as a signal to exit the X Server. The \fICtrl-Alt-Backspace\fP key combination is disabled by default. .TP 8 +.B \-[no]wgl +Enable [disable] the GLX extension to use the native Windows WGL interface +for hardware accelerated OpenGL (AIGLX). (Experimental) +.TP 8 .B \-[no]winkill Enable or disable the \fIAlt-F4\fP key combination as a signal to exit the X Server. diff --git a/xorg-server/hw/xwin/man/XWinrc.man b/xorg-server/hw/xwin/man/XWinrc.man index 5c1fb979b..e4c454fba 100644 --- a/xorg-server/hw/xwin/man/XWinrc.man +++ b/xorg-server/hw/xwin/man/XWinrc.man @@ -1,4 +1,4 @@ -.TH XWIN 5 __vendorversion__ +.TH XWIN __filemansuffix__ __vendorversion__ .SH NAME diff --git a/xorg-server/hw/xwin/winmultiwindowwindow.c b/xorg-server/hw/xwin/winmultiwindowwindow.c index 2d9a46e40..2329d163e 100644 --- a/xorg-server/hw/xwin/winmultiwindowwindow.c +++ b/xorg-server/hw/xwin/winmultiwindowwindow.c @@ -110,7 +110,10 @@ winCreateWindowMultiWindow (WindowPtr pWin) pWinPriv->hWnd = NULL; pWinPriv->pScreenPriv = winGetScreenPriv(pWin->drawable.pScreen); pWinPriv->fXKilled = FALSE; - +#ifdef XWIN_GLX_WINDOWS + pWinPriv->fWglUsed = FALSE; +#endif + return fResult; } @@ -372,9 +375,8 @@ winReparentWindowMultiWindow (WindowPtr pWin, WindowPtr pPriorParent) ScreenPtr pScreen = pWin->drawable.pScreen; winScreenPriv(pScreen); -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winReparentMultiWindow - pWin: %08x\n", pWin); -#endif + winDebug("winReparentMultiWindow - pWin:%08x XID:0x%x, reparent from pWin:%08x XID:0x%x to pWin:%08x XID:0x%x\n", + pWin, pWin->drawable.id, pPriorParent, pPriorParent->drawable.id, pWin->parent, pWin->parent->drawable.id); WIN_UNWRAP(ReparentWindow); if (pScreen->ReparentWindow) @@ -498,9 +500,7 @@ winCreateWindowsWindow (WindowPtr pWin) winInitMultiWindowClass(); -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winCreateWindowsWindow - pWin: %08x\n", pWin); -#endif + winDebug("winCreateWindowsTopLevelWindow - pWin:%08x XID:0x%x \n", pWin, pWin->drawable.id); iX = pWin->drawable.x + GetSystemMetrics (SM_XVIRTUALSCREEN); iY = pWin->drawable.y + GetSystemMetrics (SM_YVIRTUALSCREEN); @@ -626,9 +626,7 @@ winDestroyWindowsWindow (WindowPtr pWin) HICON hIcon; HICON hIconSm; -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winDestroyWindowsWindow\n"); -#endif + winDebug("winDestroyWindowsWindow - pWin:%08x XID:0x%x \n", pWin, pWin->drawable.id); /* Bail out if the Windows window handle is invalid */ if (pWinPriv->hWnd == NULL) @@ -652,6 +650,11 @@ winDestroyWindowsWindow (WindowPtr pWin) winDestroyIcon(hIcon); winDestroyIcon(hIconSm); +#ifdef XWIN_GLX_WINDOWS + /* No longer note WGL used on this window */ + pWinPriv->fWglUsed = FALSE; +#endif + /* Process all messages on our queue */ while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { @@ -663,9 +666,7 @@ winDestroyWindowsWindow (WindowPtr pWin) winInDestroyWindowsWindow = oldstate; -#if CYGMULTIWINDOW_DEBUG - ErrorF ("-winDestroyWindowsWindow\n"); -#endif + winDebug("winDestroyWindowsWindow - done\n"); } diff --git a/xorg-server/hw/xwin/winmultiwindowwndproc.c b/xorg-server/hw/xwin/winmultiwindowwndproc.c index 1a3be78d5..fb1938b3a 100644 --- a/xorg-server/hw/xwin/winmultiwindowwndproc.c +++ b/xorg-server/hw/xwin/winmultiwindowwndproc.c @@ -472,6 +472,20 @@ winTopLevelWindowProc (HWND hwnd, UINT message, return 0; } +#ifdef XWIN_GLX_WINDOWS + if (pWinPriv->fWglUsed) + { + /* + For regions which are being drawn by GL, the shadow framebuffer doesn't have the + correct bits, so don't bitblt from the shadow framebuffer + + XXX: For now, just leave it alone, but ideally we want to send an expose event to + the window so it really redraws the affected region... + */ + ValidateRect(hwnd, &(ps.rcPaint)); + } + else +#endif /* Try to copy from the shadow buffer */ if (!BitBlt (hdcUpdate, ps.rcPaint.left, ps.rcPaint.top, diff --git a/xorg-server/hw/xwin/winwindow.h b/xorg-server/hw/xwin/winwindow.h index ebe43091f..a6c8e05dd 100644 --- a/xorg-server/hw/xwin/winwindow.h +++ b/xorg-server/hw/xwin/winwindow.h @@ -80,6 +80,9 @@ typedef struct winPrivScreenPtr pScreenPriv; Bool fXKilled; HDWP hDwp; +#ifdef XWIN_GLX_WINDOWS + Bool fWglUsed; +#endif /* Privates used by primary fb DirectDraw server */ LPDDSURFACEDESC pddsdPrimary; -- cgit v1.2.3