FreeRDP
Loading...
Searching...
No Matches
cache.c
1
20#include <freerdp/config.h>
21
22#include <winpr/crt.h>
23
24#include <winpr/stream.h>
25
26#include "cache.h"
27
28rdpCache* cache_new(rdpContext* context)
29{
30 rdpCache* cache = NULL;
31
32 WINPR_ASSERT(context);
33
34 cache = (rdpCache*)calloc(1, sizeof(rdpCache));
35
36 if (!cache)
37 return NULL;
38
39 cache->glyph = glyph_cache_new(context);
40
41 if (!cache->glyph)
42 goto error;
43
44 cache->brush = brush_cache_new(context);
45
46 if (!cache->brush)
47 goto error;
48
49 cache->pointer = pointer_cache_new(context);
50
51 if (!cache->pointer)
52 goto error;
53
54 cache->bitmap = bitmap_cache_new(context);
55
56 if (!cache->bitmap)
57 goto error;
58
59 cache->offscreen = offscreen_cache_new(context);
60
61 if (!cache->offscreen)
62 goto error;
63
64 cache->palette = palette_cache_new(context);
65
66 if (!cache->palette)
67 goto error;
68
69 cache->nine_grid = nine_grid_cache_new(context);
70
71 if (!cache->nine_grid)
72 goto error;
73
74 return cache;
75error:
76 WINPR_PRAGMA_DIAG_PUSH
77 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
78 cache_free(cache);
79 WINPR_PRAGMA_DIAG_POP
80 return NULL;
81}
82
83void cache_free(rdpCache* cache)
84{
85 if (cache != NULL)
86 {
87 glyph_cache_free(cache->glyph);
88 brush_cache_free(cache->brush);
89 pointer_cache_free(cache->pointer);
90 bitmap_cache_free(cache->bitmap);
91 offscreen_cache_free(cache->offscreen);
92 palette_cache_free(cache->palette);
93 nine_grid_cache_free(cache->nine_grid);
94 free(cache);
95 }
96}
97
98CACHE_COLOR_TABLE_ORDER* copy_cache_color_table_order(rdpContext* context,
99 const CACHE_COLOR_TABLE_ORDER* order)
100{
101 CACHE_COLOR_TABLE_ORDER* dst = calloc(1, sizeof(CACHE_COLOR_TABLE_ORDER));
102
103 if (!dst || !order)
104 goto fail;
105
106 *dst = *order;
107 return dst;
108fail:
109 WINPR_PRAGMA_DIAG_PUSH
110 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
111 free_cache_color_table_order(context, dst);
112 WINPR_PRAGMA_DIAG_POP
113 return NULL;
114}
115
116void free_cache_color_table_order(WINPR_ATTR_UNUSED rdpContext* context,
118{
119 free(order);
120}
121
122SURFACE_BITS_COMMAND* copy_surface_bits_command(rdpContext* context,
123 const SURFACE_BITS_COMMAND* order)
124{
125 SURFACE_BITS_COMMAND* dst = calloc(1, sizeof(SURFACE_BITS_COMMAND));
126 if (!dst || !order)
127 goto fail;
128
129 *dst = *order;
130
131 dst->bmp.bitmapData = (BYTE*)malloc(order->bmp.bitmapDataLength);
132
133 if (!dst->bmp.bitmapData)
134 goto fail;
135
136 CopyMemory(dst->bmp.bitmapData, order->bmp.bitmapData, order->bmp.bitmapDataLength);
137
138 return dst;
139
140fail:
141 WINPR_PRAGMA_DIAG_PUSH
142 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
143 free_surface_bits_command(context, dst);
144 WINPR_PRAGMA_DIAG_POP
145 return NULL;
146}
147
148void free_surface_bits_command(WINPR_ATTR_UNUSED rdpContext* context, SURFACE_BITS_COMMAND* order)
149{
150 if (order)
151 free(order->bmp.bitmapData);
152 free(order);
153}