2011-08-05 21:58:46 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-05 21:58:46 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-09-24 02:41:07 +04:00
|
|
|
#include <stdio.h>
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
#include <freerdp/update.h>
|
|
|
|
#include <freerdp/freerdp.h>
|
2013-03-22 00:45:25 +04:00
|
|
|
#include <winpr/stream.h>
|
2011-08-05 21:58:46 +04:00
|
|
|
|
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
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE 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)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE style;
|
2012-02-13 02:14:59 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
static void update_gdi_cache_brush(rdpContext* context, CACHE_BRUSH_ORDER* cacheBrush)
|
2011-10-21 07:15:18 +04:00
|
|
|
{
|
2013-01-29 03:42:32 +04:00
|
|
|
int length;
|
|
|
|
void* data = NULL;
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpCache* cache = context->cache;
|
2013-01-29 03:42:32 +04:00
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
length = cacheBrush->bpp * 64 / 8;
|
2013-01-29 03:42:32 +04:00
|
|
|
|
|
|
|
data = malloc(length);
|
2013-11-03 22:51:41 +04:00
|
|
|
CopyMemory(data, cacheBrush->data, length);
|
2013-01-29 03:42:32 +04:00
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
brush_cache_put(cache->brush, cacheBrush->index, data, cacheBrush->bpp);
|
2011-10-21 07:15:18 +04:00
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
void* brush_cache_get(rdpBrushCache* brushCache, UINT32 index, UINT32* bpp)
|
2011-08-05 21:58:46 +04:00
|
|
|
{
|
|
|
|
void* entry;
|
|
|
|
|
2014-04-21 22:42:24 +04:00
|
|
|
if (!brushCache)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!bpp)
|
|
|
|
return NULL;
|
2013-09-02 12:57:44 +04:00
|
|
|
|
2011-08-08 05:12:36 +04:00
|
|
|
if (*bpp == 1)
|
2011-08-05 21:58:46 +04:00
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
if (index >= brushCache->maxMonoEntries)
|
2011-08-08 05:12:36 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid brush (%d bpp) index: 0x%04X\n", *bpp, index);
|
2011-08-08 05:12:36 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
*bpp = brushCache->monoEntries[index].bpp;
|
|
|
|
entry = brushCache->monoEntries[index].entry;
|
2011-08-08 05:12:36 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
if (index >= brushCache->maxEntries)
|
2011-08-08 05:12:36 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid brush (%d bpp) index: 0x%04X\n", *bpp, index);
|
2011-08-08 05:12:36 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
*bpp = brushCache->entries[index].bpp;
|
|
|
|
entry = brushCache->entries[index].entry;
|
2011-08-05 21:58:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (entry == NULL)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid brush (%d bpp) at index: 0x%04X\n", *bpp, index);
|
2011-08-05 21:58:46 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
void brush_cache_put(rdpBrushCache* brushCache, 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
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
if (index >= brushCache->maxMonoEntries)
|
2011-08-08 05:12:36 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid brush (%d bpp) index: 0x%04X\n", bpp, index);
|
2013-11-03 22:51:41 +04:00
|
|
|
|
2013-09-02 12:57:44 +04:00
|
|
|
if (entry)
|
|
|
|
free(entry);
|
2013-11-03 22:51:41 +04:00
|
|
|
|
2011-08-08 05:12:36 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
prevEntry = brushCache->monoEntries[index].entry;
|
2012-02-02 06:11:46 +04:00
|
|
|
|
|
|
|
if (prevEntry != NULL)
|
2012-10-09 07:21:26 +04:00
|
|
|
free(prevEntry);
|
2012-02-02 06:11:46 +04:00
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
brushCache->monoEntries[index].bpp = bpp;
|
|
|
|
brushCache->monoEntries[index].entry = entry;
|
2011-08-08 05:12:36 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
if (index >= brushCache->maxEntries)
|
2011-08-08 05:12:36 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid brush (%d bpp) index: 0x%04X\n", bpp, index);
|
2013-11-03 22:51:41 +04:00
|
|
|
|
2013-09-02 12:57:44 +04:00
|
|
|
if (entry)
|
|
|
|
free(entry);
|
2013-11-03 22:51:41 +04:00
|
|
|
|
2011-08-08 05:12:36 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
prevEntry = brushCache->entries[index].entry;
|
2012-02-02 06:11:46 +04:00
|
|
|
|
|
|
|
if (prevEntry != NULL)
|
2012-10-09 07:21:26 +04:00
|
|
|
free(prevEntry);
|
2012-02-02 06:11:46 +04:00
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
brushCache->entries[index].bpp = bpp;
|
|
|
|
brushCache->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
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
rdpBrushCache* brushCache;
|
2011-08-05 21:58:46 +04:00
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
brushCache = (rdpBrushCache*) malloc(sizeof(rdpBrushCache));
|
2011-08-05 21:58:46 +04:00
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
if (brushCache)
|
2011-08-05 21:58:46 +04:00
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
ZeroMemory(brushCache, sizeof(rdpBrushCache));
|
|
|
|
|
|
|
|
brushCache->settings = settings;
|
2011-08-05 21:58:46 +04:00
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
brushCache->maxEntries = 64;
|
|
|
|
brushCache->maxMonoEntries = 64;
|
2011-08-05 21:58:46 +04:00
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
brushCache->entries = (BRUSH_ENTRY*) malloc(sizeof(BRUSH_ENTRY) * brushCache->maxEntries);
|
|
|
|
ZeroMemory(brushCache->entries, sizeof(BRUSH_ENTRY) * brushCache->maxEntries);
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
brushCache->monoEntries = (BRUSH_ENTRY*) malloc(sizeof(BRUSH_ENTRY) * brushCache->maxMonoEntries);
|
|
|
|
ZeroMemory(brushCache->monoEntries, sizeof(BRUSH_ENTRY) * brushCache->maxMonoEntries);
|
2011-08-05 21:58:46 +04:00
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
return brushCache;
|
2011-08-05 21:58:46 +04:00
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
void brush_cache_free(rdpBrushCache* brushCache)
|
2011-08-05 21:58:46 +04:00
|
|
|
{
|
2012-02-02 03:42:20 +04:00
|
|
|
int i;
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
if (brushCache)
|
2011-08-05 21:58:46 +04:00
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
if (brushCache->entries)
|
2012-02-02 03:42:20 +04:00
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
for (i = 0; i < (int) brushCache->maxEntries; i++)
|
2012-02-02 03:42:20 +04:00
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
if (brushCache->entries[i].entry != NULL)
|
|
|
|
free(brushCache->entries[i].entry);
|
2012-02-02 03:42:20 +04:00
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
free(brushCache->entries);
|
2012-02-02 03:42:20 +04:00
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
if (brushCache->monoEntries)
|
2012-02-02 03:42:20 +04:00
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
for (i = 0; i < (int) brushCache->maxMonoEntries; i++)
|
2012-02-02 03:42:20 +04:00
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
if (brushCache->monoEntries[i].entry != NULL)
|
|
|
|
free(brushCache->monoEntries[i].entry);
|
2012-02-02 03:42:20 +04:00
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
free(brushCache->monoEntries);
|
2012-02-02 03:42:20 +04:00
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
free(brushCache);
|
2011-08-05 21:58:46 +04:00
|
|
|
}
|
|
|
|
}
|