示例#1
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;
}
示例#2
0
文件: gdi.c 项目: AMV007/FreeRDP
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;
}