void gdi_free(freerdp* instance) { rdpGdi* gdi = instance->context->gdi; if (gdi) { gdi_bitmap_free_ex(gdi->primary); gdi_bitmap_free_ex(gdi->tile); gdi_bitmap_free_ex(gdi->image); gdi_DeleteDC(gdi->hdc); _aligned_free(gdi->bitmap_buffer); free(gdi); } instance->context->gdi = (rdpGdi*) NULL; }
void gdi_resize(rdpGdi* gdi, int width, int height) { if (gdi && gdi->primary) { if (gdi->width != width || gdi->height != height) { if (gdi->drawing == gdi->primary) gdi->drawing = NULL; gdi->width = width; gdi->height = height; gdi_bitmap_free_ex(gdi->primary); gdi->primary_buffer = NULL; gdi_init_primary(gdi); } } }
BOOL gdi_resize(rdpGdi* gdi, int width, int height) { if (!gdi || !gdi->primary) return FALSE; if (gdi->width == width && gdi->height == height) return TRUE; if (gdi->drawing == gdi->primary) gdi->drawing = NULL; gdi->width = width; gdi->height = height; gdi_bitmap_free_ex(gdi->primary); gdi->primary = NULL; gdi->primary_buffer = NULL; return gdi_init_primary(gdi); }
BOOL gdi_resize_ex(rdpGdi* gdi, UINT32 width, UINT32 height, UINT32 stride, UINT32 format, BYTE* buffer, void (*pfree)(void*)) { if (!gdi || !gdi->primary) return FALSE; if (gdi->width == width && gdi->height == height && (!buffer || gdi->primary_buffer == buffer)) return TRUE; if (gdi->drawing == gdi->primary) gdi->drawing = NULL; gdi->width = width; gdi->height = height; gdi_bitmap_free_ex(gdi->primary); gdi->primary = NULL; gdi->primary_buffer = NULL; return gdi_init_primary(gdi, stride, format, buffer, pfree); }
void gdi_free(freerdp* instance) { rdpGdi* gdi; rdpContext* context; if (!instance || !instance->context) return; gdi = instance->context->gdi; if (gdi) { gdi_bitmap_free_ex(gdi->primary); gdi_DeleteDC(gdi->hdc); free(gdi); } context = instance->context; cache_free(context->cache); context->cache = NULL; instance->context->gdi = (rdpGdi*) NULL; }
BOOL gdi_init(freerdp* instance, UINT32 flags, BYTE* buffer) { BOOL rgb555; rdpGdi* gdi; rdpCache* cache = NULL; gdi = (rdpGdi*) calloc(1, sizeof(rdpGdi)); if (!gdi) goto fail_gdi; instance->context->gdi = gdi; gdi->context = instance->context; 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; } if (!(gdi->hdc = gdi_GetDC())) goto fail_get_hdc; 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; if (!gdi_init_primary(gdi)) goto fail_init_primary; if (!(gdi->tile = gdi_bitmap_new_ex(gdi, 64, 64, 32, NULL))) goto fail_tile_bitmap; if (!(gdi->image = gdi_bitmap_new_ex(gdi, 64, 64, 32, NULL))) goto fail_image_bitmap; if (!instance->context->cache) { if (!(cache = cache_new(instance->settings))) goto fail_cache; 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); if (!gdi_register_graphics(instance->context->graphics)) goto fail_register_graphics; instance->update->BitmapUpdate = gdi_bitmap_update; return TRUE; fail_register_graphics: free(cache); fail_cache: gdi_bitmap_free_ex(gdi->image); fail_image_bitmap: gdi_bitmap_free_ex(gdi->tile); fail_tile_bitmap: gdi_bitmap_free_ex(gdi->primary); fail_init_primary: gdi_DeleteDC(gdi->hdc); fail_get_hdc: free(gdi); fail_gdi: WLog_ERR(TAG, "failed to initialize gdi"); return FALSE; }