2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
#include <freerdp/gdi/gdi.h>
|
|
|
|
|
|
|
|
#include <freerdp/gdi/dc.h>
|
|
|
|
#include <freerdp/gdi/pen.h>
|
|
|
|
#include <freerdp/gdi/region.h>
|
|
|
|
#include <freerdp/gdi/bitmap.h>
|
2016-07-18 13:36:22 +03:00
|
|
|
#include <freerdp/gdi/gdi.h>
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
#include "line.h"
|
|
|
|
#include "brush.h"
|
2016-07-18 13:36:22 +03:00
|
|
|
#include "drawing.h"
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
static int test_gdi_GetDC(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2015-05-08 22:39:23 +03:00
|
|
|
HGDI_DC hdc;
|
|
|
|
|
|
|
|
if (!(hdc = gdi_GetDC()))
|
|
|
|
{
|
|
|
|
printf("failed to get gdi device context\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2016-07-15 17:22:09 +03:00
|
|
|
if (hdc->format != PIXEL_FORMAT_XRGB32)
|
2013-12-11 01:35:46 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hdc->drawMode != GDI_R2_BLACK)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreateCompatibleDC(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
|
|
|
HGDI_DC hdc;
|
|
|
|
HGDI_DC chdc;
|
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!(hdc = gdi_GetDC()))
|
|
|
|
{
|
|
|
|
printf("failed to get gdi device context\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
hdc->format = PIXEL_FORMAT_RGB16;
|
2013-12-11 01:35:46 +04:00
|
|
|
hdc->drawMode = GDI_R2_XORPEN;
|
|
|
|
|
2015-06-26 15:32:38 +03:00
|
|
|
if (!(chdc = gdi_CreateCompatibleDC(hdc)))
|
|
|
|
{
|
|
|
|
printf("gdi_CreateCompatibleDC failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (chdc->format != hdc->format)
|
2013-12-11 01:35:46 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (chdc->drawMode != hdc->drawMode)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreateBitmap(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 format = PIXEL_FORMAT_ARGB32;
|
|
|
|
UINT32 width;
|
|
|
|
UINT32 height;
|
2013-12-11 01:35:46 +04:00
|
|
|
BYTE* data;
|
|
|
|
HGDI_BITMAP hBitmap;
|
|
|
|
width = 32;
|
|
|
|
height = 16;
|
2016-07-15 17:22:09 +03:00
|
|
|
|
2015-06-26 15:32:38 +03:00
|
|
|
if (!(data = (BYTE*) _aligned_malloc(width * height * 4, 16)))
|
|
|
|
{
|
|
|
|
printf("failed to allocate aligned bitmap data memory\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!(hBitmap = gdi_CreateBitmap(width, height, format, data)))
|
2015-06-26 15:32:38 +03:00
|
|
|
{
|
|
|
|
printf("gdi_CreateBitmap failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hBitmap->objectType != GDIOBJECT_BITMAP)
|
|
|
|
return -1;
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (hBitmap->format != format)
|
2013-12-11 01:35:46 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hBitmap->width != width)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hBitmap->height != height)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hBitmap->data != data)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hBitmap);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreateCompatibleBitmap(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
|
|
|
HGDI_DC hdc;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 width;
|
|
|
|
UINT32 height;
|
2013-12-11 01:35:46 +04:00
|
|
|
HGDI_BITMAP hBitmap;
|
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!(hdc = gdi_GetDC()))
|
|
|
|
{
|
|
|
|
printf("failed to get gdi device context\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
hdc->format = PIXEL_FORMAT_ARGB32;
|
2013-12-11 01:35:46 +04:00
|
|
|
width = 32;
|
|
|
|
height = 16;
|
|
|
|
hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
|
|
|
|
|
|
|
|
if (hBitmap->objectType != GDIOBJECT_BITMAP)
|
|
|
|
return -1;
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (hBitmap->format != hdc->format)
|
2013-12-11 01:35:46 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hBitmap->width != width)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hBitmap->height != height)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!hBitmap->data)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hBitmap);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreatePen(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2016-07-15 17:22:09 +03:00
|
|
|
const UINT32 format = PIXEL_FORMAT_RGBA32;
|
|
|
|
HGDI_PEN hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD,
|
|
|
|
format, NULL);
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2015-06-26 15:32:38 +03:00
|
|
|
if (!hPen)
|
|
|
|
{
|
|
|
|
printf("gdi_CreatePen failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-12-11 01:35:46 +04:00
|
|
|
if (hPen->style != GDI_PS_SOLID)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hPen->width != 8)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hPen->color != 0xAABBCCDD)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hPen);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreateSolidBrush(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
|
|
|
HGDI_BRUSH hBrush = gdi_CreateSolidBrush(0xAABBCCDD);
|
|
|
|
|
|
|
|
if (hBrush->objectType != GDIOBJECT_BRUSH)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hBrush->style != GDI_BS_SOLID)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hBrush->color != 0xAABBCCDD)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hBrush);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreatePatternBrush(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
|
|
|
HGDI_BRUSH hBrush;
|
|
|
|
HGDI_BITMAP hBitmap;
|
|
|
|
hBitmap = gdi_CreateBitmap(64, 64, 32, NULL);
|
|
|
|
hBrush = gdi_CreatePatternBrush(hBitmap);
|
|
|
|
|
|
|
|
if (hBrush->objectType != GDIOBJECT_BRUSH)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hBrush->style != GDI_BS_PATTERN)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hBrush->pattern != hBitmap)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hBitmap);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreateRectRgn(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
|
|
|
int x1 = 32;
|
|
|
|
int y1 = 64;
|
|
|
|
int x2 = 128;
|
|
|
|
int y2 = 256;
|
|
|
|
HGDI_RGN hRegion = gdi_CreateRectRgn(x1, y1, x2, y2);
|
|
|
|
|
|
|
|
if (hRegion->objectType != GDIOBJECT_REGION)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hRegion->x != x1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hRegion->y != y1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hRegion->w != x2 - x1 + 1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hRegion->h != y2 - y1 + 1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hRegion->null)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hRegion);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreateRect(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2015-06-26 15:32:38 +03:00
|
|
|
HGDI_RECT hRect;
|
2013-12-11 01:35:46 +04:00
|
|
|
int x1 = 32;
|
|
|
|
int y1 = 64;
|
|
|
|
int x2 = 128;
|
|
|
|
int y2 = 256;
|
|
|
|
|
2015-06-26 15:32:38 +03:00
|
|
|
if (!(hRect = gdi_CreateRect(x1, y1, x2, y2)))
|
|
|
|
{
|
|
|
|
printf("gdi_CreateRect failed\n");
|
2015-04-17 17:21:55 +03:00
|
|
|
return -1;
|
2015-06-26 15:32:38 +03:00
|
|
|
}
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hRect->objectType != GDIOBJECT_RECT)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hRect->left != x1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hRect->top != y1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hRect->right != x2)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hRect->bottom != y2)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hRect);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_GetPixel(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
|
|
|
HGDI_DC hdc;
|
|
|
|
int width = 128;
|
|
|
|
int height = 64;
|
|
|
|
HGDI_BITMAP hBitmap;
|
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!(hdc = gdi_GetDC()))
|
|
|
|
{
|
|
|
|
printf("failed to get gdi device context\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
hdc->format = PIXEL_FORMAT_ARGB32;
|
2013-12-11 01:35:46 +04:00
|
|
|
hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
|
|
|
|
gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap);
|
|
|
|
hBitmap->data[(64 * width * 4) + 32 * 4 + 0] = 0xDD;
|
|
|
|
hBitmap->data[(64 * width * 4) + 32 * 4 + 1] = 0xCC;
|
|
|
|
hBitmap->data[(64 * width * 4) + 32 * 4 + 2] = 0xBB;
|
|
|
|
hBitmap->data[(64 * width * 4) + 32 * 4 + 3] = 0xAA;
|
|
|
|
|
|
|
|
if (gdi_GetPixel(hdc, 32, 64) != 0xAABBCCDD)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hBitmap);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_SetPixel(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
|
|
|
HGDI_DC hdc;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 width = 128;
|
|
|
|
UINT32 height = 64;
|
2013-12-11 01:35:46 +04:00
|
|
|
HGDI_BITMAP hBitmap;
|
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!(hdc = gdi_GetDC()))
|
|
|
|
{
|
|
|
|
printf("failed to get gdi device context\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
hdc->format = PIXEL_FORMAT_ARGB32;
|
2013-12-11 01:35:46 +04:00
|
|
|
hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
|
|
|
|
gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap);
|
|
|
|
gdi_SetPixel(hdc, 32, 64, 0xAABBCCDD);
|
|
|
|
|
|
|
|
if (gdi_GetPixel(hdc, 32, 64) != 0xAABBCCDD)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
gdi_SetPixel(hdc, width - 1, height - 1, 0xAABBCCDD);
|
|
|
|
|
|
|
|
if (gdi_GetPixel(hdc, width - 1, height - 1) != 0xAABBCCDD)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hBitmap);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_SetROP2(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2015-05-08 22:39:23 +03:00
|
|
|
HGDI_DC hdc;
|
|
|
|
|
|
|
|
if (!(hdc = gdi_GetDC()))
|
|
|
|
{
|
|
|
|
printf("failed to get gdi device context\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
gdi_SetROP2(hdc, GDI_R2_BLACK);
|
|
|
|
|
|
|
|
if (hdc->drawMode != GDI_R2_BLACK)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_MoveToEx(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
|
|
|
HGDI_DC hdc;
|
|
|
|
HGDI_PEN hPen;
|
|
|
|
HGDI_POINT prevPoint;
|
2016-07-15 17:22:09 +03:00
|
|
|
const UINT32 format = PIXEL_FORMAT_RGBA32;
|
2016-07-18 13:36:22 +03:00
|
|
|
gdiPalette* palette = NULL;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!(hdc = gdi_GetDC()))
|
|
|
|
{
|
|
|
|
printf("failed to get gdi device context\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-07-15 17:22:09 +03:00
|
|
|
if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD, format, palette)))
|
2015-06-26 15:32:38 +03:00
|
|
|
{
|
|
|
|
printf("gdi_CreatePen failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-12-11 01:35:46 +04:00
|
|
|
gdi_SelectObject(hdc, (HGDIOBJECT) hPen);
|
|
|
|
gdi_MoveToEx(hdc, 128, 256, NULL);
|
|
|
|
|
|
|
|
if (hdc->pen->posX != 128)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hdc->pen->posY != 256)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
prevPoint = (HGDI_POINT) malloc(sizeof(GDI_POINT));
|
|
|
|
ZeroMemory(prevPoint, sizeof(GDI_POINT));
|
|
|
|
gdi_MoveToEx(hdc, 64, 128, prevPoint);
|
|
|
|
|
|
|
|
if (prevPoint->x != 128)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (prevPoint->y != 256)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hdc->pen->posX != 64)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hdc->pen->posY != 128)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TestGdiCreate(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
fprintf(stderr, "test_gdi_GetDC()\n");
|
|
|
|
|
|
|
|
if (test_gdi_GetDC() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fprintf(stderr, "test_gdi_CreateCompatibleDC()\n");
|
|
|
|
|
|
|
|
if (test_gdi_CreateCompatibleDC() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fprintf(stderr, "test_gdi_CreateBitmap()\n");
|
|
|
|
|
|
|
|
if (test_gdi_CreateBitmap() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fprintf(stderr, "test_gdi_CreateCompatibleBitmap()\n");
|
|
|
|
|
|
|
|
if (test_gdi_CreateCompatibleBitmap() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fprintf(stderr, "test_gdi_CreatePen()\n");
|
|
|
|
|
|
|
|
if (test_gdi_CreatePen() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fprintf(stderr, "test_gdi_CreateSolidBrush()\n");
|
|
|
|
|
|
|
|
if (test_gdi_CreateSolidBrush() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fprintf(stderr, "test_gdi_CreatePatternBrush()\n");
|
|
|
|
|
|
|
|
if (test_gdi_CreatePatternBrush() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fprintf(stderr, "test_gdi_CreateRectRgn()\n");
|
|
|
|
|
|
|
|
if (test_gdi_CreateRectRgn() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fprintf(stderr, "test_gdi_CreateRect()\n");
|
|
|
|
|
|
|
|
if (test_gdi_CreateRect() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fprintf(stderr, "test_gdi_GetPixel()\n");
|
|
|
|
|
|
|
|
if (test_gdi_GetPixel() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fprintf(stderr, "test_gdi_SetPixel()\n");
|
|
|
|
|
|
|
|
if (test_gdi_SetPixel() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fprintf(stderr, "test_gdi_SetROP2()\n");
|
|
|
|
|
|
|
|
if (test_gdi_SetROP2() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fprintf(stderr, "test_gdi_MoveToEx()\n");
|
|
|
|
|
|
|
|
if (test_gdi_MoveToEx() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|