/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/update.h> |
27 | | #include <freerdp/freerdp.h> |
28 | | #include <winpr/stream.h> |
29 | | |
30 | | #include "nine_grid.h" |
31 | | #include "cache.h" |
32 | | |
33 | | typedef struct |
34 | | { |
35 | | void* entry; |
36 | | } NINE_GRID_ENTRY; |
37 | | |
38 | | struct rdp_nine_grid_cache |
39 | | { |
40 | | pDrawNineGrid DrawNineGrid; /* 0 */ |
41 | | pMultiDrawNineGrid MultiDrawNineGrid; /* 1 */ |
42 | | UINT32 paddingA[16 - 2]; /* 2 */ |
43 | | |
44 | | UINT32 maxEntries; /* 16 */ |
45 | | UINT32 maxSize; /* 17 */ |
46 | | NINE_GRID_ENTRY* entries; /* 18 */ |
47 | | UINT32 paddingB[32 - 19]; /* 19 */ |
48 | | |
49 | | rdpContext* context; |
50 | | }; |
51 | | |
52 | | static BOOL update_gdi_draw_nine_grid(rdpContext* context, |
53 | | const DRAW_NINE_GRID_ORDER* draw_nine_grid) |
54 | 0 | { |
55 | 0 | rdpCache* cache = context->cache; |
56 | 0 | return IFCALLRESULT(TRUE, cache->nine_grid->DrawNineGrid, context, draw_nine_grid); |
57 | 0 | } |
58 | | |
59 | | static BOOL update_gdi_multi_draw_nine_grid(rdpContext* context, |
60 | | const MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid) |
61 | 0 | { |
62 | 0 | rdpCache* cache = context->cache; |
63 | 0 | return IFCALLRESULT(TRUE, cache->nine_grid->MultiDrawNineGrid, context, multi_draw_nine_grid); |
64 | 0 | } |
65 | | |
66 | | void nine_grid_cache_register_callbacks(rdpUpdate* update) |
67 | 0 | { |
68 | 0 | rdpCache* cache = update->context->cache; |
69 | |
|
70 | 0 | cache->nine_grid->DrawNineGrid = update->primary->DrawNineGrid; |
71 | 0 | cache->nine_grid->MultiDrawNineGrid = update->primary->MultiDrawNineGrid; |
72 | |
|
73 | 0 | update->primary->DrawNineGrid = update_gdi_draw_nine_grid; |
74 | 0 | update->primary->MultiDrawNineGrid = update_gdi_multi_draw_nine_grid; |
75 | 0 | } |
76 | | |
77 | | rdpNineGridCache* nine_grid_cache_new(rdpContext* context) |
78 | 0 | { |
79 | 0 | rdpNineGridCache* nine_grid = NULL; |
80 | 0 | rdpSettings* settings = NULL; |
81 | |
|
82 | 0 | WINPR_ASSERT(context); |
83 | | |
84 | 0 | settings = context->settings; |
85 | 0 | WINPR_ASSERT(settings); |
86 | | |
87 | 0 | nine_grid = (rdpNineGridCache*)calloc(1, sizeof(rdpNineGridCache)); |
88 | 0 | if (!nine_grid) |
89 | 0 | return NULL; |
90 | | |
91 | 0 | nine_grid->context = context; |
92 | |
|
93 | 0 | nine_grid->maxSize = 2560; |
94 | 0 | nine_grid->maxEntries = 256; |
95 | |
|
96 | 0 | if (!freerdp_settings_set_uint32(settings, FreeRDP_DrawNineGridCacheSize, nine_grid->maxSize)) |
97 | 0 | goto fail; |
98 | 0 | if (!freerdp_settings_set_uint32(settings, FreeRDP_DrawNineGridCacheEntries, |
99 | 0 | nine_grid->maxEntries)) |
100 | 0 | goto fail; |
101 | | |
102 | 0 | nine_grid->entries = (NINE_GRID_ENTRY*)calloc(nine_grid->maxEntries, sizeof(NINE_GRID_ENTRY)); |
103 | 0 | if (!nine_grid->entries) |
104 | 0 | goto fail; |
105 | | |
106 | 0 | return nine_grid; |
107 | | |
108 | 0 | fail: |
109 | 0 | WINPR_PRAGMA_DIAG_PUSH |
110 | 0 | WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC |
111 | 0 | nine_grid_cache_free(nine_grid); |
112 | 0 | WINPR_PRAGMA_DIAG_POP |
113 | 0 | return NULL; |
114 | 0 | } |
115 | | |
116 | | void nine_grid_cache_free(rdpNineGridCache* nine_grid) |
117 | 0 | { |
118 | 0 | if (nine_grid != NULL) |
119 | 0 | { |
120 | 0 | if (nine_grid->entries != NULL) |
121 | 0 | { |
122 | 0 | for (size_t i = 0; i < nine_grid->maxEntries; i++) |
123 | 0 | free(nine_grid->entries[i].entry); |
124 | |
|
125 | 0 | free(nine_grid->entries); |
126 | 0 | } |
127 | |
|
128 | 0 | free(nine_grid); |
129 | 0 | } |
130 | 0 | } |