BOOL gdi_Glyph_New(rdpContext* context, rdpGlyph* glyph) { BYTE* data; gdiGlyph* gdi_glyph; gdi_glyph = (gdiGlyph*) glyph; gdi_glyph->hdc = gdi_GetDC(); if (!gdi_glyph->hdc) return FALSE; gdi_glyph->hdc->bytesPerPixel = 1; gdi_glyph->hdc->bitsPerPixel = 1; data = freerdp_glyph_convert(glyph->cx, glyph->cy, glyph->aj); if (!data) { gdi_DeleteDC(gdi_glyph->hdc); return FALSE; } gdi_glyph->bitmap = gdi_CreateBitmap(glyph->cx, glyph->cy, 1, data); if (!gdi_glyph->bitmap) { gdi_DeleteDC(gdi_glyph->hdc); _aligned_free(data); return FALSE; } gdi_glyph->bitmap->bytesPerPixel = 1; gdi_glyph->bitmap->bitsPerPixel = 1; gdi_SelectObject(gdi_glyph->hdc, (HGDIOBJECT) gdi_glyph->bitmap); gdi_glyph->org_bitmap = NULL; return TRUE; }
int test_gdi_SetPixel(void) { HGDI_DC hdc; int width = 128; int height = 64; HGDI_BITMAP hBitmap; if (!(hdc = gdi_GetDC())) { printf("failed to get gdi device context\n"); return -1; } hdc->bytesPerPixel = 4; hdc->bitsPerPixel = 32; 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; }
int test_gdi_CreateCompatibleDC(void) { HGDI_DC hdc; HGDI_DC chdc; if (!(hdc = gdi_GetDC())) { printf("failed to get gdi device context\n"); return -1; } hdc->bytesPerPixel = 2; hdc->bitsPerPixel = 16; hdc->drawMode = GDI_R2_XORPEN; chdc = gdi_CreateCompatibleDC(hdc); if (chdc->bytesPerPixel != hdc->bytesPerPixel) return -1; if (chdc->bitsPerPixel != hdc->bitsPerPixel) return -1; if (chdc->drawMode != hdc->drawMode) return -1; return 0; }
BOOL gdi_init_ex(freerdp* instance, UINT32 format, UINT32 stride, BYTE* buffer, void (*pfree)(void*)) { UINT32 SrcFormat = gdi_get_pixel_format(instance->settings->ColorDepth); rdpGdi* gdi = (rdpGdi*) calloc(1, sizeof(rdpGdi)); rdpContext* context = instance->context; if (!gdi) goto fail; instance->context->gdi = gdi; gdi->log = WLog_Get(TAG); if (!gdi->log) goto fail; gdi->context = instance->context; gdi->width = instance->settings->DesktopWidth; gdi->height = instance->settings->DesktopHeight; gdi->dstFormat = format; /* default internal buffer format */ WLog_Print(gdi->log, WLOG_INFO, "Local framebuffer format %s", GetColorFormatName(gdi->dstFormat)); WLog_Print(gdi->log, WLOG_INFO, "Remote framebuffer format %s", GetColorFormatName(SrcFormat)); if (!(gdi->hdc = gdi_GetDC())) goto fail; gdi->hdc->format = gdi->dstFormat; if (!gdi_init_primary(gdi, stride, gdi->dstFormat, buffer, pfree)) goto fail; if (!(context->cache = cache_new(instance->settings))) goto fail; if (!freerdp_client_codecs_prepare(context->codecs, FREERDP_CODEC_ALL, gdi->width, gdi->height)) goto fail; gdi_register_update_callbacks(instance->update); brush_cache_register_callbacks(instance->update); glyph_cache_register_callbacks(instance->update); bitmap_cache_register_callbacks(instance->update); offscreen_cache_register_callbacks(instance->update); palette_cache_register_callbacks(instance->update); if (!gdi_register_graphics(instance->context->graphics)) goto fail; return TRUE; fail: gdi_free(instance); WLog_ERR(TAG, "failed to initialize gdi"); return FALSE; }
int test_gdi_SetROP2(void) { HGDI_DC hdc; if (!(hdc = gdi_GetDC())) { printf("failed to get gdi device context\n"); return -1; } gdi_SetROP2(hdc, GDI_R2_BLACK); if (hdc->drawMode != GDI_R2_BLACK) return -1; return 0; }
void gdi_Glyph_New(rdpContext* context, rdpGlyph* glyph) { uint8* data; gdiGlyph* gdi_glyph; gdi_glyph = (gdiGlyph*) glyph; gdi_glyph->hdc = gdi_GetDC(); gdi_glyph->hdc->bytesPerPixel = 1; gdi_glyph->hdc->bitsPerPixel = 1; data = freerdp_glyph_convert(glyph->cx, glyph->cy, glyph->aj); gdi_glyph->bitmap = gdi_CreateBitmap(glyph->cx, glyph->cy, 1, data); gdi_glyph->bitmap->bytesPerPixel = 1; gdi_glyph->bitmap->bitsPerPixel = 1; gdi_SelectObject(gdi_glyph->hdc, (HGDIOBJECT) gdi_glyph->bitmap); gdi_glyph->org_bitmap = NULL; }
int test_gdi_CreateCompatibleBitmap(void) { HGDI_DC hdc; int width; int height; HGDI_BITMAP hBitmap; if (!(hdc = gdi_GetDC())) { printf("failed to get gdi device context\n"); return -1; } hdc->bytesPerPixel = 4; hdc->bitsPerPixel = 32; width = 32; height = 16; hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height); if (hBitmap->objectType != GDIOBJECT_BITMAP) return -1; if (hBitmap->bytesPerPixel != hdc->bytesPerPixel) return -1; if (hBitmap->bitsPerPixel != hdc->bitsPerPixel) 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; }
int test_gdi_MoveToEx(void) { HGDI_DC hdc; HGDI_PEN hPen; HGDI_POINT prevPoint; if (!(hdc = gdi_GetDC())) { printf("failed to get gdi device context\n"); return -1; } hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD); 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 test_gdi_GetDC(void) { HGDI_DC hdc; if (!(hdc = gdi_GetDC())) { printf("failed to get gdi device context\n"); return -1; } if (hdc->bytesPerPixel != 4) return -1; if (hdc->bitsPerPixel != 32) return -1; if (hdc->drawMode != GDI_R2_BLACK) return -1; return 0; }
/* Glyph Class */ static BOOL gdi_Glyph_New(rdpContext* context, const rdpGlyph* glyph) { BYTE* data; gdiGlyph* gdi_glyph; if (!context || !glyph) return FALSE; gdi_glyph = (gdiGlyph*) glyph; gdi_glyph->hdc = gdi_GetDC(); if (!gdi_glyph->hdc) return FALSE; gdi_glyph->hdc->format = PIXEL_FORMAT_MONO; data = freerdp_glyph_convert(glyph->cx, glyph->cy, glyph->aj); if (!data) { gdi_DeleteDC(gdi_glyph->hdc); return FALSE; } gdi_glyph->bitmap = gdi_CreateBitmap(glyph->cx, glyph->cy, PIXEL_FORMAT_MONO, data); if (!gdi_glyph->bitmap) { gdi_DeleteDC(gdi_glyph->hdc); _aligned_free(data); return FALSE; } gdi_SelectObject(gdi_glyph->hdc, (HGDIOBJECT) gdi_glyph->bitmap); gdi_glyph->org_bitmap = NULL; return TRUE; }
BOOL wf_post_connect(freerdp* instance) { rdpGdi* gdi; wfInfo* wfi; rdpCache* cache; wfContext* context; WCHAR lpWindowName[64]; rdpSettings* settings; settings = instance->settings; context = (wfContext*) instance->context; cache = instance->context->cache; wfi = context->wfi; wfi->dstBpp = 32; wfi->width = settings->DesktopWidth; wfi->height = settings->DesktopHeight; if (wfi->sw_gdi) { gdi_init(instance, CLRCONV_ALPHA | CLRCONV_INVERT | CLRBUF_32BPP, NULL); gdi = instance->context->gdi; wfi->hdc = gdi->primary->hdc; wfi->primary = wf_image_new(wfi, wfi->width, wfi->height, wfi->dstBpp, gdi->primary_buffer); } else { wf_gdi_register_update_callbacks(instance->update); wfi->srcBpp = instance->settings->ColorDepth; wfi->primary = wf_image_new(wfi, wfi->width, wfi->height, wfi->dstBpp, NULL); wfi->hdc = gdi_GetDC(); wfi->hdc->bitsPerPixel = wfi->dstBpp; wfi->hdc->bytesPerPixel = wfi->dstBpp / 8; wfi->hdc->alpha = wfi->clrconv->alpha; wfi->hdc->invert = wfi->clrconv->invert; wfi->hdc->hwnd = (HGDI_WND) malloc(sizeof(GDI_WND)); wfi->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0); wfi->hdc->hwnd->invalid->null = 1; wfi->hdc->hwnd->count = 32; wfi->hdc->hwnd->cinvalid = (HGDI_RGN) malloc(sizeof(GDI_RGN) * wfi->hdc->hwnd->count); wfi->hdc->hwnd->ninvalid = 0; if (settings->RemoteFxCodec) { wfi->tile = wf_image_new(wfi, 64, 64, 32, NULL); wfi->rfx_context = rfx_context_new(); } if (settings->NSCodec) { wfi->nsc_context = nsc_context_new(); } } if (settings->WindowTitle != NULL) _snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"%S", settings->WindowTitle); else if (settings->ServerPort == 3389) _snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"FreeRDP: %S", settings->ServerHostname); else _snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"FreeRDP: %S:%d", settings->ServerHostname, settings->ServerPort); if (!wfi->hwnd) { wfi->hwnd = CreateWindowEx((DWORD) NULL, wfi->wndClassName, lpWindowName, 0, 0, 0, 0, 0, wfi->hWndParent, NULL, wfi->hInstance, NULL); SetWindowLongPtr(wfi->hwnd, GWLP_USERDATA, (LONG_PTR) wfi); } wf_resize_window(wfi); BitBlt(wfi->primary->hdc, 0, 0, wfi->width, wfi->height, NULL, 0, 0, BLACKNESS); wfi->drawing = wfi->primary; ShowWindow(wfi->hwnd, SW_SHOWNORMAL); UpdateWindow(wfi->hwnd); if (wfi->sw_gdi) { instance->update->BeginPaint = wf_sw_begin_paint; instance->update->EndPaint = wf_sw_end_paint; instance->update->DesktopResize = wf_sw_desktop_resize; } else { instance->update->BeginPaint = wf_hw_begin_paint; instance->update->EndPaint = wf_hw_end_paint; instance->update->DesktopResize = wf_hw_desktop_resize; } pointer_cache_register_callbacks(instance->update); if (wfi->sw_gdi != TRUE) { brush_cache_register_callbacks(instance->update); bitmap_cache_register_callbacks(instance->update); offscreen_cache_register_callbacks(instance->update); } wf_register_graphics(instance->context->graphics); freerdp_channels_post_connect(instance->context->channels, instance); wf_cliprdr_init(wfi, instance->context->channels); return TRUE; }
static BOOL remmina_rdp_post_connect(freerdp* instance) { rfContext* rfi; RemminaProtocolWidget* gp; RemminaPluginRdpUiObject* ui; rdpGdi* gdi; UINT32 flags; rfi = (rfContext*) instance->context; gp = rfi->protocol_widget; rfi->width = rfi->settings->DesktopWidth; rfi->height = rfi->settings->DesktopHeight; rfi->srcBpp = rfi->settings->ColorDepth; if (rfi->settings->RemoteFxCodec == FALSE) rfi->sw_gdi = TRUE; rf_register_graphics(instance->context->graphics); flags = CLRCONV_ALPHA; if (rfi->bpp == 32) { flags |= CLRBUF_32BPP; rfi->cairo_format = CAIRO_FORMAT_ARGB32; } else if (rfi->bpp == 24) { flags |= CLRBUF_24BPP; rfi->cairo_format = CAIRO_FORMAT_RGB24; } else { flags |= CLRBUF_16BPP; rfi->cairo_format = CAIRO_FORMAT_RGB16_565; } gdi_init(instance, flags, NULL); gdi = instance->context->gdi; rfi->primary_buffer = gdi->primary_buffer; rfi->hdc = gdi_GetDC(); rfi->hdc->bitsPerPixel = rfi->bpp; rfi->hdc->bytesPerPixel = rfi->bpp / 8; rfi->hdc->hwnd = (HGDI_WND) malloc(sizeof(GDI_WND)); rfi->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0); rfi->hdc->hwnd->invalid->null = 1; rfi->hdc->hwnd->count = 32; rfi->hdc->hwnd->cinvalid = (HGDI_RGN) malloc(sizeof(GDI_RGN) * rfi->hdc->hwnd->count); rfi->hdc->hwnd->ninvalid = 0; pointer_cache_register_callbacks(instance->update); /* if (rfi->sw_gdi != true) { glyph_cache_register_callbacks(instance->update); brush_cache_register_callbacks(instance->update); bitmap_cache_register_callbacks(instance->update); offscreen_cache_register_callbacks(instance->update); palette_cache_register_callbacks(instance->update); } */ instance->update->BeginPaint = rf_begin_paint; instance->update->EndPaint = rf_end_paint; instance->update->DesktopResize = rf_desktop_resize; freerdp_channels_post_connect(rfi->channels, instance); remmina_plugin_service->protocol_plugin_emit_signal(gp, "connect"); ui = g_new0(RemminaPluginRdpUiObject, 1); ui->type = REMMINA_RDP_UI_CONNECTED; rf_queue_ui(gp, ui); return True; }
int TestGdiLine(int argc, char* argv[]) { int rc = -1; UINT32 x, i; gdiPalette g; const UINT32 RawFormat = PIXEL_FORMAT_RGB8; const UINT32 colorFormats[] = { PIXEL_FORMAT_RGB15, PIXEL_FORMAT_ARGB15, PIXEL_FORMAT_RGB16, PIXEL_FORMAT_RGB24, PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGR15, PIXEL_FORMAT_ABGR15, PIXEL_FORMAT_BGR16, PIXEL_FORMAT_BGR24, PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 }; const UINT32 number_formats = sizeof(colorFormats) / sizeof(colorFormats[0]); for (i = 0; i < number_formats; i++) { HGDI_DC hdc = NULL; HGDI_PEN pen = NULL; HGDI_BITMAP hBmp = NULL; struct ropMap rop_map[] = { {GDI_R2_BLACK, NULL, line_to_R2_BLACK}, {GDI_R2_NOTMERGEPEN, NULL, line_to_R2_NOTMERGEPEN}, {GDI_R2_MASKNOTPEN, NULL, line_to_R2_MASKNOTPEN}, {GDI_R2_NOTCOPYPEN, NULL, line_to_R2_NOTCOPYPEN}, {GDI_R2_MASKPENNOT, NULL, line_to_R2_MASKPENNOT}, {GDI_R2_NOT, NULL, line_to_R2_NOT}, {GDI_R2_XORPEN, NULL, line_to_R2_XORPEN}, {GDI_R2_NOTMASKPEN, NULL, line_to_R2_NOTMASKPEN}, {GDI_R2_MASKPEN, NULL, line_to_R2_MASKPEN}, {GDI_R2_NOTXORPEN, NULL, line_to_R2_NOTXORPEN}, {GDI_R2_NOP, NULL, line_to_R2_NOP}, {GDI_R2_MERGENOTPEN, NULL, line_to_R2_MERGENOTPEN}, {GDI_R2_COPYPEN, NULL, line_to_R2_COPYPEN}, {GDI_R2_MERGEPENNOT, NULL, line_to_R2_MERGEPENNOT}, {GDI_R2_MERGEPEN, NULL, line_to_R2_MERGEPEN}, {GDI_R2_WHITE, NULL, line_to_R2_WHITE} }; const UINT32 map_size = sizeof(rop_map) / sizeof(rop_map[0]); HGDI_BITMAP hBmp_LineTo[LINTETO_NUMBER] = {NULL}; gdiPalette* hPalette = &g; UINT32 penColor; const UINT32 format = colorFormats[i]; g.format = format; for (i = 0; i < 256; i++) g.palette[i] = GetColor(format, i, i, i, 0xFF); rc = -1; if (!(hdc = gdi_GetDC())) { printf("failed to get gdi device context\n"); goto fail; } hdc->format = format; gdi_SetNullClipRgn(hdc); penColor = GetColor(format, 0xFF, 0xFF, 0xFF, 0xFF); if (!(pen = gdi_CreatePen(1, 1, penColor, format, hPalette))) { printf("gdi_CreatePen failed\n"); goto fail; } gdi_SelectObject(hdc, (HGDIOBJECT) pen); hBmp = gdi_CreateCompatibleBitmap(hdc, 16, 16); gdi_SelectObject(hdc, (HGDIOBJECT) hBmp); for (x = 0; x < LINTETO_NUMBER; x++) { hBmp_LineTo[x] = test_convert_to_bitmap(line_to_case[x], RawFormat, 0, 0, 0, format, 0, 0, 0, 16, 16, hPalette); if (!hBmp_LineTo[x]) goto fail; } for (x = 0; x < map_size; x++) { rop_map[x].bmp = test_convert_to_bitmap(rop_map[x].src, RawFormat, 0, 0, 0, format, 0, 0, 0, 16, 16, hPalette); if (!rop_map[x].bmp) goto fail; } if (!test_line(hdc, hPalette, 0, 0, 15, 15, hBmp, hBmp_LineTo[0], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 15, 15, 0, 0, hBmp, hBmp_LineTo[1], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 15, 0, 0, 15, hBmp, hBmp_LineTo[2], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 0, 15, 15, 0, hBmp, hBmp_LineTo[3], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 0, 8, 15, 8, hBmp, hBmp_LineTo[4], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 15, 8, 0, 8, hBmp, hBmp_LineTo[5], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 8, 0, 8, 15, hBmp, hBmp_LineTo[6], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 8, 15, 8, 0, hBmp, hBmp_LineTo[7], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 4, 4, 12, 12, hBmp, hBmp_LineTo[8], 0, 0, 16, 16)) goto fail; if (!test_line(hdc, hPalette, 0, 0, 16, 16, hBmp, hBmp_LineTo[9], 5, 5, 8, 8)) goto fail; if (!test_line(hdc, hPalette, 0, 0, 26, 26, hBmp, hBmp_LineTo[10], 0, 0, 16, 16)) goto fail; for (x = 0; x < map_size; x++) { char name[1024]; _snprintf(name, sizeof(name), "%s [%s]", gdi_rop_to_string(rop_map[x].rop), GetColorFormatName(hdc->format)); /* Test Case 13: (0,0) -> (16,16), R2_NOTMERGEPEN */ if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS, hPalette)) { printf("gdi_BitBlt failed (line #%u)\n", __LINE__); goto fail; } gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, rop_map[x].rop); gdi_LineTo(hdc, 16, 16); if (!test_assert_bitmaps_equal(hBmp, rop_map[x].bmp, name, hPalette)) goto fail; } rc = 0; fail: for (x = 0; x < LINTETO_NUMBER; x++) gdi_DeleteObject((HGDIOBJECT) hBmp_LineTo[x]); for (x = 0; x < map_size; x++) gdi_DeleteObject((HGDIOBJECT) rop_map[x].bmp); gdi_DeleteObject((HGDIOBJECT) pen); gdi_DeleteDC(hdc); if (rc != 0) break; } return rc; }
boolean wf_post_connect(freerdp* instance) { rdpGdi* gdi; wfInfo* wfi; rdpCache* cache; wfContext* context; int width, height; wchar_t win_title[64]; rdpSettings* settings; settings = instance->settings; context = (wfContext*) instance->context; cache = instance->context->cache; wfi = context->wfi; wfi->dstBpp = 32; width = settings->width; height = settings->height; if (wfi->sw_gdi) { gdi_init(instance, CLRCONV_ALPHA | CLRCONV_INVERT | CLRBUF_32BPP, NULL); gdi = instance->context->gdi; wfi->hdc = gdi->primary->hdc; wfi->primary = wf_image_new(wfi, width, height, wfi->dstBpp, gdi->primary_buffer); rfx_context_set_cpu_opt(gdi->rfx_context, wfi_detect_cpu()); } else { wf_gdi_register_update_callbacks(instance->update); wfi->srcBpp = instance->settings->color_depth; wfi->primary = wf_image_new(wfi, width, height, wfi->dstBpp, NULL); wfi->hdc = gdi_GetDC(); wfi->hdc->bitsPerPixel = wfi->dstBpp; wfi->hdc->bytesPerPixel = wfi->dstBpp / 8; wfi->hdc->alpha = wfi->clrconv->alpha; wfi->hdc->invert = wfi->clrconv->invert; wfi->hdc->hwnd = (HGDI_WND) xmalloc(sizeof(GDI_WND)); wfi->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0); wfi->hdc->hwnd->invalid->null = 1; wfi->hdc->hwnd->count = 32; wfi->hdc->hwnd->cinvalid = (HGDI_RGN) xmalloc(sizeof(GDI_RGN) * wfi->hdc->hwnd->count); wfi->hdc->hwnd->ninvalid = 0; wfi->image = wf_bitmap_new(wfi, 64, 64, 32, NULL); wfi->image->_bitmap.data = NULL; if (settings->rfx_codec) { wfi->tile = wf_bitmap_new(wfi, 64, 64, 32, NULL); wfi->rfx_context = rfx_context_new(); rfx_context_set_cpu_opt(wfi->rfx_context, wfi_detect_cpu()); } if (settings->ns_codec) wfi->nsc_context = nsc_context_new(); } if (settings->window_title != NULL) _snwprintf(win_title, sizeof(win_title), L"%S", settings->window_title); else if (settings->port == 3389) _snwprintf(win_title, ARRAY_SIZE(win_title), L"FreeRDP: %S", settings->hostname); else _snwprintf(win_title, ARRAY_SIZE(win_title), L"FreeRDP: %S:%d", settings->hostname, settings->port); if (wfi->hwnd == 0) { wfi->hwnd = CreateWindowEx((DWORD) NULL, g_wnd_class_name, win_title, 0, 0, 0, 0, 0, NULL, NULL, g_hInstance, NULL); SetWindowLongPtr(wfi->hwnd, GWLP_USERDATA, (LONG_PTR) wfi); } if (wfi->fullscreen) { SetWindowLongPtr(wfi->hwnd, GWL_STYLE, WS_POPUP); SetWindowPos(wfi->hwnd, HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED); } else { POINT diff; RECT rc_client, rc_wnd; SetWindowLongPtr(wfi->hwnd, GWL_STYLE, WS_CAPTION | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX); /* Now resize to get full canvas size and room for caption and borders */ SetWindowPos(wfi->hwnd, HWND_TOP, 10, 10, width, height, SWP_FRAMECHANGED); GetClientRect(wfi->hwnd, &rc_client); GetWindowRect(wfi->hwnd, &rc_wnd); diff.x = (rc_wnd.right - rc_wnd.left) - rc_client.right; diff.y = (rc_wnd.bottom - rc_wnd.top) - rc_client.bottom; SetWindowPos(wfi->hwnd, HWND_TOP, -1, -1, width + diff.x, height + diff.y, SWP_NOMOVE | SWP_FRAMECHANGED); } BitBlt(wfi->primary->hdc, 0, 0, width, height, NULL, 0, 0, BLACKNESS); wfi->drawing = wfi->primary; ShowWindow(wfi->hwnd, SW_SHOWNORMAL); UpdateWindow(wfi->hwnd); if (wfi->sw_gdi) { instance->update->BeginPaint = wf_sw_begin_paint; instance->update->EndPaint = wf_sw_end_paint; } else { instance->update->BeginPaint = wf_hw_begin_paint; instance->update->EndPaint = wf_hw_end_paint; } pointer_cache_register_callbacks(instance->update); if (wfi->sw_gdi != true) { brush_cache_register_callbacks(instance->update); bitmap_cache_register_callbacks(instance->update); offscreen_cache_register_callbacks(instance->update); } wf_register_graphics(instance->context->graphics); freerdp_channels_post_connect(instance->context->channels, instance); return true; }
int test_gdi_ClipCoords(void) { BOOL draw; HGDI_DC hdc; HGDI_RGN rgn1; HGDI_RGN rgn2; HGDI_BITMAP bmp; if (!(hdc = gdi_GetDC())) { printf("failed to get gdi device context\n"); return -1; } hdc->bytesPerPixel = 4; hdc->bitsPerPixel = 32; bmp = gdi_CreateBitmapEx(1024, 768, 4, NULL, NULL); gdi_SelectObject(hdc, (HGDIOBJECT) bmp); gdi_SetNullClipRgn(hdc); rgn1 = gdi_CreateRectRgn(0, 0, 0, 0); rgn2 = gdi_CreateRectRgn(0, 0, 0, 0); rgn1->null = 1; rgn2->null = 1; /* null clipping region */ gdi_SetNullClipRgn(hdc); gdi_SetRgn(rgn1, 20, 20, 100, 100); gdi_SetRgn(rgn2, 20, 20, 100, 100); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); if (!gdi_EqualRgn(rgn1, rgn2)) return -1; /* region all inside clipping region */ gdi_SetClipRgn(hdc, 0, 0, 1024, 768); gdi_SetRgn(rgn1, 20, 20, 100, 100); gdi_SetRgn(rgn2, 20, 20, 100, 100); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); if (!gdi_EqualRgn(rgn1, rgn2)) return -1; /* region all outside clipping region, on the left */ gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetRgn(rgn1, 20, 20, 100, 100); gdi_SetRgn(rgn2, 0, 0, 0, 0); draw = gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); if (draw) return -1; /* region all outside clipping region, on the right */ gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetRgn(rgn1, 420, 420, 100, 100); gdi_SetRgn(rgn2, 0, 0, 0, 0); draw = gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); if (draw) return -1; /* region all outside clipping region, on top */ gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetRgn(rgn1, 300, 20, 100, 100); gdi_SetRgn(rgn2, 0, 0, 0, 0); draw = gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); if (draw) return -1; /* region all outside clipping region, at the bottom */ gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetRgn(rgn1, 300, 420, 100, 100); gdi_SetRgn(rgn2, 0, 0, 0, 0); draw = gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); if (draw) return -1; /* left outside, right = clip, top = clip, bottom = clip */ gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetRgn(rgn1, 100, 300, 300, 100); gdi_SetRgn(rgn2, 300, 300, 100, 100); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); if (!gdi_EqualRgn(rgn1, rgn2)) return -1; /* left outside, right inside, top = clip, bottom = clip */ gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetRgn(rgn1, 100, 300, 250, 100); gdi_SetRgn(rgn2, 300, 300, 50, 100); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); if (!gdi_EqualRgn(rgn1, rgn2)) return -1; /* left = clip, right outside, top = clip, bottom = clip */ gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetRgn(rgn1, 300, 300, 300, 100); gdi_SetRgn(rgn2, 300, 300, 100, 100); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); if (!gdi_EqualRgn(rgn1, rgn2)) return -1; /* left inside, right outside, top = clip, bottom = clip */ gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetRgn(rgn1, 350, 300, 200, 100); gdi_SetRgn(rgn2, 350, 300, 50, 100); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); if (!gdi_EqualRgn(rgn1, rgn2)) return -1; /* top outside, bottom = clip, left = clip, right = clip */ gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetRgn(rgn1, 300, 100, 300, 300); gdi_SetRgn(rgn2, 300, 300, 100, 100); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); if (!gdi_EqualRgn(rgn1, rgn2)) return -1; /* top = clip, bottom outside, left = clip, right = clip */ gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetRgn(rgn1, 300, 300, 100, 200); gdi_SetRgn(rgn2, 300, 300, 100, 100); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); if (!gdi_EqualRgn(rgn1, rgn2)) return -1; /* top = clip, bottom = clip, top = clip, bottom = clip */ gdi_SetClipRgn(hdc, 300, 300, 100, 100); gdi_SetRgn(rgn1, 300, 300, 100, 100); gdi_SetRgn(rgn2, 300, 300, 100, 100); gdi_ClipCoords(hdc, &(rgn1->x), &(rgn1->y), &(rgn1->w), &(rgn1->h), NULL, NULL); if (!gdi_EqualRgn(rgn1, rgn2)) return -1; return 0; }
int test_gdi_InvalidateRegion(void) { HGDI_DC hdc; HGDI_RGN rgn1; HGDI_RGN rgn2; HGDI_RGN invalid; HGDI_BITMAP bmp; if (!(hdc = gdi_GetDC())) { printf("failed to get gdi device context\n"); return -1; } hdc->bytesPerPixel = 4; hdc->bitsPerPixel = 32; bmp = gdi_CreateBitmapEx(1024, 768, 4, NULL, NULL); gdi_SelectObject(hdc, (HGDIOBJECT) bmp); gdi_SetNullClipRgn(hdc); hdc->hwnd = (HGDI_WND) calloc(1, sizeof(GDI_WND)); hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0); hdc->hwnd->invalid->null = 1; invalid = hdc->hwnd->invalid; hdc->hwnd->count = 16; hdc->hwnd->cinvalid = (HGDI_RGN) calloc(hdc->hwnd->count, sizeof(GDI_RGN)); rgn1 = gdi_CreateRectRgn(0, 0, 0, 0); rgn2 = gdi_CreateRectRgn(0, 0, 0, 0); rgn1->null = 1; rgn2->null = 1; /* no previous invalid region */ invalid->null = 1; gdi_SetRgn(rgn1, 300, 300, 100, 100); gdi_SetRgn(rgn2, 300, 300, 100, 100); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; /* region same as invalid region */ gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(rgn1, 300, 300, 100, 100); gdi_SetRgn(rgn2, 300, 300, 100, 100); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; /* left outside */ gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(rgn1, 100, 300, 300, 100); gdi_SetRgn(rgn2, 100, 300, 300, 100); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; /* right outside */ gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(rgn1, 300, 300, 300, 100); gdi_SetRgn(rgn2, 300, 300, 300, 100); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; /* top outside */ gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(rgn1, 300, 100, 100, 300); gdi_SetRgn(rgn2, 300, 100, 100, 300); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; /* bottom outside */ gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(rgn1, 300, 300, 100, 300); gdi_SetRgn(rgn2, 300, 300, 100, 300); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; /* left outside, right outside */ gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(rgn1, 100, 300, 600, 300); gdi_SetRgn(rgn2, 100, 300, 600, 300); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; /* top outside, bottom outside */ gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(rgn1, 300, 100, 100, 500); gdi_SetRgn(rgn2, 300, 100, 100, 500); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; /* all outside, left */ gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(rgn1, 100, 300, 100, 100); gdi_SetRgn(rgn2, 100, 300, 300, 100); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; /* all outside, right */ gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(rgn1, 700, 300, 100, 100); gdi_SetRgn(rgn2, 300, 300, 500, 100); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; /* all outside, top */ gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(rgn1, 300, 100, 100, 100); gdi_SetRgn(rgn2, 300, 100, 100, 300); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; /* all outside, bottom */ gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(rgn1, 300, 500, 100, 100); gdi_SetRgn(rgn2, 300, 300, 100, 300); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; /* all outside */ gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(rgn1, 100, 100, 600, 600); gdi_SetRgn(rgn2, 100, 100, 600, 600); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; /* everything */ gdi_SetRgn(invalid, 300, 300, 100, 100); gdi_SetRgn(rgn1, 0, 0, 1024, 768); gdi_SetRgn(rgn2, 0, 0, 1024, 768); gdi_InvalidateRegion(hdc, rgn1->x, rgn1->y, rgn1->w, rgn1->h); if (!gdi_EqualRgn(invalid, rgn2)) return -1; return 0; }
int TestGdiLine(int argc, char* argv[]) { HGDI_DC hdc; HGDI_PEN pen; BYTE* data; HGDI_BITMAP hBmp; HGDI_BITMAP hBmp_LineTo_1; HGDI_BITMAP hBmp_LineTo_2; HGDI_BITMAP hBmp_LineTo_3; HGDI_BITMAP hBmp_LineTo_4; HGDI_BITMAP hBmp_LineTo_5; HGDI_BITMAP hBmp_LineTo_6; HGDI_BITMAP hBmp_LineTo_7; HGDI_BITMAP hBmp_LineTo_8; HGDI_BITMAP hBmp_LineTo_9; HGDI_BITMAP hBmp_LineTo_10; HGDI_BITMAP hBmp_LineTo_11; HGDI_BITMAP hBmp_LineTo_R2_BLACK; HGDI_BITMAP hBmp_LineTo_R2_NOTMERGEPEN; HGDI_BITMAP hBmp_LineTo_R2_MASKNOTPEN; HGDI_BITMAP hBmp_LineTo_R2_NOTCOPYPEN; HGDI_BITMAP hBmp_LineTo_R2_MASKPENNOT; HGDI_BITMAP hBmp_LineTo_R2_NOT; HGDI_BITMAP hBmp_LineTo_R2_XORPEN; HGDI_BITMAP hBmp_LineTo_R2_NOTMASKPEN; HGDI_BITMAP hBmp_LineTo_R2_MASKPEN; HGDI_BITMAP hBmp_LineTo_R2_NOTXORPEN; HGDI_BITMAP hBmp_LineTo_R2_NOP; HGDI_BITMAP hBmp_LineTo_R2_MERGENOTPEN; HGDI_BITMAP hBmp_LineTo_R2_COPYPEN; HGDI_BITMAP hBmp_LineTo_R2_MERGEPENNOT; HGDI_BITMAP hBmp_LineTo_R2_MERGEPEN; HGDI_BITMAP hBmp_LineTo_R2_WHITE; rdpPalette* hPalette; HCLRCONV clrconv; int bitsPerPixel = 8; int bytesPerPixel = 1; hdc = gdi_GetDC(); hdc->bitsPerPixel = bitsPerPixel; hdc->bytesPerPixel = bytesPerPixel; gdi_SetNullClipRgn(hdc); pen = gdi_CreatePen(1, 1, 0); gdi_SelectObject(hdc, (HGDIOBJECT) pen); hBmp = gdi_CreateCompatibleBitmap(hdc, 16, 16); gdi_SelectObject(hdc, (HGDIOBJECT) hBmp); hPalette = (rdpPalette*) gdi_GetSystemPalette(); clrconv = (HCLRCONV) malloc(sizeof(CLRCONV)); clrconv->alpha = 1; clrconv->invert = 0; clrconv->palette = hPalette; data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_1, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_1 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_2, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_2 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_3, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_3 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_4, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_4 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_5, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_5, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_6, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_6 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_7, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_7 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_8, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_8 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_9, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_9 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_10, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_10 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_11, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_11 = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_BLACK, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_BLACK = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTMERGEPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_NOTMERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKNOTPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_MASKNOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTCOPYPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_NOTCOPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKPENNOT, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_MASKPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOT, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_NOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_XORPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_XORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTMASKPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_NOTMASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_MASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTXORPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_NOTXORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOP, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_NOP = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGENOTPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_MERGENOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_COPYPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_COPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGEPENNOT, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_MERGEPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGEPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_MERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data); data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_WHITE, NULL, 16, 16, 8, bitsPerPixel, clrconv); hBmp_LineTo_R2_WHITE = gdi_CreateBitmap(16, 16, bitsPerPixel, data); /* Test Case 1: (0,0) -> (15, 15) */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_LineTo(hdc, 15, 15); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_1, "Case 1") < 0) return -1; /* Test Case 2: (15,15) -> (0,0) */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_MoveToEx(hdc, 15, 15, NULL); gdi_LineTo(hdc, 0, 0); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_2, "Case 2") < 0) return -1; /* Test Case 3: (15,0) -> (0,15) */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_MoveToEx(hdc, 15, 0, NULL); gdi_LineTo(hdc, 0, 15); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_3, "Case 3") < 0) return -1; /* Test Case 4: (0,15) -> (15,0) */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_MoveToEx(hdc, 0, 15, NULL); gdi_LineTo(hdc, 15, 0); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_4, "Case 4") < 0) return -1; /* Test Case 5: (0,8) -> (15,8) */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_MoveToEx(hdc, 0, 8, NULL); gdi_LineTo(hdc, 15, 8); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_5, "Case 5") < 0) return -1; /* Test Case 6: (15,8) -> (0,8) */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_MoveToEx(hdc, 15, 8, NULL); gdi_LineTo(hdc, 0, 8); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_6, "Case 6") < 0) return -1; /* Test Case 7: (8,0) -> (8,15) */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_MoveToEx(hdc, 8, 0, NULL); gdi_LineTo(hdc, 8, 15); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_7, "Case 7") < 0) return -1; /* Test Case 8: (8,15) -> (8,0) */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_MoveToEx(hdc, 8, 15, NULL); gdi_LineTo(hdc, 8, 0); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_8, "Case 8") < 0) return -1; /* Test Case 9: (4,4) -> (12,12) */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_MoveToEx(hdc, 4, 4, NULL); gdi_LineTo(hdc, 12, 12); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_9, "Case 9") < 0) return -1; /* Test Case 10: (12,12) -> (4,4) */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_MoveToEx(hdc, 12, 12, NULL); gdi_LineTo(hdc, 4, 4); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_10, "Case 10") < 0) return -1; /* Test Case 11: (0,0) -> (+10,+10) */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_LineTo(hdc, 16 + 10, 16 + 10); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_11, "Case 11") < 0) return -1; /* Test Case 12: (0,0) -> (16,16), R2_BLACK */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_BLACK); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_BLACK, "Case 12") < 0) return -1; /* Test Case 13: (0,0) -> (16,16), R2_NOTMERGEPEN */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_NOTMERGEPEN); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_NOTMERGEPEN, "Case 13") < 0) return -1; /* Test Case 14: (0,0) -> (16,16), R2_MASKNOTPEN */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_MASKNOTPEN); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_MASKNOTPEN, "Case 14") < 0) return -1; /* Test Case 15: (0,0) -> (16,16), R2_NOTCOPYPEN */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_NOTCOPYPEN); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_NOTCOPYPEN, "Case 15") < 0) return -1; /* Test Case 16: (0,0) -> (16,16), R2_MASKPENNOT */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_MASKPENNOT); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_MASKPENNOT, "Case 16") < 0) return -1; /* Test Case 17: (0,0) -> (16,16), R2_NOT */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_NOT); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_NOT, "Case 17") < 0) return -1; /* Test Case 18: (0,0) -> (16,16), R2_XORPEN */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_XORPEN); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_XORPEN, "Case 18") < 0) return -1; /* Test Case 19: (0,0) -> (16,16), R2_NOTMASKPEN */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_NOTMASKPEN); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_NOTMASKPEN, "Case 19") < 0) return -1; /* Test Case 20: (0,0) -> (16,16), R2_MASKPEN */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_MASKPEN); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_MASKPEN, "Case 20") < 0) return -1; /* Test Case 21: (0,0) -> (16,16), R2_NOTXORPEN */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_NOTXORPEN); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_NOTXORPEN, "Case 21") < 0) return -1; /* Test Case 22: (0,0) -> (16,16), R2_NOP */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_NOP); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_NOP, "Case 22") < 0) return -1; /* Test Case 23: (0,0) -> (16,16), R2_MERGENOTPEN */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_MERGENOTPEN); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_MERGENOTPEN, "Case 23") < 0) return -1; /* Test Case 24: (0,0) -> (16,16), R2_COPYPEN */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_COPYPEN); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_COPYPEN, "Case 24") < 0) return -1; /* Test Case 25: (0,0) -> (16,16), R2_MERGEPENNOT */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_MERGEPENNOT); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_MERGEPENNOT, "Case 25") < 0) return -1; /* Test Case 26: (0,0) -> (16,16), R2_MERGEPEN */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_MERGEPEN); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_MERGEPEN, "Case 26") < 0) return -1; /* Test Case 27: (0,0) -> (16,16), R2_WHITE */ gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS); gdi_SetClipRgn(hdc, 0, 0, 16, 16); gdi_MoveToEx(hdc, 0, 0, NULL); gdi_SetROP2(hdc, GDI_R2_WHITE); gdi_LineTo(hdc, 16, 16); if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_WHITE, "Case 27") < 0) return -1; return 0; }
int TestGdiEllipse(int argc, char* argv[]) { int rc = -1; UINT32 i, j; const UINT32 RawFormat = PIXEL_FORMAT_RGB8; const UINT32 colorFormats[] = { PIXEL_FORMAT_RGB15, PIXEL_FORMAT_ARGB15, PIXEL_FORMAT_RGB16, PIXEL_FORMAT_RGB24, PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGR15, PIXEL_FORMAT_ABGR15, PIXEL_FORMAT_BGR16, PIXEL_FORMAT_BGR24, PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 }; const UINT32 number_formats = sizeof(colorFormats) / sizeof(colorFormats[0]); gdiPalette g; for (i = 0; i < number_formats; i++) { HGDI_DC hdc = NULL; HGDI_PEN pen = NULL; HGDI_BITMAP hBmp = NULL; HGDI_BITMAP hBmp_Ellipse_1 = NULL; HGDI_BITMAP hBmp_Ellipse_2 = NULL; HGDI_BITMAP hBmp_Ellipse_3 = NULL; const UINT32 format = colorFormats[i]; gdiPalette* hPalette = &g; g.format = format; for (j = 0; j < 256; j++) g.palette[i] = GetColor(format, j, j, j, 0xFF); rc = -1; if (!(hdc = gdi_GetDC())) { printf("failed to get gdi device context\n"); goto fail; } hdc->format = format; gdi_SetNullClipRgn(hdc); if (!(pen = gdi_CreatePen(1, 1, 0, format, hPalette))) { printf("gdi_CreatePen failed\n"); goto fail; } gdi_SelectObject(hdc, (HGDIOBJECT) pen); hBmp = gdi_CreateCompatibleBitmap(hdc, 16, 16); gdi_SelectObject(hdc, (HGDIOBJECT) hBmp); hBmp_Ellipse_1 = test_convert_to_bitmap(ellipse_case_1, RawFormat, 0, 0, 0, format, 0, 0, 0, 16, 16, hPalette); if (!hBmp_Ellipse_1) goto fail; hBmp_Ellipse_2 = test_convert_to_bitmap(ellipse_case_2, RawFormat, 0, 0, 0, format, 0, 0, 0, 16, 16, hPalette); if (!hBmp_Ellipse_2) goto fail; hBmp_Ellipse_3 = test_convert_to_bitmap(ellipse_case_3, RawFormat, 0, 0, 0, format, 0, 0, 0, 16, 16, hPalette); if (!hBmp_Ellipse_3) goto fail; /* Test Case 1: (0,0) -> (16, 16) */ if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS, hPalette)) { printf("gdi_BitBlt failed (line #%u)\n", __LINE__); goto fail; } if (!gdi_Ellipse(hdc, 0, 0, 15, 15)) goto fail; rc = 0; fail: gdi_DeleteObject((HGDIOBJECT) hBmp_Ellipse_1); gdi_DeleteObject((HGDIOBJECT) hBmp_Ellipse_2); gdi_DeleteObject((HGDIOBJECT) hBmp_Ellipse_3); gdi_DeleteObject((HGDIOBJECT) hBmp); gdi_DeleteObject((HGDIOBJECT) pen); gdi_DeleteDC(hdc); if (rc != 0) break; } return rc; }
BOOL wf_post_connect(freerdp* instance) { rdpGdi* gdi; DWORD dwStyle; rdpCache* cache; wfContext* wfc; rdpContext* context; WCHAR lpWindowName[64]; rdpSettings* settings; EmbedWindowEventArgs e; settings = instance->settings; context = instance->context; wfc = (wfContext*) instance->context; cache = instance->context->cache; wfc->dstBpp = 32; wfc->width = settings->DesktopWidth; wfc->height = settings->DesktopHeight; if (settings->SoftwareGdi) { wfc->primary = wf_image_new(wfc, wfc->width, wfc->height, wfc->dstBpp, NULL); if (!gdi_init(instance, CLRCONV_ALPHA | CLRBUF_32BPP, wfc->primary->pdata)) return FALSE; gdi = instance->context->gdi; wfc->hdc = gdi->primary->hdc; } else { wf_gdi_register_update_callbacks(instance->update); wfc->srcBpp = instance->settings->ColorDepth; wfc->primary = wf_image_new(wfc, wfc->width, wfc->height, wfc->dstBpp, NULL); if (!(wfc->hdc = gdi_GetDC())) return FALSE; wfc->hdc->bitsPerPixel = wfc->dstBpp; wfc->hdc->bytesPerPixel = wfc->dstBpp / 8; wfc->hdc->alpha = wfc->clrconv->alpha; wfc->hdc->invert = wfc->clrconv->invert; wfc->hdc->hwnd = (HGDI_WND) malloc(sizeof(GDI_WND)); wfc->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0); wfc->hdc->hwnd->invalid->null = 1; wfc->hdc->hwnd->count = 32; wfc->hdc->hwnd->cinvalid = (HGDI_RGN) malloc(sizeof(GDI_RGN) * wfc->hdc->hwnd->count); wfc->hdc->hwnd->ninvalid = 0; if (settings->RemoteFxCodec) { wfc->tile = wf_image_new(wfc, 64, 64, 32, NULL); } } if (settings->WindowTitle != NULL) _snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"%S", settings->WindowTitle); else if (settings->ServerPort == 3389) _snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"FreeRDP: %S", settings->ServerHostname); else _snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"FreeRDP: %S:%d", settings->ServerHostname, settings->ServerPort); if (settings->EmbeddedWindow) settings->Decorations = FALSE; if (wfc->fullscreen) dwStyle = WS_POPUP; else if (!settings->Decorations) dwStyle = WS_CHILD | WS_BORDER; else dwStyle = WS_CAPTION | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_SIZEBOX | WS_MAXIMIZEBOX; if (!wfc->hwnd) { wfc->hwnd = CreateWindowEx((DWORD) NULL, wfc->wndClassName, lpWindowName, dwStyle, 0, 0, 0, 0, wfc->hWndParent, NULL, wfc->hInstance, NULL); SetWindowLongPtr(wfc->hwnd, GWLP_USERDATA, (LONG_PTR) wfc); } wf_resize_window(wfc); wf_add_system_menu(wfc); BitBlt(wfc->primary->hdc, 0, 0, wfc->width, wfc->height, NULL, 0, 0, BLACKNESS); wfc->drawing = wfc->primary; EventArgsInit(&e, "wfreerdp"); e.embed = FALSE; e.handle = (void*) wfc->hwnd; PubSub_OnEmbedWindow(context->pubSub, context, &e); ShowWindow(wfc->hwnd, SW_SHOWNORMAL); UpdateWindow(wfc->hwnd); if (settings->SoftwareGdi) { instance->update->BeginPaint = (pBeginPaint) wf_sw_begin_paint; instance->update->EndPaint = (pEndPaint) wf_sw_end_paint; instance->update->DesktopResize = (pDesktopResize) wf_sw_desktop_resize; } else { instance->update->BeginPaint = (pBeginPaint) wf_hw_begin_paint; instance->update->EndPaint = (pEndPaint) wf_hw_end_paint; instance->update->DesktopResize = (pDesktopResize) wf_hw_desktop_resize; } pointer_cache_register_callbacks(instance->update); wf_register_pointer(context->graphics); if (!settings->SoftwareGdi) { brush_cache_register_callbacks(instance->update); bitmap_cache_register_callbacks(instance->update); offscreen_cache_register_callbacks(instance->update); wf_register_graphics(context->graphics); instance->update->BitmapUpdate = wf_gdi_bitmap_update; } freerdp_channels_post_connect(context->channels, instance); if (wfc->fullscreen) floatbar_window_create(wfc); return TRUE; }
int gdi_init(freerdp* instance, UINT32 flags, BYTE* buffer) { BOOL rgb555; rdpGdi* gdi; rdpCache* cache; gdi = (rdpGdi*) calloc(1, sizeof(rdpGdi)); if (!gdi) return -1; instance->context->gdi = gdi; gdi->context = instance->context; cache = instance->context->cache; gdi->codecs = instance->context->codecs; gdi->width = instance->settings->DesktopWidth; gdi->height = instance->settings->DesktopHeight; gdi->srcBpp = instance->settings->ColorDepth; gdi->primary_buffer = buffer; /* default internal buffer format */ gdi->dstBpp = 32; gdi->bytesPerPixel = 4; gdi->format = PIXEL_FORMAT_XRGB32; if (flags & CLRCONV_INVERT) gdi->invert = TRUE; rgb555 = (flags & CLRCONV_RGB555) ? TRUE : FALSE; if (gdi->srcBpp > 16) { if (flags & CLRBUF_32BPP) { gdi->dstBpp = 32; gdi->bytesPerPixel = 4; } else if (flags & CLRBUF_16BPP) { gdi->dstBpp = rgb555 ? 15 : 16; gdi->bytesPerPixel = 2; } } else { if (flags & CLRBUF_16BPP) { gdi->dstBpp = rgb555 ? 15 : 16; gdi->bytesPerPixel = 2; } else if (flags & CLRBUF_32BPP) { gdi->dstBpp = 32; gdi->bytesPerPixel = 4; } } if (!gdi->invert) { if (gdi->bytesPerPixel == 4) gdi->format = PIXEL_FORMAT_XRGB32; else if ((gdi->bytesPerPixel == 2) && (gdi->dstBpp == 16)) gdi->format = PIXEL_FORMAT_RGB565; else if ((gdi->bytesPerPixel == 2) && (gdi->dstBpp == 15)) gdi->format = PIXEL_FORMAT_RGB555; } else { if (gdi->bytesPerPixel == 4) gdi->format = PIXEL_FORMAT_XBGR32; else if ((gdi->bytesPerPixel == 2) && (gdi->dstBpp == 16)) gdi->format = PIXEL_FORMAT_BGR565; else if ((gdi->bytesPerPixel == 2) && (gdi->dstBpp == 15)) gdi->format = PIXEL_FORMAT_BGR555; } gdi->hdc = gdi_GetDC(); gdi->hdc->bitsPerPixel = gdi->dstBpp; gdi->hdc->bytesPerPixel = gdi->bytesPerPixel; gdi->hdc->alpha = (flags & CLRCONV_ALPHA) ? TRUE : FALSE; gdi->hdc->invert = (flags & CLRCONV_INVERT) ? TRUE : FALSE; gdi->hdc->rgb555 = (flags & CLRCONV_RGB555) ? TRUE : FALSE; gdi_init_primary(gdi); gdi->tile = gdi_bitmap_new_ex(gdi, 64, 64, 32, NULL); gdi->image = gdi_bitmap_new_ex(gdi, 64, 64, 32, NULL); if (!cache) { cache = cache_new(instance->settings); instance->context->cache = cache; } gdi_register_update_callbacks(instance->update); brush_cache_register_callbacks(instance->update); glyph_cache_register_callbacks(instance->update); bitmap_cache_register_callbacks(instance->update); offscreen_cache_register_callbacks(instance->update); palette_cache_register_callbacks(instance->update); gdi_register_graphics(instance->context->graphics); instance->update->BitmapUpdate = gdi_bitmap_update; return 0; }
int test_gdi_FillRect(void) { int rc = -1; HGDI_DC hdc = NULL; HGDI_RECT hRect = NULL; HGDI_BRUSH hBrush = NULL; HGDI_BITMAP hBitmap = NULL; UINT32 color; UINT32 pixel; UINT32 rawPixel; UINT32 x, y; UINT32 badPixels; UINT32 goodPixels; UINT32 width = 200; UINT32 height = 300; UINT32 left = 20; UINT32 top = 40; UINT32 right = 60; UINT32 bottom = 80; if (!(hdc = gdi_GetDC())) { printf("failed to get gdi device context\n"); goto fail; } hdc->format = PIXEL_FORMAT_XRGB32; if (!(hRect = gdi_CreateRect(left, top, right, bottom))) { printf("gdi_CreateRect failed\n"); goto fail; } hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height); ZeroMemory(hBitmap->data, width * height * GetBytesPerPixel(hdc->format)); gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap); color = FreeRDPGetColor(PIXEL_FORMAT_ARGB32, 0xAA, 0xBB, 0xCC, 0xFF); hBrush = gdi_CreateSolidBrush(color); gdi_FillRect(hdc, hRect, hBrush); badPixels = 0; goodPixels = 0; for (x = 0; x < width; x++) { for (y = 0; y < height; y++) { rawPixel = gdi_GetPixel(hdc, x, y); pixel = FreeRDPConvertColor(rawPixel, hdc->format, PIXEL_FORMAT_ARGB32, NULL); if (gdi_PtInRect(hRect, x, y)) { if (pixel == color) { goodPixels++; } else { printf("actual:%08"PRIX32" expected:%08"PRIX32"\n", gdi_GetPixel(hdc, x, y), color); badPixels++; } } else { if (pixel == color) { badPixels++; } else { goodPixels++; } } } } if (goodPixels != width * height) goto fail; if (badPixels != 0) goto fail; rc = 0; fail: gdi_DeleteObject((HGDIOBJECT) hBrush); gdi_DeleteObject((HGDIOBJECT) hBitmap); gdi_DeleteObject((HGDIOBJECT)hRect); gdi_DeleteDC(hdc); return rc; }