20#include "../core/update.h"
22#include <winpr/assert.h>
24#include <freerdp/client/geometry.h>
25#include <freerdp/client/video.h>
26#include <freerdp/gdi/gdi.h>
27#include <freerdp/gdi/video.h>
28#include <freerdp/gdi/region.h>
30void gdi_video_geometry_init(rdpGdi* gdi, GeometryClientContext* geom)
36 if (gdi->geometry != geom)
37 gdi->geometryInstances = 0;
38 gdi->geometryInstances++;
43 VideoClientContext* video = gdi->video;
46 WINPR_ASSERT(video->setGeometry);
47 video->setGeometry(video, gdi->geometry);
51void gdi_video_geometry_uninit(rdpGdi* gdi, GeometryClientContext* geom)
56 if (gdi->geometry != geom)
59 if (gdi->geometryInstances > 0)
60 gdi->geometryInstances--;
61 if (gdi->geometryInstances > 0)
67 gdi->geometry =
nullptr;
71 VideoClientContext* video = gdi->video;
74 WINPR_ASSERT(video->setGeometry);
75 video->setGeometry(video,
nullptr);
79static VideoSurface* gdiVideoCreateSurface(WINPR_ATTR_UNUSED VideoClientContext* video, UINT32 x,
80 UINT32 y, UINT32 width, UINT32 height)
82 return VideoClient_CreateCommonContext(
sizeof(
VideoSurface), x, y, width, height);
85static BOOL gdiVideoShowSurface(VideoClientContext* video,
const VideoSurface* surface,
86 UINT32 destinationWidth, UINT32 destinationHeight)
89 rdpGdi* gdi =
nullptr;
90 rdpUpdate* update =
nullptr;
93 WINPR_ASSERT(surface);
95 gdi = (rdpGdi*)video->custom;
97 WINPR_ASSERT(gdi->context);
99 update = gdi->context->update;
100 WINPR_ASSERT(update);
102 if (!update_begin_paint(update))
105 if ((gdi->width < 0) || (gdi->height < 0))
110 if ((surface->x >= (UINT32)gdi->width) || (surface->y >= (UINT32)gdi->height))
114 const UINT32 nXSrc = surface->x;
115 const UINT32 nYSrc = surface->y;
116 const UINT32 nXDst = nXSrc;
117 const UINT32 nYDst = nYSrc;
118 const UINT32 width = MIN(destinationWidth, (UINT32)gdi->width - surface->x);
119 const UINT32 height = MIN(destinationHeight, (UINT32)gdi->height - surface->y);
121 WINPR_ASSERT(gdi->primary_buffer);
122 WINPR_ASSERT(gdi->primary);
123 WINPR_ASSERT(gdi->primary->hdc);
125 if (!freerdp_image_scale(gdi->primary_buffer, gdi->primary->hdc->format, gdi->stride, nXDst,
126 nYDst, width, height, surface->data, surface->format,
127 surface->scanline, 0, 0, surface->w, surface->h))
130 if ((nXDst > INT32_MAX) || (nYDst > INT32_MAX) || (width > INT32_MAX) ||
131 (height > INT32_MAX))
134 rc = gdi_InvalidateRegion(gdi->primary->hdc, (INT32)nXDst, (INT32)nYDst, (INT32)width,
139 if (!update_end_paint(update))
145static BOOL gdiVideoDeleteSurface(VideoClientContext* video,
VideoSurface* surface)
148 VideoClient_DestroyCommonContext(surface);
152void gdi_video_control_init(rdpGdi* gdi, VideoClientContext* video)
159 video->createSurface = gdiVideoCreateSurface;
160 video->showSurface = gdiVideoShowSurface;
161 video->deleteSurface = gdiVideoDeleteSurface;
162 video->setGeometry(video, gdi->geometry);
165void gdi_video_control_uninit(rdpGdi* gdi, WINPR_ATTR_UNUSED VideoClientContext* video)
168 gdi->video =
nullptr;
171void gdi_video_data_init(WINPR_ATTR_UNUSED rdpGdi* gdi, WINPR_ATTR_UNUSED VideoClientContext* video)
174 WINPR_ASSERT(gdi->context);
177void gdi_video_data_uninit(WINPR_ATTR_UNUSED rdpGdi* gdi,
178 WINPR_ATTR_UNUSED VideoClientContext* context)
181 WINPR_ASSERT(gdi->context);
184VideoSurface* VideoClient_CreateCommonContext(
size_t size, UINT32 x, UINT32 y, UINT32 w, UINT32 h)
186 if ((w == 0) || (h == 0))
191 const UINT32 alignedWidth = w + 32 - w % 16;
192 const UINT32 alignedHeight = h + 32 - h % 16;
193 if ((alignedWidth > UINT16_MAX) || (alignedHeight > UINT16_MAX))
200 ret->format = PIXEL_FORMAT_BGRX32;
205 ret->alignedWidth = alignedWidth;
206 ret->alignedHeight = alignedHeight;
208 ret->scanline = ret->alignedWidth * FreeRDPGetBytesPerPixel(ret->format);
209 ret->data = winpr_aligned_calloc(ret->scanline, ret->alignedHeight, 64);
214 VideoClient_DestroyCommonContext(ret);
218void VideoClient_DestroyCommonContext(
VideoSurface* surface)
222 winpr_aligned_free(surface->data);
an implementation of surface used by the video channel