summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.sources4
-rw-r--r--atari/Makefile.target22
-rwxr-xr-xatari/bitmap.c36
-rwxr-xr-xatari/bitmap.h34
-rwxr-xr-xatari/browser.c43
-rwxr-xr-xatari/browser_win.c21
-rw-r--r--atari/ctxmenu.c82
-rwxr-xr-xatari/doc/readme.txt4
-rwxr-xr-xatari/font.c7
-rwxr-xr-xatari/gui.c5
-rwxr-xr-xatari/history.c2
-rwxr-xr-xatari/options.h3
-rwxr-xr-xatari/plot.c255
-rwxr-xr-xatari/plot.h37
-rwxr-xr-xatari/plot/font_freetype.c20
-rw-r--r--atari/plot/font_internal.c20
-rw-r--r--atari/plot/font_internal.h4
-rwxr-xr-xatari/plot/font_vdi.c2
-rw-r--r--atari/plot/fontplot.c88
-rw-r--r--atari/plot/fontplot.h79
-rwxr-xr-xatari/plot/plot.c2068
-rwxr-xr-xatari/plot/plot.h187
-rwxr-xr-xatari/plot/plotter.c662
-rwxr-xr-xatari/plot/plotter.h364
-rw-r--r--atari/plot/plotter_gd.c237
-rw-r--r--atari/plot/plotter_gd.h39
-rwxr-xr-xatari/plot/plotter_vdi.c1713
-rwxr-xr-xatari/plot/plotter_vdi.h109
-rwxr-xr-xatari/statusbar.c49
-rwxr-xr-xatari/toolbar.c75
-rwxr-xr-xatari/toolbar.h2
-rwxr-xr-xatari/treeview.c24
-rwxr-xr-xatari/verify_ssl.c30
-rw-r--r--css/select.c1
-rw-r--r--javascript/jsapi/document.c6
-rw-r--r--render/box_construct.c4
-rw-r--r--render/box_normalise.c14
-rw-r--r--render/html.c513
-rw-r--r--render/html.h7
-rw-r--r--render/html_internal.h21
-rw-r--r--render/html_script.c339
-rw-r--r--render/hubbub_binding.c1325
-rw-r--r--render/libdom_binding.c126
-rw-r--r--render/parser_binding.h63
44 files changed, 3185 insertions, 5561 deletions
diff --git a/Makefile.sources b/Makefile.sources
index 613d700ea..608381934 100644
--- a/Makefile.sources
+++ b/Makefile.sources
@@ -13,8 +13,8 @@ S_CSS := css.c dump.c internal.c select.c utils.c
S_RENDER := box.c box_construct.c box_normalise.c \
font.c form.c \
- html.c html_interaction.c html_redraw.c html_forms.c \
- libdom_binding.c imagemap.c layout.c list.c search.c table.c \
+ html.c html_script.c html_interaction.c html_redraw.c html_forms.c \
+ imagemap.c layout.c list.c search.c table.c \
textinput.c textplain.c
S_UTILS := base64.c filename.c hashtable.c locale.c messages.c nsurl.c \
diff --git a/atari/Makefile.target b/atari/Makefile.target
index 27538817d..2589a4208 100644
--- a/atari/Makefile.target
+++ b/atari/Makefile.target
@@ -2,9 +2,20 @@
# Atari target setup
# ----------------------------------------------------------------------------
+# define additional CFLAGS and LDFLAGS requirements for pkg-configed libs here
+NETSURF_FEATURE_JS_CFLAGS := -DWITH_JS -DJS_HAS_FILE_OBJECT=0
+NETSURF_FEATURE_MOZJS_CFLAGS := -DWITH_MOZJS -DJS_HAS_FILE_OBJECT=0
+
+ifeq ($(NETSURF_USE_MOZJS),YES)
+NETSURF_USE_JS:=YES
+NETSURF_USE_MOZJS:=YES
+endif
+
+# non-pkgconfig components
$(eval $(call feature_enabled,MNG,-DWITH_MNG,-lmng,PNG/MNG/JNG (libmng)))
-$(eval $(call feature_enabled,GD_PLOTTER,-DWITH_GD_PLOTTER,-lgd,GD Plotter (libgd) ))
-$(eval $(call feature_enabled,PNG,-DWITH_PNG,-lpng,PNG (libpng) ))
+$(eval $(call feature_enabled,GD_PLOTTER,-DWITH_GD_PLOTTER,-lgd,GD Plotter (libgd)))
+$(eval $(call feature_enabled,PNG,-DWITH_PNG,-lpng,PNG (libpng)))
+$(eval $(call feature_enabled,MOZJS,-DWITH_MOZJS,-ljs,JavaScript (Spidermonkey)))
CFLAGS += -DATARI_USE_FREETYPE $(shell freetype-config --cflags)
LDFLAGS += -lcflib -lfreetype
@@ -37,11 +48,8 @@ LDFLAGS += -lxml2 -lz -liconv -lcares -lHermes -lwindom -lgem -lm
S_ATARI := gui.c findfile.c filetype.c misc.c bitmap.c schedule.c \
download.c thumbnail.c login.c verify_ssl.c treeview.c hotlist.c history.c\
search.c font.c \
- plot.c plot/plotter.c \
- plot/plotter_vdi.c \
- plot/plotter_gd.c \
- plot/font_vdi.c plot/font_freetype.c plot/font_internal.c \
- plot/eddi.s \
+ plot/plot.c plot/fontplot.c plot/eddi.s \
+ plot/font_freetype.c plot/font_internal.c \
redrawslots.c encoding.c \
browser_win.c toolbar.c statusbar.c browser.c \
global_evnt.c osspec.c dragdrop.c system_colour.c \
diff --git a/atari/bitmap.c b/atari/bitmap.c
index 97fa37484..9cfebcaf6 100755
--- a/atari/bitmap.c
+++ b/atari/bitmap.c
@@ -23,11 +23,43 @@
#include "assert.h"
+#include "desktop/options.h"
#include "image/bitmap.h"
#include "atari/bitmap.h"
-#include "atari/plot.h"
+#include "atari/plot/plot.h"
#include "utils/log.h"
+
+/*
+ bpp: bits per pixel,
+
+*/
+int init_mfdb(int bpp, int w, int h, uint32_t flags, MFDB * out )
+{
+ int dststride;
+ dststride = MFDB_STRIDE( w );
+ int size = MFDB_SIZE( bpp, dststride, h );
+ if( bpp > 0 ) {
+ if( (flags & MFDB_FLAG_NOALLOC) == 0 ) {
+ out->fd_addr = malloc( size );
+ if( out->fd_addr == NULL ){
+ return( 0 );
+ }
+ if( (flags & MFDB_FLAG_ZEROMEM) ){
+ memset( out->fd_addr, 0, size );
+ }
+ }
+ out->fd_stand = (flags & MFDB_FLAG_STAND) ? 1 : 0;
+ out->fd_nplanes = (short)bpp;
+ out->fd_r1 = out->fd_r2 = out->fd_r3 = 0;
+ } else {
+ memset( out, 0, sizeof(MFDB) );
+ }
+ out->fd_w = dststride;
+ out->fd_h = h;
+ out->fd_wdwidth = dststride >> 4;
+ return( size );
+}
/**
@@ -327,7 +359,7 @@ bool bitmap_test_opaque(void *bitmap)
LOG(("NULL bitmap!"));
return false;
}
-
+
if( nsoption_int(atari_transparency) == 0 ){
return( true );
}
diff --git a/atari/bitmap.h b/atari/bitmap.h
index f917f5560..7002a14ee 100755
--- a/atari/bitmap.h
+++ b/atari/bitmap.h
@@ -19,10 +19,35 @@
#ifndef NS_ATARI_BITMAP_H
#define NS_ATARI_BITMAP_H
+#include <gem.h>
+
+/* Flags for init_mfdb function: */
+#define MFDB_FLAG_STAND 0x01
+#define MFDB_FLAG_ZEROMEM 0x02
+#define MFDB_FLAG_NOALLOC 0x04
+
#define BITMAP_SHRINK 0
#define BITMAP_GROW 1024 /* Don't realloc when bitmap size shrinks */
#define BITMAP_CLEAR 2048 /* Zero bitmap memory */
+
+/*
+ calculates MFDB compatible rowstride (in number of bits)
+*/
+#define MFDB_STRIDE( w ) (((w & 15) != 0) ? (w | 15)+1 : w)
+
+
+/*
+Calculate size of an mfdb,
+
+ params:
+
+ bpp: Bits per pixel,
+ stride: Word aligned rowstride (width) as returned by MFDB_STRIDE,
+ h: Height in pixels
+*/
+#define MFDB_SIZE( bpp, stride, h ) ( ((stride >> 3) * h) * bpp )
+
struct bitmap {
int width;
int height;
@@ -41,5 +66,14 @@ void * bitmap_create_ex( int w, int h, short bpp, int rowstride, unsigned int st
void bitmap_to_mfdb(void * bitmap, MFDB * out);
void * bitmap_realloc( int w, int h, short bpp, int rowstride, unsigned int state, void * bmp );
size_t bitmap_buffer_size( void * bitmap ) ;
+/*
+ setup an MFDB struct and allocate memory for it when it is needed.
+ If bpp == 0, this function assumes that the MFDB shall point to the screen
+ and will not allocate any memory (mfdb.fd_addr == 0).
+ The function will return 0 when the memory allocation fails
+ ( out of memory), otherwise it returns the size of the mfdb.fd_addr
+ as number of bytes.
+*/
+int init_mfdb(int bpp, int w, int h, uint32_t flags, MFDB * out );
#endif
diff --git a/atari/browser.c b/atari/browser.c
index 3d05dbd39..373cd73c7 100755
--- a/atari/browser.c
+++ b/atari/browser.c
@@ -52,14 +52,16 @@
#include "atari/res/netsurf.rsh"
#include "atari/redrawslots.h"
#include "atari/browser.h"
-#include "atari/plot/plotter.h"
-#include "atari/plot.h"
+#include "atari/plot/plot.h"
+#include "atari/plot/plot.h"
#include "atari/encoding.h"
#include "atari/ctxmenu.h"
#include "cflib.h"
-extern GEM_PLOTTER plotter;
-extern struct gui_window *input_window;
+extern struct gui_window *input_window;
+
+extern long atari_plot_flags;
+extern int atari_plot_vdi_handle;
static void browser_process_scroll( struct gui_window * gw, LGRECT bwrect );
static void browser_redraw_content( struct gui_window * gw, int xoff, int yoff,
@@ -431,7 +433,7 @@ static void browser_process_scroll( struct gui_window * gw, LGRECT bwrect )
dst.g_y = h;
dst.g_w = src.g_w;
dst.g_h = src.g_h;
- plotter->copy_rect( plotter, src, dst );
+ plot_copy_rect(src, dst);
b->scroll.current.y += b->scroll.requested.y;
browser_schedule_redraw( gw, 0, 0, bwrect.g_w, h );
}
@@ -446,7 +448,7 @@ static void browser_process_scroll( struct gui_window * gw, LGRECT bwrect )
dst.g_y = 0;
dst.g_w = bwrect.g_w;
dst.g_h = bwrect.g_h - h;
- plotter->copy_rect( plotter, src, dst );
+ plot_copy_rect(src, dst );
b->scroll.current.y += b->scroll.requested.y;
browser_schedule_redraw( gw, 0, bwrect.g_h - h, bwrect.g_w, bwrect.g_h );
}
@@ -461,7 +463,7 @@ static void browser_process_scroll( struct gui_window * gw, LGRECT bwrect )
dst.g_y = 0;
dst.g_w = bwrect.g_w - w;
dst.g_h = bwrect.g_h;
- plotter->copy_rect( plotter, src, dst );
+ plot_copy_rect(src, dst );
b->scroll.current.x += b->scroll.requested.x;
browser_schedule_redraw( gw, 0, 0, w, bwrect.g_h );
}
@@ -476,7 +478,7 @@ static void browser_process_scroll( struct gui_window * gw, LGRECT bwrect )
dst.g_y = 0;
dst.g_w = bwrect.g_w - w;
dst.g_h = bwrect.g_h;
- plotter->copy_rect( plotter, src, dst );
+ plot_copy_rect(src, dst );
b->scroll.current.x += b->scroll.requested.x;
browser_schedule_redraw( gw, bwrect.g_w - w, 0, bwrect.g_w, bwrect.g_h );
}
@@ -746,15 +748,14 @@ void browser_redraw( struct gui_window * gw )
}
browser_get_rect(gw, BR_CONTENT, &bwrect);
-
- plotter->resize(plotter, bwrect.g_w, bwrect.g_h);
- plotter->move(plotter, bwrect.g_x, bwrect.g_y );
+
+ plot_set_dimensions(bwrect.g_x, bwrect.g_y, bwrect.g_w, bwrect.g_h);
clip.x0 = 0;
clip.y0 = 0;
clip.x1 = bwrect.g_w;
clip.y1 = bwrect.g_h;
- plotter->set_clip( plotter, &clip );
- if( plotter->lock(plotter) == 0 )
+ plot_clip(&clip);
+ if (plot_lock() == false)
return;
if( b->scroll.required == true && b->bw->current_content != NULL) {
@@ -763,7 +764,7 @@ void browser_redraw( struct gui_window * gw )
}
if ((b->redraw.areas_used > 0) && b->bw->current_content != NULL ) {
- if( (plotter->flags & PLOT_FLAG_OFFSCREEN) == 0 ) {
+ if( (atari_plot_flags & PLOT_FLAG_OFFSCREEN) == 0 ) {
int i;
GRECT area;
@@ -773,7 +774,7 @@ void browser_redraw( struct gui_window * gw )
todo[1] = bwrect.g_y;
todo[2] = todo[0] + bwrect.g_w-1;
todo[3] = todo[1] + bwrect.g_h-1;
- vs_clip(plotter->vdi_handle, 1, (short*)&todo[0]);
+ vs_clip(atari_plot_vdi_handle, 1, (short*)&todo[0]);
wind_get( 0, WF_TOP, &wf_top[0], &wf_top[1],
&wf_top[2], &wf_top[3] );
@@ -859,9 +860,7 @@ void browser_redraw( struct gui_window * gw )
}
}
}
-
-
- vs_clip(plotter->vdi_handle, 0, (short*)&todo);
+ vs_clip(atari_plot_vdi_handle, 0, (short*)&todo);
} else {
/* its save to do a complete redraw without knowledge about GEM windows :) */
@@ -881,7 +880,7 @@ void browser_redraw( struct gui_window * gw )
area.g_y = bwrect.g_y;
area.g_w = bwrect.g_w;
area.g_h = bwrect.g_h;
- //plotter->blit( plotter, &area );
+ //plot_blit( plotter, &area );
}
b->redraw.areas_used = 0;
}
@@ -895,12 +894,12 @@ void browser_redraw( struct gui_window * gw )
area.g_y = bwrect.g_y;
area.g_w = bwrect.g_w;
area.g_h = bwrect.g_h;
- vs_clip(plotter->vdi_handle, 1, (short*)&todo[0]);
+ vs_clip(atari_plot_vdi_handle, 1, (short*)&todo[0]);
browser_redraw_caret( gw, &area );
- vs_clip(plotter->vdi_handle, 0, (short*)&todo[0]);
+ vs_clip(atari_plot_vdi_handle, 0, (short*)&todo[0]);
b->caret.redraw = false;
}
- plotter->unlock(plotter);
+ plot_unlock();
/* TODO: if we use offscreen bitmap, trigger content redraw here */
}
diff --git a/atari/browser_win.c b/atari/browser_win.c
index 4719230d3..273ef48eb 100755
--- a/atari/browser_win.c
+++ b/atari/browser_win.c
@@ -46,13 +46,13 @@
#include "atari/gui.h"
#include "atari/browser_win.h"
#include "atari/browser.h"
-#include "atari/misc.h"
+#include "atari/misc.h"
+#include "atari/plot/plot.h"
#include "atari/global_evnt.h"
#include "atari/res/netsurf.rsh"
#include "atari/browser.h"
#include "atari/toolbar.h"
#include "atari/statusbar.h"
-#include "atari/plot/plotter.h"
#include "atari/dragdrop.h"
#include "atari/search.h"
#include "atari/osspec.h"
@@ -61,7 +61,6 @@
extern void * h_gem_rsrc;
extern struct gui_window *input_window;
-extern GEM_PLOTTER plotter;
void __CDECL std_szd( WINDOW * win, short buff[8], void * );
void __CDECL std_mvd( WINDOW * win, short buff[8], void * );
@@ -228,9 +227,8 @@ void window_open( struct gui_window * gw, GRECT pos )
/* recompute the nested component sizes and positions: */
browser_update_rects( gw );
mt_WindGetGrect( &app, gw->root->handle, WF_CURRXYWH, (GRECT*)&gw->root->loc);
- browser_get_rect( gw, BR_CONTENT, &br );
- plotter->move( plotter, br.g_x, br.g_y );
- plotter->resize( plotter, br.g_w, br.g_h );
+ browser_get_rect( gw, BR_CONTENT, &br );
+ plot_set_dimensions(br.g_x, br.g_y, br.g_w, br.g_h);
gw->browser->attached = true;
if( gw->root->statusbar != NULL ){
gw->root->statusbar->attached = true;
@@ -503,13 +501,10 @@ static void __CDECL evnt_window_icondraw( WINDOW *win, short buff[8], void * dat
} else {
struct rect clip = { 0,0,w,h };
plot_set_dimensions( x,y,w,h );
- plotter->set_clip(plotter, &clip );
- plotter->bitmap_resize( plotter, gw->icon, w, h );
- plotter->bitmap(
- plotter,
- ( gw->icon->resized ) ? gw->icon->resized : gw->icon,
- 0, 0, 0xffffff, BITMAPF_NONE
- );
+ plot_clip(&clip);
+ plot_resize_bitmap(gw->icon, w, h);
+ plot_blit_bitmap(( gw->icon->resized ) ? gw->icon->resized : gw->icon,
+ 0, 0, 0xffffff, BITMAPF_NONE);
}
}
diff --git a/atari/ctxmenu.c b/atari/ctxmenu.c
index 2acf61ca4..25b3c847b 100644
--- a/atari/ctxmenu.c
+++ b/atari/ctxmenu.c
@@ -32,7 +32,8 @@
#include "desktop/textinput.h"
#include "content/content.h"
#include "content/hlcache.h"
-#include "content/urldb.h"
+#include "content/urldb.h"
+#include "render/html.h"
#include "css/css.h"
#include "render/box.h"
#include "render/form.h"
@@ -67,16 +68,14 @@ struct s_context_info ctxinfo;
static struct s_context_info * get_context_info( struct gui_window * gw, short mx, short my )
{
- int posx, posy;
struct box *box;
- struct box *file_box = 0;
hlcache_handle *h;
int box_x, box_y;
LGRECT bwrect;
struct contextual_content ccdata;
- struct browser_window * bw = gw->browser->bw;
- h = bw->current_content;
+ struct browser_window * bw = gw->browser->bw;
+ h = bw->current_content;
ctxinfo.flags = 0;
browser_get_rect( gw, BR_CONTENT, &bwrect );
@@ -146,17 +145,17 @@ void context_popup( struct gui_window * gw, short x, short y )
int choice;
struct s_context_info * ctx;
unsigned long size;
- char * data;
+ const char * data;
FILE * fp_tmpfile;
char * tempfile;
- int err = 0;
- char * editor;
+ int err = 0;
+ char * editor;
char cmdline[128];
pop = get_tree( POP_CTX );
- if( pop == NULL )
+ if (pop == NULL)
return;
- ctx = get_context_info( gw, x, y );
+ ctx = get_context_info(gw, x, y);
/*
Disable all items by default:
@@ -177,7 +176,7 @@ void context_popup( struct gui_window * gw, short x, short y )
if( ctx->flags & CNT_HREF ){
SET_BIT(pop[ POP_CTX_COPY_LINK ].ob_state, DISABLED, 0);
- SET_BIT(pop[ POP_CTX_OPEN_NEW ].ob_state, DISABLED, 0);
+ SET_BIT(pop[ POP_CTX_OPEN_NEW ].ob_state, DISABLED, 0);
SET_BIT(pop[ POP_CTX_SAVE_LINK_AS ].ob_state, DISABLED, 0);
}
@@ -210,24 +209,24 @@ void context_popup( struct gui_window * gw, short x, short y )
browser_window_key_press( gw->browser->bw, KEY_SELECT_ALL );
break;
- case POP_CTX_SAVE_AS:
- if( ctx->ccdata.object != NULL ) {
+ case POP_CTX_SAVE_AS:
+ if( ctx->ccdata.object != NULL ) {
if( hlcache_handle_get_url(ctx->ccdata.object) != NULL ) {
browser_window_download(
gw->browser->bw,
nsurl_access(hlcache_handle_get_url(ctx->ccdata.object)),
nsurl_access(hlcache_handle_get_url(gw->browser->bw->current_content))
);
- }
- }
-
- case POP_CTX_SAVE_LINK_AS:
- if( ctx->ccdata.link_url != NULL ) {
+ }
+ }
+
+ case POP_CTX_SAVE_LINK_AS:
+ if( ctx->ccdata.link_url != NULL ) {
browser_window_download(
gw->browser->bw,
- nsurl_access((const char*)ctx->ccdata.link_url),
+ ctx->ccdata.link_url,
nsurl_access(hlcache_handle_get_url(gw->browser->bw->current_content))
- );
+ );
}
break;
@@ -257,33 +256,34 @@ void context_popup( struct gui_window * gw, short x, short y )
}
break;
- case POP_CTX_VIEW_SOURCE:
+ case POP_CTX_VIEW_SOURCE:
editor = nsoption_charp(atari_editor);
- if( editor != NULL && strlen(editor)>0 ) {
- data = content_get_source_data( gw->browser->bw->current_content, &size );
- if( size > 0 && data != NULL ){
+ if (editor != NULL && strlen(editor)>0) {
+ data = content_get_source_data(gw->browser->bw->current_content,
+ &size);
+ if (size > 0 && data != NULL){
tempfile = tmpnam( NULL );
fp_tmpfile = fopen( tempfile, "w" );
- if( fp_tmpfile ){
- fwrite( data, size, 1, fp_tmpfile );
- fclose( fp_tmpfile );
-
- // TODO: check if app is runnin, if not, use pexec or such.
- /*
- sprintf((char*)&cmdline, "%s \"%s\"", nsoption_charp(atari_editor), tempfile );
- system( (char*)&cmdline );
- */
- err = ShelWrite( editor, tempfile , editor, 1, 0);
+ if (fp_tmpfile != NULL){
+ fwrite(data, size, 1, fp_tmpfile);
+ fclose(fp_tmpfile );
+
+ // TODO: check if app is runnin, if not, use pexec or such.
+ /*
+ sprintf((char*)&cmdline, "%s \"%s\"", nsoption_charp(atari_editor), tempfile );
+ system( (char*)&cmdline );
+ */
+ err = ShelWrite( editor, tempfile , editor, 1, 0);
LOG(("Launched: %s %s (%d)\n", editor, tempfile, err ));
- } else {
- printf("Could not open temp file: %s!\n", tempfile );
- }
+ } else {
+ printf("Could not open temp file: %s!\n", tempfile );
+ }
- } else {
- LOG(("Invalid content!"));
+ } else {
+ LOG(("Invalid content!"));
}
- } else {
- form_alert(0, "[1][Set option \"option_atari_editor\".][OK]");
+ } else {
+ form_alert(0, "[1][Set option \"option_atari_editor\".][OK]");
}
break;
diff --git a/atari/doc/readme.txt b/atari/doc/readme.txt
index 18620a542..829b59ec8 100755
--- a/atari/doc/readme.txt
+++ b/atari/doc/readme.txt
@@ -6,10 +6,10 @@
NATIVE ATARI ALPHA
- Version 3.0 (Development Version)
+ Version 2.9 (Release Version)
Ported by: m0n0
-Release date: 09.09.2011
+Release date: xx.xx.xx
Contact: ole@monochrom.net
WWW: http://netsurf-browser.org
diff --git a/atari/font.c b/atari/font.c
index cb47c8ef3..713765818 100755
--- a/atari/font.c
+++ b/atari/font.c
@@ -31,13 +31,12 @@
#include "atari/gui.h"
#include "atari/font.h"
-#include "atari/plot.h"
+#include "atari/plot/plot.h"
#include "atari/findfile.h"
#include "atari/gui.h"
-#include "atari/plot.h"
-#include "atari/plot/plotter.h"
+#include "atari/plot/plot.h"
-extern GEM_FONT_PLOTTER fplotter;
+extern FONT_PLOTTER fplotter;
static bool atari_font_position_in_string(const plot_font_style_t * fstyle,const char *string,
size_t length,int x, size_t *char_offset, int *actual_x )
diff --git a/atari/gui.c b/atari/gui.c
index fef8fcb62..12e516f73 100755
--- a/atari/gui.c
+++ b/atari/gui.c
@@ -71,7 +71,7 @@
#include "atari/global_evnt.h"
#include "atari/encoding.h"
#include "atari/res/netsurf.rsh"
-#include "atari/plot.h"
+#include "atari/plot/plot.h"
#include "atari/clipboard.h"
#include "atari/osspec.h"
#include "atari/search.h"
@@ -85,7 +85,6 @@ struct gui_window *window_list = NULL;
void * h_gem_rsrc;
OBJECT * h_gem_menu;
OBJECT **rsc_trindex;
-short vdih;
short rsc_ntree;
long next_poll;
bool rendering = false;
@@ -972,7 +971,7 @@ static void gui_init(int argc, char** argv)
die("unable to process command line.\n");
nkc_init();
- atari_plotter_init( nsoption_charp(atari_screen_driver), nsoption_charp(atari_font_driver) );
+ atari_plotter_init(nsoption_charp(atari_font_driver));
}
static char *theapp = (char*)"NetSurf";
diff --git a/atari/history.c b/atari/history.c
index 683d6a588..c145da3ad 100755
--- a/atari/history.c
+++ b/atari/history.c
@@ -103,7 +103,7 @@ bool global_history_init( void )
LOG(("Failed to allocate history window"));
return( false );
}
- /* TODO: load hotlist strings from messages */
+ /* TODO: load history strings from messages */
WindSetStr( gl_history.window, WF_NAME, (char*)"History" );
//WindSetPtr( gl_history.window, WF_TOOLBAR, tree, evnt_history_toolbar );
EvntAttach( gl_history.window, WM_CLOSED, evnt_history_close );
diff --git a/atari/options.h b/atari/options.h
index 9b6257d9c..005271f62 100755
--- a/atari/options.h
+++ b/atari/options.h
@@ -25,7 +25,6 @@
#define NSOPTION_EXTRA_DEFINE \
- char *atari_screen_driver; \
char *atari_font_driver; \
int atari_font_monochrom; \
int atari_dither; \
@@ -50,7 +49,6 @@
char *tree_icons_path
#define NSOPTION_EXTRA_DEFAULTS \
- .atari_screen_driver = (char*)"vdi", \
.atari_font_driver = (char*)"vdi", \
.atari_font_monochrom = 0, \
.atari_dither = 1, \
@@ -75,7 +73,6 @@
.tree_icons_path = (char*)"./res/icons"
#define NSOPTION_EXTRA_TABLE \
- { "atari_screen_driver", OPTION_STRING, &nsoptions.atari_screen_driver },\
{ "atari_font_driver", OPTION_STRING, &nsoptions.atari_font_driver },\
{ "atari_font_monochrom", OPTION_INTEGER, &nsoptions.atari_font_monochrom },\
{ "atari_image_toolbar", OPTION_INTEGER, &nsoptions.atari_image_toolbar },\
diff --git a/atari/plot.c b/atari/plot.c
deleted file mode 100755
index 861460f49..000000000
--- a/atari/plot.c
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * Copyright 2010 Ole Loots <ole@monochrom.net>
- *
- * 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/>.
- */
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <limits.h>
-#include <math.h>
-#include <stdbool.h>
-#include <windom.h>
-
-#include "image/bitmap.h"
-#include "utils/log.h"
-#include "utils/utf8.h"
-#include "utils/utils.h"
-#include "desktop/gui.h"
-#include "desktop/plotters.h"
-
-#include "atari/bitmap.h"
-#include "atari/gui.h"
-#include "atari/plot.h"
-#include "desktop/options.h"
-#include "atari/plot.h"
-
-GEM_PLOTTER plotter = NULL;
-GEM_FONT_PLOTTER fplotter = NULL;
-
-extern short vdih;
-
-/*
-Init screen and font driver objects.
-Returns non-zero value > -1 when the objects could be succesfully created.
-Returns value < 0 to indicate an error
-*/
-
-int atari_plotter_init( char* drvrname, char * fdrvrname )
-{
- GRECT loc_pos={0,0,360,400};
- int err=0;
- struct s_driver_table_entry * drvinfo;
- int flags = 0;
- unsigned long font_flags = 0;
-
- if( nsoption_int(atari_dither) == 1)
- flags |= PLOT_FLAG_DITHER;
- if( nsoption_int(atari_transparency) == 1 )
- flags |= PLOT_FLAG_TRANS;
- if( nsoption_int(atari_font_monochrom) == 1 )
- font_flags |= FONTPLOT_FLAG_MONOGLYPH;
-
- vdih = app.graf.handle;
- if( verbose_log ) {
- dump_vdi_info( vdih ) ;
- dump_plot_drivers();
- dump_font_drivers();
- }
- drvinfo = get_screen_driver_entry( drvrname );
-
- LOG(("using plotters: %s, %s", drvrname, fdrvrname));
- fplotter = new_font_plotter(vdih, fdrvrname, font_flags, &err );
- if(err){
- const char * desc = plotter_err_str(err);
- die(("Unable to load font plotter %s -> %s", fdrvrname, desc ));
- }
-
- plotter = new_plotter( vdih, drvrname, &loc_pos, drvinfo->max_bpp,
- flags, fplotter, &err );
- if(err){
- const char * desc = plotter_err_str(err);
- die(("Unable to load graphics plotter %s -> %s", drvrname, desc ));
- }
-
- return( err );
-}
-
-int atari_plotter_finalise( void )
-{
- delete_plotter( plotter );
- delete_font_plotter( fplotter );
-}
-
-bool plot_rectangle( int x0, int y0, int x1, int y1,
- const plot_style_t *style )
-{
- plotter->rectangle( plotter, x0, y0, x1, y1, style );
- return ( true );
-}
-
-bool plot_line( int x0, int y0, int x1, int y1,
- const plot_style_t *style )
-{
- plotter->line( plotter, x0, y0, x1, y1, style );
- return ( true );
-}
-
-static bool plot_polygon(const int *p, unsigned int n,
- const plot_style_t *style)
-{
- plotter->polygon( plotter, p, n, style );
- return ( true );
-}
-
-bool plot_set_dimensions( int x, int y, int w, int h )
-{
- plotter->resize( plotter, w, h );
- plotter->move( plotter, x, y );
-}
-
-bool plot_clip(const struct rect *clip)
-{
- plotter->set_clip( plotter, clip );
- return ( true );
-}
-
-
-bool plot_get_clip(struct rect * out)
-{
- plotter->get_clip( plotter, out );
- return( true );
-}
-
-
-static bool plot_text(int x, int y, const char *text, size_t length, const plot_font_style_t *fstyle )
-{
- plotter->text( plotter, x, y, text, length, fstyle );
- return ( true );
-}
-
-static bool plot_disc(int x, int y, int radius, const plot_style_t *style)
-{
- plotter->disc(plotter, x, y, radius, style );
- return ( true );
-}
-
-static bool plot_arc(int x, int y, int radius, int angle1, int angle2,
- const plot_style_t *style)
-{
- plotter->arc( plotter, x, y, radius, angle1, angle2, style );
- return ( true );
-}
-
-static bool plot_bitmap(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg,
- bitmap_flags_t flags)
-{
- struct bitmap * bm = NULL;
- bool repeat_x = (flags & BITMAPF_REPEAT_X);
- bool repeat_y = (flags & BITMAPF_REPEAT_Y);
- int bmpw,bmph;
- struct rect clip;
-
- bmpw = bitmap_get_width(bitmap);
- bmph = bitmap_get_height(bitmap);
-
- if ( repeat_x || repeat_y ) {
- plotter->get_clip( plotter, &clip );
- if( repeat_x && width == 1 && repeat_y && height == 1 ){
- width = MAX( width, clip.x1 - x );
- height = MAX( height, clip.y1 - y );
- }
- else if( repeat_x && width == 1 ){
- width = MAX( width, clip.x1 - x);
- }
- else if( repeat_y && height == 1){
- height = MAX( height, clip.y1 - y );
- }
- }
-
- if( width != bmpw || height != bmph ) {
- plotter->bitmap_resize(plotter, bitmap, width, height );
- if( bitmap->resized )
- bm = bitmap->resized;
- else
- bm = bitmap;
- } else {
- bm = bitmap;
- }
-
- /* out of memory? */
- if( bm == NULL ) {
- printf("plot: out of memory! bmp: %p, bmpres: %p\n", bitmap, bitmap->resized );
- return( true );
- }
-
- if (!(repeat_x || repeat_y) ) {
- plotter->bitmap( plotter, bm, x, y, bg, flags );
- } else {
- int xf,yf;
- int xoff = x;
- int yoff = y;
-
- if (yoff > clip.y0 )
- yoff = (clip.y0 - height) + ((yoff - clip.y0) % height);
- if (xoff > clip.x0 )
- xoff = (clip.x0 - width) + ((xoff - clip.x0) % width);
- /* for now, repeating just works in the rigth / down direction */
- /*
- if( repeat_x == true )
- xoff = clip.x0;
- if(repeat_y == true )
- yoff = clip.y0;
- */
-
- for( xf = xoff; xf < clip.x1; xf += width ) {
- for( yf = yoff; yf < clip.y1; yf += height ) {
- plotter->bitmap( plotter, bm, xf, yf, bg, flags );
- if (!repeat_y)
- break;
- }
- if (!repeat_x)
- break;
- }
- }
- return ( true );
-}
-
-static bool plot_path(const float *p, unsigned int n, colour fill, float width,
- colour c, const float transform[6])
-{
- plotter->path( plotter, p, n, fill, width, c, transform );
- return ( true );
-}
-
-
-
-const struct plotter_table atari_plotters = {
- .rectangle = plot_rectangle,
- .line = plot_line,
- .polygon = plot_polygon,
- .clip = plot_clip,
- .text = plot_text,
- .disc = plot_disc,
- .arc = plot_arc,
- .bitmap = plot_bitmap,
- .path = plot_path,
- .flush = NULL,
- .group_start = NULL,
- .group_end = NULL,
- .option_knockout = true
-};
diff --git a/atari/plot.h b/atari/plot.h
deleted file mode 100755
index b3f93b219..000000000
--- a/atari/plot.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2010 Ole Loots <ole@monochrom.net>
- *
- * 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/>.
- */
-
-#ifndef NS_ATARI_PLOT_H
-#define NS_ATARI_PLOT_H
-
-#include "desktop/plotters.h"
-#include "atari/plot/plotter.h"
-
-struct rect;
-
-extern const struct plotter_table atari_plotters;
-
-int atari_plotter_init( char*, char * );
-int atari_plotter_finalise( void );
-bool plot_set_dimensions( int x, int y, int w, int h );
-bool plot_get_clip(struct rect * out);
-bool plot_clip(const struct rect *clip);
-bool plot_rectangle( int x0, int y0, int x1, int y1,const plot_style_t *style );
-bool plot_line( int x0, int y0, int x1, int y1, const plot_style_t *style );
-
-#endif
diff --git a/atari/plot/font_freetype.c b/atari/plot/font_freetype.c
index 355809346..4717fdee9 100755
--- a/atari/plot/font_freetype.c
+++ b/atari/plot/font_freetype.c
@@ -20,12 +20,16 @@
#ifdef WITH_FREETYPE_FONT_DRIVER
#include <ft2build.h>
#include FT_CACHE_H
-
-#include "atari/plot/plotter.h"
+
+#include "desktop/options.h"
+#include "atari/plot/plot.h"
#include "atari/plot/font_freetype.h"
#define DEJAVU_PATH "/usr/share/fonts/truetype/ttf-dejavu/"
+
+extern unsigned long atari_plot_flags;
+extern int atari_plot_vdi_handle;
static FT_Library library;
static FTC_Manager ft_cmanager;
@@ -395,7 +399,7 @@ static void draw_glyph8(FONT_PLOTTER self, GRECT * clip, GRECT * loc, uint8_t *
h = loc->g_h;
w = loc->g_w;
-
+
assert( h <= fontbmp_allocated_height );
assert( w <= fontbmp_allocated_width );
@@ -408,7 +412,7 @@ static void draw_glyph8(FONT_PLOTTER self, GRECT * clip, GRECT * loc, uint8_t *
linebuf[xloop] = (uint32_t)(colour | fontpix);
}
}
- self->plotter->bitmap( self->plotter, fontbmp, loc->g_x, loc->g_y, 0, BITMAPF_MONOGLYPH);
+ plot_blit_bitmap(fontbmp, loc->g_x, loc->g_y, 0, BITMAPF_MONOGLYPH);
}
static void draw_glyph1(FONT_PLOTTER self, GRECT * clip, GRECT * loc, uint8_t * pixdata, int pitch, uint32_t colour)
@@ -464,10 +468,10 @@ static void draw_glyph1(FONT_PLOTTER self, GRECT * clip, GRECT * loc, uint8_t *
#ifdef WITH_8BPP_SUPPORT
if( app.nplanes > 8 ){
#endif
- self->plotter->plot_mfdb( self->plotter, loc, &tmp, OFFSET_CUSTOM_COLOR, PLOT_FLAG_TRANS );
+ plot_blit_mfdb(loc, &tmp, OFFSET_CUSTOM_COLOR, PLOT_FLAG_TRANS );
#ifdef WITH_8BPP_SUPPORT
} else {
- self->plotter->plot_mfdb( self->plotter, loc, &tmp, colour, PLOT_FLAG_TRANS );
+ plot_blit_mfdb(loc, &tmp, colour, PLOT_FLAG_TRANS );
}
#endif
@@ -493,7 +497,7 @@ static int text( FONT_PLOTTER self, int x, int y, const char *text, size_t leng
#endif
unsigned short out[4];
rgb_to_vdi1000( (unsigned char*)&c, (unsigned short*)&out );
- vs_color( self->plotter->vdi_handle, OFFSET_CUSTOM_COLOR, (unsigned short*)&out[0] );
+ vs_color(atari_plot_vdi_handle, OFFSET_CUSTOM_COLOR, (unsigned short*)&out[0]);
#ifdef WITH_8BPP_SUPPORT
} else {
c = RGB_TO_VDI(c);
@@ -501,7 +505,7 @@ static int text( FONT_PLOTTER self, int x, int y, const char *text, size_t leng
#endif
}
- self->plotter->get_clip( self->plotter, &clipping );
+ plot_get_clip(&clipping);
clip.g_x = clipping.x0;
clip.g_y = clipping.y0;
clip.g_w = (clipping.x1 - clipping.x0)+1;
diff --git a/atari/plot/font_internal.c b/atari/plot/font_internal.c
index e8ddc5ae1..4edec4565 100644
--- a/atari/plot/font_internal.c
+++ b/atari/plot/font_internal.c
@@ -17,15 +17,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifdef WITH_INTERNAL_FONT_DRIVER
-#include "atari/plot/plotter.h"
+#ifdef WITH_INTERNAL_FONT_DRIVER
+
+#include "atari/plot/plot.h"
+#include "atari/plot/fontplot.h"
#include "atari/plot/font_internal.h"
#include "utils/utf8.h"
#include "utils/log.h"
#include <windom.h>
-
+
+extern unsigned long atari_plot_flags;
+extern int atari_plot_vdi_handle;
static int dtor( FONT_PLOTTER self );
static int str_width( FONT_PLOTTER self,const plot_font_style_t *fstyle, const char * str, size_t length, int * width );
@@ -162,7 +166,7 @@ static void draw_glyph1(FONT_PLOTTER self, GRECT *inloc, uint8_t *chrp, int pitc
pixmask = (pixmask << 1);
}
}
- self->plotter->bitmap( self->plotter, fontbmp, loc.g_x, loc.g_y, 0, BITMAPF_MONOGLYPH );
+ plot_blit_bitmap(fontbmp, loc.g_x, loc.g_y, 0, BITMAPF_MONOGLYPH );
}
static int text( FONT_PLOTTER self, int x, int y, const char *text, size_t length,
@@ -192,7 +196,7 @@ static int text( FONT_PLOTTER self, int x, int y, const char *text, size_t leng
return( 1 );
}
- if( self->plotter->flags & PLOT_FLAG_OFFSCREEN ){
+ if(atari_plot_flags & PLOT_FLAG_OFFSCREEN ){
/* when the plotter is an offscreen plotter the call to
bitmap() isn't that expensive. Draw an 8 bit bitmap into the
offscreen buffer.
@@ -245,12 +249,12 @@ static int text( FONT_PLOTTER self, int x, int y, const char *text, size_t leng
#endif
unsigned short out[4];
rgb_to_vdi1000( (unsigned char*)&fstyle->foreground, (unsigned short*)&out );
- vs_color( self->plotter->vdi_handle, OFFSET_CUSTOM_COLOR, (unsigned short*)&out[0] );
- self->plotter->plot_mfdb( self->plotter, &loc, &tmp, OFFSET_CUSTOM_COLOR, PLOT_FLAG_TRANS );
+ vs_color(atari_plot_vdi_handle, OFFSET_CUSTOM_COLOR, (unsigned short*)&out[0] );
+ plot_blit_mfdb(&loc, &tmp, OFFSET_CUSTOM_COLOR, PLOT_FLAG_TRANS );
#ifdef WITH_8BPP_SUPPORT
} else {
unsigned char c = RGB_TO_VDI(fstyle->foreground);
- self->plotter->plot_mfdb( self->plotter, &loc, &tmp, c, PLOT_FLAG_TRANS );
+ plot_blit_mfdb(&loc, &tmp, c, PLOT_FLAG_TRANS );
}
#endif
}
diff --git a/atari/plot/font_internal.h b/atari/plot/font_internal.h
index b5de3c2cc..628a63cdc 100644
--- a/atari/plot/font_internal.h
+++ b/atari/plot/font_internal.h
@@ -18,7 +18,9 @@
*/
#ifdef WITH_INTERNAL_FONT_DRIVER
#ifndef FONT_PLOTTER_INTERNAL
-#define FONT_PLOTTER_INTERNAL
+#define FONT_PLOTTER_INTERNAL
+
+#include "atari/plot/plot.h"
int ctor_font_plotter_internal( FONT_PLOTTER self );
diff --git a/atari/plot/font_vdi.c b/atari/plot/font_vdi.c
index 56afab569..89596b38a 100755
--- a/atari/plot/font_vdi.c
+++ b/atari/plot/font_vdi.c
@@ -17,7 +17,7 @@
*/
#ifdef WITH_VDI_FONT_DRIVER
-#include "atari/plot/plotter.h"
+#include "atari/plot/plot.h"
#include "atari/plot/font_vdi.h"
#include "utils/utf8.h"
diff --git a/atari/plot/fontplot.c b/atari/plot/fontplot.c
new file mode 100644
index 000000000..ba4e26776
--- /dev/null
+++ b/atari/plot/fontplot.c
@@ -0,0 +1,88 @@
+#include "atari/plot/fontplot.h"
+
+const struct s_font_driver_table_entry font_driver_table[] =
+{
+#ifdef WITH_VDI_FONT_DRIVER
+ {"vdi", ctor_font_plotter_vdi, 0},
+#endif
+#ifdef WITH_FREETYPE_FONT_DRIVER
+ {"freetype", ctor_font_plotter_freetype, 0},
+#endif
+#ifdef WITH_INTERNAL_FONT_DRIVER
+ {"internal", ctor_font_plotter_internal, 0},
+#endif
+ {(char*)NULL, NULL, 0}
+};
+
+void dump_font_drivers(void)
+{
+ int i = 0;
+ while( font_driver_table[i].name != NULL ) {
+ printf("%s -> flags: %d\n",
+ font_driver_table[i].name,
+ font_driver_table[i].flags
+ );
+ i++;
+ }
+}
+
+
+/*
+ Create an new text plotter object
+*/
+FONT_PLOTTER new_font_plotter( int vdihandle, char * name, unsigned long flags,
+ int * error)
+{
+ int i=0;
+ int res = 0-ERR_PLOTTER_NOT_AVAILABLE;
+ FONT_PLOTTER fplotter = (FONT_PLOTTER)malloc( sizeof(struct s_font_plotter) );
+ if( fplotter == NULL ) {
+ *error = 0-ERR_NO_MEM;
+ return( NULL );
+ }
+ memset( fplotter, 0, sizeof(FONT_PLOTTER));
+ fplotter->vdi_handle = vdihandle;
+ fplotter->name = name;
+ fplotter->flags = 0;
+ fplotter->flags |= flags;
+ for( i = 0; ; i++) {
+ if( font_driver_table[i].name == NULL ) {
+ res = 0-ERR_PLOTTER_NOT_AVAILABLE;
+ break;
+ } else {
+ if( strcmp(name, font_driver_table[i].name) == 0 ) {
+ if( font_driver_table[i].ctor ) {
+ res = font_driver_table[i].ctor( fplotter );
+ *error = 0;
+ } else {
+ res = 0-ERR_PLOTTER_NOT_AVAILABLE;
+ *error = res;
+ return (NULL);
+ }
+ break;
+ }
+ }
+ }
+ if( res < 0 ) {
+ free( fplotter );
+ *error = res;
+ return( NULL );
+ }
+ return( fplotter );
+}
+
+/*
+ Free an font plotter
+*/
+int delete_font_plotter(FONT_PLOTTER p)
+{
+ if( p ) {
+ p->dtor(p);
+ free( p );
+ p = NULL;
+ }
+ else
+ return( -1 );
+ return( 0 );
+}
+
diff --git a/atari/plot/fontplot.h b/atari/plot/fontplot.h
new file mode 100644
index 000000000..e4286a961
--- /dev/null
+++ b/atari/plot/fontplot.h
@@ -0,0 +1,79 @@
+#ifndef FONT_PLOT_H
+#define FONT_PLOT_H
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <math.h>
+#include <assert.h>
+#include <string.h>
+
+#include "desktop/plot_style.h"
+#include "image/bitmap.h"
+#include "utils/log.h"
+#include "atari/bitmap.h"
+#include "atari/plot/eddi.h"
+#include "atari/gui.h"
+#include "atari/misc.h"
+#include "atari/osspec.h"
+
+typedef struct s_font_plotter * FONT_PLOTTER;
+
+struct s_font_driver_table_entry
+{
+ const char * name;
+ int (*ctor)( FONT_PLOTTER self );
+ int flags;
+};
+
+/* declaration of font plotter member functions: (_fpmf_ prefix) */
+typedef int (*_fpmf_str_width)( FONT_PLOTTER self, const plot_font_style_t *fstyle,
+ const char * str, size_t length, int * width);
+typedef int (*_fpmf_str_split)( FONT_PLOTTER self, const plot_font_style_t *fstyle,
+ const char *string, size_t length,
+ int x, size_t *char_offset, int *actual_x);
+typedef int (*_fpmf_pixel_pos)( FONT_PLOTTER self, const plot_font_style_t *fstyle,
+ const char *string, size_t length,
+ int x, size_t *char_offset, int *actual_x);
+typedef int (*_fpmf_text)( FONT_PLOTTER self, int x, int y, const char *text,
+ size_t length, const plot_font_style_t *fstyle);
+
+typedef void (*_fpmf_draw_glyph)(FONT_PLOTTER self, GRECT * clip, GRECT * loc,
+ uint8_t * pixdata, int pitch, uint32_t colour);
+typedef int (*_fpmf_dtor)( FONT_PLOTTER self );
+
+
+/* prototype of the font plotter "object" */
+struct s_font_plotter
+{
+ char * name;
+ int flags;
+ int vdi_handle;
+ void * priv_data;
+
+ _fpmf_str_width str_width;
+ _fpmf_str_split str_split;
+ _fpmf_pixel_pos pixel_pos;
+ _fpmf_text text;
+ _fpmf_draw_glyph draw_glyph;
+ _fpmf_dtor dtor;
+};
+
+
+void dump_font_drivers(void);
+FONT_PLOTTER new_font_plotter( int vdihandle, char * name, unsigned long flags,
+ int * error);
+int delete_font_plotter( FONT_PLOTTER p );
+#ifdef WITH_VDI_FONT_DRIVER
+ #include "atari/plot/font_vdi.h"
+#endif
+#ifdef WITH_INTERNAL_FONT_DRIVER
+ #include "atari/plot/font_internal.h"
+#endif
+#ifdef WITH_FREETYPE_FONT_DRIVER
+ #include "atari/plot/font_freetype.h"
+#endif
+
+
+
+#endif
diff --git a/atari/plot/plot.c b/atari/plot/plot.c
new file mode 100755
index 000000000..458e3dd8a
--- /dev/null
+++ b/atari/plot/plot.c
@@ -0,0 +1,2068 @@
+/*
+ * Copyright 2010 Ole Loots <ole@monochrom.net>
+ *
+ * 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/>.
+ */
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <string.h>
+#include <limits.h>
+#include <math.h>
+#include <stdbool.h>
+#include <windom.h>
+
+#include "image/bitmap.h"
+#include "utils/log.h"
+#include "utils/utf8.h"
+#include "utils/utils.h"
+#include "desktop/gui.h"
+#include "desktop/plotters.h"
+
+#include "atari/bitmap.h"
+#include "atari/gui.h"
+#include "desktop/options.h"
+#include "atari/plot/plot.h"
+
+struct s_view {
+ short x; /* drawing (screen) offset x */
+ short y; /* drawing (screen) offset y */
+ short w; /* width of buffer, not in sync with vis_w */
+ short h; /* height of buffer, not in sync with vis_w */
+ short vis_x; /* visible rectangle of the screen buffer */
+ short vis_y; /* coords are relative to plot location */
+ short vis_w; /* clipped to screen dimensions */
+ short vis_h; /* visible width */
+ struct rect clipping; /* clipping rectangle */
+};
+
+
+#ifdef WITH_8BPP_SUPPORT
+static unsigned short sys_pal[256][3]; /*RGB*/
+static unsigned short pal[256][3]; /*RGB*/
+static char rgb_lookup[256][4];
+short web_std_colors[6] = {0, 51, 102, 153, 204, 255};
+
+unsigned short vdi_web_pal[216][3] = {
+ {0x000,0x000,0x000}, {0x0c8,0x000,0x000}, {0x190,0x000,0x000}, {0x258,0x000,0x000}, {0x320,0x000,0x000}, {0x3e8,0x000,0x000},
+ {0x000,0x0c8,0x000}, {0x0c8,0x0c8,0x000}, {0x190,0x0c8,0x000}, {0x258,0x0c8,0x000}, {0x320,0x0c8,0x000}, {0x3e8,0x0c8,0x000},
+ {0x000,0x190,0x000}, {0x0c8,0x190,0x000}, {0x190,0x190,0x000}, {0x258,0x190,0x000}, {0x320,0x190,0x000}, {0x3e8,0x190,0x000},
+ {0x000,0x258,0x000}, {0x0c8,0x258,0x000}, {0x190,0x258,0x000}, {0x258,0x258,0x000}, {0x320,0x258,0x000}, {0x3e8,0x258,0x000},
+ {0x000,0x320,0x000}, {0x0c8,0x320,0x000}, {0x190,0x320,0x000}, {0x258,0x320,0x000}, {0x320,0x320,0x000}, {0x3e8,0x320,0x000},
+ {0x000,0x3e8,0x000}, {0x0c8,0x3e8,0x000}, {0x190,0x3e8,0x000}, {0x258,0x3e8,0x000}, {0x320,0x3e8,0x000}, {0x3e8,0x3e8,0x000},
+ {0x000,0x000,0x0c8}, {0x0c8,0x000,0x0c8}, {0x190,0x000,0x0c8}, {0x258,0x000,0x0c8}, {0x320,0x000,0x0c8}, {0x3e8,0x000,0x0c8},
+ {0x000,0x0c8,0x0c8}, {0x0c8,0x0c8,0x0c8}, {0x190,0x0c8,0x0c8}, {0x258,0x0c8,0x0c8}, {0x320,0x0c8,0x0c8}, {0x3e8,0x0c8,0x0c8},
+ {0x000,0x190,0x0c8}, {0x0c8,0x190,0x0c8}, {0x190,0x190,0x0c8}, {0x258,0x190,0x0c8}, {0x320,0x190,0x0c8}, {0x3e8,0x190,0x0c8},
+ {0x000,0x258,0x0c8}, {0x0c8,0x258,0x0c8}, {0x190,0x258,0x0c8}, {0x258,0x258,0x0c8}, {0x320,0x258,0x0c8}, {0x3e8,0x258,0x0c8},
+ {0x000,0x320,0x0c8}, {0x0c8,0x320,0x0c8}, {0x190,0x320,0x0c8}, {0x258,0x320,0x0c8}, {0x320,0x320,0x0c8}, {0x3e8,0x320,0x0c8},
+ {0x000,0x3e8,0x0c8}, {0x0c8,0x3e8,0x0c8}, {0x190,0x3e8,0x0c8}, {0x258,0x3e8,0x0c8}, {0x320,0x3e8,0x0c8}, {0x3e8,0x3e8,0x0c8},
+ {0x000,0x000,0x190}, {0x0c8,0x000,0x190}, {0x190,0x000,0x190}, {0x258,0x000,0x190}, {0x320,0x000,0x190}, {0x3e8,0x000,0x190},
+ {0x000,0x0c8,0x190}, {0x0c8,0x0c8,0x190}, {0x190,0x0c8,0x190}, {0x258,0x0c8,0x190}, {0x320,0x0c8,0x190}, {0x3e8,0x0c8,0x190},
+ {0x000,0x190,0x190}, {0x0c8,0x190,0x190}, {0x190,0x190,0x190}, {0x258,0x190,0x190}, {0x320,0x190,0x190}, {0x3e8,0x190,0x190},
+ {0x000,0x258,0x190}, {0x0c8,0x258,0x190}, {0x190,0x258,0x190}, {0x258,0x258,0x190}, {0x320,0x258,0x190}, {0x3e8,0x258,0x190},
+ {0x000,0x320,0x190}, {0x0c8,0x320,0x190}, {0x190,0x320,0x190}, {0x258,0x320,0x190}, {0x320,0x320,0x190}, {0x3e8,0x320,0x190},
+ {0x000,0x3e8,0x190}, {0x0c8,0x3e8,0x190}, {0x190,0x3e8,0x190}, {0x258,0x3e8,0x190}, {0x320,0x3e8,0x190}, {0x3e8,0x3e8,0x190},
+ {0x000,0x000,0x258}, {0x0c8,0x000,0x258}, {0x190,0x000,0x258}, {0x258,0x000,0x258}, {0x320,0x000,0x258}, {0x3e8,0x000,0x258},
+ {0x000,0x0c8,0x258}, {0x0c8,0x0c8,0x258}, {0x190,0x0c8,0x258}, {0x258,0x0c8,0x258}, {0x320,0x0c8,0x258}, {0x3e8,0x0c8,0x258},
+ {0x000,0x190,0x258}, {0x0c8,0x190,0x258}, {0x190,0x190,0x258}, {0x258,0x190,0x258}, {0x320,0x190,0x258}, {0x3e8,0x190,0x258},
+ {0x000,0x258,0x258}, {0x0c8,0x258,0x258}, {0x190,0x258,0x258}, {0x258,0x258,0x258}, {0x320,0x258,0x258}, {0x3e8,0x258,0x258},
+ {0x000,0x320,0x258}, {0x0c8,0x320,0x258}, {0x190,0x320,0x258}, {0x258,0x320,0x258}, {0x320,0x320,0x258}, {0x3e8,0x320,0x258},
+ {0x000,0x3e8,0x258}, {0x0c8,0x3e8,0x258}, {0x190,0x3e8,0x258}, {0x258,0x3e8,0x258}, {0x320,0x3e8,0x258}, {0x3e8,0x3e8,0x258},
+ {0x000,0x000,0x320}, {0x0c8,0x000,0x320}, {0x190,0x000,0x320}, {0x258,0x000,0x320}, {0x320,0x000,0x320}, {0x3e8,0x000,0x320},
+ {0x000,0x0c8,0x320}, {0x0c8,0x0c8,0x320}, {0x190,0x0c8,0x320}, {0x258,0x0c8,0x320}, {0x320,0x0c8,0x320}, {0x3e8,0x0c8,0x320},
+ {0x000,0x190,0x320}, {0x0c8,0x190,0x320}, {0x190,0x190,0x320}, {0x258,0x190,0x320}, {0x320,0x190,0x320}, {0x3e8,0x190,0x320},
+ {0x000,0x258,0x320}, {0x0c8,0x258,0x320}, {0x190,0x258,0x320}, {0x258,0x258,0x320}, {0x320,0x258,0x320}, {0x3e8,0x258,0x320},
+ {0x000,0x320,0x320}, {0x0c8,0x320,0x320}, {0x190,0x320,0x320}, {0x258,0x320,0x320}, {0x320,0x320,0x320}, {0x3e8,0x320,0x320},
+ {0x000,0x3e8,0x320}, {0x0c8,0x3e8,0x320}, {0x190,0x3e8,0x320}, {0x258,0x3e8,0x320}, {0x320,0x3e8,0x320}, {0x3e8,0x3e8,0x320},
+ {0x000,0x000,0x3e8}, {0x0c8,0x000,0x3e8}, {0x190,0x000,0x3e8}, {0x258,0x000,0x3e8}, {0x320,0x000,0x3e8}, {0x3e8,0x000,0x3e8},
+ {0x000,0x0c8,0x3e8}, {0x0c8,0x0c8,0x3e8}, {0x190,0x0c8,0x3e8}, {0x258,0x0c8,0x3e8}, {0x320,0x0c8,0x3e8}, {0x3e8,0x0c8,0x3e8},
+ {0x000,0x190,0x3e8}, {0x0c8,0x190,0x3e8}, {0x190,0x190,0x3e8}, {0x258,0x190,0x3e8}, {0x320,0x190,0x3e8}, {0x3e8,0x190,0x3e8},
+ {0x000,0x258,0x3e8}, {0x0c8,0x258,0x3e8}, {0x190,0x258,0x3e8}, {0x258,0x258,0x3e8}, {0x320,0x258,0x3e8}, {0x3e8,0x258,0x3e8},
+ {0x000,0x320,0x3e8}, {0x0c8,0x320,0x3e8}, {0x190,0x320,0x3e8}, {0x258,0x320,0x3e8}, {0x320,0x320,0x3e8}, {0x3e8,0x320,0x3e8},
+ {0x000,0x3e8,0x3e8}, {0x0c8,0x3e8,0x3e8}, {0x190,0x3e8,0x3e8}, {0x258,0x3e8,0x3e8}, {0x320,0x3e8,0x3e8}, {0x3e8,0x3e8,0x3e8}
+};
+#endif
+
+/* Error code translations: */
+static const char * plot_error_codes[] = {
+ "None",
+ "ERR_BUFFERSIZE_EXCEEDS_SCREEN",
+ "ERR_NO_MEM",
+ "ERR_PLOTTER_NOT_AVAILABLE"
+};
+
+FONT_PLOTTER fplotter = NULL;
+
+extern short vdih;
+
+/* temp buffer for bitmap conversion: */
+static void * buf_packed;
+static int size_buf_packed;
+
+/* temp buffer for bitmap conversion: */
+void * buf_planar;
+int size_buf_planar;
+
+/* buffer for plot operations that require device format, */
+/* currently used for transparent mfdb blits and snapshots: */
+static MFDB buf_scr;
+static int size_buf_scr;
+
+/* buffer for std form, used during 8bpp snapshot */
+MFDB buf_std;
+int size_buf_std;
+
+struct bitmap * buf_scr_compat;
+
+/* intermediate bitmap format */
+static HermesFormat vfmt;
+
+/* no screen format here, hermes may not suitable for it */
+
+/* netsurf source bitmap format */
+static HermesFormat nsfmt;
+
+static struct s_vdi_sysinfo vdi_sysinfo;
+/* bit depth of framebuffers: */
+static int atari_plot_bpp_virt;
+static struct s_view view;
+
+static HermesHandle hermes_pal_h; /* hermes palette handle */
+static HermesHandle hermes_cnv_h; /* hermes converter instance handle */
+static HermesHandle hermes_res_h;
+
+static short prev_vdi_clip[4];
+static struct bitmap snapshot;
+
+int atari_plot_vdi_handle;
+unsigned long atari_plot_flags;
+unsigned long atari_font_flags;
+
+typedef bool (*bitmap_convert_fnc)( struct bitmap * img, int x, int y,
+ GRECT * clip, uint32_t bg, uint32_t flags, MFDB *out );
+static bitmap_convert_fnc bitmap_convert;
+
+const char* plot_err_str(int i)
+{
+ return(plot_error_codes[abs(i)]);
+}
+
+
+static inline void vsl_rgbcolor(short vdih, uint32_t cin)
+{
+ #ifdef WITH_8BPP_SUPPORT
+ if( vdi_sysinfo.scr_bpp > 8 ) {
+ #endif
+ unsigned short c[4];
+ rgb_to_vdi1000( (unsigned char*)&cin, (unsigned short*)&c);
+ vs_color(vdih, OFFSET_CUSTOM_COLOR, (unsigned short*)&c[0]);
+ vsl_color(vdih, OFFSET_CUSTOM_COLOR);
+ #ifdef WITH_8BPP_SUPPORT
+ } else {
+ if( vdi_sysinfo.scr_bpp >= 4 ){
+ vsl_color(vdih, RGB_TO_VDI(cin));
+ }
+ else
+ vsl_color(vdih, BLACK);
+ }
+ #endif
+}
+
+static inline void vsf_rgbcolor(short vdih, uint32_t cin)
+{
+ #ifdef WITH_8BPP_SUPPORT
+ if( vdi_sysinfo.scr_bpp > 8 ) {
+ #endif
+ unsigned short c[4];
+ rgb_to_vdi1000( (unsigned char*)&cin, (unsigned short*)&c );
+ vs_color( vdih, OFFSET_CUSTOM_COLOR, &c[0] );
+ vsf_color( vdih, OFFSET_CUSTOM_COLOR );
+ #ifdef WITH_8BPP_SUPPORT
+ } else {
+ if( vdi_sysinfo.scr_bpp >= 4 ){
+ vsf_color( vdih, RGB_TO_VDI(cin) );
+ }
+ else
+ vsf_color( vdih, WHITE );
+ }
+ #endif
+}
+
+
+
+/*
+ Get current visible coords
+*/
+static inline void plotter_get_visible_grect(GRECT * out)
+{
+ out->g_x = view.vis_x;
+ out->g_y = view.vis_y;
+ out->g_w = view.vis_w;
+ out->g_h = view.vis_h;
+}
+
+
+
+/* calculate visible area of framebuffer in coords relative to framebuffer */
+/* position */
+/* result: */
+/* this function should calculates an rectangle relative to the plot origin*/
+/* and size. */
+/* If the ploter coords do not fall within the screen region, */
+/* all values of the region are set to zero. */
+static inline void update_visible_rect(void)
+{
+ GRECT screen;
+ GRECT common;
+ GRECT frame;
+
+ screen.g_x = 0;
+ screen.g_y = 0;
+ screen.g_w = vdi_sysinfo.scr_w;
+ screen.g_h = vdi_sysinfo.scr_h;
+
+ common.g_x = frame.g_x = view.x;
+ common.g_y = frame.g_y = view.y;
+ common.g_w = frame.g_w = view.w;
+ common.g_h = frame.g_h = view.h;
+
+ if( rc_intersect( &screen, &common ) ) {
+ view.vis_w = common.g_w;
+ view.vis_h = common.g_h;
+ if( view.x < screen.g_x )
+ view.vis_x = frame.g_w - common.g_w;
+ else
+ view.vis_x = 0;
+ if( view.y <screen.g_y )
+ view.vis_y = frame.g_h - common.g_h;
+ else
+ view.vis_y = 0;
+ } else {
+ view.vis_w = view.vis_h = 0;
+ view.vis_x = view.vis_y = 0;
+ }
+}
+
+/* Returns the visible parts of the box (relative coords within framebuffer),*/
+/* relative to screen coords (normally starting at 0,0 ) */
+static inline bool fbrect_to_screen(GRECT box, GRECT * ret)
+{
+ GRECT out, vis, screen;
+
+ screen.g_x = 0;
+ screen.g_y = 0;
+ screen.g_w = vdi_sysinfo.scr_w;
+ screen.g_h = vdi_sysinfo.scr_h;
+
+ /* get visible region: */
+ vis.g_x = view.x;
+ vis.g_y = view.y;
+ vis.g_w = view.w;
+ vis.g_h = view.h;
+
+ if ( !rc_intersect( &screen, &vis ) ) {
+ return( false );
+ }
+ vis.g_x = view.w - vis.g_w;
+ vis.g_y = view.h - vis.g_h;
+
+ /* clip box to visible region: */
+ if( !rc_intersect(&vis, &box) ) {
+ return( false );
+ }
+ out.g_x = box.g_x + view.x;
+ out.g_y = box.g_y + view.y;
+ out.g_w = box.g_w;
+ out.g_h = box.g_h;
+ *ret = out;
+ return ( true );
+}
+
+/* convert framebuffer clipping to vdi clipping and activates it */
+static inline void plotter_vdi_clip(bool set)
+{
+ // TODO : check this
+ return;
+ if( set == true ) {
+ struct rect c;
+ short vdiflags[58];
+ short newclip[4];
+ plot_get_clip(&c);
+ vq_extnd(atari_plot_vdi_handle, 1, (short*)&vdiflags);
+ prev_vdi_clip[0] = vdiflags[45];
+ prev_vdi_clip[1] = vdiflags[46];
+ prev_vdi_clip[2] = vdiflags[47];
+ prev_vdi_clip[3] = vdiflags[48];
+ newclip[0] = view.x + MAX(c.x0, 0);
+ newclip[1] = view.y + MAX(c.y0, 0);
+ newclip[2] = MIN(view.x+view.w, newclip[0] + (c.x1 - c.x0) )-1;
+ newclip[3] = MIN(view.y+view.h, newclip[1] + (c.y1 - c.y0) )-1;
+ vs_clip(atari_plot_vdi_handle, 1, (short*)&newclip );
+ } else {
+ vs_clip(atari_plot_vdi_handle, 1, (short *)&prev_vdi_clip );
+ }
+}
+
+
+/* copy an rectangle from the plot buffer to screen */
+/* because this is an on-screen plotter, this is an screen to screen copy. */
+bool plot_copy_rect(GRECT src, GRECT dst)
+{
+ MFDB devmf;
+ MFDB scrmf;
+ short pxy[8];
+ GRECT vis;
+
+ /* clip to visible rect, only needed for onscreen renderer: */
+ plotter_get_visible_grect(&vis );
+
+ if( !rc_intersect(&vis, &src) )
+ return(true);
+ if( !rc_intersect(&vis, &dst) )
+ return(true);
+
+ src.g_x = view.x + src.g_x;
+ src.g_y = view.y + src.g_y;
+ dst.g_x = view.x + dst.g_x;
+ dst.g_y = view.y + dst.g_y;
+
+ devmf.fd_addr = NULL;
+ devmf.fd_w = src.g_w;
+ devmf.fd_h = src.g_h;
+ devmf.fd_wdwidth = 0;
+ devmf.fd_stand = 0;
+ devmf.fd_nplanes = 0;
+ devmf.fd_r1 = devmf.fd_r2 = devmf.fd_r3 = 0;
+
+ scrmf.fd_addr = NULL;
+ scrmf.fd_w = dst.g_w;
+ scrmf.fd_h = dst.g_h;
+ scrmf.fd_wdwidth = 0 ;
+ scrmf.fd_stand = 0;
+ scrmf.fd_nplanes = 0;
+ scrmf.fd_r1 = scrmf.fd_r2 = scrmf.fd_r3 = 0;
+
+ pxy[0] = src.g_x;
+ pxy[1] = src.g_y;
+ pxy[2] = pxy[0] + src.g_w-1;
+ pxy[3] = pxy[1] + src.g_h-1;
+ pxy[4] = dst.g_x;
+ pxy[5] = dst.g_y;
+ pxy[6] = pxy[4] + dst.g_w-1;
+ pxy[7] = pxy[5] + dst.g_h-1;
+ plot_lock();
+ vro_cpyfm( atari_plot_vdi_handle, S_ONLY, (short*)&pxy, &devmf, &scrmf);
+ plot_unlock();
+
+ return(true);
+}
+
+static struct s_vdi_sysinfo * read_vdi_sysinfo(short vdih, struct s_vdi_sysinfo * info) {
+
+ unsigned long cookie_EdDI=0;
+ short out[300];
+ memset( info, 0, sizeof(struct s_vdi_sysinfo) );
+
+ info->vdi_handle = vdih;
+ if ( tos_getcookie(C_EdDI, &cookie_EdDI) == C_NOTFOUND ) {
+ info->EdDiVersion = 0;
+ } else {
+ info->EdDiVersion = EdDI_version( (void *)cookie_EdDI );
+ }
+
+ memset( &out, 0, sizeof(short)*300 );
+ vq_extnd( vdih, 0, (short*)&out );
+ info->scr_w = out[0]+1;
+ info->scr_h = out[1]+1;
+ if( out[39] == 2 ) {
+ info->scr_bpp = 1;
+ info->colors = out[39];
+ } else {
+ info->colors = out[39];
+ }
+
+ memset( &out, 0, sizeof(short)*300 );
+ vq_extnd( vdih, 1, (short*)&out );
+ info->scr_bpp = out[4];
+ info->maxpolycoords = out[14];
+ info->maxintin = out[15];
+ if( out[30] & 1 ) {
+ info->rasterscale = true;
+ } else {
+ info->rasterscale = false;
+ }
+
+ switch( info->scr_bpp ) {
+ case 8:
+ info->pixelsize=1;
+ break;
+ case 15:
+ case 16:
+ info->pixelsize=2;
+ break;
+ case 24:
+ info->pixelsize=3;
+ break;
+ case 32:
+ info->pixelsize=4;
+ break;
+ case 64:
+ info->pixelsize=8;
+ break;
+ default:
+ info->pixelsize=1;
+ break;
+
+ }
+ info->pitch = info->scr_w * info->pixelsize;
+ info->vdiformat = ( (info->scr_bpp <= 8) ? VDI_FORMAT_INTER : VDI_FORMAT_PACK);
+ info->screensize = ( info->scr_w * info->pixelsize ) * info->scr_h;
+
+ if( info->EdDiVersion >= EDDI_10 ) {
+ memset( &out, 0, sizeof(short)*300 );
+ vq_scrninfo(vdih, (short*)&out);
+ info->vdiformat = out[0];
+ info->clut = out[1];
+ info->scr_bpp = out[2];
+ info->hicolors = *((unsigned long*) &out[3]);
+ if( info->EdDiVersion >= EDDI_11 ) {
+ info->pitch = out[5];
+ info->screen = (void *) *((unsigned long *) &out[6]);
+ }
+
+ switch( info->clut ) {
+
+ case VDI_CLUT_HARDWARE: {
+
+ }
+ break;
+
+ case VDI_CLUT_SOFTWARE: {
+ int component; /* red, green, blue, alpha, overlay */
+ int num_bit;
+ unsigned short *tmp_p;
+
+ /* We can build masks with info here */
+ tmp_p = (unsigned short *) &out[16];
+ for (component=0; component<5; component++) {
+ for (num_bit=0; num_bit<16; num_bit++) {
+ unsigned short val;
+
+ val = *tmp_p++;
+
+ if (val == 0xffff) {
+ continue;
+ }
+
+ switch(component) {
+ case 0:
+ info->mask_r |= 1<< val;
+ break;
+ case 1:
+ info->mask_g |= 1<< val;
+ break;
+ case 2:
+ info->mask_b |= 1<< val;
+ break;
+ case 3:
+ info->mask_a |= 1<< val;
+ break;
+ }
+ }
+ }
+ }
+
+ /* Remove lower green bits for Intel endian screen */
+ if ((info->mask_g == ((7<<13)|3)) || (info->mask_g == ((7<<13)|7))) {
+ info->mask_g &= ~(7<<13);
+ }
+ break;
+
+ case VDI_CLUT_NONE:
+ break;
+ }
+ }
+}
+
+
+/*
+ Convert an RGB color to an VDI Color
+*/
+void rgb_to_vdi1000(unsigned char * in, unsigned short * out)
+{
+ double r = ((double)in[3]/255); /* prozentsatz red */
+ double g = ((double)in[2]/255); /* prozentsatz green */
+ double b = ((double)in[1]/255); /* prozentsatz blue */
+ out[0] = 1000 * r + 0.5;
+ out[1] = 1000 * g + 0.5;
+ out[2] = 1000 * b + 0.5;
+ return;
+}
+
+void vdi1000_to_rgb(unsigned short * in, unsigned char * out)
+{
+ double r = ((double)in[0]/1000); /* prozentsatz red */
+ double g = ((double)in[1]/1000); /* prozentsatz green */
+ double b = ((double)in[2]/1000); /* prozentsatz blue */
+ out[2] = 255 * r + 0.5;
+ out[1] = 255 * g + 0.5;
+ out[0] = 255 * b + 0.5;
+ return;
+}
+
+
+#ifdef WITH_8BPP_SUPPORT
+
+static inline void set_stdpx( MFDB * dst, int wdplanesz, int x, int y, unsigned char val )
+{
+ short * buf;
+ short whichbit = (1<<(15-(x%16)));
+
+ buf = dst->fd_addr;
+ buf += ((dst->fd_wdwidth*(y))+(x>>4));
+
+ *buf = (val&1) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
+
+ buf += wdplanesz;
+ *buf = (val&(1<<1)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
+
+ buf += wdplanesz;
+ *buf = (val&(1<<2)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
+
+ buf += wdplanesz;
+ *buf = (val&(1<<3)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
+
+ buf += wdplanesz;
+ *buf = (val&(1<<4)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
+
+ buf += wdplanesz;
+ *buf = (val&(1<<5)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
+
+ buf += wdplanesz;
+ *buf = (val&(1<<6)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
+
+ buf += wdplanesz;
+ *buf = (val&(1<<7)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
+}
+
+static inline unsigned char get_stdpx(MFDB * dst, int wdplanesz, int x, int y)
+{
+ unsigned char ret=0;
+ short * buf;
+ short whichbit = (1<<(15-(x%16)));
+
+ buf = dst->fd_addr;
+ buf += ((dst->fd_wdwidth*(y))+(x>>4));
+
+ if( *buf & whichbit )
+ ret |= 1;
+
+ buf += wdplanesz;
+ if( *buf & whichbit )
+ ret |= 2;
+
+ buf += wdplanesz;
+ if( *buf & whichbit )
+ ret |= 4;
+
+ buf += wdplanesz;
+ if( *buf & whichbit )
+ ret |= 8;
+
+ buf += wdplanesz;
+ if( *buf & whichbit )
+ ret |= 16;
+
+ buf += wdplanesz;
+ if( *buf & whichbit )
+ ret |= 32;
+
+ buf += wdplanesz;
+ if( *buf & whichbit )
+ ret |= 64;
+
+ buf += wdplanesz;
+ if( *buf & whichbit )
+ ret |= 128;
+
+ return( ret );
+}
+
+/*
+ Convert an RGB color into an index into the 216 colors web pallette
+*/
+short rgb_to_666_index(unsigned char r, unsigned char g, unsigned char b)
+{
+ short ret = 0;
+ short i;
+ unsigned char rgb[3] = {r,g,b};
+ unsigned char tval[3];
+
+ int diff_a, diff_b, diff_c;
+ diff_a = abs(r-g);
+ diff_b = abs(r-b);
+ diff_c = abs(r-b);
+ if( diff_a < 2 && diff_b < 2 && diff_c < 2 ) {
+ if( (r!=0XFF) && (g!=0XFF) && (g!=0XFF) ) {
+ if( ((r&0xF0)>>4) != 0 )
+ //printf("conv gray: %x -> %d\n", ((r&0xF0)>>4) , (OFFSET_CUST_PAL) + ((r&0xF0)>>4) );
+ return( (OFFSET_CUST_PAL - OFFSET_WEB_PAL) + ((r&0xF0)>>4) );
+ }
+ }
+
+ /* convert each 8bit color to 6bit web color: */
+ for( i=0; i<3; i++) {
+ if(0 == rgb[i] % web_std_colors[1] ) {
+ tval[i] = rgb[i] / web_std_colors[1];
+ } else {
+ int pos = ((short)rgb[i] / web_std_colors[1]);
+ if( abs(rgb[i] - web_std_colors[pos]) > abs(rgb[i] - web_std_colors[pos+1]) )
+ tval[i] = pos+1;
+ else
+ tval[i] = pos;
+ }
+ }
+ return(tval[2]*36+tval[1]*6+tval[0]);
+}
+#endif
+
+
+static void dump_vdi_info( short vdih )
+{
+ struct s_vdi_sysinfo temp;
+ read_vdi_sysinfo( vdih, &temp );
+ printf("struct s_vdi_sysinfo {\n");
+ printf(" short vdi_handle: %d\n", temp.vdi_handle);
+ printf(" short scr_w: %d \n", temp.scr_w);
+ printf(" short scr_h: %d\n", temp.scr_h);
+ printf(" short scr_bpp: %d\n", temp.scr_bpp);
+ printf(" int colors: %d\n", temp.colors);
+ printf(" ulong hicolors: %d\n", temp.hicolors);
+ printf(" short pixelsize: %d\n", temp.pixelsize);
+ printf(" unsigned short pitch: %d\n", temp.pitch);
+ printf(" unsigned short vdiformat: %d\n", temp.vdiformat);
+ printf(" unsigned short clut: %d\n", temp.clut);
+ printf(" void * screen: 0x0%p\n", temp.screen);
+ printf(" unsigned long screensize: %d\n", temp.screensize);
+ printf(" unsigned long mask_r: 0x0%08x\n", temp.mask_r);
+ printf(" unsigned long mask_g: 0x0%08x\n", temp.mask_g);
+ printf(" unsigned long mask_b: 0x0%08x\n", temp.mask_b);
+ printf(" unsigned long mask_a: 0x0%08x\n", temp.mask_a);
+ printf(" short maxintin: %d\n", temp.maxintin);
+ printf(" short maxpolycoords: %d\n", temp.maxpolycoords);
+ printf(" unsigned long EdDiVersion: 0x0%03x\n", temp.EdDiVersion);
+ printf(" unsigned short rasterscale: 0x%2x\n", temp.rasterscale);
+ printf("};\n");
+}
+
+bool plot_resize_bitmap(struct bitmap * img, int nw, int nh)
+{
+ HermesFormat fmt;
+ short bpp = bitmap_get_bpp( img );
+ int stride = bitmap_get_rowstride( img );
+ int err;
+
+ if( img->resized != NULL ) {
+ if( img->resized->width != nw || img->resized->height != nh ) {
+ bitmap_destroy( img->resized );
+ img->resized = NULL;
+ } else {
+ /* the bitmap is already resized */
+ return( 0 );
+ }
+ }
+
+ /* allocate the mem for resized bitmap */
+ img->resized = bitmap_create_ex( nw, nh, bpp, nw*bpp, 0, NULL );
+ if( img->resized == NULL ) {
+ printf("W: %d, H: %d, bpp: %d\n", nw, nh, bpp);
+ assert( img->resized );
+ return ( -ERR_NO_MEM );
+ }
+
+ /* allocate an converter, only for resizing */
+ err = Hermes_ConverterRequest( hermes_res_h,
+ &nsfmt,
+ &nsfmt
+ );
+ if( err == 0 ) {
+ return( -ERR_PLOTTER_NOT_AVAILABLE );
+ }
+
+ err = Hermes_ConverterCopy( hermes_res_h,
+ img->pixdata,
+ 0, /* x src coord of top left in pixel coords */
+ 0, /* y src coord of top left in pixel coords */
+ bitmap_get_width( img ), bitmap_get_height( img ),
+ stride, /* stride as bytes */
+ img->resized->pixdata,
+ 0, /* x dst coord of top left in pixel coords */
+ 0, /* y dst coord of top left in pixel coords */
+ nw, nh,
+ bitmap_get_rowstride(img->resized) /* stride as bytes */
+ );
+ if( err == 0 ) {
+ bitmap_destroy( img->resized );
+ img->resized = NULL;
+ return( -2 );
+ }
+
+ return( 0 );
+}
+
+// create snapshot, native screen format
+static MFDB * snapshot_create_native_mfdb(int x, int y, int w, int h)
+{
+ MFDB scr;
+ short pxy[8];
+
+ /* allocate memory for the snapshot */
+ {
+ int scr_stride = MFDB_STRIDE( w );
+ int scr_size = ( ((scr_stride >> 3) * h) * vdi_sysinfo.scr_bpp );
+ if(size_buf_scr == 0 ){
+ /* init screen mfdb */
+ buf_scr.fd_addr = malloc( scr_size );
+ size_buf_scr = scr_size;
+ } else {
+ if( scr_size >size_buf_scr ) {
+ buf_scr.fd_addr = realloc(
+ buf_scr.fd_addr, scr_size
+ );
+ size_buf_scr = scr_size;
+ }
+ }
+ if(buf_scr.fd_addr == NULL ) {
+ size_buf_scr = 0;
+ return( NULL );
+ }
+ buf_scr.fd_nplanes = vdi_sysinfo.scr_bpp;
+ buf_scr.fd_w = scr_stride;
+ buf_scr.fd_h = h;
+ buf_scr.fd_wdwidth = scr_stride >> 4;
+ assert(buf_scr.fd_addr != NULL );
+ }
+ init_mfdb( 0, w, h, 0, &scr );
+ pxy[0] = x;
+ pxy[1] = y;
+ pxy[2] = pxy[0] + w-1;
+ pxy[3] = pxy[1] + h-1;
+ pxy[4] = 0;
+ pxy[5] = 0;
+ pxy[6] = w-1;
+ pxy[7] = h-1;
+ vro_cpyfm(
+ atari_plot_vdi_handle, S_ONLY, (short*)&pxy,
+ &scr, &buf_scr
+ );
+
+ return( &buf_scr );
+}
+
+// create snapshot, vdi std. format
+static MFDB * snapshot_create_std_mfdb(int x, int y, int w, int h)
+{
+ /* allocate memory for the snapshot */
+ {
+ int scr_stride = MFDB_STRIDE( w );
+ int scr_size = ( ((scr_stride >> 3) * h) * app.nplanes );
+ if(size_buf_std == 0 ){
+ /* init screen mfdb */
+ buf_std.fd_addr = malloc( scr_size );
+ size_buf_std = scr_size;
+ } else {
+ if( scr_size >size_buf_std ) {
+ buf_std.fd_addr = realloc(
+ buf_std.fd_addr, scr_size
+ );
+ size_buf_std = scr_size;
+ }
+ }
+ if(buf_std.fd_addr == NULL ) {
+ size_buf_std = 0;
+ return( NULL );
+ }
+ buf_std.fd_nplanes = app.nplanes;
+ buf_std.fd_w = scr_stride;
+ buf_std.fd_h = h;
+ buf_std.fd_stand = 1;
+ buf_std.fd_wdwidth = scr_stride >> 4;
+ assert(buf_std.fd_addr != NULL );
+ }
+ MFDB * native = snapshot_create_native_mfdb(x,y,w,h );
+ assert( native );
+
+ vr_trnfm(atari_plot_vdi_handle, native, &buf_std );
+ return( &buf_std );
+}
+
+/*
+ This will create an snapshot of the screen in netsurf ABGR format
+*/
+
+static struct bitmap * snapshot_create(int x, int y, int w, int h)
+{
+ int err;
+ MFDB * native;
+ // uint32_t start = clock();
+
+ // FIXME: This can be optimized a lot.
+ // 1. do not copy the snapshot to the bitmap buffer
+ // when the format of screen and bitmap equals.
+ // just point the bitmap to the native mfdb.
+ // 2. if we have eddi 1.1, we could optimize that further
+ // make snapshot_create_native_mfdb just returning a pointer
+ // to the screen.
+
+ native = snapshot_create_native_mfdb(x, y, w, h );
+
+ if(vfmt.bits == 32 )
+ goto no_copy;
+
+ /* allocate buffer for result bitmap: */
+ if(buf_scr_compat == NULL ) {
+ buf_scr_compat = bitmap_create(w, h, 0);
+ } else {
+ buf_scr_compat = bitmap_realloc( w, h,
+ buf_scr_compat->bpp,
+ w *buf_scr_compat->bpp,
+ BITMAP_GROW,
+ buf_scr_compat );
+ }
+
+ /* convert screen buffer to ns format: */
+ err = Hermes_ConverterRequest( hermes_cnv_h,
+ &vfmt,
+ &nsfmt
+ );
+ assert( err != 0 );
+ err = Hermes_ConverterCopy( hermes_cnv_h,
+ native->fd_addr,
+ 0, /* x src coord of top left in pixel coords */
+ 0, /* y src coord of top left in pixel coords */
+ w, h,
+ native->fd_w * vdi_sysinfo.pixelsize, /* stride as bytes */
+ buf_scr_compat->pixdata,
+ 0, /* x dst coord of top left in pixel coords */
+ 0, /* y dst coord of top left in pixel coords */
+ w, h,
+ bitmap_get_rowstride(buf_scr_compat) /* stride as bytes */
+ );
+ assert( err != 0 );
+ return( (struct bitmap * )buf_scr_compat );
+
+no_copy:
+
+ snapshot.width = w;
+ snapshot.height = h;
+ snapshot.pixdata = native->fd_addr;
+ snapshot.native = *native;
+ snapshot.rowstride = MFDB_STRIDE( w )*4;
+
+ uint32_t row, col;
+ for (row = 0; row<(uint32_t)h; row++) {
+ // fd_w matches stride!
+ uint32_t *rowptr = ((uint32_t*)native->fd_addr + ((row*native->fd_w)));
+ for (col=0; col<(uint32_t)w; col++) {
+ *(rowptr+col) = (*(rowptr+col)<<8);
+ }
+ }
+ return( &snapshot );
+}
+
+static void snapshot_suspend(void)
+{
+ if(size_buf_scr > CONV_KEEP_LIMIT ) {
+ buf_scr.fd_addr = realloc(
+ buf_scr.fd_addr, CONV_KEEP_LIMIT
+ );
+ if(buf_scr.fd_addr != NULL ) {
+ size_buf_scr = CONV_KEEP_LIMIT;
+ } else {
+ size_buf_scr = 0;
+ }
+ }
+
+ if(size_buf_std > CONV_KEEP_LIMIT ) {
+ buf_std.fd_addr = realloc(
+ buf_std.fd_addr, CONV_KEEP_LIMIT
+ );
+ if(buf_std.fd_addr != NULL ) {
+ size_buf_std = CONV_KEEP_LIMIT;
+ } else {
+ size_buf_std = 0;
+ }
+ }
+
+ if(buf_scr_compat != NULL ) {
+ size_t bs = bitmap_buffer_size(buf_scr_compat );
+ if( bs > CONV_KEEP_LIMIT ) {
+ int w = 0;
+ int h = 1;
+ w = (CONV_KEEP_LIMIT /buf_scr_compat->bpp);
+ assert( CONV_KEEP_LIMIT == w*buf_scr_compat->bpp );
+ buf_scr_compat = bitmap_realloc( w, h,
+ buf_scr_compat->bpp,
+ CONV_KEEP_LIMIT, BITMAP_SHRINK,buf_scr_compat
+ );
+ }
+ }
+}
+
+static void snapshot_destroy(void)
+{
+
+ free(buf_scr.fd_addr);
+ if( buf_scr_compat != NULL) {
+ bitmap_destroy(buf_scr_compat);
+ }
+
+ buf_scr.fd_addr = NULL;
+ buf_scr_compat = NULL;
+
+#ifdef WITH_8BPP_SUPPORT
+ free(buf_std.fd_addr);
+ buf_std.fd_addr = NULL;
+#endif
+}
+
+
+static inline uint32_t ablend(uint32_t pixel, uint32_t scrpixel)
+{
+ int opacity = pixel & 0xFF;
+ int transp = 0x100 - opacity;
+ uint32_t rb, g;
+ pixel >>= 8;
+ scrpixel >>= 8;
+ rb = ((pixel & 0xFF00FF) * opacity +
+ (scrpixel & 0xFF00FF) * transp) >> 8;
+ g = ((pixel & 0x00FF00) * opacity +
+ (scrpixel & 0x00FF00) * transp) >> 8;
+
+ return ((rb & 0xFF00FF) | (g & 0xFF00)) << 8;
+}
+
+/*
+ Alpha blends an image, using one pixel as the background.
+ The bitmap receives the result.
+*/
+static bool ablend_pixel( struct bitmap * img, uint32_t bg, GRECT * clip )
+{
+ uint32_t * imgrow;
+ int img_x, img_y, img_stride;
+
+ img_stride= bitmap_get_rowstride(img);
+
+ for( img_y = 0; img_y < clip->g_h; img_y++) {
+ imgrow = (uint32_t *)(img->pixdata + (img_stride * img_y));
+ for( img_x = 0; img_x < clip->g_w; img_x++ ) {
+ imgrow[img_x] = ablend( imgrow[img_x], bg );
+ }
+ }
+ return(true);
+}
+
+
+/*
+ Aplha blends the foreground image (img) onto the
+ background images (bg). The background receives the blended
+ image pixels.
+*/
+static bool ablend_bitmap( struct bitmap * img, struct bitmap * bg,
+ GRECT * img_clip, GRECT * bg_clip )
+{
+ uint32_t * imgrow;
+ uint32_t * screenrow;
+ int img_x, img_y, bg_x, bg_y, img_stride, bg_stride;
+
+ bg_clip = bg_clip;
+ img_stride= bitmap_get_rowstride(img);
+ bg_stride = bitmap_get_rowstride(bg);
+
+ for( img_y = img_clip->g_y, bg_y = 0; bg_y < img_clip->g_h; bg_y++, img_y++) {
+ imgrow = (uint32_t *)(img->pixdata + (img_stride * img_y));
+ screenrow = (uint32_t *)(bg->pixdata + (bg_stride * bg_y));
+ for( img_x = img_clip->g_x, bg_x = 0; bg_x < img_clip->g_w; bg_x++, img_x++ ) {
+
+ // when the pixel isn't fully transparent,...:
+ if( (imgrow[img_x] & 0x0FF) != 0 ){
+ screenrow[bg_x] = ablend( imgrow[img_x], screenrow[bg_x]);
+ }
+
+ // FIXME, maybe this loop would be faster??:
+ // ---
+ //if( (imgrow[img_x] & 0x0FF) != 0xFF ){
+ // imgrow[bg_x] = ablend( imgrow[img_x], screenrow[bg_x]);
+ //}
+
+ // or maybe even this???
+ // ---
+ //if( (imgrow[img_x] & 0x0FF) == 0xFF ){
+ // screenrow[bg_x] = imgrow[img_x];
+ //} else if( (imgrow[img_x] & 0x0FF) != 0x00 ) {
+ // screenrow[bg_x] = ablend( imgrow[img_x], screenrow[bg_x]);
+ //}
+ }
+ }
+ return(false);
+}
+
+
+#ifdef WITH_8BPP_SUPPORT
+static bool bitmap_convert_8(struct bitmap * img, int x,
+ int y, GRECT * clip, uint32_t bg, uint32_t flags,
+ MFDB *out )
+{
+ MFDB native;
+ MFDB stdform;
+ int dststride; /* stride of dest. image */
+ int dstsize; /* size of dest. in byte */
+ int err;
+ int bw, bh;
+ int process_w, process_h;
+ struct bitmap * scrbuf = NULL;
+ struct bitmap * source;
+ bool cache = ( flags & BITMAPF_BUFFER_NATIVE );
+ bool opaque = bitmap_get_opaque( img );
+
+ if( opaque == false ){
+ if( ( (atari_plot_flags & PLOT_FLAG_TRANS) == 0)
+ &&
+ ((flags & (BITMAPF_MONOGLYPH|BITMAPF_BUFFER_NATIVE))==0) ){
+ opaque = true;
+ }
+ }
+
+ assert( clip->g_h > 0 );
+ assert( clip->g_w > 0 );
+
+ process_w = bw = bitmap_get_width( img );
+ process_h = bh = bitmap_get_height( img );
+
+ // The converted bitmap can be saved for subsequent blits, when
+ // the bitmap is fully opaque
+
+ if( (opaque == true) || (flags & BITMAPF_BUFFER_NATIVE ) ){
+ if( img->converted == true ){
+ *out = img->native;
+ return( 0 );
+ }
+ if( ( flags & BITMAPF_MONOGLYPH ) == 0 ){
+ cache = true;
+ }
+ }
+ if( ( flags & BITMAPF_MONOGLYPH ) != 0 ){
+ assert(cache == false);
+ }
+
+ /* (re)allocate buffer for out image: */
+ /* altough the buffer is named "buf_packed" on 8bit systems */
+ /* it's not... */
+ if( cache == false ){
+ // the size of the output will match the size of the clipping:
+ dststride = MFDB_STRIDE( clip->g_w );
+ dstsize = ( ((dststride >> 3) * clip->g_h) * atari_plot_bpp_virt);
+ if( dstsize > size_buf_packed) {
+ int blocks = (dstsize / (CONV_BLOCK_SIZE-1))+1;
+ if( buf_packed == NULL )
+ buf_packed =(void*)malloc( blocks * CONV_BLOCK_SIZE);
+ else
+ buf_packed =(void*)realloc(buf_packed,blocks * CONV_BLOCK_SIZE);
+ assert( buf_packed );
+ if( buf_packed == NULL ) {
+ return( 0-ERR_NO_MEM );
+ }
+ size_buf_packed = blocks * CONV_BLOCK_SIZE;
+ }
+ native.fd_addr = buf_packed;
+ }
+ else {
+ // the output image will be completly saved, so size of the output
+ // image will match the input image size.
+ dststride = MFDB_STRIDE( bw );
+ dstsize = ( ((dststride >> 3) * bh) * atari_plot_bpp_virt);
+ assert( out->fd_addr == NULL );
+ native.fd_addr = (void*)malloc( dstsize );
+ if (native.fd_addr == NULL){
+ if (scrbuf != NULL)
+ bitmap_destroy(scrbuf);
+ return( 0-ERR_NO_MEM );
+ }
+ }
+
+
+ /*
+ on 8 bit systems we must convert the TC (ABGR) image
+ to vdi standard format. ( only tested for 256 colors )
+ and then convert it to native format with v_trnfm()
+ */
+ // realloc mem for stdform
+ if( opaque == false ){
+ // point image to snapshot buffer, otherwise allocate mem
+ MFDB * bg = snapshot_create_std_mfdb(x, y, clip->g_w, clip->g_h);
+ stdform.fd_addr = bg->fd_addr;
+ bh = clip->g_h;
+ } else {
+ if( dstsize > size_buf_planar) {
+ int blocks = (dstsize / (CONV_BLOCK_SIZE-1))+1;
+ if( buf_planar == NULL )
+ buf_planar =(void*)malloc( blocks * CONV_BLOCK_SIZE );
+ else
+ buf_planar =(void*)realloc(
+ buf_planar,
+ blocks * CONV_BLOCK_SIZE
+ );
+ assert( buf_planar );
+ if( buf_planar == NULL ) {
+ return( 0-ERR_NO_MEM );
+ }
+ size_buf_planar = blocks * CONV_BLOCK_SIZE;
+ }
+ stdform.fd_addr = buf_planar;
+ }
+ stdform.fd_w = dststride;
+ stdform.fd_h = bh;
+ stdform.fd_wdwidth = dststride >> 4;
+ stdform.fd_stand = 1;
+ stdform.fd_nplanes = (short)atari_plot_bpp_virt;
+ stdform.fd_r1 = stdform.fd_r2 = stdform.fd_r3 = 0;
+
+ int img_stride = bitmap_get_rowstride(img);
+ uint32_t prev_pixel = 0x12345678;
+ unsigned long col = 0;
+ unsigned char val = 0;
+ uint32_t * row;
+ uint32_t pixel;
+ int wdplanesize = stdform.fd_wdwidth*stdform.fd_h;
+
+ if( opaque == false ){
+ // apply transparency and convert to vdi std format
+ unsigned long bgcol = 0;
+ unsigned char prev_col = 0;
+ for( y=0; y<clip->g_h; y++ ){
+ row = (uint32_t *)(img->pixdata + (img_stride * (y+clip->g_y)));
+ for( x=0; x<clip->g_w; x++ ){
+ pixel = row[x+clip->g_x];
+ if( (pixel&0xFF) == 0 ){
+ continue;
+ }
+ if( (pixel&0xFF) < 0xF0 ){
+ col = get_stdpx( &stdform, wdplanesize,x,y );
+ if( (col != prev_col) || (y == 0) )
+ bgcol = (((rgb_lookup[col][2] << 16) | (rgb_lookup[col][1] << 8) | (rgb_lookup[col][0]))<<8);
+ if( prev_col != col || prev_pixel != pixel ){
+ prev_col = col;
+ pixel = ablend( pixel, bgcol );
+ prev_pixel = pixel;
+ pixel = pixel >> 8;
+ /* convert pixel value to vdi color index: */
+ col = ( ((pixel&0xFF)<<16)
+ | (pixel&0xFF00)
+ | ((pixel&0xFF0000)>>16) );
+ val = RGB_TO_VDI( col );
+ }
+ set_stdpx( &stdform, wdplanesize, x, y, val );
+ } else {
+ if( pixel != prev_pixel ){
+ /* convert pixel value to vdi color index: */
+ pixel = pixel >> 8;
+ col = ( ((pixel&0xFF)<<16)
+ | (pixel&0xFF00)
+ | ((pixel&0xFF0000)>>16) );
+ val = RGB_TO_VDI( col );
+ prev_pixel = pixel;
+ }
+ set_stdpx( &stdform, wdplanesize, x, y, val );
+ }
+ }
+ }
+ // adjust output position:
+ clip->g_x = 0;
+ clip->g_y = 0;
+ } else {
+ // convert the whole image data to vdi std format.
+ for( y=0; y < bh; y++ ){
+ row = (uint32_t *)(img->pixdata + (img_stride * y));
+ for( x=0; x < bw; x++ ){
+ pixel = row[x];
+ if( pixel != prev_pixel ){
+ /* convert pixel value to vdi color index: */
+ pixel = pixel >> 8;
+ col = ( ((pixel&0xFF)<<16)
+ | (pixel&0xFF00)
+ | ((pixel&0xFF0000)>>16) );
+ val = RGB_TO_VDI( col );
+ prev_pixel = pixel;
+ }
+ set_stdpx( &stdform, wdplanesize, x, y, val );
+ }
+ }
+ }
+
+ // convert into native format:
+ native.fd_w = stdform.fd_w;
+ native.fd_h = stdform.fd_h;
+ native.fd_wdwidth = stdform.fd_wdwidth;
+ native.fd_stand = 0;
+ native.fd_nplanes = (short)atari_plot_bpp_virt;
+ native.fd_r1 = native.fd_r2 = native.fd_r3 = 0;
+ vr_trnfm(atari_plot_vdi_handle, &stdform, &native );
+ *out = native;
+ if( cache == true ){
+ img->native = native;
+ img->converted = true;
+ }
+
+ return(0);
+}
+#endif
+
+
+/*
+*
+* Convert bitmap to the native screen format
+* img: the bitmap
+* x: coordinate where the bitmap REGION (described in clip)
+* shall be drawn (screen coords)
+* y: coordinate where the bitmap REGION (described in clip)
+* shall be drawn (screen coords)
+* clip: which area of the bitmap shall be drawn
+* bg: background color
+* flags: blit flags
+* out: the result MFDB
+*/
+static bool bitmap_convert_tc(struct bitmap * img, int x, int y,
+ GRECT * clip, uint32_t bg, uint32_t flags, MFDB *out )
+{
+ int dststride; /* stride of dest. image */
+ int dstsize; /* size of dest. in byte */
+ int err;
+ int bw, bh;
+ struct bitmap * scrbuf = NULL;
+ struct bitmap * source = NULL;
+ bool cache = ( flags & BITMAPF_BUFFER_NATIVE );
+ bool opaque = bitmap_get_opaque( img );
+
+ if( opaque == false ){
+ if( ( (atari_plot_flags & PLOT_FLAG_TRANS) == 0)
+ &&
+ ((flags & (BITMAPF_MONOGLYPH|BITMAPF_BUFFER_NATIVE))==0) ){
+ opaque = true;
+ }
+ }
+
+
+ assert( clip->g_h > 0 );
+ assert( clip->g_w > 0 );
+
+ bw = bitmap_get_width( img );
+ bh = bitmap_get_height( img );
+
+ // The converted bitmap can be saved for subsequent blits, WHEN:
+ // A.) the bitmap is fully opaque OR
+ // B.) the bitmap is completly inside the window
+ // the latter one is important for alpha blits,
+ // because we must get the window background to apply transparency
+ // If the image is not completly within the window,
+ // we can't get the whole background for the image.
+ // this only works if the image isn't used at several different places.
+ // In fact in case of alpha bitmap caching it is only used for the
+ // toolbar buttons right now.
+
+ if( (opaque == true) || (flags & BITMAPF_BUFFER_NATIVE ) ){
+ if( img->converted == true ){
+ *out = img->native;
+ return( 0 );
+ }
+ if( ( flags & BITMAPF_MONOGLYPH ) == 0 ){
+ cache = true;
+ }
+ }
+
+ /* rem. if eddi xy is installed, we could directly access the screen! */
+ /* apply transparency to the image: */
+ if (( opaque == false )) {
+ /* copy the screen to an temp buffer: */
+ if ((flags & BITMAPF_BUFFER_NATIVE) == 0) {
+ scrbuf = snapshot_create(x, y, clip->g_w, clip->g_h);
+ if( scrbuf != NULL ) {
+
+ assert( clip->g_w <= bw );
+ assert( clip->g_h <= bh );
+
+ // copy blended pixels to the screen buffer:
+ ablend_bitmap( img, scrbuf, clip, NULL );
+ /* adjust size which gets converted: */
+ bw = clip->g_w;
+ bh = clip->g_h;
+ /* adjust output position: */
+ clip->g_x = 0;
+ clip->g_y = 0;
+ /* set the source of conversion: */
+ source = scrbuf;
+ }
+ } else {
+ /*
+ The whole bitmap can be transformed to an mfdb
+ (and get's cached)
+ */
+ GRECT region = { 0, 0, bw, bh };
+ ablend_pixel( img, bg, &region );
+ source = img;
+ }
+ } else {
+ source = img;
+ }
+ /* (re)allocate buffer for converted image: */
+ dststride = MFDB_STRIDE(bw);
+ dstsize = ( ((dststride >> 3) * bh) * atari_plot_bpp_virt );
+ if (cache == false) {
+ if (dstsize > size_buf_packed) {
+ int blocks = (dstsize / (CONV_BLOCK_SIZE-1))+1;
+ if( buf_packed == NULL )
+ buf_packed =(void*)malloc( blocks * CONV_BLOCK_SIZE );
+ else
+ buf_packed =(void*)realloc(buf_packed,
+ blocks * CONV_BLOCK_SIZE);
+ assert( buf_packed );
+ if( buf_packed == NULL ) {
+ if( scrbuf != NULL )
+ bitmap_destroy( scrbuf );
+ return( 0-ERR_NO_MEM );
+ }
+ size_buf_packed = blocks * CONV_BLOCK_SIZE;
+ }
+ out->fd_addr = buf_packed;
+ } else {
+ assert( out->fd_addr == NULL );
+ out->fd_addr = (void*)malloc( dstsize );
+ if( out->fd_addr == NULL ){
+ if( scrbuf != NULL )
+ bitmap_destroy( scrbuf );
+ return( 0-ERR_NO_MEM );
+ }
+ }
+
+ out->fd_w = dststride;
+ out->fd_h = bh;
+ out->fd_wdwidth = dststride >> 4;
+ out->fd_stand = 0;
+ out->fd_nplanes = (short)atari_plot_bpp_virt;
+ out->fd_r1 = out->fd_r2 = out->fd_r3 = 0;
+
+ err = Hermes_ConverterRequest(
+ hermes_cnv_h,
+ &nsfmt,
+ &vfmt
+ );
+ assert( err != 0 );
+
+ // FIXME: here we can use the same optimization which is used for
+ // the snapshot creation.
+
+ /* convert image to virtual format: */
+ err = Hermes_ConverterCopy( hermes_cnv_h,
+ source->pixdata,
+ 0, /* x src coord of top left in pixel coords */
+ 0, /* y src coord of top left in pixel coords */
+ bw, bh,
+ source->rowstride, /* stride as bytes */
+ out->fd_addr,
+ 0, /* x dst coord of top left in pixel coords */
+ 0, /* y dst coord of top left in pixel coords */
+ bw, bh,
+ (dststride >> 3) * atari_plot_bpp_virt /* stride as bytes */
+ );
+ assert( err != 0 );
+
+ if( cache == true ){
+ img->native = *out;
+ img->converted = true;
+ }
+ return( 0 );
+
+}
+
+static void convert_bitmap_done(void)
+{
+ if (size_buf_packed > CONV_KEEP_LIMIT) {
+ /* free the mem if it was an large allocation ... */
+ buf_packed = realloc(buf_packed, CONV_KEEP_LIMIT);
+ size_buf_packed = CONV_KEEP_LIMIT;
+ }
+ snapshot_suspend();
+}
+
+
+bool plot_blit_bitmap(struct bitmap * bmp, int x, int y,
+ unsigned long bg, unsigned long flags )
+{
+ MFDB src_mf;
+ MFDB scrmf;
+ short pxy[8];
+ GRECT off, clip, vis;
+ int screen_x, screen_y;
+
+ src_mf.fd_addr = NULL;
+ scrmf.fd_addr = NULL;
+
+ off.g_x = x;
+ off.g_y = y;
+ off.g_h = bmp->height;
+ off.g_w = bmp->width;
+
+ // clip plotter clip rectangle:
+ clip.g_x = view.clipping.x0;
+ clip.g_y = view.clipping.y0;
+ clip.g_w = view.clipping.x1 - view.clipping.x0;
+ clip.g_h = view.clipping.y1 - view.clipping.y0;
+
+ if( !rc_intersect( &clip, &off) ) {
+ return(true);
+ }
+
+ // clip the visible rectangle of the plot area
+ // this is the area of the plotter which falls into
+ // screen region:
+ plotter_get_visible_grect(&vis);
+ if( !rc_intersect( &vis, &off) ) {
+ return(true);
+ }
+
+ screen_x = view.x + off.g_x;
+ screen_y = view.y + off.g_y;
+
+ // convert the clipping relative to bitmap:
+ off.g_x = off.g_x - x;
+ off.g_y = off.g_y - y;
+ assert( (off.g_x >= 0) && (off.g_y >= 0) );
+
+ /* Convert the Bitmap to native screen format - ready for output. */
+ /* This includes blending transparent pixels: */
+ if (bitmap_convert(bmp, screen_x, screen_y, &off, bg, flags, &src_mf)
+ != 0 ) {
+ return(true);
+ }
+
+ // setup the src region:
+ pxy[0] = off.g_x;
+ pxy[1] = off.g_y;
+ pxy[2] = off.g_x + off.g_w-1;
+ pxy[3] = off.g_y + off.g_h-1;
+
+ // setup the target region:
+ pxy[4] = screen_x;
+ pxy[5] = screen_y;
+ pxy[6] = screen_x + off.g_w-1;
+ pxy[7] = screen_y + off.g_h-1;
+
+ vro_cpyfm(atari_plot_vdi_handle, S_ONLY, (short*)&pxy, &src_mf, &scrmf);
+ convert_bitmap_done();
+ return(true);
+}
+
+bool plot_blit_mfdb(GRECT * loc, MFDB * insrc, unsigned char fgcolor,
+ uint32_t flags)
+{
+
+ MFDB screen, tran;
+ MFDB * src;
+ short pxy[8];
+ short c[2] = {fgcolor, WHITE};
+ GRECT off;
+
+ plotter_get_clip_grect(&off);
+ if( rc_intersect(loc, &off) == 0 ){
+ return( 1 );
+ }
+
+ init_mfdb( 0, loc->g_w, loc->g_h, 0, &screen );
+
+ if( insrc->fd_stand ){
+ int size = init_mfdb( insrc->fd_nplanes, loc->g_w, loc->g_h,
+ MFDB_FLAG_NOALLOC,
+ &tran
+ );
+ if( size_buf_scr == 0 ){
+ buf_scr.fd_addr = malloc( size );
+ size_buf_scr = size;
+ } else {
+ if( size > size_buf_scr ) {
+ buf_scr.fd_addr = realloc(
+ buf_scr.fd_addr, size
+ );
+ size_buf_scr = size;
+ }
+ }
+ tran.fd_addr = buf_scr.fd_addr;
+ vr_trnfm(atari_plot_vdi_handle, insrc, &tran );
+ src = &tran;
+ } else {
+ src = insrc;
+ }
+
+ pxy[0] = off.g_x - loc->g_x;
+ pxy[1] = off.g_y - loc->g_y;
+ pxy[2] = pxy[0] + off.g_w - 1;
+ pxy[3] = pxy[1] + off.g_h - 1;
+ pxy[4] = view.x + off.g_x;
+ pxy[5] = view.y + off.g_y;
+ pxy[6] = pxy[4] + off.g_w-1;
+ pxy[7] = pxy[5] + off.g_h-1;
+
+
+ if( flags & PLOT_FLAG_TRANS && src->fd_nplanes == 1){
+ vrt_cpyfm(atari_plot_vdi_handle, MD_TRANS, (short*)pxy, src, &screen, (short*)&c );
+ } else {
+ /* this method only plots transparent bitmaps, right now... */
+ }
+ return( 1 );
+}
+
+/*
+Init screen and font driver objects.
+Returns non-zero value > -1 when the objects could be succesfully created.
+Returns value < 0 to indicate an error
+*/
+
+int atari_plotter_init(char * fdrvrname)
+{
+
+ GRECT loc_pos= {0,0,360,400};
+ int err=0,i;
+
+ if( nsoption_int(atari_dither) == 1)
+ atari_plot_flags |= PLOT_FLAG_DITHER;
+ if( nsoption_int(atari_transparency) == 1 )
+ atari_plot_flags |= PLOT_FLAG_TRANS;
+ if( nsoption_int(atari_font_monochrom) == 1 )
+ atari_font_flags |= FONTPLOT_FLAG_MONOGLYPH;
+
+ atari_plot_vdi_handle = app.graf.handle;
+ read_vdi_sysinfo(atari_plot_vdi_handle, &vdi_sysinfo);
+ if( verbose_log ) {
+ dump_vdi_info( atari_plot_vdi_handle ) ;
+ dump_font_drivers();
+ }
+
+ fplotter = new_font_plotter(atari_plot_vdi_handle, fdrvrname,
+ atari_font_flags, &err);
+ if(err) {
+ const char * desc = plot_err_str(err);
+ die(("Unable to load font plotter %s -> %s", fdrvrname, desc ));
+ }
+
+ memset(&view, 0, sizeof(struct s_view));
+ atari_plot_bpp_virt = app.nplanes;
+ view.x = loc_pos.g_x;
+ view.y = loc_pos.g_y;
+ view.w = loc_pos.g_w;
+ view.h = loc_pos.g_h;
+ size_buf_packed = 0;
+ size_buf_planar = 0;
+ buf_packed = NULL;
+ buf_planar = NULL;
+ if( vdi_sysinfo.vdiformat == VDI_FORMAT_PACK ) {
+ atari_plot_bpp_virt = vdi_sysinfo.scr_bpp;
+ } else {
+ atari_plot_bpp_virt = 8;
+ }
+
+ update_visible_rect();
+
+ struct rect clip;
+ clip.x0 = 0;
+ clip.y0 = 0;
+ clip.x1 = view.w;
+ clip.y1 = view.h;
+ plot_clip(&clip);
+
+ assert(Hermes_Init());
+
+#ifdef WITH_8BPP_SUPPORT
+ bitmap_convert = (app.nplanes > 8) ? bitmap_convert_tc : bitmap_convert_8;
+
+ /* Setup color lookup tables and palette */
+ i = 0;
+ unsigned char * col;
+ unsigned char rgbcol[4];
+ unsigned char graytone=0;
+ if( app.nplanes <= 8 ){
+ for( i=0; i<=255; i++ ) {
+
+ // get the current color and save it for restore:
+ vq_color(atari_plot_vdi_handle, i, 1, (unsigned short*)&sys_pal[i][0] );
+ if( i<OFFSET_WEB_PAL ) {
+ pal[i][0] = sys_pal[i][0];
+ pal[i][1] = sys_pal[i][1];
+ pal[i][2] = sys_pal[i][2];
+ } else if( app.nplanes >= 8 ) {
+ if ( i < OFFSET_CUST_PAL ){
+ pal[i][0] = vdi_web_pal[i-OFFSET_WEB_PAL][0];
+ pal[i][1] = vdi_web_pal[i-OFFSET_WEB_PAL][1];
+ pal[i][2] = vdi_web_pal[i-OFFSET_WEB_PAL][2];
+ //set the new palette color to websafe value:
+ vs_color(atari_plot_vdi_handle, i, &pal[i][0]);
+ }
+ if( i >= OFFSET_CUST_PAL && i<OFFSET_CUST_PAL+16 ) {
+ /* here we define 20 additional gray colors... */
+ rgbcol[1] = rgbcol[2] = rgbcol[3] = ((graytone&0x0F) << 4);
+ rgb_to_vdi1000( &rgbcol[0], &pal[i][0] );
+ vs_color(atari_plot_vdi_handle, i, &pal[i][0]);
+ graytone++;
+ }
+
+ }
+ vdi1000_to_rgb( &pal[i][0], &rgb_lookup[i][0] );
+ }
+
+ } else {
+ /* no need to change the palette - its application specific */
+ }
+#else
+ bitmap_convert = bitmap_convert_tc;
+#endif
+
+ /* Setup Hermes conversion handles */
+ unsigned long hermesflags = (atari_plot_flags & PLOT_FLAG_DITHER) ? HERMES_CONVERT_DITHER : 0;
+ hermes_cnv_h = Hermes_ConverterInstance(hermesflags);
+ assert( hermes_cnv_h );
+ hermes_res_h = Hermes_ConverterInstance(hermesflags);
+ assert( hermes_res_h );
+
+ /* set up the src & dst format: */
+ /* netsurf uses RGBA ... */
+ nsfmt.a = 0xFFUL;
+ nsfmt.b = 0x0FF00UL;
+ nsfmt.g = 0x0FF0000UL;
+ nsfmt.r = 0x0FF000000UL;
+ nsfmt.bits = 32;
+ nsfmt.indexed = false;
+ nsfmt.has_colorkey = false;
+
+ vfmt.r = vdi_sysinfo.mask_r;
+ vfmt.g = vdi_sysinfo.mask_g;
+ vfmt.b = vdi_sysinfo.mask_b;
+ vfmt.a = vdi_sysinfo.mask_a;
+ vfmt.bits = atari_plot_bpp_virt;
+ vfmt.indexed = (atari_plot_bpp_virt <= 8) ? 1 : 0;
+ vfmt.has_colorkey = 0;
+
+ return( err );
+}
+
+int atari_plotter_finalise( void )
+{
+ int i=0;
+
+ delete_font_plotter(fplotter);
+
+#ifdef WITH_8BPP_SUPPORT
+ if (vfmt.indexed) {
+ for (i=OFFSET_WEB_PAL; i<OFFSET_CUST_PAL+16; i++) {
+ vs_color(atari_plot_vdi_handle, i, &sys_pal[i][0]);
+ }
+ }
+#endif
+
+ /* close Hermes stuff: */
+ Hermes_ConverterReturn(hermes_cnv_h);
+ Hermes_Done();
+
+ /* free up temporary buffers */
+ free(buf_packed );
+ free(buf_planar);
+ snapshot_destroy();
+}
+
+bool plot_lock(void)
+{
+ if ((atari_plot_flags & PLOT_FLAG_LOCKED) != 0)
+ return(true);
+ if( !wind_update(BEG_UPDATE|0x100) )
+ return(false);
+ if( !wind_update(BEG_MCTRL|0x100) ){
+ wind_update(END_UPDATE);
+ return(false);
+ }
+ atari_plot_flags |= PLOT_FLAG_LOCKED;
+ graf_mouse(M_OFF, NULL);
+ return(true);
+}
+
+bool plot_unlock(void)
+{
+ if( (atari_plot_flags & PLOT_FLAG_LOCKED) == 0 )
+ return(true);
+ wind_update(END_MCTRL);
+ wind_update(END_UPDATE);
+ graf_mouse(M_ON, NULL);
+ atari_plot_flags &= ~PLOT_FLAG_LOCKED;
+ return(false);
+}
+
+bool plot_rectangle(int x0, int y0, int x1, int y1,
+ const plot_style_t *pstyle )
+{
+ short pxy[4];
+ GRECT r, rclip, sclip;
+ int sw = pstyle->stroke_width;
+ uint32_t lt;
+
+ /* current canvas clip: */
+ rclip.g_x = view.clipping.x0;
+ rclip.g_y = view.clipping.y0;
+ rclip.g_w = view.clipping.x1 - view.clipping.x0;
+ rclip.g_h = view.clipping.y1 - view.clipping.y0;
+
+ /* physical clipping: */
+ sclip.g_x = rclip.g_x;
+ sclip.g_y = rclip.g_y;
+ sclip.g_w = view.vis_w;
+ sclip.g_h = view.vis_h;
+
+ rc_intersect(&sclip, &rclip);
+ r.g_x = x0;
+ r.g_y = y0;
+ r.g_w = x1 - x0;
+ r.g_h = y1 - y0;
+
+ if (!rc_intersect( &rclip, &r )) {
+ return(true);
+ }
+ if (pstyle->stroke_type != PLOT_OP_TYPE_NONE) {
+ /*
+ manually draw the line, because we do not need vdi clipping
+ for vertical / horizontal line draws.
+ */
+ if( sw == 0)
+ sw = 1;
+
+ NSLT2VDI(lt, pstyle);
+ vsl_type(atari_plot_vdi_handle, (lt&0x0F));
+ /*
+ if the line style is not available within VDI system,
+ define own style:
+ */
+ if( (lt&0x0F) == 7 ){
+ vsl_udsty(atari_plot_vdi_handle, ((lt&0xFFFF00) >> 8));
+ }
+ vsl_width(atari_plot_vdi_handle, (short)sw );
+ vsl_rgbcolor(atari_plot_vdi_handle, pstyle->stroke_colour);
+ /* top border: */
+ if( r.g_y == y0){
+ pxy[0] = view.x + r.g_x;
+ pxy[1] = view.y + r.g_y ;
+ pxy[2] = view.x + r.g_x + r.g_w;
+ pxy[3] = view.y + r.g_y;
+ v_pline(atari_plot_vdi_handle, 2, (short *)&pxy);
+ }
+
+ /* right border: */
+ if( r.g_x + r.g_w == x1 ){
+ pxy[0] = view.x + r.g_x + r.g_w;
+ pxy[1] = view.y + r.g_y;
+ pxy[2] = view.x + r.g_x + r.g_w;
+ pxy[3] = view.y + r.g_y + r.g_h;
+ v_pline(atari_plot_vdi_handle, 2, (short *)&pxy);
+ }
+
+ /* bottom border: */
+ if( r.g_y+r.g_h == y1 ){
+ pxy[0] = view.x + r.g_x;
+ pxy[1] = view.y + r.g_y+r.g_h;
+ pxy[2] = view.x + r.g_x+r.g_w;
+ pxy[3] = view.y + r.g_y+r.g_h;
+ v_pline(atari_plot_vdi_handle, 2, (short *)&pxy);
+ }
+
+ /* left border: */
+ if( r.g_x == x0 ){
+ pxy[0] = view.x + r.g_x;
+ pxy[1] = view.y + r.g_y;
+ pxy[2] = view.x + r.g_x;
+ pxy[3] = view.y + r.g_y + r.g_h;
+ v_pline(atari_plot_vdi_handle, 2, (short *)&pxy);
+ }
+ }
+
+ if( pstyle->fill_type != PLOT_OP_TYPE_NONE ){
+ short stroke_width = (short)(pstyle->stroke_type != PLOT_OP_TYPE_NONE) ?
+ pstyle->stroke_width : 0;
+
+ vsf_rgbcolor(atari_plot_vdi_handle, pstyle->fill_colour);
+ vsf_perimeter(atari_plot_vdi_handle, 0);
+ vsf_interior(atari_plot_vdi_handle, FIS_SOLID);
+
+
+ pxy[0] = view.x + r.g_x + stroke_width;
+ pxy[1] = view.y + r.g_y + stroke_width;
+ pxy[2] = view.x + r.g_x + r.g_w -1 - stroke_width;
+ pxy[3] = view.y + r.g_y + r.g_h -1 - stroke_width;
+
+ vsf_style(atari_plot_vdi_handle, 1);
+ v_bar(atari_plot_vdi_handle, (short*)&pxy);
+ }
+ return (true);
+}
+
+bool plot_line(int x0, int y0, int x1, int y1,
+ const plot_style_t *pstyle )
+{
+ short pxy[4];
+ uint32_t lt;
+ int sw = pstyle->stroke_width;
+
+ pxy[0] = view.x + x0;
+ pxy[1] = view.y + y0;
+ pxy[2] = view.x + x1;
+ pxy[3] = view.y + y1;
+
+ plotter_vdi_clip(true);
+ if( sw == 0)
+ sw = 1;
+ NSLT2VDI(lt, pstyle)
+ vsl_type(atari_plot_vdi_handle, (lt&0x0F));
+ /* if the line style is not available within VDI system,define own style: */
+ if( (lt&0x0F) == 7 ){
+ vsl_udsty(atari_plot_vdi_handle, ((lt&0xFFFF00) >> 8));
+ }
+ vsl_width(atari_plot_vdi_handle, (short)sw);
+ vsl_rgbcolor(atari_plot_vdi_handle, pstyle->stroke_colour);
+ v_pline(atari_plot_vdi_handle, 2, (short *)&pxy );
+ plotter_vdi_clip(false);
+ return ( true );
+}
+
+static bool plot_polygon(const int *p, unsigned int n,
+ const plot_style_t *pstyle)
+{
+ short pxy[n*2];
+ unsigned int i=0;
+ short d[4];
+ if (vdi_sysinfo.maxpolycoords > 0)
+ assert( (signed int)n < vdi_sysinfo.maxpolycoords);
+ plotter_vdi_clip(true);
+ vsf_interior(atari_plot_vdi_handle, FIS_SOLID);
+ vsf_style(atari_plot_vdi_handle, 1);
+ for (i = 0; i<n*2; i=i+2) {
+ pxy[i] = (short)view.x+p[i];
+ pxy[i+1] = (short)view.y+p[i+1];
+ }
+ if (pstyle->fill_type == PLOT_OP_TYPE_SOLID) {
+ vsf_rgbcolor(atari_plot_vdi_handle, pstyle->fill_colour);
+ v_fillarea(atari_plot_vdi_handle, n, (short*)&pxy);
+ } else {
+ pxy[n*2]=pxy[0];
+ pxy[n*2+1]=pxy[1];
+ vsl_rgbcolor(atari_plot_vdi_handle, pstyle->stroke_colour);
+ v_pline(atari_plot_vdi_handle, n+1, (short *)&pxy);
+ }
+ plotter_vdi_clip(false);
+ return ( true );
+}
+
+bool plot_set_dimensions(int x, int y, int w, int h)
+{
+ bool doupdate = false;
+
+ if (!(w == view.w && h == view.h)) {
+ struct rect newclip = { 0, 0, w-1, h-1 };
+ view.w = (short)w;
+ view.h = (short)h;
+ doupdate = true;
+ }
+ if (!(x == view.x && y == view.y)) {
+ view.x = (short)x;
+ view.y = (short)y;
+ doupdate = true;
+ }
+ if (doupdate==true)
+ update_visible_rect();
+ return(true);
+}
+
+bool plot_clip(const struct rect *clip)
+{
+ // FIXME: consider the canvas size
+ view.clipping.x0 = clip->x0;
+ view.clipping.y0 = clip->y0;
+ view.clipping.x1 = clip->x1;
+ view.clipping.y1 = clip->y1;
+ return ( true );
+}
+
+
+bool plot_get_clip(struct rect * out)
+{
+ out->x0 = view.clipping.x0;
+ out->y0 = view.clipping.y0;
+ out->x1 = view.clipping.x1;
+ out->y1 = view.clipping.y1;
+ return( true );
+}
+
+void plotter_get_clip_grect(GRECT * out)
+{
+ struct rect clip={0,0,0,0};
+ plot_get_clip(&clip);
+ out->g_x = clip.x0;
+ out->g_y = clip.y0;
+ out->g_w = clip.x1 - clip.x0;
+ out->g_h = clip.y1 - clip.y0;
+}
+
+static bool plot_text(int x, int y, const char *text, size_t length, const plot_font_style_t *fstyle )
+{
+ fplotter->text(fplotter, x, y, text, length, fstyle);
+ return ( true );
+}
+
+static bool plot_disc(int x, int y, int radius, const plot_style_t *pstyle)
+{
+ plotter_vdi_clip(true);
+ if (pstyle->fill_type != PLOT_OP_TYPE_SOLID) {
+ vsf_rgbcolor(atari_plot_vdi_handle, pstyle->stroke_colour);
+ vsf_perimeter(atari_plot_vdi_handle, 1);
+ vsf_interior(atari_plot_vdi_handle, 0);
+ v_circle(atari_plot_vdi_handle, view.x + x, view.y + y, radius);
+ } else {
+ vsf_rgbcolor(atari_plot_vdi_handle, pstyle->fill_colour);
+ vsf_perimeter(atari_plot_vdi_handle, 0);
+ vsf_interior(atari_plot_vdi_handle, FIS_SOLID);
+ v_circle(atari_plot_vdi_handle, view.x + x, view.y + y, radius);
+ }
+ plotter_vdi_clip(false);
+ return ( true );
+}
+
+static bool plot_arc(int x, int y, int radius, int angle1, int angle2,
+ const plot_style_t *pstyle)
+{
+ //plotter_vdi_clip(true);
+ vswr_mode(atari_plot_vdi_handle, MD_REPLACE );
+ if (pstyle->fill_type == PLOT_OP_TYPE_NONE)
+ return(true);
+ if ( pstyle->fill_type != PLOT_OP_TYPE_SOLID) {
+ vsl_rgbcolor(atari_plot_vdi_handle, pstyle->stroke_colour);
+ vsf_perimeter(atari_plot_vdi_handle, 1);
+ vsf_interior(atari_plot_vdi_handle, 1 );
+ v_arc(atari_plot_vdi_handle, view.x + x, view.y + y, radius, angle1*10, angle2*10);
+ } else {
+ vsf_rgbcolor(atari_plot_vdi_handle, pstyle->fill_colour);
+ vsl_width(atari_plot_vdi_handle, 1 );
+ vsf_perimeter(atari_plot_vdi_handle, 1);
+ v_arc(atari_plot_vdi_handle, view.x + x, view.y + y, radius, angle1*10, angle2*10);
+ }
+ //plotter_vdi_clip(true);
+ return (true);
+}
+
+static bool plot_bitmap(int x, int y, int width, int height,
+ struct bitmap *bitmap, colour bg,
+ bitmap_flags_t flags)
+{
+ struct bitmap * bm = NULL;
+ bool repeat_x = (flags & BITMAPF_REPEAT_X);
+ bool repeat_y = (flags & BITMAPF_REPEAT_Y);
+ int bmpw,bmph;
+ struct rect clip = {0,0,0,0};
+
+ bmpw = bitmap_get_width(bitmap);
+ bmph = bitmap_get_height(bitmap);
+
+ if ( repeat_x || repeat_y ) {
+ plot_get_clip(&clip);
+ if( repeat_x && width == 1 && repeat_y && height == 1 ) {
+ width = MAX( width, clip.x1 - x );
+ height = MAX( height, clip.y1 - y );
+ } else if( repeat_x && width == 1 ) {
+ width = MAX( width, clip.x1 - x);
+ } else if( repeat_y && height == 1) {
+ height = MAX( height, clip.y1 - y );
+ }
+ }
+
+ if( width != bmpw || height != bmph ) {
+ plot_resize_bitmap(bitmap, width, height );
+ if( bitmap->resized )
+ bm = bitmap->resized;
+ else
+ bm = bitmap;
+ } else {
+ bm = bitmap;
+ }
+
+ /* out of memory? */
+ if( bm == NULL ) {
+ printf("plot: out of memory! bmp: %p, bmpres: %p\n", bitmap, bitmap->resized );
+ return( true );
+ }
+
+ if (!(repeat_x || repeat_y) ) {
+ plot_blit_bitmap(bm, x, y, bg, flags );
+ } else {
+ int xf,yf;
+ int xoff = x;
+ int yoff = y;
+
+ if (yoff > clip.y0 )
+ yoff = (clip.y0 - height) + ((yoff - clip.y0) % height);
+ if (xoff > clip.x0 )
+ xoff = (clip.x0 - width) + ((xoff - clip.x0) % width);
+ /* for now, repeating just works in the rigth / down direction */
+ /*
+ if( repeat_x == true )
+ xoff = clip.x0;
+ if(repeat_y == true )
+ yoff = clip.y0;
+ */
+
+ for( xf = xoff; xf < clip.x1; xf += width ) {
+ for( yf = yoff; yf < clip.y1; yf += height ) {
+ plot_blit_bitmap(bm, xf, yf, bg, flags );
+ if (!repeat_y)
+ break;
+ }
+ if (!repeat_x)
+ break;
+ }
+ }
+ return ( true );
+}
+
+static bool plot_path(const float *p, unsigned int n, colour fill, float width,
+ colour c, const float transform[6])
+{
+ return ( true );
+}
+
+
+
+const struct plotter_table atari_plotters = {
+ .rectangle = plot_rectangle,
+ .line = plot_line,
+ .polygon = plot_polygon,
+ .clip = plot_clip,
+ .text = plot_text,
+ .disc = plot_disc,
+ .arc = plot_arc,
+ .bitmap = plot_bitmap,
+ .path = plot_path,
+ .flush = NULL,
+ .group_start = NULL,
+ .group_end = NULL,
+ .option_knockout = true
+};
diff --git a/atari/plot/plot.h b/atari/plot/plot.h
new file mode 100755
index 000000000..71546648e
--- /dev/null
+++ b/atari/plot/plot.h
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2010 Ole Loots <ole@monochrom.net>
+ *
+ * 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/>.
+ */
+
+#ifndef NS_ATARI_PLOT_H
+#define NS_ATARI_PLOT_H
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <windom.h>
+#include <assert.h>
+#include <mint/osbind.h>
+#include <mint/cookie.h>
+#include <Hermes/Hermes.h>
+
+#include "desktop/plotters.h"
+#include "desktop/plot_style.h"
+#include "image/bitmap.h"
+
+#include "atari/bitmap.h"
+#include "atari/plot/eddi.h"
+#include "atari/plot/fontplot.h"
+
+/* how much memory should be kept allocated for temp. conversion bitmaps: */
+#define CONV_KEEP_LIMIT 512000
+/* how much memory to allocate if some is needed: */
+#define CONV_BLOCK_SIZE 32000
+
+/* Plotter Option Flags: */
+#define PLOT_FLAG_DITHER 0x04 /* true if the plotter shall dither images */
+#define PLOT_FLAG_TRANS 0x08 /* true if the plotter supports transparent operations */
+
+/* Plotter "feature" flags */
+#define PLOT_FLAG_HAS_DITHER 0x0400
+#define PLOT_FLAG_HAS_ALPHA 0x0800
+#define PLOT_FLAG_OFFSCREEN 0x1000 /* offsreen plotter should set this flag */
+
+/* Plotter "internal" flags */
+#define PLOT_FLAG_LOCKED 0x08000 /* plotter should set this flag during screen updates */
+
+/* Font Plotter flags: */
+#define FONTPLOT_FLAG_MONOGLYPH 0x01
+
+/* Flags for init_mfdb function: */
+#define MFDB_FLAG_STAND 0x01
+#define MFDB_FLAG_ZEROMEM 0x02
+#define MFDB_FLAG_NOALLOC 0x04
+
+/* Flags for blit functions: */
+#define BITMAPF_MONOGLYPH 4096 /* The bitmap is an character bitmap */
+#define BITMAPF_BUFFER_NATIVE 8192 /* Bitmap shall be kept converted */
+
+/* Error codes: */
+#define ERR_BUFFERSIZE_EXCEEDS_SCREEN 1 /* The buffer allocated is larger than the screen */
+#define ERR_NO_MEM 2 /* Not enough memory for requested operation */
+#define ERR_PLOTTER_NOT_AVAILABLE 3 /* invalid plotter driver name passed */
+
+struct s_vdi_sysinfo {
+ short vdi_handle; /* vdi handle */
+ short scr_w; /* resolution horz. */
+ short scr_h; /* resolution vert. */
+ short scr_bpp; /* bits per pixel */
+ int colors; /* 0=hiclor, 2=mono */
+ unsigned long hicolors; /* if colors = 0 */
+ short pixelsize; /* bytes per pixel */
+ unsigned short pitch; /* row pitch */
+ unsigned short vdiformat; /* pixel format */
+ unsigned short clut; /* type of clut support */
+ void * screen; /* pointer to screen, or NULL */
+ unsigned long screensize; /* size of screen (in bytes) */
+ unsigned long mask_r; /* color masks */
+ unsigned long mask_g;
+ unsigned long mask_b;
+ unsigned long mask_a;
+ short maxintin; /* maximum pxy items */
+ short maxpolycoords; /* max coords for p_line etc. */
+ unsigned long EdDiVersion; /* EdDi Version or 0 */
+ bool rasterscale; /* raster scaling support */
+};
+
+struct rect;
+
+extern const struct plotter_table atari_plotters;
+
+int atari_plotter_init(char *);
+int atari_plotter_finalise(void);
+/* translate an error number */
+const char* plot_err_str(int i) ;
+
+bool plot_lock(void);
+bool plot_unlock(void);
+bool plot_set_dimensions( int x, int y, int w, int h );
+bool plot_get_clip(struct rect * out);
+/* Get clipping for current framebuffer as GRECT */
+void plotter_get_clip_grect(GRECT * out);
+bool plot_clip(const struct rect *clip);
+bool plot_rectangle( int x0, int y0, int x1, int y1,const plot_style_t *style );
+bool plot_line( int x0, int y0, int x1, int y1, const plot_style_t *style );
+bool plot_resize_bitmap(struct bitmap * img, int nw, int nh);
+bool plot_blit_bitmap(struct bitmap * bmp, int x, int y,
+ unsigned long bg, unsigned long flags);
+bool plot_blit_mfdb(GRECT * loc, MFDB * insrc, unsigned char fgcolor,
+ uint32_t flags);
+bool plot_copy_rect(GRECT src, GRECT dst);
+/*
+* Capture the screen at x,y location
+* param self instance
+* param x absolute screen coords
+* param y absolute screen coords
+* param w width
+* param h height
+*
+* This creates an snapshot in RGBA format (NetSurf's native format)
+*
+*/
+static struct bitmap * snapshot_create(int x, int y, int w, int h);
+
+/* Garbage collection of the snapshot routine */
+/* this should be called after you are done with the data returned by snapshot_create */
+/* don't access the screenshot after you called this function */
+static void snapshot_suspend(void);
+
+/* destroy memory used by screenshot */
+static void snapshot_destroy(void);
+
+/* convert an vdi color to bgra */
+void vdi1000_to_rgb( unsigned short * in, unsigned char * out );
+
+/* convert an bgra color to vdi1000 color */
+void rgb_to_vdi1000( unsigned char * in, unsigned short * out );
+
+/* convert an rgb color to an index into the web palette */
+short rgb_to_666_index(unsigned char r, unsigned char g, unsigned char b);
+
+/* assign vdi line style to dst ( netsurf type ) */
+#define NSLT2VDI(dst, src) \
+ dst = 0;\
+ switch( src->stroke_type ) {\
+ case PLOT_OP_TYPE_DOT: \
+ dst = (0xAAAA00 | 7);\
+ break;\
+ case PLOT_OP_TYPE_DASH:\
+ dst = 3; \
+ break;\
+ case PLOT_OP_TYPE_SOLID:\
+ case PLOT_OP_TYPE_NONE:\
+ default:\
+ dst = 1;\
+ break;\
+ }\
+
+
+#define PLOTTER_IS_LOCKED() ( atari_plot_flags & PLOTTER_FLAG_LOCKED )
+
+
+#ifdef WITH_8BPP_SUPPORT
+/* some Well known indexes into the VDI palette */
+/* common indexes into the VDI palette */
+/* (only used when running with 256 colors or less ) */
+#define OFFSET_WEB_PAL 16
+#define OFFSET_CUST_PAL 232
+#define RGB_TO_VDI(c) rgb_to_666_index( (c&0xFF),(c&0xFF00)>>8,(c&0xFF0000)>>16)+OFFSET_WEB_PAL
+#endif
+
+/* the name of this macro is crap - it should be named bgr_to_rgba ... or so */
+#define ABGR_TO_RGB(c) ( ((c&0xFF)<<16) | (c&0xFF00) | ((c&0xFF0000)>>16) ) << 8
+/* this index into the palette is used by the TC renderer to set current draw color: */
+#define OFFSET_CUSTOM_COLOR 255
+
+#endif
diff --git a/atari/plot/plotter.c b/atari/plot/plotter.c
deleted file mode 100755
index 25d065ec8..000000000
--- a/atari/plot/plotter.c
+++ /dev/null
@@ -1,662 +0,0 @@
-/*
- * Copyright 2010 Ole Loots <ole@monochrom.net>
- *
- * 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/>.
- */
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-#include <windom.h>
-#include <assert.h>
-#include <mint/osbind.h>
-#include <mint/cookie.h>
-#include <Hermes/Hermes.h>
-
-#include "desktop/plot_style.h"
-#include "atari/bitmap.h"
-#include "image/bitmap.h"
-#include "atari/plot/eddi.h"
-#include "atari/plot/plotter.h"
-#include "atari/plot/plotter_vdi.h"
-#ifdef WITH_GD_PLOTTER
- #include "atari/plot/plotter_gd.h"
-#endif
-
-#ifdef WITH_VDI_FONT_DRIVER
- #include "atari/plot/font_vdi.h"
-#endif
-#ifdef WITH_INTERNAL_FONT_DRIVER
- #include "atari/plot/font_internal.h"
-#endif
-#ifdef WITH_FREETYPE_FONT_DRIVER
- #include "atari/plot/font_freetype.h"
-#endif
-#include "atari/gui.h"
-#include "utils/log.h"
-#include "atari/misc.h"
-#include "atari/osspec.h"
-
-
-struct s_driver_table_entry screen_driver_table[] =
-{
- {
- (char*)"vdi",
- ctor_plotter_vdi,
- PLOT_FLAG_HAS_ALPHA,
- 32
- },
-#ifdef WITH_GD_PLOTTER
- {
- (char*)"gd",
- ctor_plotter_gd,
- PLOT_FLAG_OFFSCREEN | PLOT_FLAG_HAS_ALPHA,
- 32
- },
-#endif
- {(char*)NULL, NULL, 0, 0 }
-};
-
-const struct s_font_driver_table_entry font_driver_table[] =
-{
-#ifdef WITH_VDI_FONT_DRIVER
- {"vdi", ctor_font_plotter_vdi, 0},
-#endif
-#ifdef WITH_FREETYPE_FONT_DRIVER
- {"freetype", ctor_font_plotter_freetype, 0},
-#endif
-#ifdef WITH_INTERNAL_FONT_DRIVER
- {"internal", ctor_font_plotter_internal, 0},
-#endif
- {(char*)NULL, NULL, 0}
-};
-
-
-unsigned short vdi_web_pal[216][3] = {
- {0x000,0x000,0x000}, {0x0c8,0x000,0x000}, {0x190,0x000,0x000}, {0x258,0x000,0x000}, {0x320,0x000,0x000}, {0x3e8,0x000,0x000},
- {0x000,0x0c8,0x000}, {0x0c8,0x0c8,0x000}, {0x190,0x0c8,0x000}, {0x258,0x0c8,0x000}, {0x320,0x0c8,0x000}, {0x3e8,0x0c8,0x000},
- {0x000,0x190,0x000}, {0x0c8,0x190,0x000}, {0x190,0x190,0x000}, {0x258,0x190,0x000}, {0x320,0x190,0x000}, {0x3e8,0x190,0x000},
- {0x000,0x258,0x000}, {0x0c8,0x258,0x000}, {0x190,0x258,0x000}, {0x258,0x258,0x000}, {0x320,0x258,0x000}, {0x3e8,0x258,0x000},
- {0x000,0x320,0x000}, {0x0c8,0x320,0x000}, {0x190,0x320,0x000}, {0x258,0x320,0x000}, {0x320,0x320,0x000}, {0x3e8,0x320,0x000},
- {0x000,0x3e8,0x000}, {0x0c8,0x3e8,0x000}, {0x190,0x3e8,0x000}, {0x258,0x3e8,0x000}, {0x320,0x3e8,0x000}, {0x3e8,0x3e8,0x000},
- {0x000,0x000,0x0c8}, {0x0c8,0x000,0x0c8}, {0x190,0x000,0x0c8}, {0x258,0x000,0x0c8}, {0x320,0x000,0x0c8}, {0x3e8,0x000,0x0c8},
- {0x000,0x0c8,0x0c8}, {0x0c8,0x0c8,0x0c8}, {0x190,0x0c8,0x0c8}, {0x258,0x0c8,0x0c8}, {0x320,0x0c8,0x0c8}, {0x3e8,0x0c8,0x0c8},
- {0x000,0x190,0x0c8}, {0x0c8,0x190,0x0c8}, {0x190,0x190,0x0c8}, {0x258,0x190,0x0c8}, {0x320,0x190,0x0c8}, {0x3e8,0x190,0x0c8},
- {0x000,0x258,0x0c8}, {0x0c8,0x258,0x0c8}, {0x190,0x258,0x0c8}, {0x258,0x258,0x0c8}, {0x320,0x258,0x0c8}, {0x3e8,0x258,0x0c8},
- {0x000,0x320,0x0c8}, {0x0c8,0x320,0x0c8}, {0x190,0x320,0x0c8}, {0x258,0x320,0x0c8}, {0x320,0x320,0x0c8}, {0x3e8,0x320,0x0c8},
- {0x000,0x3e8,0x0c8}, {0x0c8,0x3e8,0x0c8}, {0x190,0x3e8,0x0c8}, {0x258,0x3e8,0x0c8}, {0x320,0x3e8,0x0c8}, {0x3e8,0x3e8,0x0c8},
- {0x000,0x000,0x190}, {0x0c8,0x000,0x190}, {0x190,0x000,0x190}, {0x258,0x000,0x190}, {0x320,0x000,0x190}, {0x3e8,0x000,0x190},
- {0x000,0x0c8,0x190}, {0x0c8,0x0c8,0x190}, {0x190,0x0c8,0x190}, {0x258,0x0c8,0x190}, {0x320,0x0c8,0x190}, {0x3e8,0x0c8,0x190},
- {0x000,0x190,0x190}, {0x0c8,0x190,0x190}, {0x190,0x190,0x190}, {0x258,0x190,0x190}, {0x320,0x190,0x190}, {0x3e8,0x190,0x190},
- {0x000,0x258,0x190}, {0x0c8,0x258,0x190}, {0x190,0x258,0x190}, {0x258,0x258,0x190}, {0x320,0x258,0x190}, {0x3e8,0x258,0x190},
- {0x000,0x320,0x190}, {0x0c8,0x320,0x190}, {0x190,0x320,0x190}, {0x258,0x320,0x190}, {0x320,0x320,0x190}, {0x3e8,0x320,0x190},
- {0x000,0x3e8,0x190}, {0x0c8,0x3e8,0x190}, {0x190,0x3e8,0x190}, {0x258,0x3e8,0x190}, {0x320,0x3e8,0x190}, {0x3e8,0x3e8,0x190},
- {0x000,0x000,0x258}, {0x0c8,0x000,0x258}, {0x190,0x000,0x258}, {0x258,0x000,0x258}, {0x320,0x000,0x258}, {0x3e8,0x000,0x258},
- {0x000,0x0c8,0x258}, {0x0c8,0x0c8,0x258}, {0x190,0x0c8,0x258}, {0x258,0x0c8,0x258}, {0x320,0x0c8,0x258}, {0x3e8,0x0c8,0x258},
- {0x000,0x190,0x258}, {0x0c8,0x190,0x258}, {0x190,0x190,0x258}, {0x258,0x190,0x258}, {0x320,0x190,0x258}, {0x3e8,0x190,0x258},
- {0x000,0x258,0x258}, {0x0c8,0x258,0x258}, {0x190,0x258,0x258}, {0x258,0x258,0x258}, {0x320,0x258,0x258}, {0x3e8,0x258,0x258},
- {0x000,0x320,0x258}, {0x0c8,0x320,0x258}, {0x190,0x320,0x258}, {0x258,0x320,0x258}, {0x320,0x320,0x258}, {0x3e8,0x320,0x258},
- {0x000,0x3e8,0x258}, {0x0c8,0x3e8,0x258}, {0x190,0x3e8,0x258}, {0x258,0x3e8,0x258}, {0x320,0x3e8,0x258}, {0x3e8,0x3e8,0x258},
- {0x000,0x000,0x320}, {0x0c8,0x000,0x320}, {0x190,0x000,0x320}, {0x258,0x000,0x320}, {0x320,0x000,0x320}, {0x3e8,0x000,0x320},
- {0x000,0x0c8,0x320}, {0x0c8,0x0c8,0x320}, {0x190,0x0c8,0x320}, {0x258,0x0c8,0x320}, {0x320,0x0c8,0x320}, {0x3e8,0x0c8,0x320},
- {0x000,0x190,0x320}, {0x0c8,0x190,0x320}, {0x190,0x190,0x320}, {0x258,0x190,0x320}, {0x320,0x190,0x320}, {0x3e8,0x190,0x320},
- {0x000,0x258,0x320}, {0x0c8,0x258,0x320}, {0x190,0x258,0x320}, {0x258,0x258,0x320}, {0x320,0x258,0x320}, {0x3e8,0x258,0x320},
- {0x000,0x320,0x320}, {0x0c8,0x320,0x320}, {0x190,0x320,0x320}, {0x258,0x320,0x320}, {0x320,0x320,0x320}, {0x3e8,0x320,0x320},
- {0x000,0x3e8,0x320}, {0x0c8,0x3e8,0x320}, {0x190,0x3e8,0x320}, {0x258,0x3e8,0x320}, {0x320,0x3e8,0x320}, {0x3e8,0x3e8,0x320},
- {0x000,0x000,0x3e8}, {0x0c8,0x000,0x3e8}, {0x190,0x000,0x3e8}, {0x258,0x000,0x3e8}, {0x320,0x000,0x3e8}, {0x3e8,0x000,0x3e8},
- {0x000,0x0c8,0x3e8}, {0x0c8,0x0c8,0x3e8}, {0x190,0x0c8,0x3e8}, {0x258,0x0c8,0x3e8}, {0x320,0x0c8,0x3e8}, {0x3e8,0x0c8,0x3e8},
- {0x000,0x190,0x3e8}, {0x0c8,0x190,0x3e8}, {0x190,0x190,0x3e8}, {0x258,0x190,0x3e8}, {0x320,0x190,0x3e8}, {0x3e8,0x190,0x3e8},
- {0x000,0x258,0x3e8}, {0x0c8,0x258,0x3e8}, {0x190,0x258,0x3e8}, {0x258,0x258,0x3e8}, {0x320,0x258,0x3e8}, {0x3e8,0x258,0x3e8},
- {0x000,0x320,0x3e8}, {0x0c8,0x320,0x3e8}, {0x190,0x320,0x3e8}, {0x258,0x320,0x3e8}, {0x320,0x320,0x3e8}, {0x3e8,0x320,0x3e8},
- {0x000,0x3e8,0x3e8}, {0x0c8,0x3e8,0x3e8}, {0x190,0x3e8,0x3e8}, {0x258,0x3e8,0x3e8}, {0x320,0x3e8,0x3e8}, {0x3e8,0x3e8,0x3e8}
-};
-
-
-/* get index to driver in driver list by name */
-static int drvrname_idx( char * name );
-
-/* Error code translations: */
-static const char * plot_error_codes[] =
-{
- "None",
- "ERR_BUFFERSIZE_EXCEEDS_SCREEN",
- "ERR_NO_MEM",
- "ERR_PLOTTER_NOT_AVAILABLE"
-};
-
-struct s_vdi_sysinfo vdi_sysinfo;
-
-struct s_vdi_sysinfo * read_vdi_sysinfo( short vdih, struct s_vdi_sysinfo * info ) {
-
- unsigned long cookie_EdDI=0;
- short out[300];
- memset( info, 0, sizeof(struct s_vdi_sysinfo) );
-
- info->vdi_handle = vdih;
- if ( tos_getcookie(C_EdDI, &cookie_EdDI) == C_NOTFOUND ) {
- info->EdDiVersion = 0;
- } else {
- info->EdDiVersion = EdDI_version( (void *)cookie_EdDI );
- }
-
- memset( &out, 0, sizeof(short)*300 );
- vq_extnd( vdih, 0, (short*)&out );
- info->scr_w = out[0]+1;
- info->scr_h = out[1]+1;
- if( out[39] == 2 ) {
- info->scr_bpp = 1;
- info->colors = out[39];
- } else {
- info->colors = out[39];
- }
-
- memset( &out, 0, sizeof(short)*300 );
- vq_extnd( vdih, 1, (short*)&out );
- info->scr_bpp = out[4];
- info->maxpolycoords = out[14];
- info->maxintin = out[15];
- if( out[30] & 1 ) {
- info->rasterscale = true;
- } else {
- info->rasterscale = false;
- }
-
- switch( info->scr_bpp ) {
- case 8:
- info->pixelsize=1;
- break;
- case 15:
- case 16:
- info->pixelsize=2;
- break;
- case 24:
- info->pixelsize=3;
- break;
- case 32:
- info->pixelsize=4;
- break;
- case 64:
- info->pixelsize=8;
- break;
- default:
- info->pixelsize=1;
- break;
-
- }
- info->pitch = info->scr_w * info->pixelsize;
- info->vdiformat = ( (info->scr_bpp <= 8) ? VDI_FORMAT_INTER : VDI_FORMAT_PACK);
- info->screensize = ( info->scr_w * info->pixelsize ) * info->scr_h;
-
- if( info->EdDiVersion >= EDDI_10 ) {
- memset( &out, 0, sizeof(short)*300 );
- vq_scrninfo(vdih, (short*)&out);
- info->vdiformat = out[0];
- info->clut = out[1];
- info->scr_bpp = out[2];
- info->hicolors = *((unsigned long*) &out[3]);
- if( info->EdDiVersion >= EDDI_11 ) {
- info->pitch = out[5];
- info->screen = (void *) *((unsigned long *) &out[6]);
- }
-
- switch( info->clut ) {
-
- case VDI_CLUT_HARDWARE:
- {
-
- }
- break;
-
- case VDI_CLUT_SOFTWARE:
- {
- int component; /* red, green, blue, alpha, overlay */
- int num_bit;
- unsigned short *tmp_p;
-
- /* We can build masks with info here */
- tmp_p = (unsigned short *) &out[16];
- for (component=0;component<5;component++) {
- for (num_bit=0;num_bit<16;num_bit++) {
- unsigned short val;
-
- val = *tmp_p++;
-
- if (val == 0xffff) {
- continue;
- }
-
- switch(component) {
- case 0:
- info->mask_r |= 1<< val;
- break;
- case 1:
- info->mask_g |= 1<< val;
- break;
- case 2:
- info->mask_b |= 1<< val;
- break;
- case 3:
- info->mask_a |= 1<< val;
- break;
- }
- }
- }
- }
-
- /* Remove lower green bits for Intel endian screen */
- if ((info->mask_g == ((7<<13)|3)) || (info->mask_g == ((7<<13)|7))) {
- info->mask_g &= ~(7<<13);
- }
- break;
-
- case VDI_CLUT_NONE:
- break;
- }
- }
-}
-
-
-/*
- lookup an plotter ID by name
-*/
-static int drvrname_idx( char * name )
-{
- int i;
- for( i = 0; ; i++) {
- if( screen_driver_table[i].name == NULL ) {
- return( -1 );
- }
- else {
- if( strcmp(name, screen_driver_table[i].name) == 0 ) {
- return( i );
- }
- }
- }
-}
-
-/*
- lookup of font plotter ID by name
-*/
-static int font_drvrname_idx( char * name )
-{
- int i;
- for( i = 0; ; i++) {
- if( font_driver_table[i].name == NULL ) {
- return( -1 );
- }
- else {
- if( strcmp(name, font_driver_table[i].name) == 0 ) {
- return( i );
- }
- }
- }
-}
-
-/*
- Get an plotter info entry, the entry contains an pointer to ctor
-*/
-struct s_driver_table_entry * get_screen_driver_entry( char * name )
-{
- int idx = drvrname_idx( name );
- if( idx < 0 )
- return( 0 );
- else
- return( &screen_driver_table[idx] );
-}
-
-/*
- Get an font plotter info entry, the entry contains an pointer to ctor.
-*/
-struct s_font_driver_table_entry * get_font_driver_entry( char * name )
-{
- int idx = font_drvrname_idx( name );
- if( idx < 0 )
- return( 0 );
- else
- return( (struct s_font_driver_table_entry *)&font_driver_table[idx] );
-}
-
-
-/*
- Create an new text plotter object
-*/
-FONT_PLOTTER new_font_plotter( int vdihandle, char * name, unsigned long flags, int * error)
-{
- int i=0;
- int res = 0-ERR_PLOTTER_NOT_AVAILABLE;
- FONT_PLOTTER fplotter = (FONT_PLOTTER)malloc( sizeof(struct s_font_plotter) );
- if( fplotter == NULL ) {
- *error = 0-ERR_NO_MEM;
- return( NULL );
- }
- memset( fplotter, 0, sizeof(FONT_PLOTTER));
- fplotter->vdi_handle = vdihandle;
- fplotter->name = name;
- fplotter->flags = 0;
- fplotter->flags |= flags;
- for( i = 0; ; i++) {
- if( font_driver_table[i].name == NULL ) {
- res = 0-ERR_PLOTTER_NOT_AVAILABLE;
- break;
- } else {
- if( strcmp(name, font_driver_table[i].name) == 0 ) {
- if( font_driver_table[i].ctor ) {
- res = font_driver_table[i].ctor( fplotter );
- *error = 0;
- } else {
- res = 0-ERR_PLOTTER_NOT_AVAILABLE;
- *error = res;
- return (NULL);
- }
- break;
- }
- }
- }
- if( res < 0 ) {
- free( fplotter );
- *error = res;
- return( NULL );
- }
- fplotter->plotter = NULL;
- return( fplotter );
-}
-
-static bool init=false;
-static int inst=0;
-
-/*
- Create an new plotter object
-*/
-GEM_PLOTTER new_plotter(int vdihandle, char * name, GRECT * loc_size,
- int virt_bpp, unsigned long flags, FONT_PLOTTER fplotter, int * error )
-{
- int res = 0-ERR_PLOTTER_NOT_AVAILABLE;
- int i;
- assert( fplotter != NULL );
-
- GEM_PLOTTER gemplotter = (GEM_PLOTTER)malloc( sizeof(struct s_gem_plotter) );
- if( !gemplotter ) {
- *error = 0-ERR_NO_MEM;
- return( NULL );
- }
- memset( gemplotter, 0, sizeof(struct s_gem_plotter));
-
- gemplotter->name = name;
- gemplotter->vdi_handle = vdihandle;
- gemplotter->flags = 0;
- gemplotter->font_plotter = fplotter;
- gemplotter->bpp_virt = virt_bpp;
-
- /* request vdi info once, so every plotter is able to access the info */
- if( !init ) {
- /* vdi_sysinfo */
- read_vdi_sysinfo( vdihandle, &vdi_sysinfo );
- init = true;
- }
- for( i = 0; ; i++) {
- if( screen_driver_table[i].name == NULL ) {
- res = 0-ERR_PLOTTER_NOT_AVAILABLE;
- break;
- }
- else {
- if( strcmp(name, screen_driver_table[i].name) == 0 ) {
- if( screen_driver_table[i].ctor ) {
- gemplotter->flags = (screen_driver_table[i].flags | flags);
- res = screen_driver_table[i].ctor( gemplotter, loc_size );
- *error = 0;
- } else {
- res = 0-ERR_PLOTTER_NOT_AVAILABLE;
- *error = res;
- return (NULL);
- }
- break;
- }
- }
- }
- if( res < 0 ) {
- free( gemplotter );
- *error = res;
- return( NULL );
- }
- inst++;
- gemplotter->font_plotter->plotter = gemplotter;
- return( gemplotter );
-}
-
-/*
- Free an plotter
-*/
-int delete_plotter( GEM_PLOTTER p )
-{
- if( p ) {
- p->dtor( p );
- free( p );
- p = NULL;
- inst--;
- if( inst == 0 ){
-
- }
- }
- else
- return( -1 );
- return( 0 );
-}
-
-/*
- Free an font plotter
-*/
-int delete_font_plotter( FONT_PLOTTER p )
-{
- if( p ) {
- p->dtor(p);
- free( p );
- p = NULL;
- }
- else
- return( -1 );
- return( 0 );
-}
-
-/*
- x - x coord
- y - y coord
- stride - stride in bytes
- bpp - bits per pixel
-*/
-int calc_chunked_buffer_size(int x, int y, int stride, int bpp)
-{
- return( (x * (bpp >> 3)) * y );
-}
-
-/*
- x - x coord
- y - y coord
- stride - stride in bytes
- bpp - bits per pixel
-*/
-int get_pixel_offset( int x, int y, int stride, int bpp )
-{
- LOG(("byte_pp: %d, pure: %d, result: %d\n",(bpp >> 3),(y * stride + x), (y * stride + x) * (bpp >> 3)));
- return( ( (y * stride) + x) * (bpp >> 3) );
-}
-
-const char* plotter_err_str(int i) { return(plot_error_codes[abs(i)]); }
-
-void dump_vdi_info( short vdih )
-{
- struct s_vdi_sysinfo temp;
- read_vdi_sysinfo( vdih, &temp );
- printf("struct s_vdi_sysinfo {\n");
- printf(" short vdi_handle: %d\n", temp.vdi_handle);
- printf(" short scr_w: %d \n", temp.scr_w);
- printf(" short scr_h: %d\n", temp.scr_h);
- printf(" short scr_bpp: %d\n", temp.scr_bpp);
- printf(" int colors: %d\n", temp.colors);
- printf(" ulong hicolors: %d\n", temp.hicolors);
- printf(" short pixelsize: %d\n", temp.pixelsize);
- printf(" unsigned short pitch: %d\n", temp.pitch);
- printf(" unsigned short vdiformat: %d\n", temp.vdiformat);
- printf(" unsigned short clut: %d\n", temp.clut);
- printf(" void * screen: 0x0%p\n", temp.screen);
- printf(" unsigned long screensize: %d\n", temp.screensize);
- printf(" unsigned long mask_r: 0x0%08x\n", temp.mask_r);
- printf(" unsigned long mask_g: 0x0%08x\n", temp.mask_g);
- printf(" unsigned long mask_b: 0x0%08x\n", temp.mask_b);
- printf(" unsigned long mask_a: 0x0%08x\n", temp.mask_a);
- printf(" short maxintin: %d\n", temp.maxintin);
- printf(" short maxpolycoords: %d\n", temp.maxpolycoords);
- printf(" unsigned long EdDiVersion: 0x0%03x\n", temp.EdDiVersion);
- printf(" unsigned short rasterscale: 0x%2x\n", temp.rasterscale);
- printf("};\n");
-}
-
-void dump_plot_drivers(void)
-{
- int i = 0;
- while( screen_driver_table[i].name != NULL ) {
- printf("%s -> max_bpp: %d, flags: %d\n",
- screen_driver_table[i].name,
- screen_driver_table[i].max_bpp,
- screen_driver_table[i].flags
- );
- i++;
- }
-}
-
-void dump_font_drivers(void)
-{
- int i = 0;
- while( font_driver_table[i].name != NULL ) {
- printf("%s -> flags: %d\n",
- font_driver_table[i].name,
- font_driver_table[i].flags
- );
- i++;
- }
-}
-
-/*
- bpp: bits per pixel,
-
-*/
-int init_mfdb(int bpp, int w, int h, uint32_t flags, MFDB * out )
-{
- int dststride;
- dststride = MFDB_STRIDE( w );
- int size = MFDB_SIZE( bpp, dststride, h );
- if( bpp > 0 ) {
- if( (flags & MFDB_FLAG_NOALLOC) == 0 ) {
- out->fd_addr = malloc( size );
- if( out->fd_addr == NULL ){
- return( 0 );
- }
- if( (flags & MFDB_FLAG_ZEROMEM) ){
- memset( out->fd_addr, 0, size );
- }
- }
- out->fd_stand = (flags & MFDB_FLAG_STAND) ? 1 : 0;
- out->fd_nplanes = (short)bpp;
- out->fd_r1 = out->fd_r2 = out->fd_r3 = 0;
- } else {
- memset( out, 0, sizeof(MFDB) );
- }
- out->fd_w = dststride;
- out->fd_h = h;
- out->fd_wdwidth = dststride >> 4;
- return( size );
-}
-
-void plotter_get_clip_grect( GEM_PLOTTER self, GRECT * out )
-{
- struct rect clip;
- self->get_clip( self, &clip );
- out->g_x = clip.x0;
- out->g_y = clip.y0;
- out->g_w = clip.x1 - clip.x0;
- out->g_h = clip.y1 - clip.y0;
-}
-
-/*
- Convert an RGB color to an VDI Color
-*/
-void rgb_to_vdi1000( unsigned char * in, unsigned short * out )
-{
- double r = ((double)in[3]/255); /* prozentsatz red */
- double g = ((double)in[2]/255); /* prozentsatz green */
- double b = ((double)in[1]/255); /* prozentsatz blue */
- out[0] = 1000 * r + 0.5;
- out[1] = 1000 * g + 0.5;
- out[2] = 1000 * b + 0.5;
- return;
-}
-
-void vdi1000_to_rgb( unsigned short * in, unsigned char * out )
-{
- double r = ((double)in[0]/1000); /* prozentsatz red */
- double g = ((double)in[1]/1000); /* prozentsatz green */
- double b = ((double)in[2]/1000); /* prozentsatz blue */
- out[2] = 255 * r + 0.5;
- out[1] = 255 * g + 0.5;
- out[0] = 255 * b + 0.5;
- return;
-}
-
-
-#ifdef WITH_8BPP_SUPPORT
-
-
-short web_std_colors[6] = {0, 51, 102, 153, 204, 255};
-
-/*
- Convert an RGB color into an index into the 216 colors web pallette
-*/
-short rgb_to_666_index(unsigned char r, unsigned char g, unsigned char b)
-{
- short ret = 0;
- short i;
- unsigned char rgb[3] = {r,g,b};
- unsigned char tval[3];
-
- int diff_a, diff_b, diff_c;
- diff_a = abs(r-g);
- diff_b = abs(r-b);
- diff_c = abs(r-b);
- if( diff_a < 2 && diff_b < 2 && diff_c < 2 ){
- if( (r!=0XFF) && (g!=0XFF) && (g!=0XFF) ){
- if( ((r&0xF0)>>4) != 0 )
- //printf("conv gray: %x -> %d\n", ((r&0xF0)>>4) , (OFFSET_CUST_PAL) + ((r&0xF0)>>4) );
- return( (OFFSET_CUST_PAL - OFFSET_WEB_PAL) + ((r&0xF0)>>4) );
- }
- }
-
- /* convert each 8bit color to 6bit web color: */
- for( i=0; i<3; i++) {
- if(0 == rgb[i] % web_std_colors[1] ) {
- tval[i] = rgb[i] / web_std_colors[1];
- }
- else {
- int pos = ((short)rgb[i] / web_std_colors[1]);
- if( abs(rgb[i] - web_std_colors[pos]) > abs(rgb[i] - web_std_colors[pos+1]) )
- tval[i] = pos+1;
- else
- tval[i] = pos;
- }
- }
- return( tval[2]*36+tval[1]*6+tval[0] );
-}
-#endif
-
-
diff --git a/atari/plot/plotter.h b/atari/plot/plotter.h
deleted file mode 100755
index 40fe6c62d..000000000
--- a/atari/plot/plotter.h
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
- * Copyright 2010 Ole Loots <ole@monochrom.net>
- *
- * 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/>.
- */
-#ifndef _GEM_PLOTTER_API_H_
-#define _GEM_PLOTTER_API_H_
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <math.h>
-#include <assert.h>
-#include <string.h>
-#include <windom.h>
-
-#include "desktop/plotters.h"
-#include "desktop/plot_style.h"
-#include "image/bitmap.h"
-#include "atari/bitmap.h"
-#include "atari/osspec.h"
-#include "atari/gui.h"
-#include "atari/font.h"
-#include "desktop/options.h"
-#include "atari/findfile.h"
-#include "utils/utf8.h"
-#include "utils/log.h"
-
-#ifndef ceilf
-#warning "ceilf emulation"
-#define ceilf(x) (float)ceil((double)x)
-#endif
-
-#ifdef TEST_PLOTTER
-#define verbose_log 1
-#define LOG(x) do { if (verbose_log) (printf(__FILE__ " %s %i: ", __PRETTY_FUNCTION__, __LINE__), printf x, fputc('\n', stdout)); } while (0)
-#endif
-
-#define MAX_FRAMEBUFS 0x010
-#define C2P (1<<0) /* C2P convert buffer 1 to buffer 2 */
-/* TODO: implement offscreen buffer switch */
-
-/* Plotter Option Flags: */
-#define PLOT_FLAG_DITHER 0x04 /* true if the plotter shall dither images */
-#define PLOT_FLAG_TRANS 0x08 /* true if the plotter supports transparent operations */
-
-/* Plotter "feature" flags */
-#define PLOT_FLAG_HAS_DITHER 0x0400
-#define PLOT_FLAG_HAS_ALPHA 0x0800
-#define PLOT_FLAG_OFFSCREEN 0x1000 /* offsreen plotter should set this flag */
-
-/* Plotter "internal" flags */
-#define PLOT_FLAG_LOCKED 0x08000 /* plotter should set this flag during screen updates */
-
-/* Font Plotter flags: */
-#define FONTPLOT_FLAG_MONOGLYPH 0x01
-
-/* Flags for init_mfdb function: */
-#define MFDB_FLAG_STAND 0x01
-#define MFDB_FLAG_ZEROMEM 0x02
-#define MFDB_FLAG_NOALLOC 0x04
-
-/* Flags for blit functions: */
-#define BITMAPF_MONOGLYPH 4096 /* The bitmap is an character bitmap */
-#define BITMAPF_BUFFER_NATIVE 8192 /* Bitmap shall be kept converted */
-
-/* Error codes: */
-#define ERR_BUFFERSIZE_EXCEEDS_SCREEN 1 /* The buffer allocated is larger than the screen */
-#define ERR_NO_MEM 2 /* Not enough memory for requested operation */
-#define ERR_PLOTTER_NOT_AVAILABLE 3 /* invalid plotter driver name passed */
-
-/* Grapics & Font Plotter "Objects": */
-typedef struct s_font_plotter * FONT_PLOTTER;
-typedef struct s_gem_plotter * GEM_PLOTTER;
-typedef struct s_font_plotter * GEM_FONT_PLOTTER; /* for public use ... */
-
-
-/* declaration of font plotter member functions: (_fpmf_ prefix) */
-typedef int (*_fpmf_str_width)( FONT_PLOTTER self, const plot_font_style_t *fstyle,
- const char * str, size_t length, int * width);
-typedef int (*_fpmf_str_split)( FONT_PLOTTER self, const plot_font_style_t *fstyle,
- const char *string, size_t length,
- int x, size_t *char_offset, int *actual_x);
-typedef int (*_fpmf_pixel_pos)( FONT_PLOTTER self, const plot_font_style_t *fstyle,
- const char *string, size_t length,
- int x, size_t *char_offset, int *actual_x);
-typedef int (*_fpmf_text)( FONT_PLOTTER self, int x, int y, const char *text,
- size_t length, const plot_font_style_t *fstyle);
-
-typedef void (*_fpmf_draw_glyph)(FONT_PLOTTER self, GRECT * clip, GRECT * loc,
- uint8_t * pixdata, int pitch, uint32_t colour);
-typedef int (*_fpmf_dtor)( FONT_PLOTTER self );
-
-
-/* prototype of the font plotter "object" */
-struct s_font_plotter
-{
- char * name;
- int flags;
- int vdi_handle;
- void * priv_data;
- GEM_PLOTTER plotter;
-
- _fpmf_str_width str_width;
- _fpmf_str_split str_split;
- _fpmf_pixel_pos pixel_pos;
- _fpmf_text text;
- _fpmf_draw_glyph draw_glyph;
- _fpmf_dtor dtor;
-};
-
-
-struct rect;
-
-struct s_vdi_sysinfo {
- short vdi_handle; /* vdi handle */
- short scr_w; /* resolution horz. */
- short scr_h; /* resolution vert. */
- short scr_bpp; /* bits per pixel */
- int colors; /* 0=hiclor, 2=mono */
- unsigned long hicolors; /* if colors = 0 */
- short pixelsize; /* bytes per pixel */
- unsigned short pitch; /* row pitch */
- unsigned short vdiformat; /* pixel format */
- unsigned short clut; /* type of clut support */
- void * screen; /* pointer to screen, or NULL */
- unsigned long screensize;/* size of screen (in bytes) */
- unsigned long mask_r; /* color masks */
- unsigned long mask_g;
- unsigned long mask_b;
- unsigned long mask_a;
- short maxintin; /* maximum pxy items */
- short maxpolycoords; /* max coords for p_line etc. */
- unsigned long EdDiVersion;/* EdDi Version or 0 */
- bool rasterscale; /* raster scaling support */
-};
-
-
-/* declaration of plotter member functions ( _pmf_ prefix )*/
-typedef int (*_pmf_resize)(GEM_PLOTTER self, int w, int h);
-typedef int (*_pmf_move)(GEM_PLOTTER self, short x, short y );
-typedef void * (*_pmf_create_framebuffer)(GEM_PLOTTER self);
-typedef void * (*_pmf_switch_to_framebuffer)(GEM_PLOTTER self);
-typedef int (*_pmf_lock)(GEM_PLOTTER self);
-typedef int (*_pmf_unlock)(GEM_PLOTTER self);
-typedef int (*_pmf_put_pixel)(GEM_PLOTTER self, int x, int y, int color );
-typedef int (*_pmf_copy_rect)(GEM_PLOTTER self, GRECT src, GRECT dst );
-typedef int (*_pmf_set_clip)(GEM_PLOTTER self, const struct rect * clip );
-typedef int (*_pmf_get_clip)(GEM_PLOTTER self, struct rect * clip_out );
-typedef int (*_pmf_arc)(GEM_PLOTTER self, int x, int y, int radius, int angle1, int angle2, const plot_style_t * pstyle);
-typedef int (*_pmf_disc)(GEM_PLOTTER self, int x, int y, int radius, const plot_style_t * pstyle);
-typedef int (*_pmf_line)(GEM_PLOTTER self, int x0, int y0, int x1, int y1, const plot_style_t * pstyle);
-typedef int (*_pmf_rectangle)(GEM_PLOTTER self, int x0, int y0, int x1, int y1, const plot_style_t * pstyle);
-typedef int (*_pmf_polygon)(GEM_PLOTTER self, const int *p, unsigned int n, const plot_style_t * pstyle);
-typedef int (*_pmf_path)(GEM_PLOTTER self, const float *p, unsigned int n, int fill, float width, int c, const float transform[6]);
-typedef int (*_pmf_bitmap_resize) ( GEM_PLOTTER self, struct bitmap * bm, int nw, int nh );
-typedef int (*_pmf_bitmap_convert)( GEM_PLOTTER self, struct bitmap * img, int x, int y,
- GRECT * clip, uint32_t bg, uint32_t flags, MFDB *out );
-typedef int (*_pmf_bitmap)(GEM_PLOTTER self, struct bitmap * bmp, int x, int y,
- unsigned long bg, unsigned long flags );
-typedef int (*_pmf_plot_mfdb)(GEM_PLOTTER self, GRECT * loc, MFDB * mfdb, unsigned char fgcolor, uint32_t flags);
-typedef int (*_pmf_text)(GEM_PLOTTER self, int x, int y, const char *text, size_t length, const plot_font_style_t *fstyle);
-typedef int (*_pmf_blit)(GEM_PLOTTER self, GRECT * region);
-typedef int (*_pmf_dtor)(GEM_PLOTTER self);
-
-
-/* this is the prototype of an plotter "object" */
-struct s_gem_plotter
-{
- char * name; /* name that identifies the Plotter */
- unsigned long flags;
- int vdi_handle;
- struct s_vdi_sysinfo * scr;
- void * priv_data;
- /* bit depth of framebuffers: */
- int bpp_virt;
-
- FONT_PLOTTER font_plotter;
- /* set new dimensions (realloc memory): */
- _pmf_resize resize;
- /* set drawing origin: */
- _pmf_move move;
- _pmf_lock lock;
- _pmf_unlock unlock;
- _pmf_create_framebuffer create_framebuffer;
- _pmf_switch_to_framebuffer switch_to_framebuffer;
- _pmf_put_pixel put_pixel;
- _pmf_copy_rect copy_rect;
- _pmf_set_clip set_clip;
- _pmf_get_clip get_clip;
- _pmf_arc arc;
- _pmf_disc disc;
- _pmf_line line;
- _pmf_rectangle rectangle;
- _pmf_polygon polygon;
- _pmf_path path;
- /* scale an netsurf bitmap: */
- _pmf_bitmap_resize bitmap_resize;
- /* convert an ABGR (netsurf) bitmap to screen format, ready for vro_cpyfm */
- _pmf_bitmap_convert bitmap_convert;
- /* plot an netsurf bitmap into the buffer / screen: */
- _pmf_bitmap bitmap;
- /* plot an mfdb into the buffer / screen: */
- _pmf_plot_mfdb plot_mfdb;
- /* draw to screen, only valid for offscreen plotters: */
- _pmf_blit blit;
- _pmf_text text;
- _pmf_dtor dtor;
-};
-
-
-/* these 2 structs hold info about an specific driver. */
-/* a table in plotter.c defines all the available plotters */
-struct s_driver_table_entry
-{
-
- /* name (unique) */
- char * name;
-
- /* pointer to ctor of the plotter */
- int (*ctor)( GEM_PLOTTER self, GRECT * log_isze );
-
- /* a bitmask containing info about supported operations */
- int flags;
-
- /* the maximum supported screen depth of the plotter */
- int max_bpp;
-};
-
-struct s_font_driver_table_entry
-{
- const char * name;
- int (*ctor)( FONT_PLOTTER self );
- int flags;
-};
-
-typedef struct s_driver_table_entry * PLOTTER_INFO;
-typedef struct s_font_driver_table_entry * FONT_PLOTTER_INFO;
-
-/* get s_driver_table_entry from driver table */
-struct s_driver_table_entry * get_screen_driver_entry(char * name);
-
-/* get s_font_driver_table_entry from driver table */
-struct s_font_driver_table_entry * get_font_driver_entry(char * name);
-
-/* fill screen / sys info */
-struct s_vdi_sysinfo * read_vdi_sysinfo(short vdih, struct s_vdi_sysinfo * info );
-
-/*
- Create an new plotter object
- Error Values:
- -1 no mem
- -2 error configuring plotter
- -3 Plotter not available
-*/
-GEM_PLOTTER new_plotter(int vdihandle, char * name,
- GRECT *, int virt_bpp, unsigned long flags, FONT_PLOTTER font_renderer,
- int * error);
-
-/*
- Create an new font plotter object
- Error Values:
- -1 no mem
- -2 error configuring font plotter
- -3 Font Plotter not available
-*/
-FONT_PLOTTER new_font_plotter(int vdihandle, char * name, unsigned long flags, int * error );
-
-/* free the plotter resources */
-int delete_plotter( GEM_PLOTTER p );
-int delete_font_plotter( FONT_PLOTTER p );
-
-
-/* calculate size of intermediate buffer */
-int calc_chunked_buffer_size(int x, int y, int stride, int bpp);
-
-/* calculates the pixel offset from x,y pos */
-int get_pixel_offset( int x, int y, int stride, int bpp );
-
-/* translate an error number */
-const char* plotter_err_str(int i) ;
-
-void dump_font_drivers(void);
-void dump_plot_drivers(void);
-void dump_vdi_info(short);
-
-/* convert an vdi color to bgra */
-void vdi1000_to_rgb( unsigned short * in, unsigned char * out );
-
-/* convert an bgra color to vdi1000 color */
-void rgb_to_vdi1000( unsigned char * in, unsigned short * out );
-
-/* convert an rgb color to an index into the web palette */
-short rgb_to_666_index(unsigned char r, unsigned char g, unsigned char b);
-
-/*
- setup an MFDB struct and allocate memory for it when it is needed.
- If bpp == 0, this function assumes that the MFDB shall point to the screen
- and will not allocate any memory (mfdb.fd_addr == 0).
- The function will return 0 when the memory allocation fails
- ( out of memory), otherwise it returns the size of the mfdb.fd_addr
- as number of bytes.
-*/
-int init_mfdb(int bpp, int w, int h, uint32_t flags, MFDB * out );
-
-/* shared / static methods follows */
-
-/*
- Get clipping for current framebuffer
-*/
-int plotter_get_clip( GEM_PLOTTER self, struct rect * out );
-
-/*
- Get clipping for current framebuffer as GRECT
-*/
-void plotter_get_clip_grect( GEM_PLOTTER self, GRECT * out );
-
-
-#define PLOTTER_IS_LOCKED(plotter) ( plotter->private_flags & PLOTTER_FLAG_LOCKED )
-
-
-/*
- calculates MFDB compatible rowstride (in number of bits)
-*/
-#define MFDB_STRIDE( w ) (((w & 15) != 0) ? (w | 15)+1 : w)
-
-/*
-Calculate size of an mfdb,
-
- params:
-
- bpp: Bits per pixel,
- stride: Word aligned rowstride (width) as returned by MFDB_STRIDE,
- h: Height in pixels
-*/
-#define MFDB_SIZE( bpp, stride, h ) ( ((stride >> 3) * h) * bpp )
-
-#ifdef WITH_8BPP_SUPPORT
-/* some Well known indexes into the VDI palette */
-/* common indexes into the VDI palette */
-/* (only used when running with 256 colors or less ) */
-#define OFFSET_WEB_PAL 16
-#define OFFSET_CUST_PAL 232
-#define RGB_TO_VDI(c) rgb_to_666_index( (c&0xFF),(c&0xFF00)>>8,(c&0xFF0000)>>16)+OFFSET_WEB_PAL
-#endif
-
-/* the name of this macro is crap - it should be named bgr_to_rgba ... or so */
-#define ABGR_TO_RGB(c) ( ((c&0xFF)<<16) | (c&0xFF00) | ((c&0xFF0000)>>16) ) << 8
-/* this index into the palette is used by the TC renderer to set current draw color: */
-#define OFFSET_CUSTOM_COLOR 255
-
-
-#endif
diff --git a/atari/plot/plotter_gd.c b/atari/plot/plotter_gd.c
deleted file mode 100644
index 39b44be07..000000000
--- a/atari/plot/plotter_gd.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * Copyright 2012 Ole Loots <ole@monochrom.net>
- *
- * 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/>.
- */
-
-#ifdef WITH_GD_PLOTTER
-
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-#include <assert.h>
-#include <windom.h>
-#include <gd.h>
-
-#include "atari/plot/eddi.h"
-#include "atari/plot/plotter.h"
-#include "atari/plot/plotter_gd.h"
-
-#include "plotter.h"
-
-static int dtor( GEM_PLOTTER self );
-static int resize( GEM_PLOTTER self, int w, int h );
-static int move( GEM_PLOTTER self, short x, short y );
-static int lock( GEM_PLOTTER self );
-static int unlock( GEM_PLOTTER self );
-static int put_pixel(GEM_PLOTTER self, int x, int y, int color );
-static int copy_rect( GEM_PLOTTER self, GRECT src, GRECT dst );
-static int get_clip( GEM_PLOTTER instance, struct rect * clip);
-static int set_clip( GEM_PLOTTER instance, const struct rect * clip );
-static int arc(GEM_PLOTTER self,int x, int y, int radius, int angle1, int angle2, const plot_style_t * pstyle);
-static int disc(GEM_PLOTTER self,int x, int y, int radius, const plot_style_t * pstyle);
-static int line(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle);
-static int rectangle(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle);
-static int polygon(GEM_PLOTTER self,const int *p, unsigned int n, const plot_style_t * pstyle);
-static int path(GEM_PLOTTER self,const float *p, unsigned int n, int fill, float width, int c, const float transform[6]);
-static int bitmap_resize( GEM_PLOTTER self, struct bitmap * img, int nw, int nh );
-static int bitmap_convert( GEM_PLOTTER self, struct bitmap * img, int x, int y,
- GRECT * clip,uint32_t bg,uint32_t flags, MFDB *out );
-static int bitmap( GEM_PLOTTER self, struct bitmap * bmp, int x, int y,
- unsigned long bg, unsigned long flags );
-static int plot_mfdb( GEM_PLOTTER self, GRECT * where, MFDB * mfdb, unsigned char fgcolor, uint32_t flags);
-static int text(GEM_PLOTTER self, int x, int y, const char *text,size_t length, const plot_font_style_t *fstyle);
-static int clip(GEM_PLOTTER self, const struct rect * clip);
-
-int ctor_plotter_gd( GEM_PLOTTER instance, GRECT * origin_size )
-{
-
- instance->dtor = dtor;
- instance->resize= resize;
- instance->move = move;
- instance->lock = lock;
- instance->unlock = unlock;
- instance->put_pixel = put_pixel;
- instance->copy_rect = copy_rect;
- instance->get_clip = get_clip;
- instance->set_clip = set_clip;
- instance->arc = arc;
- instance->disc = disc;
- instance->line = line;
- instance->rectangle = rectangle;
- instance->polygon = polygon;
- instance->path = path;
- instance->bitmap = bitmap;
- instance->bitmap_resize = bitmap_resize;
- instance->bitmap_convert = bitmap_convert;
- instance->plot_mfdb = NULL;
- instance->text = text;
-
- instance->priv_data = malloc( sizeof(struct s_gd_priv_data) );
- if( instance->priv_data == NULL )
- return( 0-ERR_NO_MEM );
- memset( instance->priv_data, 0, sizeof(struct s_gd_priv_data) );
-
- // allocate framebuffer
- THIS(instance)->vbuf = gdImageCreateTrueColor( origin_size->g_w,
- origin_size->g_h );
-
- THIS(instance)->origin_x = origin_size->g_x;
- THIS(instance)->origin_y = origin_size->g_y;
-
- return( 1 );
-}
-
-static int dtor( GEM_PLOTTER instance )
-{
- int i;
- free( instance->priv_data );
- gdImageDestroy( THIS(instance)->vbuf );
- return( 1 );
-}
-
-static int resize( GEM_PLOTTER instance, int w, int h )
-{
- return( 1 );
-}
-
-static int move( GEM_PLOTTER instance, short x, short y )
-{
- THIS(instance)->origin_x = x;
- THIS(instance)->origin_y = y;
- return( 1 );
-}
-
-static int lock( GEM_PLOTTER instance ){
- instance->flags |= PLOT_FLAG_LOCKED;
- return( 1 );
-}
-
-static int unlock( GEM_PLOTTER instance )
-{
- instance->flags &= ~PLOT_FLAG_LOCKED;
- return( 1 );
-}
-
-static int put_pixel(GEM_PLOTTER instance, int x, int y, int color )
-{
- gdImageSetPixel( THIS(instance)->vbuf, x, y, color );
- return( 1 );
-}
-
-static int copy_rect( GEM_PLOTTER instance, GRECT src, GRECT dst )
-{
- return( 1 );
-}
-
-static int arc(GEM_PLOTTER instance,int x, int y, int radius, int angle1, int angle2, const plot_style_t * pstyle)
-{
- return( 1 );
-}
-
-static int disc(GEM_PLOTTER instance,int x, int y, int radius, const plot_style_t * pstyle)
-{
- return( 1 );
-}
-
-static int line(GEM_PLOTTER instance,int x0, int y0, int x1, int y1, const plot_style_t * pstyle)
-{
- int w = pstyle->stroke_width;
- if( ((w % 2) == 0) || (w < 1) ){
- w++;
- }
- gdImageSetThickness( THIS(instance)->vbuf, w );
- // FIXME: set stroke style
- //gdImageSetStyle( THIS(instance), style, nofpix );
- gdImageLine( THIS(instance)->vbuf, x0, y0, x1, y1, pstyle->stroke_colour );
- return( 1 );
-}
-
-static int rectangle(GEM_PLOTTER instance,int x0, int y0, int x1, int y1, const plot_style_t * pstyle)
-{
- int lw = pstyle->stroke_width;
-
- if( pstyle->fill_type != PLOT_OP_TYPE_NONE ){
- gdImageFilledRectangle( THIS(instance)->vbuf,
- x0, y0, x1, y1,
- pstyle->fill_colour );
- }
-
- if( pstyle->stroke_type != PLOT_OP_TYPE_NONE ){
- gdImageLine( THIS(instance)->vbuf,
- x0, y0, x1, y1,
- pstyle->stroke_colour );
- }
- return( 1 );
-}
-
-static int polygon(GEM_PLOTTER instance,const int *p, unsigned int n, const plot_style_t * pstyle)
-{
- //gdImagePolygon( THIS(instance).vbuf, points, count, c );
- return( 1 );
-}
-static int path(GEM_PLOTTER instance,const float *p, unsigned int n, int fill, float width, int c, const float transform[6])
-{
- return( 1 );
-}
-
-static int bitmap_resize( GEM_PLOTTER instance, struct bitmap * img, int nw, int nh )
-{
- return( 1 );
-}
-
-static int bitmap_convert( GEM_PLOTTER instance, struct bitmap * img, int x, int y,
- GRECT * clip,uint32_t bg,uint32_t flags, MFDB *out )
-{
- return( 1 );
-}
-
-static int bitmap( GEM_PLOTTER instance, struct bitmap * bmp, int x, int y,
- unsigned long bg, unsigned long flags )
-{
- return( 1 );
-}
-
-static int plot_mfdb( GEM_PLOTTER instance, GRECT * where, MFDB * mfdb, unsigned char fgcolor, uint32_t flags)
-{
- return( 1 );
-}
-
-static int text( GEM_PLOTTER instance, int x, int y, const char *text,size_t length, const plot_font_style_t *fstyle)
-{
- return( 1 );
-}
-
-
-static int get_clip( GEM_PLOTTER instance, struct rect * clip)
-{
- gdImageGetClip( THIS(instance)->vbuf,
- &clip->x0, &clip->y0,
- &clip->x0, &clip->y0 );
- return( 1 );
-}
-
-static int set_clip( GEM_PLOTTER instance, const struct rect * clip )
-{
- gdImageSetClip( THIS(instance)->vbuf, clip->x0,
- clip->y0, clip->x1,
- clip->y1 );
- return ( 1 );
-}
-
-
-#endif
diff --git a/atari/plot/plotter_gd.h b/atari/plot/plotter_gd.h
deleted file mode 100644
index b449997d8..000000000
--- a/atari/plot/plotter_gd.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2012 Ole Loots <ole@monochrom.net>
- *
- * 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/>.
- */
-#ifdef WITH_GD_PLOTTER
-#ifndef GEM_PLOTTER_GD_H_INCLUDED
-#define GEM_PLOTTER_GD_H_INCLUDED
-
-
-#include <gd.h>
-#include "plotter.h"
-
-struct s_gd_priv_data {
- gdImagePtr vbuf;
- int origin_x;
- int origin_y;
-};
-
-/* this is an shortcut cast to access the members of the s_gd_priv_data */
-#define THIS(instance) ((struct s_gd_priv_data*)instance->priv_data)
-
-/* Each driver object must export 1 it's own constructor: */
-int ctor_plotter_gd( GEM_PLOTTER p, GRECT * loc_size );
-
-#endif
-#endif
diff --git a/atari/plot/plotter_vdi.c b/atari/plot/plotter_vdi.c
deleted file mode 100755
index 8b4550e80..000000000
--- a/atari/plot/plotter_vdi.c
+++ /dev/null
@@ -1,1713 +0,0 @@
-/*
- * Copyright 2010 Ole Loots <ole@monochrom.net>
- *
- * 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/>.
- */
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-#include <assert.h>
-#include <windom.h>
-#include <Hermes/Hermes.h>
-
-#include "atari/plot/eddi.h"
-#include "atari/plot/plotter.h"
-#include "atari/plot/plotter_vdi.h"
-
-
-/* assign vdi line style to dst ( netsurf type ) */
-#define NSLT2VDI(dst, src) \
- dst = 0;\
- switch( src->stroke_type ) {\
- case PLOT_OP_TYPE_DOT: \
- dst = (0xAAAA00 | 7);\
- break;\
- case PLOT_OP_TYPE_DASH:\
- dst = 3; \
- break;\
- case PLOT_OP_TYPE_SOLID:\
- case PLOT_OP_TYPE_NONE:\
- default:\
- dst = 1;\
- break;\
- }\
-
-static int dtor( GEM_PLOTTER self );
-static int resize( GEM_PLOTTER self, int w, int h );
-static int move( GEM_PLOTTER self, short x, short y );
-static int lock( GEM_PLOTTER self );
-static int unlock( GEM_PLOTTER self );
-static int put_pixel(GEM_PLOTTER self, int x, int y, int color );
-static int copy_rect( GEM_PLOTTER self, GRECT src, GRECT dst );
-static int set_clip(GEM_PLOTTER self, const struct rect * clip);
-static int get_clip( GEM_PLOTTER self, struct rect * out );
-static int arc(GEM_PLOTTER self,int x, int y, int radius, int angle1, int angle2, const plot_style_t * pstyle);
-static int disc(GEM_PLOTTER self,int x, int y, int radius, const plot_style_t * pstyle);
-static int line(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle);
-static int rectangle(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle);
-static int polygon(GEM_PLOTTER self,const int *p, unsigned int n, const plot_style_t * pstyle);
-static int path(GEM_PLOTTER self,const float *p, unsigned int n, int fill, float width, int c, const float transform[6]);
-static int bitmap_resize( GEM_PLOTTER self, struct bitmap * img, int nw, int nh );
-static int bitmap_convert( GEM_PLOTTER self, struct bitmap * img, int x, int y,
- GRECT * clip,uint32_t bg,uint32_t flags, MFDB *out );
-static int bitmap_convert_8( GEM_PLOTTER self, struct bitmap * img,int x, int y,
- GRECT * clip,uint32_t bg,uint32_t flags, MFDB *out );
-static int bitmap( GEM_PLOTTER self, struct bitmap * bmp, int x, int y,
- unsigned long bg, unsigned long flags );
-static int plot_mfdb( GEM_PLOTTER self, GRECT * where, MFDB * mfdb, unsigned char fgcolor, uint32_t flags);
-static int text(GEM_PLOTTER self, int x, int y, const char *text,size_t length, const plot_font_style_t *fstyle);
-
-static inline void set_stdpx( MFDB * dst, int wdplanesz, int x, int y, unsigned char val );
-static inline unsigned char get_stdpx(MFDB * dst, int wdplanesz, int x, int y );
-
-/*
- Set clipping for current framebuffer
-*/
-static int plotter_std_clip(GEM_PLOTTER self, const struct rect * clip);
-
-
-extern struct s_vdi_sysinfo vdi_sysinfo;
-
-static HermesHandle hermes_pal_h; /* hermes palette handle */
-static HermesHandle hermes_cnv_h; /* hermes converter instance handle */
-static HermesHandle hermes_res_h;
-
-static short prev_vdi_clip[4];
-static struct bitmap snapshot;
-
-#ifdef WITH_8BPP_SUPPORT
-static unsigned short sys_pal[256][3]; /*RGB*/
-static unsigned short pal[256][3]; /*RGB*/
-static char rgb_lookup[256][4];
-extern unsigned short vdi_web_pal[216][3];
-#endif
-
-
-static inline void vsl_rgbcolor( short vdih, uint32_t cin )
-{
- #ifdef WITH_8BPP_SUPPORT
- if( vdi_sysinfo.scr_bpp > 8 ) {
- #endif
- unsigned short c[4];
- rgb_to_vdi1000( (unsigned char*)&cin, (unsigned short*)&c );
- vs_color( vdih, OFFSET_CUSTOM_COLOR, (unsigned short*)&c[0] );
- vsl_color( vdih, OFFSET_CUSTOM_COLOR );
- #ifdef WITH_8BPP_SUPPORT
- } else {
- if( vdi_sysinfo.scr_bpp >= 4 ){
- vsl_color( vdih, RGB_TO_VDI(cin) );
- }
- else
- vsl_color( vdih, BLACK );
- }
- #endif
-}
-
-static inline void vsf_rgbcolor( short vdih, uint32_t cin )
-{
- #ifdef WITH_8BPP_SUPPORT
- if( vdi_sysinfo.scr_bpp > 8 ) {
- #endif
- unsigned short c[4];
- rgb_to_vdi1000( (unsigned char*)&cin, (unsigned short*)&c );
- vs_color( vdih, OFFSET_CUSTOM_COLOR, &c[0] );
- vsf_color( vdih, OFFSET_CUSTOM_COLOR );
- #ifdef WITH_8BPP_SUPPORT
- } else {
- if( vdi_sysinfo.scr_bpp >= 4 ){
- vsf_color( vdih, RGB_TO_VDI(cin) );
- }
- else
- vsf_color( vdih, WHITE );
- }
- #endif
-}
-
-static int set_clip(GEM_PLOTTER self, const struct rect * clip)
-{
- // FIXME: consider the canvas size
- VIEW( self ).clipping.x0 = clip->x0;
- VIEW( self ).clipping.y0 = clip->y0;
- VIEW( self ).clipping.x1 = clip->x1;
- VIEW( self ).clipping.y1 = clip->y1;
- return ( 1 );
-}
-
-static int get_clip( GEM_PLOTTER self, struct rect * out )
-{
- out->x0 = VIEW( self ).clipping.x0;
- out->y0 = VIEW( self ).clipping.y0;
- out->x1 = VIEW( self ).clipping.x1;
- out->y1 = VIEW( self ).clipping.y1;
- return( 1 );
-}
-
-/*
- Get current visible coords
-*/
-static inline void plotter_get_visible_grect( GEM_PLOTTER self, GRECT * out )
-{
- out->g_x = VIEW( self ).vis_x;
- out->g_y = VIEW( self ).vis_y;
- out->g_w = VIEW( self ).vis_w;
- out->g_h = VIEW( self ).vis_h;
-}
-
-
-/*
- 1. calculate visible area of framebuffer in coords relative to framebuffer position
-
- result:
- this function should calculates an rectangle relative to the plot origin and
- size.
- If the ploter coords do not fall within the screen region,
- all values of the region are set to zero.
-*/
-static inline void update_visible_rect( GEM_PLOTTER p )
-{
- GRECT screen;
- GRECT common;
- GRECT frame;
-
- screen.g_x = 0;
- screen.g_y = 0;
- screen.g_w = vdi_sysinfo.scr_w;
- screen.g_h = vdi_sysinfo.scr_h;
-
- common.g_x = frame.g_x = VIEW(p).x;
- common.g_y = frame.g_y = VIEW(p).y;
- common.g_w = frame.g_w = VIEW(p).w;
- common.g_h = frame.g_h = VIEW(p).h;
-
- if( rc_intersect( &screen, &common ) ) {
- VIEW(p).vis_w = common.g_w;
- VIEW(p).vis_h = common.g_h;
- if( VIEW(p).x < screen.g_x )
- VIEW(p).vis_x = frame.g_w - common.g_w;
- else
- VIEW(p).vis_x = 0;
- if( VIEW(p).y <screen.g_y )
- VIEW(p).vis_y = frame.g_h - common.g_h;
- else
- VIEW(p).vis_y = 0;
- } else {
- VIEW(p).vis_w = VIEW(p).vis_h = 0;
- VIEW(p).vis_x = VIEW(p).vis_y = 0;
- }
-}
-
-/*
- Returns the visible parts of the box (relative coords within framebuffer),
- relative to screen coords (normally starting at 0,0 )
-*/
-static inline bool fbrect_to_screen( GEM_PLOTTER self, GRECT box, GRECT * ret )
-{
- GRECT out, vis, screen;
-
- screen.g_x = 0;
- screen.g_y = 0;
- screen.g_w = vdi_sysinfo.scr_w;
- screen.g_h = vdi_sysinfo.scr_h;
-
- /* get visible region: */
- vis.g_x = VIEW(self).x;
- vis.g_y = VIEW(self).y;
- vis.g_w = VIEW(self).w;
- vis.g_h = VIEW(self).h;
-
- if ( !rc_intersect( &screen, &vis ) ) {
- return( false );
- }
- vis.g_x = VIEW(self).w - vis.g_w;
- vis.g_y = VIEW(self).h - vis.g_h;
-
- /* clip box to visible region: */
- if( !rc_intersect(&vis, &box) ) {
- return( false );
- }
- out.g_x = box.g_x + VIEW(self).x;
- out.g_y = box.g_y + VIEW(self).y;
- out.g_w = box.g_w;
- out.g_h = box.g_h;
- *ret = out;
- return ( true );
-}
-
-/*
- convert framebuffer clipping to vdi clipping and activates it
-*/
-
-static inline void plotter_vdi_clip( GEM_PLOTTER self, bool set)
-{
- return;
- if( set == true ) {
- struct rect c;
- short vdiflags[58];
- short newclip[4];
- self->get_clip( self, &c );
- vq_extnd( self->vdi_handle, 1, (short*)&vdiflags);
- prev_vdi_clip[0] = vdiflags[45];
- prev_vdi_clip[1] = vdiflags[46];
- prev_vdi_clip[2] = vdiflags[47];
- prev_vdi_clip[3] = vdiflags[48];
- newclip[0] = VIEW(self).x + MAX(c.x0, 0);
- newclip[1] = VIEW(self).y + MAX(c.y0, 0);
- newclip[2] = MIN(VIEW(self).x+VIEW(self).w, newclip[0] + (c.x1 - c.x0) )-1;
- newclip[3] = MIN(VIEW(self).y+VIEW(self).h, newclip[1] + (c.y1 - c.y0) )-1;
- vs_clip( self->vdi_handle, 1, (short*)&newclip );
- } else {
- vs_clip( self->vdi_handle, 1, (short *)&prev_vdi_clip );
- }
-}
-
-int ctor_plotter_vdi( GEM_PLOTTER self , GRECT * loc_size )
-{
- int retval = 0;
- int i;
- struct rect clip;
-
- self->dtor = dtor;
- self->resize= resize;
- self->move = move;
- self->lock = lock;
- self->unlock = unlock;
- self->put_pixel = put_pixel;
- self->copy_rect = copy_rect;
- self->set_clip = set_clip;
- self->get_clip = get_clip;
- self->arc = arc;
- self->disc = disc;
- self->line = line;
- self->rectangle = rectangle;
- self->polygon = polygon;
- self->path = path;
- self->bitmap = bitmap;
- self->bitmap_resize = bitmap_resize;
- /* override virtual bpp - must be in sync with screen for this driver: */
- self->bpp_virt = app.nplanes;
-#ifdef WITH_8BPP_SUPPORT
- self->bitmap_convert =(app.nplanes > 8) ? bitmap_convert : bitmap_convert_8;
-#else
- self->bitmap_convert = bitmap_convert;
-#endif
- self->plot_mfdb = plot_mfdb;
- self->text = text;
- LOG(("Screen: x: %d, y: %d\n", vdi_sysinfo.scr_w, vdi_sysinfo.scr_h));
-
- self->priv_data = malloc( sizeof(struct s_vdi_priv_data) );
- if( self->priv_data == NULL )
- return( 0-ERR_NO_MEM );
- memset( self->priv_data, 0, sizeof(struct s_vdi_priv_data) );
- memset( &VIEW(self), 0, sizeof( struct s_view) );
- VIEW( self ).x = loc_size->g_x;
- VIEW( self ).y = loc_size->g_y;
- VIEW( self ).w = loc_size->g_w;
- VIEW( self ).h = loc_size->g_h;
- DUMMY_PRIV(self)->bufops = 0;
- DUMMY_PRIV(self)->size_buf_packed = 0;
- DUMMY_PRIV(self)->size_buf_planar = 0;
- DUMMY_PRIV(self)->buf_packed = NULL;
- DUMMY_PRIV(self)->buf_planar = NULL;
- if( vdi_sysinfo.vdiformat == VDI_FORMAT_PACK ) {
- self->bpp_virt = vdi_sysinfo.scr_bpp;
- } else {
- DUMMY_PRIV(self)->bufops = C2P;
- self->bpp_virt = 8;
- }
-
- VIEW(self).mem = NULL;
- update_visible_rect( self );
-
- clip.x0 = 0;
- clip.y0 = 0;
- clip.x1 = VIEW(self).w;
- clip.y1 = VIEW(self).h;
- self->set_clip( self, &clip );
-
- assert( Hermes_Init() );
- /* store system palette & setup the new (web) palette: */
-#ifdef WITH_8BPP_SUPPORT
- i = 0;
-
- unsigned char * col;
- unsigned char rgbcol[4];
- unsigned char graytone=0;
- if( app.nplanes <= 8 ){
- for( i=0; i<=255; i++ ) {
-
- // get the current color and save it for restore:
- vq_color(self->vdi_handle, i, 1, (unsigned short*)&sys_pal[i][0] );
- if( i<OFFSET_WEB_PAL ) {
- pal[i][0] = sys_pal[i][0];
- pal[i][1] = sys_pal[i][1];
- pal[i][2] = sys_pal[i][2];
- } else if( app.nplanes >= 8 ) {
- if ( i < OFFSET_CUST_PAL ){
- pal[i][0] = vdi_web_pal[i-OFFSET_WEB_PAL][0];
- pal[i][1] = vdi_web_pal[i-OFFSET_WEB_PAL][1];
- pal[i][2] = vdi_web_pal[i-OFFSET_WEB_PAL][2];
- //set the new palette color to websafe value:
- vs_color( self->vdi_handle, i, &pal[i][0] );
- }
- if( i >= OFFSET_CUST_PAL && i<OFFSET_CUST_PAL+16 ) {
- /* here we define 20 additional gray colors... */
- rgbcol[1] = rgbcol[2] = rgbcol[3] = ((graytone&0x0F) << 4);
- rgb_to_vdi1000( &rgbcol[0], &pal[i][0] );
- vs_color( self->vdi_handle, i, &pal[i][0] );
- graytone++;
- }
-
- }
- vdi1000_to_rgb( &pal[i][0], &rgb_lookup[i][0] );
- }
-
- } else {
- /* no need to change the palette - its application specific */
- }
-
-
-#endif
-
- unsigned long flags = ( self->flags & PLOT_FLAG_DITHER ) ? HERMES_CONVERT_DITHER : 0;
- hermes_cnv_h = Hermes_ConverterInstance( flags );
- assert( hermes_cnv_h );
- hermes_res_h = Hermes_ConverterInstance( flags );
- assert( hermes_res_h );
-
- /* set up the src & dst format: */
- /* netsurf uses RGBA ... */
- DUMMY_PRIV(self)->nsfmt.a = 0xFFUL;
- DUMMY_PRIV(self)->nsfmt.b = 0x0FF00UL;
- DUMMY_PRIV(self)->nsfmt.g = 0x0FF0000UL;
- DUMMY_PRIV(self)->nsfmt.r = 0x0FF000000UL;
- DUMMY_PRIV(self)->nsfmt.bits = 32;
- DUMMY_PRIV(self)->nsfmt.indexed = false;
- DUMMY_PRIV(self)->nsfmt.has_colorkey = false;
-
- DUMMY_PRIV(self)->vfmt.r = vdi_sysinfo.mask_r;
- DUMMY_PRIV(self)->vfmt.g = vdi_sysinfo.mask_g;
- DUMMY_PRIV(self)->vfmt.b = vdi_sysinfo.mask_b;
- DUMMY_PRIV(self)->vfmt.a = vdi_sysinfo.mask_a;
- DUMMY_PRIV(self)->vfmt.bits = self->bpp_virt;
- DUMMY_PRIV(self)->vfmt.indexed = ( app.nplanes <= 8 ) ? 1 : 0;
- DUMMY_PRIV(self)->vfmt.has_colorkey = 0;
-
- return( 1 );
-}
-
-static int dtor( GEM_PLOTTER self )
-{
- int i=0;
- LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
-
- if( VIEW(self).mem )
- free( VIEW(self).mem );
-
-#ifdef WITH_8BPP_SUPPORT
- if( DUMMY_PRIV(self)->vfmt.indexed ){
- for( i=OFFSET_WEB_PAL; i<OFFSET_CUST_PAL+16; i++){
- vs_color( self->vdi_handle, i, &sys_pal[i][0] );
- }
- }
-#endif
-
- /* close Hermes stuff: */
- Hermes_ConverterReturn( hermes_cnv_h );
-
- Hermes_Done();
-
- if( self->priv_data != NULL ){
- if( DUMMY_PRIV(self)->buf_packed )
- free( DUMMY_PRIV(self)->buf_packed );
- if( DUMMY_PRIV(self)->buf_planar )
- free( DUMMY_PRIV(self)->buf_planar );
- free( self->priv_data );
- }
- snapshot_destroy( self );
- return( 1 );
-}
-
-static int resize( GEM_PLOTTER self, int w, int h )
-{
- if( w == VIEW(self).w && h == VIEW(self).h )
- return( 1 );
- struct rect newclip = { 0, 0, w-1, h-1 };
- VIEW(self).w = w;
- VIEW(self).h = h;
- update_visible_rect( self );
- set_clip( self, &newclip);
- LOG(("%s: %s\n", (char*)__FILE__, (char*)__FUNCTION__));
- return( 1 );
-}
-static int move( GEM_PLOTTER self,short x, short y )
-{
- bool upd;
- if(x == VIEW(self).x && y == VIEW(self).y ){
- return 1;
- }
- LOG(("%s: x: %d, y: %d\n",(char*)__FUNCTION__, x, y));
- VIEW(self).x = x;
- VIEW(self).y = y;
- update_visible_rect( self );
- return( 1 );
-}
-
-
-static int lock( GEM_PLOTTER self )
-{
- LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
- if( (self->flags & PLOT_FLAG_LOCKED) != 0 )
- return(1);
- self->flags |= PLOT_FLAG_LOCKED;
- if( !wind_update(BEG_UPDATE|0x100) )
- return(0);
- if( !wind_update(BEG_MCTRL|0x100) ){
- wind_update(END_UPDATE);
- return(0);
- }
- graf_mouse(M_OFF, NULL);
- return( 1 );
-}
-
-static int unlock( GEM_PLOTTER self )
-{
- LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
- if( (self->flags & PLOT_FLAG_LOCKED) == 0 )
- return(1);
- self->flags &= ~PLOT_FLAG_LOCKED;
- wind_update(END_MCTRL);
- wind_update(END_UPDATE);
- graf_mouse(M_ON, NULL);
- return( 1 );
-}
-
-static int put_pixel(GEM_PLOTTER self, int x, int y, int color )
-{
- LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
- return( 1 );
-}
-
-/* copy an rectangle from the plot buffer to screen */
-/* because this is an on-screen plotter, this is an screen to screen copy. */
-static int copy_rect( GEM_PLOTTER self, GRECT src, GRECT dst )
-{
- MFDB devmf;
- MFDB scrmf;
- short pxy[8];
- GRECT vis;
-
- /* clip to visible rect, only needed for onscreen renderer: */
- plotter_get_visible_grect( self, &vis );
-
- if( !rc_intersect(&vis, &src) )
- return 1;
- if( !rc_intersect(&vis, &dst) )
- return 1;
-
- src.g_x = VIEW(self).x + src.g_x;
- src.g_y = VIEW(self).y + src.g_y;
- dst.g_x = VIEW(self).x + dst.g_x;
- dst.g_y = VIEW(self).y + dst.g_y;
-
- devmf.fd_addr = NULL;
- devmf.fd_w = src.g_w;
- devmf.fd_h = src.g_h;
- devmf.fd_wdwidth = 0;
- devmf.fd_stand = 0;
- devmf.fd_nplanes = 0;
- devmf.fd_r1 = devmf.fd_r2 = devmf.fd_r3 = 0;
-
- scrmf.fd_addr = NULL;
- scrmf.fd_w = dst.g_w;
- scrmf.fd_h = dst.g_h;
- scrmf.fd_wdwidth = 0 ;
- scrmf.fd_stand = 0;
- scrmf.fd_nplanes = 0;
- scrmf.fd_r1 = scrmf.fd_r2 = scrmf.fd_r3 = 0;
-
- pxy[0] = src.g_x;
- pxy[1] = src.g_y;
- pxy[2] = pxy[0] + src.g_w-1;
- pxy[3] = pxy[1] + src.g_h-1;
- pxy[4] = dst.g_x;
- pxy[5] = dst.g_y;
- pxy[6] = pxy[4] + dst.g_w-1;
- pxy[7] = pxy[5] + dst.g_h-1;
- self->lock( self );
- vro_cpyfm( self->vdi_handle, S_ONLY, (short*)&pxy, &devmf, &scrmf);
- self->unlock( self );
-
- return( 1 );
-}
-
-static int arc(GEM_PLOTTER self,int x, int y, int radius, int angle1, int angle2, const plot_style_t * pstyle)
-{
- //plotter_vdi_clip( self, 1);
- vswr_mode( self->vdi_handle, MD_REPLACE );
- if( pstyle->fill_type == PLOT_OP_TYPE_NONE )
- return 1;
- if( pstyle->fill_type != PLOT_OP_TYPE_SOLID) {
- vsl_rgbcolor( self->vdi_handle, pstyle->stroke_colour);
- vsf_perimeter( self->vdi_handle, 1);
- vsf_interior( self->vdi_handle, 1 );
- v_arc( self->vdi_handle, VIEW(self).x + x, VIEW(self).y + y, radius, angle1*10, angle2*10 );
- } else {
- vsf_rgbcolor( self->vdi_handle, pstyle->fill_colour);
- vsl_width( self->vdi_handle, 1 );
- vsf_perimeter( self->vdi_handle, 1);
- v_arc( self->vdi_handle, VIEW(self).x + x, VIEW(self).y + y, radius, angle1*10, angle2*10 );
- }
- //plotter_vdi_clip( self, 0);
- return ( 1 );
-}
-
-static int disc(GEM_PLOTTER self,int x, int y, int radius, const plot_style_t * pstyle)
-{
- plotter_vdi_clip( self, 1);
- if( pstyle->fill_type != PLOT_OP_TYPE_SOLID) {
- vsf_rgbcolor( self->vdi_handle, pstyle->stroke_colour );
- vsf_perimeter( self->vdi_handle, 1);
- vsf_interior( self->vdi_handle, 0 );
- v_circle( self->vdi_handle, VIEW(self).x + x, VIEW(self).y + y, radius );
- } else {
- vsf_rgbcolor( self->vdi_handle, pstyle->fill_colour );
- vsf_perimeter( self->vdi_handle, 0);
- vsf_interior( self->vdi_handle, FIS_SOLID );
- v_circle( self->vdi_handle, VIEW(self).x + x, VIEW(self).y + y, radius );
- }
- plotter_vdi_clip( self, 0);
- return ( 1 );
-}
-
-
-static int line(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle)
-{
- short pxy[4];
- uint32_t lt;
- int sw = pstyle->stroke_width;
-
- pxy[0] = VIEW(self).x + x0;
- pxy[1] = VIEW(self).y + y0;
- pxy[2] = VIEW(self).x + x1;
- pxy[3] = VIEW(self).y + y1;
-
- plotter_vdi_clip( self, 1);
- if( sw == 0)
- sw = 1;
- NSLT2VDI(lt, pstyle)
- vsl_type( self->vdi_handle, (lt&0x0F) );
- /* if the line style is not available within VDI system,define own style: */
- if( (lt&0x0F) == 7 ){
- vsl_udsty(self->vdi_handle, ((lt&0xFFFF00) >> 8) );
- }
- vsl_width( self->vdi_handle, (short)sw );
- vsl_rgbcolor( self->vdi_handle, pstyle->stroke_colour );
- v_pline(self->vdi_handle, 2, (short *)&pxy );
- plotter_vdi_clip( self, 0);
- return ( 1 );
-}
-
-static int rectangle(GEM_PLOTTER self,int x0, int y0, int x1, int y1, const plot_style_t * pstyle)
-{
- short pxy[4];
- GRECT r, rclip, sclip;
- int sw = pstyle->stroke_width;
- uint32_t lt;
-
- /* current canvas clip: */
- rclip.g_x = VIEW( self ).clipping.x0;
- rclip.g_y = VIEW( self ).clipping.y0;
- rclip.g_w = VIEW( self ).clipping.x1 - VIEW( self ).clipping.x0;
- rclip.g_h = VIEW( self ).clipping.y1 - VIEW( self ).clipping.y0;
-
- /* physical clipping: */
- sclip.g_x = rclip.g_x;
- sclip.g_y = rclip.g_y;
- sclip.g_w = VIEW(self).vis_w;
- sclip.g_h = VIEW(self).vis_h;
-
- rc_intersect(&sclip, &rclip);
- r.g_x = x0;
- r.g_y = y0;
- r.g_w = x1 - x0;
- r.g_h = y1 - y0;
-
- if( !rc_intersect( &rclip, &r ) ) {
- return( 1 );
- }
- if( pstyle->stroke_type != PLOT_OP_TYPE_NONE ){
- /*
- manually draw the line, because we do not need vdi clipping
- for vertical / horizontal line draws.
- */
- if( sw == 0)
- sw = 1;
-
- NSLT2VDI(lt, pstyle);
- vsl_type( self->vdi_handle, (lt&0x0F) );
- /*
- if the line style is not available within VDI system,
- define own style:
- */
- if( (lt&0x0F) == 7 ){
- vsl_udsty(self->vdi_handle, ((lt&0xFFFF00) >> 8) );
- }
- vsl_width( self->vdi_handle, (short)sw );
- vsl_rgbcolor( self->vdi_handle, pstyle->stroke_colour );
- /* top border: */
- if( r.g_y == y0){
- pxy[0] = VIEW(self).x + r.g_x;
- pxy[1] = VIEW(self).y + r.g_y ;
- pxy[2] = VIEW(self).x + r.g_x + r.g_w;
- pxy[3] = VIEW(self).y + r.g_y;
- v_pline(self->vdi_handle, 2, (short *)&pxy );
- }
-
- /* right border: */
- if( r.g_x + r.g_w == x1 ){
- pxy[0] = VIEW(self).x + r.g_x + r.g_w;
- pxy[1] = VIEW(self).y + r.g_y;
- pxy[2] = VIEW(self).x + r.g_x + r.g_w;
- pxy[3] = VIEW(self).y + r.g_y + r.g_h;
- v_pline(self->vdi_handle, 2, (short *)&pxy );
- }
-
- /* bottom border: */
- if( r.g_y+r.g_h == y1 ){
- pxy[0] = VIEW(self).x + r.g_x;
- pxy[1] = VIEW(self).y + r.g_y+r.g_h;
- pxy[2] = VIEW(self).x + r.g_x+r.g_w;
- pxy[3] = VIEW(self).y + r.g_y+r.g_h;
- v_pline(self->vdi_handle, 2, (short *)&pxy );
- }
-
- /* left border: */
- if( r.g_x == x0 ){
- pxy[0] = VIEW(self).x + r.g_x;
- pxy[1] = VIEW(self).y + r.g_y;
- pxy[2] = VIEW(self).x + r.g_x;
- pxy[3] = VIEW(self).y + r.g_y + r.g_h;
- v_pline(self->vdi_handle, 2, (short *)&pxy );
- }
- }
-
- if( pstyle->fill_type != PLOT_OP_TYPE_NONE ){
- short stroke_width = (short)(pstyle->stroke_type != PLOT_OP_TYPE_NONE) ?
- pstyle->stroke_width : 0;
-
- vsf_rgbcolor( self->vdi_handle, pstyle->fill_colour );
- vsf_perimeter( self->vdi_handle, 0);
- vsf_interior( self->vdi_handle, FIS_SOLID );
-
-
- pxy[0] = VIEW(self).x + r.g_x + stroke_width;
- pxy[1] = VIEW(self).y + r.g_y + stroke_width;
- pxy[2] = VIEW(self).x + r.g_x + r.g_w -1 - stroke_width ;
- pxy[3] = VIEW(self).y + r.g_y + r.g_h -1 - stroke_width;
-
- vsf_style( self->vdi_handle, 1);
- v_bar( self->vdi_handle, (short*)&pxy );
- }
-
- return ( 1 );
-}
-
-static int polygon(GEM_PLOTTER self,const int *p, unsigned int n, const plot_style_t * pstyle)
-{
- short pxy[n*2];
- unsigned int i=0;
- short d[4];
- if( vdi_sysinfo.maxpolycoords > 0 )
- assert( (signed int)n < vdi_sysinfo.maxpolycoords );
- plotter_vdi_clip( self, 1);
- vsf_interior( self->vdi_handle, FIS_SOLID );
- vsf_style( self->vdi_handle, 1);
- for( i = 0; i<n*2; i=i+2 ) {
- pxy[i] = (short)VIEW(self).x+p[i];
- pxy[i+1] = (short)VIEW(self).y+p[i+1];
- }
- if( pstyle->fill_type == PLOT_OP_TYPE_SOLID){
- vsf_rgbcolor( self->vdi_handle, pstyle->fill_colour);
- v_fillarea(self->vdi_handle, n, (short*)&pxy);
-
- } else {
- pxy[n*2]=pxy[0];
- pxy[n*2+1]=pxy[1];
- vsl_rgbcolor( self->vdi_handle, pstyle->stroke_colour);
- v_pline(self->vdi_handle, n+1, (short *)&pxy );
- }
- plotter_vdi_clip( self, 0);
- return ( 1 );
-}
-
-static int path(GEM_PLOTTER self,const float *p, unsigned int n, int fill, float width,
- int c, const float transform[6])
-{
- LOG(("%s: %s\n", (char*)__FILE__, __FUNCTION__));
- return ( 1 );
-}
-
-
-static inline uint32_t ablend(uint32_t pixel, uint32_t scrpixel)
-{
- int opacity = pixel & 0xFF;
- int transp = 0x100 - opacity;
- uint32_t rb, g;
- pixel >>= 8;
- scrpixel >>= 8;
- rb = ((pixel & 0xFF00FF) * opacity +
- (scrpixel & 0xFF00FF) * transp) >> 8;
- g = ((pixel & 0x00FF00) * opacity +
- (scrpixel & 0x00FF00) * transp) >> 8;
-
- return ((rb & 0xFF00FF) | (g & 0xFF00)) << 8;
-}
-
-static int bitmap_resize( GEM_PLOTTER self, struct bitmap * img, int nw, int nh )
-{
- HermesFormat fmt;
- short bpp = bitmap_get_bpp( img );
- int stride = bitmap_get_rowstride( img );
- int err;
-
- if( img->resized != NULL ) {
- if( img->resized->width != nw || img->resized->height != nh ) {
- bitmap_destroy( img->resized );
- img->resized = NULL;
- } else {
- /* the bitmap is already resized */
- return( 0 );
- }
- }
-
- /* allocate the mem for resized bitmap */
- img->resized = bitmap_create_ex( nw, nh, bpp, nw*bpp, 0, NULL );
- if( img->resized == NULL ) {
- printf("W: %d, H: %d, bpp: %d\n", nw, nh, bpp);
- assert( img->resized );
- return ( -ERR_NO_MEM );
- }
-
- /* allocate an converter, only for resizing */
- err = Hermes_ConverterRequest( hermes_res_h,
- &DUMMY_PRIV(self)->nsfmt,
- &DUMMY_PRIV(self)->nsfmt
- );
- if( err == 0 ) {
- return( -ERR_PLOTTER_NOT_AVAILABLE );
- }
-
- err = Hermes_ConverterCopy( hermes_res_h,
- img->pixdata,
- 0, /* x src coord of top left in pixel coords */
- 0, /* y src coord of top left in pixel coords */
- bitmap_get_width( img ), bitmap_get_height( img ),
- stride, /* stride as bytes */
- img->resized->pixdata,
- 0, /* x dst coord of top left in pixel coords */
- 0, /* y dst coord of top left in pixel coords */
- nw, nh,
- bitmap_get_rowstride( img->resized ) /* stride as bytes */
- );
- if( err == 0 ) {
- bitmap_destroy( img->resized );
- img->resized = NULL;
- return( -2 );
- }
-
- return( 0 );
-}
-
-// create snapshot, native screen format
-static MFDB * snapshot_create_native_mfdb( GEM_PLOTTER self, int x, int y, int w, int h)
-{
- MFDB scr;
- short pxy[8];
-
- /* allocate memory for the snapshot */
- {
- int scr_stride = MFDB_STRIDE( w );
- int scr_size = ( ((scr_stride >> 3) * h) * vdi_sysinfo.scr_bpp );
- if( DUMMY_PRIV(self)->size_buf_scr == 0 ){
- /* init screen mfdb */
- DUMMY_PRIV(self)->buf_scr.fd_addr = malloc( scr_size );
- DUMMY_PRIV(self)->size_buf_scr = scr_size;
- } else {
- if( scr_size > DUMMY_PRIV(self)->size_buf_scr ) {
- DUMMY_PRIV(self)->buf_scr.fd_addr = realloc(
- DUMMY_PRIV(self)->buf_scr.fd_addr, scr_size
- );
- DUMMY_PRIV(self)->size_buf_scr = scr_size;
- }
- }
- if( DUMMY_PRIV(self)->buf_scr.fd_addr == NULL ) {
- DUMMY_PRIV(self)->size_buf_scr = 0;
- return( NULL );
- }
- DUMMY_PRIV(self)->buf_scr.fd_nplanes = vdi_sysinfo.scr_bpp;
- DUMMY_PRIV(self)->buf_scr.fd_w = scr_stride;
- DUMMY_PRIV(self)->buf_scr.fd_h = h;
- DUMMY_PRIV(self)->buf_scr.fd_wdwidth = scr_stride >> 4;
- assert( DUMMY_PRIV(self)->buf_scr.fd_addr != NULL );
- }
- init_mfdb( 0, w, h, 0, &scr );
- pxy[0] = x;
- pxy[1] = y;
- pxy[2] = pxy[0] + w-1;
- pxy[3] = pxy[1] + h-1;
- pxy[4] = 0;
- pxy[5] = 0;
- pxy[6] = w-1;
- pxy[7] = h-1;
- vro_cpyfm(
- self->vdi_handle, S_ONLY, (short*)&pxy,
- &scr, &DUMMY_PRIV(self)->buf_scr
- );
-
- return( &DUMMY_PRIV(self)->buf_scr );
-}
-
-// create snapshot, vdi std. format
-static MFDB * snapshot_create_std_mfdb(GEM_PLOTTER self, int x, int y, int w, int h)
-{
- /* allocate memory for the snapshot */
- {
- int scr_stride = MFDB_STRIDE( w );
- int scr_size = ( ((scr_stride >> 3) * h) * app.nplanes );
- if( DUMMY_PRIV(self)->size_buf_std == 0 ){
- /* init screen mfdb */
- DUMMY_PRIV(self)->buf_std.fd_addr = malloc( scr_size );
- DUMMY_PRIV(self)->size_buf_std = scr_size;
- } else {
- if( scr_size > DUMMY_PRIV(self)->size_buf_std ) {
- DUMMY_PRIV(self)->buf_std.fd_addr = realloc(
- DUMMY_PRIV(self)->buf_std.fd_addr, scr_size
- );
- DUMMY_PRIV(self)->size_buf_std = scr_size;
- }
- }
- if( DUMMY_PRIV(self)->buf_std.fd_addr == NULL ) {
- DUMMY_PRIV(self)->size_buf_std = 0;
- return( NULL );
- }
- DUMMY_PRIV(self)->buf_std.fd_nplanes = app.nplanes;
- DUMMY_PRIV(self)->buf_std.fd_w = scr_stride;
- DUMMY_PRIV(self)->buf_std.fd_h = h;
- DUMMY_PRIV(self)->buf_std.fd_stand = 1;
- DUMMY_PRIV(self)->buf_std.fd_wdwidth = scr_stride >> 4;
- assert( DUMMY_PRIV(self)->buf_std.fd_addr != NULL );
- }
- MFDB * native = snapshot_create_native_mfdb( self, x,y,w,h );
- assert( native );
-
- vr_trnfm( self->vdi_handle, native, &DUMMY_PRIV(self)->buf_std );
- return( &DUMMY_PRIV(self)->buf_std );
-}
-
-/*
- This will create an snapshot of the screen in netsurf ABGR format
-*/
-
-static struct bitmap * snapshot_create(GEM_PLOTTER self, int x, int y, int w, int h)
-{
- int err;
- MFDB * native;
- uint32_t start = clock();
-
- // FIXME: This can be optimized a lot.
- // 1. do not copy the snapshot to the bitmap buffer
- // when the format of screen and bitmap equals.
- // just point the bitmap to the native mfdb.
- // 2. if we have eddi 1.1, we could optimize that further
- // make snapshot_create_native_mfdb just returning a pointer
- // to the screen.
-
- native = snapshot_create_native_mfdb( self, x, y, w, h );
-
- if( DUMMY_PRIV(self)->vfmt.bits == 32 )
- goto no_copy;
-
- /* allocate buffer for result bitmap: */
- if( DUMMY_PRIV(self)->buf_scr_compat == NULL ) {
- DUMMY_PRIV(self)->buf_scr_compat = bitmap_create(w, h, 0);
- } else {
- DUMMY_PRIV(self)->buf_scr_compat = bitmap_realloc( w, h,
- DUMMY_PRIV(self)->buf_scr_compat->bpp,
- w * DUMMY_PRIV(self)->buf_scr_compat->bpp,
- BITMAP_GROW,
- DUMMY_PRIV(self)->buf_scr_compat );
- }
-
- /* convert screen buffer to ns format: */
- err = Hermes_ConverterRequest( hermes_cnv_h,
- &DUMMY_PRIV(self)->vfmt,
- &DUMMY_PRIV(self)->nsfmt
- );
- assert( err != 0 );
- err = Hermes_ConverterCopy( hermes_cnv_h,
- native->fd_addr,
- 0, /* x src coord of top left in pixel coords */
- 0, /* y src coord of top left in pixel coords */
- w, h,
- native->fd_w * vdi_sysinfo.pixelsize, /* stride as bytes */
- DUMMY_PRIV(self)->buf_scr_compat->pixdata,
- 0, /* x dst coord of top left in pixel coords */
- 0, /* y dst coord of top left in pixel coords */
- w, h,
- bitmap_get_rowstride(DUMMY_PRIV(self)->buf_scr_compat) /* stride as bytes */
- );
- assert( err != 0 );
- return( (struct bitmap * )DUMMY_PRIV(self)->buf_scr_compat );
-
-no_copy:
-
- snapshot.width = w;
- snapshot.height = h;
- snapshot.pixdata = native->fd_addr;
- snapshot.native = *native;
- snapshot.rowstride = MFDB_STRIDE( w )*4;
-
- uint32_t row, col;
- for( row = 0; row<h; row++ ){
- // fd_w matches stride!
- uint32_t *rowptr = ((uint32_t*)native->fd_addr + ((row*native->fd_w)));
- for( col=0; col<w; col++){
- *(rowptr+col) = (*(rowptr+col)<<8);
- }
- }
- return( &snapshot );
-}
-
-static void snapshot_suspend(GEM_PLOTTER self )
-{
- if( DUMMY_PRIV(self)->size_buf_scr > CONV_KEEP_LIMIT ) {
- DUMMY_PRIV(self)->buf_scr.fd_addr = realloc(
- DUMMY_PRIV(self)->buf_scr.fd_addr, CONV_KEEP_LIMIT
- );
- if( DUMMY_PRIV(self)->buf_scr.fd_addr != NULL ) {
- DUMMY_PRIV(self)->size_buf_scr = CONV_KEEP_LIMIT;
- } else {
- DUMMY_PRIV(self)->size_buf_scr = 0;
- }
- }
-
- if( DUMMY_PRIV(self)->size_buf_std > CONV_KEEP_LIMIT ) {
- DUMMY_PRIV(self)->buf_std.fd_addr = realloc(
- DUMMY_PRIV(self)->buf_std.fd_addr, CONV_KEEP_LIMIT
- );
- if( DUMMY_PRIV(self)->buf_std.fd_addr != NULL ) {
- DUMMY_PRIV(self)->size_buf_std = CONV_KEEP_LIMIT;
- } else {
- DUMMY_PRIV(self)->size_buf_std = 0;
- }
- }
-
- if( DUMMY_PRIV(self)->buf_scr_compat != NULL ) {
- size_t bs = bitmap_buffer_size( DUMMY_PRIV(self)->buf_scr_compat );
- if( bs > CONV_KEEP_LIMIT ) {
- int w = 0;
- int h = 1;
- w = (CONV_KEEP_LIMIT / DUMMY_PRIV(self)->buf_scr_compat->bpp);
- assert( CONV_KEEP_LIMIT == w*DUMMY_PRIV(self)->buf_scr_compat->bpp );
- DUMMY_PRIV(self)->buf_scr_compat = bitmap_realloc( w, h,
- DUMMY_PRIV(self)->buf_scr_compat->bpp,
- CONV_KEEP_LIMIT, BITMAP_SHRINK, DUMMY_PRIV(self)->buf_scr_compat
- );
- }
- }
-}
-
-static void snapshot_destroy( GEM_PLOTTER self )
-{
-
- free( DUMMY_PRIV(self)->buf_scr.fd_addr );
- if( DUMMY_PRIV(self)->buf_scr_compat != NULL ) {
- bitmap_destroy( DUMMY_PRIV(self)->buf_scr_compat );
- }
-
- DUMMY_PRIV(self)->buf_scr.fd_addr = NULL;
- DUMMY_PRIV(self)->buf_scr_compat = NULL;
-
-#ifdef WITH_8BPP_SUPPORT
- free( DUMMY_PRIV(self)->buf_std.fd_addr );
- DUMMY_PRIV(self)->buf_std.fd_addr = NULL;
-#endif
-}
-
-
-#ifdef WITH_8BPP_SUPPORT
-
-static inline void set_stdpx( MFDB * dst, int wdplanesz, int x, int y, unsigned char val )
-{
- short * buf;
- short whichbit = (1<<(15-(x%16)));
-
- buf = dst->fd_addr;
- buf += ((dst->fd_wdwidth*(y))+(x>>4));
-
- *buf = (val&1) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
-
- buf += wdplanesz;
- *buf = (val&(1<<1)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
-
- buf += wdplanesz;
- *buf = (val&(1<<2)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
-
- buf += wdplanesz;
- *buf = (val&(1<<3)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
-
- buf += wdplanesz;
- *buf = (val&(1<<4)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
-
- buf += wdplanesz;
- *buf = (val&(1<<5)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
-
- buf += wdplanesz;
- *buf = (val&(1<<6)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
-
- buf += wdplanesz;
- *buf = (val&(1<<7)) ? ((*buf)|(whichbit)) : ((*buf)&~(whichbit));
-}
-
-static inline unsigned char get_stdpx(MFDB * dst, int wdplanesz, int x, int y )
-{
- unsigned char ret=0;
- short * buf;
- short whichbit = (1<<(15-(x%16)));
-
- buf = dst->fd_addr;
- buf += ((dst->fd_wdwidth*(y))+(x>>4));
-
- if( *buf & whichbit )
- ret |= 1;
-
- buf += wdplanesz;
- if( *buf & whichbit )
- ret |= 2;
-
- buf += wdplanesz;
- if( *buf & whichbit )
- ret |= 4;
-
- buf += wdplanesz;
- if( *buf & whichbit )
- ret |= 8;
-
- buf += wdplanesz;
- if( *buf & whichbit )
- ret |= 16;
-
- buf += wdplanesz;
- if( *buf & whichbit )
- ret |= 32;
-
- buf += wdplanesz;
- if( *buf & whichbit )
- ret |= 64;
-
- buf += wdplanesz;
- if( *buf & whichbit )
- ret |= 128;
-
- return( ret );
-}
-
-static int bitmap_convert_8( GEM_PLOTTER self, struct bitmap * img, int x,
- int y, GRECT * clip, uint32_t bg, uint32_t flags,
- MFDB *out )
-{
- MFDB native;
- MFDB stdform;
- int dststride; /* stride of dest. image */
- int dstsize; /* size of dest. in byte */
- int err;
- int bw, bh;
- int process_w, process_h;
- struct bitmap * scrbuf = NULL;
- struct bitmap * source;
- bool cache = ( flags & BITMAPF_BUFFER_NATIVE );
- bool opaque = bitmap_get_opaque( img );
-
- if( opaque == false ){
- if( ( (self->flags & PLOT_FLAG_TRANS) == 0)
- &&
- ((flags & (BITMAPF_MONOGLYPH|BITMAPF_BUFFER_NATIVE))==0) ){
- opaque = true;
- }
- }
-
- assert( clip->g_h > 0 );
- assert( clip->g_w > 0 );
-
- process_w = bw = bitmap_get_width( img );
- process_h = bh = bitmap_get_height( img );
-
- // The converted bitmap can be saved for subsequent blits, when
- // the bitmap is fully opaque
-
- if( (opaque == true) || (flags & BITMAPF_BUFFER_NATIVE ) ){
- if( img->converted == true ){
- *out = img->native;
- return( 0 );
- }
- if( ( flags & BITMAPF_MONOGLYPH ) == 0 ){
- cache = true;
- }
- }
- if( ( flags & BITMAPF_MONOGLYPH ) != 0 ){
- assert(cache == false);
- }
-
- /* (re)allocate buffer for out image: */
- /* altough the buffer is named "buf_packed" on 8bit systems */
- /* it's not... */
- if( cache == false ){
- // the size of the output will match the size of the clipping:
- dststride = MFDB_STRIDE( clip->g_w );
- dstsize = ( ((dststride >> 3) * clip->g_h) * self->bpp_virt );
- if( dstsize > DUMMY_PRIV(self)->size_buf_packed) {
- int blocks = (dstsize / (CONV_BLOCK_SIZE-1))+1;
- if( DUMMY_PRIV(self)->buf_packed == NULL )
- DUMMY_PRIV(self)->buf_packed =(void*)malloc( blocks * CONV_BLOCK_SIZE );
- else
- DUMMY_PRIV(self)->buf_packed =(void*)realloc(
- DUMMY_PRIV(self)->buf_packed,
- blocks * CONV_BLOCK_SIZE
- );
- assert( DUMMY_PRIV(self)->buf_packed );
- if( DUMMY_PRIV(self)->buf_packed == NULL ) {
- return( 0-ERR_NO_MEM );
- }
- DUMMY_PRIV(self)->size_buf_packed = blocks * CONV_BLOCK_SIZE;
- }
- native.fd_addr = DUMMY_PRIV(self)->buf_packed;
- }
- else {
- // the output image will be completly saved, so size of the output
- // image will match the input image size.
- dststride = MFDB_STRIDE( bw );
- dstsize = ( ((dststride >> 3) * bh) * self->bpp_virt );
- assert( out->fd_addr == NULL );
- native.fd_addr = (void*)malloc( dstsize );
- if( native.fd_addr == NULL ){
- if( scrbuf != NULL )
- bitmap_destroy( scrbuf );
- return( 0-ERR_NO_MEM );
- }
- }
-
-
- /*
- on 8 bit systems we must convert the TC (ABGR) image
- to vdi standard format. ( only tested for 256 colors )
- and then convert it to native format with v_trnfm()
- */
- // realloc mem for stdform
- if( opaque == false ){
- // point image to snapshot buffer, otherwise allocate mem
- MFDB * bg = snapshot_create_std_mfdb( self, x, y, clip->g_w,
- clip->g_h );
- stdform.fd_addr = bg->fd_addr;
- bh = clip->g_h;
- } else {
- if( dstsize > DUMMY_PRIV(self)->size_buf_planar) {
- int blocks = (dstsize / (CONV_BLOCK_SIZE-1))+1;
- if( DUMMY_PRIV(self)->buf_planar == NULL )
- DUMMY_PRIV(self)->buf_planar =(void*)malloc( blocks * CONV_BLOCK_SIZE );
- else
- DUMMY_PRIV(self)->buf_planar =(void*)realloc(
- DUMMY_PRIV(self)->buf_planar,
- blocks * CONV_BLOCK_SIZE
- );
- assert( DUMMY_PRIV(self)->buf_planar );
- if( DUMMY_PRIV(self)->buf_planar == NULL ) {
- return( 0-ERR_NO_MEM );
- }
- DUMMY_PRIV(self)->size_buf_planar = blocks * CONV_BLOCK_SIZE;
- }
- stdform.fd_addr = DUMMY_PRIV(self)->buf_planar;
- }
- stdform.fd_w = dststride;
- stdform.fd_h = bh;
- stdform.fd_wdwidth = dststride >> 4;
- stdform.fd_stand = 1;
- stdform.fd_nplanes = (short)self->bpp_virt;
- stdform.fd_r1 = stdform.fd_r2 = stdform.fd_r3 = 0;
-
- int img_stride = bitmap_get_rowstride(img);
- uint32_t prev_pixel = 0x12345678;
- unsigned long col = 0;
- unsigned char val = 0;
- uint32_t * row;
- uint32_t pixel;
- int wdplanesize = stdform.fd_wdwidth*stdform.fd_h;
-
- if( opaque == false ){
- // apply transparency and convert to vdi std format
- unsigned long bgcol = 0;
- unsigned char prev_col = 0;
- for( y=0; y<clip->g_h; y++ ){
- row = (uint32_t *)(img->pixdata + (img_stride * (y+clip->g_y)));
- for( x=0; x<clip->g_w; x++ ){
- pixel = row[x+clip->g_x];
- if( (pixel&0xFF) == 0 ){
- continue;
- }
- if( (pixel&0xFF) < 0xF0 ){
- col = get_stdpx( &stdform, wdplanesize,x,y );
- if( (col != prev_col) || (y == 0) )
- bgcol = (((rgb_lookup[col][2] << 16) | (rgb_lookup[col][1] << 8) | (rgb_lookup[col][0]))<<8);
- if( prev_col != col || prev_pixel != pixel ){
- prev_col = col;
- pixel = ablend( pixel, bgcol );
- prev_pixel = pixel;
- pixel = pixel >> 8;
- /* convert pixel value to vdi color index: */
- col = ( ((pixel&0xFF)<<16)
- | (pixel&0xFF00)
- | ((pixel&0xFF0000)>>16) );
- val = RGB_TO_VDI( col );
- }
- set_stdpx( &stdform, wdplanesize, x, y, val );
- } else {
- if( pixel != prev_pixel ){
- /* convert pixel value to vdi color index: */
- pixel = pixel >> 8;
- col = ( ((pixel&0xFF)<<16)
- | (pixel&0xFF00)
- | ((pixel&0xFF0000)>>16) );
- val = RGB_TO_VDI( col );
- prev_pixel = pixel;
- }
- set_stdpx( &stdform, wdplanesize, x, y, val );
- }
- }
- }
- // adjust output position:
- clip->g_x = 0;
- clip->g_y = 0;
- } else {
- // convert the whole image data to vdi std format.
- for( y=0; y < bh; y++ ){
- row = (uint32_t *)(img->pixdata + (img_stride * y));
- for( x=0; x < bw; x++ ){
- pixel = row[x];
- if( pixel != prev_pixel ){
- /* convert pixel value to vdi color index: */
- pixel = pixel >> 8;
- col = ( ((pixel&0xFF)<<16)
- | (pixel&0xFF00)
- | ((pixel&0xFF0000)>>16) );
- val = RGB_TO_VDI( col );
- prev_pixel = pixel;
- }
- set_stdpx( &stdform, wdplanesize, x, y, val );
- }
- }
- }
-
- // convert into native format:
- native.fd_w = stdform.fd_w;
- native.fd_h = stdform.fd_h;
- native.fd_wdwidth = stdform.fd_wdwidth;
- native.fd_stand = 0;
- native.fd_nplanes = (short)self->bpp_virt;
- native.fd_r1 = native.fd_r2 = native.fd_r3 = 0;
- vr_trnfm( self->vdi_handle, &stdform, &native );
- *out = native;
- if( cache == true ){
- img->native = native;
- img->converted = true;
- }
-
- return(0);
-}
-#endif
-
-/*
- Aplha blends the foreground image (img) onto the
- background images (bg). The background receives the blended
- image pixels.
-*/
-static int ablend_bitmap( struct bitmap * img, struct bitmap * bg,
- GRECT * img_clip, GRECT * bg_clip )
-{
- uint32_t * imgrow;
- uint32_t * screenrow;
- int img_x, img_y, bg_x, bg_y, img_stride, bg_stride;
-
- bg_clip = bg_clip;
- img_stride= bitmap_get_rowstride(img);
- bg_stride = bitmap_get_rowstride(bg);
-
- for( img_y = img_clip->g_y, bg_y = 0; bg_y < img_clip->g_h; bg_y++, img_y++) {
- imgrow = (uint32_t *)(img->pixdata + (img_stride * img_y));
- screenrow = (uint32_t *)(bg->pixdata + (bg_stride * bg_y));
- for( img_x = img_clip->g_x, bg_x = 0; bg_x < img_clip->g_w; bg_x++, img_x++ ) {
-
- // when the pixel isn't fully transparent,...:
- if( (imgrow[img_x] & 0x0FF) != 0 ){
- screenrow[bg_x] = ablend( imgrow[img_x], screenrow[bg_x]);
- }
-
- // FIXME, maybe this loop would be faster??:
- // ---
- //if( (imgrow[img_x] & 0x0FF) != 0xFF ){
- // imgrow[bg_x] = ablend( imgrow[img_x], screenrow[bg_x]);
- //}
-
- // or maybe even this???
- // ---
- //if( (imgrow[img_x] & 0x0FF) == 0xFF ){
- // screenrow[bg_x] = imgrow[img_x];
- //} else if( (imgrow[img_x] & 0x0FF) != 0x00 ) {
- // screenrow[bg_x] = ablend( imgrow[img_x], screenrow[bg_x]);
- //}
- }
- }
- return( 0 );
-}
-
-/*
- Alpha blends an image, using one pixel as the background.
- The bitmap receives the result.
-*/
-static int ablend_pixel( struct bitmap * img, uint32_t bg, GRECT * clip )
-{
- uint32_t * imgrow;
- int img_x, img_y, img_stride;
-
- img_stride= bitmap_get_rowstride(img);
-
- for( img_y = 0; img_y < clip->g_h; img_y++) {
- imgrow = (uint32_t *)(img->pixdata + (img_stride * img_y));
- for( img_x = 0; img_x < clip->g_w; img_x++ ) {
- imgrow[img_x] = ablend( imgrow[img_x], bg );
- }
- }
- return( 0 );
-}
-
-/*
-*
-* Convert bitmap to the native screen format
-* self: the plotter instance
-* img: the bitmap
-* x: coordinate where the bitmap REGION (described in clip)
-* shall be drawn (screen coords)
-* y: coordinate where the bitmap REGION (described in clip)
-* shall be drawn (screen coords)
-* clip: which area of the bitmap shall be drawn
-* bg: background color
-* flags: blit flags
-* out: the result MFDB
-*/
-static int bitmap_convert( GEM_PLOTTER self, struct bitmap * img, int x, int y,
- GRECT * clip, uint32_t bg, uint32_t flags, MFDB *out )
-{
- int dststride; /* stride of dest. image */
- int dstsize; /* size of dest. in byte */
- int err;
- int bw, bh;
- struct bitmap * scrbuf = NULL;
- struct bitmap * source = NULL;
- bool cache = ( flags & BITMAPF_BUFFER_NATIVE );
- bool opaque = bitmap_get_opaque( img );
-
- if( opaque == false ){
- if( ( (self->flags & PLOT_FLAG_TRANS) == 0)
- &&
- ((flags & (BITMAPF_MONOGLYPH|BITMAPF_BUFFER_NATIVE))==0) ){
- opaque = true;
- }
- }
-
-
- assert( clip->g_h > 0 );
- assert( clip->g_w > 0 );
-
- bw = bitmap_get_width( img );
- bh = bitmap_get_height( img );
-
- // The converted bitmap can be saved for subsequent blits, WHEN:
- // A.) the bitmap is fully opaque OR
- // B.) the bitmap is completly inside the window
- // the latter one is important for alpha blits,
- // because we must get the window background to apply transparency
- // If the image is not completly within the window,
- // we can't get the whole background for the image.
- // this only works if the image isn't used at several different places.
- // In fact in case of alpha bitmap caching it is only used for the
- // toolbar buttons right now.
-
- if( (opaque == true) || (flags & BITMAPF_BUFFER_NATIVE ) ){
- if( img->converted == true ){
- *out = img->native;
- return( 0 );
- }
- if( ( flags & BITMAPF_MONOGLYPH ) == 0 ){
- cache = true;
- }
- }
-
- /* rem. if eddi xy is installed, we could directly access the screen! */
- /* apply transparency to the image: */
- if( ( opaque == false ) ) {
- /* copy the screen to an temp buffer: */
- if( (flags & BITMAPF_BUFFER_NATIVE) == 0 ){
- scrbuf = snapshot_create(self, x, y, clip->g_w, clip->g_h );
- if( scrbuf != NULL ) {
-
- assert( clip->g_w <= bw );
- assert( clip->g_h <= bh );
-
- // copy blended pixels to the screen buffer:
- ablend_bitmap( img, scrbuf, clip, NULL );
- /* adjust size which gets converted: */
- bw = clip->g_w;
- bh = clip->g_h;
- /* adjust output position: */
- clip->g_x = 0;
- clip->g_y = 0;
- /* set the source of conversion: */
- source = scrbuf;
- }
- } else {
- /*
- The whole bitmap can be transformed to an mfdb
- (and get's cached)
- */
- GRECT region = { 0, 0, bw, bh };
- ablend_pixel( img, bg, &region );
- source = img;
- }
- } else {
- source = img;
- }
- /* (re)allocate buffer for converted image: */
- dststride = MFDB_STRIDE( bw );
- dstsize = ( ((dststride >> 3) * bh) * self->bpp_virt );
- if( cache == false ){
- if( dstsize > DUMMY_PRIV(self)->size_buf_packed) {
- int blocks = (dstsize / (CONV_BLOCK_SIZE-1))+1;
- if( DUMMY_PRIV(self)->buf_packed == NULL )
- DUMMY_PRIV(self)->buf_packed =(void*)malloc( blocks * CONV_BLOCK_SIZE );
- else
- DUMMY_PRIV(self)->buf_packed =(void*)realloc(
- DUMMY_PRIV(self)->buf_packed,
- blocks * CONV_BLOCK_SIZE
- );
- assert( DUMMY_PRIV(self)->buf_packed );
- if( DUMMY_PRIV(self)->buf_packed == NULL ) {
- if( scrbuf != NULL )
- bitmap_destroy( scrbuf );
- return( 0-ERR_NO_MEM );
- }
- DUMMY_PRIV(self)->size_buf_packed = blocks * CONV_BLOCK_SIZE;
- }
- out->fd_addr = DUMMY_PRIV(self)->buf_packed;
- } else {
- assert( out->fd_addr == NULL );
- out->fd_addr = (void*)malloc( dstsize );
- if( out->fd_addr == NULL ){
- if( scrbuf != NULL )
- bitmap_destroy( scrbuf );
- return( 0-ERR_NO_MEM );
- }
- }
-
- out->fd_w = dststride;
- out->fd_h = bh;
- out->fd_wdwidth = dststride >> 4;
- out->fd_stand = 0;
- out->fd_nplanes = (short)self->bpp_virt;
- out->fd_r1 = out->fd_r2 = out->fd_r3 = 0;
-
- err = Hermes_ConverterRequest(
- hermes_cnv_h,
- &DUMMY_PRIV(self)->nsfmt,
- &DUMMY_PRIV(self)->vfmt
- );
- assert( err != 0 );
-
- // FIXME: here we can use the same optimization which is used for
- // the snapshot creation.
-
- /* convert image to virtual format: */
- err = Hermes_ConverterCopy( hermes_cnv_h,
- source->pixdata,
- 0, /* x src coord of top left in pixel coords */
- 0, /* y src coord of top left in pixel coords */
- bw, bh,
- source->rowstride, /* stride as bytes */
- out->fd_addr,
- 0, /* x dst coord of top left in pixel coords */
- 0, /* y dst coord of top left in pixel coords */
- bw, bh,
- (dststride >> 3) * self->bpp_virt /* stride as bytes */
- );
- assert( err != 0 );
-
- if( cache == true ){
- img->native = *out;
- img->converted = true;
- }
- return( 0 );
-
-}
-
-static void convert_bitmap_done( GEM_PLOTTER self )
-{
- if( DUMMY_PRIV(self)->size_buf_packed > CONV_KEEP_LIMIT ) {
- /* free the mem if it was an large allocation ... */
- DUMMY_PRIV(self)->buf_packed = realloc( DUMMY_PRIV(self)->buf_packed, CONV_KEEP_LIMIT );
- DUMMY_PRIV(self)->size_buf_packed = CONV_KEEP_LIMIT;
- }
- snapshot_suspend( self );
-}
-
-
-static int bitmap( GEM_PLOTTER self, struct bitmap * bmp, int x, int y,
- unsigned long bg, unsigned long flags )
-{
- MFDB src_mf;
- MFDB scrmf;
- short pxy[8];
- GRECT off, clip, vis;
- int screen_x, screen_y;
-
- src_mf.fd_addr = NULL;
- scrmf.fd_addr = NULL;
-
- off.g_x = x;
- off.g_y = y;
- off.g_h = bmp->height;
- off.g_w = bmp->width;
-
- // clip plotter clip rectangle:
- clip.g_x = VIEW( self ).clipping.x0;
- clip.g_y = VIEW( self ).clipping.y0;
- clip.g_w = VIEW( self ).clipping.x1 - VIEW( self ).clipping.x0;
- clip.g_h = VIEW( self ).clipping.y1 - VIEW( self ).clipping.y0;
-
- if( !rc_intersect( &clip, &off) ) {
- return( 1 );
- }
-
- // clip the visible rectangle of the plot area
- // this is the area of the plotter which falls into
- // screen region:
- plotter_get_visible_grect( self, &vis );
- if( !rc_intersect( &vis, &off) ) {
- return( 1 );
- }
-
- screen_x = VIEW(self).x + off.g_x;
- screen_y = VIEW(self).y + off.g_y;
-
- // convert the clipping relative to bitmap:
- off.g_x = off.g_x - x;
- off.g_y = off.g_y - y;
- assert( (off.g_x >= 0) && (off.g_y >= 0) );
-
- /* Convert the Bitmap to native screen format - ready for output. */
- /* This includes blending transparent pixels: */
- if( self->bitmap_convert( self, bmp, screen_x, screen_y, &off, bg, flags, &src_mf) != 0 ) {
- return( 1 );
- }
-
- // setup the src region:
- pxy[0] = off.g_x;
- pxy[1] = off.g_y;
- pxy[2] = off.g_x + off.g_w-1;
- pxy[3] = off.g_y + off.g_h-1;
-
- // setup the target region:
- pxy[4] = screen_x;
- pxy[5] = screen_y;
- pxy[6] = screen_x + off.g_w-1;
- pxy[7] = screen_y + off.g_h-1;
-
- vro_cpyfm( self->vdi_handle, S_ONLY, (short*)&pxy, &src_mf, &scrmf);
- convert_bitmap_done( self );
- return( 1 );
-}
-
-static int plot_mfdb (GEM_PLOTTER self, GRECT * loc, MFDB * insrc, unsigned char fgcolor, uint32_t flags)
-{
-
- MFDB screen, tran;
- MFDB * src;
- short pxy[8];
- short c[2] = {fgcolor, WHITE};
- GRECT off;
-
- plotter_get_clip_grect( self, &off );
- if( rc_intersect(loc, &off) == 0 ){
- return( 1 );
- }
-
- init_mfdb( 0, loc->g_w, loc->g_h, 0, &screen );
-
- if( insrc->fd_stand ){
- int size = init_mfdb( insrc->fd_nplanes, loc->g_w, loc->g_h,
- MFDB_FLAG_NOALLOC,
- &tran
- );
- if( DUMMY_PRIV(self)->size_buf_scr == 0 ){
- DUMMY_PRIV(self)->buf_scr.fd_addr = malloc( size );
- DUMMY_PRIV(self)->size_buf_scr = size;
- } else {
- if( size > DUMMY_PRIV(self)->size_buf_scr ) {
- DUMMY_PRIV(self)->buf_scr.fd_addr = realloc(
- DUMMY_PRIV(self)->buf_scr.fd_addr, size
- );
- DUMMY_PRIV(self)->size_buf_scr = size;
- }
- }
- tran.fd_addr = DUMMY_PRIV(self)->buf_scr.fd_addr;
- vr_trnfm( self->vdi_handle, insrc, &tran );
- src = &tran;
- } else {
- src = insrc;
- }
-
- pxy[0] = off.g_x - loc->g_x;
- pxy[1] = off.g_y - loc->g_y;
- pxy[2] = pxy[0] + off.g_w - 1;
- pxy[3] = pxy[1] + off.g_h - 1;
- pxy[4] = VIEW(self).x + off.g_x;
- pxy[5] = VIEW(self).y + off.g_y;
- pxy[6] = pxy[4] + off.g_w-1;
- pxy[7] = pxy[5] + off.g_h-1;
-
-
- if( flags & PLOT_FLAG_TRANS && src->fd_nplanes == 1){
- vrt_cpyfm( self->vdi_handle, MD_TRANS, (short*)pxy, src, &screen, (short*)&c );
- } else {
- /* this method only plots transparent bitmaps, right now... */
- }
- return( 1 );
-}
-
-static int text(GEM_PLOTTER self, int x, int y, const char *text, size_t length, const plot_font_style_t *fstyle)
-{
- self->font_plotter->text( self->font_plotter, x, y,
- text, length, fstyle
- );
- return ( 1 );
-}
diff --git a/atari/plot/plotter_vdi.h b/atari/plot/plotter_vdi.h
deleted file mode 100755
index 0dd8dcb17..000000000
--- a/atari/plot/plotter_vdi.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright 2010 Ole Loots <ole@monochrom.net>
- *
- * 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/>.
- */
-#ifndef GEM_PLOTTER_DUMMY_H_INCLUDED
-#define GEM_PLOTTER_DUMMY_H_INCLUDED
-
-#include "plotter.h"
-#include <Hermes/Hermes.h>
-
-struct s_view
-{
- short x; /* drawing (screen) offset x */
- short y; /* drawing (screen) offset y */
- short w; /* width of buffer, not in sync with vis_w */
- short h; /* height of buffer, not in sync with vis_w */
- short vis_x; /* visible rectangle of the screen buffer */
- short vis_y; /* coords are relative to plot location */
- short vis_w; /* clipped to screen dimensions */
- short vis_h; /* */
- struct rect clipping;
- int size;
- bool swapped;
- void * mem;
-};
-
-struct s_vdi_priv_data {
- short bufops;
- /* temp buffer for bitmap conversion: */
- void * buf_packed;
- int size_buf_packed;
-
- /* temp buffer for bitmap conversion: */
- void * buf_planar;
- int size_buf_planar;
-
- /* buffer for plot operations that require device format, */
- /* currently used for transparent mfdb blits and snapshots: */
- MFDB buf_scr;
- int size_buf_scr;
-
- /* buffer for std form, used during 8bpp snapshot */
- MFDB buf_std;
- int size_buf_std;
-
- struct bitmap * buf_scr_compat;
-
- /* intermediate bitmap format */
- HermesFormat vfmt;
-
- /* no screen format here, hermes may not suitable for it */
-
- /* netsurf source bitmap format */
- HermesFormat nsfmt;
-
- /* Some internal structure used everywhere */
- /* trying to describe screen position, plotting origins and maxmimum */
- /* extent. */
- struct s_view view;
-};
-
-/* how much memory should be kept allocated for temp. conversion bitmaps: */
-#define CONV_KEEP_LIMIT 512000
-/* how much memory to allocate if some is needed: */
-#define CONV_BLOCK_SIZE 32000
-
-/* this is an shortcut cast to access the members of the s_vdi_priv_data */
-#define DUMMY_PRIV(_self) ((struct s_vdi_priv_data*)_self->priv_data)
-
-#define VIEW( priv ) DUMMY_PRIV( priv )->view
-
-/* Each driver object must export 1 it's own constructor: */
-int ctor_plotter_vdi( GEM_PLOTTER p, GRECT * loc_size );
-
-/*
-* Capture the screen at x,y location
-* param self instance
-* param x absolute screen coords
-* param y absolute screen coords
-* param w width
-* param h height
-*
-* This creates an snapshot in RGBA format (NetSurf's native format)
-*
-*/
-static struct bitmap * snapshot_create(GEM_PLOTTER self, int x, int y, int w, int h);
-
-/* Garbage collection of the snapshot routine */
-/* this should be called after you are done with the data returned by snapshot_create */
-/* don't access the screenshot after you called this function */
-static void snapshot_suspend(GEM_PLOTTER self );
-
-/* destroy memory used by screenshot */
-static void snapshot_destroy( GEM_PLOTTER self );
-
-#endif
diff --git a/atari/statusbar.c b/atari/statusbar.c
index 24c55526a..f4dbbe578 100755
--- a/atari/statusbar.c
+++ b/atari/statusbar.c
@@ -42,10 +42,10 @@
#include "atari/misc.h"
#include "atari/global_evnt.h"
#include "atari/res/netsurf.rsh"
-#include "atari/plot/plotter.h"
+#include "atari/plot/plot.h"
#include "atari/osspec.h"
-extern short vdih;
+extern int atari_plot_vdi_handle;
static
void __CDECL evnt_sb_redraw( COMPONENT *c, long buff[8] )
@@ -69,42 +69,43 @@ void __CDECL evnt_sb_redraw( COMPONENT *c, long buff[8] )
if ( !rc_lintersect( (LGRECT*)&buff[4], &lclip ) ) {
return;
}
- vsf_interior( vdih, FIS_SOLID );
- vsl_color( vdih, BLACK );
- vsl_type( vdih, 1);
- vsl_width( vdih, 1 );
- vst_color(vdih, BLACK);
-
- vst_height( vdih, atari_sysinfo.medium_sfont_pxh, &pxy[0], &pxy[1], &pxy[2], &pxy[3] );
- vst_alignment(vdih, 0, 5, &d, &d );
- vst_effects( vdih, 0 );
+ vsf_interior(atari_plot_vdi_handle, FIS_SOLID );
+ vsl_color(atari_plot_vdi_handle, BLACK );
+ vsl_type(atari_plot_vdi_handle, 1);
+ vsl_width(atari_plot_vdi_handle, 1 );
+ vst_color(atari_plot_vdi_handle, BLACK);
+
+ vst_height(atari_plot_vdi_handle, atari_sysinfo.medium_sfont_pxh, &pxy[0], &pxy[1], &pxy[2], &pxy[3] );
+ vst_alignment(atari_plot_vdi_handle, 0, 5, &d, &d );
+ vst_effects(atari_plot_vdi_handle, 0 );
pxyclip[0] = lclip.g_x;
pxyclip[1] = lclip.g_y;
pxyclip[2] = lclip.g_x + lclip.g_w-1;
pxyclip[3] = lclip.g_y + lclip.g_h-1;
- vs_clip(vdih, 1, (short*)&pxyclip );
- vswr_mode( vdih, MD_REPLACE );
+ vs_clip(atari_plot_vdi_handle, 1, (short*)&pxyclip );
+ vswr_mode(atari_plot_vdi_handle, MD_REPLACE );
if( lclip.g_y <= work.g_y ) {
pxy[0] = work.g_x;
pxy[1] = work.g_y;
pxy[2] = MIN( work.g_x + work.g_w, lclip.g_x + lclip.g_w );
pxy[3] = work.g_y;
- v_pline( vdih, 2, (short*)&pxy );
+ v_pline(atari_plot_vdi_handle, 2, (short*)&pxy );
}
if(app.nplanes > 2) {
- vsf_color( vdih, LWHITE);
+ vsf_color(atari_plot_vdi_handle, LWHITE);
} else {
- vsf_color( vdih, WHITE );
+ vsf_color(atari_plot_vdi_handle, WHITE );
}
pxy[0] = work.g_x;
pxy[1] = work.g_y+1;
pxy[2] = work.g_x + work.g_w-1;
pxy[3] = work.g_y + work.g_h-1;
- v_bar( vdih, pxy );
+ v_bar(atari_plot_vdi_handle, pxy );
+
if( sb->textlen > 0 ) {
short curx;
@@ -114,32 +115,32 @@ void __CDECL evnt_sb_redraw( COMPONENT *c, long buff[8] )
t[1]=0;
if( atari_sysinfo.sfont_monospaced ) {
t[0]='A';
- int r = vqt_width( vdih, t[0], &vqw[0], &vqw[1], &vqw[2] );
+ int r = vqt_width(atari_plot_vdi_handle, t[0], &vqw[0], &vqw[1], &vqw[2] );
cw = vqw[0];
}
- vswr_mode( vdih, MD_TRANS );
+ vswr_mode(atari_plot_vdi_handle, MD_TRANS );
for( curx = work.g_x + 2, i=0 ; (curx+cw < work.g_x+work.g_w ) && i < sb->textlen; i++ ){
t[0] = sb->text[i];
if( !atari_sysinfo.sfont_monospaced ) {
- vqt_width( vdih, t[0], &vqw[0], &vqw[1], &vqw[2] );
+ vqt_width(atari_plot_vdi_handle, t[0], &vqw[0], &vqw[1], &vqw[2] );
cw = vqw[0];
}
if( curx >= lclip.g_x - cw ) {
- v_gtext( vdih, curx, work.g_y + 5, (char*)&t );
+ v_gtext(atari_plot_vdi_handle, curx, work.g_y + 5, (char*)&t );
}
curx += cw;
if( curx >= lclip.g_x + lclip.g_w )
break;
}
}
- vswr_mode( vdih, MD_REPLACE );
+ vswr_mode(atari_plot_vdi_handle, MD_REPLACE );
pxy[0] = work.g_x + work.g_w;
pxy[1] = work.g_y + work.g_h;
pxy[2] = work.g_x + work.g_w;
pxy[3] = work.g_y + work.g_h-work.g_h;
- v_pline( vdih, 2, (short*)&pxy );
+ v_pline(atari_plot_vdi_handle, 2, (short*)&pxy );
- vs_clip(vdih, 0, (short*)&pxyclip );
+ vs_clip(atari_plot_vdi_handle, 0, (short*)&pxyclip );
return;
}
diff --git a/atari/toolbar.c b/atari/toolbar.c
index a17ca8a67..dd822ebc5 100755
--- a/atari/toolbar.c
+++ b/atari/toolbar.c
@@ -37,6 +37,7 @@
#include "desktop/plot_style.h"
#include "desktop/plotters.h"
#include "desktop/tree.h"
+#include "desktop/options.h"
#include "utils/utf8.h"
#include "atari/clipboard.h"
#include "atari/gui.h"
@@ -46,17 +47,16 @@
#include "atari/clipboard.h"
#include "atari/misc.h"
#include "atari/global_evnt.h"
-#include "atari/plot.h"
+#include "atari/plot/plot.h"
#include "cflib.h"
#include "atari/res/netsurf.rsh"
-#include "atari/plot/plotter.h"
extern char * cfg_homepage_url;
-extern short vdih;
extern void * h_gem_rsrc;
-extern GEM_PLOTTER plotter;
extern struct gui_window * input_window;
+extern long atari_plot_flags;
+extern int atari_plot_vdi_handle;
static OBJECT * toolbar_buttons = NULL;
static OBJECT * throbber_form = NULL;
@@ -187,7 +187,7 @@ void toolbar_init( void )
for( i=0; i<n; i++ ){
toolbar_styles[i].bgcolor = toolbar_bg_color;
if( img_toolbar ){
- vq_color( vdih, toolbar_bg_color, 0, vdicolor );
+ vq_color(atari_plot_vdi_handle, toolbar_bg_color, 0, vdicolor );
vdi1000_to_rgb( vdicolor, (unsigned char*)&rgbcolor );
toolbar_styles[i].icon_bgcolor = rgbcolor;
}
@@ -291,9 +291,9 @@ static void __CDECL button_redraw( COMPONENT *c, long buff[8], void * data )
}
/* Setup draw mode: */
- vsf_interior( vdih , 1 );
- vsf_color( vdih, toolbar_styles[tb->style].bgcolor );
- vswr_mode( vdih, MD_REPLACE);
+ vsf_interior(atari_plot_vdi_handle , 1 );
+ vsf_color(atari_plot_vdi_handle, toolbar_styles[tb->style].bgcolor );
+ vswr_mode(atari_plot_vdi_handle, MD_REPLACE);
/* go through the rectangle list, using classic AES methods. */
/* Windom ComGetLGrect is buggy for WF_FIRST/NEXTXYWH */
@@ -310,8 +310,8 @@ static void __CDECL button_redraw( COMPONENT *c, long buff[8], void * data )
pxy[1] = todo.g_y;
pxy[2] = todo.g_w + todo.g_x-1;
pxy[3] = todo.g_h + todo.g_y-1;
- vs_clip( vdih, 1, (short*)&pxy );
- v_bar( vdih, (short*)&pxy );
+ vs_clip(atari_plot_vdi_handle, 1, (short*)&pxy );
+ v_bar(atari_plot_vdi_handle, (short*)&pxy );
if( img_toolbar == true ){
atari_plotters.bitmap( bmpx, bmpy, bmpw, bmph, icon,
@@ -320,7 +320,7 @@ static void __CDECL button_redraw( COMPONENT *c, long buff[8], void * data )
} else {
objc_draw( tree, 0, 0, todo.g_x, todo.g_y, todo.g_w, todo.g_h );
}
- vs_clip( vdih, 0, (short*)&clip );
+ vs_clip(atari_plot_vdi_handle, 0, (short*)&clip );
}
wind_get(gw->root->handle->handle, WF_NEXTXYWH,
&todo.g_x, &todo.g_y, &todo.g_w, &todo.g_h );
@@ -389,17 +389,17 @@ void __CDECL evnt_throbber_redraw( COMPONENT *c, long buff[8])
clip = work;
if ( !rc_lintersect( (LGRECT*)&buff[4], &clip ) ) return;
- vsf_interior( vdih , 1 );
+ vsf_interior(atari_plot_vdi_handle , 1 );
if(app.nplanes > 2 )
- vsf_color( vdih, toolbar_styles[tb->style].bgcolor );
+ vsf_color(atari_plot_vdi_handle, toolbar_styles[tb->style].bgcolor );
else
- vsf_color( vdih, WHITE );
+ vsf_color(atari_plot_vdi_handle, WHITE );
pxy[0] = (short)buff[4];
pxy[1] = (short)buff[5];
pxy[2] = (short)buff[4] + buff[6]-1;
pxy[3] = (short)buff[5] + buff[7]-2;
- v_bar( vdih, (short*)&pxy );
- vs_clip( vdih, 1, (short*)&pxy );
+ v_bar(atari_plot_vdi_handle, (short*)&pxy );
+ vs_clip(atari_plot_vdi_handle, 1, (short*)&pxy );
if( img_toolbar ){
@@ -492,41 +492,41 @@ void __CDECL evnt_url_redraw( COMPONENT *c, long buff[8] )
pxy[1] = clip.g_y;
pxy[2] = clip.g_w + clip.g_x-1;
pxy[3] = clip.g_h + clip.g_y-1;
- vs_clip( vdih, 1, (short*)&pxy );
+ vs_clip(atari_plot_vdi_handle, 1, (short*)&pxy );
- vsf_perimeter( vdih, 0 );
- vsf_interior( vdih , 1 );
- vsf_color( vdih, toolbar_styles[tb->style].bgcolor );
+ vsf_perimeter(atari_plot_vdi_handle, 0 );
+ vsf_interior(atari_plot_vdi_handle , 1 );
+ vsf_color(atari_plot_vdi_handle, toolbar_styles[tb->style].bgcolor );
//left margin:
pxy[0] = work.g_x;
pxy[1] = work.g_y;
pxy[2] = work.g_x + TOOLBAR_URL_MARGIN_LEFT-1;
pxy[3] = work.g_y + work.g_h-1;
- v_bar( vdih, pxy );
+ v_bar(atari_plot_vdi_handle, pxy );
// right margin:
pxy[0] = work.g_x+work.g_w-TOOLBAR_URL_MARGIN_RIGHT;
pxy[1] = work.g_y;
pxy[2] = work.g_x+work.g_w-1;
pxy[3] = work.g_y+work.g_h-1;
- v_bar( vdih, pxy );
+ v_bar(atari_plot_vdi_handle, pxy );
// top margin:
pxy[0] = work.g_x;
pxy[1] = work.g_y;
pxy[2] = work.g_x+work.g_w-1;
pxy[3] = work.g_y+TOOLBAR_URL_MARGIN_TOP-1;
- v_bar( vdih, pxy );
+ v_bar(atari_plot_vdi_handle, pxy );
// bottom margin:
pxy[0] = work.g_x;
pxy[1] = work.g_y+work.g_h-TOOLBAR_URL_MARGIN_BOTTOM;
pxy[2] = work.g_x+work.g_w-1;
pxy[3] = work.g_y+work.g_h-1;
- v_bar( vdih, pxy );
+ v_bar(atari_plot_vdi_handle, pxy );
- vs_clip( vdih, 0, (short*)&pxy );
+ vs_clip(atari_plot_vdi_handle, 0, (short*)&pxy );
// TBD: request redraw of textarea for specific region.
clip.g_x -= work.g_x+TOOLBAR_URL_MARGIN_LEFT;
@@ -619,14 +619,14 @@ static void __CDECL evnt_toolbar_redraw( COMPONENT *c, long buff[8], void *data
if( work.g_y + work.g_h != clip.g_y + clip.g_h ) return;
- vswr_mode( vdih, MD_REPLACE );
- vsl_color( vdih, BLACK );
- vsl_type( vdih, 1 );
- vsl_width( vdih, 1 );
+ vswr_mode(atari_plot_vdi_handle, MD_REPLACE );
+ vsl_color(atari_plot_vdi_handle, BLACK );
+ vsl_type(atari_plot_vdi_handle, 1 );
+ vsl_width(atari_plot_vdi_handle, 1 );
pxy[0] = clip.g_x;
pxy[1] = pxy[3] = work.g_y + work.g_h-1 ;
pxy[2] = clip.g_x + clip.g_w;
- v_pline( vdih, 2, (short*)&pxy );
+ v_pline(atari_plot_vdi_handle, 2, (short*)&pxy );
}
@@ -659,10 +659,11 @@ static void tb_txt_request_redraw(void *data, int x, int y, int w, int h)
}
void tb_url_redraw( struct gui_window * gw )
-{
+{
+
CMP_TOOLBAR t = gw->root->toolbar;
if (t != NULL) {
- if( t->url.redraw && ((plotter->flags & PLOT_FLAG_OFFSCREEN) == 0) ) {
+ if( t->url.redraw && ((atari_plot_flags & PLOT_FLAG_OFFSCREEN) == 0) ) {
const struct redraw_context ctx = {
.interactive = true,
@@ -679,14 +680,14 @@ void tb_url_redraw( struct gui_window * gw )
work.g_h -= TOOLBAR_URL_MARGIN_BOTTOM;
plot_set_dimensions( work.g_x, work.g_y, work.g_w, work.g_h );
- if( plotter->lock( plotter ) == 0 )
+ if(plot_lock() == false)
return;
todo[0] = work.g_x;
todo[1] = work.g_y;
todo[2] = todo[0] + work.g_w-1;
todo[3] = todo[1] + work.g_h-1;
- vs_clip(plotter->vdi_handle, 1, (short*)&todo );
+ vs_clip(atari_plot_vdi_handle, 1, (short*)&todo );
if( wind_get(gw->root->handle->handle, WF_FIRSTXYWH,
&todo[0], &todo[1], &todo[2], &todo[3] )!=0 ) {
@@ -719,11 +720,11 @@ void tb_url_redraw( struct gui_window * gw )
}
}
} else {
- plotter->unlock( plotter );
+ plot_unlock();
return;
}
- plotter->unlock( plotter );
- vs_clip(plotter->vdi_handle, 0, (short*)&todo);
+ plot_unlock();
+ vs_clip(atari_plot_vdi_handle, 0, (short*)&todo);
t->url.redraw = false;
t->url.rdw_area.g_x = 65000;
t->url.rdw_area.g_y = 65000;
diff --git a/atari/toolbar.h b/atari/toolbar.h
index 66b998840..7f8640843 100755
--- a/atari/toolbar.h
+++ b/atari/toolbar.h
@@ -22,7 +22,7 @@
#include "desktop/textarea.h"
#include "desktop/textinput.h"
#include "content/hlcache.h"
-#include "atari/browser.h"
+#include "atari/browser.h"
#define TB_BUTTON_WIDTH 32
#define THROBBER_WIDTH 32
diff --git a/atari/treeview.c b/atari/treeview.c
index d5f9957d3..4a5cb0a75 100755
--- a/atari/treeview.c
+++ b/atari/treeview.c
@@ -35,7 +35,7 @@
#include "utils/utils.h"
#include "atari/gui.h"
#include "atari/treeview.h"
-#include "atari/plot.h"
+#include "atari/plot/plot.h"
#include "atari/misc.h"
#include "cflib.h"
@@ -43,7 +43,8 @@ extern int mouse_hold_start[3];
extern browser_mouse_state bmstate;
extern short last_drag_x;
extern short last_drag_y;
-extern GEM_PLOTTER plotter;
+extern long atari_plot_flags;
+extern int atari_plot_vdi_handle;
static void atari_treeview_resized(struct tree *tree,int w,int h,void *pw);
static void atari_treeview_scroll_visible(int y, int h, void *pw);
@@ -265,9 +266,10 @@ bool atari_treeview_mevent( NSTREEVIEW tv, browser_mouse_state bms, int x, int y
void atari_treeview_redraw( NSTREEVIEW tv)
-{
+{
+
if (tv != NULL) {
- if( tv->redraw && ((plotter->flags & PLOT_FLAG_OFFSCREEN) == 0) ) {
+ if( tv->redraw && ((atari_plot_flags & PLOT_FLAG_OFFSCREEN) == 0) ) {
short todo[4];
GRECT work;
WindGetGrect( tv->window, WF_WORKXYWH, &work );
@@ -277,17 +279,15 @@ void atari_treeview_redraw( NSTREEVIEW tv)
.background_images = true,
.plot = &atari_plotters
};
-
- plotter->resize(plotter, work.g_w, work.g_h);
- plotter->move(plotter, work.g_x, work.g_y );
- if( plotter->lock( plotter ) == 0 )
+ plot_set_dimensions(work.g_x, work.g_y, work.g_w, work.g_h);
+ if (plot_lock() == false)
return;
todo[0] = work.g_x;
todo[1] = work.g_y;
todo[2] = todo[0] + work.g_w-1;
todo[3] = todo[1] + work.g_h-1;
- vs_clip(plotter->vdi_handle, 1, (short*)&todo );
+ vs_clip(atari_plot_vdi_handle, 1, (short*)&todo );
if( wind_get(tv->window->handle, WF_FIRSTXYWH,
&todo[0], &todo[1], &todo[2], &todo[3] )!=0 ) {
@@ -316,11 +316,11 @@ void atari_treeview_redraw( NSTREEVIEW tv)
}
}
} else {
- plotter->unlock( plotter );
+ plot_unlock();
return;
}
- plotter->unlock( plotter );
- vs_clip(plotter->vdi_handle, 0, (short*)&todo);
+ plot_unlock();
+ vs_clip(atari_plot_vdi_handle, 0, (short*)&todo);
tv->redraw = false;
tv->rdw_area.g_x = 65000;
tv->rdw_area.g_y = 65000;
diff --git a/atari/verify_ssl.c b/atari/verify_ssl.c
index 1f56e46f9..e6a57b7b2 100755
--- a/atari/verify_ssl.c
+++ b/atari/verify_ssl.c
@@ -33,12 +33,12 @@
#include "atari/verify_ssl.h"
/*
- todo: this file need to use the treeview api - complete rework,
- current implementation is not used in any way.
+ todo: this file need to use the treeview api - complete rework,
+ current implementation is not used in any way.
*/
extern void * h_gem_rsrc;
-extern short vdih;
+extern short atari_plot_vdi_handle;
#define CERT_INF_LINES 8
@@ -95,15 +95,15 @@ static void __CDECL cert_info_draw( WINDOW * win, short buf[8], void * data)
work.g_h = 176;
maxchars = (work.g_w / 8)+1;
- vs_clip( vdih, 1,(short*) &pxy );
- vswr_mode( vdih, MD_REPLACE );
- vsf_interior( vdih, 1 );
- vsf_color( vdih, LWHITE );
- v_bar( vdih, (short*)&pxy );
- vst_height( vdih, 16, &d, &d, &cbw, &cbh );
- vst_alignment(vdih, 0, 5, &d, &d );
- vst_color( vdih, BLACK );
- vst_effects( vdih, 0 );
+ vs_clip( atari_plot_vdi_handle, 1,(short*) &pxy );
+ vswr_mode( atari_plot_vdi_handle, MD_REPLACE );
+ vsf_interior( atari_plot_vdi_handle, 1 );
+ vsf_color( atari_plot_vdi_handle, LWHITE );
+ v_bar( atari_plot_vdi_handle, (short*)&pxy );
+ vst_height( atari_plot_vdi_handle, 16, &d, &d, &cbw, &cbh );
+ vst_alignment(atari_plot_vdi_handle, 0, 5, &d, &d );
+ vst_color( atari_plot_vdi_handle, BLACK );
+ vst_effects( atari_plot_vdi_handle, 0 );
px_ypos = px_xpos = 0;
for(i=0; i<CERT_INF_LINES; i++ ) {
switch( i ) {
@@ -145,12 +145,12 @@ static void __CDECL cert_info_draw( WINDOW * win, short buf[8], void * data)
if( (int)strlen(line) > dp->scrollx ) {
if( dp->scrollx + maxchars < 511 && ( (signed int)strlen(line) - dp->scrollx) > maxchars )
line[dp->scrollx + maxchars] = 0;
- v_gtext(vdih, work.g_x + 1, work.g_y + px_ypos, &line[dp->scrollx]);
+ v_gtext(atari_plot_vdi_handle, work.g_x + 1, work.g_y + px_ypos, &line[dp->scrollx]);
}
px_ypos += cbh;
}
- vst_alignment(vdih, 0, 0, &d, &d );
- vs_clip( vdih, 0, (short*)&pxy );
+ vst_alignment(atari_plot_vdi_handle, 0, 0, &d, &d );
+ vs_clip( atari_plot_vdi_handle, 0, (short*)&pxy );
free( line );
}
diff --git a/css/select.c b/css/select.c
index 026aedc7c..1ea818f0e 100644
--- a/css/select.c
+++ b/css/select.c
@@ -28,7 +28,6 @@
#include "css/utils.h"
#include "desktop/gui.h"
#include "desktop/options.h"
-#include "render/parser_binding.h"
#include "utils/log.h"
#include "utils/url.h"
#include "utils/utils.h"
diff --git a/javascript/jsapi/document.c b/javascript/jsapi/document.c
index 7d4ebc543..dfad551d6 100644
--- a/javascript/jsapi/document.c
+++ b/javascript/jsapi/document.c
@@ -56,9 +56,9 @@ static JSBool JSAPI_NATIVE(write, JSContext *cx, uintN argc, jsval *vp)
JSString_to_char(u16_txt, txt, length);
- LOG(("content %p parser %p writing %s",htmlc, htmlc->parser_binding, txt));
- if (htmlc->parser_binding != NULL) {
- dom_hubbub_parser_insert_chunk(htmlc->parser_binding, (uint8_t *)txt, length);
+ LOG(("content %p parser %p writing %s",htmlc, htmlc->parser, txt));
+ if (htmlc->parser != NULL) {
+ dom_hubbub_parser_insert_chunk(htmlc->parser, (uint8_t *)txt, length);
}
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
diff --git a/render/box_construct.c b/render/box_construct.c
index c09563d89..5f8b092c5 100644
--- a/render/box_construct.c
+++ b/render/box_construct.c
@@ -1426,7 +1426,7 @@ css_select_results *box_get_style(html_content *c,
dom_string_byte_length(s),
c->encoding,
nsurl_access(content_get_url(&c->base)),
- c->quirks != BINDING_QUIRKS_MODE_NONE,
+ c->quirks != DOM_DOCUMENT_QUIRKS_MODE_NONE,
box_style_alloc, NULL);
dom_string_unref(s);
@@ -1437,7 +1437,7 @@ css_select_results *box_get_style(html_content *c,
/* Populate selection context */
ctx.ctx = c->select_ctx;
- ctx.quirks = (c->quirks == BINDING_QUIRKS_MODE_FULL);
+ ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
ctx.base_url = c->base_url;
ctx.universal = c->universal;
diff --git a/render/box_normalise.c b/render/box_normalise.c
index fb378d3e7..19a1cbc25 100644
--- a/render/box_normalise.c
+++ b/render/box_normalise.c
@@ -152,7 +152,7 @@ bool box_normalise_block(struct box *block, html_content *c)
assert(block->style != NULL);
ctx.ctx = c->select_ctx;
- ctx.quirks = (c->quirks == BINDING_QUIRKS_MODE_FULL);
+ ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
ctx.base_url = c->base_url;
ctx.universal = c->universal;
@@ -254,7 +254,7 @@ bool box_normalise_table(struct box *table, html_content * c)
assert(table->style != NULL);
ctx.ctx = c->select_ctx;
- ctx.quirks = (c->quirks == BINDING_QUIRKS_MODE_FULL);
+ ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
ctx.base_url = c->base_url;
ctx.universal = c->universal;
@@ -341,7 +341,7 @@ bool box_normalise_table(struct box *table, html_content * c)
assert(table->style != NULL);
ctx.ctx = c->select_ctx;
- ctx.quirks = (c->quirks == BINDING_QUIRKS_MODE_FULL);
+ ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
ctx.base_url = c->base_url;
ctx.universal = c->universal;
@@ -477,7 +477,7 @@ bool box_normalise_table_spans(struct box *table, struct span_info *spans,
ctx.ctx = c->select_ctx;
ctx.quirks = (c->quirks ==
- BINDING_QUIRKS_MODE_FULL);
+ DOM_DOCUMENT_QUIRKS_MODE_FULL);
ctx.base_url = c->base_url;
ctx.universal = c->universal;
@@ -587,7 +587,7 @@ bool box_normalise_table_row_group(struct box *row_group,
assert(row_group->style != NULL);
ctx.ctx = c->select_ctx;
- ctx.quirks = (c->quirks == BINDING_QUIRKS_MODE_FULL);
+ ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
ctx.base_url = c->base_url;
ctx.universal = c->universal;
@@ -662,7 +662,7 @@ bool box_normalise_table_row_group(struct box *row_group,
assert(row_group->style != NULL);
ctx.ctx = c->select_ctx;
- ctx.quirks = (c->quirks == BINDING_QUIRKS_MODE_FULL);
+ ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
ctx.base_url = c->base_url;
ctx.universal = c->universal;
@@ -732,7 +732,7 @@ bool box_normalise_table_row(struct box *row,
assert(row->style != NULL);
ctx.ctx = c->select_ctx;
- ctx.quirks = (c->quirks == BINDING_QUIRKS_MODE_FULL);
+ ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
ctx.base_url = c->base_url;
ctx.universal = c->universal;
diff --git a/render/html.c b/render/html.c
index 996bfc3a5..8c11f35b9 100644
--- a/render/html.c
+++ b/render/html.c
@@ -28,8 +28,6 @@
#include <strings.h>
#include <stdlib.h>
-#include <dom/dom.h>
-
#include "utils/config.h"
#include "content/content_protected.h"
#include "content/fetch.h"
@@ -38,7 +36,6 @@
#include "desktop/options.h"
#include "desktop/selection.h"
#include "desktop/scrollbar.h"
-#include "javascript/js.h"
#include "image/bitmap.h"
#include "render/box.h"
#include "render/font.h"
@@ -86,15 +83,15 @@ static dom_string *html_dom_string_head;
static dom_string *html_dom_string_rel;
dom_string *html_dom_string_href;
static dom_string *html_dom_string_hreflang;
-static dom_string *html_dom_string_type;
+dom_string *html_dom_string_type;
static dom_string *html_dom_string_media;
static dom_string *html_dom_string_sizes;
static dom_string *html_dom_string_title;
static dom_string *html_dom_string_base;
static dom_string *html_dom_string_link;
static dom_string *html_dom_string_script;
-static dom_string *html_dom_string_text_javascript;
-static dom_string *html_dom_string_src;
+dom_string *html_dom_string_text_javascript;
+dom_string *html_dom_string_src;
dom_string *html_dom_string_target;
static dom_string *html_dom_string__parent;
static dom_string *html_dom_string__self;
@@ -117,107 +114,6 @@ dom_string *html_dom_string_circle;
dom_string *html_dom_string_poly;
dom_string *html_dom_string_polygon;
-typedef bool (script_handler_t)(struct jscontext *jscontext, const char *data, size_t size) ;
-
-
-static script_handler_t *select_script_handler(content_type ctype)
-{
- if (ctype == CONTENT_JS) {
- return js_exec;
- }
- return NULL;
-}
-
-
-/* attempt to progress script execution
- *
- * execute scripts using algorithm found in:
- * http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#the-script-element
- *
- */
-static bool html_scripts_exec(html_content *c)
-{
- unsigned int i;
- struct html_script *s;
- script_handler_t *script_handler;
-
- if (c->jscontext == NULL)
- return false;
-
- for (i = 0, s = c->scripts; i != c->scripts_count; i++, s++) {
- if (s->already_started) {
- continue;
- }
-
- assert((s->type == HTML_SCRIPT_EXTERNAL) ||
- (s->type == HTML_SCRIPT_INTERNAL));
-
- if (s->type == HTML_SCRIPT_EXTERNAL) {
- /* ensure script content is present */
- if (s->data.external == NULL)
- continue;
-
- /* ensure script content fetch status is not an error */
- if (content_get_status(s->data.external) == CONTENT_STATUS_ERROR)
- continue;
-
- /* ensure script handler for content type */
- script_handler = select_script_handler(content_get_type(s->data.external));
- if (script_handler == NULL)
- continue; /* unsupported type */
-
- if (content_get_status(s->data.external) == CONTENT_STATUS_DONE) {
- /* external script is now available */
- const char *data;
- unsigned long size;
- data = content_get_source_data(s->data.external, &size );
- script_handler(c->jscontext, data, size);
-
- s->already_started = true;
-
- } else {
- /* script not yet available */
-
- /* check if deferable or asynchronous */
- if (!s->defer && !s->async) {
- break;
- }
- }
- }
- }
-
- return true;
-}
-
-/* create new html script entry */
-static struct html_script *
-html_process_new_script(html_content *c, enum html_script_type type)
-{
- struct html_script *nscript;
- /* add space for new script entry */
- nscript = realloc(c->scripts,
- sizeof(struct html_script) * (c->scripts_count + 1));
- if (nscript == NULL) {
- return NULL;
- }
-
- c->scripts = nscript;
-
- /* increment script entry count */
- nscript = &c->scripts[c->scripts_count];
- c->scripts_count++;
-
- nscript->already_started = false;
- nscript->parser_inserted = false;
- nscript->force_async = true;
- nscript->ready_exec = false;
- nscript->async = false;
- nscript->defer = false;
-
- nscript->type = type;
-
- return nscript;
-}
static void html_destroy_objects(html_content *html)
{
@@ -293,8 +189,8 @@ static void html_box_convert_done(html_content *c, bool success)
/*imagemap_dump(c);*/
/* Destroy the parser binding */
- binding_destroy_tree(c->parser_binding);
- c->parser_binding = NULL;
+ dom_hubbub_parser_destroy(c->parser);
+ c->parser = NULL;
content_set_ready(&c->base);
@@ -309,7 +205,7 @@ static void html_box_convert_done(html_content *c, bool success)
*
* \param c Content to convert
*/
-static void html_finish_conversion(html_content *c)
+void html_finish_conversion(html_content *c)
{
union content_msg_data msg_data;
dom_exception exc; /* returned by libdom functions */
@@ -400,217 +296,17 @@ static void html_finish_conversion(html_content *c)
}
-/**
- * Callback for fetchcache() for linked stylesheets.
- */
-
-static nserror
-html_convert_script_callback(hlcache_handle *script,
- const hlcache_event *event,
- void *pw)
-{
- html_content *parent = pw;
- unsigned int i;
- struct html_script *s;
-
- /* Find script */
- for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
- if (s->type == HTML_SCRIPT_EXTERNAL &&
- s->data.external == script)
- break;
- }
-
- assert(i != parent->scripts_count);
-
- switch (event->type) {
- case CONTENT_MSG_LOADING:
- break;
-
- case CONTENT_MSG_READY:
- break;
-
- case CONTENT_MSG_DONE:
- LOG(("script %d done '%s'", i,
- nsurl_access(hlcache_handle_get_url(script))));
- parent->base.active--;
- LOG(("%d fetches active", parent->base.active));
-
- /* script finished loading so try and continue execution */
- html_scripts_exec(parent);
- break;
-
- case CONTENT_MSG_ERROR:
- LOG(("script %s failed: %s",
- nsurl_access(hlcache_handle_get_url(script)),
- event->data.error));
- hlcache_handle_release(script);
- s->data.external = NULL;
- parent->base.active--;
- LOG(("%d fetches active", parent->base.active));
- content_add_error(&parent->base, "?", 0);
-
- /* script failed loading so try and continue execution */
- html_scripts_exec(parent);
-
- break;
-
- case CONTENT_MSG_STATUS:
- html_set_status(parent, content_get_status_message(script));
- content_broadcast(&parent->base, CONTENT_MSG_STATUS,
- event->data);
- break;
-
- default:
- assert(0);
- }
-
- if (parent->base.active == 0)
- html_finish_conversion(parent);
-
- return NSERROR_OK;
-}
-
-/** process script node
- *
- *
- */
-static dom_hubbub_error
-html_process_script(void *ctx, dom_node *node)
-{
- html_content *c = (html_content *)ctx;
- dom_exception exc; /* returned by libdom functions */
- dom_string *src, *script, *mimetype;
- struct html_script *nscript;
- union content_msg_data msg_data;
-
- /* ensure javascript context is available */
- if (c->jscontext == NULL) {
- union content_msg_data msg_data;
-
- msg_data.jscontext = &c->jscontext;
- content_broadcast(&c->base, CONTENT_MSG_GETCTX, msg_data);
- LOG(("javascript context %p ", c->jscontext));
- if (c->jscontext == NULL) {
- /* no context and it could not be created, abort */
- return DOM_HUBBUB_OK;
- }
- }
-
- LOG(("content %p parser %p node %p",c,c->parser_binding, node));
-
- exc = dom_element_get_attribute(node, html_dom_string_type, &mimetype);
- if (exc != DOM_NO_ERR || mimetype == NULL) {
- mimetype = dom_string_ref(html_dom_string_text_javascript);
- }
-
- exc = dom_element_get_attribute(node, html_dom_string_src, &src);
- if (exc != DOM_NO_ERR || src == NULL) {
- struct lwc_string_s *lwcmimetype;
- script_handler_t *script_handler;
-
- /* does not appear to be a src so script is inline content */
- exc = dom_node_get_text_content(node, &script);
- if ((exc != DOM_NO_ERR) || (script == NULL)) {
- dom_string_unref(mimetype);
- return DOM_HUBBUB_OK; /* no contents, skip */
- }
-
- nscript = html_process_new_script(c, HTML_STYLESHEET_INTERNAL);
- if (nscript == NULL) {
- dom_string_unref(mimetype);
- dom_string_unref(script);
- goto html_process_script_no_memory;
- }
-
- nscript->data.internal = script;
- nscript->mimetype = mimetype;
- nscript->already_started = true;
-
- /* charset (encoding) */
-
- /* ensure script handler for content type */
- dom_string_intern(mimetype, &lwcmimetype);
- script_handler = select_script_handler(content_factory_type_from_mime_type(lwcmimetype));
- lwc_string_unref(lwcmimetype);
-
- if (script_handler != NULL) {
- script_handler(c->jscontext,
- dom_string_data(script),
- dom_string_byte_length(script));
- }
-
-
- } else {
- /* script with a src tag */
- nserror ns_error;
- nsurl *joined;
- hlcache_child_context child;
-
-
- nscript = html_process_new_script(c, HTML_STYLESHEET_EXTERNAL);
- if (nscript == NULL) {
- dom_string_unref(src);
- dom_string_unref(mimetype);
- goto html_process_script_no_memory;
- }
-
- /* charset (encoding) */
-
- ns_error = nsurl_join(c->base_url, dom_string_data(src), &joined);
- dom_string_unref(src);
- if (ns_error != NSERROR_OK) {
- dom_string_unref(mimetype);
- goto html_process_script_no_memory;
- }
-
- nscript->mimetype = mimetype; /* keep reference to mimetype */
-
- LOG(("script %i '%s'", c->scripts_count, nsurl_access(joined)));
-
- child.charset = c->encoding;
- child.quirks = c->base.quirks;
-
- ns_error = hlcache_handle_retrieve(joined,
- 0,
- content_get_url(&c->base),
- NULL,
- html_convert_script_callback,
- c,
- &child,
- CONTENT_SCRIPT,
- &nscript->data.external);
-
- nsurl_unref(joined);
-
- if (ns_error != NSERROR_OK) {
- goto html_process_script_no_memory;
- }
-
- c->base.active++; /* ensure base content knows the fetch is active */
- LOG(("%d fetches active", c->base.active));
-
- }
- html_scripts_exec(c);
-
- return DOM_HUBBUB_OK;
-
-html_process_script_no_memory:
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- return DOM_HUBBUB_NOMEM;
-}
static nserror
html_create_html_data(html_content *c, const http_parameter *params)
{
lwc_string *charset;
union content_msg_data msg_data;
- binding_error error;
nserror nerror;
- c->parser_binding = NULL;
+ c->parser = NULL;
c->document = NULL;
- c->quirks = BINDING_QUIRKS_MODE_NONE;
+ c->quirks = DOM_DOCUMENT_QUIRKS_MODE_NONE;
c->encoding = NULL;
c->base_url = nsurl_ref(content_get_url(&c->base));
c->base_target = NULL;
@@ -637,8 +333,10 @@ html_create_html_data(html_content *c, const http_parameter *params)
c->jscontext = NULL;
if (lwc_intern_string("*", SLEN("*"), &c->universal) != lwc_error_ok) {
- error = BINDING_NOMEM;
- goto error;
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+
+ return NSERROR_NOMEM;
}
selection_prepare(&c->sel, (struct content *)c, true);
@@ -650,60 +348,56 @@ html_create_html_data(html_content *c, const http_parameter *params)
lwc_string_unref(charset);
if (c->encoding == NULL) {
- error = BINDING_NOMEM;
- goto error;
+ lwc_string_unref(c->universal);
+ c->universal = NULL;
+
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+
+ return NSERROR_NOMEM;
+
}
- c->encoding_source = ENCODING_SOURCE_HEADER;
+ c->encoding_source = DOM_HUBBUB_ENCODING_SOURCE_HEADER;
}
/* Create the parser binding */
- error = binding_create_tree(&c->parser_binding,
- c->encoding,
- nsoption_bool(enable_javascript),
- html_process_script,
- c);
- if (error == BINDING_BADENCODING && c->encoding != NULL) {
+ c->parser = dom_hubbub_parser_create(c->encoding,
+ true,
+ nsoption_bool(enable_javascript),
+ NULL,
+ html_process_script,
+ c);
+ if ((c->parser == NULL) && (c->encoding != NULL)) {
/* Ok, we don't support the declared encoding. Bailing out
* isn't exactly user-friendly, so fall back to autodetect */
talloc_free(c->encoding);
c->encoding = NULL;
- error = binding_create_tree(&c->parser_binding,
- c->encoding,
- nsoption_bool(enable_javascript),
- html_process_script,
- c);
+ c->parser = dom_hubbub_parser_create(c->encoding,
+ true,
+ nsoption_bool(enable_javascript),
+ NULL,
+ html_process_script,
+ c);
- }
-
- if (error != BINDING_OK)
- goto error;
- return NSERROR_OK;
-
-error:
- if (error == BINDING_BADENCODING) {
- LOG(("Bad encoding: %s", c->encoding ? c->encoding : ""));
- msg_data.error = messages_get("ParsingFail");
- nerror = NSERROR_BAD_ENCODING;
- } else {
- msg_data.error = messages_get("NoMemory");
- nerror = NSERROR_NOMEM;
}
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ if (c->parser == NULL) {
+ nsurl_unref(c->base_url);
+ c->base_url = NULL;
- if (c->universal != NULL) {
lwc_string_unref(c->universal);
c->universal = NULL;
- }
- if (c->base_url != NULL) {
- nsurl_unref(c->base_url);
- c->base_url = NULL;
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+
+ return NSERROR_NOMEM;
}
- return nerror;
+ return NSERROR_OK;
+
}
/**
@@ -757,14 +451,16 @@ static bool
html_process_data(struct content *c, const char *data, unsigned int size)
{
html_content *html = (html_content *) c;
- binding_error err;
+ dom_hubbub_error error;
const char *encoding;
+ const char *source_data;
+ unsigned long source_size;
- err = binding_parse_chunk(html->parser_binding,
- (const uint8_t *) data, size);
- if (err == BINDING_ENCODINGCHANGE) {
+ error = dom_hubbub_parser_parse_chunk(html->parser, (const uint8_t *) data, size);
+
+ if (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE)) {
goto encoding_change;
- } else if (err != BINDING_OK) {
+ } else if (error != DOM_HUBBUB_OK) {
union content_msg_data msg_data;
msg_data.error = messages_get("NoMemory");
@@ -778,9 +474,8 @@ html_process_data(struct content *c, const char *data, unsigned int size)
encoding_change:
/* Retrieve new encoding */
- encoding = binding_get_encoding(
- html->parser_binding,
- &html->encoding_source);
+ encoding = dom_hubbub_parser_get_encoding(html->parser,
+ &html->encoding_source);
if (html->encoding != NULL)
talloc_free(html->encoding);
@@ -795,16 +490,17 @@ encoding_change:
}
/* Destroy binding */
- binding_destroy_tree(html->parser_binding);
- html->parser_binding = NULL;
+ dom_hubbub_parser_destroy(html->parser);
+ html->parser = NULL;
/* Create new binding, using the new encoding */
- err = binding_create_tree(&html->parser_binding,
- html->encoding,
- nsoption_bool(enable_javascript),
- html_process_script,
- html);
- if (err == BINDING_BADENCODING) {
+ html->parser = dom_hubbub_parser_create(html->encoding,
+ true,
+ nsoption_bool(enable_javascript),
+ NULL,
+ html_process_script,
+ html);
+ if (html->parser == NULL) {
/* Ok, we don't support the declared encoding. Bailing out
* isn't exactly user-friendly, so fall back to Windows-1252 */
talloc_free(html->encoding);
@@ -817,37 +513,35 @@ encoding_change:
return false;
}
- err = binding_create_tree(&html->parser_binding,
- html->encoding,
- nsoption_bool(enable_javascript),
- html_process_script,
- html);
- }
+ html->parser = dom_hubbub_parser_create(html->encoding,
+ true,
+ nsoption_bool(enable_javascript),
+ NULL,
+ html_process_script,
+ html);
- if (err != BINDING_OK) {
- union content_msg_data msg_data;
+ if (html->parser == NULL) {
+ union content_msg_data msg_data;
+
+ /** @todo add a message callback function and pass the
+ * parser errors back instead of everything being
+ * OOM
+ */
- if (err == BINDING_BADENCODING) {
- LOG(("Bad encoding: %s", html->encoding
- ? html->encoding : ""));
- msg_data.error = messages_get("ParsingFail");
- } else
msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- }
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ return false;
+ }
- {
- const char *source_data;
- unsigned long source_size;
+ }
- source_data = content__get_source_data(c, &source_size);
+ source_data = content__get_source_data(c, &source_size);
- /* Recurse to reprocess all the data. This is safe because
- * the encoding is now specified at parser start which means
- * it cannot be changed again. */
- return html_process_data(c, source_data, source_size);
- }
+ /* Recurse to reprocess all the data. This is safe because
+ * the encoding is now specified at parser start which means
+ * it cannot be changed again. */
+ return html_process_data(c, source_data, source_size);
+
}
@@ -2156,7 +1850,7 @@ static bool html_find_stylesheets(html_content *c, dom_node *html)
c->base.active++;
LOG(("%d fetches active", c->base.active));
- if (c->quirks == BINDING_QUIRKS_MODE_FULL) {
+ if (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL) {
ns_error = hlcache_handle_retrieve(html_quirks_stylesheet_url,
0, content_get_url(&c->base), NULL,
html_convert_css_callback, c, &child,
@@ -2224,7 +1918,7 @@ html_find_stylesheets_no_memory:
static bool html_convert(struct content *c)
{
html_content *htmlc = (html_content *) c;
- binding_error err;
+ dom_hubbub_error err;
dom_node *html, *head;
union content_msg_data msg_data;
unsigned long size;
@@ -2235,18 +1929,18 @@ static bool html_convert(struct content *c)
/* finish parsing */
content__get_source_data(c, &size);
- err = binding_parse_completed(htmlc->parser_binding);
- if (err != BINDING_OK) {
+ err = dom_hubbub_parser_completed(htmlc->parser);
+ if (err != DOM_HUBBUB_OK) {
union content_msg_data msg_data;
+ /** @todo Improve precessing of errors */
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
return false;
}
- htmlc->document = binding_get_document(htmlc->parser_binding,
- &htmlc->quirks);
+ htmlc->document = dom_hubbub_parser_get_document(htmlc->parser);
if (htmlc->document == NULL) {
LOG(("Parsing failed"));
@@ -2255,10 +1949,18 @@ static bool html_convert(struct content *c)
return false;
}
+ exc = dom_document_get_quirks_mode(htmlc->document, &htmlc->quirks);
+ if (exc != DOM_NO_ERR) {
+ LOG(("error retrieving quirks"));
+ }
+
+ LOG(("quirks set to %d", htmlc->quirks));
+
+
if (htmlc->encoding == NULL) {
- const char *encoding = binding_get_encoding(
- htmlc->parser_binding,
- &htmlc->encoding_source);
+ const char *encoding;
+ encoding = dom_hubbub_parser_get_encoding(htmlc->parser,
+ &htmlc->encoding_source);
htmlc->encoding = talloc_strdup(c, encoding);
if (htmlc->encoding == NULL) {
@@ -2667,13 +2369,14 @@ static void html_destroy(struct content *c)
if (html->base_url)
nsurl_unref(html->base_url);
- if (html->parser_binding != NULL) {
- binding_destroy_tree(html->parser_binding);
- html->parser_binding = NULL;
+ if (html->parser != NULL) {
+ dom_hubbub_parser_destroy(html->parser);
+ html->parser = NULL;
}
- if (html->document != NULL)
- binding_destroy_document(html->document);
+ if (html->document != NULL) {
+ dom_node_unref(html->document);
+ }
/* Free base target */
if (html->base_target != NULL) {
@@ -3244,7 +2947,7 @@ const char *html_get_encoding(hlcache_handle *h)
* \param h Content to retrieve charset from
* \return Pointer to charset, or NULL
*/
-binding_encoding_source html_get_encoding_source(hlcache_handle *h)
+dom_hubbub_encoding_source html_get_encoding_source(hlcache_handle *h)
{
html_content *c = (html_content *) hlcache_handle_get_content(h);
diff --git a/render/html.h b/render/html.h
index 5867bcff2..64548f810 100644
--- a/render/html.h
+++ b/render/html.h
@@ -26,11 +26,14 @@
#define _NETSURF_RENDER_HTML_H_
#include <stdbool.h>
+
+#include <dom/dom.h>
+#include <dom/bindings/hubbub/parser.h>
+
#include "content/content_type.h"
#include "css/css.h"
#include "desktop/mouse.h"
#include "desktop/plot_style.h"
-#include "render/parser_binding.h"
#include "desktop/frame_types.h"
struct fetch_multipart_data;
@@ -167,7 +170,7 @@ bool text_redraw(const char *utf8_text, size_t utf8_len,
dom_document *html_get_document(struct hlcache_handle *h);
struct box *html_get_box_tree(struct hlcache_handle *h);
const char *html_get_encoding(struct hlcache_handle *h);
-binding_encoding_source html_get_encoding_source(struct hlcache_handle *h);
+dom_hubbub_encoding_source html_get_encoding_source(struct hlcache_handle *h);
struct content_html_frames *html_get_frameset(struct hlcache_handle *h);
struct content_html_iframe *html_get_iframe(struct hlcache_handle *h);
nsurl *html_get_base_url(struct hlcache_handle *h);
diff --git a/render/html_internal.h b/render/html_internal.h
index d5e1f05f3..ad032f720 100644
--- a/render/html_internal.h
+++ b/render/html_internal.h
@@ -31,17 +31,17 @@
typedef struct html_content {
struct content base;
- /** Parser object handle */
- void *parser_binding;
+ dom_hubbub_parser *parser; /**< Parser object handle */
+
/** Document tree */
dom_document *document;
/** Quirkyness of document */
- binding_quirks_mode quirks;
+ dom_document_quirks_mode quirks;
/** Encoding of source, NULL if unknown. */
char *encoding;
/** Source of encoding information. */
- binding_encoding_source encoding_source;
+ dom_hubbub_encoding_source encoding_source;
/** Base URL (may be a copy of content->url). */
nsurl *base_url;
@@ -127,6 +127,12 @@ void html__redraw_a_box(struct content *c, struct box *box);
struct browser_window *html_get_browser_window(struct content *c);
struct search_context *html_get_search(struct content *c);
void html_set_search(struct content *c, struct search_context *s);
+/**
+ * Complete conversion of an HTML document
+ *
+ * \param c Content to convert
+ */
+void html_finish_conversion(html_content *c);
/* in render/html_redraw.c */
bool html_redraw(struct content *c, struct content_redraw_data *data,
@@ -140,6 +146,10 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
void html_overflow_scroll_callback(void *client_data,
struct scrollbar_msg_data *scrollbar_data);
+
+/* in render/html_script.c */
+dom_hubbub_error html_process_script(void *ctx, dom_node *node);
+
/* in render/html_forms.c */
struct form *html_forms_get_forms(const char *docenc, dom_html_document *doc);
struct form_control *html_forms_get_control_for_node(struct form *forms, dom_node *node);
@@ -163,6 +173,9 @@ extern struct dom_string *html_dom_string_coords;
extern struct dom_string *html_dom_string_circle;
extern struct dom_string *html_dom_string_poly;
extern struct dom_string *html_dom_string_polygon;
+extern struct dom_string *html_dom_string_text_javascript;
+extern struct dom_string *html_dom_string_type;
+extern struct dom_string *html_dom_string_src;
#endif
diff --git a/render/html_script.c b/render/html_script.c
new file mode 100644
index 000000000..631dcca1e
--- /dev/null
+++ b/render/html_script.c
@@ -0,0 +1,339 @@
+/*
+ * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * 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/>.
+ */
+
+/** \file
+ * Content for text/html scripts (implementation).
+ */
+
+#include <assert.h>
+#include <ctype.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+
+#include "utils/config.h"
+#include "utils/log.h"
+#include "utils/messages.h"
+#include "javascript/js.h"
+#include "content/content_protected.h"
+#include "content/fetch.h"
+#include "render/html_internal.h"
+
+typedef bool (script_handler_t)(struct jscontext *jscontext, const char *data, size_t size) ;
+
+
+static script_handler_t *select_script_handler(content_type ctype)
+{
+ if (ctype == CONTENT_JS) {
+ return js_exec;
+ }
+ return NULL;
+}
+
+
+/* attempt to progress script execution
+ *
+ * execute scripts using algorithm found in:
+ * http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#the-script-element
+ *
+ */
+static bool html_scripts_exec(html_content *c)
+{
+ unsigned int i;
+ struct html_script *s;
+ script_handler_t *script_handler;
+
+ if (c->jscontext == NULL)
+ return false;
+
+ for (i = 0, s = c->scripts; i != c->scripts_count; i++, s++) {
+ if (s->already_started) {
+ continue;
+ }
+
+ assert((s->type == HTML_SCRIPT_EXTERNAL) ||
+ (s->type == HTML_SCRIPT_INTERNAL));
+
+ if (s->type == HTML_SCRIPT_EXTERNAL) {
+ /* ensure script content is present */
+ if (s->data.external == NULL)
+ continue;
+
+ /* ensure script content fetch status is not an error */
+ if (content_get_status(s->data.external) == CONTENT_STATUS_ERROR)
+ continue;
+
+ /* ensure script handler for content type */
+ script_handler = select_script_handler(content_get_type(s->data.external));
+ if (script_handler == NULL)
+ continue; /* unsupported type */
+
+ if (content_get_status(s->data.external) == CONTENT_STATUS_DONE) {
+ /* external script is now available */
+ const char *data;
+ unsigned long size;
+ data = content_get_source_data(s->data.external, &size );
+ script_handler(c->jscontext, data, size);
+
+ s->already_started = true;
+
+ } else {
+ /* script not yet available */
+
+ /* check if deferable or asynchronous */
+ if (!s->defer && !s->async) {
+ break;
+ }
+ }
+ }
+ }
+
+ return true;
+}
+
+/* create new html script entry */
+static struct html_script *
+html_process_new_script(html_content *c, enum html_script_type type)
+{
+ struct html_script *nscript;
+ /* add space for new script entry */
+ nscript = realloc(c->scripts,
+ sizeof(struct html_script) * (c->scripts_count + 1));
+ if (nscript == NULL) {
+ return NULL;
+ }
+
+ c->scripts = nscript;
+
+ /* increment script entry count */
+ nscript = &c->scripts[c->scripts_count];
+ c->scripts_count++;
+
+ nscript->already_started = false;
+ nscript->parser_inserted = false;
+ nscript->force_async = true;
+ nscript->ready_exec = false;
+ nscript->async = false;
+ nscript->defer = false;
+
+ nscript->type = type;
+
+ return nscript;
+}
+
+/**
+ * Callback for fetchcache() for linked stylesheets.
+ */
+
+static nserror
+html_convert_script_callback(hlcache_handle *script,
+ const hlcache_event *event,
+ void *pw)
+{
+ html_content *parent = pw;
+ unsigned int i;
+ struct html_script *s;
+
+ /* Find script */
+ for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
+ if (s->type == HTML_SCRIPT_EXTERNAL &&
+ s->data.external == script)
+ break;
+ }
+
+ assert(i != parent->scripts_count);
+
+ switch (event->type) {
+ case CONTENT_MSG_LOADING:
+ break;
+
+ case CONTENT_MSG_READY:
+ break;
+
+ case CONTENT_MSG_DONE:
+ LOG(("script %d done '%s'", i,
+ nsurl_access(hlcache_handle_get_url(script))));
+ parent->base.active--;
+ LOG(("%d fetches active", parent->base.active));
+
+ /* script finished loading so try and continue execution */
+ html_scripts_exec(parent);
+ break;
+
+ case CONTENT_MSG_ERROR:
+ LOG(("script %s failed: %s",
+ nsurl_access(hlcache_handle_get_url(script)),
+ event->data.error));
+ hlcache_handle_release(script);
+ s->data.external = NULL;
+ parent->base.active--;
+ LOG(("%d fetches active", parent->base.active));
+ content_add_error(&parent->base, "?", 0);
+
+ /* script failed loading so try and continue execution */
+ html_scripts_exec(parent);
+
+ break;
+
+ case CONTENT_MSG_STATUS:
+ html_set_status(parent, content_get_status_message(script));
+ content_broadcast(&parent->base, CONTENT_MSG_STATUS,
+ event->data);
+ break;
+
+ default:
+ assert(0);
+ }
+
+ if (parent->base.active == 0)
+ html_finish_conversion(parent);
+
+ return NSERROR_OK;
+}
+
+/** process script node
+ *
+ *
+ */
+dom_hubbub_error
+html_process_script(void *ctx, dom_node *node)
+{
+ html_content *c = (html_content *)ctx;
+ dom_exception exc; /* returned by libdom functions */
+ dom_string *src, *script, *mimetype;
+ struct html_script *nscript;
+ union content_msg_data msg_data;
+
+ /* ensure javascript context is available */
+ if (c->jscontext == NULL) {
+ union content_msg_data msg_data;
+
+ msg_data.jscontext = &c->jscontext;
+ content_broadcast(&c->base, CONTENT_MSG_GETCTX, msg_data);
+ LOG(("javascript context %p ", c->jscontext));
+ if (c->jscontext == NULL) {
+ /* no context and it could not be created, abort */
+ return DOM_HUBBUB_OK;
+ }
+ }
+
+ LOG(("content %p parser %p node %p",c,c->parser, node));
+
+ exc = dom_element_get_attribute(node, html_dom_string_type, &mimetype);
+ if (exc != DOM_NO_ERR || mimetype == NULL) {
+ mimetype = dom_string_ref(html_dom_string_text_javascript);
+ }
+
+ exc = dom_element_get_attribute(node, html_dom_string_src, &src);
+ if (exc != DOM_NO_ERR || src == NULL) {
+ struct lwc_string_s *lwcmimetype;
+ script_handler_t *script_handler;
+
+ /* does not appear to be a src so script is inline content */
+ exc = dom_node_get_text_content(node, &script);
+ if ((exc != DOM_NO_ERR) || (script == NULL)) {
+ dom_string_unref(mimetype);
+ return DOM_HUBBUB_OK; /* no contents, skip */
+ }
+
+ nscript = html_process_new_script(c, HTML_STYLESHEET_INTERNAL);
+ if (nscript == NULL) {
+ dom_string_unref(mimetype);
+ dom_string_unref(script);
+ goto html_process_script_no_memory;
+ }
+
+ nscript->data.internal = script;
+ nscript->mimetype = mimetype;
+ nscript->already_started = true;
+
+ /* charset (encoding) */
+
+ /* ensure script handler for content type */
+ dom_string_intern(mimetype, &lwcmimetype);
+ script_handler = select_script_handler(content_factory_type_from_mime_type(lwcmimetype));
+ lwc_string_unref(lwcmimetype);
+
+ if (script_handler != NULL) {
+ script_handler(c->jscontext,
+ dom_string_data(script),
+ dom_string_byte_length(script));
+ }
+
+
+ } else {
+ /* script with a src tag */
+ nserror ns_error;
+ nsurl *joined;
+ hlcache_child_context child;
+
+
+ nscript = html_process_new_script(c, HTML_STYLESHEET_EXTERNAL);
+ if (nscript == NULL) {
+ dom_string_unref(src);
+ dom_string_unref(mimetype);
+ goto html_process_script_no_memory;
+ }
+
+ /* charset (encoding) */
+
+ ns_error = nsurl_join(c->base_url, dom_string_data(src), &joined);
+ dom_string_unref(src);
+ if (ns_error != NSERROR_OK) {
+ dom_string_unref(mimetype);
+ goto html_process_script_no_memory;
+ }
+
+ nscript->mimetype = mimetype; /* keep reference to mimetype */
+
+ LOG(("script %i '%s'", c->scripts_count, nsurl_access(joined)));
+
+ child.charset = c->encoding;
+ child.quirks = c->base.quirks;
+
+ ns_error = hlcache_handle_retrieve(joined,
+ 0,
+ content_get_url(&c->base),
+ NULL,
+ html_convert_script_callback,
+ c,
+ &child,
+ CONTENT_SCRIPT,
+ &nscript->data.external);
+
+ nsurl_unref(joined);
+
+ if (ns_error != NSERROR_OK) {
+ goto html_process_script_no_memory;
+ }
+
+ c->base.active++; /* ensure base content knows the fetch is active */
+ LOG(("%d fetches active", c->base.active));
+
+ }
+ html_scripts_exec(c);
+
+ return DOM_HUBBUB_OK;
+
+html_process_script_no_memory:
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return DOM_HUBBUB_NOMEM;
+}
diff --git a/render/hubbub_binding.c b/render/hubbub_binding.c
deleted file mode 100644
index 2f9899fad..000000000
--- a/render/hubbub_binding.c
+++ /dev/null
@@ -1,1325 +0,0 @@
-/*
- * Copyright 2008 Andrew Sidwell <takkaria@netsurf-browser.org>
- * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
- *
- * 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/>.
- */
-
-#include <assert.h>
-#include <stdbool.h>
-#include <string.h>
-
-#include <libxml/HTMLparser.h>
-#include <libxml/HTMLtree.h>
-
-#include <hubbub/parser.h>
-#include <hubbub/tree.h>
-
-#include "render/form.h"
-#include "render/parser_binding.h"
-
-#include "utils/config.h"
-#include "utils/log.h"
-#include "utils/talloc.h"
-#include "utils/utils.h"
-
-/**
- * Private data attached to each DOM node
- */
-typedef struct hubbub_private {
- binding_private base;
-
- uint32_t refcnt;
-} hubbub_private;
-
-typedef struct hubbub_ctx {
- hubbub_parser *parser;
-
- htmlDocPtr document;
- bool owns_doc;
-
- binding_quirks_mode quirks;
-
- const char *encoding;
- binding_encoding_source encoding_source;
-
-#define NUM_NAMESPACES (6)
- xmlNsPtr namespaces[NUM_NAMESPACES];
-#undef NUM_NAMESPACES
-
- hubbub_tree_handler tree_handler;
-
- struct form *forms;
-} hubbub_ctx;
-
-static struct {
- const char *prefix;
- const char *url;
-} namespaces[] = {
- { NULL, NULL },
- { NULL, "http://www.w3.org/1999/xhtml" },
- { "math", "http://www.w3.org/1998/Math/MathML" },
- { "svg", "http://www.w3.org/2000/svg" },
- { "xlink", "http://www.w3.org/1999/xlink" },
- /** \todo Oh dear. LibXML2 refuses to create any namespace with a
- * prefix of "xml". That sucks, royally. */
- { "xml", "http://www.w3.org/XML/1998/namespace" },
- { "xmlns", "http://www.w3.org/2000/xmlns/" }
-};
-
-static hubbub_private *create_private(uint32_t refcnt);
-static hubbub_private *copy_private(const hubbub_private *p, uint32_t refcnt);
-static void destroy_private(hubbub_private *p);
-static inline char *c_string_from_hubbub_string(hubbub_ctx *ctx,
- const hubbub_string *str);
-static void create_namespaces(hubbub_ctx *ctx, xmlNode *root);
-static hubbub_error create_comment(void *ctx, const hubbub_string *data,
- void **result);
-static hubbub_error create_doctype(void *ctx, const hubbub_doctype *doctype,
- void **result);
-static hubbub_error create_element(void *ctx, const hubbub_tag *tag,
- void **result);
-static hubbub_error create_text(void *ctx, const hubbub_string *data,
- void **result);
-static hubbub_error ref_node(void *ctx, void *node);
-static hubbub_error unref_node(void *ctx, void *node);
-static hubbub_error append_child(void *ctx, void *parent, void *child,
- void **result);
-static hubbub_error insert_before(void *ctx, void *parent, void *child,
- void *ref_child, void **result);
-static hubbub_error remove_child(void *ctx, void *parent, void *child,
- void **result);
-static hubbub_error clone_node(void *ctx, void *node, bool deep, void **result);
-static hubbub_error reparent_children(void *ctx, void *node, void *new_parent);
-static hubbub_error get_parent(void *ctx, void *node, bool element_only,
- void **result);
-static hubbub_error has_children(void *ctx, void *node, bool *result);
-static hubbub_error form_associate(void *ctx, void *form, void *node);
-static hubbub_error add_attributes(void *ctx, void *node,
- const hubbub_attribute *attributes, uint32_t n_attributes);
-static hubbub_error set_quirks_mode(void *ctx, hubbub_quirks_mode mode);
-static hubbub_error change_encoding(void *ctx, const char *charset);
-
-static struct form *parse_form_element(xmlNode *node, const char *docenc);
-static struct form_control *parse_input_element(xmlNode *node);
-static struct form_control *parse_button_element(xmlNode *node);
-static struct form_control *parse_select_element(xmlNode *node);
-static struct form_control *parse_textarea_element(xmlNode *node);
-
-static hubbub_tree_handler tree_handler = {
- create_comment,
- create_doctype,
- create_element,
- create_text,
- ref_node,
- unref_node,
- append_child,
- insert_before,
- remove_child,
- clone_node,
- reparent_children,
- get_parent,
- has_children,
- form_associate,
- add_attributes,
- set_quirks_mode,
- change_encoding,
- NULL
-};
-
-static void *ns_talloc_based_realloc(void *ptr, size_t len, void *pw)
-{
- /* talloc_realloc_size(pw, ptr, 0) == talloc_free(ptr) */
- return talloc_realloc_size(pw, ptr, len);
-}
-
-binding_error binding_create_tree(void *arena, const char *charset, void **ctx)
-{
- hubbub_ctx *c;
- hubbub_parser_optparams params;
- uint32_t i;
- hubbub_error error;
-
- c = malloc(sizeof(hubbub_ctx));
- if (c == NULL)
- return BINDING_NOMEM;
-
- c->parser = NULL;
- c->encoding = charset;
- c->encoding_source = charset != NULL ? ENCODING_SOURCE_HEADER
- : ENCODING_SOURCE_DETECTED;
- c->document = NULL;
- c->owns_doc = true;
- c->quirks = BINDING_QUIRKS_MODE_NONE;
- c->forms = NULL;
-
- error = hubbub_parser_create(charset, true, ns_talloc_based_realloc,
- arena, &c->parser);
- if (error != HUBBUB_OK) {
- free(c);
- if (error == HUBBUB_BADENCODING)
- return BINDING_BADENCODING;
- else
- return BINDING_NOMEM; /* Assume OOM */
- }
-
- c->document = htmlNewDocNoDtD(NULL, NULL);
- if (c->document == NULL) {
- hubbub_parser_destroy(c->parser);
- free(c);
- return BINDING_NOMEM;
- }
- c->document->_private = create_private(0);
- if (c->document->_private == NULL) {
- xmlFreeDoc(c->document);
- hubbub_parser_destroy(c->parser);
- free(c);
- return BINDING_NOMEM;
- }
-
- for (i = 0; i < sizeof(c->namespaces) / sizeof(c->namespaces[0]); i++) {
- c->namespaces[i] = NULL;
- }
-
- c->tree_handler = tree_handler;
- c->tree_handler.ctx = (void *) c;
-
- params.tree_handler = &c->tree_handler;
- hubbub_parser_setopt(c->parser, HUBBUB_PARSER_TREE_HANDLER, &params);
-
- ref_node(c, c->document);
- params.document_node = c->document;
- hubbub_parser_setopt(c->parser, HUBBUB_PARSER_DOCUMENT_NODE, &params);
-
- *ctx = (void *) c;
-
- return BINDING_OK;
-}
-
-binding_error binding_destroy_tree(void *ctx)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
-
- if (ctx == NULL)
- return BINDING_OK;
-
- if (c->parser != NULL)
- hubbub_parser_destroy(c->parser);
-
- if (c->owns_doc)
- binding_destroy_document(c->document);
-
- c->parser = NULL;
- c->encoding = NULL;
- c->document = NULL;
-
- free(c);
-
- return BINDING_OK;
-}
-
-binding_error binding_parse_chunk(void *ctx, const uint8_t *data, size_t len)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
- hubbub_error err;
-
- err = hubbub_parser_parse_chunk(c->parser, (uint8_t *) data, len);
- if (err == HUBBUB_ENCODINGCHANGE)
- return BINDING_ENCODINGCHANGE;
-
- return err == HUBBUB_NOMEM ? BINDING_NOMEM : BINDING_OK;
-}
-
-binding_error binding_parse_completed(void *ctx)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
- hubbub_error error;
-
- error = hubbub_parser_completed(c->parser);
-
- return error == HUBBUB_NOMEM ? BINDING_NOMEM : BINDING_OK;
-}
-
-const char *binding_get_encoding(void *ctx, binding_encoding_source *source)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
-
- *source = c->encoding_source;
-
- return c->encoding != NULL ? c->encoding : "Windows-1252";
-}
-
-xmlDocPtr binding_get_document(void *ctx, binding_quirks_mode *quirks)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
- xmlDocPtr doc = c->document;
-
- c->owns_doc = false;
-
- *quirks = c->quirks;
-
- return doc;
-}
-
-struct form *binding_get_forms(void *ctx)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
-
- return c->forms;
-}
-
-struct form_control *binding_get_control_for_node(void *ctx, xmlNodePtr node)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
- struct form *f;
- struct form_control *ctl = NULL;
-
- for (f = c->forms; f != NULL; f = f->prev) {
- for (ctl = f->controls; ctl != NULL; ctl = ctl->next) {
- if (ctl->node == node)
- return ctl;
- }
- }
-
- /* No control found. This implies that it's not associated
- * with any form. In this case, we create a control for it
- * on the fly. */
- if (strcasecmp((const char *) node->name, "input") == 0) {
- ctl = parse_input_element(node);
- } else if (strcasecmp((const char *) node->name, "button") == 0) {
- ctl = parse_button_element(node);
- } else if (strcasecmp((const char *) node->name, "select") == 0) {
- ctl = parse_select_element(node);
- } else if (strcasecmp((const char *) node->name, "textarea") == 0) {
- ctl = parse_textarea_element(node);
- }
-
- return ctl;
-}
-
-void binding_destroy_document(xmlDocPtr doc)
-{
- xmlNode *n = (xmlNode *) doc;
-
- while (n != NULL) {
- destroy_private(n->_private);
-
- if (n->children != NULL) {
- n = n->children;
- } else if (n->next != NULL) {
- n = n->next;
- } else {
- while (n->parent != NULL && n->parent->next == NULL)
- n = n->parent;
-
- if (n->parent != NULL)
- n = n->parent->next;
- else
- n = NULL;
- }
- }
-
- xmlFreeDoc(doc);
-}
-
-/*****************************************************************************/
-
-hubbub_private *create_private(uint32_t refcnt)
-{
- hubbub_private *pvt = calloc(1, sizeof(*pvt));
-
- if (pvt != NULL)
- pvt->refcnt = refcnt;
-
- return pvt;
-}
-
-hubbub_private *copy_private(const hubbub_private *p, uint32_t refcnt)
-{
- hubbub_private *pvt = calloc(1, sizeof(*pvt));
-
- if (pvt != NULL) {
- pvt->refcnt = refcnt;
-
- if (p->base.nclasses > 0) {
- pvt->base.classes =
- malloc(p->base.nclasses * sizeof(lwc_string *));
- if (pvt->base.classes == NULL) {
- free(pvt);
- return NULL;
- }
-
- while (pvt->base.nclasses < p->base.nclasses) {
- pvt->base.classes[pvt->base.nclasses] =
- lwc_string_ref(p->base.classes[
- pvt->base.nclasses]);
- pvt->base.nclasses++;
- }
- }
-
- if (p->base.localname != NULL)
- pvt->base.localname = lwc_string_ref(p->base.localname);
-
- if (p->base.id != NULL)
- pvt->base.id = lwc_string_ref(p->base.id);
- }
-
- return pvt;
-}
-
-void destroy_private(hubbub_private *p)
-{
- if (p->base.localname != NULL)
- lwc_string_unref(p->base.localname);
-
- if (p->base.id != NULL)
- lwc_string_unref(p->base.id);
-
- while (p->base.nclasses > 0)
- lwc_string_unref(p->base.classes[--p->base.nclasses]);
-
- if (p->base.classes != NULL)
- free(p->base.classes);
-
- free(p);
-}
-
-char *c_string_from_hubbub_string(hubbub_ctx *ctx, const hubbub_string *str)
-{
- return strndup((const char *) str->ptr, (int) str->len);
-}
-
-void create_namespaces(hubbub_ctx *ctx, xmlNode *root)
-{
- uint32_t i;
-
- for (i = 1; i < sizeof(namespaces) / sizeof(namespaces[0]); i++) {
- ctx->namespaces[i - 1] = xmlNewNs(root,
- BAD_CAST namespaces[i].url,
- BAD_CAST namespaces[i].prefix);
-
- if (ctx->namespaces[i - 1] == NULL) {
- LOG(("Failed creating namespace %s\n",
- namespaces[i].prefix));
- }
- }
-}
-
-hubbub_error create_comment(void *ctx, const hubbub_string *data, void **result)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
- char *content;
- xmlNodePtr n;
-
- content = c_string_from_hubbub_string(c, data);
- if (content == NULL)
- return HUBBUB_NOMEM;
-
- n = xmlNewDocComment(c->document, BAD_CAST content);
- if (n == NULL) {
- free(content);
- return HUBBUB_NOMEM;
- }
- n->_private = create_private(1);
- if (n->_private == NULL) {
- xmlFreeNode(n);
- free(content);
- return HUBBUB_NOMEM;
- }
-
- free(content);
-
- *result = (void *) n;
-
- return HUBBUB_OK;
-}
-
-hubbub_error create_doctype(void *ctx, const hubbub_doctype *doctype,
- void **result)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
- char *name, *public = NULL, *system = NULL;
- xmlDtdPtr n;
-
- name = c_string_from_hubbub_string(c, &doctype->name);
- if (name == NULL)
- return HUBBUB_NOMEM;
-
- if (!doctype->public_missing) {
- public = c_string_from_hubbub_string(c, &doctype->public_id);
- if (public == NULL) {
- free(name);
- return HUBBUB_NOMEM;
- }
- }
-
- if (!doctype->system_missing) {
- system = c_string_from_hubbub_string(c, &doctype->system_id);
- if (system == NULL) {
- free(public);
- free(name);
- return HUBBUB_NOMEM;
- }
- }
-
- n = xmlNewDtd(c->document, BAD_CAST name,
- BAD_CAST (public ? public : ""),
- BAD_CAST (system ? system : ""));
- if (n == NULL) {
- free(system);
- free(public);
- free(name);
- return HUBBUB_NOMEM;
- }
- n->_private = create_private(1);
- if (n->_private == NULL) {
- xmlFreeDtd(n);
- free(system);
- free(public);
- free(name);
- return HUBBUB_NOMEM;
- }
-
- *result = (void *) n;
-
- free(system);
- free(public);
- free(name);
-
- return HUBBUB_OK;
-}
-
-hubbub_error create_element(void *ctx, const hubbub_tag *tag, void **result)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
- lwc_string *iname;
- xmlNodePtr n;
-
- if (lwc_intern_string((const char *) tag->name.ptr, tag->name.len,
- &iname) != lwc_error_ok) {
- return HUBBUB_NOMEM;
- }
-
- if (c->namespaces[0] != NULL) {
- n = xmlNewDocNode(c->document, c->namespaces[tag->ns - 1],
- BAD_CAST lwc_string_data(iname), NULL);
- } else {
- n = xmlNewDocNode(c->document, NULL,
- BAD_CAST lwc_string_data(iname), NULL);
-
- /* We're creating the root node of the document. Therefore,
- * create the namespaces and set this node's namespace */
- if (n != NULL && c->namespaces[0] == NULL) {
- create_namespaces(c, (void *) n);
-
- xmlSetNs(n, c->namespaces[tag->ns - 1]);
- }
- }
- if (n == NULL) {
- lwc_string_unref(iname);
- return HUBBUB_NOMEM;
- }
- n->_private = create_private(1);
- if (n->_private == NULL) {
- xmlFreeNode(n);
- lwc_string_unref(iname);
- return HUBBUB_NOMEM;
- }
-
- if (tag->n_attributes > 0 && add_attributes(ctx, (void *) n,
- tag->attributes, tag->n_attributes) != HUBBUB_OK) {
- destroy_private(n->_private);
- xmlFreeNode(n);
- lwc_string_unref(iname);
- return HUBBUB_NOMEM;
- }
-
- if (lwc_string_length(iname) == SLEN("form") &&
- strcasecmp(lwc_string_data(iname), "form") == 0) {
- struct form *form = parse_form_element(n, c->encoding);
-
- /* Memory exhaustion */
- if (form == NULL) {
- destroy_private(n->_private);
- xmlFreeNode(n);
- lwc_string_unref(iname);
- return HUBBUB_NOMEM;
- }
-
- /* Insert into list */
- form->prev = c->forms;
- c->forms = form;
- }
-
- ((binding_private *) n->_private)->localname = iname;
-
- *result = (void *) n;
-
- return HUBBUB_OK;
-}
-
-hubbub_error create_text(void *ctx, const hubbub_string *data, void **result)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
- xmlNodePtr n;
-
- n = xmlNewDocTextLen(c->document, BAD_CAST data->ptr, (int) data->len);
- if (n == NULL) {
- return HUBBUB_NOMEM;
- }
- n->_private = create_private(1);
- if (n->_private == NULL) {
- xmlFreeNode(n);
- return HUBBUB_NOMEM;
- }
-
- *result = (void *) n;
-
- return HUBBUB_OK;
-}
-
-hubbub_error ref_node(void *ctx, void *node)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
- hubbub_private *pvt;
-
- if (node == c->document) {
- xmlDoc *n = (xmlDoc *) node;
- pvt = n->_private;
-
- pvt->refcnt++;
- } else {
- xmlNode *n = (xmlNode *) node;
- pvt = n->_private;
-
- pvt->refcnt++;
- }
-
- return HUBBUB_OK;
-}
-
-hubbub_error unref_node(void *ctx, void *node)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
- hubbub_private *pvt;
-
- if (node == c->document) {
- xmlDoc *n = (xmlDoc *) node;
- pvt = n->_private;
-
- assert(pvt->refcnt != 0 && "Node has refcount of zero");
-
- pvt->refcnt--;
- } else {
- xmlNode *n = (xmlNode *) node;
- pvt = n->_private;
-
- assert(pvt->refcnt != 0 && "Node has refcount of zero");
-
- pvt->refcnt--;
-
- if (pvt->refcnt == 0 && n->parent == NULL) {
- destroy_private(pvt);
- xmlFreeNode(n);
- }
- }
-
- return HUBBUB_OK;
-}
-
-hubbub_error append_child(void *ctx, void *parent, void *child, void **result)
-{
- xmlNode *chld = (xmlNode *) child;
- xmlNode *p = (xmlNode *) parent;
-
- /** \todo Text node merging logic as per
- * http://www.whatwg.org/specs/web-apps/current-work/multipage/ \
- * tree-construction.html#insert-a-character
- *
- * Doesn't actually matter for us until we have scripting. Thus,
- * this is something which can wait until libdom.
- */
- if (chld->type == XML_TEXT_NODE && p->last != NULL &&
- p->last->type == XML_TEXT_NODE) {
- /* Need to clone the child, as libxml will free it if it
- * merges the content with a pre-existing text node. */
- chld = xmlCopyNode(chld, 0);
- if (chld == NULL)
- return HUBBUB_NOMEM;
-
- *result = xmlAddChild(p, chld);
-
- assert(*result != (void *) chld);
- } else {
- *result = xmlAddChild(p, chld);
- }
-
- if (*result == NULL)
- return HUBBUB_NOMEM;
-
- ref_node(ctx, *result);
-
- return HUBBUB_OK;
-}
-
-hubbub_error insert_before(void *ctx, void *parent, void *child,
- void *ref_child, void **result)
-{
- xmlNode *chld = (xmlNode *) child;
- xmlNode *ref = (xmlNode *) ref_child;
-
- if (chld->type == XML_TEXT_NODE && ref->prev != NULL &&
- ref->prev->type == XML_TEXT_NODE) {
- /* Clone text node, as it'll be freed by libxml */
- chld = xmlCopyNode(chld, 0);
- if (chld == NULL)
- return HUBBUB_NOMEM;
-
- *result = xmlAddNextSibling(ref->prev, chld);
-
- assert(*result != (void *) chld);
- } else {
- *result = xmlAddPrevSibling(ref, chld);
- }
-
- if (*result == NULL)
- return HUBBUB_NOMEM;
-
- ref_node(ctx, *result);
-
- return HUBBUB_OK;
-}
-
-hubbub_error remove_child(void *ctx, void *parent, void *child, void **result)
-{
- xmlNode *chld = (xmlNode *) child;
-
- xmlUnlinkNode(chld);
-
- *result = child;
-
- ref_node(ctx, *result);
-
- return HUBBUB_OK;
-}
-
-hubbub_error clone_node(void *ctx, void *node, bool deep, void **result)
-{
- xmlNode *n = (xmlNode *) node;
- xmlNode *clonedtree;
-
- /* Shallow clone node */
- clonedtree = xmlCopyNode(n, 2);
- if (clonedtree == NULL)
- return HUBBUB_NOMEM;
-
- clonedtree->_private = copy_private(n->_private, 1);
- if (clonedtree->_private == NULL) {
- xmlFreeNode(clonedtree);
- return HUBBUB_NOMEM;
- }
-
- /* Iteratively clone children too, if required */
- if (deep && n->children != NULL) {
- xmlNode *parent = clonedtree, *copy;
-
- n = n->children;
-
- while (n != node) {
- copy = xmlCopyNode(n, 2);
- if (copy == NULL)
- goto error;
-
- copy->_private = copy_private(n->_private, 0);
- if (copy->_private == NULL) {
- xmlFreeNode(copy);
- goto error;
- }
-
- xmlAddChild(parent, copy);
-
- if (n->children != NULL) {
- parent = copy;
- n = n->children;
- } else if (n->next != NULL) {
- n = n->next;
- } else {
- while (n->parent != node &&
- n->parent->next == NULL) {
- parent = parent->parent;
- n = n->parent;
- }
-
- if (n->parent != node) {
- parent = parent->parent;
- n = n->parent->next;
- } else
- n = node;
- }
- }
- }
-
- *result = clonedtree;
-
- return HUBBUB_OK;
-
-error:
- n = clonedtree;
-
- while (n != NULL) {
- destroy_private(n->_private);
-
- if (n->children != NULL) {
- n = n->children;
- } else if (n->next != NULL) {
- n = n->next;
- } else {
- while (n->parent != NULL && n->parent->next == NULL) {
- n = n->parent;
- }
-
- if (n->parent != NULL)
- n = n->parent->next;
- else
- n = NULL;
- }
- }
-
- xmlFreeNode(clonedtree);
-
- return HUBBUB_NOMEM;
-}
-
-hubbub_error reparent_children(void *ctx, void *node, void *new_parent)
-{
- xmlNode *n = (xmlNode *) node;
- xmlNode *p = (xmlNode *) new_parent;
- xmlNode *child;
-
- for (child = n->children; child != NULL; ) {
- xmlNode *next = child->next;
-
- xmlUnlinkNode(child);
-
- if (xmlAddChild(p, child) == NULL)
- return HUBBUB_NOMEM;
-
- child = next;
- }
-
- return HUBBUB_OK;
-}
-
-hubbub_error get_parent(void *ctx, void *node, bool element_only, void **result)
-{
- xmlNode *n = (xmlNode *) node;
-
- *result = (void *) n->parent;
-
- if (*result != NULL && element_only &&
- ((xmlNode *) *result)->type != XML_ELEMENT_NODE) {
- *result = NULL;
- }
-
- if (*result != NULL)
- ref_node(ctx, *result);
-
- return HUBBUB_OK;
-}
-
-hubbub_error has_children(void *ctx, void *node, bool *result)
-{
- xmlNode *n = (xmlNode *) node;
-
- *result = n->children != NULL;
-
- return HUBBUB_OK;
-}
-
-hubbub_error form_associate(void *ctx, void *form, void *node)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
- xmlNode *n = (xmlNode *) node;
- struct form *f;
- struct form_control *control = NULL;
- xmlChar *id = NULL;
-
- /* Find form object to associate with:
- *
- * 1) If node possesses an @form, use the form with a matching @id
- * 2) Otherwise, use the form provided
- */
- id = xmlGetProp(n, (const xmlChar *) "form");
- for (f = c->forms; f != NULL; f = f->prev) {
- if (id == NULL && f->node == form) {
- break;
- } else if (id != NULL) {
- xmlNode *fn = (xmlNode *) f->node;
- xmlChar *fid = xmlGetProp(fn, (const xmlChar *) "id");
-
- if (fid != NULL && strcmp((char *) id,
- (char *) fid) == 0) {
- xmlFree(fid);
- break;
- } else if (fid != NULL) {
- xmlFree(fid);
- }
- }
- }
- if (id != NULL)
- xmlFree(id);
-
- /* None found -- give up */
- if (f == NULL)
- return HUBBUB_OK;
-
- /* Will be one of: button, fieldset, input, label,
- * output, select, textarea.
- *
- * We ignore fieldset, label and output.
- */
- if (strcasecmp((const char *) n->name, "input") == 0) {
- control = parse_input_element(n);
- } else if (strcasecmp((const char *) n->name, "button") == 0) {
- control = parse_button_element(n);
- } else if (strcasecmp((const char *) n->name, "select") == 0) {
- control = parse_select_element(n);
- } else if (strcasecmp((const char *) n->name, "textarea") == 0) {
- control = parse_textarea_element(n);
- } else
- return HUBBUB_OK;
-
- /* Memory exhaustion */
- if (control == NULL)
- return HUBBUB_NOMEM;
-
- /* Add the control to the form */
- form_add_control(f, control);
-
- return HUBBUB_OK;
-}
-
-static hubbub_error parse_class_attr(lwc_string *value,
- lwc_string ***classes, uint32_t *nclasses)
-{
- const char *pv;
- lwc_string **cls = NULL;
- uint32_t count = 0;
-
- /* Count number of classes */
- for (pv = lwc_string_data(value); *pv != '\0'; ) {
- if (*pv != ' ') {
- while (*pv != ' ' && *pv != '\0')
- pv++;
- count++;
- } else {
- while (*pv == ' ')
- pv++;
- }
- }
-
- /* If there are some, unpack them */
- if (count > 0) {
- cls = malloc(count * sizeof(lwc_string *));
- if (cls == NULL)
- return HUBBUB_NOMEM;
-
- for (pv = lwc_string_data(value), count = 0; *pv != '\0'; ) {
- if (*pv != ' ') {
- const char *s = pv;
- while (*pv != ' ' && *pv != '\0')
- pv++;
- if (lwc_intern_string(s, pv - s,
- &cls[count]) != lwc_error_ok)
- goto error;
- count++;
- } else {
- while (*pv == ' ')
- pv++;
- }
- }
- }
-
- *classes = cls;
- *nclasses = count;
-
- return HUBBUB_OK;
-error:
- while (count > 0)
- lwc_string_unref(cls[--count]);
-
- free(cls);
-
- return HUBBUB_NOMEM;
-}
-
-hubbub_error add_attributes(void *ctx, void *node,
- const hubbub_attribute *attributes, uint32_t n_attributes)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
- xmlNode *n = (xmlNode *) node;
- binding_private *p = n->_private;
- uint32_t attr;
-
- for (attr = 0; attr < n_attributes; attr++) {
- xmlAttr *prop;
- lwc_string *name, *value;
-
- if (lwc_intern_string((const char *) attributes[attr].name.ptr,
- attributes[attr].name.len,
- &name) != lwc_error_ok)
- return HUBBUB_NOMEM;
-
- if (lwc_intern_string((const char *) attributes[attr].value.ptr,
- attributes[attr].value.len,
- &value) != lwc_error_ok) {
- lwc_string_unref(name);
- return HUBBUB_NOMEM;
- }
-
- if (attributes[attr].ns != HUBBUB_NS_NULL &&
- c->namespaces[0] != NULL) {
- prop = xmlNewNsProp(n,
- c->namespaces[attributes[attr].ns - 1],
- BAD_CAST lwc_string_data(name),
- BAD_CAST lwc_string_data(value));
- } else {
- prop = xmlNewProp(n, BAD_CAST lwc_string_data(name),
- BAD_CAST lwc_string_data(value));
- }
-
- /* Handle @id / @class */
- if (p->id == NULL && lwc_string_length(name) == SLEN("id") &&
- strcasecmp(lwc_string_data(name), "id") == 0) {
- p->id = lwc_string_ref(value);
- } else if (p->nclasses == 0 &&
- lwc_string_length(name) == SLEN("class") &&
- strcasecmp(lwc_string_data(name),
- "class") == 0) {
- hubbub_error error;
-
- error = parse_class_attr(value, &p->classes,
- &p->nclasses);
- if (error != HUBBUB_OK) {
- lwc_string_unref(value);
- lwc_string_unref(name);
- return error;
- }
- }
-
- lwc_string_unref(value);
- lwc_string_unref(name);
-
- if (prop == NULL) {
- return HUBBUB_NOMEM;
- }
- }
-
- return HUBBUB_OK;
-}
-
-hubbub_error set_quirks_mode(void *ctx, hubbub_quirks_mode mode)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
-
- switch (mode) {
- case HUBBUB_QUIRKS_MODE_NONE:
- c->quirks = BINDING_QUIRKS_MODE_NONE;
- break;
- case HUBBUB_QUIRKS_MODE_LIMITED:
- c->quirks = BINDING_QUIRKS_MODE_LIMITED;
- break;
- case HUBBUB_QUIRKS_MODE_FULL:
- c->quirks = BINDING_QUIRKS_MODE_FULL;
- break;
- }
-
- return HUBBUB_OK;
-}
-
-hubbub_error change_encoding(void *ctx, const char *charset)
-{
- hubbub_ctx *c = (hubbub_ctx *) ctx;
- uint32_t source;
- const char *name;
-
- /* If we have an encoding here, it means we are *certain* */
- if (c->encoding != NULL) {
- return HUBBUB_OK;
- }
-
- /* Find the confidence otherwise (can only be from a BOM) */
- name = hubbub_parser_read_charset(c->parser, &source);
-
- if (source == HUBBUB_CHARSET_CONFIDENT) {
- c->encoding_source = ENCODING_SOURCE_DETECTED;
- c->encoding = (char *) charset;
- return HUBBUB_OK;
- }
-
- /* So here we have something of confidence tentative... */
- /* http://www.whatwg.org/specs/web-apps/current-work/#change */
-
- /* 2. "If the new encoding is identical or equivalent to the encoding
- * that is already being used to interpret the input stream, then set
- * the confidence to confident and abort these steps." */
-
- /* Whatever happens, the encoding should be set here; either for
- * reprocessing with a different charset, or for confirming that the
- * charset is in fact correct */
- c->encoding = charset;
- c->encoding_source = ENCODING_SOURCE_META;
-
- /* Equal encodings will have the same string pointers */
- return (charset == name) ? HUBBUB_OK : HUBBUB_ENCODINGCHANGE;
-}
-
-struct form *parse_form_element(xmlNode *node, const char *docenc)
-{
- struct form *form;
- form_method method;
- xmlChar *action, *meth, *charset, *target;
-
- action = xmlGetProp(node, (const xmlChar *) "action");
- charset = xmlGetProp(node, (const xmlChar *) "accept-charset");
- target = xmlGetProp(node, (const xmlChar *) "target");
-
- method = method_GET;
- meth = xmlGetProp(node, (const xmlChar *) "method");
- if (meth != NULL) {
- if (strcasecmp((char *) meth, "post") == 0) {
- xmlChar *enctype;
-
- method = method_POST_URLENC;
-
- enctype = xmlGetProp(node, (const xmlChar *) "enctype");
- if (enctype != NULL) {
- if (strcasecmp((char *) enctype,
- "multipart/form-data") == 0)
- method = method_POST_MULTIPART;
-
- xmlFree(enctype);
- }
- }
- xmlFree(meth);
- }
-
- form = form_new(node, (char *) action, (char *) target, method,
- (char *) charset, docenc);
-
- if (target != NULL)
- xmlFree(target);
- if (charset != NULL)
- xmlFree(charset);
- if (action != NULL)
- xmlFree(action);
-
- return form;
-}
-
-struct form_control *parse_input_element(xmlNode *node)
-{
- struct form_control *control = NULL;
- xmlChar *type = xmlGetProp(node, (const xmlChar *) "type");
- xmlChar *name;
-
- if (type != NULL && strcasecmp((char *) type, "password") == 0) {
- control = form_new_control(node, GADGET_PASSWORD);
- } else if (type != NULL && strcasecmp((char *) type, "file") == 0) {
- control = form_new_control(node, GADGET_FILE);
- } else if (type != NULL && strcasecmp((char *) type, "hidden") == 0) {
- control = form_new_control(node, GADGET_HIDDEN);
- } else if (type != NULL && strcasecmp((char *) type, "checkbox") == 0) {
- control = form_new_control(node, GADGET_CHECKBOX);
- } else if (type != NULL && strcasecmp((char *) type, "radio") == 0) {
- control = form_new_control(node, GADGET_RADIO);
- } else if (type != NULL && strcasecmp((char *) type, "submit") == 0) {
- control = form_new_control(node, GADGET_SUBMIT);
- } else if (type != NULL && strcasecmp((char *) type, "reset") == 0) {
- control = form_new_control(node, GADGET_RESET);
- } else if (type != NULL && strcasecmp((char *) type, "button") == 0) {
- control = form_new_control(node, GADGET_BUTTON);
- } else if (type != NULL && strcasecmp((char *) type, "image") == 0) {
- control = form_new_control(node, GADGET_IMAGE);
- } else {
- control = form_new_control(node, GADGET_TEXTBOX);
- }
-
- xmlFree(type);
-
- if (control == NULL)
- return NULL;
-
- if (control->type == GADGET_CHECKBOX || control->type == GADGET_RADIO) {
- control->selected =
- xmlHasProp(node, (const xmlChar *) "checked") != NULL;
- }
-
- if (control->type == GADGET_PASSWORD ||
- control->type == GADGET_TEXTBOX) {
- xmlChar *len = xmlGetProp(node, (const xmlChar *) "maxlength");
- if (len != NULL) {
- if (len[0] != '\0')
- control->maxlength = atoi((char *) len);
- xmlFree(len);
- }
- }
-
- if (control->type != GADGET_FILE && control->type != GADGET_IMAGE) {
- xmlChar *value = xmlGetProp(node, (const xmlChar *) "value");
- if (value != NULL) {
- control->value = strdup((char *) value);
-
- xmlFree(value);
-
- if (control->value == NULL) {
- form_free_control(control);
- return NULL;
- }
-
- control->length = strlen(control->value);
- }
-
- if (control->type == GADGET_TEXTBOX ||
- control->type == GADGET_PASSWORD) {
- if (control->value == NULL) {
- control->value = strdup("");
- if (control->value == NULL) {
- form_free_control(control);
- return NULL;
- }
-
- control->length = 0;
- }
-
- control->initial_value = strdup(control->value);
- if (control->initial_value == NULL) {
- form_free_control(control);
- return NULL;
- }
- }
- }
-
- name = xmlGetProp(node, (const xmlChar *) "name");
- if (name != NULL) {
- control->name = strdup((char *) name);
-
- xmlFree(name);
-
- if (control->name == NULL) {
- form_free_control(control);
- return NULL;
- }
- }
-
- return control;
-}
-
-struct form_control *parse_button_element(xmlNode *node)
-{
- struct form_control *control;
- xmlChar *type = xmlGetProp(node, (const xmlChar *) "type");
- xmlChar *name;
- xmlChar *value;
-
- if (type == NULL || strcasecmp((char *) type, "submit") == 0) {
- control = form_new_control(node, GADGET_SUBMIT);
- } else if (strcasecmp((char *) type, "reset") == 0) {
- control = form_new_control(node, GADGET_RESET);
- } else {
- control = form_new_control(node, GADGET_BUTTON);
- }
-
- xmlFree(type);
-
- if (control == NULL)
- return NULL;
-
- value = xmlGetProp(node, (const xmlChar *) "value");
- if (value != NULL) {
- control->value = strdup((char *) value);
-
- xmlFree(value);
-
- if (control->value == NULL) {
- form_free_control(control);
- return NULL;
- }
- }
-
- name = xmlGetProp(node, (const xmlChar *) "name");
- if (name != NULL) {
- control->name = strdup((char *) name);
-
- xmlFree(name);
-
- if (control->name == NULL) {
- form_free_control(control);
- return NULL;
- }
- }
-
- return control;
-}
-
-struct form_control *parse_select_element(xmlNode *node)
-{
- struct form_control *control = form_new_control(node, GADGET_SELECT);
- xmlChar *name;
-
- if (control == NULL)
- return NULL;
-
- control->data.select.multiple =
- xmlHasProp(node, (const xmlChar *) "multiple") != NULL;
-
- name = xmlGetProp(node, (const xmlChar *) "name");
- if (name != NULL) {
- control->name = strdup((char *) name);
-
- xmlFree(name);
-
- if (control->name == NULL) {
- form_free_control(control);
- return NULL;
- }
- }
-
- return control;
-}
-
-struct form_control *parse_textarea_element(xmlNode *node)
-{
- struct form_control *control = form_new_control(node, GADGET_TEXTAREA);
- xmlChar *name;
-
- if (control == NULL)
- return NULL;
-
- name = xmlGetProp(node, (const xmlChar *) "name");
- if (name != NULL) {
- control->name = strdup((char *) name);
-
- xmlFree(name);
-
- if (control->name == NULL) {
- form_free_control(control);
- return NULL;
- }
- }
-
- return control;
-}
-
diff --git a/render/libdom_binding.c b/render/libdom_binding.c
deleted file mode 100644
index 9ae76469c..000000000
--- a/render/libdom_binding.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2011 Vincent Sanders <vince@netsurf-browser.org>
- *
- * 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/>.
- */
-
-#include <dom/dom.h>
-#include <dom/bindings/hubbub/parser.h>
-
-#include "render/form.h"
-#include "render/parser_binding.h"
-
-#include "utils/log.h"
-
-binding_error binding_create_tree(void **ctx, const char *charset, bool enable_script, dom_script script, void *context)
-{
- dom_hubbub_parser *parser = NULL;
-
- parser = dom_hubbub_parser_create(charset, true, enable_script, NULL, script, context);
- if (parser == NULL) {
- LOG(("Can't create Hubbub Parser\n"));
- return BINDING_NOMEM;
- }
- *ctx = parser;
- return BINDING_OK;
-}
-
-binding_error binding_destroy_tree(void *ctx)
-{
- dom_hubbub_parser_destroy(ctx);
- return BINDING_OK;
-}
-
-binding_error binding_parse_chunk(void *ctx, const uint8_t *data, size_t len)
-{
- dom_hubbub_error error;
- error = dom_hubbub_parser_parse_chunk(ctx, data, len);
- if (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE)) {
- return BINDING_ENCODINGCHANGE;
- } else if (error != DOM_HUBBUB_OK) {
- return BINDING_NOMEM;
- }
- return BINDING_OK;
-}
-
-binding_error binding_parse_completed(void *ctx)
-{
- dom_hubbub_error error;
- error = dom_hubbub_parser_completed(ctx);
- if (error != DOM_HUBBUB_OK) {
- return BINDING_NOMEM;
- }
- return BINDING_OK;
-}
-
-const char *binding_get_encoding(void *ctx, binding_encoding_source *source)
-{
- dom_hubbub_encoding_source hubbub_src;
- const char *encoding;
-
- encoding = dom_hubbub_parser_get_encoding(ctx, &hubbub_src);
-
- switch (hubbub_src) {
- case DOM_HUBBUB_ENCODING_SOURCE_HEADER:
- *source = ENCODING_SOURCE_HEADER;
- break;
-
- case DOM_HUBBUB_ENCODING_SOURCE_DETECTED:
- *source = ENCODING_SOURCE_DETECTED;
- break;
-
- case DOM_HUBBUB_ENCODING_SOURCE_META:
- *source = ENCODING_SOURCE_META;
- break;
- }
-
- return encoding;
-}
-
-dom_document *binding_get_document(void *ctx, binding_quirks_mode *quirks)
-{
- return dom_hubbub_parser_get_document(ctx);
-}
-
-struct form *binding_get_forms(void *ctx)
-{
- return NULL;
-}
-
-struct form_control *binding_get_control_for_node(void *ctx, dom_node *node)
-{
- /** \todo implement properly */
- struct form_control *ctl = form_new_control(node, GADGET_HIDDEN);
- if (ctl != NULL) {
- ctl->value = strdup("");
- ctl->initial_value = strdup("");
- ctl->name = strdup("foo");
-
- if (ctl->value == NULL || ctl->initial_value == NULL ||
- ctl->name == NULL) {
- form_free_control(ctl);
- ctl = NULL;
- }
- }
-
- return ctl;
-}
-
-void binding_destroy_document(dom_document *doc)
-{
- dom_node_unref(doc);
-}
-
-
diff --git a/render/parser_binding.h b/render/parser_binding.h
deleted file mode 100644
index cf3497867..000000000
--- a/render/parser_binding.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
- *
- * 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/>.
- */
-
-#ifndef _NETSURF_RENDER_PARSER_BINDING_H_
-#define _NETSURF_RENDER_PARSER_BINDING_H_
-
-#include <dom/dom.h>
-#include <dom/bindings/hubbub/parser.h>
-
-struct box;
-struct form;
-struct form_control;
-
-typedef enum binding_error {
- BINDING_OK,
- BINDING_NOMEM,
- BINDING_BADENCODING,
- BINDING_ENCODINGCHANGE
-} binding_error;
-
-typedef enum binding_encoding_source {
- ENCODING_SOURCE_HEADER,
- ENCODING_SOURCE_DETECTED,
- ENCODING_SOURCE_META
-} binding_encoding_source;
-
-typedef enum binding_quirks_mode {
- BINDING_QUIRKS_MODE_NONE,
- BINDING_QUIRKS_MODE_LIMITED,
- BINDING_QUIRKS_MODE_FULL
-} binding_quirks_mode;
-
-binding_error binding_create_tree(void **ctx, const char *charset, bool enable_script, dom_script script, void *context);
-binding_error binding_destroy_tree(void *ctx);
-
-binding_error binding_parse_chunk(void *ctx, const uint8_t *data, size_t len);
-binding_error binding_parse_completed(void *ctx);
-
-const char *binding_get_encoding(void *ctx, binding_encoding_source *source);
-dom_document *binding_get_document(void *ctx, binding_quirks_mode *quirks);
-
-struct form *binding_get_forms(void *ctx);
-struct form_control *binding_get_control_for_node(void *ctx, dom_node *node);
-
-void binding_destroy_document(dom_document *doc);
-
-#endif
-