2013-12-28 20:53:12 -08:00
|
|
|
/*
|
2016-03-25 12:59:40 -07:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you 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
|
2012-01-02 17:59:52 -08:00
|
|
|
*
|
2016-03-25 12:59:40 -07:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-01-02 17:59:52 -08:00
|
|
|
*
|
2016-03-25 12:59:40 -07: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.
|
2013-12-28 20:53:12 -08:00
|
|
|
*/
|
|
|
|
|
2019-12-23 13:29:13 -08:00
|
|
|
#include "bitmap.h"
|
2016-09-11 17:28:50 -07:00
|
|
|
#include "common/display.h"
|
|
|
|
#include "common/surface.h"
|
2020-01-21 14:53:57 -08:00
|
|
|
#include "config.h"
|
2016-02-29 21:50:00 -08:00
|
|
|
#include "rdp.h"
|
2012-01-02 17:59:52 -08:00
|
|
|
|
|
|
|
#include <cairo/cairo.h>
|
2014-01-01 14:44:28 -08:00
|
|
|
#include <freerdp/freerdp.h>
|
2012-01-02 17:59:52 -08:00
|
|
|
#include <guacamole/client.h>
|
2020-01-04 13:07:28 -08:00
|
|
|
#include <winpr/crt.h>
|
2013-07-17 11:54:24 -07:00
|
|
|
#include <winpr/wtypes.h>
|
|
|
|
|
2014-06-10 18:45:14 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2020-01-11 20:14:14 -08:00
|
|
|
void guac_rdp_cache_bitmap(rdpContext* context, rdpBitmap* bitmap) {
|
2012-01-02 17:59:52 -08:00
|
|
|
|
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
2016-02-29 21:50:00 -08:00
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
2012-01-02 17:59:52 -08:00
|
|
|
|
2016-02-29 21:50:00 -08:00
|
|
|
/* Allocate buffer */
|
|
|
|
guac_common_display_layer* buffer = guac_common_display_alloc_buffer(
|
|
|
|
rdp_client->display, bitmap->width, bitmap->height);
|
2012-04-10 11:51:46 -07:00
|
|
|
|
2012-04-10 11:04:38 -07:00
|
|
|
/* Cache image data if present */
|
|
|
|
if (bitmap->data != NULL) {
|
|
|
|
|
|
|
|
/* Create surface from image data */
|
2014-04-30 11:44:06 -07:00
|
|
|
cairo_surface_t* image = cairo_image_surface_create_for_data(
|
2012-04-10 11:04:38 -07:00
|
|
|
bitmap->data, CAIRO_FORMAT_RGB24,
|
|
|
|
bitmap->width, bitmap->height, 4*bitmap->width);
|
|
|
|
|
|
|
|
/* Send surface to buffer */
|
2016-02-29 21:50:00 -08:00
|
|
|
guac_common_surface_draw(buffer->surface, 0, 0, image);
|
2012-04-10 11:04:38 -07:00
|
|
|
|
|
|
|
/* Free surface */
|
2014-04-30 11:44:06 -07:00
|
|
|
cairo_surface_destroy(image);
|
2012-04-10 11:04:38 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-10 11:51:46 -07:00
|
|
|
/* Store buffer reference in bitmap */
|
2016-02-29 21:50:00 -08:00
|
|
|
((guac_rdp_bitmap*) bitmap)->layer = buffer;
|
2012-04-10 11:51:46 -07:00
|
|
|
|
2012-04-10 11:04:38 -07:00
|
|
|
}
|
|
|
|
|
2017-03-25 19:59:04 -07:00
|
|
|
BOOL guac_rdp_bitmap_new(rdpContext* context, rdpBitmap* bitmap) {
|
2012-02-08 15:09:12 -08:00
|
|
|
|
2014-04-30 11:44:06 -07:00
|
|
|
/* No corresponding surface yet - caching is deferred. */
|
2016-02-29 21:50:00 -08:00
|
|
|
((guac_rdp_bitmap*) bitmap)->layer = NULL;
|
2012-04-10 13:21:13 -07:00
|
|
|
|
|
|
|
/* Start at zero usage */
|
|
|
|
((guac_rdp_bitmap*) bitmap)->used = 0;
|
2012-04-10 11:04:38 -07:00
|
|
|
|
2017-03-25 19:59:04 -07:00
|
|
|
return TRUE;
|
|
|
|
|
2012-01-02 17:59:52 -08:00
|
|
|
}
|
|
|
|
|
2017-03-25 19:59:04 -07:00
|
|
|
BOOL guac_rdp_bitmap_paint(rdpContext* context, rdpBitmap* bitmap) {
|
2012-01-03 13:20:24 -08:00
|
|
|
|
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
2016-02-29 21:50:00 -08:00
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
2014-04-30 11:44:06 -07:00
|
|
|
|
2016-02-29 21:50:00 -08:00
|
|
|
guac_common_display_layer* buffer = ((guac_rdp_bitmap*) bitmap)->layer;
|
2012-01-03 13:20:24 -08:00
|
|
|
|
2012-03-05 12:10:03 -08:00
|
|
|
int width = bitmap->right - bitmap->left + 1;
|
|
|
|
int height = bitmap->bottom - bitmap->top + 1;
|
2012-03-01 15:27:25 -05:00
|
|
|
|
2012-04-10 13:21:13 -07:00
|
|
|
/* If not cached, cache if necessary */
|
2016-02-29 21:50:00 -08:00
|
|
|
if (buffer == NULL && ((guac_rdp_bitmap*) bitmap)->used >= 1)
|
2012-04-10 14:23:37 -07:00
|
|
|
guac_rdp_cache_bitmap(context, bitmap);
|
2012-04-10 13:21:13 -07:00
|
|
|
|
2012-04-10 11:04:38 -07:00
|
|
|
/* If cached, retrieve from cache */
|
2016-02-29 21:50:00 -08:00
|
|
|
if (buffer != NULL)
|
|
|
|
guac_common_surface_copy(buffer->surface, 0, 0, width, height,
|
|
|
|
rdp_client->display->default_surface,
|
|
|
|
bitmap->left, bitmap->top);
|
2012-04-03 14:03:52 -07:00
|
|
|
|
|
|
|
/* Otherwise, draw with stored image data */
|
|
|
|
else if (bitmap->data != NULL) {
|
|
|
|
|
|
|
|
/* Create surface from image data */
|
2014-04-30 11:44:06 -07:00
|
|
|
cairo_surface_t* image = cairo_image_surface_create_for_data(
|
2012-04-03 14:03:52 -07:00
|
|
|
bitmap->data, CAIRO_FORMAT_RGB24,
|
|
|
|
width, height, 4*bitmap->width);
|
|
|
|
|
2014-04-30 11:44:06 -07:00
|
|
|
/* Draw image on default surface */
|
2016-02-29 21:50:00 -08:00
|
|
|
guac_common_surface_draw(rdp_client->display->default_surface,
|
|
|
|
bitmap->left, bitmap->top, image);
|
2012-04-03 14:03:52 -07:00
|
|
|
|
|
|
|
/* Free surface */
|
2014-04-30 11:44:06 -07:00
|
|
|
cairo_surface_destroy(image);
|
2012-04-03 14:03:52 -07:00
|
|
|
|
|
|
|
}
|
2012-02-08 12:11:32 -08:00
|
|
|
|
2012-04-10 13:21:13 -07:00
|
|
|
/* Increment usage counter */
|
|
|
|
((guac_rdp_bitmap*) bitmap)->used++;
|
|
|
|
|
2017-03-25 19:59:04 -07:00
|
|
|
return TRUE;
|
|
|
|
|
2012-01-03 13:04:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void guac_rdp_bitmap_free(rdpContext* context, rdpBitmap* bitmap) {
|
2014-04-30 11:44:06 -07:00
|
|
|
|
2012-01-03 13:04:50 -08:00
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
2016-02-29 21:50:00 -08:00
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
|
|
|
guac_common_display_layer* buffer = ((guac_rdp_bitmap*) bitmap)->layer;
|
2012-04-10 13:21:13 -07:00
|
|
|
|
2014-04-30 12:32:19 -07:00
|
|
|
/* If cached, free buffer */
|
|
|
|
if (buffer != NULL)
|
2016-02-29 21:50:00 -08:00
|
|
|
guac_common_display_free_buffer(rdp_client->display, buffer);
|
2014-04-30 12:32:19 -07:00
|
|
|
|
2020-01-21 14:53:57 -08:00
|
|
|
#ifndef FREERDP_BITMAP_FREE_FREES_BITMAP
|
|
|
|
/* NOTE: Except in FreeRDP 2.0.0-rc0 and earlier, FreeRDP-allocated memory
|
|
|
|
* for the rdpBitmap will NOT be automatically released after this free
|
|
|
|
* handler is invoked, thus we must do so manually here */
|
2019-12-30 16:11:13 -08:00
|
|
|
|
|
|
|
_aligned_free(bitmap->data);
|
|
|
|
free(bitmap);
|
2020-01-21 14:53:57 -08:00
|
|
|
#endif
|
2019-12-30 16:11:13 -08:00
|
|
|
|
2012-01-03 13:04:50 -08:00
|
|
|
}
|
|
|
|
|
2017-03-25 19:59:04 -07:00
|
|
|
BOOL guac_rdp_bitmap_setsurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary) {
|
2014-04-30 11:44:06 -07:00
|
|
|
|
2012-01-03 13:39:59 -08:00
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
2016-02-29 21:50:00 -08:00
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
2012-01-10 23:31:24 -08:00
|
|
|
|
2012-02-08 12:11:32 -08:00
|
|
|
if (primary)
|
2016-02-29 21:50:00 -08:00
|
|
|
rdp_client->current_surface = rdp_client->display->default_surface;
|
2012-04-10 11:04:38 -07:00
|
|
|
|
|
|
|
else {
|
|
|
|
|
2013-06-13 23:38:20 -07:00
|
|
|
/* Make sure that the recieved bitmap is not NULL before processing */
|
|
|
|
if (bitmap == NULL) {
|
2014-11-07 16:32:19 -08:00
|
|
|
guac_client_log(client, GUAC_LOG_INFO, "NULL bitmap found in bitmap_setsurface instruction.");
|
2019-09-29 15:01:23 -07:00
|
|
|
return TRUE;
|
2013-06-13 23:38:20 -07:00
|
|
|
}
|
|
|
|
|
2012-04-10 11:51:46 -07:00
|
|
|
/* If not available as a surface, make available. */
|
2016-02-29 21:50:00 -08:00
|
|
|
if (((guac_rdp_bitmap*) bitmap)->layer == NULL)
|
2012-04-10 14:23:37 -07:00
|
|
|
guac_rdp_cache_bitmap(context, bitmap);
|
2012-04-10 11:51:46 -07:00
|
|
|
|
2016-02-29 21:50:00 -08:00
|
|
|
rdp_client->current_surface =
|
|
|
|
((guac_rdp_bitmap*) bitmap)->layer->surface;
|
2012-04-10 11:04:38 -07:00
|
|
|
|
|
|
|
}
|
2012-02-08 15:09:12 -08:00
|
|
|
|
2017-03-25 19:59:04 -07:00
|
|
|
return TRUE;
|
|
|
|
|
2012-01-03 13:39:59 -08:00
|
|
|
}
|
|
|
|
|