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.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2014-06-05 02:03:25 +04:00
|
|
|
|
2024-01-23 18:49:54 +03:00
|
|
|
#include <math.h>
|
2022-01-19 11:27:39 +03:00
|
|
|
#include <winpr/assert.h>
|
2014-09-12 19:13:01 +04:00
|
|
|
#include <freerdp/log.h>
|
2014-06-05 02:03:25 +04:00
|
|
|
#include "xf_gfx.h"
|
2017-12-20 18:13:42 +03:00
|
|
|
#include "xf_rail.h"
|
2014-06-05 02:03:25 +04:00
|
|
|
|
2018-02-12 13:14:54 +03:00
|
|
|
#include <X11/Xutil.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
|
|
|
{
|
2017-03-28 12:49:13 +03:00
|
|
|
UINT rc = ERROR_INTERNAL_ERROR;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 surfaceX = 0;
|
|
|
|
UINT32 surfaceY = 0;
|
2024-09-02 15:57:55 +03:00
|
|
|
RECTANGLE_16 surfaceRect = { 0 };
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 nbRects = 0;
|
|
|
|
const RECTANGLE_16* rects = NULL;
|
2022-01-19 11:27:39 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
WINPR_ASSERT(surface);
|
|
|
|
|
2024-09-02 15:57:55 +03:00
|
|
|
rdpGdi* gdi = xfc->common.context.gdi;
|
2022-01-19 11:27:39 +03:00
|
|
|
WINPR_ASSERT(gdi);
|
|
|
|
|
2024-09-02 15:57:55 +03:00
|
|
|
rdpSettings* settings = xfc->common.context.settings;
|
2022-01-19 11:27:39 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
surfaceX = surface->gdi.outputOriginX;
|
|
|
|
surfaceY = surface->gdi.outputOriginY;
|
2017-04-11 13:30:37 +03:00
|
|
|
surfaceRect.left = 0;
|
|
|
|
surfaceRect.top = 0;
|
2019-05-08 11:32:01 +03:00
|
|
|
surfaceRect.right = surface->gdi.mappedWidth;
|
|
|
|
surfaceRect.bottom = surface->gdi.mappedHeight;
|
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);
|
2019-11-06 17:24:51 +03:00
|
|
|
region16_intersect_rect(&(surface->gdi.invalidRegion), &(surface->gdi.invalidRegion),
|
|
|
|
&surfaceRect);
|
2024-09-02 15:57:55 +03:00
|
|
|
const double sx = 1.0 * surface->gdi.outputTargetWidth / (double)surface->gdi.mappedWidth;
|
|
|
|
const double sy = 1.0 * surface->gdi.outputTargetHeight / (double)surface->gdi.mappedHeight;
|
2014-06-05 06:49:03 +04:00
|
|
|
|
2017-03-30 18:23:04 +03:00
|
|
|
if (!(rects = region16_rects(&surface->gdi.invalidRegion, &nbRects)))
|
|
|
|
return CHANNEL_RC_OK;
|
2014-06-05 20:36:01 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < nbRects; x++)
|
2017-03-30 18:23:04 +03:00
|
|
|
{
|
2022-11-28 10:39:08 +03:00
|
|
|
const RECTANGLE_16* rect = &rects[x];
|
|
|
|
const UINT32 nXSrc = rect->left;
|
|
|
|
const UINT32 nYSrc = rect->top;
|
|
|
|
const UINT32 swidth = rect->right - nXSrc;
|
|
|
|
const UINT32 sheight = rect->bottom - nYSrc;
|
2024-09-02 15:57:55 +03:00
|
|
|
const UINT32 nXDst = (UINT32)lround(1.0 * surfaceX + nXSrc * sx);
|
|
|
|
const UINT32 nYDst = (UINT32)lround(1.0 * surfaceY + nYSrc * sy);
|
|
|
|
const UINT32 dwidth = (UINT32)lround(1.0 * swidth * sx);
|
|
|
|
const UINT32 dheight = (UINT32)lround(1.0 * sheight * sy);
|
2014-06-05 20:36:01 +04:00
|
|
|
|
2014-09-17 22:29:56 +04:00
|
|
|
if (surface->stage)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_image_scale(surface->stage, gdi->dstFormat, surface->stageScanline, nXSrc,
|
|
|
|
nYSrc, dwidth, dheight, surface->gdi.data, surface->gdi.format,
|
|
|
|
surface->gdi.scanline, nXSrc, nYSrc, swidth, sheight))
|
2017-03-28 12:49:13 +03:00
|
|
|
goto fail;
|
2014-09-17 22:29:56 +04:00
|
|
|
}
|
|
|
|
|
2017-12-20 18:13:42 +03:00
|
|
|
if (xfc->remote_app)
|
2014-12-01 13:56:44 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
XPutImage(xfc->display, xfc->primary, xfc->gc, surface->image, nXSrc, nYSrc, nXDst,
|
|
|
|
nYDst, dwidth, dheight);
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2022-11-28 10:39:08 +03:00
|
|
|
xf_rail_paint_surface(xfc, surface->gdi.windowId, rect);
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2014-12-01 13:56:44 +03:00
|
|
|
}
|
2017-12-20 18:13:42 +03:00
|
|
|
else
|
|
|
|
#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))
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
XPutImage(xfc->display, xfc->primary, xfc->gc, surface->image, nXSrc, nYSrc, nXDst,
|
|
|
|
nYDst, dwidth, dheight);
|
|
|
|
xf_draw_screen(xfc, nXDst, nYDst, dwidth, dheight);
|
|
|
|
}
|
|
|
|
else
|
2017-12-20 18:13:42 +03:00
|
|
|
#endif
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
XPutImage(xfc->display, xfc->drawable, xfc->gc, surface->image, nXSrc, nYSrc, nXDst,
|
|
|
|
nYDst, dwidth, dheight);
|
|
|
|
}
|
2014-06-05 06:49:03 +04:00
|
|
|
}
|
2014-06-05 20:36:01 +04:00
|
|
|
|
2017-03-28 12:49:13 +03:00
|
|
|
rc = CHANNEL_RC_OK;
|
|
|
|
fail:
|
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);
|
2017-03-28 12:49:13 +03:00
|
|
|
return rc;
|
2014-06-05 20:36:01 +04:00
|
|
|
}
|
|
|
|
|
2022-11-08 11:07:38 +03:00
|
|
|
static UINT xf_WindowUpdate(RdpgfxClientContext* context, xfGfxSurface* surface)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(surface);
|
|
|
|
return IFCALLRESULT(CHANNEL_RC_OK, context->UpdateWindowFromSurface, context, &surface->gdi);
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static UINT xf_UpdateSurfaces(RdpgfxClientContext* context)
|
2015-02-07 01:46:15 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT16 count = 0;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT status = CHANNEL_RC_OK;
|
2015-02-11 00:32:07 +03:00
|
|
|
UINT16* pSurfaceIds = NULL;
|
2016-07-13 15:58:11 +03:00
|
|
|
rdpGdi* gdi = (rdpGdi*)context->custom;
|
2024-01-23 18:49:54 +03:00
|
|
|
xfContext* xfc = NULL;
|
2015-02-07 01:46:15 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!gdi)
|
|
|
|
return status;
|
|
|
|
|
2018-02-08 12:34:49 +03:00
|
|
|
if (gdi->suppressOutput)
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
xfc = (xfContext*)gdi->context;
|
2018-10-23 12:52:06 +03:00
|
|
|
EnterCriticalSection(&context->mux);
|
2015-06-09 16:22:26 +03:00
|
|
|
context->GetSurfaceIds(context, &pSurfaceIds, &count);
|
2015-02-07 01:46:15 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < count; index++)
|
2015-02-07 01:46:15 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
xfGfxSurface* surface = (xfGfxSurface*)context->GetSurfaceData(context, pSurfaceIds[index]);
|
2015-02-07 01:46:15 +03:00
|
|
|
|
2019-05-07 11:22:02 +03:00
|
|
|
if (!surface)
|
|
|
|
continue;
|
|
|
|
|
2019-05-08 11:32:01 +03:00
|
|
|
/* If UpdateSurfaceArea callback is available, the output has already been updated. */
|
|
|
|
if (context->UpdateSurfaceArea)
|
|
|
|
{
|
2022-11-08 11:07:38 +03:00
|
|
|
if (surface->gdi.handleInUpdateSurfaceArea)
|
2019-05-08 11:32:01 +03:00
|
|
|
continue;
|
|
|
|
}
|
2015-02-07 01:46:15 +03:00
|
|
|
|
2019-05-07 11:22:02 +03:00
|
|
|
if (surface->gdi.outputMapped)
|
|
|
|
status = xf_OutputUpdate(xfc, surface);
|
2022-11-08 11:07:38 +03:00
|
|
|
else if (surface->gdi.windowMapped)
|
|
|
|
status = xf_WindowUpdate(context, surface);
|
2015-02-07 01:46:15 +03:00
|
|
|
|
2022-11-08 11:07:38 +03:00
|
|
|
if (status != CHANNEL_RC_OK)
|
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);
|
2018-10-23 12:52:06 +03:00
|
|
|
LeaveCriticalSection(&context->mux);
|
2015-02-11 00:32:07 +03:00
|
|
|
return status;
|
2015-02-07 01:46:15 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT xf_OutputExpose(xfContext* xfc, UINT32 x, UINT32 y, UINT32 width, UINT32 height)
|
2014-06-13 00:13:12 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT16 count = 0;
|
2018-10-23 12:52:06 +03:00
|
|
|
UINT status = ERROR_INTERNAL_ERROR;
|
2022-11-08 11:07:38 +03:00
|
|
|
RECTANGLE_16 invalidRect = { 0 };
|
|
|
|
RECTANGLE_16 intersection = { 0 };
|
2015-02-11 00:32:07 +03:00
|
|
|
UINT16* pSurfaceIds = NULL;
|
2024-01-23 18:49:54 +03:00
|
|
|
RdpgfxClientContext* context = NULL;
|
2022-01-19 11:27:39 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
WINPR_ASSERT(xfc->common.context.gdi);
|
|
|
|
|
|
|
|
context = xfc->common.context.gdi->gfx;
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
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;
|
2018-10-23 12:52:06 +03:00
|
|
|
status = context->GetSurfaceIds(context, &pSurfaceIds, &count);
|
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
goto fail;
|
2015-02-11 00:32:07 +03:00
|
|
|
|
2020-04-10 19:48:17 +03:00
|
|
|
if (!TryEnterCriticalSection(&context->mux))
|
|
|
|
{
|
|
|
|
free(pSurfaceIds);
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < count; index++)
|
2015-02-11 00:32:07 +03:00
|
|
|
{
|
2022-11-08 11:07:38 +03:00
|
|
|
RECTANGLE_16 surfaceRect = { 0 };
|
|
|
|
xfGfxSurface* surface = (xfGfxSurface*)context->GetSurfaceData(context, pSurfaceIds[index]);
|
2015-02-11 00:32:07 +03:00
|
|
|
|
2022-11-08 11:07:38 +03:00
|
|
|
if (!surface || (!surface->gdi.outputMapped && !surface->gdi.windowMapped))
|
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;
|
2019-05-07 11:22:02 +03:00
|
|
|
surfaceRect.right = surface->gdi.outputOriginX + surface->gdi.outputTargetWidth;
|
|
|
|
surfaceRect.bottom = surface->gdi.outputOriginY + surface->gdi.outputTargetHeight;
|
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;
|
2019-11-06 17:24:51 +03:00
|
|
|
region16_union_rect(&surface->gdi.invalidRegion, &surface->gdi.invalidRegion,
|
2016-07-14 17:08:06 +03:00
|
|
|
&intersection);
|
2015-02-11 00:32:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pSurfaceIds);
|
2018-12-04 18:56:22 +03:00
|
|
|
LeaveCriticalSection(&context->mux);
|
2016-04-05 18:07:45 +03:00
|
|
|
IFCALLRET(context->UpdateSurfaces, status, context);
|
2018-10-23 12:52:06 +03:00
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
fail:
|
2015-02-07 01:46:15 +03:00
|
|
|
return status;
|
2014-06-13 00:13:12 +04:00
|
|
|
}
|
|
|
|
|
2021-06-17 10:21:20 +03:00
|
|
|
static UINT32 x11_pad_scanline(UINT32 scanline, UINT32 inPad)
|
2016-11-24 11:02:06 +03:00
|
|
|
{
|
2017-02-15 13:56:50 +03:00
|
|
|
/* Ensure X11 alignment is met */
|
2016-11-24 11:02:06 +03:00
|
|
|
if (inPad > 0)
|
|
|
|
{
|
|
|
|
const UINT32 align = inPad / 8;
|
|
|
|
const UINT32 pad = align - scanline % align;
|
|
|
|
|
|
|
|
if (align != pad)
|
|
|
|
scanline += pad;
|
|
|
|
}
|
|
|
|
|
2017-02-15 13:56:50 +03:00
|
|
|
/* 16 byte alingment is required for ASM optimized code */
|
|
|
|
if (scanline % 16)
|
|
|
|
scanline += 16 - scanline % 16;
|
|
|
|
|
2016-11-24 11:02:06 +03:00
|
|
|
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
|
|
|
{
|
2017-05-01 23:39:52 +03:00
|
|
|
UINT ret = CHANNEL_RC_NO_MEMORY;
|
2024-01-23 18:49:54 +03:00
|
|
|
size_t size = 0;
|
|
|
|
xfGfxSurface* surface = NULL;
|
2016-07-13 15:58:11 +03:00
|
|
|
rdpGdi* gdi = (rdpGdi*)context->custom;
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)gdi->context;
|
|
|
|
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
|
|
|
|
2021-02-08 11:35:44 +03:00
|
|
|
surface->gdi.codecs = context->codecs;
|
2018-02-08 13:55:57 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!surface->gdi.codecs)
|
2014-06-05 02:03:25 +04:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "global GDI codecs aren't set");
|
2017-05-01 23:39:52 +03:00
|
|
|
goto out_free;
|
2014-06-05 02:03:25 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
surface->gdi.surfaceId = createSurface->surfaceId;
|
2019-05-08 11:32:01 +03:00
|
|
|
surface->gdi.width = x11_pad_scanline(createSurface->width, 0);
|
|
|
|
surface->gdi.height = x11_pad_scanline(createSurface->height, 0);
|
|
|
|
surface->gdi.mappedWidth = createSurface->width;
|
|
|
|
surface->gdi.mappedHeight = createSurface->height;
|
|
|
|
surface->gdi.outputTargetWidth = createSurface->width;
|
|
|
|
surface->gdi.outputTargetHeight = 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:
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "unknown pixelFormat 0x%" PRIx32 "", createSurface->pixelFormat);
|
2017-05-01 23:39:52 +03:00
|
|
|
ret = ERROR_INTERNAL_ERROR;
|
|
|
|
goto out_free;
|
2014-07-02 00:32:36 +04:00
|
|
|
}
|
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
surface->gdi.scanline = surface->gdi.width * FreeRDPGetBytesPerPixel(surface->gdi.format);
|
2016-11-24 11:02:06 +03:00
|
|
|
surface->gdi.scanline = x11_pad_scanline(surface->gdi.scanline, xfc->scanline_pad);
|
2023-08-22 10:41:28 +03:00
|
|
|
size = 1ull * surface->gdi.scanline * surface->gdi.height;
|
2022-05-11 12:28:55 +03:00
|
|
|
surface->gdi.data = (BYTE*)winpr_aligned_malloc(size, 16);
|
2018-02-08 13:55:57 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!surface->gdi.data)
|
2014-08-13 22:56:40 +04:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "unable to allocate GDI data");
|
2017-05-01 23:39:52 +03:00
|
|
|
goto out_free;
|
2014-08-13 22:56:40 +04:00
|
|
|
}
|
2018-02-08 13:55:57 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
ZeroMemory(surface->gdi.data, size);
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2022-06-20 16:54:46 +03:00
|
|
|
if (FreeRDPAreColorFormatsEqualNoAlpha(gdi->dstFormat, surface->gdi.format))
|
2014-07-09 02:04:24 +04:00
|
|
|
{
|
2022-11-28 09:31:19 +03:00
|
|
|
WINPR_ASSERT(xfc->depth != 0);
|
2019-11-06 17:24:51 +03:00
|
|
|
surface->image =
|
|
|
|
XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0,
|
|
|
|
(char*)surface->gdi.data, surface->gdi.mappedWidth,
|
|
|
|
surface->gdi.mappedHeight, 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;
|
2022-04-28 06:43:31 +03:00
|
|
|
UINT32 bytes = FreeRDPGetBytesPerPixel(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);
|
2023-08-22 10:41:28 +03:00
|
|
|
size = 1ull * surface->stageScanline * surface->gdi.height;
|
2022-05-11 12:28:55 +03:00
|
|
|
surface->stage = (BYTE*)winpr_aligned_malloc(size, 16);
|
2018-02-08 13:55:57 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!surface->stage)
|
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "unable to allocate stage buffer");
|
2017-05-01 23:39:52 +03:00
|
|
|
goto out_free_gdidata;
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2017-05-01 23:39:52 +03:00
|
|
|
|
2018-02-08 13:55:57 +03:00
|
|
|
ZeroMemory(surface->stage, size);
|
2022-11-28 09:31:19 +03:00
|
|
|
WINPR_ASSERT(xfc->depth != 0);
|
2019-11-06 17:24:51 +03:00
|
|
|
surface->image =
|
|
|
|
XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, (char*)surface->stage,
|
|
|
|
surface->gdi.mappedWidth, surface->gdi.mappedHeight, xfc->scanline_pad,
|
|
|
|
surface->stageScanline);
|
2016-03-02 17:16:49 +03:00
|
|
|
}
|
|
|
|
|
2017-05-01 23:39:52 +03:00
|
|
|
if (!surface->image)
|
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "an error occurred when creating the XImage");
|
2017-05-01 23:39:52 +03:00
|
|
|
goto error_surface_image;
|
|
|
|
}
|
|
|
|
|
2017-09-18 11:47:56 +03:00
|
|
|
surface->image->byte_order = LSBFirst;
|
|
|
|
surface->image->bitmap_bit_order = LSBFirst;
|
2022-11-08 11:07:38 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
region16_init(&surface->gdi.invalidRegion);
|
2018-02-08 13:55:57 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (context->SetSurfaceData(context, surface->gdi.surfaceId, (void*)surface) != CHANNEL_RC_OK)
|
2017-05-01 23:39:52 +03:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "an error occurred during SetSurfaceData");
|
2017-05-01 23:39:52 +03:00
|
|
|
goto error_set_surface_data;
|
|
|
|
}
|
|
|
|
|
2018-02-08 13:55:57 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2017-05-01 23:39:52 +03:00
|
|
|
error_set_surface_data:
|
2018-02-12 13:14:54 +03:00
|
|
|
surface->image->data = NULL;
|
2018-02-12 12:02:35 +03:00
|
|
|
XDestroyImage(surface->image);
|
2017-05-01 23:39:52 +03:00
|
|
|
error_surface_image:
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(surface->stage);
|
2017-05-01 23:39:52 +03:00
|
|
|
out_free_gdidata:
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(surface->gdi.data);
|
2017-05-01 23:39:52 +03:00
|
|
|
out_free:
|
|
|
|
free(surface);
|
|
|
|
return ret;
|
2016-03-02 17:16:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT status = 0;
|
2018-10-23 12:52:06 +03:00
|
|
|
EnterCriticalSection(&context->mux);
|
2019-11-06 17:24:51 +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)
|
|
|
|
{
|
2022-11-08 11:07:38 +03:00
|
|
|
if (surface->gdi.windowMapped)
|
2019-05-07 11:22:02 +03:00
|
|
|
IFCALL(context->UnmapWindowForSurface, context, surface->gdi.windowId);
|
|
|
|
|
2017-08-14 11:16:14 +03:00
|
|
|
#ifdef WITH_GFX_H264
|
|
|
|
h264_context_free(surface->gdi.h264);
|
|
|
|
#endif
|
2018-02-12 13:14:54 +03:00
|
|
|
surface->image->data = NULL;
|
2018-02-12 12:02:35 +03:00
|
|
|
XDestroyImage(surface->image);
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(surface->gdi.data);
|
|
|
|
winpr_aligned_free(surface->stage);
|
2016-04-05 18:07:45 +03:00
|
|
|
region16_uninit(&surface->gdi.invalidRegion);
|
|
|
|
codecs = surface->gdi.codecs;
|
|
|
|
free(surface);
|
|
|
|
}
|
2014-07-02 07:28:09 +04:00
|
|
|
|
2018-10-23 12:52:06 +03:00
|
|
|
status = 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)
|
2019-11-06 17:24:51 +03:00
|
|
|
progressive_delete_surface_context(codecs->progressive, deleteSurface->surfaceId);
|
2014-07-02 07:28:09 +04:00
|
|
|
|
2018-10-23 12:52:06 +03:00
|
|
|
LeaveCriticalSection(&context->mux);
|
|
|
|
return status;
|
2014-07-02 07:28:09 +04:00
|
|
|
}
|
|
|
|
|
2022-11-08 11:07:38 +03:00
|
|
|
static UINT xf_UpdateWindowFromSurface(RdpgfxClientContext* context, gdiGfxSurface* surface)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(surface);
|
|
|
|
|
|
|
|
rdpGdi* gdi = (rdpGdi*)context->custom;
|
|
|
|
WINPR_ASSERT(gdi);
|
|
|
|
|
|
|
|
xfContext* xfc = (xfContext*)gdi->context;
|
|
|
|
WINPR_ASSERT(gdi->context);
|
|
|
|
|
2022-11-08 11:33:02 +03:00
|
|
|
if (freerdp_settings_get_bool(gdi->context->settings, FreeRDP_RemoteApplicationMode))
|
|
|
|
return xf_AppUpdateWindowFromSurface(xfc, surface);
|
2022-11-08 11:07:38 +03:00
|
|
|
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "function not implemented");
|
2022-11-08 11:07:38 +03:00
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpGdi* gdi = NULL;
|
|
|
|
const rdpSettings* settings = NULL;
|
2022-01-19 11:27:39 +03:00
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
WINPR_ASSERT(gfx);
|
|
|
|
|
|
|
|
settings = xfc->common.context.settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
gdi = xfc->common.context.gdi;
|
|
|
|
|
2019-05-08 11:32:01 +03:00
|
|
|
gdi_graphics_pipeline_init(gdi, gfx);
|
|
|
|
|
2023-10-13 10:48:44 +03:00
|
|
|
if (!freerdp_settings_get_bool(settings, FreeRDP_SoftwareGdi))
|
2019-05-08 11:32:01 +03:00
|
|
|
{
|
|
|
|
gfx->UpdateSurfaces = xf_UpdateSurfaces;
|
|
|
|
gfx->CreateSurface = xf_CreateSurface;
|
|
|
|
gfx->DeleteSurface = xf_DeleteSurface;
|
|
|
|
}
|
2022-11-08 11:07:38 +03:00
|
|
|
gfx->UpdateWindowFromSurface = xf_UpdateWindowFromSurface;
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2014-06-20 21:52:13 +04:00
|
|
|
|
|
|
|
void xf_graphics_pipeline_uninit(xfContext* xfc, RdpgfxClientContext* gfx)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpGdi* gdi = NULL;
|
2022-01-19 11:27:39 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
|
|
|
|
gdi = xfc->common.context.gdi;
|
2016-04-05 18:07:45 +03:00
|
|
|
gdi_graphics_pipeline_uninit(gdi, gfx);
|
2014-06-20 21:52:13 +04:00
|
|
|
}
|