diff --git a/client/X11/xf_gfx.c b/client/X11/xf_gfx.c index dd73d1ec8..6ff850a92 100644 --- a/client/X11/xf_gfx.c +++ b/client/X11/xf_gfx.c @@ -46,7 +46,6 @@ static UINT xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface) XSetClipMask(xfc->display, xfc->gc, None); XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); - region16_intersect_rect(&(surface->gdi.invalidRegion), &(surface->gdi.invalidRegion), &surfaceRect); @@ -215,12 +214,13 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, xfGfxSurface* surface; rdpGdi* gdi = (rdpGdi*)context->custom; xfContext* xfc = (xfContext*) gdi->context; + surface = (xfGfxSurface*) calloc(1, sizeof(xfGfxSurface)); - surface = (xfGfxSurface *) calloc(1, sizeof(xfGfxSurface)); if (!surface) return CHANNEL_RC_NO_MEMORY; surface->gdi.codecs = gdi->context->codecs; + if (!surface->gdi.codecs) { WLog_ERR(TAG, "%s: global GDI codecs aren't set", __FUNCTION__); @@ -250,13 +250,14 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, surface->gdi.scanline = surface->gdi.width * GetBytesPerPixel(surface->gdi.format); surface->gdi.scanline = x11_pad_scanline(surface->gdi.scanline, xfc->scanline_pad); size = surface->gdi.scanline * surface->gdi.height; - surface->gdi.data = (BYTE*)_aligned_malloc(size, 16); + if (!surface->gdi.data) { WLog_ERR(TAG, "%s: unable to allocate GDI data", __FUNCTION__); goto out_free; } + ZeroMemory(surface->gdi.data, size); if (AreColorFormatsEqualNoAlpha(gdi->dstFormat, surface->gdi.format)) @@ -272,15 +273,15 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, surface->stageScanline = width * bytes; surface->stageScanline = x11_pad_scanline(surface->stageScanline, xfc->scanline_pad); size = surface->stageScanline * surface->gdi.height; - surface->stage = (BYTE*) _aligned_malloc(size, 16); + if (!surface->stage) { WLog_ERR(TAG, "%s: unable to allocate stage buffer", __FUNCTION__); goto out_free_gdidata; } - ZeroMemory(surface->stage, size); + ZeroMemory(surface->stage, size); surface->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, (char*) surface->stage, surface->gdi.width, surface->gdi.height, @@ -295,16 +296,16 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, surface->image->byte_order = LSBFirst; surface->image->bitmap_bit_order = LSBFirst; - surface->gdi.outputMapped = FALSE; region16_init(&surface->gdi.invalidRegion); + if (context->SetSurfaceData(context, surface->gdi.surfaceId, (void*) surface) != CHANNEL_RC_OK) { WLog_ERR(TAG, "%s: an error occurred during SetSurfaceData", __FUNCTION__); goto error_set_surface_data; } - return CHANNEL_RC_OK; + return CHANNEL_RC_OK; error_set_surface_data: XFree(surface->image); error_surface_image: diff --git a/libfreerdp/gdi/gfx.c b/libfreerdp/gdi/gfx.c index 210c60c7c..03c7427c0 100644 --- a/libfreerdp/gdi/gfx.c +++ b/libfreerdp/gdi/gfx.c @@ -112,7 +112,7 @@ static UINT gdi_OutputUpdate(rdpGdi* gdi, gdiGfxSurface* surface) &(surface->invalidRegion), &surfaceRect); if (!(rects = region16_rects(&surface->invalidRegion, &nbRects)) || !nbRects) - return CHANNEL_RC_OK; + return CHANNEL_RC_OK; update->BeginPaint(gdi->context); @@ -136,7 +136,6 @@ static UINT gdi_OutputUpdate(rdpGdi* gdi, gdiGfxSurface* surface) } update->EndPaint(gdi->context); - region16_clear(&(surface->invalidRegion)); return CHANNEL_RC_OK; } @@ -212,11 +211,12 @@ static UINT gdi_SurfaceCommand_Uncompressed(rdpGdi* gdi, UINT status = CHANNEL_RC_OK; gdiGfxSurface* surface; RECTANGLE_16 invalidRect; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); + if (!surface) { - WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, cmd->surfaceId); + WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, + cmd->surfaceId); return ERROR_NOT_FOUND; } @@ -231,7 +231,6 @@ static UINT gdi_SurfaceCommand_Uncompressed(rdpGdi* gdi, invalidRect.bottom = cmd->bottom; region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect); - IFCALL(context->UpdateSurfaceArea, context, surface->surfaceId, 1, &invalidRect); if (!gdi->inGfxFrame) @@ -257,17 +256,18 @@ static UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, REGION16 invalidRegion; const RECTANGLE_16* rects; UINT32 nrRects, x; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); + if (!surface) { - WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, cmd->surfaceId); + WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, + cmd->surfaceId); return ERROR_NOT_FOUND; } rfx_context_set_pixel_format(surface->codecs->rfx, cmd->format); - region16_init(&invalidRegion); + if (!rfx_process_message(surface->codecs->rfx, cmd->data, cmd->length, cmd->left, cmd->top, surface->data, surface->format, surface->scanline, @@ -281,10 +281,11 @@ static UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, rects = region16_rects(&invalidRegion, &nrRects); IFCALL(context->UpdateSurfaceArea, context, surface->surfaceId, nrRects, rects); - for (x=0; xinvalidRegion, &surface->invalidRegion, &rects[x]); region16_uninit(&invalidRegion); + if (!gdi->inGfxFrame) { status = CHANNEL_RC_NOT_INITIALIZED; @@ -307,11 +308,12 @@ static UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, UINT status = CHANNEL_RC_OK; gdiGfxSurface* surface; RECTANGLE_16 invalidRect; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); + if (!surface) { - WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, cmd->surfaceId); + WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, + cmd->surfaceId); return ERROR_NOT_FOUND; } @@ -333,7 +335,6 @@ static UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, invalidRect.bottom = cmd->bottom; region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect); - IFCALL(context->UpdateSurfaceArea, context, surface->surfaceId, 1, &invalidRect); if (!gdi->inGfxFrame) @@ -357,11 +358,12 @@ static UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context, BYTE* DstData = NULL; gdiGfxSurface* surface; RECTANGLE_16 invalidRect; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); + if (!surface) { - WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, cmd->surfaceId); + WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, + cmd->surfaceId); return ERROR_NOT_FOUND; } @@ -380,7 +382,6 @@ static UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context, invalidRect.bottom = cmd->bottom; region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect); - IFCALL(context->UpdateSurfaceArea, context, surface->surfaceId, 1, &invalidRect); if (!gdi->inGfxFrame) @@ -408,17 +409,19 @@ static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, gdiGfxSurface* surface; RDPGFX_H264_METABLOCK* meta; RDPGFX_AVC420_BITMAP_STREAM* bs; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); + if (!surface) { - WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, cmd->surfaceId); + WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, + cmd->surfaceId); return ERROR_NOT_FOUND; } if (!surface->h264) { surface->h264 = h264_context_new(FALSE); + if (!surface->h264) { WLog_ERR(TAG, "%s: unable to create h264 context", __FUNCTION__); @@ -430,6 +433,7 @@ static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, } bs = (RDPGFX_AVC420_BITMAP_STREAM*) cmd->extra; + if (!bs) return ERROR_INTERNAL_ERROR; @@ -450,6 +454,7 @@ static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), (RECTANGLE_16*) & (meta->regionRects[i])); } + IFCALL(context->UpdateSurfaceArea, context, surface->surfaceId, meta->numRegionRects, meta->regionRects); @@ -484,17 +489,19 @@ static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_AVC420_BITMAP_STREAM* avc2; RDPGFX_H264_METABLOCK* meta2; RECTANGLE_16* regionRects = NULL; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); + if (!surface) { - WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, cmd->surfaceId); + WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, + cmd->surfaceId); return ERROR_NOT_FOUND; } if (!surface->h264) { surface->h264 = h264_context_new(FALSE); + if (!surface->h264) { WLog_ERR(TAG, "%s: unable to create h264 context", __FUNCTION__); @@ -533,6 +540,7 @@ static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context, { region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &(meta1->regionRects[i])); } + IFCALL(context->UpdateSurfaceArea, context, surface->surfaceId, meta1->numRegionRects, meta1->regionRects); @@ -540,6 +548,7 @@ static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context, { region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &(meta2->regionRects[i])); } + IFCALL(context->UpdateSurfaceArea, context, surface->surfaceId, meta2->numRegionRects, meta2->regionRects); @@ -568,11 +577,12 @@ static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context, UINT32 color; gdiGfxSurface* surface; RECTANGLE_16 invalidRect; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); + if (!surface) { - WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, cmd->surfaceId); + WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, + cmd->surfaceId); return ERROR_NOT_FOUND; } @@ -590,7 +600,6 @@ static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context, invalidRect.bottom = cmd->bottom; region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect); - IFCALL(context->UpdateSurfaceArea, context, surface->surfaceId, 1, &invalidRect); if (!gdi->inGfxFrame) @@ -617,17 +626,17 @@ static UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, REGION16 invalidRegion; const RECTANGLE_16* rects; UINT32 nrRects, x; - /** * Note: Since this comes via a Wire-To-Surface-2 PDU the * cmd's top/left/right/bottom/width/height members are always zero! * The update region is determined during decompression. */ - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); + if (!surface) { - WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, cmd->surfaceId); + WLog_ERR(TAG, "%s: unable to retrieve surfaceData for surfaceId=%"PRIu32"", __FUNCTION__, + cmd->surfaceId); return ERROR_NOT_FOUND; } @@ -657,8 +666,9 @@ static UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, rects = region16_rects(&invalidRegion, &nrRects); IFCALL(context->UpdateSurfaceArea, context, surface->surfaceId, nrRects, rects); - for (x=0; xinvalidRegion, &surface->invalidRegion, &rects[x]); + region16_uninit(&invalidRegion); if (!gdi->inGfxFrame) @@ -759,7 +769,7 @@ static UINT gdi_CreateSurface(RdpgfxClientContext* context, const RDPGFX_CREATE_SURFACE_PDU* createSurface) { gdiGfxSurface* surface; - rdpGdi* gdi = (rdpGdi*) context->custom; + rdpGdi* gdi = (rdpGdi*) context->custom; surface = (gdiGfxSurface*) calloc(1, sizeof(gdiGfxSurface)); if (!surface) @@ -886,6 +896,7 @@ static UINT gdi_SolidFill(RdpgfxClientContext* context, region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect); } + IFCALL(context->UpdateSurfaceArea, context, surface->surfaceId, solidFill->fillRectCount, solidFill->fillRects); @@ -975,14 +986,14 @@ static UINT gdi_SurfaceToCache(RdpgfxClientContext* context, const RECTANGLE_16* rect; gdiGfxSurface* surface; gdiGfxCacheEntry* cacheEntry; - rect = &(surfaceToCache->rectSrc); - surface = (gdiGfxSurface*) context->GetSurfaceData(context, surfaceToCache->surfaceId); + if (!surface) return ERROR_INTERNAL_ERROR; cacheEntry = (gdiGfxCacheEntry*) calloc(1, sizeof(gdiGfxCacheEntry)); + if (!cacheEntry) return ERROR_NOT_ENOUGH_MEMORY; @@ -990,8 +1001,8 @@ static UINT gdi_SurfaceToCache(RdpgfxClientContext* context, cacheEntry->height = (UINT32)(rect->bottom - rect->top); cacheEntry->format = surface->format; cacheEntry->scanline = gfx_align_scanline(cacheEntry->width * 4, 16); - cacheEntry->data = (BYTE*) calloc(cacheEntry->height, cacheEntry->scanline); + if (!cacheEntry->data) { free(cacheEntry); @@ -1024,7 +1035,6 @@ static UINT gdi_CacheToSurface(RdpgfxClientContext* context, gdiGfxCacheEntry* cacheEntry; RECTANGLE_16 invalidRect; rdpGdi* gdi = (rdpGdi*) context->custom; - surface = (gdiGfxSurface*) context->GetSurfaceData(context, cacheToSurface->surfaceId); cacheEntry = (gdiGfxCacheEntry*) context->GetCacheSlotData(context, cacheToSurface->cacheSlot);