FreeRDP/client/X11/xf_video.c

113 lines
2.9 KiB
C
Raw Normal View History

/**
* 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.
*/
#include <freerdp/client/geometry.h>
#include <freerdp/client/video.h>
2018-02-08 10:55:27 +03:00
#include <freerdp/gdi/video.h>
#include "xf_video.h"
#define TAG CLIENT_TAG("video")
typedef struct
{
VideoSurface base;
2018-02-08 09:49:50 +03:00
XImage* image;
} xfVideoSurface;
2018-02-08 09:49:50 +03:00
static VideoSurface* xfVideoCreateSurface(VideoClientContext* video, BYTE* data, UINT32 x, UINT32 y,
UINT32 width, UINT32 height)
{
2018-02-08 09:49:50 +03:00
xfContext* xfc = (xfContext*)video->custom;
xfVideoSurface* ret = calloc(1, sizeof(*ret));
if (!ret)
return NULL;
ret->base.data = data;
ret->base.x = x;
ret->base.y = y;
ret->base.w = width;
ret->base.h = height;
ret->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0,
2018-02-08 09:49:50 +03:00
(char*)data, width, height, 8, width * 4);
if (!ret->image)
{
WLog_ERR(TAG, "unable to create surface image");
free(ret);
return NULL;
}
2018-02-08 09:49:50 +03:00
return &ret->base;
}
2018-02-08 10:55:27 +03:00
static BOOL xfVideoShowSurface(VideoClientContext* video, VideoSurface* surface)
{
2018-02-08 10:55:27 +03:00
xfVideoSurface* xfSurface = (xfVideoSurface*)surface;
2018-02-08 09:49:50 +03:00
xfContext* xfc = video->custom;
#ifdef WITH_XRENDER
if (xfc->context.settings->SmartSizing
|| xfc->context.settings->MultiTouchGestures)
{
2018-02-08 10:55:27 +03:00
XPutImage(xfc->display, xfc->primary, xfc->gc, xfSurface->image,
0, 0, surface->x, surface->y, surface->w, surface->h);
xf_draw_screen(xfc, surface->x, surface->y, surface->w, surface->h);
2018-02-08 09:49:50 +03:00
}
else
#endif
{
2018-02-08 10:55:27 +03:00
XPutImage(xfc->display, xfc->drawable, xfc->gc, xfSurface->image,
2018-02-08 09:49:50 +03:00
0, 0,
2018-02-08 10:55:27 +03:00
surface->x, surface->y, surface->w, surface->h);
2018-02-08 09:49:50 +03:00
}
return TRUE;
}
2018-02-08 10:55:27 +03:00
static BOOL xfVideoDeleteSurface(VideoClientContext* video, VideoSurface* surface)
{
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);
free(surface);
return TRUE;
}
2018-02-08 09:49:50 +03:00
void xf_video_control_init(xfContext* xfc, VideoClientContext* video)
{
2018-02-08 10:55:27 +03:00
gdi_video_control_init(xfc->context.gdi, video);
video->custom = xfc;
video->createSurface = xfVideoCreateSurface;
2018-02-08 10:55:27 +03:00
video->showSurface = xfVideoShowSurface;
video->deleteSurface = xfVideoDeleteSurface;
}
2018-02-08 09:49:50 +03:00
void xf_video_control_uninit(xfContext* xfc, VideoClientContext* video)
{
2018-02-08 10:55:27 +03:00
gdi_video_control_uninit(xfc->context.gdi, video);
}