2011-07-01 05:23:36 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-01 05:23:36 +04:00
|
|
|
* GDI Library
|
|
|
|
*
|
|
|
|
* Copyright 2010-2011 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
|
2011-07-01 05:23:36 +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
|
|
|
|
*
|
2011-10-02 23:16:22 +04:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-07-01 05:23:36 +04:00
|
|
|
*
|
|
|
|
* 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>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2011-07-01 05:23:36 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-11-22 04:22:41 +04:00
|
|
|
#include <winpr/crt.h>
|
2021-10-07 11:25:09 +03:00
|
|
|
#include <winpr/assert.h>
|
2012-11-22 04:22:41 +04:00
|
|
|
|
2011-08-31 12:35:50 +04:00
|
|
|
#include <freerdp/api.h>
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2011-07-01 05:23:36 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
|
|
|
|
2018-02-08 12:34:49 +03:00
|
|
|
#include <freerdp/gdi/gdi.h>
|
2011-08-22 21:08:01 +04:00
|
|
|
#include <freerdp/gdi/dc.h>
|
|
|
|
#include <freerdp/gdi/pen.h>
|
|
|
|
#include <freerdp/gdi/shape.h>
|
|
|
|
#include <freerdp/gdi/region.h>
|
|
|
|
#include <freerdp/gdi/bitmap.h>
|
2011-07-01 05:23:36 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
#include "drawing.h"
|
|
|
|
#include "clipping.h"
|
|
|
|
#include "brush.h"
|
|
|
|
#include "line.h"
|
2011-10-21 01:28:59 +04:00
|
|
|
#include "gdi.h"
|
2016-10-10 11:38:54 +03:00
|
|
|
#include "../core/graphics.h"
|
2021-10-07 11:25:09 +03:00
|
|
|
#include "../core/update.h"
|
2023-02-07 17:42:52 +03:00
|
|
|
#include "../cache/cache.h"
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("gdi")
|
|
|
|
|
2011-07-01 05:23:36 +04:00
|
|
|
/* Ternary Raster Operation Table */
|
2017-12-22 12:25:05 +03:00
|
|
|
typedef struct
|
2011-07-01 05:23:36 +04:00
|
|
|
{
|
2017-12-22 12:25:05 +03:00
|
|
|
DWORD code;
|
|
|
|
const char* name;
|
|
|
|
} rop_table_entry;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static const rop_table_entry rop3_code_table[] = { { GDI_BLACKNESS, "0" },
|
|
|
|
{ GDI_DPSoon, "DPSoon" },
|
|
|
|
{ GDI_DPSona, "DPSona" },
|
|
|
|
{ GDI_PSon, "PSon" },
|
|
|
|
{ GDI_SDPona, "SDPona" },
|
|
|
|
{ GDI_DPon, "DPon" },
|
|
|
|
{ GDI_PDSxnon, "PDSxnon" },
|
|
|
|
{ GDI_PDSaon, "PDSaon" },
|
|
|
|
{ GDI_SDPnaa, "SDPnaa" },
|
|
|
|
{ GDI_PDSxon, "PDSxon" },
|
|
|
|
{ GDI_DPna, "DPna" },
|
|
|
|
{ GDI_PSDnaon, "PSDnaon" },
|
|
|
|
{ GDI_SPna, "SPna" },
|
|
|
|
{ GDI_PDSnaon, "PDSnaon" },
|
|
|
|
{ GDI_PDSonon, "PDSonon" },
|
|
|
|
{ GDI_Pn, "Pn" },
|
|
|
|
{ GDI_PDSona, "PDSona" },
|
|
|
|
{ GDI_NOTSRCERASE, "DSon" },
|
|
|
|
{ GDI_SDPxnon, "SDPxnon" },
|
|
|
|
{ GDI_SDPaon, "SDPaon" },
|
|
|
|
{ GDI_DPSxnon, "DPSxnon" },
|
|
|
|
{ GDI_DPSaon, "DPSaon" },
|
|
|
|
{ GDI_PSDPSanaxx, "PSDPSanaxx" },
|
|
|
|
{ GDI_SSPxDSxaxn, "SSPxDSxaxn" },
|
|
|
|
{ GDI_SPxPDxa, "SPxPDxa" },
|
|
|
|
{ GDI_SDPSanaxn, "SDPSanaxn" },
|
|
|
|
{ GDI_PDSPaox, "PDSPaox" },
|
|
|
|
{ GDI_SDPSxaxn, "SDPSxaxn" },
|
|
|
|
{ GDI_PSDPaox, "PSDPaox" },
|
|
|
|
{ GDI_DSPDxaxn, "DSPDxaxn" },
|
|
|
|
{ GDI_PDSox, "PDSox" },
|
|
|
|
{ GDI_PDSoan, "PDSoan" },
|
|
|
|
{ GDI_DPSnaa, "DPSnaa" },
|
|
|
|
{ GDI_SDPxon, "SDPxon" },
|
|
|
|
{ GDI_DSna, "DSna" },
|
|
|
|
{ GDI_SPDnaon, "SPDnaon" },
|
|
|
|
{ GDI_SPxDSxa, "SPxDSxa" },
|
|
|
|
{ GDI_PDSPanaxn, "PDSPanaxn" },
|
|
|
|
{ GDI_SDPSaox, "SDPSaox" },
|
|
|
|
{ GDI_SDPSxnox, "SDPSxnox" },
|
|
|
|
{ GDI_DPSxa, "DPSxa" },
|
|
|
|
{ GDI_PSDPSaoxxn, "PSDPSaoxxn" },
|
|
|
|
{ GDI_DPSana, "DPSana" },
|
|
|
|
{ GDI_SSPxPDxaxn, "SSPxPDxaxn" },
|
|
|
|
{ GDI_SPDSoax, "SPDSoax" },
|
|
|
|
{ GDI_PSDnox, "PSDnox" },
|
|
|
|
{ GDI_PSDPxox, "PSDPxox" },
|
|
|
|
{ GDI_PSDnoan, "PSDnoan" },
|
|
|
|
{ GDI_PSna, "PSna" },
|
|
|
|
{ GDI_SDPnaon, "SDPnaon" },
|
|
|
|
{ GDI_SDPSoox, "SDPSoox" },
|
|
|
|
{ GDI_NOTSRCCOPY, "Sn" },
|
|
|
|
{ GDI_SPDSaox, "SPDSaox" },
|
|
|
|
{ GDI_SPDSxnox, "SPDSxnox" },
|
|
|
|
{ GDI_SDPox, "SDPox" },
|
|
|
|
{ GDI_SDPoan, "SDPoan" },
|
|
|
|
{ GDI_PSDPoax, "PSDPoax" },
|
|
|
|
{ GDI_SPDnox, "SPDnox" },
|
|
|
|
{ GDI_SPDSxox, "SPDSxox" },
|
|
|
|
{ GDI_SPDnoan, "SPDnoan" },
|
|
|
|
{ GDI_PSx, "PSx" },
|
|
|
|
{ GDI_SPDSonox, "SPDSonox" },
|
|
|
|
{ GDI_SPDSnaox, "SPDSnaox" },
|
|
|
|
{ GDI_PSan, "PSan" },
|
|
|
|
{ GDI_PSDnaa, "PSDnaa" },
|
|
|
|
{ GDI_DPSxon, "DPSxon" },
|
|
|
|
{ GDI_SDxPDxa, "SDxPDxa" },
|
|
|
|
{ GDI_SPDSanaxn, "SPDSanaxn" },
|
|
|
|
{ GDI_SRCERASE, "SDna" },
|
|
|
|
{ GDI_DPSnaon, "DPSnaon" },
|
|
|
|
{ GDI_DSPDaox, "DSPDaox" },
|
|
|
|
{ GDI_PSDPxaxn, "PSDPxaxn" },
|
|
|
|
{ GDI_SDPxa, "SDPxa" },
|
|
|
|
{ GDI_PDSPDaoxxn, "PDSPDaoxxn" },
|
|
|
|
{ GDI_DPSDoax, "DPSDoax" },
|
|
|
|
{ GDI_PDSnox, "PDSnox" },
|
|
|
|
{ GDI_SDPana, "SDPana" },
|
|
|
|
{ GDI_SSPxDSxoxn, "SSPxDSxoxn" },
|
|
|
|
{ GDI_PDSPxox, "PDSPxox" },
|
|
|
|
{ GDI_PDSnoan, "PDSnoan" },
|
|
|
|
{ GDI_PDna, "PDna" },
|
|
|
|
{ GDI_DSPnaon, "DSPnaon" },
|
|
|
|
{ GDI_DPSDaox, "DPSDaox" },
|
|
|
|
{ GDI_SPDSxaxn, "SPDSxaxn" },
|
|
|
|
{ GDI_DPSonon, "DPSonon" },
|
|
|
|
{ GDI_DSTINVERT, "Dn" },
|
|
|
|
{ GDI_DPSox, "DPSox" },
|
|
|
|
{ GDI_DPSoan, "DPSoan" },
|
|
|
|
{ GDI_PDSPoax, "PDSPoax" },
|
|
|
|
{ GDI_DPSnox, "DPSnox" },
|
|
|
|
{ GDI_PATINVERT, "DPx" },
|
|
|
|
{ GDI_DPSDonox, "DPSDonox" },
|
|
|
|
{ GDI_DPSDxox, "DPSDxox" },
|
|
|
|
{ GDI_DPSnoan, "DPSnoan" },
|
|
|
|
{ GDI_DPSDnaox, "DPSDnaox" },
|
|
|
|
{ GDI_DPan, "DPan" },
|
|
|
|
{ GDI_PDSxa, "PDSxa" },
|
|
|
|
{ GDI_DSPDSaoxxn, "DSPDSaoxxn" },
|
|
|
|
{ GDI_DSPDoax, "DSPDoax" },
|
|
|
|
{ GDI_SDPnox, "SDPnox" },
|
|
|
|
{ GDI_SDPSoax, "SDPSoax" },
|
|
|
|
{ GDI_DSPnox, "DSPnox" },
|
|
|
|
{ GDI_SRCINVERT, "DSx" },
|
|
|
|
{ GDI_SDPSonox, "SDPSonox" },
|
|
|
|
{ GDI_DSPDSonoxxn, "DSPDSonoxxn" },
|
|
|
|
{ GDI_PDSxxn, "PDSxxn" },
|
|
|
|
{ GDI_DPSax, "DPSax" },
|
|
|
|
{ GDI_PSDPSoaxxn, "PSDPSoaxxn" },
|
|
|
|
{ GDI_SDPax, "SDPax" },
|
|
|
|
{ GDI_PDSPDoaxxn, "PDSPDoaxxn" },
|
|
|
|
{ GDI_SDPSnoax, "SDPSnoax" },
|
|
|
|
{ GDI_PDSxnan, "PDSxnan" },
|
|
|
|
{ GDI_PDSana, "PDSana" },
|
|
|
|
{ GDI_SSDxPDxaxn, "SSDxPDxaxn" },
|
|
|
|
{ GDI_SDPSxox, "SDPSxox" },
|
|
|
|
{ GDI_SDPnoan, "SDPnoan" },
|
|
|
|
{ GDI_DSPDxox, "DSPDxox" },
|
|
|
|
{ GDI_DSPnoan, "DSPnoan" },
|
|
|
|
{ GDI_SDPSnaox, "SDPSnaox" },
|
|
|
|
{ GDI_DSan, "DSan" },
|
|
|
|
{ GDI_PDSax, "PDSax" },
|
|
|
|
{ GDI_DSPDSoaxxn, "DSPDSoaxxn" },
|
|
|
|
{ GDI_DPSDnoax, "DPSDnoax" },
|
|
|
|
{ GDI_SDPxnan, "SDPxnan" },
|
|
|
|
{ GDI_SPDSnoax, "SPDSnoax" },
|
|
|
|
{ GDI_DPSxnan, "DPSxnan" },
|
|
|
|
{ GDI_SPxDSxo, "SPxDSxo" },
|
|
|
|
{ GDI_DPSaan, "DPSaan" },
|
|
|
|
{ GDI_DPSaa, "DPSaa" },
|
|
|
|
{ GDI_SPxDSxon, "SPxDSxon" },
|
|
|
|
{ GDI_DPSxna, "DPSxna" },
|
|
|
|
{ GDI_SPDSnoaxn, "SPDSnoaxn" },
|
|
|
|
{ GDI_SDPxna, "SDPxna" },
|
|
|
|
{ GDI_PDSPnoaxn, "PDSPnoaxn" },
|
|
|
|
{ GDI_DSPDSoaxx, "DSPDSoaxx" },
|
|
|
|
{ GDI_PDSaxn, "PDSaxn" },
|
|
|
|
{ GDI_SRCAND, "DSa" },
|
|
|
|
{ GDI_SDPSnaoxn, "SDPSnaoxn" },
|
|
|
|
{ GDI_DSPnoa, "DSPnoa" },
|
|
|
|
{ GDI_DSPDxoxn, "DSPDxoxn" },
|
|
|
|
{ GDI_SDPnoa, "SDPnoa" },
|
|
|
|
{ GDI_SDPSxoxn, "SDPSxoxn" },
|
|
|
|
{ GDI_SSDxPDxax, "SSDxPDxax" },
|
|
|
|
{ GDI_PDSanan, "PDSanan" },
|
|
|
|
{ GDI_PDSxna, "PDSxna" },
|
|
|
|
{ GDI_SDPSnoaxn, "SDPSnoaxn" },
|
|
|
|
{ GDI_DPSDPoaxx, "DPSDPoaxx" },
|
|
|
|
{ GDI_SPDaxn, "SPDaxn" },
|
|
|
|
{ GDI_PSDPSoaxx, "PSDPSoaxx" },
|
|
|
|
{ GDI_DPSaxn, "DPSaxn" },
|
|
|
|
{ GDI_DPSxx, "DPSxx" },
|
|
|
|
{ GDI_PSDPSonoxx, "PSDPSonoxx" },
|
|
|
|
{ GDI_SDPSonoxn, "SDPSonoxn" },
|
|
|
|
{ GDI_DSxn, "DSxn" },
|
|
|
|
{ GDI_DPSnax, "DPSnax" },
|
|
|
|
{ GDI_SDPSoaxn, "SDPSoaxn" },
|
|
|
|
{ GDI_SPDnax, "SPDnax" },
|
|
|
|
{ GDI_DSPDoaxn, "DSPDoaxn" },
|
|
|
|
{ GDI_DSPDSaoxx, "DSPDSaoxx" },
|
|
|
|
{ GDI_PDSxan, "PDSxan" },
|
|
|
|
{ GDI_DPa, "DPa" },
|
|
|
|
{ GDI_PDSPnaoxn, "PDSPnaoxn" },
|
|
|
|
{ GDI_DPSnoa, "DPSnoa" },
|
|
|
|
{ GDI_DPSDxoxn, "DPSDxoxn" },
|
|
|
|
{ GDI_PDSPonoxn, "PDSPonoxn" },
|
|
|
|
{ GDI_PDxn, "PDxn" },
|
|
|
|
{ GDI_DSPnax, "DSPnax" },
|
|
|
|
{ GDI_PDSPoaxn, "PDSPoaxn" },
|
|
|
|
{ GDI_DPSoa, "DPSoa" },
|
|
|
|
{ GDI_DPSoxn, "DPSoxn" },
|
|
|
|
{ GDI_DSTCOPY, "D" },
|
|
|
|
{ GDI_DPSono, "DPSono" },
|
|
|
|
{ GDI_SPDSxax, "SPDSxax" },
|
|
|
|
{ GDI_DPSDaoxn, "DPSDaoxn" },
|
|
|
|
{ GDI_DSPnao, "DSPnao" },
|
|
|
|
{ GDI_DPno, "DPno" },
|
|
|
|
{ GDI_PDSnoa, "PDSnoa" },
|
|
|
|
{ GDI_PDSPxoxn, "PDSPxoxn" },
|
|
|
|
{ GDI_SSPxDSxox, "SSPxDSxox" },
|
|
|
|
{ GDI_SDPanan, "SDPanan" },
|
|
|
|
{ GDI_PSDnax, "PSDnax" },
|
|
|
|
{ GDI_DPSDoaxn, "DPSDoaxn" },
|
|
|
|
{ GDI_DPSDPaoxx, "DPSDPaoxx" },
|
|
|
|
{ GDI_SDPxan, "SDPxan" },
|
|
|
|
{ GDI_PSDPxax, "PSDPxax" },
|
|
|
|
{ GDI_DSPDaoxn, "DSPDaoxn" },
|
|
|
|
{ GDI_DPSnao, "DPSnao" },
|
|
|
|
{ GDI_MERGEPAINT, "DSno" },
|
|
|
|
{ GDI_SPDSanax, "SPDSanax" },
|
|
|
|
{ GDI_SDxPDxan, "SDxPDxan" },
|
|
|
|
{ GDI_DPSxo, "DPSxo" },
|
|
|
|
{ GDI_DPSano, "DPSano" },
|
|
|
|
{ GDI_MERGECOPY, "PSa" },
|
|
|
|
{ GDI_SPDSnaoxn, "SPDSnaoxn" },
|
|
|
|
{ GDI_SPDSonoxn, "SPDSonoxn" },
|
|
|
|
{ GDI_PSxn, "PSxn" },
|
|
|
|
{ GDI_SPDnoa, "SPDnoa" },
|
|
|
|
{ GDI_SPDSxoxn, "SPDSxoxn" },
|
|
|
|
{ GDI_SDPnax, "SDPnax" },
|
|
|
|
{ GDI_PSDPoaxn, "PSDPoaxn" },
|
|
|
|
{ GDI_SDPoa, "SDPoa" },
|
|
|
|
{ GDI_SPDoxn, "SPDoxn" },
|
|
|
|
{ GDI_DPSDxax, "DPSDxax" },
|
|
|
|
{ GDI_SPDSaoxn, "SPDSaoxn" },
|
|
|
|
{ GDI_SRCCOPY, "S" },
|
|
|
|
{ GDI_SDPono, "SDPono" },
|
|
|
|
{ GDI_SDPnao, "SDPnao" },
|
|
|
|
{ GDI_SPno, "SPno" },
|
|
|
|
{ GDI_PSDnoa, "PSDnoa" },
|
|
|
|
{ GDI_PSDPxoxn, "PSDPxoxn" },
|
|
|
|
{ GDI_PDSnax, "PDSnax" },
|
|
|
|
{ GDI_SPDSoaxn, "SPDSoaxn" },
|
|
|
|
{ GDI_SSPxPDxax, "SSPxPDxax" },
|
|
|
|
{ GDI_DPSanan, "DPSanan" },
|
|
|
|
{ GDI_PSDPSaoxx, "PSDPSaoxx" },
|
|
|
|
{ GDI_DPSxan, "DPSxan" },
|
|
|
|
{ GDI_PDSPxax, "PDSPxax" },
|
|
|
|
{ GDI_SDPSaoxn, "SDPSaoxn" },
|
|
|
|
{ GDI_DPSDanax, "DPSDanax" },
|
|
|
|
{ GDI_SPxDSxan, "SPxDSxan" },
|
|
|
|
{ GDI_SPDnao, "SPDnao" },
|
|
|
|
{ GDI_SDno, "SDno" },
|
|
|
|
{ GDI_SDPxo, "SDPxo" },
|
|
|
|
{ GDI_SDPano, "SDPano" },
|
|
|
|
{ GDI_PDSoa, "PDSoa" },
|
|
|
|
{ GDI_PDSoxn, "PDSoxn" },
|
|
|
|
{ GDI_DSPDxax, "DSPDxax" },
|
|
|
|
{ GDI_PSDPaoxn, "PSDPaoxn" },
|
|
|
|
{ GDI_SDPSxax, "SDPSxax" },
|
|
|
|
{ GDI_PDSPaoxn, "PDSPaoxn" },
|
|
|
|
{ GDI_SDPSanax, "SDPSanax" },
|
|
|
|
{ GDI_SPxPDxan, "SPxPDxan" },
|
|
|
|
{ GDI_SSPxDSxax, "SSPxDSxax" },
|
|
|
|
{ GDI_DSPDSanaxxn, "DSPDSanaxxn" },
|
|
|
|
{ GDI_DPSao, "DPSao" },
|
|
|
|
{ GDI_DPSxno, "DPSxno" },
|
|
|
|
{ GDI_SDPao, "SDPao" },
|
|
|
|
{ GDI_SDPxno, "SDPxno" },
|
|
|
|
{ GDI_SRCPAINT, "DSo" },
|
|
|
|
{ GDI_SDPnoo, "SDPnoo" },
|
|
|
|
{ GDI_PATCOPY, "P" },
|
|
|
|
{ GDI_PDSono, "PDSono" },
|
|
|
|
{ GDI_PDSnao, "PDSnao" },
|
|
|
|
{ GDI_PSno, "PSno" },
|
|
|
|
{ GDI_PSDnao, "PSDnao" },
|
|
|
|
{ GDI_PDno, "PDno" },
|
|
|
|
{ GDI_PDSxo, "PDSxo" },
|
|
|
|
{ GDI_PDSano, "PDSano" },
|
|
|
|
{ GDI_PDSao, "PDSao" },
|
|
|
|
{ GDI_PDSxno, "PDSxno" },
|
|
|
|
{ GDI_DPo, "DPo" },
|
|
|
|
{ GDI_PATPAINT, "DPSnoo" },
|
|
|
|
{ GDI_PSo, "PSo" },
|
|
|
|
{ GDI_PSDnoo, "PSDnoo" },
|
|
|
|
{ GDI_DPSoo, "DPSoo" },
|
|
|
|
{ GDI_WHITENESS, "1" } };
|
2011-07-01 05:23:36 +04:00
|
|
|
|
2013-02-04 18:58:22 +04:00
|
|
|
/* Hatch Patterns as monochrome data */
|
2019-11-06 17:24:51 +03:00
|
|
|
static const BYTE GDI_BS_HATCHED_PATTERNS[] = {
|
2013-02-04 18:58:22 +04:00
|
|
|
0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, /* HS_HORIZONTAL */
|
|
|
|
0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, /* HS_VERTICAL */
|
|
|
|
0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F, /* HS_FDIAGONAL */
|
|
|
|
0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0xFE, /* HS_BDIAGONAL */
|
|
|
|
0xF7, 0xF7, 0xF7, 0x00, 0xF7, 0xF7, 0xF7, 0xF7, /* HS_CROSS */
|
2019-11-06 17:24:51 +03:00
|
|
|
0x7E, 0xBD, 0xDB, 0xE7, 0xE7, 0xDB, 0xBD, 0x7E /* HS_DIACROSS */
|
2013-02-04 18:58:22 +04:00
|
|
|
};
|
|
|
|
|
2021-10-04 15:43:32 +03:00
|
|
|
BOOL gdi_decode_color(rdpGdi* gdi, const UINT32 srcColor, UINT32* color, UINT32* format)
|
2016-07-18 12:16:36 +03:00
|
|
|
{
|
2017-02-01 13:00:24 +03:00
|
|
|
UINT32 SrcFormat;
|
|
|
|
|
|
|
|
if (!gdi || !color || !gdi->context || !gdi->context->settings)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-05-02 11:55:44 +03:00
|
|
|
const UINT32 ColorDepth =
|
|
|
|
freerdp_settings_get_uint32(gdi->context->settings, FreeRDP_ColorDepth);
|
2017-02-01 13:00:24 +03:00
|
|
|
|
|
|
|
switch (ColorDepth)
|
|
|
|
{
|
|
|
|
case 32:
|
|
|
|
case 24:
|
|
|
|
SrcFormat = PIXEL_FORMAT_BGR24;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 16:
|
|
|
|
SrcFormat = PIXEL_FORMAT_RGB16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
SrcFormat = PIXEL_FORMAT_RGB15;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
SrcFormat = PIXEL_FORMAT_RGB8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-07-18 12:16:36 +03:00
|
|
|
|
|
|
|
if (format)
|
2017-02-01 13:00:24 +03:00
|
|
|
*format = gdi->dstFormat;
|
2016-07-18 12:16:36 +03:00
|
|
|
|
2017-11-24 15:19:48 +03:00
|
|
|
*color = FreeRDPConvertColor(srcColor, SrcFormat, gdi->dstFormat, &gdi->palette);
|
2016-07-18 12:16:36 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-01 05:23:36 +04:00
|
|
|
/* GDI Helper Functions */
|
2017-12-22 12:25:05 +03:00
|
|
|
DWORD gdi_rop3_code(BYTE code)
|
2011-07-01 05:23:36 +04:00
|
|
|
{
|
2017-12-22 12:25:05 +03:00
|
|
|
return rop3_code_table[code].code;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* gdi_rop3_code_string(BYTE code)
|
|
|
|
{
|
|
|
|
return rop3_code_table[code].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* gdi_rop3_string(DWORD rop)
|
|
|
|
{
|
|
|
|
const size_t count = sizeof(rop3_code_table) / sizeof(rop3_code_table[0]);
|
|
|
|
size_t x;
|
|
|
|
|
|
|
|
for (x = 0; x < count; x++)
|
|
|
|
{
|
|
|
|
if (rop3_code_table[x].code == rop)
|
|
|
|
return rop3_code_table[x].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "UNKNOWN";
|
2011-07-01 05:23:36 +04:00
|
|
|
}
|
|
|
|
|
2016-10-14 11:01:02 +03:00
|
|
|
UINT32 gdi_get_pixel_format(UINT32 bitsPerPixel)
|
2014-09-12 04:46:15 +04:00
|
|
|
{
|
2017-02-01 13:00:24 +03:00
|
|
|
UINT32 format;
|
2014-09-12 04:46:15 +04:00
|
|
|
|
|
|
|
switch (bitsPerPixel)
|
|
|
|
{
|
|
|
|
case 32:
|
2017-02-01 13:00:24 +03:00
|
|
|
format = PIXEL_FORMAT_BGRA32;
|
2014-09-12 04:46:15 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 24:
|
2016-10-14 11:01:02 +03:00
|
|
|
format = PIXEL_FORMAT_BGR24;
|
2014-09-12 04:46:15 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 16:
|
2016-10-14 11:01:02 +03:00
|
|
|
format = PIXEL_FORMAT_RGB16;
|
2014-09-12 04:46:15 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
2016-10-14 11:01:02 +03:00
|
|
|
format = PIXEL_FORMAT_RGB15;
|
2014-09-12 04:46:15 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
2016-10-14 11:01:02 +03:00
|
|
|
format = PIXEL_FORMAT_RGB8;
|
2014-09-12 04:46:15 +04:00
|
|
|
break;
|
2017-02-01 13:00:24 +03:00
|
|
|
|
|
|
|
default:
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Unsupported color depth %" PRIu32, bitsPerPixel);
|
2017-02-01 13:00:24 +03:00
|
|
|
format = 0;
|
|
|
|
break;
|
2014-09-12 04:46:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, BYTE* data)
|
2011-07-28 09:34:53 +04:00
|
|
|
{
|
2011-10-21 01:28:59 +04:00
|
|
|
gdiBitmap* bitmap;
|
2019-11-06 17:24:51 +03:00
|
|
|
bitmap = (gdiBitmap*)calloc(1, sizeof(gdiBitmap));
|
2014-07-08 23:07:19 +04:00
|
|
|
|
|
|
|
if (!bitmap)
|
2015-05-08 22:39:23 +03:00
|
|
|
goto fail_bitmap;
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!(bitmap->hdc = gdi_CreateCompatibleDC(gdi->hdc)))
|
|
|
|
goto fail_hdc;
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(gdi->log, WLOG_DEBUG, "gdi_bitmap_new: width:%d height:%d bpp:%d", width, height,
|
|
|
|
bpp);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
if (!data)
|
2011-10-21 01:28:59 +04:00
|
|
|
bitmap->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, width, height);
|
|
|
|
else
|
|
|
|
bitmap->bitmap = gdi_create_bitmap(gdi, width, height, bpp, data);
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!bitmap->bitmap)
|
|
|
|
goto fail_bitmap_bitmap;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi_SelectObject(bitmap->hdc, (HGDIOBJECT)bitmap->bitmap);
|
2011-10-21 01:28:59 +04:00
|
|
|
bitmap->org_bitmap = NULL;
|
|
|
|
return bitmap;
|
2015-05-08 22:39:23 +03:00
|
|
|
fail_bitmap_bitmap:
|
|
|
|
gdi_DeleteDC(bitmap->hdc);
|
|
|
|
fail_hdc:
|
|
|
|
free(bitmap);
|
|
|
|
fail_bitmap:
|
|
|
|
return NULL;
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void gdi_bitmap_free_ex(gdiBitmap* bitmap)
|
|
|
|
{
|
2014-02-13 20:59:05 +04:00
|
|
|
if (bitmap)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi_SelectObject(bitmap->hdc, (HGDIOBJECT)bitmap->org_bitmap);
|
|
|
|
gdi_DeleteObject((HGDIOBJECT)bitmap->bitmap);
|
2011-10-21 01:28:59 +04:00
|
|
|
gdi_DeleteDC(bitmap->hdc);
|
|
|
|
free(bitmap);
|
2011-07-28 09:34:53 +04:00
|
|
|
}
|
2011-07-28 22:32:16 +04:00
|
|
|
}
|
2011-07-28 09:34:53 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL gdi_bitmap_update(rdpContext* context, const BITMAP_UPDATE* bitmapUpdate)
|
2014-09-12 04:12:32 +04:00
|
|
|
{
|
|
|
|
UINT32 index;
|
2016-07-18 18:45:30 +03:00
|
|
|
|
|
|
|
if (!context || !bitmapUpdate || !context->gdi || !context->codecs)
|
2022-12-12 14:53:11 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
2023-01-23 14:03:18 +03:00
|
|
|
"Invalid arguments: context=%p, bitmapUpdate=%p, context->gdi=%p, "
|
2022-12-12 14:53:11 +03:00
|
|
|
"context->codecs=%p",
|
2023-01-23 14:03:18 +03:00
|
|
|
context, bitmapUpdate, context->gdi, context->codecs);
|
2016-07-18 18:45:30 +03:00
|
|
|
return FALSE;
|
2022-12-12 14:53:11 +03:00
|
|
|
}
|
2016-07-18 18:45:30 +03:00
|
|
|
|
2014-09-12 04:12:32 +04:00
|
|
|
for (index = 0; index < bitmapUpdate->number; index++)
|
|
|
|
{
|
2016-07-20 17:50:20 +03:00
|
|
|
const BITMAP_DATA* bitmap = &(bitmapUpdate->rectangles[index]);
|
2016-07-21 10:24:09 +03:00
|
|
|
rdpBitmap* bmp = Bitmap_Alloc(context);
|
|
|
|
|
|
|
|
if (!bmp)
|
2022-12-12 14:53:11 +03:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "Bitmap_Alloc failed");
|
2016-07-21 10:24:09 +03:00
|
|
|
return FALSE;
|
2022-12-12 14:53:11 +03:00
|
|
|
}
|
2016-07-21 10:24:09 +03:00
|
|
|
|
|
|
|
Bitmap_SetDimensions(bmp, bitmap->width, bitmap->height);
|
2016-07-21 11:07:42 +03:00
|
|
|
Bitmap_SetRectangle(bmp, bitmap->destLeft, bitmap->destTop, bitmap->destRight,
|
2016-08-04 17:58:07 +03:00
|
|
|
bitmap->destBottom);
|
2016-07-21 10:24:09 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!bmp->Decompress(context, bmp, bitmap->bitmapDataStream, bitmap->width, bitmap->height,
|
|
|
|
bitmap->bitsPerPixel, bitmap->bitmapLength, bitmap->compressed,
|
2016-08-04 17:58:07 +03:00
|
|
|
RDP_CODEC_ID_NONE))
|
2014-09-12 04:12:32 +04:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "bmp->Decompress failed");
|
2016-10-10 11:38:54 +03:00
|
|
|
Bitmap_Free(context, bmp);
|
2016-07-20 16:34:06 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-07-21 10:24:09 +03:00
|
|
|
|
|
|
|
if (!bmp->New(context, bmp))
|
2016-07-20 16:34:06 +03:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "bmp->New failed");
|
2016-10-10 11:38:54 +03:00
|
|
|
Bitmap_Free(context, bmp);
|
2016-07-20 16:34:06 +03:00
|
|
|
return FALSE;
|
2014-09-12 04:12:32 +04:00
|
|
|
}
|
2016-07-21 10:24:09 +03:00
|
|
|
|
2016-07-21 11:07:42 +03:00
|
|
|
if (!bmp->Paint(context, bmp))
|
2016-04-19 23:11:12 +03:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "bmp->Paint failed");
|
2016-10-10 11:38:54 +03:00
|
|
|
Bitmap_Free(context, bmp);
|
2016-07-20 16:34:06 +03:00
|
|
|
return FALSE;
|
2015-10-18 12:53:22 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-10-10 11:38:54 +03:00
|
|
|
Bitmap_Free(context, bmp);
|
2014-09-12 04:12:32 +04:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2014-09-12 04:12:32 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL gdi_palette_update(rdpContext* context, const PALETTE_UPDATE* palette)
|
2011-07-28 22:32:16 +04:00
|
|
|
{
|
2016-07-14 13:42:24 +03:00
|
|
|
UINT32 index;
|
2016-07-18 18:45:30 +03:00
|
|
|
rdpGdi* gdi;
|
|
|
|
|
|
|
|
if (!context || !palette)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gdi = context->gdi;
|
2016-04-23 12:25:55 +03:00
|
|
|
gdi->palette.format = gdi->dstFormat;
|
2014-09-18 02:30:09 +04:00
|
|
|
|
2016-07-14 13:42:24 +03:00
|
|
|
for (index = 0; index < palette->number; index++)
|
2014-09-18 02:30:09 +04:00
|
|
|
{
|
2016-07-14 13:42:24 +03:00
|
|
|
const PALETTE_ENTRY* pe = &(palette->entries[index]);
|
2016-04-19 23:11:12 +03:00
|
|
|
gdi->palette.palette[index] =
|
2017-11-24 15:19:48 +03:00
|
|
|
FreeRDPGetColor(gdi->dstFormat, pe->red, pe->green, pe->blue, 0xFF);
|
2014-09-18 02:30:09 +04:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-07-28 22:32:16 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL gdi_set_bounds(rdpContext* context, const rdpBounds* bounds)
|
2011-07-28 22:32:16 +04:00
|
|
|
{
|
2016-07-18 18:45:30 +03:00
|
|
|
rdpGdi* gdi;
|
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gdi = context->gdi;
|
2011-07-28 22:32:16 +04:00
|
|
|
|
2014-02-13 20:59:05 +04:00
|
|
|
if (bounds)
|
2011-07-28 22:32:16 +04:00
|
|
|
{
|
|
|
|
gdi_SetClipRgn(gdi->drawing->hdc, bounds->left, bounds->top,
|
2016-08-04 17:58:07 +03:00
|
|
|
bounds->right - bounds->left + 1, bounds->bottom - bounds->top + 1);
|
2011-07-28 22:32:16 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
gdi_SetNullClipRgn(gdi->drawing->hdc);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-07-28 22:32:16 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL gdi_dstblt(rdpContext* context, const DSTBLT_ORDER* dstblt)
|
2011-08-02 20:59:45 +04:00
|
|
|
{
|
2016-07-18 13:36:22 +03:00
|
|
|
rdpGdi* gdi;
|
|
|
|
|
|
|
|
if (!context || !dstblt)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gdi = context->gdi;
|
2019-11-06 17:24:51 +03:00
|
|
|
return gdi_BitBlt(gdi->drawing->hdc, dstblt->nLeftRect, dstblt->nTopRect, dstblt->nWidth,
|
|
|
|
dstblt->nHeight, NULL, 0, 0, gdi_rop3_code(dstblt->bRop), &gdi->palette);
|
2011-08-02 20:59:45 +04:00
|
|
|
}
|
|
|
|
|
2018-10-18 10:09:30 +03:00
|
|
|
static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
|
2011-08-02 20:59:45 +04:00
|
|
|
{
|
2016-04-25 10:42:59 +03:00
|
|
|
const rdpBrush* brush = &patblt->brush;
|
2014-02-13 20:59:05 +04:00
|
|
|
UINT32 foreColor;
|
|
|
|
UINT32 backColor;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 originalColor;
|
2016-08-02 15:16:49 +03:00
|
|
|
HGDI_BRUSH originalBrush, hbrush = NULL;
|
2011-11-22 03:11:43 +04:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2016-08-02 15:16:49 +03:00
|
|
|
BOOL ret = FALSE;
|
2016-07-18 12:16:36 +03:00
|
|
|
const DWORD rop = gdi_rop3_code(patblt->bRop);
|
2018-11-13 19:06:09 +03:00
|
|
|
INT32 nXSrc = 0;
|
|
|
|
INT32 nYSrc = 0;
|
2016-08-02 15:16:49 +03:00
|
|
|
BYTE data[8 * 8 * 4];
|
|
|
|
HGDI_BITMAP hBmp = NULL;
|
2016-07-18 12:16:36 +03:00
|
|
|
|
2016-07-18 13:36:22 +03:00
|
|
|
if (!gdi_decode_color(gdi, patblt->foreColor, &foreColor, NULL))
|
2016-07-18 12:16:36 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2016-07-18 13:36:22 +03:00
|
|
|
if (!gdi_decode_color(gdi, patblt->backColor, &backColor, NULL))
|
2016-07-18 12:16:36 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2014-02-13 20:59:05 +04:00
|
|
|
originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);
|
2016-08-02 15:16:49 +03:00
|
|
|
originalBrush = gdi->drawing->hdc->brush;
|
2014-02-13 20:59:05 +04:00
|
|
|
|
2016-07-14 13:42:24 +03:00
|
|
|
switch (brush->style)
|
2011-08-02 20:59:45 +04:00
|
|
|
{
|
2016-07-14 13:42:24 +03:00
|
|
|
case GDI_BS_SOLID:
|
2016-08-02 15:16:49 +03:00
|
|
|
hbrush = gdi_CreateSolidBrush(foreColor);
|
2016-07-14 13:42:24 +03:00
|
|
|
break;
|
2014-10-22 05:56:10 +04:00
|
|
|
|
2016-07-14 13:42:24 +03:00
|
|
|
case GDI_BS_HATCHED:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
const BYTE* hatched;
|
|
|
|
hatched = GDI_BS_HATCHED_PATTERNS + (8 * brush->hatch);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_image_copy_from_monochrome(data, gdi->drawing->hdc->format, 0, 0, 0, 8, 8,
|
|
|
|
hatched, backColor, foreColor, &gdi->palette))
|
|
|
|
goto out_error;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hBmp = gdi_CreateBitmapEx(8, 8, gdi->drawing->hdc->format, 0, data, NULL);
|
2013-02-04 18:58:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!hBmp)
|
|
|
|
goto out_error;
|
2011-08-02 20:59:45 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hbrush = gdi_CreateHatchBrush(hBmp);
|
|
|
|
}
|
|
|
|
break;
|
2014-10-22 05:56:10 +04:00
|
|
|
|
2016-07-14 13:42:24 +03:00
|
|
|
case GDI_BS_PATTERN:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
UINT32 brushFormat;
|
2014-10-22 05:56:10 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (brush->bpp > 1)
|
|
|
|
{
|
|
|
|
UINT32 bpp = brush->bpp;
|
2017-11-20 17:00:09 +03:00
|
|
|
|
2022-05-02 11:55:44 +03:00
|
|
|
if ((bpp == 16) &&
|
|
|
|
(freerdp_settings_get_uint32(context->settings, FreeRDP_ColorDepth) == 15))
|
2019-11-06 17:24:51 +03:00
|
|
|
bpp = 15;
|
2017-11-20 17:00:09 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
brushFormat = gdi_get_pixel_format(bpp);
|
2016-07-14 13:42:24 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_image_copy(data, gdi->drawing->hdc->format, 0, 0, 0, 8, 8, brush->data,
|
|
|
|
brushFormat, 0, 0, 0, &gdi->palette, FREERDP_FLIP_NONE))
|
|
|
|
goto out_error;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!freerdp_image_copy_from_monochrome(data, gdi->drawing->hdc->format, 0, 0, 0, 8,
|
|
|
|
8, brush->data, backColor, foreColor,
|
|
|
|
&gdi->palette))
|
|
|
|
goto out_error;
|
|
|
|
}
|
2011-08-02 20:59:45 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hBmp = gdi_CreateBitmapEx(8, 8, gdi->drawing->hdc->format, 0, data, NULL);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!hBmp)
|
|
|
|
goto out_error;
|
2011-08-02 20:59:45 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hbrush = gdi_CreatePatternBrush(hBmp);
|
|
|
|
}
|
|
|
|
break;
|
2016-07-14 13:42:24 +03:00
|
|
|
|
|
|
|
default:
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "unimplemented brush style:%" PRIu32 "", brush->style);
|
2016-07-14 13:42:24 +03:00
|
|
|
break;
|
2011-08-04 11:39:10 +04:00
|
|
|
}
|
2014-02-13 20:59:05 +04:00
|
|
|
|
2018-10-16 09:45:06 +03:00
|
|
|
if (hbrush)
|
2016-08-02 15:16:49 +03:00
|
|
|
{
|
|
|
|
hbrush->nXOrg = brush->x;
|
|
|
|
hbrush->nYOrg = brush->y;
|
|
|
|
gdi->drawing->hdc->brush = hbrush;
|
2019-11-06 17:24:51 +03:00
|
|
|
ret = gdi_BitBlt(gdi->drawing->hdc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth,
|
|
|
|
patblt->nHeight, gdi->primary->hdc, nXSrc, nYSrc, rop, &gdi->palette);
|
2016-08-02 15:16:49 +03:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
out_error:
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi_DeleteObject((HGDIOBJECT)hBmp);
|
|
|
|
gdi_DeleteObject((HGDIOBJECT)hbrush);
|
2016-08-02 15:16:49 +03:00
|
|
|
gdi->drawing->hdc->brush = originalBrush;
|
2014-02-13 20:59:05 +04:00
|
|
|
gdi_SetTextColor(gdi->drawing->hdc, originalColor);
|
2015-04-14 11:14:23 +03:00
|
|
|
return ret;
|
2011-08-02 20:59:45 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL gdi_scrblt(rdpContext* context, const SCRBLT_ORDER* scrblt)
|
2011-08-02 20:59:45 +04:00
|
|
|
{
|
2016-07-18 18:45:30 +03:00
|
|
|
rdpGdi* gdi;
|
|
|
|
|
|
|
|
if (!context || !context->gdi)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gdi = context->gdi;
|
2019-11-06 17:24:51 +03:00
|
|
|
return gdi_BitBlt(gdi->drawing->hdc, scrblt->nLeftRect, scrblt->nTopRect, scrblt->nWidth,
|
|
|
|
scrblt->nHeight, gdi->primary->hdc, scrblt->nXSrc, scrblt->nYSrc,
|
|
|
|
gdi_rop3_code(scrblt->bRop), &gdi->palette);
|
2011-08-02 20:59:45 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL gdi_opaque_rect(rdpContext* context, const OPAQUE_RECT_ORDER* opaque_rect)
|
2011-07-28 22:32:16 +04:00
|
|
|
{
|
|
|
|
GDI_RECT rect;
|
|
|
|
HGDI_BRUSH hBrush;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 brush_color;
|
2014-02-13 20:59:05 +04:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2015-06-26 15:32:38 +03:00
|
|
|
BOOL ret;
|
2018-10-22 15:12:22 +03:00
|
|
|
INT32 x = opaque_rect->nLeftRect;
|
|
|
|
INT32 y = opaque_rect->nTopRect;
|
|
|
|
INT32 w = opaque_rect->nWidth;
|
|
|
|
INT32 h = opaque_rect->nHeight;
|
|
|
|
gdi_ClipCoords(gdi->drawing->hdc, &x, &y, &w, &h, NULL, NULL);
|
|
|
|
gdi_CRgnToRect(x, y, w, h, &rect);
|
2016-07-18 12:16:36 +03:00
|
|
|
|
2016-07-18 13:36:22 +03:00
|
|
|
if (!gdi_decode_color(gdi, opaque_rect->color, &brush_color, NULL))
|
2016-07-18 12:16:36 +03:00
|
|
|
return FALSE;
|
2011-07-28 22:32:16 +04:00
|
|
|
|
2015-06-26 15:32:38 +03:00
|
|
|
if (!(hBrush = gdi_CreateSolidBrush(brush_color)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ret = gdi_FillRect(gdi->drawing->hdc, &rect, hBrush);
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi_DeleteObject((HGDIOBJECT)hBrush);
|
2015-04-14 11:14:23 +03:00
|
|
|
return ret;
|
2011-07-28 09:34:53 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL gdi_multi_opaque_rect(rdpContext* context,
|
2016-08-04 17:58:07 +03:00
|
|
|
const MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect)
|
2011-08-02 20:59:45 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 i;
|
2011-08-04 01:09:12 +04:00
|
|
|
GDI_RECT rect;
|
|
|
|
HGDI_BRUSH hBrush;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 brush_color;
|
2014-02-13 20:59:05 +04:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL ret = TRUE;
|
2011-08-04 01:09:12 +04:00
|
|
|
|
2016-07-18 13:36:22 +03:00
|
|
|
if (!gdi_decode_color(gdi, multi_opaque_rect->color, &brush_color, NULL))
|
2016-07-18 12:16:36 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hBrush = gdi_CreateSolidBrush(brush_color);
|
|
|
|
|
|
|
|
if (!hBrush)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-07-19 14:02:08 +03:00
|
|
|
for (i = 0; i < multi_opaque_rect->numRectangles; i++)
|
2011-08-04 01:09:12 +04:00
|
|
|
{
|
2016-07-18 12:16:36 +03:00
|
|
|
const DELTA_RECT* rectangle = &multi_opaque_rect->rectangles[i];
|
2018-10-22 15:12:22 +03:00
|
|
|
INT32 x = rectangle->left;
|
|
|
|
INT32 y = rectangle->top;
|
|
|
|
INT32 w = rectangle->width;
|
|
|
|
INT32 h = rectangle->height;
|
|
|
|
gdi_ClipCoords(gdi->drawing->hdc, &x, &y, &w, &h, NULL, NULL);
|
|
|
|
gdi_CRgnToRect(x, y, w, h, &rect);
|
2016-07-19 14:02:08 +03:00
|
|
|
ret = gdi_FillRect(gdi->drawing->hdc, &rect, hBrush);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
break;
|
2011-08-13 12:52:05 +04:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi_DeleteObject((HGDIOBJECT)hBrush);
|
2015-04-14 11:14:23 +03:00
|
|
|
return ret;
|
2011-08-02 20:59:45 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL gdi_line_to(rdpContext* context, const LINE_TO_ORDER* lineTo)
|
2011-08-03 11:29:56 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 color;
|
2011-08-03 11:29:56 +04:00
|
|
|
HGDI_PEN hPen;
|
2014-02-13 20:59:05 +04:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2018-11-19 19:24:24 +03:00
|
|
|
INT32 xStart = lineTo->nXStart;
|
|
|
|
INT32 yStart = lineTo->nYStart;
|
|
|
|
INT32 xEnd = lineTo->nXEnd;
|
|
|
|
INT32 yEnd = lineTo->nYEnd;
|
|
|
|
INT32 w = 0;
|
|
|
|
INT32 h = 0;
|
|
|
|
gdi_ClipCoords(gdi->drawing->hdc, &xStart, &yStart, &w, &h, NULL, NULL);
|
|
|
|
gdi_ClipCoords(gdi->drawing->hdc, &xEnd, &yEnd, &w, &h, NULL, NULL);
|
2016-07-18 12:16:36 +03:00
|
|
|
|
2017-01-09 18:35:34 +03:00
|
|
|
if (!gdi_decode_color(gdi, lineTo->penColor, &color, NULL))
|
2016-07-18 12:16:36 +03:00
|
|
|
return FALSE;
|
2011-08-03 11:29:56 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!(hPen = gdi_CreatePen(lineTo->penStyle, lineTo->penWidth, color, gdi->drawing->hdc->format,
|
|
|
|
&gdi->palette)))
|
2015-04-14 11:14:23 +03:00
|
|
|
return FALSE;
|
2015-06-26 15:32:38 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT)hPen);
|
2014-02-13 20:59:05 +04:00
|
|
|
gdi_SetROP2(gdi->drawing->hdc, lineTo->bRop2);
|
|
|
|
gdi_MoveToEx(gdi->drawing->hdc, lineTo->nXStart, lineTo->nYStart, NULL);
|
|
|
|
gdi_LineTo(gdi->drawing->hdc, lineTo->nXEnd, lineTo->nYEnd);
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi_DeleteObject((HGDIOBJECT)hPen);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-08-03 11:29:56 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL gdi_polyline(rdpContext* context, const POLYLINE_ORDER* polyline)
|
2011-08-05 00:22:15 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 i;
|
2014-02-13 20:59:05 +04:00
|
|
|
INT32 x;
|
|
|
|
INT32 y;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 color;
|
2011-08-05 00:22:15 +04:00
|
|
|
HGDI_PEN hPen;
|
|
|
|
DELTA_POINT* points;
|
2011-11-22 03:11:43 +04:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2018-11-19 19:24:24 +03:00
|
|
|
INT32 w = 0, h = 0;
|
2016-07-18 12:16:36 +03:00
|
|
|
|
2016-11-14 11:36:16 +03:00
|
|
|
if (!gdi_decode_color(gdi, polyline->penColor, &color, NULL))
|
2016-07-18 12:16:36 +03:00
|
|
|
return FALSE;
|
2011-08-05 00:22:15 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 1, color, gdi->drawing->hdc->format, &gdi->palette)))
|
2015-04-14 11:14:23 +03:00
|
|
|
return FALSE;
|
2015-06-26 15:32:38 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT)hPen);
|
2011-08-05 00:22:15 +04:00
|
|
|
gdi_SetROP2(gdi->drawing->hdc, polyline->bRop2);
|
2011-12-02 07:59:23 +04:00
|
|
|
x = polyline->xStart;
|
|
|
|
y = polyline->yStart;
|
2018-11-19 19:24:24 +03:00
|
|
|
gdi_ClipCoords(gdi->drawing->hdc, &x, &y, &w, &h, NULL, NULL);
|
2011-12-02 07:59:23 +04:00
|
|
|
gdi_MoveToEx(gdi->drawing->hdc, x, y, NULL);
|
2011-08-05 00:22:15 +04:00
|
|
|
points = polyline->points;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-07-19 14:02:08 +03:00
|
|
|
for (i = 0; i < polyline->numDeltaEntries; i++)
|
2011-08-05 00:22:15 +04:00
|
|
|
{
|
2011-12-02 07:59:23 +04:00
|
|
|
x += points[i].x;
|
|
|
|
y += points[i].y;
|
2018-11-19 19:24:24 +03:00
|
|
|
gdi_ClipCoords(gdi->drawing->hdc, &x, &y, &w, &h, NULL, NULL);
|
2011-12-02 07:59:23 +04:00
|
|
|
gdi_LineTo(gdi->drawing->hdc, x, y);
|
|
|
|
gdi_MoveToEx(gdi->drawing->hdc, x, y, NULL);
|
2011-08-05 00:22:15 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi_DeleteObject((HGDIOBJECT)hPen);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-08-05 00:22:15 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
static BOOL gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
|
2011-10-05 05:29:01 +04:00
|
|
|
{
|
2016-07-18 18:45:30 +03:00
|
|
|
gdiBitmap* bitmap;
|
|
|
|
rdpGdi* gdi;
|
|
|
|
|
|
|
|
if (!context || !memblt || !context->gdi || !memblt->bitmap)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
bitmap = (gdiBitmap*)memblt->bitmap;
|
2016-07-18 18:45:30 +03:00
|
|
|
gdi = context->gdi;
|
2019-11-06 17:24:51 +03:00
|
|
|
return gdi_BitBlt(gdi->drawing->hdc, memblt->nLeftRect, memblt->nTopRect, memblt->nWidth,
|
|
|
|
memblt->nHeight, bitmap->hdc, memblt->nXSrc, memblt->nYSrc,
|
|
|
|
gdi_rop3_code(memblt->bRop), &gdi->palette);
|
2011-10-05 05:29:01 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
|
2011-10-05 05:29:01 +04:00
|
|
|
{
|
2012-02-13 04:41:39 +04:00
|
|
|
HGDI_BRUSH originalBrush;
|
|
|
|
rdpGdi* gdi = context->gdi;
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL ret = TRUE;
|
2016-07-14 13:42:24 +03:00
|
|
|
const rdpBrush* brush = &mem3blt->brush;
|
2019-11-06 17:24:51 +03:00
|
|
|
gdiBitmap* bitmap = (gdiBitmap*)mem3blt->bitmap;
|
2016-07-18 12:16:36 +03:00
|
|
|
UINT32 foreColor;
|
|
|
|
UINT32 backColor;
|
|
|
|
UINT32 originalColor;
|
|
|
|
|
2016-07-18 13:36:22 +03:00
|
|
|
if (!gdi_decode_color(gdi, mem3blt->foreColor, &foreColor, NULL))
|
2016-07-18 12:16:36 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2016-07-18 13:36:22 +03:00
|
|
|
if (!gdi_decode_color(gdi, mem3blt->backColor, &backColor, NULL))
|
2016-07-18 12:16:36 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);
|
2016-07-14 13:42:24 +03:00
|
|
|
|
|
|
|
switch (brush->style)
|
2013-02-04 20:40:40 +04:00
|
|
|
{
|
2016-07-14 13:42:24 +03:00
|
|
|
case GDI_BS_SOLID:
|
|
|
|
originalBrush = gdi->drawing->hdc->brush;
|
|
|
|
gdi->drawing->hdc->brush = gdi_CreateSolidBrush(foreColor);
|
2013-02-04 20:40:40 +04:00
|
|
|
|
2016-07-14 13:42:24 +03:00
|
|
|
if (!gdi->drawing->hdc->brush)
|
2015-04-14 11:14:23 +03:00
|
|
|
{
|
|
|
|
ret = FALSE;
|
|
|
|
goto out_fail;
|
|
|
|
}
|
2014-10-22 05:56:10 +04:00
|
|
|
|
2016-07-14 13:42:24 +03:00
|
|
|
ret = gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
|
2019-11-06 17:24:51 +03:00
|
|
|
mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc, mem3blt->nXSrc,
|
|
|
|
mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop), &gdi->palette);
|
|
|
|
gdi_DeleteObject((HGDIOBJECT)gdi->drawing->hdc->brush);
|
2016-07-14 13:42:24 +03:00
|
|
|
gdi->drawing->hdc->brush = originalBrush;
|
|
|
|
break;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-07-14 13:42:24 +03:00
|
|
|
case GDI_BS_PATTERN:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
HGDI_BITMAP hBmp;
|
|
|
|
UINT32 brushFormat;
|
2022-05-11 12:28:55 +03:00
|
|
|
BYTE* data = (BYTE*)winpr_aligned_malloc(
|
2022-04-28 06:43:31 +03:00
|
|
|
8 * 8 * FreeRDPGetBytesPerPixel(gdi->drawing->hdc->format), 16);
|
2014-10-22 05:56:10 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
ret = FALSE;
|
|
|
|
goto out_fail;
|
|
|
|
}
|
2013-02-04 20:40:40 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (brush->bpp > 1)
|
|
|
|
{
|
|
|
|
UINT32 bpp = brush->bpp;
|
2017-11-20 17:00:09 +03:00
|
|
|
|
2022-06-23 10:09:55 +03:00
|
|
|
const UINT32 ColorDepth =
|
|
|
|
freerdp_settings_get_uint32(gdi->context->settings, FreeRDP_ColorDepth);
|
|
|
|
if ((bpp == 16) && (ColorDepth == 15))
|
2019-11-06 17:24:51 +03:00
|
|
|
bpp = 15;
|
2017-11-20 17:00:09 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
brushFormat = gdi_get_pixel_format(bpp);
|
2016-07-14 13:42:24 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_image_copy(data, gdi->drawing->hdc->format, 0, 0, 0, 8, 8, brush->data,
|
|
|
|
brushFormat, 0, 0, 0, &gdi->palette, FREERDP_FLIP_NONE))
|
2016-07-14 13:42:24 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
ret = FALSE;
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(data);
|
2019-11-06 17:24:51 +03:00
|
|
|
goto out_fail;
|
2016-07-14 13:42:24 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!freerdp_image_copy_from_monochrome(data, gdi->drawing->hdc->format, 0, 0, 0, 8,
|
|
|
|
8, brush->data, backColor, foreColor,
|
|
|
|
&gdi->palette))
|
2016-07-14 13:42:24 +03:00
|
|
|
{
|
|
|
|
ret = FALSE;
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(data);
|
2016-07-14 13:42:24 +03:00
|
|
|
goto out_fail;
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->format, data);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!hBmp)
|
|
|
|
{
|
|
|
|
ret = FALSE;
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(data);
|
2019-11-06 17:24:51 +03:00
|
|
|
goto out_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
originalBrush = gdi->drawing->hdc->brush;
|
|
|
|
gdi->drawing->hdc->brush = gdi_CreatePatternBrush(hBmp);
|
2016-07-14 13:42:24 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!gdi->drawing->hdc->brush)
|
|
|
|
{
|
|
|
|
gdi_DeleteObject((HGDIOBJECT)hBmp);
|
|
|
|
goto out_fail;
|
2016-07-14 13:42:24 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
|
|
|
gdi->drawing->hdc->brush->nXOrg = brush->x;
|
|
|
|
gdi->drawing->hdc->brush->nYOrg = brush->y;
|
|
|
|
ret = gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
|
|
|
|
mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc, mem3blt->nXSrc,
|
|
|
|
mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop), &gdi->palette);
|
|
|
|
gdi_DeleteObject((HGDIOBJECT)gdi->drawing->hdc->brush);
|
|
|
|
gdi_DeleteObject((HGDIOBJECT)hBmp);
|
|
|
|
gdi->drawing->hdc->brush = originalBrush;
|
|
|
|
}
|
|
|
|
break;
|
2016-07-14 13:42:24 +03:00
|
|
|
|
|
|
|
default:
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Mem3Blt unimplemented brush style:%" PRIu32 "", brush->style);
|
2016-07-14 13:42:24 +03:00
|
|
|
break;
|
2012-02-13 04:41:39 +04:00
|
|
|
}
|
2014-02-12 03:02:26 +04:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
out_fail:
|
2014-02-12 03:02:26 +04:00
|
|
|
gdi_SetTextColor(gdi->drawing->hdc, originalColor);
|
2015-04-14 11:14:23 +03:00
|
|
|
return ret;
|
2012-02-13 00:21:08 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL gdi_polygon_sc(rdpContext* context, const POLYGON_SC_ORDER* polygon_sc)
|
2012-02-13 00:21:08 +04:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "not implemented");
|
2016-07-19 14:02:08 +03:00
|
|
|
return FALSE;
|
2012-02-13 00:21:08 +04:00
|
|
|
}
|
2011-10-05 05:29:01 +04:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
static BOOL gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb)
|
2012-02-13 00:21:08 +04:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "not implemented");
|
2016-07-19 14:02:08 +03:00
|
|
|
return FALSE;
|
2012-02-13 00:21:08 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL gdi_ellipse_sc(rdpContext* context, const ELLIPSE_SC_ORDER* ellipse_sc)
|
2012-02-13 00:21:08 +04:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "not implemented");
|
2016-07-19 14:02:08 +03:00
|
|
|
return FALSE;
|
2012-02-13 00:21:08 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL gdi_ellipse_cb(rdpContext* context, const ELLIPSE_CB_ORDER* ellipse_cb)
|
2012-02-13 00:21:08 +04:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "not implemented");
|
2016-07-19 14:02:08 +03:00
|
|
|
return FALSE;
|
2011-10-05 05:29:01 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL gdi_frame_marker(rdpContext* context, const FRAME_MARKER_ORDER* frameMarker)
|
2014-09-06 00:06:19 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2014-09-06 00:06:19 +04:00
|
|
|
}
|
|
|
|
|
2019-11-20 13:30:14 +03:00
|
|
|
static BOOL gdi_surface_frame_marker(rdpContext* context,
|
|
|
|
const SURFACE_FRAME_MARKER* surfaceFrameMarker)
|
2013-07-15 17:00:18 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(context->gdi->log, WLOG_DEBUG, "frameId %" PRIu32 " frameAction %" PRIu32 "",
|
|
|
|
surfaceFrameMarker->frameId, surfaceFrameMarker->frameAction);
|
2013-07-15 17:00:18 +04:00
|
|
|
|
2014-09-19 22:45:58 +04:00
|
|
|
switch (surfaceFrameMarker->frameAction)
|
2013-07-15 17:00:18 +04:00
|
|
|
{
|
|
|
|
case SURFACECMD_FRAMEACTION_BEGIN:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SURFACECMD_FRAMEACTION_END:
|
2022-05-02 11:55:44 +03:00
|
|
|
if (freerdp_settings_get_uint32(context->settings, FreeRDP_FrameAcknowledge) > 0)
|
2013-07-15 17:00:18 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
IFCALL(context->update->SurfaceFrameAcknowledge, context,
|
2016-04-25 10:42:59 +03:00
|
|
|
surfaceFrameMarker->frameId);
|
2013-07-15 17:00:18 +04:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-07-15 17:00:18 +04:00
|
|
|
break;
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-07-15 17:00:18 +04:00
|
|
|
}
|
|
|
|
|
2023-05-22 11:28:42 +03:00
|
|
|
static BOOL intersect_rect(const rdpGdi* gdi, const SURFACE_BITS_COMMAND* cmd, RECTANGLE_16* prect)
|
|
|
|
{
|
|
|
|
const UINT32 w = (const UINT32)gdi->width;
|
|
|
|
const UINT32 h = (const UINT32)gdi->height;
|
|
|
|
|
|
|
|
if (cmd->destLeft > w)
|
|
|
|
return FALSE;
|
|
|
|
if (cmd->destRight > w)
|
|
|
|
return FALSE;
|
|
|
|
if (cmd->destLeft > cmd->destRight)
|
|
|
|
return FALSE;
|
|
|
|
if (cmd->destRight > UINT16_MAX)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (cmd->destTop > h)
|
|
|
|
return FALSE;
|
|
|
|
if (cmd->destBottom > h)
|
|
|
|
return FALSE;
|
|
|
|
if (cmd->destTop > cmd->destBottom)
|
|
|
|
return FALSE;
|
|
|
|
if (cmd->destBottom > UINT16_MAX)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
prect->left = (const UINT16)cmd->destLeft;
|
|
|
|
prect->top = (const UINT16)cmd->destTop;
|
|
|
|
prect->right = MIN((UINT16)cmd->destRight, prect->left + cmd->bmp.width);
|
|
|
|
prect->bottom = MIN((UINT16)cmd->destBottom, prect->top + cmd->bmp.height);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL gdi_surface_bits(rdpContext* context, const SURFACE_BITS_COMMAND* cmd)
|
2011-08-10 18:51:55 +04:00
|
|
|
{
|
2017-03-27 10:00:27 +03:00
|
|
|
BOOL result = FALSE;
|
2016-10-11 19:44:50 +03:00
|
|
|
DWORD format;
|
2023-05-22 11:28:42 +03:00
|
|
|
rdpGdi* gdi = NULL;
|
2019-11-28 10:08:30 +03:00
|
|
|
size_t size;
|
2017-03-27 10:00:27 +03:00
|
|
|
REGION16 region;
|
2023-05-22 11:28:42 +03:00
|
|
|
RECTANGLE_16 cmdRect = { 0 };
|
|
|
|
UINT32 nbRects;
|
|
|
|
const RECTANGLE_16* rects = NULL;
|
2016-08-04 17:58:07 +03:00
|
|
|
|
|
|
|
if (!context || !cmd)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gdi = context->gdi;
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(
|
|
|
|
gdi->log, WLOG_DEBUG,
|
|
|
|
"destLeft %" PRIu32 " destTop %" PRIu32 " destRight %" PRIu32 " destBottom %" PRIu32 " "
|
|
|
|
"bpp %" PRIu8 " flags %" PRIx8 " codecID %" PRIu16 " width %" PRIu16 " height %" PRIu16
|
|
|
|
" length %" PRIu32 "",
|
|
|
|
cmd->destLeft, cmd->destTop, cmd->destRight, cmd->destBottom, cmd->bmp.bpp, cmd->bmp.flags,
|
|
|
|
cmd->bmp.codecID, cmd->bmp.width, cmd->bmp.height, cmd->bmp.bitmapDataLength);
|
2017-03-27 10:00:27 +03:00
|
|
|
region16_init(®ion);
|
2023-05-22 11:28:42 +03:00
|
|
|
|
|
|
|
if (!intersect_rect(gdi, cmd, &cmdRect))
|
|
|
|
goto out;
|
2017-03-27 10:00:27 +03:00
|
|
|
|
2018-02-28 12:10:09 +03:00
|
|
|
switch (cmd->bmp.codecID)
|
2016-04-11 18:30:29 +03:00
|
|
|
{
|
2016-04-25 10:42:59 +03:00
|
|
|
case RDP_CODEC_ID_REMOTEFX:
|
2022-05-26 16:33:49 +03:00
|
|
|
case RDP_CODEC_ID_IMAGE_REMOTEFX:
|
2018-02-28 12:10:09 +03:00
|
|
|
if (!rfx_process_message(context->codecs->rfx, cmd->bmp.bitmapData,
|
2023-05-22 11:28:42 +03:00
|
|
|
cmd->bmp.bitmapDataLength, cmdRect.left, cmdRect.top,
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi->primary_buffer, gdi->dstFormat, gdi->stride, gdi->height,
|
|
|
|
®ion))
|
2016-04-25 10:42:59 +03:00
|
|
|
{
|
2016-10-11 19:44:50 +03:00
|
|
|
WLog_ERR(TAG, "Failed to process RemoteFX message");
|
2017-03-27 10:00:27 +03:00
|
|
|
goto out;
|
2016-04-25 10:42:59 +03:00
|
|
|
}
|
2017-11-20 17:00:09 +03:00
|
|
|
|
2016-04-25 10:42:59 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RDP_CODEC_ID_NSCODEC:
|
2016-10-14 11:01:02 +03:00
|
|
|
format = gdi->dstFormat;
|
2016-10-11 19:44:50 +03:00
|
|
|
|
2023-05-22 11:28:42 +03:00
|
|
|
if (!nsc_process_message(
|
|
|
|
context->codecs->nsc, cmd->bmp.bpp, cmd->bmp.width, cmd->bmp.height,
|
|
|
|
cmd->bmp.bitmapData, cmd->bmp.bitmapDataLength, gdi->primary_buffer, format,
|
|
|
|
gdi->stride, cmdRect.left, cmdRect.top, cmdRect.right - cmdRect.left,
|
|
|
|
cmdRect.bottom - cmdRect.top, FREERDP_FLIP_VERTICAL))
|
2017-03-27 10:00:27 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to process NSCodec message");
|
|
|
|
goto out;
|
|
|
|
}
|
2017-11-20 17:00:09 +03:00
|
|
|
|
2017-03-27 10:00:27 +03:00
|
|
|
region16_union_rect(®ion, ®ion, &cmdRect);
|
2016-04-25 10:42:59 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RDP_CODEC_ID_NONE:
|
2018-02-28 12:10:09 +03:00
|
|
|
format = gdi_get_pixel_format(cmd->bmp.bpp);
|
2023-08-22 10:41:28 +03:00
|
|
|
size = 1ull * cmd->bmp.width * cmd->bmp.height * FreeRDPGetBytesPerPixel(format);
|
2019-11-28 10:08:30 +03:00
|
|
|
if (size > cmd->bmp.bitmapDataLength)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Short nocodec message: got %" PRIu32 " bytes, require %" PRIuz,
|
|
|
|
cmd->bmp.bitmapDataLength, size);
|
|
|
|
goto out;
|
|
|
|
}
|
2023-05-22 11:28:42 +03:00
|
|
|
|
|
|
|
if (!freerdp_image_copy(gdi->primary_buffer, gdi->dstFormat, gdi->stride, cmdRect.left,
|
|
|
|
cmdRect.top, cmdRect.right - cmdRect.left,
|
|
|
|
cmdRect.bottom - cmdRect.top, cmd->bmp.bitmapData, format, 0, 0,
|
|
|
|
0, &gdi->palette, FREERDP_FLIP_VERTICAL))
|
2017-03-27 10:00:27 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to process nocodec message");
|
|
|
|
goto out;
|
|
|
|
}
|
2017-11-20 17:00:09 +03:00
|
|
|
|
2017-03-27 10:00:27 +03:00
|
|
|
region16_union_rect(®ion, ®ion, &cmdRect);
|
2016-04-25 10:42:59 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Unsupported codecID %" PRIu32 "", cmd->bmp.codecID);
|
2016-04-25 10:42:59 +03:00
|
|
|
break;
|
2011-08-10 18:51:55 +04:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2017-03-27 10:00:27 +03:00
|
|
|
if (!(rects = region16_rects(®ion, &nbRects)))
|
|
|
|
goto out;
|
|
|
|
|
2023-05-22 11:28:42 +03:00
|
|
|
for (UINT32 i = 0; i < nbRects; i++)
|
2016-10-10 20:39:08 +03:00
|
|
|
{
|
2017-03-27 10:00:27 +03:00
|
|
|
UINT32 left = rects[i].left;
|
|
|
|
UINT32 top = rects[i].top;
|
|
|
|
UINT32 width = rects[i].right - rects[i].left;
|
|
|
|
UINT32 height = rects[i].bottom - rects[i].top;
|
|
|
|
|
|
|
|
if (!gdi_InvalidateRegion(gdi->primary->hdc, left, top, width, height))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to update invalid region");
|
|
|
|
goto out;
|
|
|
|
}
|
2016-10-10 20:39:08 +03:00
|
|
|
}
|
|
|
|
|
2017-03-27 10:00:27 +03:00
|
|
|
result = TRUE;
|
|
|
|
out:
|
|
|
|
region16_uninit(®ion);
|
|
|
|
return result;
|
2011-08-10 18:51:55 +04:00
|
|
|
}
|
|
|
|
|
2011-07-01 05:23:36 +04:00
|
|
|
/**
|
2011-08-05 00:22:15 +04:00
|
|
|
* Register GDI callbacks with libfreerdp-core.
|
2022-04-28 00:10:49 +03:00
|
|
|
* @param update current instance
|
2011-07-01 05:23:36 +04:00
|
|
|
*/
|
|
|
|
|
2016-07-18 15:16:13 +03:00
|
|
|
static void gdi_register_update_callbacks(rdpUpdate* update)
|
2011-07-01 05:23:36 +04:00
|
|
|
{
|
2021-09-10 10:06:35 +03:00
|
|
|
rdpPrimaryUpdate* primary;
|
|
|
|
const rdpSettings* settings;
|
|
|
|
|
|
|
|
WINPR_ASSERT(update);
|
|
|
|
WINPR_ASSERT(update->context);
|
|
|
|
|
|
|
|
settings = update->context->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
primary = update->primary;
|
|
|
|
WINPR_ASSERT(primary);
|
|
|
|
|
2021-09-17 09:59:10 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_DeactivateClientDecoding))
|
|
|
|
return;
|
2011-07-28 22:32:16 +04:00
|
|
|
update->Palette = gdi_palette_update;
|
|
|
|
update->SetBounds = gdi_set_bounds;
|
2011-11-22 03:11:43 +04:00
|
|
|
primary->DstBlt = gdi_dstblt;
|
|
|
|
primary->PatBlt = gdi_patblt;
|
|
|
|
primary->ScrBlt = gdi_scrblt;
|
|
|
|
primary->OpaqueRect = gdi_opaque_rect;
|
|
|
|
primary->DrawNineGrid = NULL;
|
|
|
|
primary->MultiDstBlt = NULL;
|
|
|
|
primary->MultiPatBlt = NULL;
|
|
|
|
primary->MultiScrBlt = NULL;
|
|
|
|
primary->MultiOpaqueRect = gdi_multi_opaque_rect;
|
|
|
|
primary->MultiDrawNineGrid = NULL;
|
|
|
|
primary->LineTo = gdi_line_to;
|
2011-12-02 07:59:23 +04:00
|
|
|
primary->Polyline = gdi_polyline;
|
2011-11-22 03:11:43 +04:00
|
|
|
primary->MemBlt = gdi_memblt;
|
|
|
|
primary->Mem3Blt = gdi_mem3blt;
|
|
|
|
primary->SaveBitmap = NULL;
|
|
|
|
primary->GlyphIndex = NULL;
|
|
|
|
primary->FastIndex = NULL;
|
|
|
|
primary->FastGlyph = NULL;
|
2012-02-13 00:21:08 +04:00
|
|
|
primary->PolygonSC = gdi_polygon_sc;
|
|
|
|
primary->PolygonCB = gdi_polygon_cb;
|
|
|
|
primary->EllipseSC = gdi_ellipse_sc;
|
|
|
|
primary->EllipseCB = gdi_ellipse_cb;
|
2011-08-10 18:51:55 +04:00
|
|
|
update->SurfaceBits = gdi_surface_bits;
|
2013-07-15 17:00:18 +04:00
|
|
|
update->SurfaceFrameMarker = gdi_surface_frame_marker;
|
2014-09-06 00:06:19 +04:00
|
|
|
update->altsec->FrameMarker = gdi_frame_marker;
|
2011-07-01 05:23:36 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL gdi_init_primary(rdpGdi* gdi, UINT32 stride, UINT32 format, BYTE* buffer,
|
2021-10-07 11:25:09 +03:00
|
|
|
void (*pfree)(void*), BOOL isLocked)
|
2011-09-07 09:26:17 +04:00
|
|
|
{
|
2021-10-07 11:25:09 +03:00
|
|
|
WINPR_ASSERT(gdi);
|
|
|
|
WINPR_ASSERT(gdi->context);
|
|
|
|
WINPR_ASSERT(gdi->context->update);
|
|
|
|
if (!isLocked)
|
2022-01-11 19:00:26 +03:00
|
|
|
rdp_update_lock(gdi->context->update);
|
2021-10-07 11:25:09 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi->primary = (gdiBitmap*)calloc(1, sizeof(gdiBitmap));
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2016-07-18 13:36:22 +03:00
|
|
|
if (format > 0)
|
|
|
|
gdi->dstFormat = format;
|
|
|
|
|
|
|
|
if (stride > 0)
|
|
|
|
gdi->stride = stride;
|
2017-01-11 17:31:48 +03:00
|
|
|
else
|
2022-04-28 06:43:31 +03:00
|
|
|
gdi->stride = gdi->width * FreeRDPGetBytesPerPixel(gdi->dstFormat);
|
2016-07-18 13:36:22 +03:00
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
if (!gdi->primary)
|
2015-05-08 22:39:23 +03:00
|
|
|
goto fail_primary;
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!(gdi->primary->hdc = gdi_CreateCompatibleDC(gdi->hdc)))
|
|
|
|
goto fail_hdc;
|
2013-09-04 05:48:26 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!buffer)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi->primary->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, gdi->width, gdi->height);
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2013-09-04 05:48:26 +04:00
|
|
|
else
|
2016-08-02 15:16:49 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi->primary->bitmap =
|
|
|
|
gdi_CreateBitmapEx(gdi->width, gdi->height, gdi->dstFormat, gdi->stride, buffer, pfree);
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!gdi->primary->bitmap)
|
|
|
|
goto fail_bitmap;
|
|
|
|
|
2017-11-29 13:12:40 +03:00
|
|
|
gdi->stride = gdi->primary->bitmap->scanline;
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi_SelectObject(gdi->primary->hdc, (HGDIOBJECT)gdi->primary->bitmap);
|
2013-09-04 05:48:26 +04:00
|
|
|
gdi->primary->org_bitmap = NULL;
|
2011-09-07 09:26:17 +04:00
|
|
|
gdi->primary_buffer = gdi->primary->bitmap->data;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!(gdi->primary->hdc->hwnd = (HGDI_WND)calloc(1, sizeof(GDI_WND))))
|
2015-05-08 22:39:23 +03:00
|
|
|
goto fail_hwnd;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!(gdi->primary->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0)))
|
|
|
|
goto fail_hwnd;
|
2011-09-07 09:26:17 +04:00
|
|
|
|
2016-10-06 14:41:52 +03:00
|
|
|
gdi->primary->hdc->hwnd->invalid->null = TRUE;
|
2011-09-07 09:26:17 +04:00
|
|
|
gdi->primary->hdc->hwnd->count = 32;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!(gdi->primary->hdc->hwnd->cinvalid =
|
|
|
|
(HGDI_RGN)calloc(gdi->primary->hdc->hwnd->count, sizeof(GDI_RGN))))
|
2015-05-08 22:39:23 +03:00
|
|
|
goto fail_hwnd;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2011-09-07 09:26:17 +04:00
|
|
|
gdi->primary->hdc->hwnd->ninvalid = 0;
|
2015-05-08 22:39:23 +03:00
|
|
|
|
|
|
|
if (!gdi->drawing)
|
|
|
|
gdi->drawing = gdi->primary;
|
|
|
|
|
2022-01-11 19:00:26 +03:00
|
|
|
rdp_update_unlock(gdi->context->update);
|
2015-05-08 22:39:23 +03:00
|
|
|
return TRUE;
|
|
|
|
fail_hwnd:
|
2019-11-06 17:24:51 +03:00
|
|
|
gdi_DeleteObject((HGDIOBJECT)gdi->primary->bitmap);
|
2015-05-08 22:39:23 +03:00
|
|
|
fail_bitmap:
|
|
|
|
gdi_DeleteDC(gdi->primary->hdc);
|
|
|
|
fail_hdc:
|
|
|
|
free(gdi->primary);
|
|
|
|
gdi->primary = NULL;
|
|
|
|
fail_primary:
|
2022-01-11 19:00:26 +03:00
|
|
|
rdp_update_unlock(gdi->context->update);
|
2015-05-08 22:39:23 +03:00
|
|
|
return FALSE;
|
2011-09-07 09:26:17 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
BOOL gdi_resize(rdpGdi* gdi, UINT32 width, UINT32 height)
|
|
|
|
{
|
2016-10-18 16:16:58 +03:00
|
|
|
return gdi_resize_ex(gdi, width, height, 0, 0, NULL, NULL);
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL gdi_resize_ex(rdpGdi* gdi, UINT32 width, UINT32 height, UINT32 stride, UINT32 format,
|
|
|
|
BYTE* buffer, void (*pfree)(void*))
|
2011-09-07 09:26:17 +04:00
|
|
|
{
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!gdi || !gdi->primary)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-02-07 16:18:53 +03:00
|
|
|
if ((width > INT32_MAX) || (height > INT32_MAX))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if ((gdi->width == (INT32)width) && (gdi->height == (INT32)height) &&
|
|
|
|
(!buffer || (gdi->primary_buffer == buffer)))
|
2015-05-08 22:39:23 +03:00
|
|
|
return TRUE;
|
|
|
|
|
2021-10-07 11:25:09 +03:00
|
|
|
WINPR_ASSERT(gdi->context);
|
|
|
|
WINPR_ASSERT(gdi->context->update);
|
2022-01-11 19:00:26 +03:00
|
|
|
rdp_update_lock(gdi->context->update);
|
2021-10-07 11:25:09 +03:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (gdi->drawing == gdi->primary)
|
|
|
|
gdi->drawing = NULL;
|
|
|
|
|
2019-02-07 16:18:53 +03:00
|
|
|
gdi->width = (INT32)width;
|
|
|
|
gdi->height = (INT32)height;
|
2015-05-08 22:39:23 +03:00
|
|
|
gdi_bitmap_free_ex(gdi->primary);
|
|
|
|
gdi->primary = NULL;
|
|
|
|
gdi->primary_buffer = NULL;
|
2021-10-07 11:25:09 +03:00
|
|
|
return gdi_init_primary(gdi, stride, format, buffer, pfree, TRUE);
|
2011-09-07 09:26:17 +04:00
|
|
|
}
|
|
|
|
|
2011-07-01 05:23:36 +04:00
|
|
|
/**
|
|
|
|
* Initialize GDI
|
2022-12-09 16:35:03 +03:00
|
|
|
*
|
|
|
|
* @param instance A pointer to the instance to use
|
|
|
|
* @param format The color format for the local framebuffer
|
|
|
|
* @return \b TRUE for success, \b FALSE for failure
|
2011-07-01 05:23:36 +04:00
|
|
|
*/
|
2016-04-05 18:07:45 +03:00
|
|
|
BOOL gdi_init(freerdp* instance, UINT32 format)
|
|
|
|
{
|
2022-05-11 12:28:55 +03:00
|
|
|
return gdi_init_ex(instance, format, 0, NULL, winpr_aligned_free);
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2011-07-01 05:23:36 +04:00
|
|
|
|
2022-12-09 16:35:03 +03:00
|
|
|
/**
|
|
|
|
* Initialize GDI
|
|
|
|
*
|
|
|
|
* @param instance A pointer to the instance to use
|
|
|
|
* @param format The color format for the local framebuffer
|
|
|
|
* @param stride The size of a framebuffer line in bytes
|
|
|
|
* @param buffer A pointer to a buffer to be used as framebuffer
|
|
|
|
* @param pfree A custom function pointer to use to free the framebuffer
|
|
|
|
*
|
|
|
|
* @return \b TRUE for success, \b FALSE for failure
|
|
|
|
*/
|
2016-04-05 18:07:45 +03:00
|
|
|
BOOL gdi_init_ex(freerdp* instance, UINT32 format, UINT32 stride, BYTE* buffer,
|
2016-08-04 17:58:07 +03:00
|
|
|
void (*pfree)(void*))
|
2011-07-01 05:23:36 +04:00
|
|
|
{
|
2022-03-23 15:18:35 +03:00
|
|
|
rdpContext* context;
|
|
|
|
UINT32 SrcFormat;
|
|
|
|
rdpGdi* gdi;
|
|
|
|
|
|
|
|
WINPR_ASSERT(instance);
|
|
|
|
|
|
|
|
context = instance->context;
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(context->settings);
|
|
|
|
|
2022-06-23 10:09:55 +03:00
|
|
|
const UINT32 ColorDepth = freerdp_settings_get_uint32(context->settings, FreeRDP_ColorDepth);
|
|
|
|
SrcFormat = gdi_get_pixel_format(ColorDepth);
|
2022-03-23 15:18:35 +03:00
|
|
|
gdi = (rdpGdi*)calloc(1, sizeof(rdpGdi));
|
2014-07-08 23:07:19 +04:00
|
|
|
|
|
|
|
if (!gdi)
|
2016-07-11 12:52:56 +03:00
|
|
|
goto fail;
|
2011-10-16 08:50:10 +04:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
context->gdi = gdi;
|
2016-07-19 14:02:08 +03:00
|
|
|
gdi->log = WLog_Get(TAG);
|
|
|
|
|
|
|
|
if (!gdi->log)
|
|
|
|
goto fail;
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
gdi->context = context;
|
2022-05-02 11:55:44 +03:00
|
|
|
gdi->width = freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth);
|
|
|
|
gdi->height = freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopHeight);
|
2016-04-05 18:07:45 +03:00
|
|
|
gdi->dstFormat = format;
|
2011-07-01 05:23:36 +04:00
|
|
|
/* default internal buffer format */
|
2016-07-19 14:02:08 +03:00
|
|
|
WLog_Print(gdi->log, WLOG_INFO, "Local framebuffer format %s",
|
2017-11-24 15:19:48 +03:00
|
|
|
FreeRDPGetColorFormatName(gdi->dstFormat));
|
2016-07-19 14:02:08 +03:00
|
|
|
WLog_Print(gdi->log, WLOG_INFO, "Remote framebuffer format %s",
|
2017-11-24 15:19:48 +03:00
|
|
|
FreeRDPGetColorFormatName(SrcFormat));
|
2014-09-16 00:08:06 +04:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!(gdi->hdc = gdi_GetDC()))
|
2016-07-11 12:52:56 +03:00
|
|
|
goto fail;
|
2015-05-08 22:39:23 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
gdi->hdc->format = gdi->dstFormat;
|
2011-07-01 05:23:36 +04:00
|
|
|
|
2021-10-07 11:25:09 +03:00
|
|
|
if (!gdi_init_primary(gdi, stride, gdi->dstFormat, buffer, pfree, FALSE))
|
2016-07-11 12:52:56 +03:00
|
|
|
goto fail;
|
2011-07-01 05:23:36 +04:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
if (!(context->cache = cache_new(context)))
|
2016-07-15 17:23:00 +03:00
|
|
|
goto fail;
|
2011-10-13 23:51:07 +04:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
gdi_register_update_callbacks(context->update);
|
|
|
|
brush_cache_register_callbacks(context->update);
|
|
|
|
glyph_cache_register_callbacks(context->update);
|
|
|
|
bitmap_cache_register_callbacks(context->update);
|
|
|
|
offscreen_cache_register_callbacks(context->update);
|
|
|
|
palette_cache_register_callbacks(context->update);
|
2011-10-21 02:18:45 +04:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
if (!gdi_register_graphics(context->graphics))
|
2016-07-11 12:52:56 +03:00
|
|
|
goto fail;
|
2011-08-05 06:43:36 +04:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
return TRUE;
|
2016-07-11 12:52:56 +03:00
|
|
|
fail:
|
|
|
|
gdi_free(instance);
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "failed to initialize gdi");
|
2015-05-08 22:39:23 +03:00
|
|
|
return FALSE;
|
2011-07-01 05:23:36 +04:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:17:17 +04:00
|
|
|
void gdi_free(freerdp* instance)
|
2011-07-01 05:23:36 +04:00
|
|
|
{
|
2016-07-11 12:52:56 +03:00
|
|
|
rdpGdi* gdi;
|
|
|
|
rdpContext* context;
|
|
|
|
|
|
|
|
if (!instance || !instance->context)
|
|
|
|
return;
|
2011-07-01 05:23:36 +04:00
|
|
|
|
2016-07-11 12:52:56 +03:00
|
|
|
gdi = instance->context->gdi;
|
2016-07-14 13:42:24 +03:00
|
|
|
|
2011-07-01 05:23:36 +04:00
|
|
|
if (gdi)
|
|
|
|
{
|
2011-10-13 23:51:07 +04:00
|
|
|
gdi_bitmap_free_ex(gdi->primary);
|
2011-07-27 17:45:44 +04:00
|
|
|
gdi_DeleteDC(gdi->hdc);
|
2011-07-01 05:23:36 +04:00
|
|
|
free(gdi);
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-07-11 12:52:56 +03:00
|
|
|
context = instance->context;
|
2016-07-15 17:23:00 +03:00
|
|
|
cache_free(context->cache);
|
|
|
|
context->cache = NULL;
|
2019-11-06 17:24:51 +03:00
|
|
|
instance->context->gdi = (rdpGdi*)NULL;
|
2011-07-01 05:23:36 +04:00
|
|
|
}
|
2011-07-28 08:38:25 +04:00
|
|
|
|
2018-02-08 12:34:49 +03:00
|
|
|
BOOL gdi_send_suppress_output(rdpGdi* gdi, BOOL suppress)
|
|
|
|
{
|
|
|
|
RECTANGLE_16 rect;
|
|
|
|
rdpSettings* settings;
|
|
|
|
rdpUpdate* update;
|
|
|
|
|
|
|
|
if (!gdi || !gdi->context->settings || !gdi->context->update)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gdi->suppressOutput == suppress)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
gdi->suppressOutput = suppress;
|
|
|
|
settings = gdi->context->settings;
|
|
|
|
update = gdi->context->update;
|
|
|
|
rect.left = 0;
|
|
|
|
rect.top = 0;
|
2022-05-02 11:55:44 +03:00
|
|
|
rect.right = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
|
|
|
|
rect.bottom = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
|
2018-02-08 12:34:49 +03:00
|
|
|
return update->SuppressOutput(gdi->context, !suppress, &rect);
|
|
|
|
}
|