22 #include <freerdp/config.h>
24 #include "../core/update.h"
26 #include <freerdp/api.h>
27 #include <freerdp/log.h>
28 #include <freerdp/gdi/gfx.h>
29 #include <freerdp/gdi/region.h>
30 #include <freerdp/utils/gfx.h>
33 #define TAG FREERDP_TAG("gdi")
35 static BOOL is_rect_valid(
const RECTANGLE_16* rect,
size_t width,
size_t height)
39 if ((rect->left > rect->right) || (rect->right > width))
41 if ((rect->top > rect->bottom) || (rect->bottom > height))
51 rect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
52 rect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
53 rect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
54 rect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
55 if (!is_rect_valid(&rect, surface->width, surface->height))
58 "Command rect %" PRIu32
"x%" PRIu32
"-%" PRIu32
"x%" PRIu32
59 " not within bounds of %" PRIu32
"x%" PRIu32,
60 rect.left, rect.top, cmd->width, cmd->height, surface->width, surface->height);
67 static DWORD gfx_align_scanline(DWORD widthInBytes, DWORD alignment)
69 const UINT32 align = alignment;
70 const UINT32 pad = align - (widthInBytes % alignment);
71 UINT32 scanline = widthInBytes;
84 static UINT gdi_ResetGraphics(RdpgfxClientContext* context,
87 UINT rc = ERROR_INTERNAL_ERROR;
89 UINT32 DesktopWidth = 0;
90 UINT32 DesktopHeight = 0;
91 UINT16* pSurfaceIds = NULL;
93 rdpUpdate* update = NULL;
94 rdpSettings* settings = NULL;
96 WINPR_ASSERT(context);
97 WINPR_ASSERT(resetGraphics);
99 gdi = (rdpGdi*)context->custom;
102 update = gdi->context->update;
103 WINPR_ASSERT(update);
105 settings = gdi->context->settings;
106 WINPR_ASSERT(settings);
107 EnterCriticalSection(&context->mux);
108 DesktopWidth = resetGraphics->width;
109 DesktopHeight = resetGraphics->height;
118 WINPR_ASSERT(update->DesktopResize);
119 update->DesktopResize(gdi->context);
122 WINPR_ASSERT(context->GetSurfaceIds);
123 context->GetSurfaceIds(context, &pSurfaceIds, &count);
125 for (UINT32 index = 0; index < count; index++)
127 WINPR_ASSERT(context->GetSurfaceData);
128 gdiGfxSurface* surface =
129 (gdiGfxSurface*)context->GetSurfaceData(context, pSurfaceIds[index]);
134 memset(surface->data, 0xFF, (
size_t)surface->scanline * surface->height);
135 region16_clear(&surface->invalidRegion);
142 const UINT32 width = (UINT32)MAX(0, gdi->width);
143 const UINT32 height = (UINT32)MAX(0, gdi->height);
145 if (!freerdp_client_codecs_reset(
150 if (!freerdp_client_codecs_reset(
159 LeaveCriticalSection(&context->mux);
163 static UINT gdi_OutputUpdate(rdpGdi* gdi, gdiGfxSurface* surface)
165 UINT rc = ERROR_INTERNAL_ERROR;
171 rdpUpdate* update = NULL;
174 WINPR_ASSERT(gdi->context);
175 WINPR_ASSERT(surface);
177 update = gdi->context->update;
178 WINPR_ASSERT(update);
180 if (gdi->suppressOutput)
181 return CHANNEL_RC_OK;
183 surfaceX = surface->outputOriginX;
184 surfaceY = surface->outputOriginY;
185 surfaceRect.left = 0;
187 surfaceRect.right = (UINT16)MIN(UINT16_MAX, surface->mappedWidth);
188 surfaceRect.bottom = (UINT16)MIN(UINT16_MAX, surface->mappedHeight);
189 region16_intersect_rect(&(surface->invalidRegion), &(surface->invalidRegion), &surfaceRect);
190 const double sx = surface->outputTargetWidth / (double)surface->mappedWidth;
191 const double sy = surface->outputTargetHeight / (
double)surface->mappedHeight;
193 if (!(rects = region16_rects(&surface->invalidRegion, &nbRects)) || !nbRects)
194 return CHANNEL_RC_OK;
196 if (!update_begin_paint(update))
199 for (UINT32 i = 0; i < nbRects; i++)
201 const UINT32 nXSrc = rects[i].left;
202 const UINT32 nYSrc = rects[i].top;
203 const UINT32 nXDst = (UINT32)MIN(surfaceX + nXSrc * sx, gdi->width - 1);
204 const UINT32 nYDst = (UINT32)MIN(surfaceY + nYSrc * sy, gdi->height - 1);
205 const UINT32 swidth = rects[i].right - rects[i].left;
206 const UINT32 sheight = rects[i].bottom - rects[i].top;
207 const UINT32 dwidth = MIN((UINT32)(swidth * sx), (UINT32)gdi->width - nXDst);
208 const UINT32 dheight = MIN((UINT32)(sheight * sy), (UINT32)gdi->height - nYDst);
210 if (!freerdp_image_scale(gdi->primary_buffer, gdi->dstFormat, gdi->stride, nXDst, nYDst,
211 dwidth, dheight, surface->data, surface->format, surface->scanline,
212 nXSrc, nYSrc, swidth, sheight))
214 rc = CHANNEL_RC_NULL_DATA;
218 gdi_InvalidateRegion(gdi->primary->hdc, (INT32)nXDst, (INT32)nYDst, (INT32)dwidth,
225 if (!update_end_paint(update))
226 rc = ERROR_INTERNAL_ERROR;
228 region16_clear(&(surface->invalidRegion));
232 static UINT gdi_WindowUpdate(RdpgfxClientContext* context, gdiGfxSurface* surface)
234 WINPR_ASSERT(context);
235 WINPR_ASSERT(surface);
236 return IFCALLRESULT(CHANNEL_RC_OK, context->UpdateWindowFromSurface, context, surface);
239 static UINT gdi_UpdateSurfaces(RdpgfxClientContext* context)
242 UINT status = ERROR_INTERNAL_ERROR;
243 UINT16* pSurfaceIds = NULL;
246 WINPR_ASSERT(context);
248 gdi = (rdpGdi*)context->custom;
251 EnterCriticalSection(&context->mux);
253 WINPR_ASSERT(context->GetSurfaceIds);
254 context->GetSurfaceIds(context, &pSurfaceIds, &count);
255 status = CHANNEL_RC_OK;
257 for (UINT32 index = 0; index < count; index++)
259 WINPR_ASSERT(context->GetSurfaceData);
260 gdiGfxSurface* surface =
261 (gdiGfxSurface*)context->GetSurfaceData(context, pSurfaceIds[index]);
267 if (context->UpdateSurfaceArea)
269 if (surface->handleInUpdateSurfaceArea)
273 if (surface->outputMapped)
274 status = gdi_OutputUpdate(gdi, surface);
275 else if (surface->windowMapped)
276 status = gdi_WindowUpdate(context, surface);
278 if (status != CHANNEL_RC_OK)
283 LeaveCriticalSection(&context->mux);
296 WINPR_ASSERT(context);
297 WINPR_ASSERT(startFrame);
299 gdi = (rdpGdi*)context->custom;
301 gdi->inGfxFrame = TRUE;
302 gdi->frameId = startFrame->frameId;
303 return CHANNEL_RC_OK;
306 static UINT gdi_call_update_surfaces(RdpgfxClientContext* context)
308 WINPR_ASSERT(context);
309 return IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaces, context);
319 WINPR_ASSERT(context);
320 WINPR_ASSERT(endFrame);
322 rdpGdi* gdi = (rdpGdi*)context->custom;
324 const UINT status = gdi_call_update_surfaces(context);
325 gdi->inGfxFrame = FALSE;
329 static UINT gdi_interFrameUpdate(rdpGdi* gdi, RdpgfxClientContext* context)
332 UINT status = CHANNEL_RC_OK;
333 if (!gdi->inGfxFrame)
334 status = gdi_call_update_surfaces(context);
343 static UINT gdi_SurfaceCommand_Uncompressed(rdpGdi* gdi, RdpgfxClientContext* context,
346 UINT status = CHANNEL_RC_OK;
347 gdiGfxSurface* surface = NULL;
352 WINPR_ASSERT(context);
355 WINPR_ASSERT(context->GetSurfaceData);
357 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
361 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
362 return ERROR_NOT_FOUND;
365 if (!is_within_surface(surface, cmd))
366 return ERROR_INVALID_DATA;
368 bpp = FreeRDPGetBytesPerPixel(cmd->format);
369 size = 1ull * bpp * cmd->width * cmd->height;
370 if (cmd->length < size)
372 WLog_ERR(TAG,
"Not enough data, got %" PRIu32
", expected %" PRIuz, cmd->length, size);
373 return ERROR_INVALID_DATA;
376 if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline, cmd->left,
377 cmd->top, cmd->width, cmd->height, cmd->data, cmd->format, 0,
378 0, 0, NULL, FREERDP_FLIP_NONE))
379 return ERROR_INTERNAL_ERROR;
381 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
382 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
383 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
384 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
385 region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
386 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
389 if (status != CHANNEL_RC_OK)
392 status = gdi_interFrameUpdate(gdi, context);
403 static UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, RdpgfxClientContext* context,
406 UINT status = ERROR_INTERNAL_ERROR;
407 gdiGfxSurface* surface = NULL;
412 WINPR_ASSERT(context);
415 WINPR_ASSERT(context->GetSurfaceData);
417 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
421 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
422 return ERROR_NOT_FOUND;
425 WINPR_ASSERT(surface->codecs);
426 rfx_context_set_pixel_format(surface->codecs->rfx, cmd->format);
427 region16_init(&invalidRegion);
429 if (!rfx_process_message(surface->codecs->rfx, cmd->data, cmd->length, cmd->left, cmd->top,
430 surface->data, surface->format, surface->scanline, surface->height,
433 WLog_ERR(TAG,
"Failed to process RemoteFX message");
437 rects = region16_rects(&invalidRegion, &nrRects);
438 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
441 if (status != CHANNEL_RC_OK)
444 for (UINT32 x = 0; x < nrRects; x++)
445 region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]);
447 status = gdi_interFrameUpdate(gdi, context);
450 region16_uninit(&invalidRegion);
459 static UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, RdpgfxClientContext* context,
463 UINT status = CHANNEL_RC_OK;
464 gdiGfxSurface* surface = NULL;
467 WINPR_ASSERT(context);
470 WINPR_ASSERT(context->GetSurfaceData);
472 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
476 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
477 return ERROR_NOT_FOUND;
480 WINPR_ASSERT(surface->codecs);
481 rc = clear_decompress(surface->codecs->clear, cmd->data, cmd->length, cmd->width, cmd->height,
482 surface->data, surface->format, surface->scanline, cmd->left, cmd->top,
483 surface->width, surface->height, &gdi->palette);
487 WLog_ERR(TAG,
"clear_decompress failure: %" PRId32
"", rc);
488 return ERROR_INTERNAL_ERROR;
491 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
492 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
493 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
494 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
495 region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
496 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
499 if (status != CHANNEL_RC_OK)
502 status = gdi_interFrameUpdate(gdi, context);
513 static UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context,
516 UINT status = CHANNEL_RC_OK;
517 BYTE* DstData = NULL;
518 gdiGfxSurface* surface = NULL;
521 WINPR_ASSERT(context);
524 WINPR_ASSERT(context->GetSurfaceData);
526 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
530 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
531 return ERROR_NOT_FOUND;
534 DstData = surface->data;
536 if (!is_within_surface(surface, cmd))
537 return ERROR_INVALID_DATA;
539 if (!planar_decompress(surface->codecs->planar, cmd->data, cmd->length, cmd->width, cmd->height,
540 DstData, surface->format, surface->scanline, cmd->left, cmd->top,
541 cmd->width, cmd->height, FALSE))
542 return ERROR_INTERNAL_ERROR;
544 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
545 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
546 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
547 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
548 region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
549 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
552 if (status != CHANNEL_RC_OK)
555 status = gdi_interFrameUpdate(gdi, context);
566 static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, RdpgfxClientContext* context,
571 UINT status = CHANNEL_RC_OK;
572 gdiGfxSurface* surface = NULL;
576 WINPR_ASSERT(context);
579 WINPR_ASSERT(context->GetSurfaceData);
581 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
585 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
586 return ERROR_NOT_FOUND;
591 surface->h264 = h264_context_new(FALSE);
595 WLog_ERR(TAG,
"unable to create h264 context");
596 return ERROR_NOT_ENOUGH_MEMORY;
599 if (!h264_context_reset(surface->h264, surface->width, surface->height))
600 return ERROR_INTERNAL_ERROR;
604 return ERROR_NOT_SUPPORTED;
609 return ERROR_INTERNAL_ERROR;
612 rc = avc420_decompress(surface->h264, bs->data, bs->length, surface->data, surface->format,
613 surface->scanline, surface->width, surface->height, meta->regionRects,
614 meta->numRegionRects);
618 WLog_WARN(TAG,
"avc420_decompress failure: %" PRId32
", ignoring update.", rc);
619 return CHANNEL_RC_OK;
622 for (UINT32 i = 0; i < meta->numRegionRects; i++)
624 region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
625 &(meta->regionRects[i]));
628 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
629 meta->numRegionRects, meta->regionRects);
631 if (status != CHANNEL_RC_OK)
634 status = gdi_interFrameUpdate(gdi, context);
639 return ERROR_NOT_SUPPORTED;
648 static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context,
653 UINT status = CHANNEL_RC_OK;
654 gdiGfxSurface* surface = NULL;
661 WINPR_ASSERT(context);
664 WINPR_ASSERT(context->GetSurfaceData);
666 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
670 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
671 return ERROR_NOT_FOUND;
676 surface->h264 = h264_context_new(FALSE);
680 WLog_ERR(TAG,
"unable to create h264 context");
681 return ERROR_NOT_ENOUGH_MEMORY;
684 if (!h264_context_reset(surface->h264, surface->width, surface->height))
685 return ERROR_INTERNAL_ERROR;
689 return ERROR_NOT_SUPPORTED;
694 return ERROR_INTERNAL_ERROR;
696 avc1 = &bs->bitstream[0];
697 avc2 = &bs->bitstream[1];
700 rc = avc444_decompress(surface->h264, bs->LC, meta1->regionRects, meta1->numRegionRects,
701 avc1->data, avc1->length, meta2->regionRects, meta2->numRegionRects,
702 avc2->data, avc2->length, surface->data, surface->format,
703 surface->scanline, surface->width, surface->height, cmd->codecId);
707 WLog_WARN(TAG,
"avc444_decompress failure: %" PRIu32
", ignoring update.", status);
708 return CHANNEL_RC_OK;
711 for (UINT32 i = 0; i < meta1->numRegionRects; i++)
713 region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
714 &(meta1->regionRects[i]));
717 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
718 meta1->numRegionRects, meta1->regionRects);
720 if (status != CHANNEL_RC_OK)
723 for (UINT32 i = 0; i < meta2->numRegionRects; i++)
725 region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
726 &(meta2->regionRects[i]));
729 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
730 meta2->numRegionRects, meta2->regionRects);
732 if (status != CHANNEL_RC_OK)
735 status = gdi_interFrameUpdate(gdi, context);
740 return ERROR_NOT_SUPPORTED;
744 static BOOL gdi_apply_alpha(BYTE* data, UINT32 format, UINT32 stride,
RECTANGLE_16* rect,
745 UINT32 startOffsetX, UINT32 count, BYTE a)
749 const UINT32 bpp = FreeRDPGetBytesPerPixel(format);
752 for (
size_t y = rect->top; y < rect->bottom; y++)
754 BYTE* line = &data[y * stride];
756 for (
size_t x = first ? rect->left + startOffsetX : rect->left; x < rect->right; x++)
762 if (written == count)
765 BYTE* src = &line[x * bpp];
766 UINT32 color = FreeRDPReadColor(src, format);
767 FreeRDPSplitColor(color, format, &r, &g, &b, NULL, NULL);
768 color = FreeRDPGetColor(format, r, g, b, a);
769 FreeRDPWriteColor(src, format, color);
783 static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context,
786 UINT status = CHANNEL_RC_OK;
788 UINT16 compressed = 0;
789 gdiGfxSurface* surface = NULL;
794 WINPR_ASSERT(context);
797 s = Stream_StaticConstInit(&buffer, cmd->data, cmd->length);
799 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
800 return ERROR_INVALID_DATA;
802 WINPR_ASSERT(context->GetSurfaceData);
804 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
808 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
809 return ERROR_NOT_FOUND;
812 if (!is_within_surface(surface, cmd))
813 return ERROR_INVALID_DATA;
815 Stream_Read_UINT16(s, alphaSig);
816 Stream_Read_UINT16(s, compressed);
818 if (alphaSig != 0x414C)
819 return ERROR_INVALID_DATA;
823 if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, cmd->height, cmd->width))
824 return ERROR_INVALID_DATA;
826 for (
size_t y = cmd->top; y < cmd->top + cmd->height; y++)
828 BYTE* line = &surface->data[y * surface->scanline];
830 for (
size_t x = cmd->left; x < cmd->left + cmd->width; x++)
837 BYTE* src = &line[x * FreeRDPGetBytesPerPixel(surface->format)];
838 Stream_Read_UINT8(s, a);
839 color = FreeRDPReadColor(src, surface->format);
840 FreeRDPSplitColor(color, surface->format, &r, &g, &b, NULL, NULL);
841 color = FreeRDPGetColor(surface->format, r, g, b, a);
842 FreeRDPWriteColor(src, surface->format, color);
848 UINT32 startOffsetX = 0;
850 rect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
851 rect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
852 rect.right = (UINT16)MIN(UINT16_MAX, cmd->left + cmd->width);
853 rect.bottom = (UINT16)MIN(UINT16_MAX, cmd->top + cmd->height);
855 while (rect.top < rect.bottom)
860 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
861 return ERROR_INVALID_DATA;
863 Stream_Read_UINT8(s, a);
864 Stream_Read_UINT8(s, count);
868 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
869 return ERROR_INVALID_DATA;
871 Stream_Read_UINT16(s, count);
875 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
876 return ERROR_INVALID_DATA;
878 Stream_Read_UINT32(s, count);
882 if (!gdi_apply_alpha(surface->data, surface->format, surface->scanline, &rect,
883 startOffsetX, count, a))
884 return ERROR_INTERNAL_ERROR;
886 startOffsetX += count;
888 while (startOffsetX >= cmd->width)
890 startOffsetX -= cmd->width;
896 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
897 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
898 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
899 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
900 region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
901 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
904 if (status != CHANNEL_RC_OK)
907 status = gdi_interFrameUpdate(gdi, context);
913 #if defined(WITH_GFX_FRAME_DUMP)
916 static UINT64 xxx = 0;
917 const char* path =
"/tmp/dump/";
919 char fname[1024] = { 0 };
921 snprintf(fname,
sizeof(fname),
"%s/%08" PRIx64
".raw", path, xxx++);
922 FILE* fp = fopen(fname,
"w");
925 (void)fprintf(fp,
"frameid: %" PRIu32
"\n", frameId);
926 (void)fprintf(fp,
"surfaceId: %" PRIu32
"\n", cmd->surfaceId);
927 (void)fprintf(fp,
"codecId: %" PRIu32
"\n", cmd->codecId);
928 (void)fprintf(fp,
"contextId: %" PRIu32
"\n", cmd->contextId);
929 (void)fprintf(fp,
"format: %" PRIu32
"\n", cmd->format);
930 (void)fprintf(fp,
"left: %" PRIu32
"\n", cmd->left);
931 (void)fprintf(fp,
"top: %" PRIu32
"\n", cmd->top);
932 (void)fprintf(fp,
"right: %" PRIu32
"\n", cmd->right);
933 (void)fprintf(fp,
"bottom: %" PRIu32
"\n", cmd->bottom);
934 (void)fprintf(fp,
"width: %" PRIu32
"\n", cmd->width);
935 (void)fprintf(fp,
"height: %" PRIu32
"\n", cmd->height);
936 (void)fprintf(fp,
"length: %" PRIu32
"\n", cmd->length);
938 char* bdata = crypto_base64_encode_ex(cmd->data, cmd->length, FALSE);
939 (void)fprintf(fp,
"data: %s\n", bdata);
950 static UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, RdpgfxClientContext* context,
954 UINT status = CHANNEL_RC_OK;
955 gdiGfxSurface* surface = NULL;
965 WINPR_ASSERT(context);
967 const UINT16 surfaceId = (UINT16)MIN(UINT16_MAX, cmd->surfaceId);
969 WINPR_ASSERT(context->GetSurfaceData);
970 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceId);
974 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
975 return ERROR_NOT_FOUND;
978 if (!is_within_surface(surface, cmd))
979 return ERROR_INVALID_DATA;
981 WINPR_ASSERT(surface->codecs);
982 rc = progressive_create_surface_context(surface->codecs->progressive, surfaceId, surface->width,
987 WLog_ERR(TAG,
"progressive_create_surface_context failure: %" PRId32
"", rc);
988 return ERROR_INTERNAL_ERROR;
991 region16_init(&invalidRegion);
993 rc = progressive_decompress(surface->codecs->progressive, cmd->data, cmd->length, surface->data,
994 surface->format, surface->scanline, cmd->left, cmd->top,
995 &invalidRegion, surfaceId, gdi->frameId);
999 WLog_ERR(TAG,
"progressive_decompress failure: %" PRId32
"", rc);
1000 region16_uninit(&invalidRegion);
1001 return ERROR_INTERNAL_ERROR;
1004 rects = region16_rects(&invalidRegion, &nrRects);
1005 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1008 if (status != CHANNEL_RC_OK)
1011 for (UINT32 x = 0; x < nrRects; x++)
1012 region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]);
1014 region16_uninit(&invalidRegion);
1016 status = gdi_interFrameUpdate(gdi, context);
1029 UINT status = CHANNEL_RC_OK;
1032 if (!context || !cmd)
1033 return ERROR_INVALID_PARAMETER;
1035 gdi = (rdpGdi*)context->custom;
1037 EnterCriticalSection(&context->mux);
1038 WLog_Print(gdi->log, WLOG_TRACE,
1039 "surfaceId=%" PRIu32
", codec=%s [%" PRIu32
"], contextId=%" PRIu32
", format=%s, "
1040 "left=%" PRIu32
", top=%" PRIu32
", right=%" PRIu32
", bottom=%" PRIu32
1041 ", width=%" PRIu32
", height=%" PRIu32
" "
1042 "length=%" PRIu32
", data=%p, extra=%p",
1043 cmd->surfaceId, rdpgfx_get_codec_id_string(cmd->codecId), cmd->codecId,
1044 cmd->contextId, FreeRDPGetColorFormatName(cmd->format), cmd->left, cmd->top,
1045 cmd->right, cmd->bottom, cmd->width, cmd->height, cmd->length, (
void*)cmd->data,
1047 #if defined(WITH_GFX_FRAME_DUMP)
1048 dump_cmd(cmd, gdi->frameId);
1051 switch (cmd->codecId)
1053 case RDPGFX_CODECID_UNCOMPRESSED:
1054 status = gdi_SurfaceCommand_Uncompressed(gdi, context, cmd);
1057 case RDPGFX_CODECID_CAVIDEO:
1058 status = gdi_SurfaceCommand_RemoteFX(gdi, context, cmd);
1061 case RDPGFX_CODECID_CLEARCODEC:
1062 status = gdi_SurfaceCommand_ClearCodec(gdi, context, cmd);
1065 case RDPGFX_CODECID_PLANAR:
1066 status = gdi_SurfaceCommand_Planar(gdi, context, cmd);
1069 case RDPGFX_CODECID_AVC420:
1070 status = gdi_SurfaceCommand_AVC420(gdi, context, cmd);
1073 case RDPGFX_CODECID_AVC444v2:
1074 case RDPGFX_CODECID_AVC444:
1075 status = gdi_SurfaceCommand_AVC444(gdi, context, cmd);
1078 case RDPGFX_CODECID_ALPHA:
1079 status = gdi_SurfaceCommand_Alpha(gdi, context, cmd);
1082 case RDPGFX_CODECID_CAPROGRESSIVE:
1083 status = gdi_SurfaceCommand_Progressive(gdi, context, cmd);
1086 case RDPGFX_CODECID_CAPROGRESSIVE_V2:
1087 WLog_WARN(TAG,
"SurfaceCommand %s [0x%08" PRIX32
"] not implemented",
1088 rdpgfx_get_codec_id_string(cmd->codecId), cmd->codecId);
1092 WLog_WARN(TAG,
"Invalid SurfaceCommand %s [0x%08" PRIX32
"]",
1093 rdpgfx_get_codec_id_string(cmd->codecId), cmd->codecId);
1097 LeaveCriticalSection(&context->mux);
1107 gdi_DeleteEncodingContext(RdpgfxClientContext* context,
1110 WINPR_ASSERT(context);
1111 WINPR_ASSERT(deleteEncodingContext);
1112 WINPR_UNUSED(context);
1113 WINPR_UNUSED(deleteEncodingContext);
1114 return CHANNEL_RC_OK;
1122 static UINT gdi_CreateSurface(RdpgfxClientContext* context,
1125 UINT rc = ERROR_INTERNAL_ERROR;
1126 gdiGfxSurface* surface = NULL;
1128 WINPR_ASSERT(context);
1129 WINPR_ASSERT(createSurface);
1130 gdi = (rdpGdi*)context->custom;
1132 WINPR_ASSERT(gdi->context);
1133 EnterCriticalSection(&context->mux);
1134 surface = (gdiGfxSurface*)calloc(1,
sizeof(gdiGfxSurface));
1141 WINPR_ASSERT(context->codecs);
1142 surface->codecs = context->codecs;
1144 if (!surface->codecs)
1151 surface->surfaceId = createSurface->surfaceId;
1152 surface->width = gfx_align_scanline(createSurface->width, 16);
1153 surface->height = gfx_align_scanline(createSurface->height, 16);
1154 surface->mappedWidth = createSurface->width;
1155 surface->mappedHeight = createSurface->height;
1156 surface->outputTargetWidth = createSurface->width;
1157 surface->outputTargetHeight = createSurface->height;
1159 switch (createSurface->pixelFormat)
1161 case GFX_PIXEL_FORMAT_ARGB_8888:
1162 surface->format = PIXEL_FORMAT_BGRA32;
1165 case GFX_PIXEL_FORMAT_XRGB_8888:
1166 surface->format = PIXEL_FORMAT_BGRX32;
1174 surface->scanline = gfx_align_scanline(surface->width * 4UL, 16);
1175 surface->data = (BYTE*)winpr_aligned_malloc(1ull * surface->scanline * surface->height, 16);
1183 memset(surface->data, 0xFF, (
size_t)surface->scanline * surface->height);
1184 region16_init(&surface->invalidRegion);
1186 WINPR_ASSERT(context->SetSurfaceData);
1187 rc = context->SetSurfaceData(context, surface->surfaceId, (
void*)surface);
1189 LeaveCriticalSection(&context->mux);
1198 static UINT gdi_DeleteSurface(RdpgfxClientContext* context,
1201 UINT rc = CHANNEL_RC_OK;
1202 UINT res = ERROR_INTERNAL_ERROR;
1203 rdpCodecs* codecs = NULL;
1204 gdiGfxSurface* surface = NULL;
1205 EnterCriticalSection(&context->mux);
1207 WINPR_ASSERT(context->GetSurfaceData);
1208 surface = (gdiGfxSurface*)context->GetSurfaceData(context, deleteSurface->surfaceId);
1212 if (surface->windowMapped)
1213 rc = IFCALLRESULT(CHANNEL_RC_OK, context->UnmapWindowForSurface, context,
1216 #ifdef WITH_GFX_H264
1217 h264_context_free(surface->h264);
1219 region16_uninit(&surface->invalidRegion);
1220 codecs = surface->codecs;
1221 winpr_aligned_free(surface->data);
1225 WINPR_ASSERT(context->SetSurfaceData);
1226 res = context->SetSurfaceData(context, deleteSurface->surfaceId, NULL);
1230 if (codecs && codecs->progressive)
1231 progressive_delete_surface_context(codecs->progressive, deleteSurface->surfaceId);
1233 LeaveCriticalSection(&context->mux);
1237 static BOOL intersect_rect(
const RECTANGLE_16* rect,
const gdiGfxSurface* surface,
1241 WINPR_ASSERT(surface);
1242 WINPR_ASSERT(prect);
1244 if (rect->left > rect->right)
1246 if (rect->left > surface->width)
1248 if (rect->top > rect->bottom)
1250 if (rect->top > surface->height)
1252 prect->left = rect->left;
1253 prect->top = rect->top;
1254 prect->right = MIN(rect->right, surface->width);
1255 prect->bottom = MIN(rect->bottom, surface->height);
1266 UINT status = ERROR_INTERNAL_ERROR;
1269 rdpGdi* gdi = (rdpGdi*)context->custom;
1271 EnterCriticalSection(&context->mux);
1273 WINPR_ASSERT(context->GetSurfaceData);
1274 gdiGfxSurface* surface = (gdiGfxSurface*)context->GetSurfaceData(context, solidFill->surfaceId);
1279 const BYTE b = solidFill->fillPixel.B;
1280 const BYTE g = solidFill->fillPixel.G;
1281 const BYTE r = solidFill->fillPixel.R;
1289 if (FreeRDPColorHasAlpha(surface->format))
1290 a = solidFill->fillPixel.XA;
1293 const UINT32 color = FreeRDPGetColor(surface->format, r, g, b, a);
1295 for (UINT16 index = 0; index < solidFill->fillRectCount; index++)
1297 const RECTANGLE_16* rect = &(solidFill->fillRects[index]);
1299 if (!intersect_rect(rect, surface, &invalidRect))
1302 const UINT32 nWidth = invalidRect.right - invalidRect.left;
1303 const UINT32 nHeight = invalidRect.bottom - invalidRect.top;
1305 if (!freerdp_image_fill(surface->data, surface->format, surface->scanline, invalidRect.left,
1306 invalidRect.top, nWidth, nHeight, color))
1309 region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
1312 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1313 solidFill->fillRectCount, solidFill->fillRects);
1315 if (status != CHANNEL_RC_OK)
1318 LeaveCriticalSection(&context->mux);
1320 return gdi_interFrameUpdate(gdi, context);
1322 LeaveCriticalSection(&context->mux);
1331 static UINT gdi_SurfaceToSurface(RdpgfxClientContext* context,
1334 UINT status = ERROR_INTERNAL_ERROR;
1335 BOOL sameSurface = 0;
1340 gdiGfxSurface* surfaceSrc = NULL;
1341 gdiGfxSurface* surfaceDst = NULL;
1342 rdpGdi* gdi = (rdpGdi*)context->custom;
1343 EnterCriticalSection(&context->mux);
1344 rectSrc = &(surfaceToSurface->rectSrc);
1346 WINPR_ASSERT(context->GetSurfaceData);
1347 surfaceSrc = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdSrc);
1349 (surfaceToSurface->surfaceIdSrc == surfaceToSurface->surfaceIdDest) ? TRUE : FALSE;
1353 (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdDest);
1355 surfaceDst = surfaceSrc;
1357 if (!surfaceSrc || !surfaceDst)
1360 if (!is_rect_valid(rectSrc, surfaceSrc->width, surfaceSrc->height))
1363 nWidth = rectSrc->right - rectSrc->left;
1364 nHeight = rectSrc->bottom - rectSrc->top;
1366 for (UINT16 index = 0; index < surfaceToSurface->destPtsCount; index++)
1368 const RDPGFX_POINT16* destPt = &surfaceToSurface->destPts[index];
1370 (UINT16)MIN(UINT16_MAX, destPt->x + nWidth),
1371 (UINT16)MIN(UINT16_MAX, destPt->y + nHeight) };
1372 if (!is_rect_valid(&rect, surfaceDst->width, surfaceDst->height))
1375 if (!freerdp_image_copy(surfaceDst->data, surfaceDst->format, surfaceDst->scanline,
1376 destPt->x, destPt->y, nWidth, nHeight, surfaceSrc->data,
1377 surfaceSrc->format, surfaceSrc->scanline, rectSrc->left,
1378 rectSrc->top, NULL, FREERDP_FLIP_NONE))
1382 region16_union_rect(&surfaceDst->invalidRegion, &surfaceDst->invalidRegion, &invalidRect);
1383 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1384 surfaceDst->surfaceId, 1, &invalidRect);
1386 if (status != CHANNEL_RC_OK)
1390 LeaveCriticalSection(&context->mux);
1392 return gdi_interFrameUpdate(gdi, context);
1394 LeaveCriticalSection(&context->mux);
1398 static void gdi_GfxCacheEntryFree(gdiGfxCacheEntry* entry)
1406 static gdiGfxCacheEntry* gdi_GfxCacheEntryNew(UINT64 cacheKey, UINT32 width, UINT32 height,
1409 gdiGfxCacheEntry* cacheEntry = (gdiGfxCacheEntry*)calloc(1,
sizeof(gdiGfxCacheEntry));
1413 cacheEntry->cacheKey = cacheKey;
1414 cacheEntry->width = width;
1415 cacheEntry->height = height;
1416 cacheEntry->format = format;
1417 cacheEntry->scanline = gfx_align_scanline(cacheEntry->width * 4, 16);
1419 if ((cacheEntry->width > 0) && (cacheEntry->height > 0))
1421 cacheEntry->data = (BYTE*)calloc(cacheEntry->height, cacheEntry->scanline);
1423 if (!cacheEntry->data)
1428 gdi_GfxCacheEntryFree(cacheEntry);
1437 static UINT gdi_SurfaceToCache(RdpgfxClientContext* context,
1441 gdiGfxSurface* surface = NULL;
1442 gdiGfxCacheEntry* cacheEntry = NULL;
1443 UINT rc = ERROR_INTERNAL_ERROR;
1444 EnterCriticalSection(&context->mux);
1445 rect = &(surfaceToCache->rectSrc);
1447 WINPR_ASSERT(context->GetSurfaceData);
1448 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToCache->surfaceId);
1453 if (!is_rect_valid(rect, surface->width, surface->height))
1456 cacheEntry = gdi_GfxCacheEntryNew(surfaceToCache->cacheKey, (UINT32)(rect->right - rect->left),
1457 (UINT32)(rect->bottom - rect->top), surface->format);
1462 if (!cacheEntry->data)
1465 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1466 0, 0, cacheEntry->width, cacheEntry->height, surface->data,
1467 surface->format, surface->scanline, rect->left, rect->top,
1468 NULL, FREERDP_FLIP_NONE))
1472 WINPR_ASSERT(context->EvictCacheEntry);
1473 context->EvictCacheEntry(context, &evict);
1475 WINPR_ASSERT(context->SetCacheSlotData);
1476 rc = context->SetCacheSlotData(context, surfaceToCache->cacheSlot, (
void*)cacheEntry);
1478 if (rc != CHANNEL_RC_OK)
1479 gdi_GfxCacheEntryFree(cacheEntry);
1480 LeaveCriticalSection(&context->mux);
1489 static UINT gdi_CacheToSurface(RdpgfxClientContext* context,
1492 UINT status = ERROR_INTERNAL_ERROR;
1493 gdiGfxSurface* surface = NULL;
1494 gdiGfxCacheEntry* cacheEntry = NULL;
1496 rdpGdi* gdi = (rdpGdi*)context->custom;
1498 EnterCriticalSection(&context->mux);
1500 WINPR_ASSERT(context->GetSurfaceData);
1501 surface = (gdiGfxSurface*)context->GetSurfaceData(context, cacheToSurface->surfaceId);
1503 WINPR_ASSERT(context->GetCacheSlotData);
1504 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheToSurface->cacheSlot);
1506 if (!surface || !cacheEntry)
1509 for (UINT16 index = 0; index < cacheToSurface->destPtsCount; index++)
1513 (UINT16)MIN(UINT16_MAX, destPt->x + cacheEntry->width),
1514 (UINT16)MIN(UINT16_MAX, destPt->y + cacheEntry->height) };
1516 if (rectangle_is_empty(&rect))
1519 if (!is_rect_valid(&rect, surface->width, surface->height))
1522 if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline,
1523 destPt->x, destPt->y, cacheEntry->width,
1524 cacheEntry->height, cacheEntry->data, cacheEntry->format,
1525 cacheEntry->scanline, 0, 0, NULL, FREERDP_FLIP_NONE))
1529 region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect);
1530 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1531 surface->surfaceId, 1, &invalidRect);
1533 if (status != CHANNEL_RC_OK)
1537 LeaveCriticalSection(&context->mux);
1539 return gdi_interFrameUpdate(gdi, context);
1542 LeaveCriticalSection(&context->mux);
1551 static UINT gdi_CacheImportReply(RdpgfxClientContext* context,
1555 const UINT16* slots = NULL;
1556 UINT error = CHANNEL_RC_OK;
1558 slots = cacheImportReply->cacheSlots;
1559 count = cacheImportReply->importedEntriesCount;
1561 for (UINT16 index = 0; index < count; index++)
1563 UINT16 cacheSlot = slots[index];
1568 WINPR_ASSERT(context->GetCacheSlotData);
1569 gdiGfxCacheEntry* cacheEntry =
1570 (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1575 cacheEntry = gdi_GfxCacheEntryNew(cacheSlot, 0, 0, PIXEL_FORMAT_BGRX32);
1578 return ERROR_INTERNAL_ERROR;
1580 WINPR_ASSERT(context->SetCacheSlotData);
1581 error = context->SetCacheSlotData(context, cacheSlot, (
void*)cacheEntry);
1585 WLog_ERR(TAG,
"CacheImportReply: SetCacheSlotData failed with error %" PRIu32
"",
1587 gdi_GfxCacheEntryFree(cacheEntry);
1595 static UINT gdi_ImportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1598 UINT error = ERROR_INTERNAL_ERROR;
1599 gdiGfxCacheEntry* cacheEntry = NULL;
1602 return CHANNEL_RC_OK;
1604 cacheEntry = gdi_GfxCacheEntryNew(importCacheEntry->key64, importCacheEntry->width,
1605 importCacheEntry->height, PIXEL_FORMAT_BGRX32);
1610 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1611 0, 0, cacheEntry->width, cacheEntry->height,
1612 importCacheEntry->data, PIXEL_FORMAT_BGRX32, 0, 0, 0, NULL,
1617 WINPR_ASSERT(context->EvictCacheEntry);
1618 error = context->EvictCacheEntry(context, &evict);
1619 if (error != CHANNEL_RC_OK)
1622 WINPR_ASSERT(context->SetCacheSlotData);
1623 error = context->SetCacheSlotData(context, cacheSlot, (
void*)cacheEntry);
1628 gdi_GfxCacheEntryFree(cacheEntry);
1629 WLog_ERR(TAG,
"ImportCacheEntry: SetCacheSlotData failed with error %" PRIu32
"", error);
1635 static UINT gdi_ExportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1638 gdiGfxCacheEntry* cacheEntry = NULL;
1640 WINPR_ASSERT(context->GetCacheSlotData);
1641 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1645 exportCacheEntry->key64 = cacheEntry->cacheKey;
1646 exportCacheEntry->width = (UINT16)MIN(UINT16_MAX, cacheEntry->width);
1647 exportCacheEntry->height = (UINT16)MIN(UINT16_MAX, cacheEntry->height);
1648 exportCacheEntry->size = cacheEntry->width * cacheEntry->height * 4;
1649 exportCacheEntry->flags = 0;
1650 exportCacheEntry->data = cacheEntry->data;
1651 return CHANNEL_RC_OK;
1654 return ERROR_NOT_FOUND;
1662 static UINT gdi_EvictCacheEntry(RdpgfxClientContext* context,
1665 gdiGfxCacheEntry* cacheEntry = NULL;
1666 UINT rc = ERROR_NOT_FOUND;
1668 WINPR_ASSERT(context);
1669 WINPR_ASSERT(evictCacheEntry);
1671 EnterCriticalSection(&context->mux);
1673 WINPR_ASSERT(context->GetCacheSlotData);
1674 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, evictCacheEntry->cacheSlot);
1676 gdi_GfxCacheEntryFree(cacheEntry);
1678 WINPR_ASSERT(context->SetCacheSlotData);
1679 rc = context->SetCacheSlotData(context, evictCacheEntry->cacheSlot, NULL);
1680 LeaveCriticalSection(&context->mux);
1689 static UINT gdi_MapSurfaceToOutput(RdpgfxClientContext* context,
1692 UINT rc = ERROR_INTERNAL_ERROR;
1693 gdiGfxSurface* surface = NULL;
1694 EnterCriticalSection(&context->mux);
1696 WINPR_ASSERT(context->GetSurfaceData);
1697 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1702 if (surface->windowMapped)
1704 WLog_WARN(TAG,
"surface already windowMapped when trying to set outputMapped");
1708 surface->outputMapped = TRUE;
1709 surface->outputOriginX = surfaceToOutput->outputOriginX;
1710 surface->outputOriginY = surfaceToOutput->outputOriginY;
1711 surface->outputTargetWidth = surface->mappedWidth;
1712 surface->outputTargetHeight = surface->mappedHeight;
1713 region16_clear(&surface->invalidRegion);
1716 LeaveCriticalSection(&context->mux);
1721 gdi_MapSurfaceToScaledOutput(RdpgfxClientContext* context,
1724 UINT rc = ERROR_INTERNAL_ERROR;
1725 gdiGfxSurface* surface = NULL;
1726 EnterCriticalSection(&context->mux);
1728 WINPR_ASSERT(context->GetSurfaceData);
1729 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1734 if (surface->windowMapped)
1736 WLog_WARN(TAG,
"surface already windowMapped when trying to set outputMapped");
1740 surface->outputMapped = TRUE;
1741 surface->outputOriginX = surfaceToOutput->outputOriginX;
1742 surface->outputOriginY = surfaceToOutput->outputOriginY;
1743 surface->outputTargetWidth = surfaceToOutput->targetWidth;
1744 surface->outputTargetHeight = surfaceToOutput->targetHeight;
1745 region16_clear(&surface->invalidRegion);
1748 LeaveCriticalSection(&context->mux);
1757 static UINT gdi_MapSurfaceToWindow(RdpgfxClientContext* context,
1760 UINT rc = ERROR_INTERNAL_ERROR;
1761 gdiGfxSurface* surface = NULL;
1762 EnterCriticalSection(&context->mux);
1764 WINPR_ASSERT(context->GetSurfaceData);
1765 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1770 if (surface->outputMapped)
1772 WLog_WARN(TAG,
"surface already outputMapped when trying to set windowMapped");
1776 if (surface->windowMapped)
1778 if (surface->windowId != surfaceToWindow->windowId)
1780 WLog_WARN(TAG,
"surface windowId mismatch, has %" PRIu64
", expected %" PRIu64,
1781 surface->windowId, surfaceToWindow->windowId);
1785 surface->windowMapped = TRUE;
1787 surface->windowId = surfaceToWindow->windowId;
1788 surface->mappedWidth = surfaceToWindow->mappedWidth;
1789 surface->mappedHeight = surfaceToWindow->mappedHeight;
1790 surface->outputTargetWidth = surfaceToWindow->mappedWidth;
1791 surface->outputTargetHeight = surfaceToWindow->mappedHeight;
1792 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1793 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1795 LeaveCriticalSection(&context->mux);
1800 gdi_MapSurfaceToScaledWindow(RdpgfxClientContext* context,
1803 UINT rc = ERROR_INTERNAL_ERROR;
1804 gdiGfxSurface* surface = NULL;
1805 EnterCriticalSection(&context->mux);
1807 WINPR_ASSERT(context->GetSurfaceData);
1808 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1813 if (surface->outputMapped)
1815 WLog_WARN(TAG,
"surface already outputMapped when trying to set windowMapped");
1819 if (surface->windowMapped)
1821 if (surface->windowId != surfaceToWindow->windowId)
1823 WLog_WARN(TAG,
"surface windowId mismatch, has %" PRIu64
", expected %" PRIu64,
1824 surface->windowId, surfaceToWindow->windowId);
1828 surface->windowMapped = TRUE;
1830 surface->windowId = surfaceToWindow->windowId;
1831 surface->mappedWidth = surfaceToWindow->mappedWidth;
1832 surface->mappedHeight = surfaceToWindow->mappedHeight;
1833 surface->outputTargetWidth = surfaceToWindow->targetWidth;
1834 surface->outputTargetHeight = surfaceToWindow->targetHeight;
1835 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1836 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1838 LeaveCriticalSection(&context->mux);
1842 BOOL gdi_graphics_pipeline_init(rdpGdi* gdi, RdpgfxClientContext* gfx)
1844 return gdi_graphics_pipeline_init_ex(gdi, gfx, NULL, NULL, NULL);
1847 BOOL gdi_graphics_pipeline_init_ex(rdpGdi* gdi, RdpgfxClientContext* gfx,
1848 pcRdpgfxMapWindowForSurface map,
1849 pcRdpgfxUnmapWindowForSurface unmap,
1850 pcRdpgfxUpdateSurfaceArea update)
1852 if (!gdi || !gfx || !gdi->context || !gdi->context->settings)
1855 rdpContext* context = gdi->context;
1856 rdpSettings* settings = context->settings;
1859 gfx->custom = (
void*)gdi;
1860 gfx->ResetGraphics = gdi_ResetGraphics;
1861 gfx->StartFrame = gdi_StartFrame;
1862 gfx->EndFrame = gdi_EndFrame;
1863 gfx->SurfaceCommand = gdi_SurfaceCommand;
1864 gfx->DeleteEncodingContext = gdi_DeleteEncodingContext;
1865 gfx->CreateSurface = gdi_CreateSurface;
1866 gfx->DeleteSurface = gdi_DeleteSurface;
1867 gfx->SolidFill = gdi_SolidFill;
1868 gfx->SurfaceToSurface = gdi_SurfaceToSurface;
1869 gfx->SurfaceToCache = gdi_SurfaceToCache;
1870 gfx->CacheToSurface = gdi_CacheToSurface;
1871 gfx->CacheImportReply = gdi_CacheImportReply;
1872 gfx->ImportCacheEntry = gdi_ImportCacheEntry;
1873 gfx->ExportCacheEntry = gdi_ExportCacheEntry;
1874 gfx->EvictCacheEntry = gdi_EvictCacheEntry;
1875 gfx->MapSurfaceToOutput = gdi_MapSurfaceToOutput;
1876 gfx->MapSurfaceToWindow = gdi_MapSurfaceToWindow;
1877 gfx->MapSurfaceToScaledOutput = gdi_MapSurfaceToScaledOutput;
1878 gfx->MapSurfaceToScaledWindow = gdi_MapSurfaceToScaledWindow;
1879 gfx->UpdateSurfaces = gdi_UpdateSurfaces;
1880 gfx->MapWindowForSurface = map;
1881 gfx->UnmapWindowForSurface = unmap;
1882 gfx->UpdateSurfaceArea = update;
1890 gfx->codecs = freerdp_client_codecs_new(flags);
1893 if (!freerdp_client_codecs_prepare(gfx->codecs, FREERDP_CODEC_ALL, w, h))
1896 InitializeCriticalSection(&gfx->mux);
1897 PROFILER_CREATE(gfx->SurfaceProfiler,
"GFX-PROFILER")
1905 gdi->graphicsReset = TRUE;
1908 gfx->UpdateSurfaceArea = NULL;
1909 gfx->UpdateSurfaces = NULL;
1910 gfx->SurfaceCommand = NULL;
1916 void gdi_graphics_pipeline_uninit(rdpGdi* gdi, RdpgfxClientContext* gfx)
1925 freerdp_client_codecs_free(gfx->codecs);
1927 DeleteCriticalSection(&gfx->mux);
1928 PROFILER_PRINT_HEADER
1929 PROFILER_PRINT(gfx->SurfaceProfiler)
1930 PROFILER_PRINT_FOOTER
1931 PROFILER_FREE(gfx->SurfaceProfiler)
1934 const
char* rdpgfx_caps_version_str(UINT32 capsVersion)
1936 switch (capsVersion)
1938 case RDPGFX_CAPVERSION_8:
1939 return "RDPGFX_CAPVERSION_8";
1940 case RDPGFX_CAPVERSION_81:
1941 return "RDPGFX_CAPVERSION_81";
1942 case RDPGFX_CAPVERSION_10:
1943 return "RDPGFX_CAPVERSION_10";
1944 case RDPGFX_CAPVERSION_101:
1945 return "RDPGFX_CAPVERSION_101";
1946 case RDPGFX_CAPVERSION_102:
1947 return "RDPGFX_CAPVERSION_102";
1948 case RDPGFX_CAPVERSION_103:
1949 return "RDPGFX_CAPVERSION_103";
1950 case RDPGFX_CAPVERSION_104:
1951 return "RDPGFX_CAPVERSION_104";
1952 case RDPGFX_CAPVERSION_105:
1953 return "RDPGFX_CAPVERSION_105";
1954 case RDPGFX_CAPVERSION_106:
1955 return "RDPGFX_CAPVERSION_106";
1956 case RDPGFX_CAPVERSION_106_ERR:
1957 return "RDPGFX_CAPVERSION_106_ERR";
1958 case RDPGFX_CAPVERSION_107:
1959 return "RDPGFX_CAPVERSION_107";
1961 return "RDPGFX_CAPVERSION_UNKNOWN";
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.
FREERDP_API UINT32 freerdp_settings_get_codecs_flags(const rdpSettings *settings)
helper function to get a mask of supported codec flags.
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 param)
Sets a UINT32 settings value.