2014-06-05 02:03:25 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* X11 Graphics Pipeline
|
|
|
|
*
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2016-04-05 18:07:45 +03:00
|
|
|
* Copyright 2016 Armin Novak <armin.novak@thincast.com>
|
|
|
|
* Copyright 2016 Thincast Technologies GmbH
|
2014-06-05 02:03:25 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#include <freerdp/log.h>
|
2014-06-05 02:03:25 +04:00
|
|
|
#include "xf_gfx.h"
|
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#define TAG CLIENT_TAG("x11")
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static UINT xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface)
|
2014-06-05 02:03:25 +04:00
|
|
|
{
|
2014-06-05 06:49:03 +04:00
|
|
|
UINT16 width, height;
|
2015-02-07 01:46:15 +03:00
|
|
|
UINT32 surfaceX, surfaceY;
|
2014-06-05 20:36:01 +04:00
|
|
|
RECTANGLE_16 surfaceRect;
|
2014-06-05 06:49:03 +04:00
|
|
|
const RECTANGLE_16* extents;
|
2016-08-03 15:16:20 +03:00
|
|
|
rdpGdi* gdi;
|
|
|
|
gdi = xfc->context.gdi;
|
2016-04-05 18:07:45 +03:00
|
|
|
surfaceX = surface->gdi.outputOriginX;
|
|
|
|
surfaceY = surface->gdi.outputOriginY;
|
2015-02-07 01:46:15 +03:00
|
|
|
surfaceRect.left = surfaceX;
|
|
|
|
surfaceRect.top = surfaceY;
|
2016-04-05 18:07:45 +03:00
|
|
|
surfaceRect.right = surfaceX + surface->gdi.width;
|
|
|
|
surfaceRect.bottom = surfaceY + surface->gdi.height;
|
2014-06-13 00:13:12 +04:00
|
|
|
XSetClipMask(xfc->display, xfc->gc, None);
|
|
|
|
XSetFunction(xfc->display, xfc->gc, GXcopy);
|
|
|
|
XSetFillStyle(xfc->display, xfc->gc, FillSolid);
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!region16_is_empty(&surface->gdi.invalidRegion))
|
2014-06-05 06:49:03 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
extents = region16_extents(&surface->gdi.invalidRegion);
|
2014-06-20 01:08:50 +04:00
|
|
|
width = extents->right - extents->left;
|
|
|
|
height = extents->bottom - extents->top;
|
2014-06-05 06:49:03 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (width > surface->gdi.width)
|
|
|
|
width = surface->gdi.width;
|
2014-06-05 20:36:01 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (height > surface->gdi.height)
|
|
|
|
height = surface->gdi.height;
|
2014-06-05 20:36:01 +04:00
|
|
|
|
2014-09-17 22:29:56 +04:00
|
|
|
if (surface->stage)
|
|
|
|
{
|
2016-08-03 15:16:20 +03:00
|
|
|
freerdp_image_copy(surface->stage, gdi->dstFormat,
|
2016-07-14 17:08:06 +03:00
|
|
|
surface->stageScanline, 0, 0,
|
|
|
|
surface->gdi.width, surface->gdi.height,
|
|
|
|
surface->gdi.data, surface->gdi.format,
|
2016-10-14 11:01:02 +03:00
|
|
|
surface->gdi.scanline, 0, 0, NULL, FREERDP_FLIP_NONE);
|
2014-09-17 22:29:56 +04:00
|
|
|
}
|
|
|
|
|
2014-12-01 13:56:44 +03:00
|
|
|
#ifdef WITH_XRENDER
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2016-08-03 15:16:20 +03:00
|
|
|
if (xfc->context.settings->SmartSizing
|
|
|
|
|| xfc->context.settings->MultiTouchGestures)
|
2014-12-01 13:56:44 +03:00
|
|
|
{
|
|
|
|
XPutImage(xfc->display, xfc->primary, xfc->gc, surface->image,
|
2016-07-14 17:08:06 +03:00
|
|
|
extents->left, extents->top, extents->left + surfaceX, extents->top + surfaceY,
|
|
|
|
width, height);
|
2014-12-01 13:56:44 +03:00
|
|
|
xf_draw_screen(xfc, extents->left, extents->top, width, height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
XPutImage(xfc->display, xfc->drawable, xfc->gc,
|
2016-07-14 17:08:06 +03:00
|
|
|
surface->image, extents->left, extents->top,
|
|
|
|
extents->left + surfaceX, extents->top + surfaceY,
|
|
|
|
width, height);
|
2014-12-01 13:56:44 +03:00
|
|
|
}
|
2014-06-05 06:49:03 +04:00
|
|
|
}
|
2014-06-05 20:36:01 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
region16_clear(&surface->gdi.invalidRegion);
|
2014-06-13 00:13:12 +04:00
|
|
|
XSetClipMask(xfc->display, xfc->gc, None);
|
2015-06-30 12:41:23 +03:00
|
|
|
XSync(xfc->display, False);
|
2016-04-05 18:07:45 +03:00
|
|
|
return 0;
|
2014-06-05 20:36:01 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static UINT xf_UpdateSurfaces(RdpgfxClientContext* context)
|
2015-02-07 01:46:15 +03:00
|
|
|
{
|
2015-06-09 16:22:26 +03:00
|
|
|
UINT16 count;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 index;
|
|
|
|
UINT status = CHANNEL_RC_OK;
|
2015-02-11 00:32:07 +03:00
|
|
|
xfGfxSurface* surface;
|
|
|
|
UINT16* pSurfaceIds = NULL;
|
2016-07-13 15:58:11 +03:00
|
|
|
rdpGdi* gdi = (rdpGdi*)context->custom;
|
|
|
|
xfContext* xfc = (xfContext*) gdi->context;
|
2015-02-07 01:46:15 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!gdi)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (!gdi->graphicsReset)
|
|
|
|
return status;
|
2015-02-07 01:46:15 +03:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
context->GetSurfaceIds(context, &pSurfaceIds, &count);
|
2015-02-07 01:46:15 +03:00
|
|
|
|
2015-02-11 00:32:07 +03:00
|
|
|
for (index = 0; index < count; index++)
|
2015-02-07 01:46:15 +03:00
|
|
|
{
|
2015-02-11 00:32:07 +03:00
|
|
|
surface = (xfGfxSurface*) context->GetSurfaceData(context, pSurfaceIds[index]);
|
2015-02-07 01:46:15 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!surface || !surface->gdi.outputMapped)
|
2015-02-11 00:32:07 +03:00
|
|
|
continue;
|
2015-02-07 01:46:15 +03:00
|
|
|
|
2015-02-11 00:32:07 +03:00
|
|
|
status = xf_OutputUpdate(xfc, surface);
|
2015-02-07 01:46:15 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (status != 0)
|
2015-02-11 00:32:07 +03:00
|
|
|
break;
|
2015-02-07 01:46:15 +03:00
|
|
|
}
|
|
|
|
|
2015-02-11 00:32:07 +03:00
|
|
|
free(pSurfaceIds);
|
|
|
|
return status;
|
2015-02-07 01:46:15 +03:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT xf_OutputExpose(xfContext* xfc, UINT32 x, UINT32 y,
|
2016-07-14 17:08:06 +03:00
|
|
|
UINT32 width, UINT32 height)
|
2014-06-13 00:13:12 +04:00
|
|
|
{
|
2015-06-09 16:22:26 +03:00
|
|
|
UINT16 count;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 index;
|
|
|
|
UINT status = CHANNEL_RC_OK;
|
2015-02-11 00:32:07 +03:00
|
|
|
xfGfxSurface* surface;
|
2014-06-13 00:13:12 +04:00
|
|
|
RECTANGLE_16 invalidRect;
|
2015-02-11 00:32:07 +03:00
|
|
|
RECTANGLE_16 surfaceRect;
|
|
|
|
RECTANGLE_16 intersection;
|
|
|
|
UINT16* pSurfaceIds = NULL;
|
|
|
|
RdpgfxClientContext* context = xfc->gfx;
|
2014-06-13 00:13:12 +04:00
|
|
|
invalidRect.left = x;
|
|
|
|
invalidRect.top = y;
|
2014-06-20 01:08:50 +04:00
|
|
|
invalidRect.right = x + width;
|
|
|
|
invalidRect.bottom = y + height;
|
2015-06-09 16:22:26 +03:00
|
|
|
context->GetSurfaceIds(context, &pSurfaceIds, &count);
|
2015-02-11 00:32:07 +03:00
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
|
|
|
{
|
|
|
|
surface = (xfGfxSurface*) context->GetSurfaceData(context, pSurfaceIds[index]);
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!surface || !surface->gdi.outputMapped)
|
2015-02-11 00:32:07 +03:00
|
|
|
continue;
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
surfaceRect.left = surface->gdi.outputOriginX;
|
|
|
|
surfaceRect.top = surface->gdi.outputOriginY;
|
|
|
|
surfaceRect.right = surface->gdi.outputOriginX + surface->gdi.width;
|
|
|
|
surfaceRect.bottom = surface->gdi.outputOriginY + surface->gdi.height;
|
2015-02-11 00:32:07 +03:00
|
|
|
|
|
|
|
if (rectangles_intersection(&invalidRect, &surfaceRect, &intersection))
|
|
|
|
{
|
|
|
|
/* Invalid rects are specified relative to surface origin */
|
|
|
|
intersection.left -= surfaceRect.left;
|
|
|
|
intersection.top -= surfaceRect.top;
|
|
|
|
intersection.right -= surfaceRect.left;
|
|
|
|
intersection.bottom -= surfaceRect.top;
|
2016-04-05 18:07:45 +03:00
|
|
|
region16_union_rect(&surface->gdi.invalidRegion,
|
2016-07-14 17:08:06 +03:00
|
|
|
&surface->gdi.invalidRegion,
|
|
|
|
&intersection);
|
2015-02-11 00:32:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pSurfaceIds);
|
2016-04-05 18:07:45 +03:00
|
|
|
IFCALLRET(context->UpdateSurfaces, status, context);
|
2015-02-07 01:46:15 +03:00
|
|
|
return status;
|
2014-06-13 00:13:12 +04:00
|
|
|
}
|
|
|
|
|
2016-11-24 11:02:06 +03:00
|
|
|
static INLINE UINT32 x11_pad_scanline(UINT32 scanline, UINT32 inPad)
|
|
|
|
{
|
|
|
|
if (inPad > 0)
|
|
|
|
{
|
|
|
|
const UINT32 align = inPad / 8;
|
|
|
|
const UINT32 pad = align - scanline % align;
|
|
|
|
|
|
|
|
if (align != pad)
|
|
|
|
scanline += pad;
|
|
|
|
}
|
|
|
|
|
|
|
|
return scanline;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-05 18:07:45 +03:00
|
|
|
static UINT xf_CreateSurface(RdpgfxClientContext* context,
|
2016-07-14 17:08:06 +03:00
|
|
|
const RDPGFX_CREATE_SURFACE_PDU* createSurface)
|
2014-06-05 02:03:25 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
size_t size;
|
2014-06-13 00:13:12 +04:00
|
|
|
xfGfxSurface* surface;
|
2016-07-13 15:58:11 +03:00
|
|
|
rdpGdi* gdi = (rdpGdi*)context->custom;
|
|
|
|
xfContext* xfc = (xfContext*) gdi->context;
|
2016-04-05 18:07:45 +03:00
|
|
|
surface = (xfGfxSurface*) calloc(1, sizeof(xfGfxSurface));
|
2014-06-13 00:13:12 +04:00
|
|
|
|
|
|
|
if (!surface)
|
2016-04-05 18:07:45 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2014-06-05 02:03:25 +04:00
|
|
|
|
2016-12-06 18:44:00 +03:00
|
|
|
surface->gdi.codecs = gdi->context->codecs;
|
2014-06-13 02:23:51 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!surface->gdi.codecs)
|
2014-06-05 02:03:25 +04:00
|
|
|
{
|
2016-07-14 17:08:06 +03:00
|
|
|
free(surface);
|
2016-04-05 18:07:45 +03:00
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2014-06-05 02:03:25 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
surface->gdi.surfaceId = createSurface->surfaceId;
|
|
|
|
surface->gdi.width = (UINT32) createSurface->width;
|
|
|
|
surface->gdi.height = (UINT32) createSurface->height;
|
2016-07-14 17:08:06 +03:00
|
|
|
|
|
|
|
switch (createSurface->pixelFormat)
|
2014-07-02 00:32:36 +04:00
|
|
|
{
|
2016-07-14 17:08:06 +03:00
|
|
|
case GFX_PIXEL_FORMAT_ARGB_8888:
|
|
|
|
surface->gdi.format = PIXEL_FORMAT_BGRA32;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_PIXEL_FORMAT_XRGB_8888:
|
|
|
|
surface->gdi.format = PIXEL_FORMAT_BGRX32;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
free(surface);
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-07-02 00:32:36 +04:00
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
surface->gdi.scanline = surface->gdi.width * GetBytesPerPixel(
|
|
|
|
surface->gdi.format);
|
2016-11-24 11:02:06 +03:00
|
|
|
surface->gdi.scanline = x11_pad_scanline(surface->gdi.scanline, xfc->scanline_pad);
|
2016-04-05 18:07:45 +03:00
|
|
|
size = surface->gdi.scanline * surface->gdi.height;
|
|
|
|
surface->gdi.data = (BYTE*) _aligned_malloc(size, 16);
|
2014-07-09 02:04:24 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!surface->gdi.data)
|
2014-08-13 22:56:40 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
free(surface);
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2014-08-13 22:56:40 +04:00
|
|
|
}
|
2014-07-02 07:28:09 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
ZeroMemory(surface->gdi.data, size);
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2016-08-03 15:16:20 +03:00
|
|
|
if (gdi->dstFormat == surface->gdi.format)
|
2014-07-09 02:04:24 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
surface->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0,
|
2016-07-14 17:08:06 +03:00
|
|
|
(char*) surface->gdi.data, surface->gdi.width, surface->gdi.height,
|
|
|
|
xfc->scanline_pad, surface->gdi.scanline);
|
2014-07-09 02:04:24 +04:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
UINT32 width = surface->gdi.width;
|
2016-08-03 15:16:20 +03:00
|
|
|
UINT32 bytes = GetBytesPerPixel(gdi->dstFormat);
|
2016-04-05 18:07:45 +03:00
|
|
|
surface->stageScanline = width * bytes;
|
2016-11-24 11:02:06 +03:00
|
|
|
surface->stageScanline = x11_pad_scanline(surface->stageScanline, xfc->scanline_pad);
|
2016-04-05 18:07:45 +03:00
|
|
|
size = surface->stageScanline * surface->gdi.height;
|
|
|
|
surface->stage = (BYTE*) _aligned_malloc(size, 16);
|
2016-03-02 17:16:49 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!surface->stage)
|
|
|
|
{
|
2016-07-13 15:58:11 +03:00
|
|
|
_aligned_free(surface->gdi.data);
|
2016-04-05 18:07:45 +03:00
|
|
|
free(surface);
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2016-03-02 17:16:49 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
ZeroMemory(surface->stage, size);
|
2016-07-13 15:58:11 +03:00
|
|
|
surface->image = XCreateImage(xfc->display, xfc->visual, xfc->depth,
|
2016-07-14 17:08:06 +03:00
|
|
|
ZPixmap, 0, (char*) surface->stage,
|
|
|
|
surface->gdi.width, surface->gdi.height,
|
|
|
|
xfc->scanline_pad, surface->gdi.scanline);
|
2016-03-02 17:16:49 +03:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
surface->gdi.outputMapped = FALSE;
|
|
|
|
region16_init(&surface->gdi.invalidRegion);
|
|
|
|
context->SetSurfaceData(context, surface->gdi.surfaceId, (void*) surface);
|
2016-03-02 17:16:49 +03:00
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-04-05 18:07:45 +03:00
|
|
|
static UINT xf_DeleteSurface(RdpgfxClientContext* context,
|
2016-07-14 17:08:06 +03:00
|
|
|
const RDPGFX_DELETE_SURFACE_PDU* deleteSurface)
|
2014-07-02 07:28:09 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
rdpCodecs* codecs = NULL;
|
|
|
|
xfGfxSurface* surface = NULL;
|
2016-07-14 17:08:06 +03:00
|
|
|
surface = (xfGfxSurface*) context->GetSurfaceData(context,
|
|
|
|
deleteSurface->surfaceId);
|
2014-07-02 07:28:09 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (surface)
|
|
|
|
{
|
|
|
|
XFree(surface->image);
|
|
|
|
_aligned_free(surface->gdi.data);
|
|
|
|
_aligned_free(surface->stage);
|
|
|
|
region16_uninit(&surface->gdi.invalidRegion);
|
|
|
|
codecs = surface->gdi.codecs;
|
|
|
|
free(surface);
|
|
|
|
}
|
2014-07-02 07:28:09 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
context->SetSurfaceData(context, deleteSurface->surfaceId, NULL);
|
2014-07-02 07:28:09 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (codecs && codecs->progressive)
|
2016-07-14 17:08:06 +03:00
|
|
|
progressive_delete_surface_context(codecs->progressive,
|
|
|
|
deleteSurface->surfaceId);
|
2014-07-02 07:28:09 +04:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-07-02 07:28:09 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
void xf_graphics_pipeline_init(xfContext* xfc, RdpgfxClientContext* gfx)
|
2014-07-02 07:28:09 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
rdpGdi* gdi = xfc->context.gdi;
|
|
|
|
gdi_graphics_pipeline_init(gdi, gfx);
|
|
|
|
gfx->UpdateSurfaces = xf_UpdateSurfaces;
|
|
|
|
gfx->CreateSurface = xf_CreateSurface;
|
|
|
|
gfx->DeleteSurface = xf_DeleteSurface;
|
|
|
|
}
|
2014-06-20 21:52:13 +04:00
|
|
|
|
|
|
|
void xf_graphics_pipeline_uninit(xfContext* xfc, RdpgfxClientContext* gfx)
|
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
rdpGdi* gdi = xfc->context.gdi;
|
|
|
|
gdi_graphics_pipeline_uninit(gdi, gfx);
|
2014-06-20 21:52:13 +04:00
|
|
|
}
|