[WIN32K]
authorJérôme Gardou <jerome.gardou@reactos.org>
Fri, 14 May 2010 18:51:48 +0000 (18:51 +0000)
committerJérôme Gardou <jerome.gardou@reactos.org>
Fri, 14 May 2010 18:51:48 +0000 (18:51 +0000)
  - IntGdiCreateBitmap : assign a default palette to the bitmap created
  - Use IntCreateBitmap where we already have a bitmap to assign
  - delete all mono bitmaps related hacks in xlateobj implementation, as now all bitmaps should have a palette
Fixes last immediately visible glitches when switching modes

svn path=/branches/reactos-yarotows/; revision=47203

subsystems/win32/win32k/eng/xlate.c
subsystems/win32/win32k/include/palette.h
subsystems/win32/win32k/objects/bitmaps.c
subsystems/win32/win32k/objects/palette.c

index 2c56cea..870f363 100644 (file)
@@ -618,65 +618,31 @@ EXLATEOBJ_vInitXlateFromDCs(
         return;
     }
 
-    if (psurfSrc->ppal)
-    {
-        ppalSrc = psurfSrc->ppal;
-        GDIOBJ_IncrementShareCount(&ppalSrc->BaseObject);
-    }
-    else
-        ppalSrc = PALETTE_ShareLockPalette(pdcSrc->ppdev->devinfo.hpalDefault);
+    ppalSrc = psurfSrc->ppal;
 
     if(!ppalSrc)
-        return;
-
-    if (psurfDst->ppal)
     {
-        ppalDst = psurfDst->ppal;
-        GDIOBJ_IncrementShareCount(&ppalDst->BaseObject);
+        DPRINT1("No palette for src surface %p.\n", psurfSrc);
+        return;
     }
-    else
-        ppalDst = PALETTE_ShareLockPalette(pdcDst->ppdev->devinfo.hpalDefault);
+
+    ppalDst = psurfDst->ppal;
 
     if (!ppalDst)
     {
-        PALETTE_ShareUnlockPalette(ppalSrc);
+        DPRINT1("No palette for dst surface %p.\n", psurfDst);
         return;
     }
 
     ppalDstDc = pdcDst->dclevel.ppal;
     ASSERT(ppalDstDc);
 
-    /* KB41464 details how to convert between mono and color */
-    if (psurfDst->SurfObj.iBitmapFormat == BMF_1BPP)
-    {
-        if (psurfSrc->SurfObj.iBitmapFormat != BMF_1BPP)
-        {
-            // HACK!! FIXME: 1bpp DDBs should have gpalMono already!
-            EXLATEOBJ_vInitialize(pexlo,
-                                  ppalSrc,
-                                  &gpalMono,
-                                  pdcSrc->pdcattr->crBackgroundClr,
-                                  pdcDst->pdcattr->crBackgroundClr,
-                                  pdcDst->pdcattr->crForegroundClr);
-        }
-    }
-    else if (psurfSrc->SurfObj.iBitmapFormat == BMF_1BPP && !psurfSrc->hSecure)
-    {
-        // HACK!! FIXME: 1bpp DDBs should have gpalMono already!
-        EXLATEOBJ_vInitialize(pexlo,
-                              &gpalMono,
-                              ppalDst,
-                              0,
-                              pdcDst->pdcattr->crBackgroundClr,
-                              pdcDst->pdcattr->crForegroundClr);
-    }
-    else
-    {
-        EXLATEOBJ_vInitialize(pexlo, ppalSrc, ppalDst, 0, 0, 0);
-    }
-
-    PALETTE_ShareUnlockPalette(ppalDst);
-    PALETTE_ShareUnlockPalette(ppalSrc);
+    EXLATEOBJ_vInitialize(pexlo,
+                          ppalSrc,
+                          ppalDst,
+                          pdcSrc->pdcattr->crBackgroundClr,
+                          pdcDst->pdcattr->crBackgroundClr,
+                          pdcDst->pdcattr->crForegroundClr);
 }
 
 
@@ -699,68 +665,25 @@ EXLATEOBJ_vInitBrushXlate(
 
     EXLATEOBJ_vInitTrivial(pexlo);
 
-    if (psurfDst->ppal)
-    {
-        ppalDst = psurfDst->ppal;
-        GDIOBJ_IncrementShareCount(&ppalDst->BaseObject);
-    }
-    else
-        ppalDst = PALETTE_ShareLockPalette(pPrimarySurface->devinfo.hpalDefault);
+    ppalDst = psurfDst->ppal;
 
     if (!ppalDst)
     {
-        DPRINT1("No ppalDst!\n");
+        DPRINT1("No palette for dst surface %p.\n", psurfDst);
         return;
     }
 
     psurfPattern = SURFACE_ShareLockSurface(pbrush->hbmPattern);
     if (!psurfPattern)
     {
-        PALETTE_ShareUnlockPalette(ppalDst);
         return;
     }
 
-#if 0
-    if (psurfDst->SurfObj.iBitmapFormat == BMF_1BPP)
-    {
-        if (psurfSrc->SurfObj.iBitmapFormat != BMF_1BPP)
-        {
-            // HACK!! FIXME: 1bpp DDBs should have gpalMono already!
-            EXLATEOBJ_vInitialize(pexlo,
-                                  ppalSrc,
-                                  &gpalMono,
-                                  0,
-                                  crBackgroundClr,
-                                  crForegroundClr);
-        }
-    }
-    else
-#endif
-    if (psurfPattern->SurfObj.iBitmapFormat == BMF_1BPP &&
-        !(pbrush->flAttrs & GDIBRUSH_IS_DIB))
-    {
-        /* Special case: 1 bpp pattern, not a DIB brush. */
-        if (psurfDst->SurfObj.iBitmapFormat != BMF_1BPP)
-        {
-            // HACK!! FIXME: 1bpp DDBs should have gpalMono already!
-            EXLATEOBJ_vInitialize(pexlo,
-                                  &gpalMono,
-                                  ppalDst,
-                                  0,
-                                  crBackgroundClr,
-                                  crForegroundClr);
-        }
-    }
-    else
+    if (psurfPattern->ppal)
     {
-        /* Default: use the patterns' palette */
-        if (psurfPattern->ppal)
-        {
-            EXLATEOBJ_vInitialize(pexlo, psurfPattern->ppal, ppalDst, 0, 0, 0);
-        }
+        EXLATEOBJ_vInitialize(pexlo, psurfPattern->ppal, ppalDst, 0, crBackgroundClr, crForegroundClr);
     }
 
-    PALETTE_ShareUnlockPalette(ppalDst);
     SURFACE_ShareUnlockSurface(psurfPattern);
 }
 
index 43f59e6..4f82172 100644 (file)
@@ -54,7 +54,7 @@ typedef struct _PALETTE
   HDEV  hPDev;
 } PALETTE, *PPALETTE;
 
-extern PALETTE gpalRGB, gpalBGR, gpalMono;
+extern PALETTE gpalRGB, gpalBGR, gpalMono, gpalRGB555, gpalRGB565;
 
 
 HPALETTE FASTCALL PALETTE_AllocPalette(ULONG Mode,
index 01076d3..63cc160 100644 (file)
@@ -87,6 +87,38 @@ IntGdiCreateBitmap(
         IntSetBitmapBits(psurfBmp, psurfBmp->SurfObj.cjBits, pBits);
     }
 
+    /* Find a suitable palette for this bitmap
+     * Increment internal objects share count
+     * so we can call PALETTE_ShareUnlockPalette
+     * or GDIOBJ_IncrementShareCount safely */
+    switch(BitsPixel)
+    {
+        case 1:
+            psurfBmp->ppal = &gpalMono;
+            gpalMono.BaseObject.ulShareCount++;
+            break;
+        case 4:
+        case 8:
+            psurfBmp->ppal = PALETTE_ShareLockPalette(StockObjects[DEFAULT_PALETTE]);
+            break;
+        case 15:
+            psurfBmp->ppal = &gpalRGB555;
+            gpalRGB555.BaseObject.ulShareCount++;
+            break;
+        case 16:
+            psurfBmp->ppal = &gpalRGB565;
+            gpalRGB565.BaseObject.ulShareCount++;
+            break;
+        case 24:
+        case 32:
+            psurfBmp->ppal = &gpalRGB;
+            gpalRGB.BaseObject.ulShareCount++;
+            break;
+        default:
+            DPRINT1("Could not determine palette for bit depth %u.\n", BitsPixel);
+            break;
+    }
+
     SURFACE_UnlockSurface(psurfBmp);
 
     DPRINT("IntGdiCreateBitmap : %dx%d, %d BPP colors, topdown %d, returning %08x\n",
@@ -144,15 +176,24 @@ IntCreateCompatibleBitmap(
         if (Dc->dctype != DC_TYPE_MEMORY)
         {
             PSURFACE psurf;
-            Bmp = IntGdiCreateBitmap(abs(Width),
-                                     abs(Height),
-                                     Dc->ppdev->gdiinfo.cPlanes,
-                                     Dc->ppdev->gdiinfo.cBitsPixel,
-                                     NULL);
-            /* Set palette */
+            SIZEL size;
+
+            size.cx = abs(Width);
+            size.cy = abs(Height);
+
+            Bmp = IntCreateBitmap(size,
+                                  BITMAP_GetWidthBytes(Width, Dc->ppdev->gdiinfo.cBitsPixel),
+                                  Dc->ppdev->pSurface->SurfObj.iBitmapFormat,
+                                  0,
+                                  NULL);
+
             psurf = SURFACE_LockSurface(Bmp);
             ASSERT(psurf);
+            /* Set palette */
             psurf->ppal = PALETTE_ShareLockPalette(Dc->ppdev->devinfo.hpalDefault);
+            /* Set flags */
+            psurf->flFlags = BITMAPOBJ_IS_APIBITMAP;
+            psurf->hDC = NULL; // Fixme
             SURFACE_UnlockSurface(psurf);
         }
         else
@@ -166,20 +207,24 @@ IntCreateCompatibleBitmap(
             {
                 if (Count == sizeof(BITMAP))
                 {
-                    Bmp = IntGdiCreateBitmap(abs(Width),
-                                             abs(Height),
-                                             dibs.dsBm.bmPlanes,
-                                             dibs.dsBm.bmBitsPixel,
-                                             NULL);
+                    SIZEL size;
+                    PSURFACE psurfBmp;
+                    size.cx = abs(Width);
+                    size.cy = abs(Height);
+                    Bmp = IntCreateBitmap(size,
+                                          BITMAP_GetWidthBytes(Width, dibs.dsBm.bmBitsPixel),
+                                          psurf->SurfObj.iBitmapFormat,
+                                          0,
+                                          NULL);
+                    psurfBmp = SURFACE_LockSurface(Bmp);
+                    ASSERT(psurfBmp);
                     /* Assign palette */
-                    if(Bmp && psurf->ppal)
-                    {
-                        PSURFACE psurfBmp = SURFACE_LockSurface(Bmp);
-                        ASSERT(psurfBmp);
-                        psurfBmp->ppal = psurf->ppal;
-                        GDIOBJ_IncrementShareCount((POBJ)psurf->ppal);
-                        SURFACE_UnlockSurface(psurfBmp);
-                    }
+                    psurfBmp->ppal = psurf->ppal;
+                    GDIOBJ_IncrementShareCount((POBJ)psurf->ppal);
+                    /* Set flags */
+                    psurfBmp->flFlags = BITMAPOBJ_IS_APIBITMAP;
+                    psurfBmp->hDC = NULL; // Fixme
+                    SURFACE_UnlockSurface(psurfBmp);
                 }
                 else
                 {
index 8fcbbe4..c489ef0 100644 (file)
@@ -14,7 +14,7 @@
 
 static UINT SystemPaletteUse = SYSPAL_NOSTATIC;  /* the program need save the pallete and restore it */
 
-PALETTE gpalRGB, gpalBGR, gpalMono;
+PALETTE gpalRGB, gpalBGR, gpalMono, gpalRGB555, gpalRGB565;
 
 const PALETTEENTRY g_sysPalTemplate[NB_RESERVED_COLORS] =
 {
@@ -104,14 +104,34 @@ HPALETTE FASTCALL PALETTE_Init(VOID)
     gpalRGB.RedMask = RGB(0xFF, 0x00, 0x00);
     gpalRGB.GreenMask = RGB(0x00, 0xFF, 0x00);
     gpalRGB.BlueMask = RGB(0x00, 0x00, 0xFF);
+    gpalRGB.BaseObject.ulShareCount = 0;
+    gpalRGB.BaseObject.BaseFlags = 0 ;
 
     gpalBGR.Mode = PAL_BGR;
     gpalBGR.RedMask = RGB(0x00, 0x00, 0xFF);
     gpalBGR.GreenMask = RGB(0x00, 0xFF, 0x00);
     gpalBGR.BlueMask = RGB(0xFF, 0x00, 0x00);
+    gpalBGR.BaseObject.ulShareCount = 0;
+    gpalBGR.BaseObject.BaseFlags = 0 ;
+
+    gpalRGB555.Mode = PAL_RGB16_555 | PAL_BITFIELDS;
+    gpalRGB555.RedMask = 0x7C00;
+    gpalRGB555.GreenMask = 0x3E0;
+    gpalRGB555.BlueMask = 0x1F;
+    gpalRGB555.BaseObject.ulShareCount = 0;
+    gpalRGB555.BaseObject.BaseFlags = 0 ;
+
+    gpalRGB565.Mode = PAL_RGB16_565 | PAL_BITFIELDS;
+    gpalRGB565.RedMask = 0xF800;
+    gpalRGB565.GreenMask = 0x7E0;
+    gpalRGB565.BlueMask = 0x1F;
+    gpalRGB565.BaseObject.ulShareCount = 0;
+    gpalRGB565.BaseObject.BaseFlags = 0 ;
 
     memset(&gpalMono, 0, sizeof(PALETTE));
     gpalMono.Mode = PAL_MONOCHROME;
+    gpalMono.BaseObject.ulShareCount = 0;
+    gpalMono.BaseObject.BaseFlags = 0 ;
 
     return hpalette;
 }
@@ -169,7 +189,7 @@ PALETTE_AllocPalette(ULONG Mode,
         PalGDI->RedMask = Red;
         PalGDI->GreenMask = Green;
         PalGDI->BlueMask = Blue;
-        
+
         if (Red == 0x7c00 && Green == 0x3E0 && Blue == 0x1F)
             PalGDI->Mode |= PAL_RGB16_555;
         else if (Red == 0xF800 && Green == 0x7E0 && Blue == 0x1F)