2004-07-20 03:35:12 +04:00
|
|
|
/*
|
2005-01-21 02:17:08 +03:00
|
|
|
* Copyright 2004, 2005 Richard Wilson <info@tinct.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-07-20 03:35:12 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-07-27 02:29:15 +04:00
|
|
|
#include "swis.h"
|
2004-07-20 03:35:12 +04:00
|
|
|
#include "oslib/colourtrans.h"
|
|
|
|
#include "oslib/os.h"
|
2008-07-27 02:29:15 +04:00
|
|
|
#include "oslib/osspriteop.h"
|
2004-07-20 03:35:12 +04:00
|
|
|
#include "oslib/wimp.h"
|
2005-01-21 02:17:08 +03:00
|
|
|
#include "oslib/wimpreadsysinfo.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/buffer.h"
|
|
|
|
#include "riscos/gui.h"
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/tinct.h"
|
|
|
|
#include "riscos/wimp.h"
|
2009-03-28 22:17:08 +03:00
|
|
|
#include "riscos/wimputils.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/log.h"
|
2005-01-21 02:17:08 +03:00
|
|
|
#define BUFFER_EXCLUSIVE_USER_REDRAW "Only support pure user redraw (faster)"
|
2005-04-11 03:26:17 +04:00
|
|
|
//#define BUFFER_EMULATE_32BPP "Redirect to a 32bpp sprite and plot with Tinct"
|
2004-07-20 03:35:12 +04:00
|
|
|
|
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 osspriteop_area *buffer = NULL;
|
2009-02-01 16:37:32 +03:00
|
|
|
static char buffer_name[12] = "scr_buffer";
|
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;
|
2009-03-28 22:17:08 +03:00
|
|
|
static int context0;
|
|
|
|
static int context1;
|
|
|
|
static int context2;
|
|
|
|
static int context3;
|
2004-07-20 03:35:12 +04:00
|
|
|
|
2005-04-11 03:26:17 +04:00
|
|
|
/** The current sprite mode
|
|
|
|
*/
|
|
|
|
static os_mode mode;
|
2004-07-20 03:35:12 +04:00
|
|
|
|
2005-04-12 23:11:35 +04:00
|
|
|
|
2004-07-20 03:35:12 +04:00
|
|
|
/**
|
|
|
|
* Opens a buffer for writing to.
|
|
|
|
*
|
2005-04-12 23:11:35 +04:00
|
|
|
* The ro_plot_origin_ variables are updated to reflect the new screen origin,
|
|
|
|
* so the variables should be set before calling this function, and not
|
|
|
|
* changed until after ro_gui_buffer_close() has been called.
|
|
|
|
*
|
2004-07-20 03:35:12 +04:00
|
|
|
* \param redraw the current WIMP redraw area to buffer
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_buffer_open(wimp_draw *redraw)
|
|
|
|
{
|
2004-07-20 03:35:12 +04:00
|
|
|
int size;
|
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;
|
|
|
|
#ifdef BUFFER_EXCLUSIVE_USER_REDRAW
|
|
|
|
osspriteop_header *header;
|
|
|
|
#endif
|
2004-07-20 03:35:12 +04:00
|
|
|
|
|
|
|
/* Close any open buffer
|
|
|
|
*/
|
2005-04-11 03:26:17 +04:00
|
|
|
if (buffer)
|
2005-01-21 02:17:08 +03:00
|
|
|
ro_gui_buffer_close();
|
2004-07-20 03:35:12 +04:00
|
|
|
|
|
|
|
/* Store our clipping region
|
|
|
|
*/
|
|
|
|
clipping = redraw->clip;
|
|
|
|
|
2005-04-12 23:11:35 +04:00
|
|
|
/* Stop bad rectangles
|
|
|
|
*/
|
|
|
|
if ((clipping.x1 < clipping.x0) ||
|
|
|
|
(clipping.y1 < clipping.y0)) {
|
|
|
|
LOG(("Invalid clipping rectangle (%i, %i) to (%i,%i)",
|
|
|
|
clipping.x0, clipping.y0,
|
|
|
|
clipping.x1, clipping.y1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-07-20 03:35:12 +04:00
|
|
|
/* 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);
|
2005-04-11 03:26:17 +04:00
|
|
|
if (sprite_size.y == 1) /* work around SpriteExtend bug */
|
|
|
|
sprite_size.y = 2;
|
|
|
|
|
|
|
|
#ifdef BUFFER_EMULATE_32BPP
|
|
|
|
bpp = 5;
|
|
|
|
palette = false;
|
|
|
|
#else
|
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);
|
2005-04-11 03:26:17 +04:00
|
|
|
#endif
|
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;
|
2005-04-11 03:26:17 +04:00
|
|
|
buffer = (osspriteop_area *)malloc(total_size);
|
|
|
|
if (!buffer) {
|
|
|
|
LOG(("Failed to allocate memory"));
|
2005-04-12 23:11:35 +04:00
|
|
|
ro_gui_buffer_free();
|
2005-04-11 03:26:17 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
buffer->size = total_size;
|
|
|
|
buffer->first = 16;
|
2005-01-21 02:17:08 +03:00
|
|
|
|
2005-04-11 03:26:17 +04:00
|
|
|
#ifdef BUFFER_EMULATE_32BPP
|
|
|
|
mode = tinct_SPRITE_MODE;
|
|
|
|
#else
|
2006-03-25 09:21:21 +03:00
|
|
|
if ((error = xwimpreadsysinfo_wimp_mode(&mode)) != NULL) {
|
|
|
|
LOG(("Error reading mode '%s'", error->errmess));
|
|
|
|
ro_gui_buffer_free();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we're not in a numbered screen mode then we need
|
|
|
|
to build a suitable sprite mode word */
|
|
|
|
if (mode >= (os_mode)0x100) {
|
2009-03-28 22:17:08 +03:00
|
|
|
static const ns_os_vdu_var_list vars = {
|
|
|
|
os_MODEVAR_LOG2_BPP,
|
|
|
|
{
|
|
|
|
os_MODEVAR_XEIG_FACTOR,
|
|
|
|
os_MODEVAR_YEIG_FACTOR,
|
|
|
|
os_VDUVAR_END_LIST
|
|
|
|
}
|
2006-03-25 09:21:21 +03:00
|
|
|
};
|
|
|
|
int xeig, yeig;
|
|
|
|
int vals[4];
|
|
|
|
int type;
|
|
|
|
|
2009-03-28 22:17:08 +03:00
|
|
|
error = xos_read_vdu_variables(PTR_OS_VDU_VAR_LIST(&vars), vals);
|
2006-03-25 09:21:21 +03:00
|
|
|
if (error) {
|
|
|
|
LOG(("Error reading mode properties '%s'", error->errmess));
|
2005-04-11 03:26:17 +04:00
|
|
|
ro_gui_buffer_free();
|
2005-01-21 02:17:08 +03:00
|
|
|
return;
|
|
|
|
}
|
2005-09-14 23:08:48 +04:00
|
|
|
|
2006-03-25 09:21:21 +03:00
|
|
|
type = 1 + vals[0];
|
|
|
|
xeig = vals[1];
|
|
|
|
yeig = vals[2];
|
|
|
|
|
|
|
|
mode = (os_mode)((type << 27) | ((180 >> yeig) << 14) |
|
|
|
|
((180 >> xeig) << 1) | 1);
|
2005-01-21 02:17:08 +03:00
|
|
|
}
|
2005-04-11 03:26:17 +04:00
|
|
|
#endif
|
2005-03-28 20:16:14 +04:00
|
|
|
|
2005-01-21 02:17:08 +03:00
|
|
|
#ifdef BUFFER_EXCLUSIVE_USER_REDRAW
|
|
|
|
/* 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,
|
2009-12-02 19:30:44 +03:00
|
|
|
(osspriteop_id)os_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,
|
2009-03-28 22:17:08 +03:00
|
|
|
buffer, (osspriteop_id)(buffer + 1), save_area,
|
|
|
|
&context0, &context1, &context2, &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
|
|
|
|
2005-04-12 23:11:35 +04:00
|
|
|
/* Emulate an origin as the FontManager doesn't respect it in
|
|
|
|
most cases.
|
2004-07-20 03:35:12 +04:00
|
|
|
*/
|
2005-04-12 23:11:35 +04:00
|
|
|
ro_plot_origin_x -= clipping.x0;
|
|
|
|
ro_plot_origin_y -= clipping.y0;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-03 06:08:54 +04:00
|
|
|
/* Update the ECF origin
|
|
|
|
*/
|
|
|
|
if ((error = xos_set_ecf_origin(-ro_plot_origin_x,
|
|
|
|
-ro_plot_origin_y)) != NULL) {
|
|
|
|
LOG(("Invalid ECF origin"));
|
|
|
|
}
|
2004-07-20 03:35:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes any open buffer and flushes the contents to screen
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_buffer_close(void)
|
|
|
|
{
|
2004-07-20 03:35:12 +04:00
|
|
|
/* Check we have an open buffer
|
|
|
|
*/
|
2005-04-11 03:26:17 +04:00
|
|
|
if (!buffer)
|
2005-01-21 02:17:08 +03:00
|
|
|
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
|
|
|
*/
|
2005-04-14 05:35:47 +04:00
|
|
|
ro_plot_origin_x += clipping.x0;
|
|
|
|
ro_plot_origin_y += clipping.y0;
|
2009-03-28 22:17:08 +03:00
|
|
|
xosspriteop_unswitch_output(context0, context1, context2, context3);
|
2004-07-20 03:35:12 +04:00
|
|
|
free(save_area);
|
|
|
|
|
|
|
|
/* Plot the contents to screen
|
|
|
|
*/
|
2005-04-11 03:26:17 +04:00
|
|
|
if (mode == tinct_SPRITE_MODE)
|
|
|
|
_swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
|
|
|
|
(char *)(buffer + 1),
|
|
|
|
clipping.x0, clipping.y0,
|
2013-05-28 19:44:46 +04:00
|
|
|
nsoption_int(plot_fg_quality));
|
2005-04-11 03:26:17 +04:00
|
|
|
else
|
|
|
|
xosspriteop_put_sprite_user_coords(osspriteop_PTR,
|
|
|
|
buffer, (osspriteop_id)(buffer + 1),
|
|
|
|
clipping.x0, clipping.y0, (os_action)0);
|
2005-01-21 02:17:08 +03:00
|
|
|
ro_gui_buffer_free();
|
2006-07-03 06:08:54 +04:00
|
|
|
|
|
|
|
/* Update the ECF origin
|
|
|
|
*/
|
|
|
|
os_set_ecf_origin(0, 0);
|
2005-01-21 02:17:08 +03:00
|
|
|
}
|
2004-08-14 18:30:12 +04:00
|
|
|
|
2005-01-21 02:17:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Releases any buffer memory depending on cache constraints.
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
static void ro_gui_buffer_free(void)
|
|
|
|
{
|
2005-04-11 03:26:17 +04:00
|
|
|
free(buffer);
|
|
|
|
buffer = NULL;
|
2004-07-20 03:35:12 +04:00
|
|
|
}
|