2011-10-21 01:28:59 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-10-21 01:28:59 +04:00
|
|
|
* Graphical Objects
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-11-22 04:22:41 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2011-10-21 01:28:59 +04:00
|
|
|
#include <freerdp/graphics.h>
|
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
/* Bitmap Class */
|
|
|
|
|
2011-10-21 01:28:59 +04:00
|
|
|
rdpBitmap* Bitmap_Alloc(rdpContext* context)
|
|
|
|
{
|
|
|
|
rdpBitmap* bitmap;
|
|
|
|
rdpGraphics* graphics;
|
|
|
|
|
|
|
|
graphics = context->graphics;
|
2014-09-12 09:03:19 +04:00
|
|
|
bitmap = (rdpBitmap*) calloc(1, graphics->Bitmap_Prototype->size);
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
if (bitmap)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2014-08-20 13:54:05 +04:00
|
|
|
CopyMemory(bitmap, graphics->Bitmap_Prototype, sizeof(rdpBitmap));
|
2011-10-21 05:34:55 +04:00
|
|
|
bitmap->data = NULL;
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
void Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2014-07-08 23:07:19 +04:00
|
|
|
if (bitmap)
|
2011-10-21 02:18:45 +04:00
|
|
|
{
|
2011-10-26 07:12:28 +04:00
|
|
|
bitmap->Free(context, bitmap);
|
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
if (bitmap->data)
|
|
|
|
_aligned_free(bitmap->data);
|
2011-10-21 02:18:45 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(bitmap);
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void Bitmap_SetRectangle(rdpContext* context, rdpBitmap* bitmap, UINT16 left, UINT16 top, UINT16 right, UINT16 bottom)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2011-10-21 05:34:55 +04:00
|
|
|
bitmap->left = left;
|
|
|
|
bitmap->top = top;
|
|
|
|
bitmap->right = right;
|
|
|
|
bitmap->bottom = bottom;
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void Bitmap_SetDimensions(rdpContext* context, rdpBitmap* bitmap, UINT16 width, UINT16 height)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2011-10-21 05:34:55 +04:00
|
|
|
bitmap->width = width;
|
|
|
|
bitmap->height = height;
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
/* static method */
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary)
|
2011-10-21 02:18:45 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
return context->graphics->Bitmap_Prototype->SetSurface(context, bitmap, primary);
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void graphics_register_bitmap(rdpGraphics* graphics, rdpBitmap* bitmap)
|
|
|
|
{
|
2014-07-08 23:07:19 +04:00
|
|
|
CopyMemory(graphics->Bitmap_Prototype, bitmap, sizeof(rdpBitmap));
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
/* Pointer Class */
|
|
|
|
|
|
|
|
rdpPointer* Pointer_Alloc(rdpContext* context)
|
|
|
|
{
|
|
|
|
rdpPointer* pointer;
|
|
|
|
rdpGraphics* graphics;
|
|
|
|
|
|
|
|
graphics = context->graphics;
|
2014-09-12 09:03:19 +04:00
|
|
|
pointer = (rdpPointer*) calloc(1, graphics->Pointer_Prototype->size);
|
2011-10-21 02:18:45 +04:00
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
if (pointer)
|
2011-10-21 02:18:45 +04:00
|
|
|
{
|
2014-08-20 13:54:05 +04:00
|
|
|
CopyMemory(pointer, graphics->Pointer_Prototype, sizeof(rdpPointer));
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return pointer;
|
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL Pointer_New(rdpContext* context, rdpPointer* pointer)
|
2011-10-21 02:18:45 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Pointer_Free(rdpContext* context, rdpPointer* pointer)
|
|
|
|
{
|
2014-07-08 23:07:19 +04:00
|
|
|
if (pointer)
|
2012-02-02 03:42:20 +04:00
|
|
|
{
|
|
|
|
pointer->Free(context, pointer);
|
|
|
|
|
|
|
|
if (pointer->xorMaskData)
|
2013-06-28 17:18:20 +04:00
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(pointer->xorMaskData);
|
2013-06-28 17:18:20 +04:00
|
|
|
pointer->xorMaskData = NULL;
|
|
|
|
}
|
2011-10-21 02:18:45 +04:00
|
|
|
|
2012-02-02 03:42:20 +04:00
|
|
|
if (pointer->andMaskData)
|
2013-06-28 17:18:20 +04:00
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(pointer->andMaskData);
|
2013-06-28 17:18:20 +04:00
|
|
|
pointer->andMaskData = NULL;
|
|
|
|
}
|
2012-02-02 03:42:20 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(pointer);
|
2012-02-02 03:42:20 +04:00
|
|
|
}
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static method */
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL Pointer_Set(rdpContext* context, rdpPointer* pointer)
|
2011-10-21 02:18:45 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
return context->graphics->Pointer_Prototype->Set(context, pointer);
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL Pointer_SetNull(rdpContext* context)
|
2012-02-24 16:44:23 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
return context->graphics->Pointer_Prototype->SetNull(context);
|
2012-02-24 16:44:23 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL Pointer_SetDefault(rdpContext* context)
|
2012-02-24 16:44:23 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
return context->graphics->Pointer_Prototype->SetDefault(context);
|
2012-02-24 16:44:23 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
|
2015-01-13 19:12:02 +03:00
|
|
|
{
|
2015-04-17 17:21:55 +03:00
|
|
|
return IFCALLRESULT(TRUE, context->graphics->Pointer_Prototype->SetPosition, context, x, y);
|
2015-01-13 19:12:02 +03:00
|
|
|
}
|
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
void graphics_register_pointer(rdpGraphics* graphics, rdpPointer* pointer)
|
|
|
|
{
|
2014-07-08 23:07:19 +04:00
|
|
|
CopyMemory(graphics->Pointer_Prototype, pointer, sizeof(rdpPointer));
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
|
|
|
|
2011-11-09 09:43:56 +04:00
|
|
|
/* Glyph Class */
|
|
|
|
|
|
|
|
rdpGlyph* Glyph_Alloc(rdpContext* context)
|
|
|
|
{
|
|
|
|
rdpGlyph* glyph;
|
|
|
|
rdpGraphics* graphics;
|
|
|
|
|
|
|
|
graphics = context->graphics;
|
2014-09-12 09:03:19 +04:00
|
|
|
glyph = (rdpGlyph*) calloc(1, graphics->Glyph_Prototype->size);
|
2011-11-09 09:43:56 +04:00
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
if (glyph)
|
2011-11-09 09:43:56 +04:00
|
|
|
{
|
2014-08-20 13:54:05 +04:00
|
|
|
CopyMemory(glyph, graphics->Glyph_Prototype, sizeof(rdpGlyph));
|
2011-11-09 09:43:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return glyph;
|
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL Glyph_New(rdpContext* context, rdpGlyph* glyph)
|
2011-11-09 09:43:56 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
return context->graphics->Glyph_Prototype->New(context, glyph);
|
2011-11-09 09:43:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Glyph_Free(rdpContext* context, rdpGlyph* glyph)
|
|
|
|
{
|
|
|
|
context->graphics->Glyph_Prototype->Free(context, glyph);
|
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y)
|
2011-11-09 09:43:56 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
return context->graphics->Glyph_Prototype->Draw(context, glyph, x, y);
|
2011-11-09 09:43:56 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant)
|
2011-11-09 09:43:56 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
return context->graphics->Glyph_Prototype->BeginDraw(context, x, y, width, height, bgcolor, fgcolor, fOpRedundant);
|
2011-11-09 09:43:56 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor)
|
2011-11-09 09:43:56 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
return context->graphics->Glyph_Prototype->EndDraw(context, x, y, width, height, bgcolor, fgcolor);
|
2011-11-09 09:43:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void graphics_register_glyph(rdpGraphics* graphics, rdpGlyph* glyph)
|
|
|
|
{
|
2014-07-08 23:07:19 +04:00
|
|
|
CopyMemory(graphics->Glyph_Prototype, glyph, sizeof(rdpGlyph));
|
2011-11-09 09:43:56 +04:00
|
|
|
}
|
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
/* Graphics Module */
|
|
|
|
|
2011-10-21 01:28:59 +04:00
|
|
|
rdpGraphics* graphics_new(rdpContext* context)
|
|
|
|
{
|
|
|
|
rdpGraphics* graphics;
|
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
graphics = (rdpGraphics*) calloc(1, sizeof(rdpGraphics));
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
if (graphics)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2011-11-09 08:26:44 +04:00
|
|
|
graphics->context = context;
|
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
graphics->Bitmap_Prototype = (rdpBitmap*) calloc(1, sizeof(rdpBitmap));
|
|
|
|
|
|
|
|
if (!graphics->Bitmap_Prototype)
|
2014-11-17 02:41:06 +03:00
|
|
|
{
|
|
|
|
free (graphics);
|
2014-07-08 23:07:19 +04:00
|
|
|
return NULL;
|
2014-11-17 02:41:06 +03:00
|
|
|
}
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2011-10-21 01:28:59 +04:00
|
|
|
graphics->Bitmap_Prototype->size = sizeof(rdpBitmap);
|
|
|
|
graphics->Bitmap_Prototype->New = Bitmap_New;
|
|
|
|
graphics->Bitmap_Prototype->Free = Bitmap_Free;
|
2011-10-21 02:18:45 +04:00
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
graphics->Pointer_Prototype = (rdpPointer*) calloc(1, sizeof(rdpPointer));
|
|
|
|
|
|
|
|
if (!graphics->Pointer_Prototype)
|
2014-11-17 02:41:06 +03:00
|
|
|
{
|
|
|
|
free (graphics->Bitmap_Prototype);
|
|
|
|
free (graphics);
|
2014-07-08 23:07:19 +04:00
|
|
|
return NULL;
|
2014-11-17 02:41:06 +03:00
|
|
|
}
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
graphics->Pointer_Prototype->size = sizeof(rdpPointer);
|
|
|
|
graphics->Pointer_Prototype->New = Pointer_New;
|
|
|
|
graphics->Pointer_Prototype->Free = Pointer_Free;
|
2011-11-09 09:43:56 +04:00
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
graphics->Glyph_Prototype = (rdpGlyph*) calloc(1, sizeof(rdpGlyph));
|
|
|
|
|
|
|
|
if (!graphics->Glyph_Prototype)
|
2014-11-17 02:41:06 +03:00
|
|
|
{
|
|
|
|
free (graphics->Pointer_Prototype);
|
|
|
|
free (graphics->Bitmap_Prototype);
|
|
|
|
free (graphics);
|
2014-07-08 23:07:19 +04:00
|
|
|
return NULL;
|
2014-11-17 02:41:06 +03:00
|
|
|
}
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2011-11-09 09:43:56 +04:00
|
|
|
graphics->Glyph_Prototype->size = sizeof(rdpGlyph);
|
|
|
|
graphics->Glyph_Prototype->New = Glyph_New;
|
|
|
|
graphics->Glyph_Prototype->Free = Glyph_Free;
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return graphics;
|
|
|
|
}
|
|
|
|
|
|
|
|
void graphics_free(rdpGraphics* graphics)
|
|
|
|
{
|
2014-07-08 23:07:19 +04:00
|
|
|
if (graphics)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(graphics->Bitmap_Prototype);
|
|
|
|
free(graphics->Pointer_Prototype);
|
|
|
|
free(graphics->Glyph_Prototype);
|
|
|
|
free(graphics);
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
}
|