Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / libfreerdp-core / graphics.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * Graphical Objects
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/utils/memory.h>
21
22 #include <freerdp/graphics.h>
23
24 /* Bitmap Class */
25
26 rdpBitmap* Bitmap_Alloc(rdpContext* context)
27 {
28         rdpBitmap* bitmap;
29         rdpGraphics* graphics;
30
31         graphics = context->graphics;
32         bitmap = (rdpBitmap*) xmalloc(graphics->Bitmap_Prototype->size);
33
34         if (bitmap != NULL)
35         {
36                 memcpy(bitmap, context->graphics->Bitmap_Prototype, sizeof(rdpBitmap));
37                 bitmap->data = NULL;
38         }
39
40         return bitmap;
41 }
42
43 void Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
44 {
45
46 }
47
48 void Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
49 {
50         if (bitmap != NULL)
51         {
52                 bitmap->Free(context, bitmap);
53
54                 if (bitmap->data != NULL)
55                         xfree(bitmap->data);
56
57                 xfree(bitmap);
58         }
59 }
60
61 void Bitmap_SetRectangle(rdpContext* context, rdpBitmap* bitmap, uint16 left, uint16 top, uint16 right, uint16 bottom)
62 {
63         bitmap->left = left;
64         bitmap->top = top;
65         bitmap->right = right;
66         bitmap->bottom = bottom;
67 }
68
69 void Bitmap_SetDimensions(rdpContext* context, rdpBitmap* bitmap, uint16 width, uint16 height)
70 {
71         bitmap->width = width;
72         bitmap->height = height;
73 }
74
75 /* static method */
76 void Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, boolean primary)
77 {
78         context->graphics->Bitmap_Prototype->SetSurface(context, bitmap, primary);
79 }
80
81 void graphics_register_bitmap(rdpGraphics* graphics, rdpBitmap* bitmap)
82 {
83         memcpy(graphics->Bitmap_Prototype, bitmap, sizeof(rdpBitmap));
84 }
85
86 /* Pointer Class */
87
88 rdpPointer* Pointer_Alloc(rdpContext* context)
89 {
90         rdpPointer* pointer;
91         rdpGraphics* graphics;
92
93         graphics = context->graphics;
94         pointer = (rdpPointer*) xmalloc(graphics->Pointer_Prototype->size);
95
96         if (pointer != NULL)
97         {
98                 memcpy(pointer, context->graphics->Pointer_Prototype, sizeof(rdpPointer));
99         }
100
101         return pointer;
102 }
103
104 void Pointer_New(rdpContext* context, rdpPointer* pointer)
105 {
106
107 }
108
109 void Pointer_Free(rdpContext* context, rdpPointer* pointer)
110 {
111         if (pointer != NULL)
112         {
113                 pointer->Free(context, pointer);
114
115                 if (pointer->xorMaskData)
116                         xfree(pointer->xorMaskData);
117
118                 if (pointer->andMaskData)
119                         xfree(pointer->andMaskData);
120
121                 xfree(pointer);
122         }
123 }
124
125 /* static method */
126 void Pointer_Set(rdpContext* context, rdpPointer* pointer)
127 {
128         context->graphics->Pointer_Prototype->Set(context, pointer);
129 }
130
131 void graphics_register_pointer(rdpGraphics* graphics, rdpPointer* pointer)
132 {
133         memcpy(graphics->Pointer_Prototype, pointer, sizeof(rdpPointer));
134 }
135
136 /* Glyph Class */
137
138 rdpGlyph* Glyph_Alloc(rdpContext* context)
139 {
140         rdpGlyph* glyph;
141         rdpGraphics* graphics;
142
143         graphics = context->graphics;
144         glyph = (rdpGlyph*) xmalloc(graphics->Glyph_Prototype->size);
145
146         if (glyph != NULL)
147         {
148                 memcpy(glyph, context->graphics->Glyph_Prototype, sizeof(rdpGlyph));
149         }
150
151         return glyph;
152 }
153
154 void Glyph_New(rdpContext* context, rdpGlyph* glyph)
155 {
156         context->graphics->Glyph_Prototype->New(context, glyph);
157 }
158
159 void Glyph_Free(rdpContext* context, rdpGlyph* glyph)
160 {
161         context->graphics->Glyph_Prototype->Free(context, glyph);
162 }
163
164 void Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y)
165 {
166         context->graphics->Glyph_Prototype->Draw(context, glyph, x, y);
167 }
168
169 void Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
170 {
171         context->graphics->Glyph_Prototype->BeginDraw(context, x, y, width, height, bgcolor, fgcolor);
172 }
173
174 void Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
175 {
176         context->graphics->Glyph_Prototype->EndDraw(context, x, y, width, height, bgcolor, fgcolor);
177 }
178
179 void graphics_register_glyph(rdpGraphics* graphics, rdpGlyph* glyph)
180 {
181         memcpy(graphics->Glyph_Prototype, glyph, sizeof(rdpGlyph));
182 }
183
184 /* Graphics Module */
185
186 rdpGraphics* graphics_new(rdpContext* context)
187 {
188         rdpGraphics* graphics;
189
190         graphics = (rdpGraphics*) xzalloc(sizeof(rdpGraphics));
191
192         if (graphics != NULL)
193         {
194                 graphics->context = context;
195
196                 graphics->Bitmap_Prototype = (rdpBitmap*) xzalloc(sizeof(rdpBitmap));
197                 graphics->Bitmap_Prototype->size = sizeof(rdpBitmap);
198                 graphics->Bitmap_Prototype->New = Bitmap_New;
199                 graphics->Bitmap_Prototype->Free = Bitmap_Free;
200
201                 graphics->Pointer_Prototype = (rdpPointer*) xzalloc(sizeof(rdpPointer));
202                 graphics->Pointer_Prototype->size = sizeof(rdpPointer);
203                 graphics->Pointer_Prototype->New = Pointer_New;
204                 graphics->Pointer_Prototype->Free = Pointer_Free;
205
206                 graphics->Glyph_Prototype = (rdpGlyph*) xzalloc(sizeof(rdpGlyph));
207                 graphics->Glyph_Prototype->size = sizeof(rdpGlyph);
208                 graphics->Glyph_Prototype->New = Glyph_New;
209                 graphics->Glyph_Prototype->Free = Glyph_Free;
210         }
211
212         return graphics;
213 }
214
215 void graphics_free(rdpGraphics* graphics)
216 {
217         if (graphics != NULL)
218         {
219                 xfree(graphics->Bitmap_Prototype);
220                 xfree(graphics->Pointer_Prototype);
221                 xfree(graphics->Glyph_Prototype);
222                 xfree(graphics);
223         }
224 }