/src/FreeRDP/libfreerdp/cache/bitmap.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * FreeRDP: A Remote Desktop Protocol Implementation |
3 | | * Bitmap Cache V2 |
4 | | * |
5 | | * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com> |
6 | | * |
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 |
10 | | * |
11 | | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | * |
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. |
18 | | */ |
19 | | |
20 | | #include <freerdp/config.h> |
21 | | |
22 | | #include <stdio.h> |
23 | | |
24 | | #include <winpr/crt.h> |
25 | | #include <winpr/assert.h> |
26 | | |
27 | | #include <freerdp/freerdp.h> |
28 | | #include <freerdp/constants.h> |
29 | | #include <winpr/stream.h> |
30 | | |
31 | | #include <freerdp/log.h> |
32 | | #include <freerdp/gdi/bitmap.h> |
33 | | |
34 | | #include "../gdi/gdi.h" |
35 | | #include "../core/graphics.h" |
36 | | |
37 | | #include "bitmap.h" |
38 | | #include "cache.h" |
39 | | |
40 | | #define TAG FREERDP_TAG("cache.bitmap") |
41 | | |
42 | | static rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index); |
43 | | static BOOL bitmap_cache_put(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 index, |
44 | | rdpBitmap* bitmap); |
45 | | |
46 | | static BOOL update_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) |
47 | 0 | { |
48 | 0 | rdpBitmap* bitmap; |
49 | 0 | rdpCache* cache; |
50 | |
|
51 | 0 | cache = context->cache; |
52 | |
|
53 | 0 | if (memblt->cacheId == 0xFF) |
54 | 0 | bitmap = offscreen_cache_get(cache->offscreen, memblt->cacheIndex); |
55 | 0 | else |
56 | 0 | bitmap = bitmap_cache_get(cache->bitmap, (BYTE)memblt->cacheId, memblt->cacheIndex); |
57 | | |
58 | | /* XP-SP2 servers sometimes ask for cached bitmaps they've never defined. */ |
59 | 0 | if (bitmap == NULL) |
60 | 0 | return TRUE; |
61 | | |
62 | 0 | memblt->bitmap = bitmap; |
63 | 0 | return IFCALLRESULT(TRUE, cache->bitmap->MemBlt, context, memblt); |
64 | 0 | } |
65 | | |
66 | | static BOOL update_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) |
67 | 0 | { |
68 | 0 | BYTE style; |
69 | 0 | rdpBitmap* bitmap; |
70 | 0 | rdpCache* cache = context->cache; |
71 | 0 | rdpBrush* brush = &mem3blt->brush; |
72 | 0 | BOOL ret = TRUE; |
73 | |
|
74 | 0 | if (mem3blt->cacheId == 0xFF) |
75 | 0 | bitmap = offscreen_cache_get(cache->offscreen, mem3blt->cacheIndex); |
76 | 0 | else |
77 | 0 | bitmap = bitmap_cache_get(cache->bitmap, (BYTE)mem3blt->cacheId, mem3blt->cacheIndex); |
78 | | |
79 | | /* XP-SP2 servers sometimes ask for cached bitmaps they've never defined. */ |
80 | 0 | if (!bitmap) |
81 | 0 | return TRUE; |
82 | | |
83 | 0 | style = brush->style; |
84 | |
|
85 | 0 | if (brush->style & CACHED_BRUSH) |
86 | 0 | { |
87 | 0 | brush->data = brush_cache_get(cache->brush, brush->index, &brush->bpp); |
88 | |
|
89 | 0 | if (!brush->data) |
90 | 0 | return FALSE; |
91 | | |
92 | 0 | brush->style = 0x03; |
93 | 0 | } |
94 | | |
95 | 0 | mem3blt->bitmap = bitmap; |
96 | 0 | IFCALLRET(cache->bitmap->Mem3Blt, ret, context, mem3blt); |
97 | 0 | brush->style = style; |
98 | 0 | return ret; |
99 | 0 | } |
100 | | |
101 | | static BOOL update_gdi_cache_bitmap(rdpContext* context, const CACHE_BITMAP_ORDER* cacheBitmap) |
102 | 0 | { |
103 | 0 | rdpBitmap* bitmap; |
104 | 0 | rdpBitmap* prevBitmap; |
105 | 0 | rdpCache* cache = context->cache; |
106 | 0 | bitmap = Bitmap_Alloc(context); |
107 | |
|
108 | 0 | if (!bitmap) |
109 | 0 | return FALSE; |
110 | | |
111 | 0 | Bitmap_SetDimensions(bitmap, cacheBitmap->bitmapWidth, cacheBitmap->bitmapHeight); |
112 | |
|
113 | 0 | if (!bitmap->Decompress(context, bitmap, cacheBitmap->bitmapDataStream, |
114 | 0 | cacheBitmap->bitmapWidth, cacheBitmap->bitmapHeight, |
115 | 0 | cacheBitmap->bitmapBpp, cacheBitmap->bitmapLength, |
116 | 0 | cacheBitmap->compressed, RDP_CODEC_ID_NONE)) |
117 | 0 | { |
118 | 0 | Bitmap_Free(context, bitmap); |
119 | 0 | return FALSE; |
120 | 0 | } |
121 | | |
122 | 0 | if (!bitmap->New(context, bitmap)) |
123 | 0 | { |
124 | 0 | Bitmap_Free(context, bitmap); |
125 | 0 | return FALSE; |
126 | 0 | } |
127 | | |
128 | 0 | prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmap->cacheId, cacheBitmap->cacheIndex); |
129 | 0 | Bitmap_Free(context, prevBitmap); |
130 | 0 | return bitmap_cache_put(cache->bitmap, cacheBitmap->cacheId, cacheBitmap->cacheIndex, bitmap); |
131 | 0 | } |
132 | | |
133 | | static BOOL update_gdi_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORDER* cacheBitmapV2) |
134 | | |
135 | 0 | { |
136 | 0 | rdpBitmap* prevBitmap; |
137 | 0 | rdpCache* cache = context->cache; |
138 | 0 | rdpSettings* settings = context->settings; |
139 | 0 | rdpBitmap* bitmap = Bitmap_Alloc(context); |
140 | |
|
141 | 0 | if (!bitmap) |
142 | 0 | return FALSE; |
143 | | |
144 | 0 | const UINT32 ColorDepth = freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth); |
145 | 0 | bitmap->key64 = ((UINT64)cacheBitmapV2->key1 | (((UINT64)cacheBitmapV2->key2) << 32)); |
146 | |
|
147 | 0 | if (!cacheBitmapV2->bitmapBpp) |
148 | 0 | cacheBitmapV2->bitmapBpp = ColorDepth; |
149 | |
|
150 | 0 | if ((ColorDepth == 15) && (cacheBitmapV2->bitmapBpp == 16)) |
151 | 0 | cacheBitmapV2->bitmapBpp = ColorDepth; |
152 | |
|
153 | 0 | Bitmap_SetDimensions(bitmap, cacheBitmapV2->bitmapWidth, cacheBitmapV2->bitmapHeight); |
154 | |
|
155 | 0 | if (!bitmap->Decompress(context, bitmap, cacheBitmapV2->bitmapDataStream, |
156 | 0 | cacheBitmapV2->bitmapWidth, cacheBitmapV2->bitmapHeight, |
157 | 0 | cacheBitmapV2->bitmapBpp, cacheBitmapV2->bitmapLength, |
158 | 0 | cacheBitmapV2->compressed, RDP_CODEC_ID_NONE)) |
159 | 0 | goto fail; |
160 | | |
161 | 0 | prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmapV2->cacheId, cacheBitmapV2->cacheIndex); |
162 | |
|
163 | 0 | if (!bitmap->New(context, bitmap)) |
164 | 0 | goto fail; |
165 | | |
166 | 0 | Bitmap_Free(context, prevBitmap); |
167 | 0 | return bitmap_cache_put(cache->bitmap, cacheBitmapV2->cacheId, cacheBitmapV2->cacheIndex, |
168 | 0 | bitmap); |
169 | | |
170 | 0 | fail: |
171 | 0 | Bitmap_Free(context, bitmap); |
172 | 0 | return FALSE; |
173 | 0 | } |
174 | | |
175 | | static BOOL update_gdi_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORDER* cacheBitmapV3) |
176 | 0 | { |
177 | 0 | rdpBitmap* bitmap; |
178 | 0 | rdpBitmap* prevBitmap; |
179 | 0 | BOOL compressed = TRUE; |
180 | 0 | rdpCache* cache = context->cache; |
181 | 0 | rdpSettings* settings = context->settings; |
182 | 0 | BITMAP_DATA_EX* bitmapData = &cacheBitmapV3->bitmapData; |
183 | 0 | bitmap = Bitmap_Alloc(context); |
184 | |
|
185 | 0 | if (!bitmap) |
186 | 0 | return FALSE; |
187 | | |
188 | 0 | const UINT32 ColorDepth = freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth); |
189 | 0 | bitmap->key64 = ((UINT64)cacheBitmapV3->key1 | (((UINT64)cacheBitmapV3->key2) << 32)); |
190 | |
|
191 | 0 | if (!cacheBitmapV3->bpp) |
192 | 0 | cacheBitmapV3->bpp = ColorDepth; |
193 | |
|
194 | 0 | compressed = (bitmapData->codecID != RDP_CODEC_ID_NONE); |
195 | 0 | Bitmap_SetDimensions(bitmap, bitmapData->width, bitmapData->height); |
196 | |
|
197 | 0 | if (!bitmap->Decompress(context, bitmap, bitmapData->data, bitmapData->width, |
198 | 0 | bitmapData->height, bitmapData->bpp, bitmapData->length, compressed, |
199 | 0 | bitmapData->codecID)) |
200 | 0 | goto fail; |
201 | | |
202 | 0 | if (!bitmap->New(context, bitmap)) |
203 | 0 | goto fail; |
204 | | |
205 | 0 | prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmapV3->cacheId, cacheBitmapV3->cacheIndex); |
206 | 0 | Bitmap_Free(context, prevBitmap); |
207 | 0 | return bitmap_cache_put(cache->bitmap, cacheBitmapV3->cacheId, cacheBitmapV3->cacheIndex, |
208 | 0 | bitmap); |
209 | | |
210 | 0 | fail: |
211 | 0 | Bitmap_Free(context, bitmap); |
212 | 0 | return FALSE; |
213 | 0 | } |
214 | | |
215 | | rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index) |
216 | 0 | { |
217 | 0 | rdpBitmap* bitmap; |
218 | |
|
219 | 0 | if (id >= bitmapCache->maxCells) |
220 | 0 | { |
221 | 0 | WLog_ERR(TAG, "get invalid bitmap cell id: %" PRIu32 "", id); |
222 | 0 | return NULL; |
223 | 0 | } |
224 | | |
225 | 0 | if (index == BITMAP_CACHE_WAITING_LIST_INDEX) |
226 | 0 | { |
227 | 0 | index = bitmapCache->cells[id].number; |
228 | 0 | } |
229 | 0 | else if (index > bitmapCache->cells[id].number) |
230 | 0 | { |
231 | 0 | WLog_ERR(TAG, "get invalid bitmap index %" PRIu32 " in cell id: %" PRIu32 "", index, id); |
232 | 0 | return NULL; |
233 | 0 | } |
234 | | |
235 | 0 | bitmap = bitmapCache->cells[id].entries[index]; |
236 | 0 | return bitmap; |
237 | 0 | } |
238 | | |
239 | | BOOL bitmap_cache_put(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index, rdpBitmap* bitmap) |
240 | 0 | { |
241 | 0 | if (id > bitmapCache->maxCells) |
242 | 0 | { |
243 | 0 | WLog_ERR(TAG, "put invalid bitmap cell id: %" PRIu32 "", id); |
244 | 0 | return FALSE; |
245 | 0 | } |
246 | | |
247 | 0 | if (index == BITMAP_CACHE_WAITING_LIST_INDEX) |
248 | 0 | { |
249 | 0 | index = bitmapCache->cells[id].number; |
250 | 0 | } |
251 | 0 | else if (index > bitmapCache->cells[id].number) |
252 | 0 | { |
253 | 0 | WLog_ERR(TAG, "put invalid bitmap index %" PRIu32 " in cell id: %" PRIu32 "", index, id); |
254 | 0 | return FALSE; |
255 | 0 | } |
256 | | |
257 | 0 | bitmapCache->cells[id].entries[index] = bitmap; |
258 | 0 | return TRUE; |
259 | 0 | } |
260 | | |
261 | | void bitmap_cache_register_callbacks(rdpUpdate* update) |
262 | 0 | { |
263 | 0 | rdpCache* cache; |
264 | |
|
265 | 0 | WINPR_ASSERT(update); |
266 | 0 | WINPR_ASSERT(update->context); |
267 | 0 | WINPR_ASSERT(update->context->cache); |
268 | | |
269 | 0 | cache = update->context->cache; |
270 | 0 | WINPR_ASSERT(cache); |
271 | | |
272 | 0 | if (!freerdp_settings_get_bool(update->context->settings, FreeRDP_DeactivateClientDecoding)) |
273 | 0 | { |
274 | 0 | cache->bitmap->MemBlt = update->primary->MemBlt; |
275 | 0 | cache->bitmap->Mem3Blt = update->primary->Mem3Blt; |
276 | 0 | update->primary->MemBlt = update_gdi_memblt; |
277 | 0 | update->primary->Mem3Blt = update_gdi_mem3blt; |
278 | 0 | update->secondary->CacheBitmap = update_gdi_cache_bitmap; |
279 | 0 | update->secondary->CacheBitmapV2 = update_gdi_cache_bitmap_v2; |
280 | 0 | update->secondary->CacheBitmapV3 = update_gdi_cache_bitmap_v3; |
281 | 0 | update->BitmapUpdate = gdi_bitmap_update; |
282 | 0 | } |
283 | 0 | } |
284 | | |
285 | | static int bitmap_cache_save_persistent(rdpBitmapCache* bitmapCache) |
286 | 0 | { |
287 | 0 | int status; |
288 | 0 | UINT32 i, j; |
289 | 0 | UINT32 version; |
290 | 0 | rdpPersistentCache* persistent; |
291 | 0 | rdpContext* context = bitmapCache->context; |
292 | 0 | rdpSettings* settings = context->settings; |
293 | |
|
294 | 0 | version = settings->BitmapCacheVersion; |
295 | |
|
296 | 0 | if (version != 2) |
297 | 0 | return 0; /* persistent bitmap cache already saved in egfx channel */ |
298 | | |
299 | 0 | if (!freerdp_settings_get_bool(settings, FreeRDP_BitmapCachePersistEnabled)) |
300 | 0 | return 0; |
301 | | |
302 | 0 | if (!settings->BitmapCachePersistFile) |
303 | 0 | return 0; |
304 | | |
305 | 0 | persistent = persistent_cache_new(); |
306 | |
|
307 | 0 | if (!persistent) |
308 | 0 | return -1; |
309 | | |
310 | 0 | status = persistent_cache_open(persistent, settings->BitmapCachePersistFile, TRUE, version); |
311 | |
|
312 | 0 | if (status < 1) |
313 | 0 | goto end; |
314 | | |
315 | 0 | for (i = 0; i < bitmapCache->maxCells; i++) |
316 | 0 | { |
317 | 0 | for (j = 0; j < bitmapCache->cells[i].number + 1; j++) |
318 | 0 | { |
319 | 0 | PERSISTENT_CACHE_ENTRY cacheEntry; |
320 | 0 | rdpBitmap* bitmap = bitmapCache->cells[i].entries[j]; |
321 | |
|
322 | 0 | if (!bitmap || !bitmap->key64) |
323 | 0 | continue; |
324 | | |
325 | 0 | cacheEntry.key64 = bitmap->key64; |
326 | 0 | cacheEntry.width = bitmap->width; |
327 | 0 | cacheEntry.height = bitmap->height; |
328 | 0 | cacheEntry.size = (UINT32)(bitmap->width * bitmap->height * 4); |
329 | 0 | cacheEntry.flags = 0; |
330 | 0 | cacheEntry.data = bitmap->data; |
331 | |
|
332 | 0 | if (persistent_cache_write_entry(persistent, &cacheEntry) < 1) |
333 | 0 | { |
334 | 0 | status = -1; |
335 | 0 | goto end; |
336 | 0 | } |
337 | 0 | } |
338 | 0 | } |
339 | | |
340 | 0 | status = 1; |
341 | |
|
342 | 0 | end: |
343 | 0 | persistent_cache_free(persistent); |
344 | 0 | return status; |
345 | 0 | } |
346 | | |
347 | | rdpBitmapCache* bitmap_cache_new(rdpContext* context) |
348 | 0 | { |
349 | 0 | UINT32 i; |
350 | 0 | rdpSettings* settings; |
351 | 0 | rdpBitmapCache* bitmapCache; |
352 | |
|
353 | 0 | WINPR_ASSERT(context); |
354 | | |
355 | 0 | settings = context->settings; |
356 | 0 | WINPR_ASSERT(settings); |
357 | | |
358 | 0 | bitmapCache = (rdpBitmapCache*)calloc(1, sizeof(rdpBitmapCache)); |
359 | |
|
360 | 0 | if (!bitmapCache) |
361 | 0 | return NULL; |
362 | | |
363 | 0 | const UINT32 BitmapCacheV2NumCells = |
364 | 0 | freerdp_settings_get_uint32(settings, FreeRDP_BitmapCacheV2NumCells); |
365 | 0 | bitmapCache->context = context; |
366 | 0 | bitmapCache->cells = (BITMAP_V2_CELL*)calloc(BitmapCacheV2NumCells, sizeof(BITMAP_V2_CELL)); |
367 | |
|
368 | 0 | if (!bitmapCache->cells) |
369 | 0 | goto fail; |
370 | 0 | bitmapCache->maxCells = BitmapCacheV2NumCells; |
371 | |
|
372 | 0 | for (i = 0; i < bitmapCache->maxCells; i++) |
373 | 0 | { |
374 | 0 | const BITMAP_CACHE_V2_CELL_INFO* info = |
375 | 0 | freerdp_settings_get_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, i); |
376 | 0 | BITMAP_V2_CELL* cell = &bitmapCache->cells[i]; |
377 | 0 | UINT32 nr = info->numEntries; |
378 | | /* allocate an extra entry for BITMAP_CACHE_WAITING_LIST_INDEX */ |
379 | 0 | cell->entries = (rdpBitmap**)calloc((nr + 1), sizeof(rdpBitmap*)); |
380 | |
|
381 | 0 | if (!cell->entries) |
382 | 0 | goto fail; |
383 | 0 | cell->number = nr; |
384 | 0 | } |
385 | | |
386 | 0 | return bitmapCache; |
387 | 0 | fail: |
388 | |
|
389 | 0 | bitmap_cache_free(bitmapCache); |
390 | 0 | return NULL; |
391 | 0 | } |
392 | | |
393 | | void bitmap_cache_free(rdpBitmapCache* bitmapCache) |
394 | 0 | { |
395 | 0 | if (!bitmapCache) |
396 | 0 | return; |
397 | | |
398 | 0 | bitmap_cache_save_persistent(bitmapCache); |
399 | |
|
400 | 0 | UINT32 i; |
401 | 0 | for (i = 0; i < bitmapCache->maxCells; i++) |
402 | 0 | { |
403 | 0 | UINT32 j; |
404 | 0 | BITMAP_V2_CELL* cell = &bitmapCache->cells[i]; |
405 | |
|
406 | 0 | if (!cell->entries) |
407 | 0 | continue; |
408 | | |
409 | 0 | for (j = 0; j < cell->number + 1; j++) |
410 | 0 | { |
411 | 0 | rdpBitmap* bitmap = cell->entries[j]; |
412 | 0 | Bitmap_Free(bitmapCache->context, bitmap); |
413 | 0 | } |
414 | |
|
415 | 0 | free(bitmapCache->cells[i].entries); |
416 | 0 | } |
417 | |
|
418 | 0 | free(bitmapCache->cells); |
419 | 0 | persistent_cache_free(bitmapCache->persistent); |
420 | |
|
421 | 0 | free(bitmapCache); |
422 | 0 | } |
423 | | |
424 | | static void free_bitmap_data(BITMAP_DATA* data, size_t count) |
425 | 0 | { |
426 | 0 | size_t x; |
427 | |
|
428 | 0 | if (!data) |
429 | 0 | return; |
430 | | |
431 | 0 | for (x = 0; x < count; x++) |
432 | 0 | free(data[x].bitmapDataStream); |
433 | |
|
434 | 0 | free(data); |
435 | 0 | } |
436 | | |
437 | | static BITMAP_DATA* copy_bitmap_data(const BITMAP_DATA* data, size_t count) |
438 | 0 | { |
439 | 0 | size_t x; |
440 | 0 | BITMAP_DATA* dst = (BITMAP_DATA*)calloc(count, sizeof(BITMAP_DATA)); |
441 | |
|
442 | 0 | if (!dst) |
443 | 0 | goto fail; |
444 | | |
445 | 0 | for (x = 0; x < count; x++) |
446 | 0 | { |
447 | 0 | dst[x] = data[x]; |
448 | |
|
449 | 0 | if (data[x].bitmapLength > 0) |
450 | 0 | { |
451 | 0 | dst[x].bitmapDataStream = malloc(data[x].bitmapLength); |
452 | |
|
453 | 0 | if (!dst[x].bitmapDataStream) |
454 | 0 | goto fail; |
455 | | |
456 | 0 | memcpy(dst[x].bitmapDataStream, data[x].bitmapDataStream, data[x].bitmapLength); |
457 | 0 | } |
458 | 0 | } |
459 | | |
460 | 0 | return dst; |
461 | 0 | fail: |
462 | 0 | free_bitmap_data(dst, count); |
463 | 0 | return NULL; |
464 | 0 | } |
465 | | |
466 | | void free_bitmap_update(rdpContext* context, BITMAP_UPDATE* pointer) |
467 | 0 | { |
468 | 0 | if (!pointer) |
469 | 0 | return; |
470 | | |
471 | 0 | free_bitmap_data(pointer->rectangles, pointer->number); |
472 | 0 | free(pointer); |
473 | 0 | } |
474 | | |
475 | | BITMAP_UPDATE* copy_bitmap_update(rdpContext* context, const BITMAP_UPDATE* pointer) |
476 | 0 | { |
477 | 0 | BITMAP_UPDATE* dst = calloc(1, sizeof(BITMAP_UPDATE)); |
478 | |
|
479 | 0 | if (!dst || !pointer) |
480 | 0 | goto fail; |
481 | | |
482 | 0 | *dst = *pointer; |
483 | 0 | dst->rectangles = copy_bitmap_data(pointer->rectangles, pointer->number); |
484 | |
|
485 | 0 | if (!dst->rectangles) |
486 | 0 | goto fail; |
487 | | |
488 | 0 | return dst; |
489 | 0 | fail: |
490 | 0 | free_bitmap_update(context, dst); |
491 | 0 | return NULL; |
492 | 0 | } |
493 | | |
494 | | CACHE_BITMAP_ORDER* copy_cache_bitmap_order(rdpContext* context, const CACHE_BITMAP_ORDER* order) |
495 | 0 | { |
496 | 0 | CACHE_BITMAP_ORDER* dst = calloc(1, sizeof(CACHE_BITMAP_ORDER)); |
497 | |
|
498 | 0 | if (!dst || !order) |
499 | 0 | goto fail; |
500 | | |
501 | 0 | *dst = *order; |
502 | |
|
503 | 0 | if (order->bitmapLength > 0) |
504 | 0 | { |
505 | 0 | dst->bitmapDataStream = malloc(order->bitmapLength); |
506 | |
|
507 | 0 | if (!dst->bitmapDataStream) |
508 | 0 | goto fail; |
509 | | |
510 | 0 | memcpy(dst->bitmapDataStream, order->bitmapDataStream, order->bitmapLength); |
511 | 0 | } |
512 | | |
513 | 0 | return dst; |
514 | 0 | fail: |
515 | 0 | free_cache_bitmap_order(context, dst); |
516 | 0 | return NULL; |
517 | 0 | } |
518 | | |
519 | | void free_cache_bitmap_order(rdpContext* context, CACHE_BITMAP_ORDER* order) |
520 | 0 | { |
521 | 0 | if (order) |
522 | 0 | free(order->bitmapDataStream); |
523 | |
|
524 | 0 | free(order); |
525 | 0 | } |
526 | | |
527 | | CACHE_BITMAP_V2_ORDER* copy_cache_bitmap_v2_order(rdpContext* context, |
528 | | const CACHE_BITMAP_V2_ORDER* order) |
529 | 0 | { |
530 | 0 | CACHE_BITMAP_V2_ORDER* dst = calloc(1, sizeof(CACHE_BITMAP_V2_ORDER)); |
531 | |
|
532 | 0 | if (!dst || !order) |
533 | 0 | goto fail; |
534 | | |
535 | 0 | *dst = *order; |
536 | |
|
537 | 0 | if (order->bitmapLength > 0) |
538 | 0 | { |
539 | 0 | dst->bitmapDataStream = malloc(order->bitmapLength); |
540 | |
|
541 | 0 | if (!dst->bitmapDataStream) |
542 | 0 | goto fail; |
543 | | |
544 | 0 | memcpy(dst->bitmapDataStream, order->bitmapDataStream, order->bitmapLength); |
545 | 0 | } |
546 | | |
547 | 0 | return dst; |
548 | 0 | fail: |
549 | 0 | free_cache_bitmap_v2_order(context, dst); |
550 | 0 | return NULL; |
551 | 0 | } |
552 | | |
553 | | void free_cache_bitmap_v2_order(rdpContext* context, CACHE_BITMAP_V2_ORDER* order) |
554 | 0 | { |
555 | 0 | if (order) |
556 | 0 | free(order->bitmapDataStream); |
557 | |
|
558 | 0 | free(order); |
559 | 0 | } |
560 | | |
561 | | CACHE_BITMAP_V3_ORDER* copy_cache_bitmap_v3_order(rdpContext* context, |
562 | | const CACHE_BITMAP_V3_ORDER* order) |
563 | 0 | { |
564 | 0 | CACHE_BITMAP_V3_ORDER* dst = calloc(1, sizeof(CACHE_BITMAP_V3_ORDER)); |
565 | |
|
566 | 0 | if (!dst || !order) |
567 | 0 | goto fail; |
568 | | |
569 | 0 | *dst = *order; |
570 | |
|
571 | 0 | if (order->bitmapData.length > 0) |
572 | 0 | { |
573 | 0 | dst->bitmapData.data = malloc(order->bitmapData.length); |
574 | |
|
575 | 0 | if (!dst->bitmapData.data) |
576 | 0 | goto fail; |
577 | | |
578 | 0 | memcpy(dst->bitmapData.data, order->bitmapData.data, order->bitmapData.length); |
579 | 0 | } |
580 | | |
581 | 0 | return dst; |
582 | 0 | fail: |
583 | 0 | free_cache_bitmap_v3_order(context, dst); |
584 | 0 | return NULL; |
585 | 0 | } |
586 | | |
587 | | void free_cache_bitmap_v3_order(rdpContext* context, CACHE_BITMAP_V3_ORDER* order) |
588 | 0 | { |
589 | 0 | if (order) |
590 | 0 | free(order->bitmapData.data); |
591 | |
|
592 | 0 | free(order); |
593 | 0 | } |