2014-09-12 22:57:44 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* GDI Graphics Pipeline
|
|
|
|
*
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-09-15 11:01:05 +04:00
|
|
|
#include <freerdp/log.h>
|
2014-09-12 22:57:44 +04:00
|
|
|
#include <freerdp/gdi/gfx.h>
|
|
|
|
#include <freerdp/gdi/region.h>
|
|
|
|
|
2014-09-15 11:01:05 +04:00
|
|
|
#define TAG FREERDP_TAG("gdi")
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_ResetGraphics(RdpgfxClientContext* context, RDPGFX_RESET_GRAPHICS_PDU* resetGraphics)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
2015-10-13 22:50:39 +03:00
|
|
|
int index;
|
|
|
|
UINT16 count;
|
2014-09-26 06:08:10 +04:00
|
|
|
UINT32 DesktopWidth;
|
|
|
|
UINT32 DesktopHeight;
|
2015-10-13 22:50:39 +03:00
|
|
|
gdiGfxSurface* surface;
|
|
|
|
UINT16* pSurfaceIds = NULL;
|
2014-09-12 22:57:44 +04:00
|
|
|
rdpGdi* gdi = (rdpGdi*) context->custom;
|
2014-09-26 06:08:10 +04:00
|
|
|
rdpUpdate* update = gdi->context->update;
|
|
|
|
rdpSettings* settings = gdi->context->settings;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2014-09-26 06:08:10 +04:00
|
|
|
DesktopWidth = resetGraphics->width;
|
|
|
|
DesktopHeight = resetGraphics->height;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
if ((DesktopWidth != settings->DesktopWidth) || (DesktopHeight != settings->DesktopHeight))
|
2014-09-26 06:08:10 +04:00
|
|
|
{
|
|
|
|
settings->DesktopWidth = DesktopWidth;
|
|
|
|
settings->DesktopHeight = DesktopHeight;
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
update->DesktopResize(gdi->context);
|
|
|
|
}
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
context->GetSurfaceIds(context, &pSurfaceIds, &count);
|
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
|
|
|
{
|
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, pSurfaceIds[index]);
|
|
|
|
|
|
|
|
if (!surface || !surface->outputMapped)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
freerdp_client_codecs_reset(surface->codecs, FREERDP_CODEC_ALL);
|
|
|
|
|
|
|
|
region16_clear(&surface->invalidRegion);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pSurfaceIds);
|
|
|
|
|
|
|
|
freerdp_client_codecs_reset(gdi->codecs, FREERDP_CODEC_ALL);
|
|
|
|
|
2014-09-12 22:57:44 +04:00
|
|
|
gdi->graphicsReset = TRUE;
|
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
int gdi_OutputUpdate(rdpGdi* gdi, gdiGfxSurface* surface)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
int nDstStep;
|
|
|
|
BYTE* pDstData;
|
|
|
|
int nXDst, nYDst;
|
|
|
|
int nXSrc, nYSrc;
|
2015-10-13 22:50:39 +03:00
|
|
|
UINT16 width, height;
|
|
|
|
UINT32 surfaceX, surfaceY;
|
2014-09-12 22:57:44 +04:00
|
|
|
RECTANGLE_16 surfaceRect;
|
|
|
|
const RECTANGLE_16* extents;
|
|
|
|
rdpUpdate* update = gdi->context->update;
|
|
|
|
|
|
|
|
pDstData = gdi->primary_buffer;
|
2014-09-17 22:55:52 +04:00
|
|
|
nDstStep = gdi->bytesPerPixel * gdi->width;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
surfaceX = surface->outputOriginX;
|
|
|
|
surfaceY = surface->outputOriginY;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
surfaceRect.left = 0;
|
|
|
|
surfaceRect.top = 0;
|
2015-10-13 22:50:39 +03:00
|
|
|
surfaceRect.right = surface->width;
|
|
|
|
surfaceRect.bottom = surface->height;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
region16_intersect_rect(&(surface->invalidRegion), &(surface->invalidRegion), &surfaceRect);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
if (!region16_is_empty(&(surface->invalidRegion)))
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
2015-10-13 22:50:39 +03:00
|
|
|
extents = region16_extents(&(surface->invalidRegion));
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
nXSrc = extents->left;
|
|
|
|
nYSrc = extents->top;
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
nXDst = surfaceX + extents->left;
|
|
|
|
nYDst = surfaceY + extents->top;
|
|
|
|
|
|
|
|
width = extents->right - extents->left;
|
|
|
|
height = extents->bottom - extents->top;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
update->BeginPaint(gdi->context);
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
freerdp_image_copy(pDstData, gdi->format, nDstStep, nXDst, nYDst,
|
|
|
|
width, height, surface->data, surface->format,
|
|
|
|
surface->scanline, nXSrc, nYSrc, NULL);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
gdi_InvalidateRegion(gdi->primary->hdc, nXDst, nYDst, width, height);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
update->EndPaint(gdi->context);
|
|
|
|
}
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
region16_clear(&(surface->invalidRegion));
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
int gdi_UpdateSurfaces(rdpGdi* gdi)
|
|
|
|
{
|
|
|
|
UINT16 count;
|
|
|
|
int index;
|
|
|
|
int status = 1;
|
|
|
|
gdiGfxSurface* surface;
|
|
|
|
UINT16* pSurfaceIds = NULL;
|
|
|
|
RdpgfxClientContext* context = gdi->gfx;
|
|
|
|
|
|
|
|
if (!gdi->graphicsReset)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
context->GetSurfaceIds(context, &pSurfaceIds, &count);
|
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
|
|
|
{
|
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, pSurfaceIds[index]);
|
|
|
|
|
|
|
|
if (!surface || !surface->outputMapped)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
status = gdi_OutputUpdate(gdi, surface);
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pSurfaceIds);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-09-12 22:57:44 +04:00
|
|
|
int gdi_OutputExpose(rdpGdi* gdi, int x, int y, int width, int height)
|
|
|
|
{
|
2015-10-13 22:50:39 +03:00
|
|
|
int index;
|
|
|
|
int status = 1;
|
|
|
|
UINT16 count;
|
|
|
|
gdiGfxSurface* surface;
|
2014-09-12 22:57:44 +04:00
|
|
|
RECTANGLE_16 invalidRect;
|
2015-10-13 22:50:39 +03:00
|
|
|
RECTANGLE_16 surfaceRect;
|
|
|
|
RECTANGLE_16 intersection;
|
|
|
|
UINT16* pSurfaceIds = NULL;
|
|
|
|
RdpgfxClientContext* context = gdi->gfx;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
invalidRect.left = x;
|
|
|
|
invalidRect.top = y;
|
|
|
|
invalidRect.right = x + width;
|
|
|
|
invalidRect.bottom = y + height;
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
context->GetSurfaceIds(context, &pSurfaceIds, &count);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
for (index = 0; index < count; index++)
|
|
|
|
{
|
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, pSurfaceIds[index]);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
if (!surface || !surface->outputMapped)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
surfaceRect.left = surface->outputOriginX;
|
|
|
|
surfaceRect.top = surface->outputOriginY;
|
|
|
|
surfaceRect.right = surface->outputOriginX + surface->width;
|
|
|
|
surfaceRect.bottom = surface->outputOriginY + surface->height;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &intersection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pSurfaceIds);
|
|
|
|
|
|
|
|
if (gdi_UpdateSurfaces(gdi) < 0)
|
|
|
|
status = -1;
|
|
|
|
|
|
|
|
return status;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_StartFrame(RdpgfxClientContext* context, RDPGFX_START_FRAME_PDU* startFrame)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
rdpGdi* gdi = (rdpGdi*) context->custom;
|
|
|
|
|
|
|
|
gdi->inGfxFrame = TRUE;
|
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_EndFrame(RdpgfxClientContext* context, RDPGFX_END_FRAME_PDU* endFrame)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
rdpGdi* gdi = (rdpGdi*) context->custom;
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
gdi_UpdateSurfaces(gdi);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
gdi->inGfxFrame = FALSE;
|
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_SurfaceCommand_Uncompressed(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
gdiGfxSurface* surface;
|
|
|
|
RECTANGLE_16 invalidRect;
|
|
|
|
|
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId);
|
|
|
|
|
|
|
|
if (!surface)
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2014-09-17 00:55:47 +04:00
|
|
|
freerdp_image_copy(surface->data, surface->format, surface->scanline, cmd->left, cmd->top,
|
2014-09-18 02:30:09 +04:00
|
|
|
cmd->width, cmd->height, cmd->data, PIXEL_FORMAT_XRGB32, cmd->width * 4, 0, 0, NULL);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
invalidRect.left = cmd->left;
|
|
|
|
invalidRect.top = cmd->top;
|
|
|
|
invalidRect.right = cmd->right;
|
|
|
|
invalidRect.bottom = cmd->bottom;
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
if (!gdi->inGfxFrame)
|
2015-10-13 22:50:39 +03:00
|
|
|
gdi_UpdateSurfaces(gdi);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
int j;
|
|
|
|
UINT16 i;
|
|
|
|
RFX_RECT* rect;
|
|
|
|
RFX_TILE* tile;
|
|
|
|
int nXDst, nYDst;
|
|
|
|
int nWidth, nHeight;
|
|
|
|
int nbUpdateRects;
|
|
|
|
RFX_MESSAGE* message;
|
|
|
|
gdiGfxSurface* surface;
|
|
|
|
REGION16 updateRegion;
|
|
|
|
RECTANGLE_16 updateRect;
|
|
|
|
RECTANGLE_16* updateRects;
|
|
|
|
REGION16 clippingRects;
|
|
|
|
RECTANGLE_16 clippingRect;
|
|
|
|
|
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId);
|
|
|
|
|
|
|
|
if (!surface)
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_REMOTEFX))
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
if (!(message = rfx_process_message(surface->codecs->rfx, cmd->data, cmd->length)))
|
2015-04-23 16:42:21 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to process RemoteFX message");
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-04-23 16:42:21 +03:00
|
|
|
}
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
region16_init(&clippingRects);
|
|
|
|
|
|
|
|
for (i = 0; i < message->numRects; i++)
|
|
|
|
{
|
|
|
|
rect = &(message->rects[i]);
|
|
|
|
|
|
|
|
clippingRect.left = cmd->left + rect->x;
|
|
|
|
clippingRect.top = cmd->top + rect->y;
|
|
|
|
clippingRect.right = clippingRect.left + rect->width;
|
|
|
|
clippingRect.bottom = clippingRect.top + rect->height;
|
|
|
|
|
|
|
|
region16_union_rect(&clippingRects, &clippingRects, &clippingRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < message->numTiles; i++)
|
|
|
|
{
|
|
|
|
tile = message->tiles[i];
|
|
|
|
|
|
|
|
updateRect.left = cmd->left + tile->x;
|
|
|
|
updateRect.top = cmd->top + tile->y;
|
|
|
|
updateRect.right = updateRect.left + 64;
|
|
|
|
updateRect.bottom = updateRect.top + 64;
|
|
|
|
|
|
|
|
region16_init(&updateRegion);
|
|
|
|
region16_intersect_rect(&updateRegion, &clippingRects, &updateRect);
|
|
|
|
updateRects = (RECTANGLE_16*) region16_rects(&updateRegion, &nbUpdateRects);
|
|
|
|
|
|
|
|
for (j = 0; j < nbUpdateRects; j++)
|
|
|
|
{
|
|
|
|
nXDst = updateRects[j].left;
|
|
|
|
nYDst = updateRects[j].top;
|
|
|
|
nWidth = updateRects[j].right - updateRects[j].left;
|
|
|
|
nHeight = updateRects[j].bottom - updateRects[j].top;
|
|
|
|
|
2014-09-17 00:55:47 +04:00
|
|
|
freerdp_image_copy(surface->data, surface->format, surface->scanline,
|
2014-09-12 22:57:44 +04:00
|
|
|
nXDst, nYDst, nWidth, nHeight,
|
2014-09-18 02:30:09 +04:00
|
|
|
tile->data, PIXEL_FORMAT_XRGB32, 64 * 4, 0, 0, NULL);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &updateRects[j]);
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
region16_uninit(&updateRegion);
|
|
|
|
}
|
|
|
|
|
2015-05-20 14:35:24 +03:00
|
|
|
region16_uninit(&clippingRects);
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
rfx_message_free(surface->codecs->rfx, message);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
if (!gdi->inGfxFrame)
|
2015-10-13 22:50:39 +03:00
|
|
|
gdi_UpdateSurfaces(gdi);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
BYTE* DstData = NULL;
|
|
|
|
gdiGfxSurface* surface;
|
|
|
|
RECTANGLE_16 invalidRect;
|
|
|
|
|
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId);
|
|
|
|
|
|
|
|
if (!surface)
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
if (!freerdp_client_codecs_prepare(gdi->codecs, FREERDP_CODEC_CLEARCODEC))
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
2014-09-12 22:57:44 +04:00
|
|
|
DstData = surface->data;
|
|
|
|
|
|
|
|
status = clear_decompress(gdi->codecs->clear, cmd->data, cmd->length, &DstData,
|
2014-09-17 00:55:47 +04:00
|
|
|
surface->format, surface->scanline, cmd->left, cmd->top, cmd->width, cmd->height);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
{
|
2014-09-15 11:01:05 +04:00
|
|
|
WLog_ERR(TAG, "clear_decompress failure: %d", status);
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
invalidRect.left = cmd->left;
|
|
|
|
invalidRect.top = cmd->top;
|
|
|
|
invalidRect.right = cmd->right;
|
|
|
|
invalidRect.bottom = cmd->bottom;
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
if (!gdi->inGfxFrame)
|
2015-10-13 22:50:39 +03:00
|
|
|
gdi_UpdateSurfaces(gdi);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
BYTE* DstData = NULL;
|
|
|
|
gdiGfxSurface* surface;
|
|
|
|
RECTANGLE_16 invalidRect;
|
|
|
|
|
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId);
|
|
|
|
|
|
|
|
if (!surface)
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_PLANAR))
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
2014-09-12 22:57:44 +04:00
|
|
|
DstData = surface->data;
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
status = planar_decompress(surface->codecs->planar, cmd->data, cmd->length, &DstData,
|
2014-09-17 03:12:26 +04:00
|
|
|
PIXEL_FORMAT_XRGB32, surface->scanline, cmd->left, cmd->top, cmd->width, cmd->height, FALSE);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
invalidRect.left = cmd->left;
|
|
|
|
invalidRect.top = cmd->top;
|
|
|
|
invalidRect.right = cmd->right;
|
|
|
|
invalidRect.bottom = cmd->bottom;
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
if (!gdi->inGfxFrame)
|
2015-10-13 22:50:39 +03:00
|
|
|
gdi_UpdateSurfaces(gdi);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_SurfaceCommand_H264(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
UINT32 i;
|
|
|
|
BYTE* DstData = NULL;
|
|
|
|
gdiGfxSurface* surface;
|
|
|
|
RDPGFX_H264_METABLOCK* meta;
|
|
|
|
RDPGFX_H264_BITMAP_STREAM* bs;
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId);
|
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_H264))
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
bs = (RDPGFX_H264_BITMAP_STREAM*) cmd->extra;
|
|
|
|
|
|
|
|
if (!bs)
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
meta = &(bs->meta);
|
|
|
|
|
|
|
|
DstData = surface->data;
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
status = h264_decompress(surface->codecs->h264, bs->data, bs->length, &DstData,
|
|
|
|
PIXEL_FORMAT_XRGB32, surface->scanline, surface->width, surface->height,
|
2015-01-22 15:24:15 +03:00
|
|
|
meta->regionRects, meta->numRegionRects);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
{
|
2015-09-03 13:05:02 +03:00
|
|
|
WLog_WARN(TAG, "h264_decompress failure: %d, ignoring update.", status);
|
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < meta->numRegionRects; i++)
|
|
|
|
{
|
2015-10-13 22:50:39 +03:00
|
|
|
region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), (RECTANGLE_16*) &(meta->regionRects[i]));
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gdi->inGfxFrame)
|
2015-10-13 22:50:39 +03:00
|
|
|
gdi_UpdateSurfaces(gdi);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
gdiGfxSurface* surface;
|
|
|
|
RECTANGLE_16 invalidRect;
|
|
|
|
|
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId);
|
|
|
|
|
|
|
|
if (!surface)
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_ALPHACODEC))
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
2014-09-15 11:01:05 +04:00
|
|
|
WLog_DBG(TAG, "gdi_SurfaceCommand_Alpha: status: %d", status);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
/* fill with green for now to distinguish from the rest */
|
|
|
|
|
|
|
|
freerdp_image_fill(surface->data, PIXEL_FORMAT_XRGB32, surface->scanline,
|
|
|
|
cmd->left, cmd->top, cmd->width, cmd->height, 0x00FF00);
|
|
|
|
|
|
|
|
invalidRect.left = cmd->left;
|
|
|
|
invalidRect.top = cmd->top;
|
|
|
|
invalidRect.right = cmd->right;
|
|
|
|
invalidRect.bottom = cmd->bottom;
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
if (!gdi->inGfxFrame)
|
2015-10-13 22:50:39 +03:00
|
|
|
gdi_UpdateSurfaces(gdi);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int status;
|
|
|
|
BYTE* DstData;
|
|
|
|
RFX_RECT* rect;
|
|
|
|
int nXDst, nYDst;
|
|
|
|
int nXSrc, nYSrc;
|
|
|
|
int nWidth, nHeight;
|
|
|
|
int nbUpdateRects;
|
|
|
|
gdiGfxSurface* surface;
|
|
|
|
REGION16 updateRegion;
|
|
|
|
RECTANGLE_16 updateRect;
|
|
|
|
RECTANGLE_16* updateRects;
|
|
|
|
REGION16 clippingRects;
|
|
|
|
RECTANGLE_16 clippingRect;
|
|
|
|
RFX_PROGRESSIVE_TILE* tile;
|
|
|
|
PROGRESSIVE_BLOCK_REGION* region;
|
|
|
|
|
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId);
|
|
|
|
|
|
|
|
if (!surface)
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
if (!freerdp_client_codecs_prepare(surface->codecs, FREERDP_CODEC_PROGRESSIVE))
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
progressive_create_surface_context(surface->codecs->progressive, cmd->surfaceId, surface->width, surface->height);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
DstData = surface->data;
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
status = progressive_decompress(surface->codecs->progressive, cmd->data, cmd->length, &DstData,
|
2014-09-12 22:57:44 +04:00
|
|
|
PIXEL_FORMAT_XRGB32, surface->scanline, cmd->left, cmd->top, cmd->width, cmd->height, cmd->surfaceId);
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
{
|
2014-09-15 11:01:05 +04:00
|
|
|
WLog_ERR(TAG, "progressive_decompress failure: %d", status);
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
region = &(surface->codecs->progressive->region);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
region16_init(&clippingRects);
|
|
|
|
|
|
|
|
for (i = 0; i < region->numRects; i++)
|
|
|
|
{
|
|
|
|
rect = &(region->rects[i]);
|
|
|
|
|
|
|
|
clippingRect.left = cmd->left + rect->x;
|
|
|
|
clippingRect.top = cmd->top + rect->y;
|
|
|
|
clippingRect.right = clippingRect.left + rect->width;
|
|
|
|
clippingRect.bottom = clippingRect.top + rect->height;
|
|
|
|
|
|
|
|
region16_union_rect(&clippingRects, &clippingRects, &clippingRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < region->numTiles; i++)
|
|
|
|
{
|
|
|
|
tile = region->tiles[i];
|
|
|
|
|
|
|
|
updateRect.left = cmd->left + tile->x;
|
|
|
|
updateRect.top = cmd->top + tile->y;
|
|
|
|
updateRect.right = updateRect.left + 64;
|
|
|
|
updateRect.bottom = updateRect.top + 64;
|
|
|
|
|
|
|
|
region16_init(&updateRegion);
|
|
|
|
region16_intersect_rect(&updateRegion, &clippingRects, &updateRect);
|
|
|
|
updateRects = (RECTANGLE_16*) region16_rects(&updateRegion, &nbUpdateRects);
|
|
|
|
|
|
|
|
for (j = 0; j < nbUpdateRects; j++)
|
|
|
|
{
|
|
|
|
nXDst = updateRects[j].left;
|
|
|
|
nYDst = updateRects[j].top;
|
|
|
|
nWidth = updateRects[j].right - updateRects[j].left;
|
|
|
|
nHeight = updateRects[j].bottom - updateRects[j].top;
|
|
|
|
|
|
|
|
nXSrc = nXDst - (cmd->left + tile->x);
|
|
|
|
nYSrc = nYDst - (cmd->top + tile->y);
|
|
|
|
|
2014-09-17 00:55:47 +04:00
|
|
|
freerdp_image_copy(surface->data, surface->format,
|
2014-09-12 22:57:44 +04:00
|
|
|
surface->scanline, nXDst, nYDst, nWidth, nHeight,
|
2014-09-18 02:30:09 +04:00
|
|
|
tile->data, PIXEL_FORMAT_XRGB32, 64 * 4, nXSrc, nYSrc, NULL);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &updateRects[j]);
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
region16_uninit(&updateRegion);
|
|
|
|
}
|
|
|
|
|
2015-05-20 14:35:24 +03:00
|
|
|
region16_uninit(&clippingRects);
|
|
|
|
|
2014-09-12 22:57:44 +04:00
|
|
|
if (!gdi->inGfxFrame)
|
2015-10-13 22:50:39 +03:00
|
|
|
gdi_UpdateSurfaces(gdi);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_SurfaceCommand(RdpgfxClientContext* context, RDPGFX_SURFACE_COMMAND* cmd)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status = CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
rdpGdi* gdi = (rdpGdi*) context->custom;
|
|
|
|
|
|
|
|
switch (cmd->codecId)
|
|
|
|
{
|
|
|
|
case RDPGFX_CODECID_UNCOMPRESSED:
|
|
|
|
status = gdi_SurfaceCommand_Uncompressed(gdi, context, cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDPGFX_CODECID_CAVIDEO:
|
|
|
|
status = gdi_SurfaceCommand_RemoteFX(gdi, context, cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDPGFX_CODECID_CLEARCODEC:
|
|
|
|
status = gdi_SurfaceCommand_ClearCodec(gdi, context, cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDPGFX_CODECID_PLANAR:
|
|
|
|
status = gdi_SurfaceCommand_Planar(gdi, context, cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDPGFX_CODECID_H264:
|
|
|
|
status = gdi_SurfaceCommand_H264(gdi, context, cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDPGFX_CODECID_ALPHA:
|
|
|
|
status = gdi_SurfaceCommand_Alpha(gdi, context, cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDPGFX_CODECID_CAPROGRESSIVE:
|
|
|
|
status = gdi_SurfaceCommand_Progressive(gdi, context, cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDPGFX_CODECID_CAPROGRESSIVE_V2:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return status;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_DeleteEncodingContext(RdpgfxClientContext* context, RDPGFX_DELETE_ENCODING_CONTEXT_PDU* deleteEncodingContext)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_CreateSurface(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE_PDU* createSurface)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
gdiGfxSurface* surface;
|
2014-09-17 00:55:47 +04:00
|
|
|
rdpGdi* gdi = (rdpGdi*) context->custom;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
surface = (gdiGfxSurface*) calloc(1, sizeof(gdiGfxSurface));
|
|
|
|
|
|
|
|
if (!surface)
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
surface->codecs = codecs_new(gdi->context);
|
|
|
|
|
|
|
|
if (!surface->codecs)
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
|
2014-09-12 22:57:44 +04:00
|
|
|
surface->surfaceId = createSurface->surfaceId;
|
|
|
|
surface->width = (UINT32) createSurface->width;
|
|
|
|
surface->height = (UINT32) createSurface->height;
|
|
|
|
surface->alpha = (createSurface->pixelFormat == PIXEL_FORMAT_ARGB_8888) ? TRUE : FALSE;
|
|
|
|
|
2014-09-18 03:44:59 +04:00
|
|
|
surface->format = (!gdi->invert) ? PIXEL_FORMAT_XRGB32 : PIXEL_FORMAT_XBGR32;
|
2014-09-17 00:55:47 +04:00
|
|
|
|
2014-09-12 22:57:44 +04:00
|
|
|
surface->scanline = (surface->width + (surface->width % 4)) * 4;
|
|
|
|
surface->data = (BYTE*) calloc(1, surface->scanline * surface->height);
|
|
|
|
|
|
|
|
if (!surface->data)
|
2014-11-17 01:00:13 +03:00
|
|
|
{
|
2015-10-13 22:50:39 +03:00
|
|
|
free(surface);
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-11-17 01:00:13 +03:00
|
|
|
}
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
surface->outputMapped = FALSE;
|
|
|
|
|
|
|
|
region16_init(&surface->invalidRegion);
|
|
|
|
|
2014-09-12 22:57:44 +04:00
|
|
|
context->SetSurfaceData(context, surface->surfaceId, (void*) surface);
|
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_DeleteSurface(RdpgfxClientContext* context, RDPGFX_DELETE_SURFACE_PDU* deleteSurface)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
2015-10-13 22:50:39 +03:00
|
|
|
rdpCodecs* codecs = NULL;
|
|
|
|
gdiGfxSurface* surface = NULL;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, deleteSurface->surfaceId);
|
|
|
|
|
|
|
|
if (surface)
|
|
|
|
{
|
2015-10-13 22:50:39 +03:00
|
|
|
region16_uninit(&surface->invalidRegion);
|
|
|
|
codecs = surface->codecs;
|
2014-09-12 22:57:44 +04:00
|
|
|
free(surface->data);
|
|
|
|
free(surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
context->SetSurfaceData(context, deleteSurface->surfaceId, NULL);
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
if (codecs && codecs->progressive)
|
|
|
|
progressive_delete_surface_context(codecs->progressive, deleteSurface->surfaceId);
|
|
|
|
|
|
|
|
codecs_free(codecs);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_SolidFill(RdpgfxClientContext* context, RDPGFX_SOLID_FILL_PDU* solidFill)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
UINT16 index;
|
|
|
|
UINT32 color;
|
|
|
|
BYTE a, r, g, b;
|
|
|
|
int nWidth, nHeight;
|
|
|
|
RDPGFX_RECT16* rect;
|
|
|
|
gdiGfxSurface* surface;
|
|
|
|
RECTANGLE_16 invalidRect;
|
|
|
|
rdpGdi* gdi = (rdpGdi*) context->custom;
|
|
|
|
|
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, solidFill->surfaceId);
|
|
|
|
|
|
|
|
if (!surface)
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
b = solidFill->fillPixel.B;
|
|
|
|
g = solidFill->fillPixel.G;
|
|
|
|
r = solidFill->fillPixel.R;
|
|
|
|
a = solidFill->fillPixel.XA;
|
|
|
|
|
2014-09-18 03:44:59 +04:00
|
|
|
if (!gdi->invert)
|
2014-09-17 00:55:47 +04:00
|
|
|
color = ARGB32(a, r, g, b);
|
|
|
|
else
|
|
|
|
color = ABGR32(a, r, g, b);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
for (index = 0; index < solidFill->fillRectCount; index++)
|
|
|
|
{
|
|
|
|
rect = &(solidFill->fillRects[index]);
|
|
|
|
|
|
|
|
nWidth = rect->right - rect->left;
|
|
|
|
nHeight = rect->bottom - rect->top;
|
|
|
|
|
|
|
|
invalidRect.left = rect->left;
|
|
|
|
invalidRect.top = rect->top;
|
|
|
|
invalidRect.right = rect->right;
|
|
|
|
invalidRect.bottom = rect->bottom;
|
|
|
|
|
2014-09-17 00:55:47 +04:00
|
|
|
freerdp_image_fill(surface->data, surface->format, surface->scanline,
|
2014-09-12 22:57:44 +04:00
|
|
|
rect->left, rect->top, nWidth, nHeight, color);
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gdi->inGfxFrame)
|
2015-10-13 22:50:39 +03:00
|
|
|
gdi_UpdateSurfaces(gdi);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_SurfaceToSurface(RdpgfxClientContext* context, RDPGFX_SURFACE_TO_SURFACE_PDU* surfaceToSurface)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
UINT16 index;
|
2014-09-17 01:41:24 +04:00
|
|
|
BOOL sameSurface;
|
2014-09-12 22:57:44 +04:00
|
|
|
int nWidth, nHeight;
|
|
|
|
RDPGFX_RECT16* rectSrc;
|
|
|
|
RDPGFX_POINT16* destPt;
|
|
|
|
RECTANGLE_16 invalidRect;
|
|
|
|
gdiGfxSurface* surfaceSrc;
|
|
|
|
gdiGfxSurface* surfaceDst;
|
|
|
|
rdpGdi* gdi = (rdpGdi*) context->custom;
|
|
|
|
|
|
|
|
rectSrc = &(surfaceToSurface->rectSrc);
|
|
|
|
|
|
|
|
surfaceSrc = (gdiGfxSurface*) context->GetSurfaceData(context, surfaceToSurface->surfaceIdSrc);
|
|
|
|
|
2014-09-17 01:41:24 +04:00
|
|
|
sameSurface = (surfaceToSurface->surfaceIdSrc == surfaceToSurface->surfaceIdDest) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
if (!sameSurface)
|
2014-09-12 22:57:44 +04:00
|
|
|
surfaceDst = (gdiGfxSurface*) context->GetSurfaceData(context, surfaceToSurface->surfaceIdDest);
|
|
|
|
else
|
|
|
|
surfaceDst = surfaceSrc;
|
|
|
|
|
|
|
|
if (!surfaceSrc || !surfaceDst)
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
nWidth = rectSrc->right - rectSrc->left;
|
|
|
|
nHeight = rectSrc->bottom - rectSrc->top;
|
|
|
|
|
|
|
|
for (index = 0; index < surfaceToSurface->destPtsCount; index++)
|
|
|
|
{
|
|
|
|
destPt = &surfaceToSurface->destPts[index];
|
|
|
|
|
2014-09-17 01:41:24 +04:00
|
|
|
if (sameSurface)
|
|
|
|
{
|
|
|
|
freerdp_image_move(surfaceDst->data, surfaceDst->format, surfaceDst->scanline,
|
|
|
|
destPt->x, destPt->y, nWidth, nHeight, rectSrc->left, rectSrc->top);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
freerdp_image_copy(surfaceDst->data, surfaceDst->format, surfaceDst->scanline,
|
|
|
|
destPt->x, destPt->y, nWidth, nHeight, surfaceSrc->data, surfaceSrc->format,
|
2014-09-18 02:30:09 +04:00
|
|
|
surfaceSrc->scanline, rectSrc->left, rectSrc->top, NULL);
|
2014-09-17 01:41:24 +04:00
|
|
|
}
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
invalidRect.left = destPt->x;
|
|
|
|
invalidRect.top = destPt->y;
|
|
|
|
invalidRect.right = destPt->x + rectSrc->right;
|
|
|
|
invalidRect.bottom = destPt->y + rectSrc->bottom;
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
region16_union_rect(&surfaceDst->invalidRegion, &surfaceDst->invalidRegion, &invalidRect);
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gdi->inGfxFrame)
|
2015-10-13 22:50:39 +03:00
|
|
|
gdi_UpdateSurfaces(gdi);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_SurfaceToCache(RdpgfxClientContext* context, RDPGFX_SURFACE_TO_CACHE_PDU* surfaceToCache)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
RDPGFX_RECT16* rect;
|
|
|
|
gdiGfxSurface* surface;
|
|
|
|
gdiGfxCacheEntry* cacheEntry;
|
2014-09-17 00:55:47 +04:00
|
|
|
rdpGdi* gdi = (rdpGdi*) context->custom;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
rect = &(surfaceToCache->rectSrc);
|
|
|
|
|
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, surfaceToCache->surfaceId);
|
|
|
|
|
|
|
|
if (!surface)
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
cacheEntry = (gdiGfxCacheEntry*) calloc(1, sizeof(gdiGfxCacheEntry));
|
|
|
|
|
|
|
|
if (!cacheEntry)
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
cacheEntry->width = (UINT32) (rect->right - rect->left);
|
|
|
|
cacheEntry->height = (UINT32) (rect->bottom - rect->top);
|
|
|
|
cacheEntry->alpha = surface->alpha;
|
|
|
|
|
2014-09-18 03:44:59 +04:00
|
|
|
cacheEntry->format = (!gdi->invert) ? PIXEL_FORMAT_XRGB32 : PIXEL_FORMAT_XBGR32;
|
2014-09-17 00:55:47 +04:00
|
|
|
|
2014-09-12 22:57:44 +04:00
|
|
|
cacheEntry->scanline = (cacheEntry->width + (cacheEntry->width % 4)) * 4;
|
|
|
|
cacheEntry->data = (BYTE*) calloc(1, cacheEntry->scanline * cacheEntry->height);
|
|
|
|
|
|
|
|
if (!cacheEntry->data)
|
2014-11-17 01:00:13 +03:00
|
|
|
{
|
2015-10-13 22:50:39 +03:00
|
|
|
free(cacheEntry);
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-11-17 01:00:13 +03:00
|
|
|
}
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2014-09-17 00:55:47 +04:00
|
|
|
freerdp_image_copy(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
|
2014-09-12 22:57:44 +04:00
|
|
|
0, 0, cacheEntry->width, cacheEntry->height, surface->data,
|
2014-09-18 02:30:09 +04:00
|
|
|
surface->format, surface->scanline, rect->left, rect->top, NULL);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
context->SetCacheSlotData(context, surfaceToCache->cacheSlot, (void*) cacheEntry);
|
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_CacheToSurface(RdpgfxClientContext* context, RDPGFX_CACHE_TO_SURFACE_PDU* cacheToSurface)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
UINT16 index;
|
|
|
|
RDPGFX_POINT16* destPt;
|
|
|
|
gdiGfxSurface* surface;
|
|
|
|
gdiGfxCacheEntry* cacheEntry;
|
|
|
|
RECTANGLE_16 invalidRect;
|
|
|
|
rdpGdi* gdi = (rdpGdi*) context->custom;
|
|
|
|
|
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, cacheToSurface->surfaceId);
|
|
|
|
cacheEntry = (gdiGfxCacheEntry*) context->GetCacheSlotData(context, cacheToSurface->cacheSlot);
|
|
|
|
|
|
|
|
if (!surface || !cacheEntry)
|
2015-06-09 16:22:26 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
for (index = 0; index < cacheToSurface->destPtsCount; index++)
|
|
|
|
{
|
|
|
|
destPt = &cacheToSurface->destPts[index];
|
|
|
|
|
2014-09-17 00:55:47 +04:00
|
|
|
freerdp_image_copy(surface->data, surface->format, surface->scanline,
|
2014-09-12 22:57:44 +04:00
|
|
|
destPt->x, destPt->y, cacheEntry->width, cacheEntry->height,
|
2014-09-18 02:30:09 +04:00
|
|
|
cacheEntry->data, cacheEntry->format, cacheEntry->scanline, 0, 0, NULL);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
|
|
|
invalidRect.left = destPt->x;
|
|
|
|
invalidRect.top = destPt->y;
|
|
|
|
invalidRect.right = destPt->x + cacheEntry->width - 1;
|
|
|
|
invalidRect.bottom = destPt->y + cacheEntry->height - 1;
|
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect);
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gdi->inGfxFrame)
|
2015-10-13 22:50:39 +03:00
|
|
|
gdi_UpdateSurfaces(gdi);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_CacheImportReply(RdpgfxClientContext* context, RDPGFX_CACHE_IMPORT_REPLY_PDU* cacheImportReply)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_EvictCacheEntry(RdpgfxClientContext* context, RDPGFX_EVICT_CACHE_ENTRY_PDU* evictCacheEntry)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
|
|
|
gdiGfxCacheEntry* cacheEntry;
|
|
|
|
|
|
|
|
cacheEntry = (gdiGfxCacheEntry*) context->GetCacheSlotData(context, evictCacheEntry->cacheSlot);
|
|
|
|
|
|
|
|
if (cacheEntry)
|
|
|
|
{
|
|
|
|
free(cacheEntry->data);
|
|
|
|
free(cacheEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
context->SetCacheSlotData(context, evictCacheEntry->cacheSlot, NULL);
|
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_MapSurfaceToOutput(RdpgfxClientContext* context, RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU* surfaceToOutput)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
2015-10-13 22:50:39 +03:00
|
|
|
gdiGfxSurface* surface;
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-10-13 22:50:39 +03:00
|
|
|
surface = (gdiGfxSurface*) context->GetSurfaceData(context, surfaceToOutput->surfaceId);
|
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
surface->outputMapped = TRUE;
|
|
|
|
surface->outputOriginX = surfaceToOutput->outputOriginX;
|
|
|
|
surface->outputOriginY = surfaceToOutput->outputOriginY;
|
|
|
|
|
|
|
|
region16_clear(&surface->invalidRegion);
|
2014-09-12 22:57:44 +04:00
|
|
|
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
UINT gdi_MapSurfaceToWindow(RdpgfxClientContext* context, RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* surfaceToWindow)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
2015-06-09 16:22:26 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void gdi_graphics_pipeline_init(rdpGdi* gdi, RdpgfxClientContext* gfx)
|
|
|
|
{
|
|
|
|
gdi->gfx = gfx;
|
|
|
|
gfx->custom = (void*) gdi;
|
|
|
|
|
|
|
|
gfx->ResetGraphics = gdi_ResetGraphics;
|
|
|
|
gfx->StartFrame = gdi_StartFrame;
|
|
|
|
gfx->EndFrame = gdi_EndFrame;
|
|
|
|
gfx->SurfaceCommand = gdi_SurfaceCommand;
|
|
|
|
gfx->DeleteEncodingContext = gdi_DeleteEncodingContext;
|
|
|
|
gfx->CreateSurface = gdi_CreateSurface;
|
|
|
|
gfx->DeleteSurface = gdi_DeleteSurface;
|
|
|
|
gfx->SolidFill = gdi_SolidFill;
|
|
|
|
gfx->SurfaceToSurface = gdi_SurfaceToSurface;
|
|
|
|
gfx->SurfaceToCache = gdi_SurfaceToCache;
|
|
|
|
gfx->CacheToSurface = gdi_CacheToSurface;
|
|
|
|
gfx->CacheImportReply = gdi_CacheImportReply;
|
|
|
|
gfx->EvictCacheEntry = gdi_EvictCacheEntry;
|
|
|
|
gfx->MapSurfaceToOutput = gdi_MapSurfaceToOutput;
|
|
|
|
gfx->MapSurfaceToWindow = gdi_MapSurfaceToWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gdi_graphics_pipeline_uninit(rdpGdi* gdi, RdpgfxClientContext* gfx)
|
|
|
|
{
|
|
|
|
region16_uninit(&(gdi->invalidRegion));
|
|
|
|
|
|
|
|
gdi->gfx = NULL;
|
|
|
|
gfx->custom = NULL;
|
|
|
|
}
|
|
|
|
|