Refactored Glyph API.
authorArmin Novak <armin.novak@thincast.com>
Mon, 18 Jul 2016 12:30:26 +0000 (14:30 +0200)
committerArmin Novak <armin.novak@thincast.com>
Thu, 6 Oct 2016 11:43:02 +0000 (13:43 +0200)
include/freerdp/graphics.h
libfreerdp/cache/glyph.c
libfreerdp/core/graphics.c
libfreerdp/gdi/graphics.c

index f70ad47..edf3499 100644 (file)
@@ -151,13 +151,6 @@ struct rdp_glyph
 };
 
 FREERDP_API rdpGlyph* Glyph_Alloc(rdpContext* context);
-FREERDP_API BOOL Glyph_New(rdpContext* context, rdpGlyph* glyph);
-FREERDP_API void Glyph_Free(rdpContext* context, rdpGlyph* glyph);
-FREERDP_API BOOL Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y);
-FREERDP_API BOOL Glyph_BeginDraw(rdpContext* context, int x, int y, int width,
-                                 int height, UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant);
-FREERDP_API BOOL Glyph_EndDraw(rdpContext* context, int x, int y, int width,
-                               int height, UINT32 bgcolor, UINT32 fgcolor);
 
 /* Graphics Module */
 
index 33e789f..434961f 100644 (file)
@@ -78,7 +78,7 @@ static void update_process_glyph(rdpContext* context, const BYTE* data,
 
        if (glyph != NULL)
        {
-               Glyph_Draw(context, glyph, glyph->x + *x, glyph->y + *y);
+               glyph->Draw(context, glyph, glyph->x + *x, glyph->y + *y);
 
                if (flAccel & SO_CHAR_INC_EQUAL_BM_BASE)
                        *x += glyph->cx;
@@ -104,8 +104,10 @@ static BOOL update_process_glyph_fragments(rdpContext* context,
        BYTE* fragments;
        rdpGraphics* graphics;
        rdpGlyphCache* glyph_cache;
+       rdpGlyph* glyph;
        graphics = context->graphics;
        glyph_cache = context->cache->glyph;
+       glyph = graphics->Glyph_Prototype;
 
        if (opX + opWidth > context->settings->DesktopWidth)
        {
@@ -123,21 +125,21 @@ static BOOL update_process_glyph_fragments(rdpContext* context,
 
        if (opWidth > 0 && opHeight > 0)
        {
-               if (!Glyph_BeginDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor,
-                                    fOpRedundant))
+               if (!glyph->BeginDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor,
+                                     fOpRedundant))
                        return FALSE;
        }
        else
        {
                if (fOpRedundant)
                {
-                       if (!Glyph_BeginDraw(context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor,
-                                            fOpRedundant))
+                       if (!glyph->BeginDraw(context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor,
+                                             fOpRedundant))
                                return FALSE;
                }
                else
                {
-                       if (!Glyph_BeginDraw(context, 0, 0, 0, 0, bgcolor, fgcolor, fOpRedundant))
+                       if (!glyph->BeginDraw(context, 0, 0, 0, 0, bgcolor, fgcolor, fOpRedundant))
                                return FALSE;
                }
        }
@@ -213,9 +215,9 @@ static BOOL update_process_glyph_fragments(rdpContext* context,
        }
 
        if (opWidth > 0 && opHeight > 0)
-               return Glyph_EndDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor);
+               return glyph->EndDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor);
 
-       return Glyph_EndDraw(context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor);
+       return glyph->EndDraw(context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor);
 }
 
 static BOOL update_gdi_glyph_index(rdpContext* context,
@@ -369,7 +371,7 @@ static BOOL update_gdi_fast_glyph(rdpContext* context,
 
                CopyMemory(glyph->aj, glyphData->aj, glyph->cb);
 
-               if (!Glyph_New(context, glyph))
+               if (!glyph->New(context, glyph))
                        goto error_glyph_new;
 
                glyph_cache_put(cache->glyph, fastGlyph->cacheId, fastGlyph->data[0], glyph);
@@ -386,10 +388,8 @@ static BOOL update_gdi_fast_glyph(rdpContext* context,
                                              opRight - opLeft, opBottom - opTop,
                                              FALSE);
 error_glyph_new:
-       free(glyph->aj);
-       glyph->aj = NULL;
 error_aj:
-       Glyph_Free(context, glyph);
+       IFCALL(glyph->Free, context, glyph);
        return FALSE;
 }
 
@@ -416,9 +416,9 @@ static BOOL update_gdi_cache_glyph(rdpContext* context,
                glyph->cb = glyph_data->cb;
                glyph->aj = glyph_data->aj;
 
-               if (!Glyph_New(context, glyph))
+               if (!glyph->New(context, glyph))
                {
-                       Glyph_Free(context, glyph);
+                       glyph->Free(context, glyph);
                        return FALSE;
                }
 
@@ -454,9 +454,9 @@ static BOOL update_gdi_cache_glyph_v2(rdpContext* context,
                glyph->cb = glyphData->cb;
                glyph->aj = glyphData->aj;
 
-               if (!Glyph_New(context, glyph))
+               if (!glyph->New(context, glyph))
                {
-                       Glyph_Free(context, glyph);
+                       glyph->Free(context, glyph);
                        return FALSE;
                }
 
@@ -513,11 +513,7 @@ BOOL glyph_cache_put(rdpGlyphCache* glyphCache, UINT32 id, UINT32 index,
        prevGlyph = glyphCache->glyphCache[id].entries[index];
 
        if (prevGlyph)
-       {
-               Glyph_Free(glyphCache->context, prevGlyph);
-               free(prevGlyph->aj);
-               free(prevGlyph);
-       }
+               glyph->Free(glyphCache->context, prevGlyph);
 
        glyphCache->glyphCache[id].entries[index] = glyph;
        return TRUE;
@@ -616,9 +612,7 @@ void glyph_cache_free(rdpGlyphCache* glyphCache)
 
                                if (glyph)
                                {
-                                       Glyph_Free(glyphCache->context, glyph);
-                                       free(glyph->aj);
-                                       free(glyph);
+                                       glyph->Free(glyphCache->context, glyph);
                                        glyphCache->glyphCache[i].entries[j] = NULL;
                                }
                        }
index 5d43f70..cb61446 100644 (file)
@@ -162,35 +162,6 @@ rdpGlyph* Glyph_Alloc(rdpContext* context)
        return glyph;
 }
 
-BOOL Glyph_New(rdpContext* context, rdpGlyph* glyph)
-{
-       return context->graphics->Glyph_Prototype->New(context, glyph);
-}
-
-void Glyph_Free(rdpContext* context, rdpGlyph* glyph)
-{
-       context->graphics->Glyph_Prototype->Free(context, glyph);
-}
-
-BOOL Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y)
-{
-       return context->graphics->Glyph_Prototype->Draw(context, glyph, x, y);
-}
-
-BOOL Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height,
-                     UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant)
-{
-       return context->graphics->Glyph_Prototype->BeginDraw(context, x, y, width,
-               height, bgcolor, fgcolor, fOpRedundant);
-}
-
-BOOL Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height,
-                   UINT32 bgcolor, UINT32 fgcolor)
-{
-       return context->graphics->Glyph_Prototype->EndDraw(context, x, y, width, height,
-               bgcolor, fgcolor);
-}
-
 void graphics_register_glyph(rdpGraphics* graphics, rdpGlyph* glyph)
 {
        CopyMemory(graphics->Glyph_Prototype, glyph, sizeof(rdpGlyph));
@@ -240,8 +211,6 @@ rdpGraphics* graphics_new(rdpContext* context)
                }
 
                graphics->Glyph_Prototype->size = sizeof(rdpGlyph);
-               graphics->Glyph_Prototype->New = Glyph_New;
-               graphics->Glyph_Prototype->Free = Glyph_Free;
        }
 
        return graphics;
index 35945ca..97905b2 100644 (file)
@@ -236,6 +236,8 @@ static void gdi_Glyph_Free(rdpContext* context, rdpGlyph* glyph)
                gdi_SelectObject(gdi_glyph->hdc, (HGDIOBJECT) gdi_glyph->org_bitmap);
                gdi_DeleteObject((HGDIOBJECT) gdi_glyph->bitmap);
                gdi_DeleteDC(gdi_glyph->hdc);
+               free(glyph->aj);
+               free(glyph);
        }
 }