Coverage Report

Created: 2023-09-25 06:56

/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;
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
  cache_free(cache);
77
0
  return NULL;
78
0
}
79
80
void cache_free(rdpCache* cache)
81
0
{
82
0
  if (cache != NULL)
83
0
  {
84
0
    glyph_cache_free(cache->glyph);
85
0
    brush_cache_free(cache->brush);
86
0
    pointer_cache_free(cache->pointer);
87
0
    bitmap_cache_free(cache->bitmap);
88
0
    offscreen_cache_free(cache->offscreen);
89
0
    palette_cache_free(cache->palette);
90
0
    nine_grid_cache_free(cache->nine_grid);
91
0
    free(cache);
92
0
  }
93
0
}
94
95
CACHE_COLOR_TABLE_ORDER* copy_cache_color_table_order(rdpContext* context,
96
                                                      const CACHE_COLOR_TABLE_ORDER* order)
97
0
{
98
0
  CACHE_COLOR_TABLE_ORDER* dst = calloc(1, sizeof(CACHE_COLOR_TABLE_ORDER));
99
100
0
  if (!dst || !order)
101
0
    goto fail;
102
103
0
  *dst = *order;
104
0
  return dst;
105
0
fail:
106
0
  free_cache_color_table_order(context, dst);
107
0
  return NULL;
108
0
}
109
110
void free_cache_color_table_order(rdpContext* context, CACHE_COLOR_TABLE_ORDER* order)
111
0
{
112
0
  free(order);
113
0
}
114
115
SURFACE_BITS_COMMAND* copy_surface_bits_command(rdpContext* context,
116
                                                const SURFACE_BITS_COMMAND* order)
117
0
{
118
0
  SURFACE_BITS_COMMAND* dst = calloc(1, sizeof(SURFACE_BITS_COMMAND));
119
0
  if (!dst || !order)
120
0
    goto fail;
121
122
0
  *dst = *order;
123
124
0
  dst->bmp.bitmapData = (BYTE*)malloc(order->bmp.bitmapDataLength);
125
126
0
  if (!dst->bmp.bitmapData)
127
0
    goto fail;
128
129
0
  CopyMemory(dst->bmp.bitmapData, order->bmp.bitmapData, order->bmp.bitmapDataLength);
130
131
0
  return dst;
132
133
0
fail:
134
0
  free_surface_bits_command(context, dst);
135
0
  return NULL;
136
0
}
137
138
void free_surface_bits_command(rdpContext* context, SURFACE_BITS_COMMAND* order)
139
0
{
140
0
  if (order)
141
0
    free(order->bmp.bitmapData);
142
0
  free(order);
143
0
}