Skip to content

Commit

Permalink
libfreerdp-cache: moving glyph to a graphical object
Browse files Browse the repository at this point in the history
  • Loading branch information
awakecoding committed Nov 9, 2011
1 parent a670962 commit 155446d
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 56 deletions.
14 changes: 1 addition & 13 deletions include/freerdp/cache/glyph.h
Expand Up @@ -30,12 +30,6 @@ typedef struct _FRAGMENT_CACHE_ENTRY FRAGMENT_CACHE_ENTRY;
typedef struct _FRAGMENT_CACHE FRAGMENT_CACHE;
typedef struct rdp_glyph_cache rdpGlyphCache;

typedef void (*pGlyphNew)(rdpContext* context, rdpGlyph* glyph);
typedef void (*pGlyphFree)(rdpContext* context, rdpGlyph* glyph);
typedef void (*pDrawGlyph)(rdpContext* context, rdpGlyph* glyph, int x, int y);
typedef void (*pBeginDrawText)(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor);
typedef void (*pEndDrawText)(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor);

#include <freerdp/cache/cache.h>

struct _GLYPH_CACHE
Expand All @@ -58,13 +52,7 @@ struct _FRAGMENT_CACHE

struct rdp_glyph_cache
{
int glyph_size;
pGlyphNew GlyphNew;
pGlyphFree GlyphFree;
pDrawGlyph DrawGlyph;
pBeginDrawText BeginDrawText;
pEndDrawText EndDrawText;

rdpContext* context;
rdpSettings* settings;
GLYPH_CACHE glyphCache[10];
FRAGMENT_CACHE fragCache;
Expand Down
36 changes: 36 additions & 0 deletions include/freerdp/graphics.h
Expand Up @@ -22,6 +22,7 @@

typedef struct rdp_bitmap rdpBitmap;
typedef struct rdp_pointer rdpPointer;
typedef struct rdp_glyph rdpGlyph;

#include <stdlib.h>
#include <freerdp/api.h>
Expand Down Expand Up @@ -104,17 +105,52 @@ FREERDP_API void Pointer_New(rdpContext* context, rdpPointer* pointer);
FREERDP_API void Pointer_Free(rdpContext* context, rdpPointer* pointer);
FREERDP_API void Pointer_Set(rdpContext* context, rdpPointer* pointer);

/* Glyph Class */

typedef void (*pGlyph_New)(rdpContext* context, rdpGlyph* glyph);
typedef void (*pGlyph_Free)(rdpContext* context, rdpGlyph* glyph);
typedef void (*pGlyph_Draw)(rdpContext* context, rdpGlyph* glyph, int x, int y);
typedef void (*pGlyph_BeginDraw)(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor);
typedef void (*pGlyph_EndDraw)(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor);

struct rdp_glyph
{
size_t size;

sint16 x;
sint16 y;
uint16 cx;
uint16 cy;
uint16 cb;
uint8* aj;

pGlyph_New New;
pGlyph_Free Free;
pGlyph_Draw Draw;
pGlyph_BeginDraw BeginDraw;
pGlyph_EndDraw EndDraw;
};

FREERDP_API rdpGlyph* Glyph_Alloc(rdpContext* context);
FREERDP_API void Glyph_New(rdpContext* context, rdpGlyph* glyph);
FREERDP_API void Glyph_Free(rdpContext* context, rdpGlyph* glyph);
FREERDP_API void Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y);
FREERDP_API void Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor);
FREERDP_API void Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor);

/* Graphics Module */

struct rdp_graphics
{
rdpContext* context;
rdpBitmap* Bitmap_Prototype;
rdpPointer* Pointer_Prototype;
rdpGlyph* Glyph_Prototype;
};

FREERDP_API void graphics_register_bitmap(rdpGraphics* graphics, rdpBitmap* bitmap);
FREERDP_API void graphics_register_pointer(rdpGraphics* graphics, rdpPointer* pointer);
FREERDP_API void graphics_register_glyph(rdpGraphics* graphics, rdpGlyph* glyph);

FREERDP_API rdpGraphics* graphics_new(rdpContext* context);
FREERDP_API void graphics_free(rdpGraphics* graphics);
Expand Down
11 changes: 0 additions & 11 deletions include/freerdp/update.h
Expand Up @@ -57,17 +57,6 @@ struct rdp_brush
};
typedef struct rdp_brush rdpBrush;

struct rdp_glyph
{
sint16 x;
sint16 y;
uint16 cx;
uint16 cy;
uint16 cb;
uint8* aj;
};
typedef struct rdp_glyph rdpGlyph;

/* Bitmap Updates */

struct _BITMAP_DATA
Expand Down
36 changes: 26 additions & 10 deletions libfreerdp-cache/glyph.c
Expand Up @@ -28,15 +28,17 @@ void update_process_glyph(rdpUpdate* update, uint8* data, int* index,
{
int offset;
rdpGlyph* glyph;
rdpGraphics* graphics;
rdpGlyphCache* glyph_cache;

graphics = update->context->graphics;
glyph_cache = update->context->cache->glyph;

glyph = glyph_cache_get(glyph_cache, cacheId, data[(*index)++]);

if (glyph != NULL)
{
IFCALL(glyph_cache->DrawGlyph, update->context, glyph, *x, *y);
Glyph_Draw(update->context, glyph, *x, *y);
}

offset = data[(*index)++];
Expand All @@ -61,21 +63,22 @@ void update_process_glyph(rdpUpdate* update, uint8* data, int* index,
}

void update_process_glyph_fragments(rdpUpdate* update, uint8* data, uint8 length,
uint8 cacheId, boolean delta, boolean vertical,
uint32 bgcolor, uint32 fgcolor, int x, int y,
uint8 cacheId, boolean delta, boolean vertical, uint32 bgcolor, uint32 fgcolor, int x, int y,
int bkX, int bkY, int bkWidth, int bkHeight, int opX, int opY, int opWidth, int opHeight)
{
int n;
uint8 id;
uint8 size;
int index = 0;
uint8* fragments;
rdpGraphics* graphics;
rdpGlyphCache* glyph_cache;

graphics = update->context->graphics;
glyph_cache = update->context->cache->glyph;

if (opWidth > 1)
IFCALL(glyph_cache->BeginDrawText, update->context, opX, opY, opWidth, opHeight, bgcolor, fgcolor);
Glyph_BeginDraw(update->context, opX, opY, opWidth, opHeight, bgcolor, fgcolor);

while (index < length)
{
Expand Down Expand Up @@ -135,9 +138,9 @@ void update_process_glyph_fragments(rdpUpdate* update, uint8* data, uint8 length
}

if (opWidth > 1)
IFCALL(glyph_cache->EndDrawText, update->context, opX, opY, opWidth, opHeight, bgcolor, fgcolor);
Glyph_EndDraw(update->context, opX, opY, opWidth, opHeight, bgcolor, fgcolor);
else
IFCALL(glyph_cache->EndDrawText, update->context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor);
Glyph_EndDraw(update->context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor);
}

void update_gdi_glyph_index(rdpUpdate* update, GLYPH_INDEX_ORDER* glyph_index)
Expand Down Expand Up @@ -179,14 +182,15 @@ void update_gdi_cache_glyph(rdpUpdate* update, CACHE_GLYPH_ORDER* cache_glyph)
{
glyph_data = cache_glyph->glyphData[i];

glyph = (rdpGlyph*) xzalloc(cache->glyph->glyph_size);
glyph = Glyph_Alloc(update->context);

glyph->x = glyph_data->x;
glyph->y = glyph_data->y;
glyph->cx = glyph_data->cx;
glyph->cy = glyph_data->cy;
glyph->aj = glyph_data->aj;
glyph->cb = glyph_data->cb;
IFCALL(cache->glyph->GlyphNew, update->context, glyph);
Glyph_New(update->context, glyph);

glyph_cache_put(cache->glyph, cache_glyph->cacheId, glyph_data->cacheIndex, glyph);
}
Expand Down Expand Up @@ -218,8 +222,10 @@ rdpGlyph* glyph_cache_get(rdpGlyphCache* glyph_cache, uint8 id, uint16 index)
return entry;
}

void glyph_cache_put(rdpGlyphCache* glyph_cache, uint8 id, uint16 index, rdpGlyph* entry)
void glyph_cache_put(rdpGlyphCache* glyph_cache, uint8 id, uint16 index, rdpGlyph* glyph)
{
rdpGlyph* prevGlyph;

if (id > 9)
{
printf("invalid glyph cache id: %d\n", id);
Expand All @@ -232,7 +238,16 @@ void glyph_cache_put(rdpGlyphCache* glyph_cache, uint8 id, uint16 index, rdpGlyp
return;
}

glyph_cache->glyphCache[id].entries[index] = entry;
prevGlyph = glyph_cache->glyphCache[id].entries[index];

if (prevGlyph != NULL)
{
xfree(prevGlyph->aj);
Glyph_Free(glyph_cache->context, prevGlyph);
xfree(prevGlyph);
}

glyph_cache->glyphCache[id].entries[index] = glyph;
}

void* glyph_cache_fragment_get(rdpGlyphCache* glyph_cache, uint8 index, uint8* size)
Expand Down Expand Up @@ -270,6 +285,7 @@ rdpGlyphCache* glyph_cache_new(rdpSettings* settings)
int i;

glyph->settings = settings;
glyph->context = ((freerdp*) settings->instance)->update->context;

settings->glyphSupportLevel = GLYPH_SUPPORT_FULL;

Expand Down
57 changes: 55 additions & 2 deletions libfreerdp-core/graphics.c
Expand Up @@ -122,6 +122,54 @@ void graphics_register_pointer(rdpGraphics* graphics, rdpPointer* pointer)
memcpy(graphics->Pointer_Prototype, pointer, sizeof(rdpPointer));
}

/* Glyph Class */

rdpGlyph* Glyph_Alloc(rdpContext* context)
{
rdpGlyph* glyph;
rdpGraphics* graphics;

graphics = context->graphics;
glyph = (rdpGlyph*) xmalloc(graphics->Glyph_Prototype->size);

if (glyph != NULL)
{
memcpy(glyph, context->graphics->Glyph_Prototype, sizeof(rdpGlyph));
}

return glyph;
}

void Glyph_New(rdpContext* context, rdpGlyph* glyph)
{
context->graphics->Glyph_Prototype->New(context, glyph);
}

void Glyph_Free(rdpContext* context, rdpGlyph* glyph)
{
context->graphics->Glyph_Prototype->Free(context, glyph);
}

void Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y)
{
context->graphics->Glyph_Prototype->Draw(context, glyph, x, y);
}

void Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
{
context->graphics->Glyph_Prototype->BeginDraw(context, x, y, width, height, bgcolor, fgcolor);
}

void Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
{
context->graphics->Glyph_Prototype->EndDraw(context, x, y, width, height, bgcolor, fgcolor);
}

void graphics_register_glyph(rdpGraphics* graphics, rdpGlyph* glyph)
{
memcpy(graphics->Glyph_Prototype, glyph, sizeof(rdpGlyph));
}

/* Graphics Module */

rdpGraphics* graphics_new(rdpContext* context)
Expand All @@ -134,15 +182,20 @@ rdpGraphics* graphics_new(rdpContext* context)
{
graphics->context = context;

graphics->Bitmap_Prototype = (rdpBitmap*) xmalloc(sizeof(rdpBitmap));
graphics->Bitmap_Prototype = (rdpBitmap*) xzalloc(sizeof(rdpBitmap));
graphics->Bitmap_Prototype->size = sizeof(rdpBitmap);
graphics->Bitmap_Prototype->New = Bitmap_New;
graphics->Bitmap_Prototype->Free = Bitmap_Free;

graphics->Pointer_Prototype = (rdpPointer*) xmalloc(sizeof(rdpPointer));
graphics->Pointer_Prototype = (rdpPointer*) xzalloc(sizeof(rdpPointer));
graphics->Pointer_Prototype->size = sizeof(rdpPointer);
graphics->Pointer_Prototype->New = Pointer_New;
graphics->Pointer_Prototype->Free = Pointer_Free;

graphics->Glyph_Prototype = (rdpGlyph*) xzalloc(sizeof(rdpGlyph));
graphics->Glyph_Prototype->size = sizeof(rdpGlyph);
graphics->Glyph_Prototype->New = Glyph_New;
graphics->Glyph_Prototype->Free = Glyph_Free;
}

return graphics;
Expand Down
34 changes: 14 additions & 20 deletions libfreerdp-gdi/graphics.c
Expand Up @@ -129,7 +129,7 @@ void gdi_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, boolean prima
gdi->drawing = (gdiBitmap*) bitmap;
}

void gdi_GlyphNew(rdpContext* context, rdpGlyph* glyph)
void gdi_Glyph_New(rdpContext* context, rdpGlyph* glyph)
{
uint8* data;
gdiGlyph* gdi_glyph;
Expand All @@ -149,7 +149,7 @@ void gdi_GlyphNew(rdpContext* context, rdpGlyph* glyph)
gdi_glyph->org_bitmap = NULL;
}

void gdi_GlyphFree(rdpContext* context, rdpGlyph* glyph)
void gdi_Glyph_Free(rdpContext* context, rdpGlyph* glyph)
{
gdiGlyph* gdi_glyph;

Expand All @@ -164,7 +164,7 @@ void gdi_GlyphFree(rdpContext* context, rdpGlyph* glyph)
}
}

void gdi_DrawGlyph(rdpContext* context, rdpGlyph* glyph, int x, int y)
void gdi_Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y)
{
gdiGlyph* gdi_glyph;
rdpGdi* gdi = context->gdi;
Expand All @@ -175,15 +175,12 @@ void gdi_DrawGlyph(rdpContext* context, rdpGlyph* glyph, int x, int y)
gdi_glyph->bitmap->height, gdi_glyph->hdc, 0, 0, GDI_DSPDxax);
}

void gdi_BeginDrawText(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
void gdi_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
{
GDI_RECT rect;
HGDI_BRUSH brush;
rdpGdi* gdi = context->gdi;

printf("BeginDrawText x:%d y:%d width:%d height:%d bgcolor: 0x%04X fgcolor: 0x%04X\n",
x, y, width, height, bgcolor, fgcolor);

fgcolor = freerdp_color_convert(fgcolor, gdi->srcBpp, 32, gdi->clrconv);
gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor);

Expand All @@ -193,22 +190,18 @@ void gdi_BeginDrawText(rdpContext* context, int x, int y, int width, int height,
gdi_FillRect(gdi->drawing->hdc, &rect, brush);
}

void gdi_EndDrawText(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
void gdi_Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
{
rdpGdi* gdi = context->gdi;

printf("EndDrawText x:%d y:%d width:%d height:%d bgcolor: 0x%04X fgcolor: 0x%04X\n",
x, y, width, height, bgcolor, fgcolor);

gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor);
}

void gdi_register_graphics(rdpGraphics* graphics)
{
rdpCache* cache;
rdpBitmap bitmap;
rdpGlyph glyph;

memset(&bitmap, 0, sizeof(rdpBitmap));
bitmap.size = sizeof(gdiBitmap);

bitmap.New = gdi_Bitmap_New;
Expand All @@ -219,13 +212,14 @@ void gdi_register_graphics(rdpGraphics* graphics)

graphics_register_bitmap(graphics, &bitmap);

cache = graphics->context->cache;
glyph.size = sizeof(gdiGlyph);

glyph.New = gdi_Glyph_New;
glyph.Free = gdi_Glyph_Free;
glyph.Draw = gdi_Glyph_Draw;
glyph.BeginDraw = gdi_Glyph_BeginDraw;
glyph.EndDraw = gdi_Glyph_EndDraw;

cache->glyph->glyph_size = sizeof(gdiGlyph);
cache->glyph->GlyphNew = gdi_GlyphNew;
cache->glyph->GlyphFree = gdi_GlyphFree;
cache->glyph->DrawGlyph = gdi_DrawGlyph;
cache->glyph->BeginDrawText = gdi_BeginDrawText;
cache->glyph->EndDrawText = gdi_EndDrawText;
graphics_register_glyph(graphics, &glyph);
}

0 comments on commit 155446d

Please sign in to comment.