2 * FreeRDP: A Remote Desktop Protocol Client
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <freerdp/utils/memory.h>
22 #include <freerdp/graphics.h>
26 rdpBitmap* Bitmap_Alloc(rdpContext* context)
29 rdpGraphics* graphics;
31 graphics = context->graphics;
32 bitmap = (rdpBitmap*) xmalloc(graphics->Bitmap_Prototype->size);
36 memcpy(bitmap, context->graphics->Bitmap_Prototype, sizeof(rdpBitmap));
43 void Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
48 void Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
52 bitmap->Free(context, bitmap);
54 if (bitmap->data != NULL)
61 void Bitmap_SetRectangle(rdpContext* context, rdpBitmap* bitmap, uint16 left, uint16 top, uint16 right, uint16 bottom)
65 bitmap->right = right;
66 bitmap->bottom = bottom;
69 void Bitmap_SetDimensions(rdpContext* context, rdpBitmap* bitmap, uint16 width, uint16 height)
71 bitmap->width = width;
72 bitmap->height = height;
76 void Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, boolean primary)
78 context->graphics->Bitmap_Prototype->SetSurface(context, bitmap, primary);
81 void graphics_register_bitmap(rdpGraphics* graphics, rdpBitmap* bitmap)
83 memcpy(graphics->Bitmap_Prototype, bitmap, sizeof(rdpBitmap));
88 rdpPointer* Pointer_Alloc(rdpContext* context)
91 rdpGraphics* graphics;
93 graphics = context->graphics;
94 pointer = (rdpPointer*) xmalloc(graphics->Pointer_Prototype->size);
98 memcpy(pointer, context->graphics->Pointer_Prototype, sizeof(rdpPointer));
104 void Pointer_New(rdpContext* context, rdpPointer* pointer)
109 void Pointer_Free(rdpContext* context, rdpPointer* pointer)
113 pointer->Free(context, pointer);
115 if (pointer->xorMaskData)
116 xfree(pointer->xorMaskData);
118 if (pointer->andMaskData)
119 xfree(pointer->andMaskData);
126 void Pointer_Set(rdpContext* context, rdpPointer* pointer)
128 context->graphics->Pointer_Prototype->Set(context, pointer);
131 void graphics_register_pointer(rdpGraphics* graphics, rdpPointer* pointer)
133 memcpy(graphics->Pointer_Prototype, pointer, sizeof(rdpPointer));
138 rdpGlyph* Glyph_Alloc(rdpContext* context)
141 rdpGraphics* graphics;
143 graphics = context->graphics;
144 glyph = (rdpGlyph*) xmalloc(graphics->Glyph_Prototype->size);
148 memcpy(glyph, context->graphics->Glyph_Prototype, sizeof(rdpGlyph));
154 void Glyph_New(rdpContext* context, rdpGlyph* glyph)
156 context->graphics->Glyph_Prototype->New(context, glyph);
159 void Glyph_Free(rdpContext* context, rdpGlyph* glyph)
161 context->graphics->Glyph_Prototype->Free(context, glyph);
164 void Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y)
166 context->graphics->Glyph_Prototype->Draw(context, glyph, x, y);
169 void Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
171 context->graphics->Glyph_Prototype->BeginDraw(context, x, y, width, height, bgcolor, fgcolor);
174 void Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
176 context->graphics->Glyph_Prototype->EndDraw(context, x, y, width, height, bgcolor, fgcolor);
179 void graphics_register_glyph(rdpGraphics* graphics, rdpGlyph* glyph)
181 memcpy(graphics->Glyph_Prototype, glyph, sizeof(rdpGlyph));
184 /* Graphics Module */
186 rdpGraphics* graphics_new(rdpContext* context)
188 rdpGraphics* graphics;
190 graphics = (rdpGraphics*) xzalloc(sizeof(rdpGraphics));
192 if (graphics != NULL)
194 graphics->context = context;
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;
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;
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;
215 void graphics_free(rdpGraphics* graphics)
217 if (graphics != NULL)
219 xfree(graphics->Bitmap_Prototype);
220 xfree(graphics->Pointer_Prototype);
221 xfree(graphics->Glyph_Prototype);