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; }
void gdi_init_primary(rdpGdi* gdi) { gdi->primary = (gdiBitmap*) malloc(sizeof(gdiBitmap)); if (!gdi->primary) return; gdi->primary->hdc = gdi_CreateCompatibleDC(gdi->hdc); if (!gdi->primary_buffer) gdi->primary->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, gdi->width, gdi->height); else gdi->primary->bitmap = gdi_CreateBitmap(gdi->width, gdi->height, gdi->dstBpp, gdi->primary_buffer); gdi_SelectObject(gdi->primary->hdc, (HGDIOBJECT) gdi->primary->bitmap); gdi->primary->org_bitmap = NULL; gdi->primary_buffer = gdi->primary->bitmap->data; if (!gdi->drawing) gdi->drawing = gdi->primary; gdi->primary->hdc->hwnd = (HGDI_WND) malloc(sizeof(GDI_WND)); gdi->primary->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0); gdi->primary->hdc->hwnd->invalid->null = 1; gdi->primary->hdc->hwnd->count = 32; gdi->primary->hdc->hwnd->cinvalid = (HGDI_RGN) malloc(sizeof(GDI_RGN) * gdi->primary->hdc->hwnd->count); gdi->primary->hdc->hwnd->ninvalid = 0; }
gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, BYTE* data) { gdiBitmap* bitmap; bitmap = (gdiBitmap*) calloc(1, sizeof(gdiBitmap)); if (!bitmap) goto fail_bitmap; if (!(bitmap->hdc = gdi_CreateCompatibleDC(gdi->hdc))) goto fail_hdc; WLog_Print(gdi->log, WLOG_DEBUG, "gdi_bitmap_new: width:%d height:%d bpp:%d", width, height, bpp); if (!data) bitmap->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, width, height); else bitmap->bitmap = gdi_create_bitmap(gdi, width, height, bpp, data); if (!bitmap->bitmap) goto fail_bitmap_bitmap; gdi_SelectObject(bitmap->hdc, (HGDIOBJECT) bitmap->bitmap); bitmap->org_bitmap = NULL; return bitmap; fail_bitmap_bitmap: gdi_DeleteDC(bitmap->hdc); fail_hdc: free(bitmap); fail_bitmap: return NULL; }
static BOOL gdi_Bitmap_New(rdpContext* context, rdpBitmap* bitmap) { gdiBitmap* gdi_bitmap; rdpGdi* gdi = context->gdi; gdi_bitmap = (gdiBitmap*) bitmap; gdi_bitmap->hdc = gdi_CreateCompatibleDC(gdi->hdc); if (!gdi_bitmap->hdc) return FALSE; if (!bitmap->data) gdi_bitmap->bitmap = gdi_CreateCompatibleBitmap( gdi->hdc, bitmap->width, bitmap->height); else { UINT32 format = bitmap->format; gdi_bitmap->bitmap = gdi_create_bitmap(gdi, bitmap->width, bitmap->height, format, bitmap->data); } if (!gdi_bitmap->bitmap) { gdi_DeleteDC(gdi_bitmap->hdc); return FALSE; } gdi_bitmap->hdc->format = gdi_bitmap->bitmap->format; gdi_SelectObject(gdi_bitmap->hdc, (HGDIOBJECT) gdi_bitmap->bitmap); gdi_bitmap->org_bitmap = NULL; return TRUE; }
BOOL gdi_init_primary(rdpGdi* gdi) { gdi->primary = (gdiBitmap*) calloc(1, sizeof(gdiBitmap)); if (!gdi->primary) goto fail_primary; if (!(gdi->primary->hdc = gdi_CreateCompatibleDC(gdi->hdc))) goto fail_hdc; if (!gdi->primary_buffer) gdi->primary->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, gdi->width, gdi->height); else gdi->primary->bitmap = gdi_CreateBitmapEx(gdi->width, gdi->height, gdi->dstBpp, gdi->primary_buffer, NULL); if (!gdi->primary->bitmap) goto fail_bitmap; gdi_SelectObject(gdi->primary->hdc, (HGDIOBJECT) gdi->primary->bitmap); gdi->primary->org_bitmap = NULL; gdi->primary_buffer = gdi->primary->bitmap->data; if (!(gdi->primary->hdc->hwnd = (HGDI_WND) calloc(1, sizeof(GDI_WND)))) goto fail_hwnd; if (!(gdi->primary->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0))) goto fail_hwnd; gdi->primary->hdc->hwnd->invalid->null = 1; gdi->primary->hdc->hwnd->count = 32; if (!(gdi->primary->hdc->hwnd->cinvalid = (HGDI_RGN) calloc(gdi->primary->hdc->hwnd->count, sizeof(GDI_RGN)))) goto fail_hwnd; gdi->primary->hdc->hwnd->ninvalid = 0; if (!gdi->drawing) gdi->drawing = gdi->primary; return TRUE; fail_hwnd: gdi_DeleteObject((HGDIOBJECT) gdi->primary->bitmap); fail_bitmap: gdi_DeleteDC(gdi->primary->hdc); fail_hdc: free(gdi->primary); gdi->primary = NULL; fail_primary: return FALSE; }
void gdi_Bitmap_New(rdpContext* context, rdpBitmap* bitmap) { gdiBitmap* gdi_bitmap; rdpGdi* gdi = context->gdi; gdi_bitmap = (gdiBitmap*) bitmap; gdi_bitmap->hdc = gdi_CreateCompatibleDC(gdi->hdc); if (bitmap->data == NULL) gdi_bitmap->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, bitmap->width, bitmap->height); else gdi_bitmap->bitmap = gdi_create_bitmap(gdi, bitmap->width, bitmap->height, gdi->dstBpp, bitmap->data); gdi_SelectObject(gdi_bitmap->hdc, (HGDIOBJECT) gdi_bitmap->bitmap); gdi_bitmap->org_bitmap = NULL; }
gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, BYTE* data) { gdiBitmap* bitmap; bitmap = (gdiBitmap*) malloc(sizeof(gdiBitmap)); if (!bitmap) return NULL; bitmap->hdc = gdi_CreateCompatibleDC(gdi->hdc); DEBUG_GDI("gdi_bitmap_new: width:%d height:%d bpp:%d", width, height, bpp); if (!data) bitmap->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, width, height); else bitmap->bitmap = gdi_create_bitmap(gdi, width, height, bpp, data); gdi_SelectObject(bitmap->hdc, (HGDIOBJECT) bitmap->bitmap); bitmap->org_bitmap = NULL; return bitmap; }
static BOOL gdi_init_primary(rdpGdi* gdi, UINT32 stride, UINT32 format, BYTE* buffer, void (*pfree)(void*)) { gdi->primary = (gdiBitmap*) calloc(1, sizeof(gdiBitmap)); if (format > 0) gdi->dstFormat = format; if (stride > 0) gdi->stride = stride; else gdi->stride = gdi->width * GetBytesPerPixel(gdi->dstFormat); if (!gdi->primary) goto fail_primary; if (!(gdi->primary->hdc = gdi_CreateCompatibleDC(gdi->hdc))) goto fail_hdc; if (!buffer) { gdi->primary->bitmap = gdi_CreateCompatibleBitmap( gdi->hdc, gdi->width, gdi->height); } else { gdi->primary->bitmap = gdi_CreateBitmapEx(gdi->width, gdi->height, gdi->dstFormat, gdi->stride, buffer, pfree); } gdi->stride = gdi->primary->bitmap->scanline; if (!gdi->primary->bitmap) goto fail_bitmap; gdi_SelectObject(gdi->primary->hdc, (HGDIOBJECT) gdi->primary->bitmap); gdi->primary->org_bitmap = NULL; gdi->primary_buffer = gdi->primary->bitmap->data; if (!(gdi->primary->hdc->hwnd = (HGDI_WND) calloc(1, sizeof(GDI_WND)))) goto fail_hwnd; if (!(gdi->primary->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0))) goto fail_hwnd; gdi->primary->hdc->hwnd->invalid->null = TRUE; gdi->primary->hdc->hwnd->count = 32; if (!(gdi->primary->hdc->hwnd->cinvalid = (HGDI_RGN) calloc( gdi->primary->hdc->hwnd->count, sizeof(GDI_RGN)))) goto fail_hwnd; gdi->primary->hdc->hwnd->ninvalid = 0; if (!gdi->drawing) gdi->drawing = gdi->primary; return TRUE; fail_hwnd: gdi_DeleteObject((HGDIOBJECT) gdi->primary->bitmap); fail_bitmap: gdi_DeleteDC(gdi->primary->hdc); fail_hdc: free(gdi->primary); gdi->primary = NULL; fail_primary: return FALSE; }