- Deactivate unneeded debug prints, change DbgPrint to DPRINTx, remove unused perform...
[reactos.git] / reactos / subsystems / win32 / win32k / objects / freetype.c
index 6511dd0..5f20afc 100644 (file)
@@ -75,8 +75,6 @@ static FAST_MUTEX FontListLock;
 static BOOL RenderingEnabled = TRUE;
 
 #define MAX_FONT_CACHE 256
-UINT Hits;
-UINT Misses;
 
 typedef struct _FONT_CACHE_ENTRY
 {
@@ -1322,8 +1320,6 @@ ftGdiGlyphCacheGet(
     PLIST_ENTRY CurrentEntry;
     PFONT_CACHE_ENTRY FontEntry;
 
-//   DbgPrint("CacheGet\n");
-
     CurrentEntry = FontCacheListHead.Flink;
     while (CurrentEntry != &FontCacheListHead)
     {
@@ -1337,29 +1333,11 @@ ftGdiGlyphCacheGet(
 
     if (CurrentEntry == &FontCacheListHead)
     {
-//      DbgPrint("Miss! %x\n", FontEntry->Glyph);
-        /*
-              Misses++;
-              if (Misses>100) {
-                 DbgPrint ("Hits: %d Misses: %d\n", Hits, Misses);
-                 Hits = Misses = 0;
-              }
-        */
         return NULL;
     }
 
     RemoveEntryList(CurrentEntry);
     InsertHeadList(&FontCacheListHead, CurrentEntry);
-
-//   DbgPrint("Hit! %x\n", FontEntry->Glyph);
-    /*
-       Hits++;
-
-          if (Hits>100) {
-             DbgPrint ("Hits: %d Misses: %d\n", Hits, Misses);
-             Hits = Misses = 0;
-          }
-    */
     return FontEntry->Glyph;
 }
 
@@ -1375,25 +1353,23 @@ ftGdiGlyphCacheSet(
     INT error;
     PFONT_CACHE_ENTRY NewEntry;
 
-//   DbgPrint("CacheSet.\n");
-
     error = FT_Get_Glyph(GlyphSlot, &GlyphCopy);
     if (error)
     {
-        DbgPrint("Failure caching glyph.\n");
+        DPRINT1("Failure caching glyph.\n");
         return NULL;
     };
     error = FT_Glyph_To_Bitmap(&GlyphCopy, RenderMode, 0, 1);
     if (error)
     {
-        DbgPrint("Failure rendering glyph.\n");
+        DPRINT1("Failure rendering glyph.\n");
         return NULL;
     };
 
     NewEntry = ExAllocatePoolWithTag(PagedPool, sizeof(FONT_CACHE_ENTRY), TAG_FONT);
     if (!NewEntry)
     {
-        DbgPrint("Alloc failure caching glyph.\n");
+        DPRINT1("Alloc failure caching glyph.\n");
         FT_Done_Glyph(GlyphCopy);
         return NULL;
     }
@@ -1413,8 +1389,6 @@ ftGdiGlyphCacheSet(
         FontCacheNumEntries--;
     }
 
-//   DbgPrint("Returning the glyphcopy: %x\n", GlyphCopy);
-
     return GlyphCopy;
 }
 
@@ -1470,7 +1444,7 @@ ftGdiGetGlyphOutline(
     BOOL bIgnoreRotation)
 {
     static const FT_Matrix identityMat = {(1 << 16), 0, 0, (1 << 16)};
-    PDC_ATTR Dc_Attr;
+    PDC_ATTR pdcattr;
     PTEXTOBJ TextObj;
     PFONTGDI FontGDI;
     HFONT hFont = 0;
@@ -1498,13 +1472,12 @@ ftGdiGetGlyphOutline(
     DPRINT("%d, %08x, %p, %08lx, %p, %p\n", wch, iFormat, pgm,
            cjBuf, pvBuf, pmat2);
 
-    Dc_Attr = dc->pDc_Attr;
-    if (!Dc_Attr) Dc_Attr = &dc->Dc_Attr;
+    pdcattr = dc->pdcattr;
 
-    MatrixS2XForm(&xForm, &dc->DcLevel.mxWorldToDevice);
+    MatrixS2XForm(&xForm, &dc->dclevel.mxWorldToDevice);
     eM11 = xForm.eM11;
 
-    hFont = Dc_Attr->hlfntNew;
+    hFont = pdcattr->hlfntNew;
     TextObj = RealizeFontInit(hFont);
 
     if (!TextObj)
@@ -2228,7 +2201,7 @@ ftGdiGetTextCharsetInfo(
     LPFONTSIGNATURE lpSig,
     DWORD dwFlags)
 {
-    PDC_ATTR Dc_Attr;
+    PDC_ATTR pdcattr;
     UINT Ret = DEFAULT_CHARSET, i;
     HFONT hFont;
     PTEXTOBJ TextObj;
@@ -2240,9 +2213,8 @@ ftGdiGetTextCharsetInfo(
     DWORD cp, fs0;
     USHORT usACP, usOEM;
 
-    Dc_Attr = Dc->pDc_Attr;
-    if (!Dc_Attr) Dc_Attr = &Dc->Dc_Attr;
-    hFont = Dc_Attr->hlfntNew;
+    pdcattr = Dc->pdcattr;
+    hFont = pdcattr->hlfntNew;
     TextObj = RealizeFontInit(hFont);
 
     if (!TextObj)
@@ -2407,7 +2379,7 @@ ftGdiGetTextMetricsW(
     PTMW_INTERNAL ptmwi)
 {
     PDC dc;
-    PDC_ATTR Dc_Attr;
+    PDC_ATTR pdcattr;
     PTEXTOBJ TextObj;
     PFONTGDI FontGDI;
     FT_Face Face;
@@ -2428,9 +2400,8 @@ ftGdiGetTextMetricsW(
         SetLastWin32Error(ERROR_INVALID_HANDLE);
         return FALSE;
     }
-    Dc_Attr = dc->pDc_Attr;
-    if (!Dc_Attr) Dc_Attr = &dc->Dc_Attr;
-    TextObj = RealizeFontInit(Dc_Attr->hlfntNew);
+    pdcattr = dc->pdcattr;
+    TextObj = RealizeFontInit(pdcattr->hlfntNew);
     if (NULL != TextObj)
     {
         FontGDI = ObjToGDI(TextObj->Font, FONT);
@@ -3105,7 +3076,7 @@ GreExtTextOutW(
     IN INT XStart,
     IN INT YStart,
     IN UINT fuOptions,
-    IN OPTIONAL LPRECT lprc,
+    IN OPTIONAL PRECTL lprc,
     IN LPWSTR String,
     IN INT Count,
     IN OPTIONAL LPINT Dx,
@@ -3118,7 +3089,7 @@ GreExtTextOutW(
      */
 
     DC *dc;
-    PDC_ATTR Dc_Attr;
+    PDC_ATTR pdcattr;
     SURFOBJ *SurfObj;
     SURFACE *psurf = NULL;
     int error, glyph_index, n, i;
@@ -3131,12 +3102,6 @@ GreExtTextOutW(
     FT_Bool use_kerning;
     RECTL DestRect, MaskRect;
     POINTL SourcePoint, BrushOrigin;
-    HBRUSH hBrushFg = NULL;
-    PGDIBRUSHOBJ BrushFg = NULL;
-    GDIBRUSHINST BrushFgInst;
-    HBRUSH hBrushBg = NULL;
-    PGDIBRUSHOBJ BrushBg = NULL;
-    GDIBRUSHINST BrushBgInst;
     HBITMAP HSourceGlyph;
     SURFOBJ *SourceGlyphSurf;
     SIZEL bitSize;
@@ -3145,9 +3110,7 @@ GreExtTextOutW(
     FONTOBJ *FontObj;
     PFONTGDI FontGDI;
     PTEXTOBJ TextObj = NULL;
-    PPALGDI PalDestGDI;
     XLATEOBJ *XlateObj=NULL, *XlateObj2=NULL;
-    ULONG Mode;
     FT_Render_Mode RenderMode;
     BOOLEAN Render;
     POINT Start;
@@ -3163,15 +3126,23 @@ GreExtTextOutW(
         SetLastWin32Error(ERROR_INVALID_HANDLE);
         return FALSE;
     }
-    if (dc->DC_Type == DC_TYPE_INFO)
+    if (dc->dctype == DC_TYPE_INFO)
     {
         DC_UnlockDc(dc);
         /* Yes, Windows really returns TRUE in this case */
         return TRUE;
     }
 
-    Dc_Attr = dc->pDc_Attr;
-    if (!Dc_Attr) Dc_Attr = &dc->Dc_Attr;
+    pdcattr = dc->pdcattr;
+
+    if (pdcattr->ulDirty_ & DIRTY_TEXT)
+        DC_vUpdateTextBrush(dc);
+
+    if ((fuOptions & ETO_OPAQUE) || pdcattr->jBkMode == OPAQUE)
+    {
+        if (pdcattr->ulDirty_ & DIRTY_BACKGROUND)
+            DC_vUpdateBackgroundBrush(dc);
+    }
 
     /* Check if String is valid */
     if ((Count > 0xFFFF) || (Count > 0 && String == NULL))
@@ -3182,13 +3153,13 @@ GreExtTextOutW(
 
     DxShift = fuOptions & ETO_PDY ? 1 : 0;
 
-    if (PATH_IsPathOpen(dc->DcLevel))
+    if (PATH_IsPathOpen(dc->dclevel))
     {
         if (!PATH_ExtTextOut( dc,
                               XStart,
                               YStart,
                               fuOptions,
-                              (const RECT *)lprc,
+                              (const RECTL *)lprc,
                               String,
                               Count,
                               (const INT *)Dx)) goto fail;
@@ -3200,13 +3171,12 @@ GreExtTextOutW(
         IntLPtoDP(dc, (POINT *)lprc, 2);
     }
 
-    psurf = SURFACE_LockSurface(dc->w.hBitmap);
+    psurf = SURFACE_LockSurface(dc->rosdc.hBitmap);
     if (!psurf)
     {
         goto fail;
     }
     SurfObj = &psurf->SurfObj;
-    ASSERT(SurfObj);
 
     Start.x = XStart;
     Start.y = YStart;
@@ -3218,45 +3188,12 @@ GreExtTextOutW(
     /* Create the brushes */
     hDestPalette = psurf->hDIBPalette;
     if (!hDestPalette) hDestPalette = pPrimarySurface->DevInfo.hpalDefault;
-    PalDestGDI = PALETTE_LockPalette(hDestPalette);
-    if ( !PalDestGDI )
-        Mode = PAL_RGB;
-    else
-    {
-        Mode = PalDestGDI->Mode;
-        PALETTE_UnlockPalette(PalDestGDI);
-    }
-    XlateObj = (XLATEOBJ*)IntEngCreateXlate(Mode, PAL_RGB, hDestPalette, NULL);
+    XlateObj = (XLATEOBJ*)IntEngCreateXlate(0, PAL_RGB, hDestPalette, NULL);
     if ( !XlateObj )
     {
         goto fail;
     }
-    hBrushFg = NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj, Dc_Attr->crForegroundClr), 0);
-    if ( !hBrushFg )
-    {
-        goto fail;
-    }
-    BrushFg = BRUSHOBJ_LockBrush(hBrushFg);
-    if ( !BrushFg )
-    {
-        goto fail;
-    }
-    IntGdiInitBrushInstance(&BrushFgInst, BrushFg, NULL);
-    if ((fuOptions & ETO_OPAQUE) || Dc_Attr->jBkMode == OPAQUE)
-    {
-        hBrushBg = NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj, Dc_Attr->crBackgroundClr), 0);
-        if ( !hBrushBg )
-        {
-            goto fail;
-        }
-        BrushBg = BRUSHOBJ_LockBrush(hBrushBg);
-        if ( !BrushBg )
-        {
-            goto fail;
-        }
-        IntGdiInitBrushInstance(&BrushBgInst, BrushBg, NULL);
-    }
-    XlateObj2 = (XLATEOBJ*)IntEngCreateXlate(PAL_RGB, Mode, NULL, hDestPalette);
+    XlateObj2 = (XLATEOBJ*)IntEngCreateXlate(PAL_RGB, 0, NULL, hDestPalette);
     if ( !XlateObj2 )
     {
         goto fail;
@@ -3271,34 +3208,41 @@ GreExtTextOutW(
 
     if ((fuOptions & ETO_OPAQUE) && lprc)
     {
-        DestRect.left   = lprc->left   + dc->ptlDCOrig.x;
-        DestRect.top    = lprc->top    + dc->ptlDCOrig.y;
-        DestRect.right  = lprc->right  + dc->ptlDCOrig.x;
-        DestRect.bottom = lprc->bottom + dc->ptlDCOrig.y;
+        DestRect.left   = lprc->left;
+        DestRect.top    = lprc->top;
+        DestRect.right  = lprc->right;
+        DestRect.bottom = lprc->bottom;
+
         IntLPtoDP(dc, (LPPOINT)&DestRect, 2);
+
+        DestRect.left   += dc->ptlDCOrig.x;
+        DestRect.top    += dc->ptlDCOrig.y;
+        DestRect.right  += dc->ptlDCOrig.x;
+        DestRect.bottom += dc->ptlDCOrig.y;
+
         IntEngBitBlt(
             &psurf->SurfObj,
             NULL,
             NULL,
-            dc->CombinedClip,
+            dc->rosdc.CombinedClip,
             NULL,
             &DestRect,
             &SourcePoint,
             &SourcePoint,
-            &BrushBgInst.BrushObject,
+            &dc->eboBackground.BrushObject,
             &BrushOrigin,
             ROP3_TO_ROP4(PATCOPY));
         fuOptions &= ~ETO_OPAQUE;
     }
     else
     {
-        if (Dc_Attr->jBkMode == OPAQUE)
+        if (pdcattr->jBkMode == OPAQUE)
         {
             fuOptions |= ETO_OPAQUE;
         }
     }
 
-    TextObj = RealizeFontInit(Dc_Attr->hlfntNew);
+    TextObj = RealizeFontInit(pdcattr->hlfntNew);
     if (TextObj == NULL)
     {
         goto fail;
@@ -3361,9 +3305,9 @@ GreExtTextOutW(
      * Process the vertical alignment and determine the yoff.
      */
 
-    if (Dc_Attr->lTextAlign & TA_BASELINE)
+    if (pdcattr->lTextAlign & TA_BASELINE)
         yoff = 0;
-    else if (Dc_Attr->lTextAlign & TA_BOTTOM)
+    else if (pdcattr->lTextAlign & TA_BOTTOM)
         yoff = -face->size->metrics.descender >> 6;
     else /* TA_TOP */
         yoff = face->size->metrics.ascender >> 6;
@@ -3375,7 +3319,7 @@ GreExtTextOutW(
      * Process the horizontal alignment and modify XStart accordingly.
      */
 
-    if (Dc_Attr->lTextAlign & (TA_RIGHT | TA_CENTER))
+    if (pdcattr->lTextAlign & (TA_RIGHT | TA_CENTER))
     {
         ULONGLONG TextWidth = 0;
         LPCWSTR TempText = String;
@@ -3439,7 +3383,7 @@ GreExtTextOutW(
 
         previous = 0;
 
-        if (Dc_Attr->lTextAlign & TA_RIGHT)
+        if (pdcattr->lTextAlign & TA_RIGHT)
         {
             RealXStart -= TextWidth;
         }
@@ -3487,8 +3431,6 @@ GreExtTextOutW(
                 goto fail;
             }
         }
-//      DbgPrint("realglyph: %x\n", realglyph);
-//      DbgPrint("TextLeft: %d\n", TextLeft);
 
         /* retrieve kerning distance and move pen position */
         if (use_kerning && previous && glyph_index && NULL == Dx)
@@ -3497,12 +3439,12 @@ GreExtTextOutW(
             FT_Get_Kerning(face, previous, glyph_index, 0, &delta);
             TextLeft += delta.x;
         }
-//      DPRINT1("TextLeft: %d\n", TextLeft);
-//      DPRINT1("TextTop: %d\n", TextTop);
+        DPRINT("TextLeft: %d\n", TextLeft);
+        DPRINT("TextTop: %d\n", TextTop);
 
         if (realglyph->format == ft_glyph_format_outline)
         {
-            DbgPrint("Should already be done\n");
+            DPRINT1("Should already be done\n");
 //         error = FT_Render_Glyph(glyph, RenderMode);
             error = FT_Glyph_To_Bitmap(&realglyph, RenderMode, 0, 0);
             if (error)
@@ -3513,8 +3455,7 @@ GreExtTextOutW(
         }
         realglyph2 = (FT_BitmapGlyph)realglyph;
 
-//      DPRINT1("Pitch: %d\n", pitch);
-//      DPRINT1("Advance: %d\n", realglyph->advance.x);
+        DPRINT("Advance: %d\n", realglyph->advance.x);
 
         if (fuOptions & ETO_OPAQUE)
         {
@@ -3526,12 +3467,12 @@ GreExtTextOutW(
                 &psurf->SurfObj,
                 NULL,
                 NULL,
-                dc->CombinedClip,
+                dc->rosdc.CombinedClip,
                 NULL,
                 &DestRect,
                 &SourcePoint,
                 &SourcePoint,
-                &BrushBgInst.BrushObject,
+                &dc->eboBackground.BrushObject,
                 &BrushOrigin,
                 ROP3_TO_ROP4(PATCOPY));
             BackgroundLeft = DestRect.right;
@@ -3597,13 +3538,12 @@ GreExtTextOutW(
         IntEngMaskBlt(
             SurfObj,
             SourceGlyphSurf,
-            dc->CombinedClip,
+            dc->rosdc.CombinedClip,
             XlateObj,
             XlateObj2,
             &DestRect,
-            &SourcePoint,
             (PPOINTL)&MaskRect,
-            &BrushFgInst.BrushObject,
+            &dc->eboText.BrushObject,
             &BrushOrigin);
 
         EngUnlockSurface(SourceGlyphSurf);
@@ -3617,12 +3557,12 @@ GreExtTextOutW(
         if (NULL == Dx)
         {
             TextLeft += realglyph->advance.x >> 10;
-//         DbgPrint("new TextLeft: %d\n", TextLeft);
+             DPRINT("new TextLeft: %d\n", TextLeft);
         }
         else
         {
             TextLeft += Dx[i<<DxShift] << 6;
-//         DbgPrint("new TextLeft2: %d\n", TextLeft);
+             DPRINT("new TextLeft2: %d\n", TextLeft);
         }
 
         if (DxShift)
@@ -3642,13 +3582,6 @@ GreExtTextOutW(
     SURFACE_UnlockSurface(psurf);
     if (TextObj != NULL)
         TEXTOBJ_UnlockText(TextObj);
-    if (hBrushBg != NULL)
-    {
-        BRUSHOBJ_UnlockBrush(BrushBg);
-        NtGdiDeleteObject(hBrushBg);
-    }
-    BRUSHOBJ_UnlockBrush(BrushFg);
-    NtGdiDeleteObject(hBrushFg);
 good:
     DC_UnlockDc( dc );
 
@@ -3663,16 +3596,6 @@ fail:
         TEXTOBJ_UnlockText(TextObj);
     if (psurf != NULL)
         SURFACE_UnlockSurface(psurf);
-    if (hBrushBg != NULL)
-    {
-        BRUSHOBJ_UnlockBrush(BrushBg);
-        NtGdiDeleteObject(hBrushBg);
-    }
-    if (hBrushFg != NULL)
-    {
-        BRUSHOBJ_UnlockBrush(BrushFg);
-        NtGdiDeleteObject(hBrushFg);
-    }
     DC_UnlockDc(dc);
 
     return FALSE;
@@ -3694,7 +3617,7 @@ NtGdiExtTextOutW(
 {
     BOOL Result = FALSE;
     NTSTATUS Status = STATUS_SUCCESS;
-    RECT SafeRect;
+    RECTL SafeRect;
     BYTE LocalBuffer[STACK_TEXT_BUFFER_SIZE];
     PVOID Buffer = LocalBuffer;
     LPWSTR SafeString = NULL;
@@ -3817,7 +3740,7 @@ NtGdiGetCharABCWidthsW(
     LPABC SafeBuff;
     LPABCFLOAT SafeBuffF = NULL;
     PDC dc;
-    PDC_ATTR Dc_Attr;
+    PDC_ATTR pdcattr;
     PTEXTOBJ TextObj;
     PFONTGDI FontGDI;
     FT_Face face;
@@ -3862,9 +3785,8 @@ NtGdiGetCharABCWidthsW(
         SetLastWin32Error(ERROR_INVALID_HANDLE);
         return FALSE;
     }
-    Dc_Attr = dc->pDc_Attr;
-    if (!Dc_Attr) Dc_Attr = &dc->Dc_Attr;
-    hFont = Dc_Attr->hlfntNew;
+    pdcattr = dc->pdcattr;
+    hFont = pdcattr->hlfntNew;
     TextObj = RealizeFontInit(hFont);
     DC_UnlockDc(dc);
 
@@ -3986,7 +3908,7 @@ NtGdiGetCharWidthW(
     LPINT SafeBuff;
     PFLOAT SafeBuffF = NULL;
     PDC dc;
-    PDC_ATTR Dc_Attr;
+    PDC_ATTR pdcattr;
     PTEXTOBJ TextObj;
     PFONTGDI FontGDI;
     FT_Face face;
@@ -4030,9 +3952,8 @@ NtGdiGetCharWidthW(
         SetLastWin32Error(ERROR_INVALID_HANDLE);
         return FALSE;
     }
-    Dc_Attr = dc->pDc_Attr;
-    if (!Dc_Attr) Dc_Attr = &dc->Dc_Attr;
-    hFont = Dc_Attr->hlfntNew;
+    pdcattr = dc->pdcattr;
+    hFont = pdcattr->hlfntNew;
     TextObj = RealizeFontInit(hFont);
     DC_UnlockDc(dc);
 
@@ -4122,7 +4043,7 @@ NtGdiGetGlyphIndicesW(
     IN DWORD iMode)
 {
     PDC dc;
-    PDC_ATTR Dc_Attr;
+    PDC_ATTR pdcattr;
     PTEXTOBJ TextObj;
     PFONTGDI FontGDI;
     HFONT hFont = 0;
@@ -4142,9 +4063,8 @@ NtGdiGetGlyphIndicesW(
         SetLastWin32Error(ERROR_INVALID_HANDLE);
         return GDI_ERROR;
     }
-    Dc_Attr = dc->pDc_Attr;
-    if (!Dc_Attr) Dc_Attr = &dc->Dc_Attr;
-    hFont = Dc_Attr->hlfntNew;
+    pdcattr = dc->pdcattr;
+    hFont = pdcattr->hlfntNew;
     TextObj = RealizeFontInit(hFont);
     DC_UnlockDc(dc);
     if (!TextObj)