2017-12-15 13:15:24 +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.
|
|
|
|
*/
|
2018-02-02 12:32:21 +03:00
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
#include <winpr/assert.h>
|
2017-12-15 13:15:24 +03:00
|
|
|
#include <freerdp/client/geometry.h>
|
|
|
|
#include <freerdp/client/video.h>
|
2018-02-08 10:55:27 +03:00
|
|
|
#include <freerdp/gdi/video.h>
|
2017-12-15 13:15:24 +03:00
|
|
|
|
|
|
|
#include "xf_video.h"
|
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
#include <freerdp/log.h>
|
2017-12-15 13:15:24 +03:00
|
|
|
#define TAG CLIENT_TAG("video")
|
|
|
|
|
2018-02-02 12:32:21 +03:00
|
|
|
typedef struct
|
2017-12-15 13:15:24 +03:00
|
|
|
{
|
2018-02-02 12:32:21 +03:00
|
|
|
VideoSurface base;
|
2018-02-08 09:49:50 +03:00
|
|
|
XImage* image;
|
2018-02-02 12:32:21 +03:00
|
|
|
} xfVideoSurface;
|
2017-12-15 13:15:24 +03:00
|
|
|
|
2021-10-18 11:18:21 +03:00
|
|
|
static VideoSurface* xfVideoCreateSurface(VideoClientContext* video, UINT32 x, UINT32 y,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32 width, UINT32 height)
|
2017-12-15 13:15:24 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
xfContext* xfc = NULL;
|
|
|
|
xfVideoSurface* ret = NULL;
|
2018-02-08 09:49:50 +03:00
|
|
|
|
2021-10-18 11:18:21 +03:00
|
|
|
WINPR_ASSERT(video);
|
|
|
|
ret = (xfVideoSurface*)VideoClient_CreateCommonContext(sizeof(xfContext), x, y, width, height);
|
2017-12-15 13:15:24 +03:00
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
2021-10-18 11:18:21 +03:00
|
|
|
xfc = (xfContext*)video->custom;
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
|
|
|
|
ret->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0,
|
|
|
|
(char*)ret->base.data, width, height, 8, ret->base.scanline);
|
2018-02-08 09:49:50 +03:00
|
|
|
|
2018-02-02 12:32:21 +03:00
|
|
|
if (!ret->image)
|
2017-12-15 13:15:24 +03:00
|
|
|
{
|
2018-02-02 12:32:21 +03:00
|
|
|
WLog_ERR(TAG, "unable to create surface image");
|
2021-10-18 11:18:21 +03:00
|
|
|
VideoClient_DestroyCommonContext(&ret->base);
|
2017-12-15 13:15:24 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-02-08 09:49:50 +03:00
|
|
|
|
2018-02-02 12:32:21 +03:00
|
|
|
return &ret->base;
|
2017-12-15 13:15:24 +03:00
|
|
|
}
|
|
|
|
|
2021-10-18 11:18:21 +03:00
|
|
|
static BOOL xfVideoShowSurface(VideoClientContext* video, const VideoSurface* surface,
|
|
|
|
UINT32 destinationWidth, UINT32 destinationHeight)
|
2017-12-15 13:15:24 +03:00
|
|
|
{
|
2021-10-18 11:18:21 +03:00
|
|
|
const xfVideoSurface* xfSurface = (const xfVideoSurface*)surface;
|
2024-01-23 18:49:54 +03:00
|
|
|
xfContext* xfc = NULL;
|
|
|
|
const rdpSettings* settings = NULL;
|
2021-10-18 11:18:21 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(video);
|
|
|
|
WINPR_ASSERT(xfSurface);
|
|
|
|
|
|
|
|
xfc = video->custom;
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
settings = xfc->common.context.settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2018-02-08 09:49:50 +03:00
|
|
|
#ifdef WITH_XRENDER
|
|
|
|
|
2023-10-13 10:48:44 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_SmartSizing) ||
|
|
|
|
freerdp_settings_get_bool(settings, FreeRDP_MultiTouchGestures))
|
2018-02-08 09:49:50 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
XPutImage(xfc->display, xfc->primary, xfc->gc, xfSurface->image, 0, 0, surface->x,
|
|
|
|
surface->y, surface->w, surface->h);
|
2018-02-08 10:55:27 +03:00
|
|
|
xf_draw_screen(xfc, surface->x, surface->y, surface->w, surface->h);
|
2018-02-08 09:49:50 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
XPutImage(xfc->display, xfc->drawable, xfc->gc, xfSurface->image, 0, 0, surface->x,
|
|
|
|
surface->y, surface->w, surface->h);
|
2018-02-08 09:49:50 +03:00
|
|
|
}
|
2017-12-15 13:15:24 +03:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-02-08 10:55:27 +03:00
|
|
|
static BOOL xfVideoDeleteSurface(VideoClientContext* video, VideoSurface* surface)
|
2017-12-15 13:15:24 +03:00
|
|
|
{
|
2018-02-08 10:55:27 +03:00
|
|
|
xfVideoSurface* xfSurface = (xfVideoSurface*)surface;
|
|
|
|
|
2019-02-07 19:53:21 +03:00
|
|
|
WINPR_UNUSED(video);
|
|
|
|
|
2018-02-08 10:55:27 +03:00
|
|
|
if (xfSurface)
|
|
|
|
XFree(xfSurface->image);
|
|
|
|
|
2021-10-18 11:18:21 +03:00
|
|
|
VideoClient_DestroyCommonContext(surface);
|
2017-12-15 13:15:24 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
2021-10-18 11:18:21 +03:00
|
|
|
|
2018-02-08 09:49:50 +03:00
|
|
|
void xf_video_control_init(xfContext* xfc, VideoClientContext* video)
|
2017-12-15 13:15:24 +03:00
|
|
|
{
|
2021-10-18 11:18:21 +03:00
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
WINPR_ASSERT(video);
|
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
gdi_video_control_init(xfc->common.context.gdi, video);
|
2021-10-18 11:18:21 +03:00
|
|
|
|
|
|
|
/* X11 needs to be able to handle 32bpp colors directly. */
|
|
|
|
if (xfc->depth >= 24)
|
|
|
|
{
|
|
|
|
video->custom = xfc;
|
|
|
|
video->createSurface = xfVideoCreateSurface;
|
|
|
|
video->showSurface = xfVideoShowSurface;
|
|
|
|
video->deleteSurface = xfVideoDeleteSurface;
|
|
|
|
}
|
2017-12-15 13:15:24 +03:00
|
|
|
}
|
|
|
|
|
2018-02-08 09:49:50 +03:00
|
|
|
void xf_video_control_uninit(xfContext* xfc, VideoClientContext* video)
|
2018-01-23 18:09:21 +03:00
|
|
|
{
|
2022-01-19 11:27:39 +03:00
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
gdi_video_control_uninit(xfc->common.context.gdi, video);
|
2017-12-15 13:15:24 +03:00
|
|
|
}
|