=?UTF-8?Q?Stefan=20D=C3=B6singer=20?=: wined3d: Remove d3dfmt_p8_init_palette.

Alexandre Julliard julliard at winehq.org
Wed Jun 11 13:36:24 CDT 2014


Module: wine
Branch: master
Commit: 390921577350dd8cd5d6d6fba6d38055588330d2
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=390921577350dd8cd5d6d6fba6d38055588330d2

Author: Stefan Dösinger <stefan at codeweavers.com>
Date:   Tue Jun  3 09:41:39 2014 +0200

wined3d: Remove d3dfmt_p8_init_palette.

---

 dlls/wined3d/arb_program_shader.c |   18 ++++++---
 dlls/wined3d/surface.c            |   81 ++++++++++++++-----------------------
 dlls/wined3d/wined3d_private.h    |    2 -
 3 files changed, 44 insertions(+), 57 deletions(-)

diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index 5d23eed..fa15b1e 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -7280,12 +7280,10 @@ static GLuint gen_p8_shader(struct arbfp_blit_priv *priv,
 /* Context activation is done by the caller. */
 static void upload_palette(const struct wined3d_surface *surface, struct wined3d_context *context)
 {
-    BYTE table[256][4];
     struct wined3d_device *device = surface->resource.device;
     const struct wined3d_gl_info *gl_info = context->gl_info;
     struct arbfp_blit_priv *priv = device->blit_priv;
-
-    d3dfmt_p8_init_palette(surface, table);
+    const struct wined3d_palette *palette = surface->palette;
 
     if (!priv->palette_texture)
         gl_info->gl_ops.gl.p_glGenTextures(1, &priv->palette_texture);
@@ -7299,9 +7297,19 @@ static void upload_palette(const struct wined3d_surface *surface, struct wined3d
     /* Make sure we have discrete color levels. */
     gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-    /* Upload the palette */
     /* TODO: avoid unneeded uploads in the future by adding some SFLAG_PALETTE_DIRTY mechanism */
-    gl_info->gl_ops.gl.p_glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, table);
+    if (palette)
+    {
+        gl_info->gl_ops.gl.p_glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 256, 0, GL_BGRA,
+                GL_UNSIGNED_INT_8_8_8_8_REV, palette->colors);
+    }
+    else
+    {
+        static const DWORD black;
+        FIXME("P8 surface loaded without a palette.\n");
+        gl_info->gl_ops.gl.p_glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 1, 0, GL_BGRA,
+                GL_UNSIGNED_INT_8_8_8_8_REV, &black);
+    }
 
     /* Switch back to unit 0 in which the 2D texture will be stored. */
     context_active_texture(context, gl_info, 0);
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index f198bf0..ce95631 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -3370,38 +3370,6 @@ static BOOL color_in_range(const struct wined3d_color_key *color_key, DWORD colo
             && color <= color_key->color_space_high_value;
 }
 
-void d3dfmt_p8_init_palette(const struct wined3d_surface *surface, BYTE table[256][4])
-{
-    const struct wined3d_palette *pal = surface->palette;
-    unsigned int i;
-
-    if (!pal)
-    {
-        FIXME("No palette set.\n");
-        /* Guarantees that memory representation remains correct after sysmem<->texture transfers even if
-         * there's no palette at this time. */
-        for (i = 0; i < 256; i++)
-            table[i][3] = i;
-    }
-    else
-    {
-        TRACE("Using surface palette %p\n", pal);
-        for (i = 0; i < 256; ++i)
-        {
-            table[i][0] = pal->colors[i].rgbRed;
-            table[i][1] = pal->colors[i].rgbGreen;
-            table[i][2] = pal->colors[i].rgbBlue;
-            /* The palette index is stored in the alpha component. In case of a
-             * readback we can then read GL_ALPHA. Color keying is handled in
-             * surface_blt_to_drawable() using a GL_ALPHA_TEST using GL_NOT_EQUAL.
-             * In case of a P8 surface the color key itself is passed to
-             * glAlphaFunc in other cases the alpha component of pixels that
-             * should be masked away is set to 0. */
-            table[i][3] = i;
-        }
-    }
-}
-
 static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UINT width, UINT height,
         UINT outpitch, enum wined3d_conversion_type conversion_type, struct wined3d_surface *surface)
 {
@@ -3420,27 +3388,40 @@ static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UI
         }
 
         case WINED3D_CT_PALETTED:
-        {
-            BYTE table[256][4];
-            unsigned int x, y;
-
-            d3dfmt_p8_init_palette(surface, table);
-
-            for (y = 0; y < height; y++)
+            if (surface->palette)
             {
-                source = src + pitch * y;
-                dest = dst + outpitch * y;
-                /* This is an 1 bpp format, using the width here is fine */
-                for (x = 0; x < width; x++) {
-                    BYTE color = *source++;
-                    *dest++ = table[color][0];
-                    *dest++ = table[color][1];
-                    *dest++ = table[color][2];
-                    *dest++ = table[color][3];
+                unsigned int x, y;
+                const struct wined3d_palette *palette = surface->palette;
+                for (y = 0; y < height; y++)
+                {
+                    source = src + pitch * y;
+                    dest = dst + outpitch * y;
+                    for (x = 0; x < width; x++)
+                    {
+                        BYTE color = *source++;
+                        *dest++ = palette->colors[color].rgbRed;
+                        *dest++ = palette->colors[color].rgbGreen;
+                        *dest++ = palette->colors[color].rgbBlue;
+                        *dest++ = 0;
+                    }
                 }
             }
-        }
-        break;
+            else
+            {
+                /* This should probably use the system palette, but unless
+                 * the X server is running in P8 mode there is no such thing.
+                 * The probably best solution is to set the fixed 20 colors
+                 * from the default windows palette and set the rest to black,
+                 * white, or some ugly pink. For now use black for the entire
+                 * palette. Don't use pink everywhere. Age of Empires 2 draws
+                 * a front buffer filled with zeroes without a palette when
+                 * starting and we don't want the screen to flash in an ugly
+                 * color. */
+                FIXME("P8 surface loaded without a palette.\n");
+                memset(dst, 0, height * outpitch);
+            }
+
+            break;
 
         case WINED3D_CT_CK_565:
         {
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index b3cb884..b1c7089 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2350,8 +2350,6 @@ enum wined3d_conversion_type
     WINED3D_CT_CK_ARGB32,
 };
 
-void d3dfmt_p8_init_palette(const struct wined3d_surface *surface, BYTE table[256][4]) DECLSPEC_HIDDEN;
-
 struct wined3d_sampler
 {
     LONG refcount;




More information about the wine-cvs mailing list