2018-02-08 10:44:46 +03:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Video Optimized Remoting Virtual Channel Extension for X11
|
|
|
|
*
|
|
|
|
* Copyright 2017 David Fort <contact@hardening-consulting.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-04-11 16:30:05 +03:00
|
|
|
#include "../core/update.h"
|
2018-02-08 10:44:46 +03:00
|
|
|
|
2021-10-18 11:18:21 +03:00
|
|
|
#include <winpr/assert.h>
|
|
|
|
|
2018-02-08 10:44:46 +03:00
|
|
|
#include <freerdp/client/geometry.h>
|
|
|
|
#include <freerdp/client/video.h>
|
|
|
|
#include <freerdp/gdi/gdi.h>
|
|
|
|
#include <freerdp/gdi/video.h>
|
2018-02-08 11:45:35 +03:00
|
|
|
#include <freerdp/gdi/region.h>
|
2018-02-08 10:44:46 +03:00
|
|
|
|
|
|
|
#define TAG FREERDP_TAG("video")
|
|
|
|
|
|
|
|
void gdi_video_geometry_init(rdpGdi* gdi, GeometryClientContext* geom)
|
|
|
|
{
|
2021-10-18 11:18:21 +03:00
|
|
|
WINPR_ASSERT(gdi);
|
|
|
|
WINPR_ASSERT(geom);
|
|
|
|
|
2018-02-08 10:44:46 +03:00
|
|
|
gdi->geometry = geom;
|
|
|
|
|
|
|
|
if (gdi->video)
|
|
|
|
{
|
|
|
|
VideoClientContext* video = gdi->video;
|
2021-10-18 11:18:21 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(video);
|
|
|
|
WINPR_ASSERT(video->setGeometry);
|
2018-02-08 10:44:46 +03:00
|
|
|
video->setGeometry(video, gdi->geometry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gdi_video_geometry_uninit(rdpGdi* gdi, GeometryClientContext* geom)
|
|
|
|
{
|
2021-10-18 16:25:32 +03:00
|
|
|
WINPR_ASSERT(gdi);
|
|
|
|
WINPR_ASSERT(geom);
|
|
|
|
WINPR_UNUSED(gdi);
|
|
|
|
WINPR_UNUSED(geom);
|
2018-02-08 10:44:46 +03:00
|
|
|
}
|
|
|
|
|
2021-10-18 11:18:21 +03:00
|
|
|
static VideoSurface* gdiVideoCreateSurface(VideoClientContext* video, UINT32 x, UINT32 y,
|
|
|
|
UINT32 width, UINT32 height)
|
2018-02-08 10:44:46 +03:00
|
|
|
{
|
2021-10-18 11:18:21 +03:00
|
|
|
return VideoClient_CreateCommonContext(sizeof(VideoSurface), x, y, width, height);
|
2018-02-08 10:44:46 +03:00
|
|
|
}
|
|
|
|
|
2021-10-18 11:18:21 +03:00
|
|
|
static BOOL gdiVideoShowSurface(VideoClientContext* video, const VideoSurface* surface,
|
|
|
|
UINT32 destinationWidth, UINT32 destinationHeight)
|
2018-02-08 10:44:46 +03:00
|
|
|
{
|
2019-04-11 16:30:05 +03:00
|
|
|
BOOL rc = FALSE;
|
2021-10-18 11:18:21 +03:00
|
|
|
rdpGdi* gdi;
|
|
|
|
rdpUpdate* update;
|
|
|
|
|
|
|
|
WINPR_ASSERT(video);
|
|
|
|
WINPR_ASSERT(surface);
|
|
|
|
|
|
|
|
gdi = (rdpGdi*)video->custom;
|
|
|
|
WINPR_ASSERT(gdi);
|
|
|
|
WINPR_ASSERT(gdi->context);
|
|
|
|
|
|
|
|
update = gdi->context->update;
|
|
|
|
WINPR_ASSERT(update);
|
|
|
|
|
2019-04-11 16:30:05 +03:00
|
|
|
if (!update_begin_paint(update))
|
|
|
|
goto fail;
|
2019-02-07 16:18:53 +03:00
|
|
|
|
|
|
|
if ((gdi->width < 0) || (gdi->height < 0))
|
2019-04-11 16:30:05 +03:00
|
|
|
goto fail;
|
2019-02-07 16:18:53 +03:00
|
|
|
else
|
2018-02-08 10:44:46 +03:00
|
|
|
{
|
2018-02-08 11:45:35 +03:00
|
|
|
const UINT32 nXSrc = surface->x;
|
|
|
|
const UINT32 nYSrc = surface->y;
|
|
|
|
const UINT32 nXDst = nXSrc;
|
|
|
|
const UINT32 nYDst = nYSrc;
|
2021-10-18 11:18:21 +03:00
|
|
|
const UINT32 width = (destinationWidth + surface->x < (UINT32)gdi->width)
|
|
|
|
? destinationWidth
|
2019-11-06 17:24:51 +03:00
|
|
|
: (UINT32)gdi->width - surface->x;
|
2021-10-18 11:18:21 +03:00
|
|
|
const UINT32 height = (destinationHeight + surface->y < (UINT32)gdi->height)
|
|
|
|
? destinationHeight
|
2019-11-06 17:24:51 +03:00
|
|
|
: (UINT32)gdi->height - surface->y;
|
|
|
|
|
2021-10-18 11:18:21 +03:00
|
|
|
WINPR_ASSERT(gdi->primary_buffer);
|
|
|
|
WINPR_ASSERT(gdi->primary);
|
|
|
|
WINPR_ASSERT(gdi->primary->hdc);
|
|
|
|
|
|
|
|
if (!freerdp_image_scale(gdi->primary_buffer, gdi->primary->hdc->format, gdi->stride, nXDst,
|
|
|
|
nYDst, width, height, surface->data, surface->format,
|
|
|
|
surface->scanline, 0, 0, surface->w, surface->h))
|
2019-04-11 16:30:05 +03:00
|
|
|
goto fail;
|
2018-02-08 10:44:46 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((nXDst > INT32_MAX) || (nYDst > INT32_MAX) || (width > INT32_MAX) ||
|
|
|
|
(height > INT32_MAX))
|
2019-04-11 16:30:05 +03:00
|
|
|
goto fail;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi_InvalidateRegion(gdi->primary->hdc, (INT32)nXDst, (INT32)nYDst, (INT32)width,
|
|
|
|
(INT32)height);
|
2018-02-08 10:44:46 +03:00
|
|
|
}
|
2019-04-11 16:30:05 +03:00
|
|
|
|
|
|
|
rc = TRUE;
|
|
|
|
fail:
|
|
|
|
|
|
|
|
if (!update_end_paint(update))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return rc;
|
2018-02-08 10:44:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL gdiVideoDeleteSurface(VideoClientContext* video, VideoSurface* surface)
|
|
|
|
{
|
2021-10-18 11:18:21 +03:00
|
|
|
WINPR_UNUSED(video);
|
|
|
|
VideoClient_DestroyCommonContext(surface);
|
2018-02-08 10:44:46 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
2021-10-18 11:18:21 +03:00
|
|
|
|
2018-02-08 10:44:46 +03:00
|
|
|
void gdi_video_control_init(rdpGdi* gdi, VideoClientContext* video)
|
|
|
|
{
|
2021-10-18 11:18:21 +03:00
|
|
|
WINPR_ASSERT(gdi);
|
|
|
|
WINPR_ASSERT(video);
|
|
|
|
|
2018-02-08 10:44:46 +03:00
|
|
|
gdi->video = video;
|
|
|
|
video->custom = gdi;
|
|
|
|
video->createSurface = gdiVideoCreateSurface;
|
|
|
|
video->showSurface = gdiVideoShowSurface;
|
|
|
|
video->deleteSurface = gdiVideoDeleteSurface;
|
|
|
|
video->setGeometry(video, gdi->geometry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gdi_video_control_uninit(rdpGdi* gdi, VideoClientContext* video)
|
|
|
|
{
|
2021-10-18 11:18:21 +03:00
|
|
|
WINPR_ASSERT(gdi);
|
2018-02-08 10:44:46 +03:00
|
|
|
gdi->video = NULL;
|
|
|
|
}
|
|
|
|
|
2022-01-19 11:08:02 +03:00
|
|
|
static void gdi_video_timer(void* context, const TimerEventArgs* timer)
|
2018-02-08 10:44:46 +03:00
|
|
|
{
|
2018-02-14 12:14:33 +03:00
|
|
|
rdpContext* ctx = (rdpContext*)context;
|
2021-10-18 11:18:21 +03:00
|
|
|
rdpGdi* gdi;
|
|
|
|
|
|
|
|
WINPR_ASSERT(ctx);
|
|
|
|
WINPR_ASSERT(timer);
|
|
|
|
|
|
|
|
gdi = ctx->gdi;
|
2018-02-08 10:44:46 +03:00
|
|
|
|
|
|
|
if (gdi && gdi->video)
|
|
|
|
gdi->video->timer(gdi->video, timer->now);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gdi_video_data_init(rdpGdi* gdi, VideoClientContext* video)
|
|
|
|
{
|
2021-10-18 11:18:21 +03:00
|
|
|
WINPR_ASSERT(gdi);
|
|
|
|
WINPR_ASSERT(gdi->context);
|
2018-02-14 12:12:32 +03:00
|
|
|
PubSub_SubscribeTimer(gdi->context->pubSub, gdi_video_timer);
|
2018-02-08 10:44:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void gdi_video_data_uninit(rdpGdi* gdi, VideoClientContext* context)
|
|
|
|
{
|
2021-10-18 11:18:21 +03:00
|
|
|
WINPR_ASSERT(gdi);
|
|
|
|
WINPR_ASSERT(gdi->context);
|
2018-02-14 12:12:32 +03:00
|
|
|
PubSub_UnsubscribeTimer(gdi->context->pubSub, gdi_video_timer);
|
2018-02-08 10:44:46 +03:00
|
|
|
}
|
2021-10-18 11:18:21 +03:00
|
|
|
|
|
|
|
VideoSurface* VideoClient_CreateCommonContext(size_t size, UINT32 x, UINT32 y, UINT32 w, UINT32 h)
|
|
|
|
{
|
|
|
|
VideoSurface* ret;
|
|
|
|
|
|
|
|
WINPR_ASSERT(size >= sizeof(VideoSurface));
|
|
|
|
|
|
|
|
ret = calloc(1, size);
|
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret->format = PIXEL_FORMAT_BGRX32;
|
|
|
|
ret->x = x;
|
|
|
|
ret->y = y;
|
|
|
|
ret->w = w;
|
|
|
|
ret->h = h;
|
|
|
|
ret->alignedWidth = ret->w + 32 - ret->w % 16;
|
|
|
|
ret->alignedHeight = ret->h + 32 - ret->h % 16;
|
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
ret->scanline = ret->alignedWidth * FreeRDPGetBytesPerPixel(ret->format);
|
2022-05-11 12:28:55 +03:00
|
|
|
ret->data = winpr_aligned_malloc(ret->scanline * ret->alignedHeight * 1ULL, 64);
|
2021-10-18 11:18:21 +03:00
|
|
|
if (!ret->data)
|
|
|
|
goto fail;
|
|
|
|
return ret;
|
|
|
|
fail:
|
|
|
|
VideoClient_DestroyCommonContext(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoClient_DestroyCommonContext(VideoSurface* surface)
|
|
|
|
{
|
|
|
|
if (!surface)
|
|
|
|
return;
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(surface->data);
|
2021-10-18 11:18:21 +03:00
|
|
|
free(surface);
|
|
|
|
}
|