2011-10-22 00:45:35 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-10-22 00:45:35 +04:00
|
|
|
* Windows Graphical Objects
|
|
|
|
*
|
|
|
|
* Copyright 2010-2011 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2014-09-10 19:38:38 +04:00
|
|
|
#include <freerdp/codecs.h>
|
2014-09-12 19:13:01 +04:00
|
|
|
#include <freerdp/log.h>
|
2011-10-22 00:45:35 +04:00
|
|
|
|
|
|
|
#include "wf_gdi.h"
|
|
|
|
#include "wf_graphics.h"
|
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#define TAG CLIENT_TAG("windows")
|
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
HBITMAP wf_create_dib(wfContext* wfc, UINT32 width, UINT32 height,
|
|
|
|
UINT32 srcFormat, const BYTE* data, BYTE** pdata)
|
2011-10-22 00:45:35 +04:00
|
|
|
{
|
|
|
|
HDC hdc;
|
|
|
|
int negHeight;
|
|
|
|
HBITMAP bitmap;
|
|
|
|
BITMAPINFO bmi;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* cdata = NULL;
|
2016-08-03 13:37:40 +03:00
|
|
|
UINT32 dstFormat = srcFormat;
|
2011-10-22 00:45:35 +04:00
|
|
|
/**
|
|
|
|
* See: http://msdn.microsoft.com/en-us/library/dd183376
|
|
|
|
* if biHeight is positive, the bitmap is bottom-up
|
|
|
|
* if biHeight is negative, the bitmap is top-down
|
|
|
|
* Since we get top-down bitmaps, let's keep it that way
|
|
|
|
*/
|
|
|
|
negHeight = (height < 0) ? height : height * (-1);
|
|
|
|
hdc = GetDC(NULL);
|
|
|
|
bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
|
|
|
|
bmi.bmiHeader.biWidth = width;
|
|
|
|
bmi.bmiHeader.biHeight = negHeight;
|
|
|
|
bmi.bmiHeader.biPlanes = 1;
|
2016-08-03 13:09:24 +03:00
|
|
|
bmi.bmiHeader.biBitCount = GetBitsPerPixel(dstFormat);
|
2011-10-22 00:45:35 +04:00
|
|
|
bmi.bmiHeader.biCompression = BI_RGB;
|
|
|
|
bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**) &cdata, NULL, 0);
|
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (data)
|
|
|
|
freerdp_image_copy(cdata, dstFormat, 0, 0, 0, width, height, data, srcFormat, 0,
|
|
|
|
0, 0, &wfc->context.gdi->palette);
|
2011-10-22 00:45:35 +04:00
|
|
|
|
2015-05-07 21:20:49 +03:00
|
|
|
if (pdata)
|
2011-12-16 23:43:14 +04:00
|
|
|
*pdata = cdata;
|
|
|
|
|
2011-10-22 00:45:35 +04:00
|
|
|
ReleaseDC(NULL, hdc);
|
|
|
|
GdiFlush();
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
wfBitmap* wf_image_new(wfContext* wfc, UINT32 width, UINT32 height,
|
|
|
|
UINT32 format, const BYTE* data)
|
2011-10-22 00:45:35 +04:00
|
|
|
{
|
|
|
|
HDC hdc;
|
|
|
|
wfBitmap* image;
|
|
|
|
hdc = GetDC(NULL);
|
2012-10-09 07:21:26 +04:00
|
|
|
image = (wfBitmap*) malloc(sizeof(wfBitmap));
|
2011-10-22 00:45:35 +04:00
|
|
|
image->hdc = CreateCompatibleDC(hdc);
|
2016-08-03 13:09:24 +03:00
|
|
|
image->bitmap = wf_create_dib(wfc, width, height, format, data,
|
|
|
|
&(image->pdata));
|
2011-10-22 00:45:35 +04:00
|
|
|
image->org_bitmap = (HBITMAP) SelectObject(image->hdc, image->bitmap);
|
|
|
|
ReleaseDC(NULL, hdc);
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wf_image_free(wfBitmap* image)
|
|
|
|
{
|
|
|
|
if (image != 0)
|
|
|
|
{
|
|
|
|
SelectObject(image->hdc, image->org_bitmap);
|
|
|
|
DeleteObject(image->bitmap);
|
|
|
|
DeleteDC(image->hdc);
|
|
|
|
free(image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bitmap Class */
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static BOOL wf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
|
2011-10-22 00:45:35 +04:00
|
|
|
{
|
|
|
|
HDC hdc;
|
2016-08-03 13:09:24 +03:00
|
|
|
wfContext* wfc = (wfContext*)context;
|
2011-10-22 00:45:35 +04:00
|
|
|
wfBitmap* wf_bitmap = (wfBitmap*) bitmap;
|
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!context || !bitmap)
|
|
|
|
return FALSE;
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2011-10-26 23:38:50 +04:00
|
|
|
wf_bitmap = (wfBitmap*) bitmap;
|
2011-10-22 00:45:35 +04:00
|
|
|
hdc = GetDC(NULL);
|
|
|
|
wf_bitmap->hdc = CreateCompatibleDC(hdc);
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!bitmap->data)
|
2011-10-22 00:45:35 +04:00
|
|
|
wf_bitmap->bitmap = CreateCompatibleBitmap(hdc, bitmap->width, bitmap->height);
|
|
|
|
else
|
2016-08-03 13:09:24 +03:00
|
|
|
wf_bitmap->bitmap = wf_create_dib(wfc, bitmap->width, bitmap->height,
|
|
|
|
bitmap->format, bitmap->data, NULL);
|
2011-10-22 00:45:35 +04:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
wf_bitmap->org_bitmap = (HBITMAP) SelectObject(wf_bitmap->hdc,
|
|
|
|
wf_bitmap->bitmap);
|
2011-10-22 00:45:35 +04:00
|
|
|
ReleaseDC(NULL, hdc);
|
2016-08-03 13:09:24 +03:00
|
|
|
return TRUE;
|
2011-10-22 00:45:35 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static void wf_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
|
2011-10-22 00:45:35 +04:00
|
|
|
{
|
|
|
|
wfBitmap* wf_bitmap = (wfBitmap*) bitmap;
|
2012-10-16 22:20:04 +04:00
|
|
|
|
2011-10-22 00:45:35 +04:00
|
|
|
if (wf_bitmap != 0)
|
|
|
|
{
|
|
|
|
SelectObject(wf_bitmap->hdc, wf_bitmap->org_bitmap);
|
|
|
|
DeleteObject(wf_bitmap->bitmap);
|
|
|
|
DeleteDC(wf_bitmap->hdc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static BOOL wf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)
|
2011-10-22 00:45:35 +04:00
|
|
|
{
|
2016-08-03 13:09:24 +03:00
|
|
|
BOOL rc;
|
|
|
|
UINT32 width, height;
|
|
|
|
wfContext* wfc = (wfContext*)context;
|
2011-10-22 00:45:35 +04:00
|
|
|
wfBitmap* wf_bitmap = (wfBitmap*) bitmap;
|
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!context || !bitmap)
|
|
|
|
return FALSE;
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2011-10-22 00:45:35 +04:00
|
|
|
width = bitmap->right - bitmap->left + 1;
|
|
|
|
height = bitmap->bottom - bitmap->top + 1;
|
2016-08-03 13:09:24 +03:00
|
|
|
rc = BitBlt(wfc->primary->hdc, bitmap->left, bitmap->top,
|
|
|
|
width, height, wf_bitmap->hdc, 0, 0, SRCCOPY);
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_invalidate_region(wfc, bitmap->left, bitmap->top, width, height);
|
2016-08-03 13:09:24 +03:00
|
|
|
return rc;
|
2011-10-22 00:45:35 +04:00
|
|
|
}
|
|
|
|
|
2016-08-02 12:20:57 +03:00
|
|
|
static BOOL wf_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap,
|
2016-08-03 13:09:24 +03:00
|
|
|
BOOL primary)
|
2016-08-02 12:20:57 +03:00
|
|
|
{
|
2016-08-03 13:09:24 +03:00
|
|
|
wfContext* wfc = (wfContext*)context;
|
|
|
|
wfBitmap* bmp = (wfBitmap*) bitmap;
|
|
|
|
rdpGdi* gdi = context->gdi;
|
2016-08-02 12:20:57 +03:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!gdi || !wfc)
|
|
|
|
return FALSE;
|
2016-08-02 12:20:57 +03:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (primary)
|
|
|
|
wfc->drawing = wfc->primary;
|
|
|
|
else if (!bmp)
|
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
wfc->drawing = bmp;
|
2016-08-02 12:20:57 +03:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
return TRUE;
|
2016-08-02 12:20:57 +03:00
|
|
|
}
|
|
|
|
|
2011-10-22 00:45:35 +04:00
|
|
|
/* Pointer Class */
|
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
static BOOL flip_bitmap(const BYTE* src, BYTE* dst, UINT32 scanline,
|
|
|
|
UINT32 nHeight)
|
2016-08-02 12:20:57 +03:00
|
|
|
{
|
2016-08-03 13:09:24 +03:00
|
|
|
UINT32 x;
|
|
|
|
BYTE* bottomLine = dst + scanline * (nHeight - 1);
|
2016-08-02 12:20:57 +03:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
for (x = 0; x < nHeight; x++)
|
|
|
|
{
|
|
|
|
memcpy(bottomLine, src, scanline);
|
|
|
|
src += scanline;
|
|
|
|
bottomLine -= scanline;
|
|
|
|
}
|
2016-08-02 12:39:25 +03:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
return TRUE;
|
2016-08-02 12:20:57 +03:00
|
|
|
}
|
|
|
|
|
2016-08-02 12:39:25 +03:00
|
|
|
static BOOL wf_Pointer_New(rdpContext* context, const rdpPointer* pointer)
|
2011-10-22 00:45:35 +04:00
|
|
|
{
|
2012-10-16 22:06:23 +04:00
|
|
|
HCURSOR hCur;
|
2016-08-03 13:09:24 +03:00
|
|
|
ICONINFO info;
|
|
|
|
rdpGdi* gdi;
|
2012-10-16 22:06:23 +04:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!context || !pointer)
|
|
|
|
return FALSE;
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
gdi = context->gdi;
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!gdi)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
info.fIcon = FALSE;
|
2012-12-21 16:29:47 +04:00
|
|
|
info.xHotspot = pointer->xPos;
|
|
|
|
info.yHotspot = pointer->yPos;
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (pointer->xorBpp == 1)
|
|
|
|
{
|
|
|
|
BYTE* pdata = (BYTE*) _aligned_malloc(pointer->lengthAndMask +
|
|
|
|
pointer->lengthXorMask, 16);
|
|
|
|
CopyMemory(pdata, pointer->andMaskData, pointer->lengthAndMask);
|
|
|
|
CopyMemory(pdata + pointer->lengthAndMask, pointer->xorMaskData,
|
|
|
|
pointer->lengthXorMask);
|
|
|
|
info.hbmMask = CreateBitmap(pointer->width, pointer->height * 2, 1, 1, pdata);
|
|
|
|
_aligned_free(pdata);
|
|
|
|
info.hbmColor = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const UINT32 scanline = pointer->width * pointer->xorBpp / 8;
|
|
|
|
BYTE* pdata = (BYTE*) _aligned_malloc(pointer->lengthAndMask, 16);
|
|
|
|
flip_bitmap(pointer->andMaskData, pdata, (pointer->width + 7) / 8,
|
|
|
|
pointer->height);
|
|
|
|
info.hbmMask = CreateBitmap(pointer->width, pointer->height, 1, 1, pdata);
|
|
|
|
_aligned_free(pdata);
|
|
|
|
pdata = (BYTE*) _aligned_malloc(pointer->lengthXorMask, 16);
|
|
|
|
flip_bitmap(pointer->xorMaskData, pdata, scanline, pointer->height);
|
|
|
|
info.hbmColor = CreateBitmap(pointer->width, pointer->height, 1,
|
|
|
|
pointer->xorBpp, pdata);
|
|
|
|
_aligned_free(pdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
hCur = CreateIconIndirect(&info);
|
|
|
|
((wfPointer*) pointer)->cursor = hCur;
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2012-12-21 16:29:47 +04:00
|
|
|
if (info.hbmMask)
|
|
|
|
DeleteObject(info.hbmMask);
|
2016-08-03 13:09:24 +03:00
|
|
|
|
2012-12-21 16:29:47 +04:00
|
|
|
if (info.hbmColor)
|
|
|
|
DeleteObject(info.hbmColor);
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
return TRUE;
|
2011-10-22 00:45:35 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static BOOL wf_Pointer_Free(rdpContext* context, rdpPointer* pointer)
|
2011-10-22 00:45:35 +04:00
|
|
|
{
|
2012-10-16 22:06:23 +04:00
|
|
|
HCURSOR hCur;
|
2011-10-22 00:45:35 +04:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!context || !pointer)
|
|
|
|
return FALSE;
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2012-10-16 22:06:23 +04:00
|
|
|
hCur = ((wfPointer*) pointer)->cursor;
|
2013-06-16 06:57:21 +04:00
|
|
|
|
2012-10-16 22:06:23 +04:00
|
|
|
if (hCur != 0)
|
2012-12-21 16:29:47 +04:00
|
|
|
DestroyIcon(hCur);
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
return TRUE;
|
2011-10-22 00:45:35 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static BOOL wf_Pointer_Set(rdpContext* context, const rdpPointer* pointer)
|
2011-10-22 00:45:35 +04:00
|
|
|
{
|
2012-10-16 22:06:23 +04:00
|
|
|
HCURSOR hCur;
|
2016-08-03 13:09:24 +03:00
|
|
|
wfContext* wfc = (wfContext*)context;
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!context || !pointer)
|
|
|
|
return FALSE;
|
2011-10-22 00:45:35 +04:00
|
|
|
|
2012-10-16 22:06:23 +04:00
|
|
|
hCur = ((wfPointer*) pointer)->cursor;
|
2013-06-16 06:57:21 +04:00
|
|
|
|
2012-10-16 22:06:23 +04:00
|
|
|
if (hCur != NULL)
|
|
|
|
{
|
|
|
|
SetCursor(hCur);
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->cursor = hCur;
|
2012-10-16 22:06:23 +04:00
|
|
|
}
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
return TRUE;
|
2011-10-22 00:45:35 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static BOOL wf_Pointer_SetNull(rdpContext* context)
|
2012-02-24 16:44:23 +04:00
|
|
|
{
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!context)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2012-02-24 16:44:23 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
static BOOL wf_Pointer_SetDefault(rdpContext* context)
|
2012-02-24 16:44:23 +04:00
|
|
|
{
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!context)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2012-02-24 16:44:23 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
BOOL wf_register_pointer(rdpGraphics* graphics)
|
2011-10-22 00:45:35 +04:00
|
|
|
{
|
2014-09-11 17:40:10 +04:00
|
|
|
wfContext* wfc;
|
2011-10-22 00:45:35 +04:00
|
|
|
rdpPointer pointer;
|
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!graphics)
|
|
|
|
return FALSE;
|
2014-09-11 17:40:10 +04:00
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
wfc = (wfContext*) graphics->context;
|
2013-06-16 06:57:21 +04:00
|
|
|
ZeroMemory(&pointer, sizeof(rdpPointer));
|
2011-10-22 00:45:35 +04:00
|
|
|
pointer.size = sizeof(wfPointer);
|
2016-08-03 13:09:24 +03:00
|
|
|
pointer.New = wf_Pointer_New;
|
|
|
|
pointer.Free = wf_Pointer_Free;
|
|
|
|
pointer.Set = wf_Pointer_Set;
|
|
|
|
pointer.SetNull = wf_Pointer_SetNull;
|
|
|
|
pointer.SetDefault = wf_Pointer_SetDefault;
|
2011-10-22 00:45:35 +04:00
|
|
|
graphics_register_pointer(graphics, &pointer);
|
2016-08-03 13:09:24 +03:00
|
|
|
return TRUE;
|
2011-10-22 00:45:35 +04:00
|
|
|
}
|
2014-09-12 19:34:30 +04:00
|
|
|
|
|
|
|
/* Graphics Module */
|
|
|
|
|
2016-07-21 16:36:15 +03:00
|
|
|
BOOL wf_register_graphics(rdpGraphics* graphics)
|
2014-09-12 19:34:30 +04:00
|
|
|
{
|
|
|
|
wfContext* wfc;
|
2016-08-03 13:09:24 +03:00
|
|
|
rdpGlyph glyph;
|
2014-09-12 19:34:30 +04:00
|
|
|
rdpBitmap bitmap;
|
|
|
|
|
2016-08-03 13:09:24 +03:00
|
|
|
if (!graphics)
|
|
|
|
return FALSE;
|
2016-07-21 16:36:15 +03:00
|
|
|
|
2014-09-12 19:34:30 +04:00
|
|
|
wfc = (wfContext*) graphics->context;
|
2016-08-03 13:09:24 +03:00
|
|
|
bitmap = *graphics->Bitmap_Prototype;
|
2014-09-12 19:34:30 +04:00
|
|
|
bitmap.size = sizeof(wfBitmap);
|
2016-08-03 13:09:24 +03:00
|
|
|
bitmap.New = wf_Bitmap_New;
|
|
|
|
bitmap.Free = wf_Bitmap_Free;
|
|
|
|
bitmap.Paint = wf_Bitmap_Paint;
|
|
|
|
bitmap.SetSurface = wf_Bitmap_SetSurface;
|
|
|
|
graphics_register_bitmap(graphics, &bitmap);
|
|
|
|
glyph = *graphics->Glyph_Prototype;
|
|
|
|
graphics_register_glyph(graphics, &glyph);
|
|
|
|
return TRUE;
|
2014-09-12 19:34:30 +04:00
|
|
|
}
|