Blame server/shadow/shadow_surface.c

Packit 1fb8d4
/**
Packit 1fb8d4
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit 1fb8d4
 *
Packit 1fb8d4
 * Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
Packit 1fb8d4
 *
Packit 1fb8d4
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit 1fb8d4
 * you may not use this file except in compliance with the License.
Packit 1fb8d4
 * You may obtain a copy of the License at
Packit 1fb8d4
 *
Packit 1fb8d4
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 1fb8d4
 *
Packit 1fb8d4
 * Unless required by applicable law or agreed to in writing, software
Packit 1fb8d4
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 1fb8d4
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 1fb8d4
 * See the License for the specific language governing permissions and
Packit 1fb8d4
 * limitations under the License.
Packit 1fb8d4
 */
Packit 1fb8d4
Packit 1fb8d4
#ifdef HAVE_CONFIG_H
Packit 1fb8d4
#include "config.h"
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
#include "shadow.h"
Packit 1fb8d4
Packit 1fb8d4
#include "shadow_surface.h"
Packit 1fb8d4
#define ALIGN_SCREEN_SIZE(size, align) ((size + align - 1) & (~(align - 1)))
Packit 1fb8d4
rdpShadowSurface* shadow_surface_new(rdpShadowServer* server, int x, int y,
Packit 1fb8d4
                                     int width, int height)
Packit 1fb8d4
{
Packit 1fb8d4
	rdpShadowSurface* surface;
Packit 1fb8d4
	surface = (rdpShadowSurface*) calloc(1, sizeof(rdpShadowSurface));
Packit 1fb8d4
Packit 1fb8d4
	if (!surface)
Packit 1fb8d4
		return NULL;
Packit 1fb8d4
Packit 1fb8d4
	surface->server = server;
Packit 1fb8d4
	surface->x = x;
Packit 1fb8d4
	surface->y = y;
Packit 1fb8d4
	surface->width = width;
Packit 1fb8d4
	surface->height = height;
Packit 1fb8d4
	surface->scanline = ALIGN_SCREEN_SIZE(surface->width, 4) * 4;
Packit 1fb8d4
	surface->format = PIXEL_FORMAT_BGRX32;
Packit 1fb8d4
	surface->data = (BYTE*) calloc(ALIGN_SCREEN_SIZE(surface->height, 4),
Packit 1fb8d4
	                               surface->scanline);
Packit 1fb8d4
Packit 1fb8d4
	if (!surface->data)
Packit 1fb8d4
	{
Packit 1fb8d4
		free(surface);
Packit 1fb8d4
		return NULL;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (!InitializeCriticalSectionAndSpinCount(&(surface->lock), 4000))
Packit 1fb8d4
	{
Packit 1fb8d4
		free(surface->data);
Packit 1fb8d4
		free(surface);
Packit 1fb8d4
		return NULL;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	region16_init(&(surface->invalidRegion));
Packit 1fb8d4
	return surface;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
void shadow_surface_free(rdpShadowSurface* surface)
Packit 1fb8d4
{
Packit 1fb8d4
	if (!surface)
Packit 1fb8d4
		return;
Packit 1fb8d4
Packit 1fb8d4
	free(surface->data);
Packit 1fb8d4
	DeleteCriticalSection(&(surface->lock));
Packit 1fb8d4
	region16_uninit(&(surface->invalidRegion));
Packit 1fb8d4
	free(surface);
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
BOOL shadow_surface_resize(rdpShadowSurface* surface, int x, int y, int width,
Packit 1fb8d4
                           int height)
Packit 1fb8d4
{
Packit 1fb8d4
	BYTE* buffer = NULL;
Packit 1fb8d4
	int scanline =  ALIGN_SCREEN_SIZE(width, 4) * 4;
Packit 1fb8d4
Packit 1fb8d4
	if (!surface)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	if ((width == surface->width) && (height == surface->height))
Packit 1fb8d4
	{
Packit 1fb8d4
		/* We don't need to reset frame buffer, just update left top */
Packit 1fb8d4
		surface->x = x;
Packit 1fb8d4
		surface->y = y;
Packit 1fb8d4
		return TRUE;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	buffer = (BYTE*) realloc(surface->data, scanline * ALIGN_SCREEN_SIZE(height,
Packit 1fb8d4
	                         4));
Packit 1fb8d4
Packit 1fb8d4
	if (buffer)
Packit 1fb8d4
	{
Packit 1fb8d4
		surface->x = x;
Packit 1fb8d4
		surface->y = y;
Packit 1fb8d4
		surface->width = width;
Packit 1fb8d4
		surface->height = height;
Packit 1fb8d4
		surface->scanline = scanline;
Packit 1fb8d4
		surface->data = buffer;
Packit 1fb8d4
		return TRUE;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return FALSE;
Packit 1fb8d4
}