2 * FreeRDP: A Remote Desktop Protocol Client
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 #include <freerdp/update.h>
21 #include <freerdp/freerdp.h>
22 #include <freerdp/utils/stream.h>
23 #include <freerdp/utils/memory.h>
25 #include <freerdp/cache/brush.h>
27 void update_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
30 rdpBrush* brush = &patblt->brush;
31 rdpCache* cache = context->cache;
35 if (brush->style & CACHED_BRUSH)
37 brush->data = brush_cache_get(cache->brush, brush->index, &brush->bpp);
41 IFCALL(cache->brush->PatBlt, context, patblt);
45 void update_gdi_cache_brush(rdpContext* context, CACHE_BRUSH_ORDER* cache_brush)
47 rdpCache* cache = context->cache;
48 brush_cache_put(cache->brush, cache_brush->index, cache_brush->data, cache_brush->bpp);
51 void* brush_cache_get(rdpBrushCache* brush, uint32 index, uint32* bpp)
57 if (index > brush->maxMonoEntries)
59 printf("invalid brush (%d bpp) index: 0x%04X\n", *bpp, index);
63 *bpp = brush->monoEntries[index].bpp;
64 entry = brush->monoEntries[index].entry;
68 if (index > brush->maxEntries)
70 printf("invalid brush (%d bpp) index: 0x%04X\n", *bpp, index);
74 *bpp = brush->entries[index].bpp;
75 entry = brush->entries[index].entry;
80 printf("invalid brush (%d bpp) at index: 0x%04X\n", *bpp, index);
87 void brush_cache_put(rdpBrushCache* brush, uint32 index, void* entry, uint32 bpp)
93 if (index > brush->maxMonoEntries)
95 printf("invalid brush (%d bpp) index: 0x%04X\n", bpp, index);
99 prevEntry = brush->monoEntries[index].entry;
101 if (prevEntry != NULL)
104 brush->monoEntries[index].bpp = bpp;
105 brush->monoEntries[index].entry = entry;
109 if (index > brush->maxEntries)
111 printf("invalid brush (%d bpp) index: 0x%04X\n", bpp, index);
115 prevEntry = brush->entries[index].entry;
117 if (prevEntry != NULL)
120 brush->entries[index].bpp = bpp;
121 brush->entries[index].entry = entry;
125 void brush_cache_register_callbacks(rdpUpdate* update)
127 rdpCache* cache = update->context->cache;
129 cache->brush->PatBlt = update->primary->PatBlt;
131 update->primary->PatBlt = update_gdi_patblt;
132 update->secondary->CacheBrush = update_gdi_cache_brush;
135 rdpBrushCache* brush_cache_new(rdpSettings* settings)
137 rdpBrushCache* brush;
139 brush = (rdpBrushCache*) xzalloc(sizeof(rdpBrushCache));
143 brush->settings = settings;
145 brush->maxEntries = 64;
146 brush->maxMonoEntries = 64;
148 brush->entries = (BRUSH_ENTRY*) xzalloc(sizeof(BRUSH_ENTRY) * brush->maxEntries);
149 brush->monoEntries = (BRUSH_ENTRY*) xzalloc(sizeof(BRUSH_ENTRY) * brush->maxMonoEntries);
155 void brush_cache_free(rdpBrushCache* brush)
161 if (brush->entries != NULL)
163 for (i = 0; i < (int) brush->maxEntries; i++)
165 if (brush->entries[i].entry != NULL)
166 xfree(brush->entries[i].entry);
169 xfree(brush->entries);
172 if (brush->monoEntries != NULL)
174 for (i = 0; i < (int) brush->maxMonoEntries; i++)
176 if (brush->monoEntries[i].entry != NULL)
177 xfree(brush->monoEntries[i].entry);
180 xfree(brush->monoEntries);