FreeRDP
xf_video.c
1 
20 #include <winpr/assert.h>
21 #include <freerdp/client/geometry.h>
22 #include <freerdp/client/video.h>
23 #include <freerdp/gdi/video.h>
24 
25 #include "xf_video.h"
26 
27 #include <freerdp/log.h>
28 #define TAG CLIENT_TAG("video")
29 
30 typedef struct
31 {
32  VideoSurface base;
33  XImage* image;
34 } xfVideoSurface;
35 
36 static VideoSurface* xfVideoCreateSurface(VideoClientContext* video, UINT32 x, UINT32 y,
37  UINT32 width, UINT32 height)
38 {
39  xfContext* xfc = NULL;
40  xfVideoSurface* ret = NULL;
41 
42  WINPR_ASSERT(video);
43  ret = (xfVideoSurface*)VideoClient_CreateCommonContext(sizeof(xfContext), x, y, width, height);
44  if (!ret)
45  return NULL;
46 
47  xfc = (xfContext*)video->custom;
48  WINPR_ASSERT(xfc);
49 
50  ret->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0,
51  (char*)ret->base.data, width, height, 8, ret->base.scanline);
52 
53  if (!ret->image)
54  {
55  WLog_ERR(TAG, "unable to create surface image");
56  VideoClient_DestroyCommonContext(&ret->base);
57  return NULL;
58  }
59 
60  return &ret->base;
61 }
62 
63 static BOOL xfVideoShowSurface(VideoClientContext* video, const VideoSurface* surface,
64  UINT32 destinationWidth, UINT32 destinationHeight)
65 {
66  const xfVideoSurface* xfSurface = (const xfVideoSurface*)surface;
67  xfContext* xfc = NULL;
68  const rdpSettings* settings = NULL;
69 
70  WINPR_ASSERT(video);
71  WINPR_ASSERT(xfSurface);
72 
73  xfc = video->custom;
74  WINPR_ASSERT(xfc);
75 
76  settings = xfc->common.context.settings;
77  WINPR_ASSERT(settings);
78 
79 #ifdef WITH_XRENDER
80 
81  if (freerdp_settings_get_bool(settings, FreeRDP_SmartSizing) ||
82  freerdp_settings_get_bool(settings, FreeRDP_MultiTouchGestures))
83  {
84  XPutImage(xfc->display, xfc->primary, xfc->gc, xfSurface->image, 0, 0, surface->x,
85  surface->y, surface->w, surface->h);
86  xf_draw_screen(xfc, surface->x, surface->y, surface->w, surface->h);
87  }
88  else
89 #endif
90  {
91  XPutImage(xfc->display, xfc->drawable, xfc->gc, xfSurface->image, 0, 0, surface->x,
92  surface->y, surface->w, surface->h);
93  }
94 
95  return TRUE;
96 }
97 
98 static BOOL xfVideoDeleteSurface(VideoClientContext* video, VideoSurface* surface)
99 {
100  xfVideoSurface* xfSurface = (xfVideoSurface*)surface;
101 
102  WINPR_UNUSED(video);
103 
104  if (xfSurface)
105  XFree(xfSurface->image);
106 
107  VideoClient_DestroyCommonContext(surface);
108  return TRUE;
109 }
110 
111 void xf_video_control_init(xfContext* xfc, VideoClientContext* video)
112 {
113  WINPR_ASSERT(xfc);
114  WINPR_ASSERT(video);
115 
116  gdi_video_control_init(xfc->common.context.gdi, video);
117 
118  /* X11 needs to be able to handle 32bpp colors directly. */
119  if (xfc->depth >= 24)
120  {
121  video->custom = xfc;
122  video->createSurface = xfVideoCreateSurface;
123  video->showSurface = xfVideoShowSurface;
124  video->deleteSurface = xfVideoDeleteSurface;
125  }
126 }
127 
128 void xf_video_control_uninit(xfContext* xfc, VideoClientContext* video)
129 {
130  WINPR_ASSERT(xfc);
131  gdi_video_control_uninit(xfc->common.context.gdi, video);
132 }
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.
an implementation of surface used by the video channel
Definition: client/video.h:36