2011-08-05 21:58:46 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* Brush Cache
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
#include <freerdp/update.h>
|
|
|
|
#include <freerdp/freerdp.h>
|
2011-08-05 21:58:46 +04:00
|
|
|
#include <freerdp/utils/stream.h>
|
|
|
|
#include <freerdp/utils/memory.h>
|
|
|
|
|
2011-08-15 22:33:04 +04:00
|
|
|
#include <freerdp/cache/brush.h>
|
2011-08-05 21:58:46 +04:00
|
|
|
|
2011-11-22 03:11:43 +04:00
|
|
|
void update_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
|
2011-10-21 07:15:18 +04:00
|
|
|
{
|
2011-12-31 21:06:09 +04:00
|
|
|
uint8 style;
|
2011-10-21 07:15:18 +04:00
|
|
|
rdpBrush* brush = &patblt->brush;
|
2011-11-22 03:11:43 +04:00
|
|
|
rdpCache* cache = context->cache;
|
2011-10-21 07:15:18 +04:00
|
|
|
|
2011-12-31 21:06:09 +04:00
|
|
|
style = brush->style;
|
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
if (brush->style & CACHED_BRUSH)
|
|
|
|
{
|
|
|
|
brush->data = brush_cache_get(cache->brush, brush->index, &brush->bpp);
|
|
|
|
brush->style = 0x03;
|
|
|
|
}
|
|
|
|
|
2011-11-22 03:11:43 +04:00
|
|
|
IFCALL(cache->brush->PatBlt, context, patblt);
|
2011-12-31 21:06:09 +04:00
|
|
|
brush->style = style;
|
2011-10-21 07:15:18 +04:00
|
|
|
}
|
|
|
|
|
2012-02-13 02:14:59 +04:00
|
|
|
void update_gdi_polygon_sc(rdpContext* context, POLYGON_SC_ORDER* polygon_sc)
|
|
|
|
{
|
|
|
|
rdpCache* cache = context->cache;
|
|
|
|
IFCALL(cache->brush->PolygonSC, context, polygon_sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb)
|
|
|
|
{
|
|
|
|
uint8 style;
|
|
|
|
rdpBrush* brush = &polygon_cb->brush;
|
|
|
|
rdpCache* cache = context->cache;
|
|
|
|
|
|
|
|
style = brush->style;
|
|
|
|
|
|
|
|
if (brush->style & CACHED_BRUSH)
|
|
|
|
{
|
|
|
|
brush->data = brush_cache_get(cache->brush, brush->index, &brush->bpp);
|
|
|
|
brush->style = 0x03;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFCALL(cache->brush->PolygonCB, context, polygon_cb);
|
|
|
|
brush->style = style;
|
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
void update_gdi_cache_brush(rdpContext* context, CACHE_BRUSH_ORDER* cache_brush)
|
2011-10-21 07:15:18 +04:00
|
|
|
{
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpCache* cache = context->cache;
|
2011-10-21 07:15:18 +04:00
|
|
|
brush_cache_put(cache->brush, cache_brush->index, cache_brush->data, cache_brush->bpp);
|
|
|
|
}
|
|
|
|
|
2011-11-22 07:11:31 +04:00
|
|
|
void* brush_cache_get(rdpBrushCache* brush, uint32 index, uint32* bpp)
|
2011-08-05 21:58:46 +04:00
|
|
|
{
|
|
|
|
void* entry;
|
|
|
|
|
2011-08-08 05:12:36 +04:00
|
|
|
if (*bpp == 1)
|
2011-08-05 21:58:46 +04:00
|
|
|
{
|
2011-08-08 05:12:36 +04:00
|
|
|
if (index > brush->maxMonoEntries)
|
|
|
|
{
|
|
|
|
printf("invalid brush (%d bpp) index: 0x%04X\n", *bpp, index);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*bpp = brush->monoEntries[index].bpp;
|
|
|
|
entry = brush->monoEntries[index].entry;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (index > brush->maxEntries)
|
|
|
|
{
|
|
|
|
printf("invalid brush (%d bpp) index: 0x%04X\n", *bpp, index);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*bpp = brush->entries[index].bpp;
|
|
|
|
entry = brush->entries[index].entry;
|
2011-08-05 21:58:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (entry == NULL)
|
|
|
|
{
|
2011-08-08 05:12:36 +04:00
|
|
|
printf("invalid brush (%d bpp) at index: 0x%04X\n", *bpp, index);
|
2011-08-05 21:58:46 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2011-11-22 07:11:31 +04:00
|
|
|
void brush_cache_put(rdpBrushCache* brush, uint32 index, void* entry, uint32 bpp)
|
2011-08-05 21:58:46 +04:00
|
|
|
{
|
2012-02-02 06:11:46 +04:00
|
|
|
void* prevEntry;
|
|
|
|
|
2011-08-08 05:12:36 +04:00
|
|
|
if (bpp == 1)
|
2011-08-05 21:58:46 +04:00
|
|
|
{
|
2011-08-08 05:12:36 +04:00
|
|
|
if (index > brush->maxMonoEntries)
|
|
|
|
{
|
|
|
|
printf("invalid brush (%d bpp) index: 0x%04X\n", bpp, index);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-02 06:11:46 +04:00
|
|
|
prevEntry = brush->monoEntries[index].entry;
|
|
|
|
|
|
|
|
if (prevEntry != NULL)
|
|
|
|
xfree(prevEntry);
|
|
|
|
|
2011-08-08 05:12:36 +04:00
|
|
|
brush->monoEntries[index].bpp = bpp;
|
|
|
|
brush->monoEntries[index].entry = entry;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (index > brush->maxEntries)
|
|
|
|
{
|
|
|
|
printf("invalid brush (%d bpp) index: 0x%04X\n", bpp, index);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-02 06:11:46 +04:00
|
|
|
prevEntry = brush->entries[index].entry;
|
|
|
|
|
|
|
|
if (prevEntry != NULL)
|
|
|
|
xfree(prevEntry);
|
|
|
|
|
2011-08-08 05:12:36 +04:00
|
|
|
brush->entries[index].bpp = bpp;
|
|
|
|
brush->entries[index].entry = entry;
|
2011-08-05 21:58:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
void brush_cache_register_callbacks(rdpUpdate* update)
|
|
|
|
{
|
|
|
|
rdpCache* cache = update->context->cache;
|
|
|
|
|
2011-11-22 03:11:43 +04:00
|
|
|
cache->brush->PatBlt = update->primary->PatBlt;
|
2012-02-13 02:14:59 +04:00
|
|
|
cache->brush->PolygonSC = update->primary->PolygonSC;
|
|
|
|
cache->brush->PolygonCB = update->primary->PolygonCB;
|
2011-10-21 07:15:18 +04:00
|
|
|
|
2011-11-22 03:11:43 +04:00
|
|
|
update->primary->PatBlt = update_gdi_patblt;
|
2012-02-13 02:14:59 +04:00
|
|
|
update->primary->PolygonSC = update_gdi_polygon_sc;
|
|
|
|
update->primary->PolygonCB = update_gdi_polygon_cb;
|
2011-11-22 04:41:49 +04:00
|
|
|
update->secondary->CacheBrush = update_gdi_cache_brush;
|
2011-10-21 07:15:18 +04:00
|
|
|
}
|
|
|
|
|
2011-10-12 02:51:45 +04:00
|
|
|
rdpBrushCache* brush_cache_new(rdpSettings* settings)
|
2011-08-05 21:58:46 +04:00
|
|
|
{
|
2011-10-12 02:51:45 +04:00
|
|
|
rdpBrushCache* brush;
|
2011-08-05 21:58:46 +04:00
|
|
|
|
2011-10-12 02:51:45 +04:00
|
|
|
brush = (rdpBrushCache*) xzalloc(sizeof(rdpBrushCache));
|
2011-08-05 21:58:46 +04:00
|
|
|
|
|
|
|
if (brush != NULL)
|
|
|
|
{
|
|
|
|
brush->settings = settings;
|
|
|
|
|
|
|
|
brush->maxEntries = 64;
|
2011-08-08 05:12:36 +04:00
|
|
|
brush->maxMonoEntries = 64;
|
2011-08-05 21:58:46 +04:00
|
|
|
|
|
|
|
brush->entries = (BRUSH_ENTRY*) xzalloc(sizeof(BRUSH_ENTRY) * brush->maxEntries);
|
2011-08-08 05:12:36 +04:00
|
|
|
brush->monoEntries = (BRUSH_ENTRY*) xzalloc(sizeof(BRUSH_ENTRY) * brush->maxMonoEntries);
|
2011-08-05 21:58:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return brush;
|
|
|
|
}
|
|
|
|
|
2011-10-12 02:51:45 +04:00
|
|
|
void brush_cache_free(rdpBrushCache* brush)
|
2011-08-05 21:58:46 +04:00
|
|
|
{
|
2012-02-02 03:42:20 +04:00
|
|
|
int i;
|
|
|
|
|
2011-08-05 21:58:46 +04:00
|
|
|
if (brush != NULL)
|
|
|
|
{
|
2012-02-02 03:42:20 +04:00
|
|
|
if (brush->entries != NULL)
|
|
|
|
{
|
2012-02-09 06:16:37 +04:00
|
|
|
for (i = 0; i < (int) brush->maxEntries; i++)
|
2012-02-02 03:42:20 +04:00
|
|
|
{
|
|
|
|
if (brush->entries[i].entry != NULL)
|
|
|
|
xfree(brush->entries[i].entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
xfree(brush->entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (brush->monoEntries != NULL)
|
|
|
|
{
|
2012-02-09 06:16:37 +04:00
|
|
|
for (i = 0; i < (int) brush->maxMonoEntries; i++)
|
2012-02-02 03:42:20 +04:00
|
|
|
{
|
|
|
|
if (brush->monoEntries[i].entry != NULL)
|
|
|
|
xfree(brush->monoEntries[i].entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
xfree(brush->monoEntries);
|
|
|
|
}
|
|
|
|
|
2011-08-05 21:58:46 +04:00
|
|
|
xfree(brush);
|
|
|
|
}
|
|
|
|
}
|