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