2004-07-20 03:35:12 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
2005-01-21 02:17:08 +03:00
|
|
|
* Copyright 2004, 2005 Richard Wilson <info@tinct.net>
|
2004-07-20 03:35:12 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "oslib/colourtrans.h"
|
|
|
|
#include "oslib/os.h"
|
|
|
|
#include "oslib/osspriteop.h"
|
|
|
|
#include "oslib/wimp.h"
|
2005-01-21 02:17:08 +03:00
|
|
|
#include "oslib/wimpreadsysinfo.h"
|
2004-07-20 03:35:12 +04:00
|
|
|
#include "netsurf/riscos/buffer.h"
|
2005-01-21 02:17:08 +03:00
|
|
|
#include "netsurf/riscos/options.h"
|
2004-07-20 03:35:12 +04:00
|
|
|
#include "netsurf/riscos/wimp.h"
|
|
|
|
#include "netsurf/utils/log.h"
|
2005-01-21 02:17:08 +03:00
|
|
|
//#define NDEBUG
|
|
|
|
#define BUFFER_EXCLUSIVE_USER_REDRAW "Only support pure user redraw (faster)"
|
2004-07-20 03:35:12 +04:00
|
|
|
|
|
|
|
/* SCREEN BUFFERING
|
|
|
|
================
|
2004-08-14 18:30:12 +04:00
|
|
|
|
2004-07-20 03:35:12 +04:00
|
|
|
Because RISC OS provides no native way for windows to be buffered (ie
|
|
|
|
the contents is only updated when the task has finished doing any
|
|
|
|
drawing) certain situation cause the window contents to flicker in an
|
|
|
|
undesirable manner. Examples of this are GIF and MNG animations, and
|
|
|
|
web pages with fixed backgrounds.
|
2004-08-14 18:30:12 +04:00
|
|
|
|
2004-07-20 03:35:12 +04:00
|
|
|
To overcome this, a very simple, transparent, interface is provided here
|
|
|
|
to allow for output to be buffered. It should be noted that screen
|
|
|
|
buffering can lower the perceived client response time as the user is
|
|
|
|
unable to see that the application is doing anything.
|
2004-08-14 18:30:12 +04:00
|
|
|
|
2004-07-20 03:35:12 +04:00
|
|
|
[rjw] - Mon 19th July 2004
|
|
|
|
*/
|
|
|
|
|
2005-01-21 02:17:08 +03:00
|
|
|
static void ro_gui_buffer_free(void);
|
2004-07-20 03:35:12 +04:00
|
|
|
|
|
|
|
|
2005-01-21 02:17:08 +03:00
|
|
|
/** The buffer characteristics
|
2004-07-20 04:19:20 +04:00
|
|
|
*/
|
2005-01-21 02:17:08 +03:00
|
|
|
static bool buffer_active = false;
|
|
|
|
static osspriteop_area *buffer = NULL;
|
|
|
|
static char buffer_name[] = "scr_buffer\0\0";
|
2004-07-20 04:19:20 +04:00
|
|
|
|
2004-07-20 03:35:12 +04:00
|
|
|
/** The current clip area
|
|
|
|
*/
|
|
|
|
static os_box clipping;
|
|
|
|
|
|
|
|
/** The current save area
|
|
|
|
*/
|
|
|
|
static osspriteop_save_area *save_area;
|
|
|
|
static osspriteop_area *context1;
|
|
|
|
static osspriteop_id context2;
|
|
|
|
static osspriteop_save_area *context3;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a buffer for writing to.
|
|
|
|
*
|
|
|
|
* \param redraw the current WIMP redraw area to buffer
|
|
|
|
*/
|
|
|
|
void ro_gui_buffer_open(wimp_draw *redraw) {
|
|
|
|
int size;
|
|
|
|
int orig_x0, orig_y0;
|
2005-01-21 02:17:08 +03:00
|
|
|
int total_size;
|
2004-07-20 03:35:12 +04:00
|
|
|
os_coord sprite_size;
|
2005-01-21 02:17:08 +03:00
|
|
|
int bpp, word_width;
|
|
|
|
bool palette;
|
2004-07-21 00:02:59 +04:00
|
|
|
os_error *error;
|
2005-01-21 02:17:08 +03:00
|
|
|
int palette_size = 0;
|
|
|
|
int claim_size;
|
|
|
|
#ifdef BUFFER_EXCLUSIVE_USER_REDRAW
|
|
|
|
os_mode mode;
|
|
|
|
osspriteop_header *header;
|
|
|
|
#endif
|
2004-07-20 03:35:12 +04:00
|
|
|
|
|
|
|
/* Close any open buffer
|
|
|
|
*/
|
2005-01-21 02:17:08 +03:00
|
|
|
if (buffer_active)
|
|
|
|
ro_gui_buffer_close();
|
2004-07-20 03:35:12 +04:00
|
|
|
|
|
|
|
/* Store our clipping region
|
|
|
|
*/
|
|
|
|
clipping = redraw->clip;
|
|
|
|
|
|
|
|
/* Work out how much buffer we need
|
|
|
|
*/
|
|
|
|
sprite_size.x = clipping.x1 - clipping.x0 + 1;
|
|
|
|
sprite_size.y = clipping.y1 - clipping.y0 + 1;
|
|
|
|
ro_convert_os_units_to_pixels(&sprite_size, (os_mode)-1);
|
|
|
|
|
2004-07-20 04:19:20 +04:00
|
|
|
/* Get the screen depth as we can't use palettes for >8bpp
|
|
|
|
*/
|
|
|
|
xos_read_mode_variable((os_mode)-1, os_MODEVAR_LOG2_BPP, &bpp, 0);
|
2005-03-28 20:16:14 +04:00
|
|
|
palette = (bpp < 4);
|
2004-07-20 04:19:20 +04:00
|
|
|
|
2005-01-21 02:17:08 +03:00
|
|
|
/* Get our required buffer size
|
2004-07-20 03:35:12 +04:00
|
|
|
*/
|
2005-01-21 02:17:08 +03:00
|
|
|
word_width = ((sprite_size.x << bpp) + 31) >> 5;
|
|
|
|
if (palette)
|
|
|
|
palette_size = ((1 << (1 << bpp)) << 3);
|
|
|
|
total_size = sizeof(osspriteop_area) + sizeof(osspriteop_header) +
|
|
|
|
(word_width * sprite_size.y * 4) + palette_size;
|
|
|
|
|
|
|
|
if ((buffer == NULL) || (total_size > buffer->size)) {
|
2005-03-28 20:16:14 +04:00
|
|
|
claim_size = (total_size > (option_screen_cache << 10)) ?
|
|
|
|
total_size : (option_screen_cache << 10);
|
|
|
|
if (buffer)
|
|
|
|
free(buffer);
|
|
|
|
buffer = (osspriteop_area *)malloc(claim_size);
|
2005-01-21 02:17:08 +03:00
|
|
|
if (!buffer) {
|
|
|
|
LOG(("Failed to allocate memory"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
buffer->size = claim_size;
|
|
|
|
buffer->first = 16;
|
|
|
|
}
|
2005-03-28 20:16:14 +04:00
|
|
|
|
2005-01-21 02:17:08 +03:00
|
|
|
/* Set the sprite area details
|
|
|
|
*/
|
|
|
|
#ifdef BUFFER_EXCLUSIVE_USER_REDRAW
|
|
|
|
if ((error = xwimpreadsysinfo_wimp_mode(&mode)) != NULL) {
|
|
|
|
LOG(("Error reading mode '%s'", error->errmess));
|
|
|
|
ro_gui_buffer_free();
|
2004-07-21 00:02:59 +04:00
|
|
|
return;
|
|
|
|
}
|
2005-03-28 20:16:14 +04:00
|
|
|
|
2005-01-21 02:17:08 +03:00
|
|
|
/* Create the sprite manually so we don't waste time clearing the
|
|
|
|
background.
|
|
|
|
*/
|
|
|
|
buffer->sprite_count = 1;
|
|
|
|
buffer->used = total_size;
|
|
|
|
header = (osspriteop_header *)(buffer + 1);
|
|
|
|
header->size = total_size - sizeof(osspriteop_area);
|
|
|
|
memcpy(header->name, buffer_name, 12);
|
|
|
|
header->width = word_width - 1;
|
|
|
|
header->height = sprite_size.y - 1;
|
|
|
|
header->left_bit = 0;
|
|
|
|
header->right_bit = ((sprite_size.x << bpp) - 1) & 31;
|
|
|
|
header->image = sizeof(osspriteop_header) + palette_size;
|
|
|
|
header->mask = header->image;
|
|
|
|
header->mode = mode;
|
|
|
|
if (palette)
|
2005-03-28 20:16:14 +04:00
|
|
|
xcolourtrans_read_palette((osspriteop_area *)mode,
|
|
|
|
(osspriteop_id)colourtrans_CURRENT_MODE,
|
2005-01-21 02:17:08 +03:00
|
|
|
(os_palette *)(header + 1), palette_size,
|
2005-03-28 20:16:14 +04:00
|
|
|
(colourtrans_palette_flags)
|
|
|
|
colourtrans_FLASHING_PALETTE, 0);
|
2005-01-21 02:17:08 +03:00
|
|
|
#else
|
|
|
|
/* Read the current contents of the screen
|
2004-07-20 03:35:12 +04:00
|
|
|
*/
|
|
|
|
buffer->sprite_count = 0;
|
|
|
|
buffer->used = 16;
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((error = xosspriteop_get_sprite_user_coords(osspriteop_NAME,
|
2005-01-21 02:17:08 +03:00
|
|
|
buffer, buffer_name, palette,
|
2004-08-14 18:30:12 +04:00
|
|
|
clipping.x0, clipping.y0,
|
|
|
|
clipping.x1, clipping.y1)) != NULL) {
|
2005-01-21 02:17:08 +03:00
|
|
|
LOG(("Grab error '%s'", error->errmess));
|
|
|
|
ro_gui_buffer_free();
|
2004-07-20 03:35:12 +04:00
|
|
|
return;
|
|
|
|
}
|
2005-01-21 02:17:08 +03:00
|
|
|
#endif
|
2004-07-20 03:35:12 +04:00
|
|
|
/* Allocate OS_SpriteOp save area
|
|
|
|
*/
|
2005-01-21 02:17:08 +03:00
|
|
|
if ((error = xosspriteop_read_save_area_size(osspriteop_PTR,
|
|
|
|
buffer, (osspriteop_id)(buffer + 1), &size)) != NULL) {
|
|
|
|
LOG(("Save area error '%s'", error->errmess));
|
|
|
|
ro_gui_buffer_free();
|
2004-07-20 03:35:12 +04:00
|
|
|
return;
|
|
|
|
}
|
2004-08-14 18:30:12 +04:00
|
|
|
if ((save_area = malloc((size_t)size)) == NULL) {
|
2005-01-21 02:17:08 +03:00
|
|
|
ro_gui_buffer_free();
|
2004-07-20 03:35:12 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
save_area->a[0] = 0;
|
|
|
|
|
|
|
|
/* Switch output to sprite
|
|
|
|
*/
|
2005-01-21 02:17:08 +03:00
|
|
|
if ((error = xosspriteop_switch_output_to_sprite(osspriteop_PTR,
|
|
|
|
buffer, (osspriteop_id)(buffer + 1), save_area, 0,
|
2004-08-14 18:30:12 +04:00
|
|
|
(int *)&context1, (int *)&context2,
|
|
|
|
(int *)&context3)) != NULL) {
|
2005-01-21 02:17:08 +03:00
|
|
|
LOG(("Switching error '%s'", error->errmess));
|
2004-07-20 03:35:12 +04:00
|
|
|
free(save_area);
|
2005-01-21 02:17:08 +03:00
|
|
|
ro_gui_buffer_free();
|
2004-07-20 03:35:12 +04:00
|
|
|
return;
|
|
|
|
}
|
2004-07-21 00:02:59 +04:00
|
|
|
|
2004-07-20 03:35:12 +04:00
|
|
|
/* Move the origin such that (x0, y0) becomes (0, 0). To do this
|
|
|
|
we use VDU 29,(1 << 16) - x0; (1 << 16) - y0; because RISC OS
|
|
|
|
is so insanely legacy driven.
|
|
|
|
*/
|
|
|
|
orig_x0 = (1 << 16) - clipping.x0;
|
|
|
|
orig_y0 = (1 << 16) - clipping.y0;
|
|
|
|
os_writec((char)29);
|
|
|
|
os_writec(orig_x0 & 0xff); os_writec(orig_x0 >> 8);
|
|
|
|
os_writec(orig_y0 & 0xff); os_writec(orig_y0 >> 8);
|
2005-01-21 02:17:08 +03:00
|
|
|
buffer_active = true;
|
2004-07-20 03:35:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes any open buffer and flushes the contents to screen
|
|
|
|
*/
|
|
|
|
void ro_gui_buffer_close(void) {
|
2004-08-14 18:30:12 +04:00
|
|
|
|
2004-07-20 03:35:12 +04:00
|
|
|
/* Check we have an open buffer
|
|
|
|
*/
|
2005-01-21 02:17:08 +03:00
|
|
|
if (!buffer_active)
|
|
|
|
return;
|
2004-07-21 00:02:59 +04:00
|
|
|
|
2005-01-21 02:17:08 +03:00
|
|
|
/* Remove any previous redirection
|
2004-07-20 03:35:12 +04:00
|
|
|
*/
|
|
|
|
xosspriteop_switch_output_to_sprite(osspriteop_PTR,
|
|
|
|
context1, context2, context3,
|
|
|
|
0, 0, 0, 0);
|
|
|
|
free(save_area);
|
|
|
|
|
|
|
|
/* Plot the contents to screen
|
|
|
|
*/
|
2005-01-21 02:17:08 +03:00
|
|
|
xosspriteop_put_sprite_user_coords(osspriteop_PTR,
|
|
|
|
buffer, (osspriteop_id)(buffer + 1),
|
2004-07-20 03:35:12 +04:00
|
|
|
clipping.x0, clipping.y0, (os_action)0);
|
2005-01-21 02:17:08 +03:00
|
|
|
ro_gui_buffer_free();
|
|
|
|
buffer_active = false;
|
|
|
|
}
|
2004-08-14 18:30:12 +04:00
|
|
|
|
2005-01-21 02:17:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Releases any buffer memory depending on cache constraints.
|
|
|
|
*/
|
|
|
|
static void ro_gui_buffer_free(void) {
|
|
|
|
if (buffer == NULL)
|
|
|
|
return;
|
|
|
|
if (buffer->size > (option_screen_cache << 10)) {
|
|
|
|
free(buffer);
|
|
|
|
buffer = NULL;
|
|
|
|
}
|
2004-07-20 03:35:12 +04:00
|
|
|
}
|