/src/FreeRDP/libfreerdp/cache/nine_grid.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * FreeRDP: A Remote Desktop Protocol Implementation |
3 | | * NineGrid Cache |
4 | | * |
5 | | * Copyright 2012 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 | | |
26 | | #include <freerdp/log.h> |
27 | | #include <freerdp/update.h> |
28 | | #include <freerdp/freerdp.h> |
29 | | #include <winpr/stream.h> |
30 | | |
31 | | #include "nine_grid.h" |
32 | | #include "cache.h" |
33 | | |
34 | | #define TAG FREERDP_TAG("cache.nine_grid") |
35 | | |
36 | | typedef struct |
37 | | { |
38 | | void* entry; |
39 | | } NINE_GRID_ENTRY; |
40 | | |
41 | | struct rdp_nine_grid_cache |
42 | | { |
43 | | pDrawNineGrid DrawNineGrid; /* 0 */ |
44 | | pMultiDrawNineGrid MultiDrawNineGrid; /* 1 */ |
45 | | UINT32 paddingA[16 - 2]; /* 2 */ |
46 | | |
47 | | UINT32 maxEntries; /* 16 */ |
48 | | UINT32 maxSize; /* 17 */ |
49 | | NINE_GRID_ENTRY* entries; /* 18 */ |
50 | | UINT32 paddingB[32 - 19]; /* 19 */ |
51 | | |
52 | | rdpContext* context; |
53 | | }; |
54 | | |
55 | | static void* nine_grid_cache_get(rdpNineGridCache* nine_grid, UINT32 index); |
56 | | static void nine_grid_cache_put(rdpNineGridCache* nine_grid, UINT32 index, void* entry); |
57 | | |
58 | | static BOOL update_gdi_draw_nine_grid(rdpContext* context, |
59 | | const DRAW_NINE_GRID_ORDER* draw_nine_grid) |
60 | 0 | { |
61 | 0 | rdpCache* cache = context->cache; |
62 | 0 | return IFCALLRESULT(TRUE, cache->nine_grid->DrawNineGrid, context, draw_nine_grid); |
63 | 0 | } |
64 | | |
65 | | static BOOL update_gdi_multi_draw_nine_grid(rdpContext* context, |
66 | | const MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid) |
67 | 0 | { |
68 | 0 | rdpCache* cache = context->cache; |
69 | 0 | return IFCALLRESULT(TRUE, cache->nine_grid->MultiDrawNineGrid, context, multi_draw_nine_grid); |
70 | 0 | } |
71 | | |
72 | | void nine_grid_cache_register_callbacks(rdpUpdate* update) |
73 | 0 | { |
74 | 0 | rdpCache* cache = update->context->cache; |
75 | |
|
76 | 0 | cache->nine_grid->DrawNineGrid = update->primary->DrawNineGrid; |
77 | 0 | cache->nine_grid->MultiDrawNineGrid = update->primary->MultiDrawNineGrid; |
78 | |
|
79 | 0 | update->primary->DrawNineGrid = update_gdi_draw_nine_grid; |
80 | 0 | update->primary->MultiDrawNineGrid = update_gdi_multi_draw_nine_grid; |
81 | 0 | } |
82 | | |
83 | | void* nine_grid_cache_get(rdpNineGridCache* nine_grid, UINT32 index) |
84 | 0 | { |
85 | 0 | void* entry = NULL; |
86 | 0 |
|
87 | 0 | if (index >= nine_grid->maxEntries) |
88 | 0 | { |
89 | 0 | WLog_ERR(TAG, "invalid NineGrid index: 0x%08" PRIX32 "", index); |
90 | 0 | return NULL; |
91 | 0 | } |
92 | 0 |
|
93 | 0 | entry = nine_grid->entries[index].entry; |
94 | 0 |
|
95 | 0 | if (entry == NULL) |
96 | 0 | { |
97 | 0 | WLog_ERR(TAG, "invalid NineGrid at index: 0x%08" PRIX32 "", index); |
98 | 0 | return NULL; |
99 | 0 | } |
100 | 0 |
|
101 | 0 | return entry; |
102 | 0 | } |
103 | | |
104 | | void nine_grid_cache_put(rdpNineGridCache* nine_grid, UINT32 index, void* entry) |
105 | 0 | { |
106 | 0 | if (index >= nine_grid->maxEntries) |
107 | 0 | { |
108 | 0 | WLog_ERR(TAG, "invalid NineGrid index: 0x%08" PRIX32 "", index); |
109 | 0 | return; |
110 | 0 | } |
111 | 0 |
|
112 | 0 | free(nine_grid->entries[index].entry); |
113 | 0 | nine_grid->entries[index].entry = entry; |
114 | 0 | } |
115 | | |
116 | | rdpNineGridCache* nine_grid_cache_new(rdpContext* context) |
117 | 0 | { |
118 | 0 | rdpNineGridCache* nine_grid = NULL; |
119 | 0 | rdpSettings* settings = NULL; |
120 | |
|
121 | 0 | WINPR_ASSERT(context); |
122 | | |
123 | 0 | settings = context->settings; |
124 | 0 | WINPR_ASSERT(settings); |
125 | | |
126 | 0 | nine_grid = (rdpNineGridCache*)calloc(1, sizeof(rdpNineGridCache)); |
127 | 0 | if (!nine_grid) |
128 | 0 | return NULL; |
129 | | |
130 | 0 | nine_grid->context = context; |
131 | |
|
132 | 0 | nine_grid->maxSize = 2560; |
133 | 0 | nine_grid->maxEntries = 256; |
134 | |
|
135 | 0 | if (!freerdp_settings_set_uint32(settings, FreeRDP_DrawNineGridCacheSize, nine_grid->maxSize)) |
136 | 0 | goto fail; |
137 | 0 | if (!freerdp_settings_set_uint32(settings, FreeRDP_DrawNineGridCacheEntries, |
138 | 0 | nine_grid->maxEntries)) |
139 | 0 | goto fail; |
140 | | |
141 | 0 | nine_grid->entries = (NINE_GRID_ENTRY*)calloc(nine_grid->maxEntries, sizeof(NINE_GRID_ENTRY)); |
142 | 0 | if (!nine_grid->entries) |
143 | 0 | goto fail; |
144 | | |
145 | 0 | return nine_grid; |
146 | | |
147 | 0 | fail: |
148 | 0 | WINPR_PRAGMA_DIAG_PUSH |
149 | 0 | WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC |
150 | 0 | nine_grid_cache_free(nine_grid); |
151 | 0 | WINPR_PRAGMA_DIAG_POP |
152 | 0 | return NULL; |
153 | 0 | } |
154 | | |
155 | | void nine_grid_cache_free(rdpNineGridCache* nine_grid) |
156 | 0 | { |
157 | 0 | if (nine_grid != NULL) |
158 | 0 | { |
159 | 0 | if (nine_grid->entries != NULL) |
160 | 0 | { |
161 | 0 | for (size_t i = 0; i < nine_grid->maxEntries; i++) |
162 | 0 | free(nine_grid->entries[i].entry); |
163 | |
|
164 | 0 | free(nine_grid->entries); |
165 | 0 | } |
166 | |
|
167 | 0 | free(nine_grid); |
168 | 0 | } |
169 | 0 | } |