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
|
|
|
|
2016-08-01 18:31:59 +03:00
|
|
|
static const UINT32 colorFormatList[] =
|
|
|
|
{
|
|
|
|
PIXEL_FORMAT_RGB15,
|
|
|
|
PIXEL_FORMAT_BGR15,
|
|
|
|
PIXEL_FORMAT_RGB16,
|
|
|
|
PIXEL_FORMAT_BGR16,
|
|
|
|
PIXEL_FORMAT_RGB24,
|
|
|
|
PIXEL_FORMAT_BGR24,
|
|
|
|
PIXEL_FORMAT_ARGB32,
|
|
|
|
PIXEL_FORMAT_ABGR32,
|
|
|
|
PIXEL_FORMAT_XRGB32,
|
|
|
|
PIXEL_FORMAT_XBGR32,
|
|
|
|
PIXEL_FORMAT_RGBX32,
|
|
|
|
PIXEL_FORMAT_BGRX32
|
|
|
|
|
|
|
|
};
|
|
|
|
static const UINT32 colorFormatCount = sizeof(colorFormatList) / sizeof(
|
|
|
|
colorFormatList[0]);
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_GetDC(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
int rc = -1;
|
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)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hdc->drawMode != GDI_R2_BLACK)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
rc = 0;
|
|
|
|
fail:
|
|
|
|
gdi_DeleteDC(hdc);
|
|
|
|
return rc;
|
2013-12-11 01:35:46 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreateCompatibleDC(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
int rc = -1;
|
|
|
|
HGDI_DC hdc = NULL;
|
|
|
|
HGDI_DC chdc = 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-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");
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2015-06-26 15:32:38 +03:00
|
|
|
}
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (chdc->format != hdc->format)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (chdc->drawMode != hdc->drawMode)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
fail:
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
if (chdc)
|
|
|
|
gdi_DeleteDC(chdc);
|
|
|
|
|
|
|
|
gdi_DeleteDC(hdc);
|
|
|
|
return rc;
|
2013-12-11 01:35:46 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreateBitmap(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
int rc = -1;
|
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;
|
2017-11-15 11:11:12 +03:00
|
|
|
HGDI_BITMAP hBitmap = NULL;
|
2013-12-11 01:35:46 +04:00
|
|
|
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");
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2015-06-26 15:32:38 +03:00
|
|
|
}
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hBitmap->objectType != GDIOBJECT_BITMAP)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (hBitmap->format != format)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hBitmap->width != width)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hBitmap->height != height)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hBitmap->data != data)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
fail:
|
|
|
|
|
|
|
|
if (hBitmap)
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hBitmap);
|
|
|
|
else
|
|
|
|
free(data);
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
return rc;
|
2013-12-11 01:35:46 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreateCompatibleBitmap(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
int rc = -1;
|
2013-12-11 01:35:46 +04:00
|
|
|
HGDI_DC hdc;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 width;
|
|
|
|
UINT32 height;
|
2017-11-15 11:11:12 +03:00
|
|
|
HGDI_BITMAP hBitmap = 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-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)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (hBitmap->format != hdc->format)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hBitmap->width != width)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hBitmap->height != height)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (!hBitmap->data)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
fail:
|
|
|
|
|
|
|
|
if (hBitmap)
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hBitmap);
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
gdi_DeleteDC(hdc);
|
|
|
|
return rc;
|
2013-12-11 01:35:46 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreatePen(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
int rc = -1;
|
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)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hPen->width != 8)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hPen->color != 0xAABBCCDD)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
rc = 0;
|
|
|
|
fail:
|
2013-12-11 01:35:46 +04:00
|
|
|
gdi_DeleteObject((HGDIOBJECT) hPen);
|
2017-11-15 11:11:12 +03:00
|
|
|
return rc;
|
2013-12-11 01:35:46 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreateSolidBrush(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
int rc = -1;
|
2013-12-11 01:35:46 +04:00
|
|
|
HGDI_BRUSH hBrush = gdi_CreateSolidBrush(0xAABBCCDD);
|
|
|
|
|
|
|
|
if (hBrush->objectType != GDIOBJECT_BRUSH)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hBrush->style != GDI_BS_SOLID)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hBrush->color != 0xAABBCCDD)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
rc = 0;
|
|
|
|
fail:
|
2013-12-11 01:35:46 +04:00
|
|
|
gdi_DeleteObject((HGDIOBJECT) hBrush);
|
2017-11-15 11:11:12 +03:00
|
|
|
return rc;
|
2013-12-11 01:35:46 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreatePatternBrush(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
int rc = -1;
|
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);
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
if (!hBitmap || !hBrush)
|
|
|
|
goto fail;
|
|
|
|
|
2013-12-11 01:35:46 +04:00
|
|
|
if (hBrush->objectType != GDIOBJECT_BRUSH)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hBrush->style != GDI_BS_PATTERN)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hBrush->pattern != hBitmap)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
fail:
|
|
|
|
|
|
|
|
if (hBitmap)
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hBitmap);
|
|
|
|
|
|
|
|
if (hBrush)
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hBrush);
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
return rc;
|
2013-12-11 01:35:46 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreateRectRgn(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
int rc = -1;
|
|
|
|
UINT32 x1 = 32;
|
|
|
|
UINT32 y1 = 64;
|
|
|
|
UINT32 x2 = 128;
|
|
|
|
UINT32 y2 = 256;
|
2013-12-11 01:35:46 +04:00
|
|
|
HGDI_RGN hRegion = gdi_CreateRectRgn(x1, y1, x2, y2);
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
if (!hRegion)
|
|
|
|
return rc;
|
|
|
|
|
2013-12-11 01:35:46 +04:00
|
|
|
if (hRegion->objectType != GDIOBJECT_REGION)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hRegion->x != x1)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hRegion->y != y1)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hRegion->w != x2 - x1 + 1)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hRegion->h != y2 - y1 + 1)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hRegion->null)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
rc = 0;
|
|
|
|
fail:
|
2013-12-11 01:35:46 +04:00
|
|
|
gdi_DeleteObject((HGDIOBJECT) hRegion);
|
2017-11-15 11:11:12 +03:00
|
|
|
return rc;
|
2013-12-11 01:35:46 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_CreateRect(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
int rc = -1;
|
2015-06-26 15:32:38 +03:00
|
|
|
HGDI_RECT hRect;
|
2017-11-15 11:11:12 +03:00
|
|
|
UINT32 x1 = 32;
|
|
|
|
UINT32 y1 = 64;
|
|
|
|
UINT32 x2 = 128;
|
|
|
|
UINT32 y2 = 256;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
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)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hRect->left != x1)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hRect->top != y1)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hRect->right != x2)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hRect->bottom != y2)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
rc = 0;
|
|
|
|
fail:
|
2013-12-11 01:35:46 +04:00
|
|
|
gdi_DeleteObject((HGDIOBJECT) hRect);
|
2017-11-15 11:11:12 +03:00
|
|
|
return rc;
|
2013-12-11 01:35:46 +04:00
|
|
|
}
|
|
|
|
|
2016-08-01 18:31:59 +03:00
|
|
|
static BOOL test_gdi_GetPixel(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2016-08-01 18:31:59 +03:00
|
|
|
BOOL rc = TRUE;
|
|
|
|
UINT32 x;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2016-08-01 18:31:59 +03:00
|
|
|
for (x = 0; x < colorFormatCount; x++)
|
2015-05-08 22:39:23 +03:00
|
|
|
{
|
2016-08-01 18:31:59 +03:00
|
|
|
UINT32 i, j;
|
|
|
|
UINT32 bpp;
|
|
|
|
HGDI_DC hdc;
|
|
|
|
UINT32 width = 128;
|
|
|
|
UINT32 height = 64;
|
|
|
|
HGDI_BITMAP hBitmap;
|
|
|
|
|
|
|
|
if (!(hdc = gdi_GetDC()))
|
|
|
|
{
|
|
|
|
printf("failed to get gdi device context\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
hdc->format = colorFormatList[x];
|
|
|
|
hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
|
2017-11-15 11:11:12 +03:00
|
|
|
|
|
|
|
if (!hBitmap)
|
|
|
|
{
|
|
|
|
gdi_DeleteDC(hdc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-08-01 18:31:59 +03:00
|
|
|
gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap);
|
|
|
|
bpp = GetBytesPerPixel(hBitmap->format);
|
|
|
|
|
|
|
|
for (i = 0; i < height; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < width; j++)
|
|
|
|
{
|
|
|
|
UINT32 pixel;
|
2017-11-24 15:19:48 +03:00
|
|
|
const UINT32 color = FreeRDPGetColor(hBitmap->format, rand(), rand(), rand(), rand());
|
2016-08-01 18:31:59 +03:00
|
|
|
WriteColor(&hBitmap->data[i * hBitmap->scanline + j * bpp], hBitmap->format,
|
|
|
|
color);
|
|
|
|
pixel = gdi_GetPixel(hdc, j, i);
|
|
|
|
|
|
|
|
if (pixel != color)
|
|
|
|
{
|
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rc)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hBitmap);
|
|
|
|
gdi_DeleteDC(hdc);
|
2015-05-08 22:39:23 +03:00
|
|
|
}
|
|
|
|
|
2016-08-01 18:31:59 +03:00
|
|
|
return rc;
|
2013-12-11 01:35:46 +04:00
|
|
|
}
|
|
|
|
|
2016-08-01 18:31:59 +03:00
|
|
|
static BOOL test_gdi_SetPixel(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2016-08-01 18:31:59 +03:00
|
|
|
BOOL rc = TRUE;
|
|
|
|
UINT32 x;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2016-08-01 18:31:59 +03:00
|
|
|
for (x = 0; x < colorFormatCount; x++)
|
2015-05-08 22:39:23 +03:00
|
|
|
{
|
2016-08-01 18:31:59 +03:00
|
|
|
UINT32 i, j, bpp;
|
|
|
|
HGDI_DC hdc;
|
|
|
|
UINT32 width = 128;
|
|
|
|
UINT32 height = 64;
|
|
|
|
HGDI_BITMAP hBitmap;
|
|
|
|
|
|
|
|
if (!(hdc = gdi_GetDC()))
|
|
|
|
{
|
|
|
|
printf("failed to get gdi device context\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hdc->format = colorFormatList[x];
|
|
|
|
hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
|
|
|
|
gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap);
|
|
|
|
bpp = GetBytesPerPixel(hBitmap->format);
|
|
|
|
|
|
|
|
for (i = 0; i < height; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < width; j++)
|
|
|
|
{
|
|
|
|
UINT32 pixel;
|
2017-11-24 15:19:48 +03:00
|
|
|
const UINT32 color = FreeRDPGetColor(hBitmap->format, rand(), rand(), rand(), rand());
|
2016-08-01 18:31:59 +03:00
|
|
|
gdi_SetPixel(hdc, j, i, color);
|
|
|
|
pixel = ReadColor(&hBitmap->data[i * hBitmap->scanline + j * bpp],
|
|
|
|
hBitmap->format);
|
|
|
|
|
|
|
|
if (pixel != color)
|
|
|
|
{
|
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rc)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdi_DeleteObject((HGDIOBJECT) hBitmap);
|
|
|
|
gdi_DeleteDC(hdc);
|
2015-05-08 22:39:23 +03:00
|
|
|
}
|
|
|
|
|
2016-08-01 18:31:59 +03:00
|
|
|
return rc;
|
2013-12-11 01:35:46 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_SetROP2(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
int rc = -1;
|
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)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
rc = 0;
|
|
|
|
fail:
|
|
|
|
gdi_DeleteDC(hdc);
|
|
|
|
return rc;
|
2013-12-11 01:35:46 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static int test_gdi_MoveToEx(void)
|
2013-12-11 01:35:46 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
int rc = -1;
|
2013-12-11 01:35:46 +04:00
|
|
|
HGDI_DC hdc;
|
2017-11-15 11:11:12 +03:00
|
|
|
HGDI_PEN hPen = NULL;
|
|
|
|
HGDI_POINT prevPoint = NULL;
|
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");
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2015-06-26 15:32:38 +03:00
|
|
|
}
|
|
|
|
|
2013-12-11 01:35:46 +04:00
|
|
|
gdi_SelectObject(hdc, (HGDIOBJECT) hPen);
|
|
|
|
gdi_MoveToEx(hdc, 128, 256, NULL);
|
|
|
|
|
|
|
|
if (hdc->pen->posX != 128)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hdc->pen->posY != 256)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
prevPoint = (HGDI_POINT) malloc(sizeof(GDI_POINT));
|
|
|
|
ZeroMemory(prevPoint, sizeof(GDI_POINT));
|
|
|
|
gdi_MoveToEx(hdc, 64, 128, prevPoint);
|
|
|
|
|
|
|
|
if (prevPoint->x != 128)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (prevPoint->y != 256)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hdc->pen->posX != 64)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
2013-12-11 01:35:46 +04:00
|
|
|
|
|
|
|
if (hdc->pen->posY != 128)
|
2017-11-15 11:11:12 +03:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
fail:
|
2013-12-11 01:35:46 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
if (hPen)
|
|
|
|
gdi_DeleteObject((HGDIOBJECT)hPen);
|
|
|
|
|
|
|
|
free(prevPoint);
|
|
|
|
gdi_DeleteDC(hdc);
|
|
|
|
return rc;
|
2013-12-11 01:35:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
2016-08-01 18:31:59 +03:00
|
|
|
if (!test_gdi_GetPixel())
|
2013-12-11 01:35:46 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
fprintf(stderr, "test_gdi_SetPixel()\n");
|
|
|
|
|
2016-08-01 18:31:59 +03:00
|
|
|
if (!test_gdi_SetPixel())
|
2013-12-11 01:35:46 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|