From ff7cf937629933e782eb8103dadb8b5f27f14a4d Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Wed, 28 Nov 2012 21:30:24 +0100 Subject: Started refactoring of global redraw handling. --- atari/browser.c | 1 - atari/gui.c | 32 +++++++----- atari/gui.h | 2 + atari/redrawslots.c | 30 +++++++++-- atari/redrawslots.h | 11 +++- atari/rootwin.c | 145 ++++++++++++++++++++++++++++++++-------------------- atari/rootwin.h | 2 + atari/schedule.c | 6 +-- atari/statusbar.c | 8 +-- atari/statusbar.h | 2 +- atari/toolbar.c | 29 ++++++----- atari/toolbar.h | 1 + 12 files changed, 173 insertions(+), 96 deletions(-) (limited to 'atari') diff --git a/atari/browser.c b/atari/browser.c index 190472285..d0337f569 100755 --- a/atari/browser.c +++ b/atari/browser.c @@ -858,7 +858,6 @@ void browser_redraw( struct gui_window * gw ) /* but because this is onscreen plotter, it doesn't */ /* make much sense anyway... */ } - } if (wind_get(aes_handle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])==0) { diff --git a/atari/gui.c b/atari/gui.c index 0d85eefea..2528eff1f 100755 --- a/atari/gui.c +++ b/atari/gui.c @@ -131,18 +131,22 @@ void gui_poll(bool active) struct gui_window * g; - for( g = window_list; g != NULL; g=g->next ) { - if( browser_redraw_required( g ) ) { - browser_redraw(g); - } - if(g->root->toolbar) { - //if(g->root->toolbar->url.redraw ) { - // TODO: implement toolbar redraw mechanism - //tb_url_redraw( g ); - //} - } + if(input_window->root->redraw_slots.areas_used > 0){ + window_process_redraws(input_window->root); } +// for( g = window_list; g != NULL; g=g->next ) { +// if( browser_redraw_required( g ) ) { +// browser_redraw(g); +// } +// if(g->root->toolbar) { +// //if(g->root->toolbar->url.redraw ) { +// // TODO: implement toolbar redraw mechanism +// //tb_url_redraw( g ); +// //} +// } +// } + if( !active ) { /* this suits for stuff with lower priority */ /* TBD: really be spare on redraws??? */ @@ -179,6 +183,9 @@ void gui_poll(bool active) } } while ( gui_poll_repeat && !(active||rendering)); + if(input_window->root->redraw_slots.areas_used > 0){ + window_process_redraws(input_window->root); + } } @@ -313,6 +320,7 @@ void gui_window_set_title(struct gui_window *gw, const char *title) gw->title = realloc(gw->title, l); strncpy(gw->title, title, l); } + gw->title[l] = 0; if(input_window == gw) window_set_title(gw->root, gw->title); } @@ -336,7 +344,7 @@ void gui_window_set_status(struct gui_window *w, const char *text) w->status = realloc(w->status, l); strncpy(w->status, text, l); - w->status[l-1] = 0; + w->status[l] = 0; if(input_window == w) window_set_stauts(w->root, (char*)text); @@ -534,7 +542,7 @@ void gui_window_set_url(struct gui_window *w, const char *url) w->url = realloc(w->url, l); } strncpy(w->url, url, l); - + w->url[l] = 0; if(input_window == w->root->active_gui_window){ toolbar_set_url(w->root->toolbar, url); } diff --git a/atari/gui.h b/atari/gui.h index c2f6b44f6..88601917e 100755 --- a/atari/gui.h +++ b/atari/gui.h @@ -19,6 +19,7 @@ #ifndef NS_ATARI_GUI_H_ #define NS_ATARI_GUI_H_ +#include "atari/redrawslots.h" #include "atari/gemtk/gemtk.h" struct point_s { @@ -104,6 +105,7 @@ struct s_gui_win_root char * title; struct bitmap * icon; struct gui_window *active_gui_window; + struct s_redrw_slots redraw_slots; /* current size of window on screen: */ GRECT loc; }; diff --git a/atari/redrawslots.c b/atari/redrawslots.c index 069e6cc91..d2f74e4fb 100644 --- a/atari/redrawslots.c +++ b/atari/redrawslots.c @@ -23,10 +23,16 @@ void redraw_slots_init(struct s_redrw_slots * slots, short size) { + // TODO: allocate slots dynamically! slots->size = MIN( MAX_REDRW_SLOTS , size); slots->areas_used = 0; } +void redraw_slots_free(struct s_redrw_slots * slots) +{ + // TOOD: free areas... +} + static inline bool rect_intersect( struct rect * box1, struct rect * box2 ) { @@ -44,10 +50,19 @@ static inline bool rect_intersect( struct rect * box1, struct rect * box2 ) return true; } + + +void redraw_slot_schedule_grect(struct s_redrw_slots * slots, GRECT *area) +{ + redraw_slot_schedule(slots, area->g_x, area->g_y, + area->g_x + area->g_w, area->g_y + area->g_h); +} + /* - schedule redraw coords, coords are relative. + schedule redraw coords. */ -void redraw_slot_schedule(struct s_redrw_slots * slots, short x0, short y0, short x1, short y1) +void redraw_slot_schedule(struct s_redrw_slots * slots, short x0, short y0, + short x1, short y1) { int i; struct rect area; @@ -91,6 +106,15 @@ void redraw_slot_schedule(struct s_redrw_slots * slots, short x0, short y0, shor slots->areas[slots->size-1].x1 = MAX(slots->areas[i].x1, x1); slots->areas[slots->size-1].y1 = MAX(slots->areas[i].y1, y1); } -done: +done: return; } + +void redraw_slots_remove_area(struct s_redrw_slots * slots, int i) +{ + int x; + for(x = i+1; iareas_used; x++){ + slots->areas[x-1] = slots->areas[x]; + } + slots->areas_used--; +} diff --git a/atari/redrawslots.h b/atari/redrawslots.h index d1f0fc285..8558b7ee6 100644 --- a/atari/redrawslots.h +++ b/atari/redrawslots.h @@ -20,6 +20,10 @@ #ifndef ATARI_REDRAW_SLOTS_H #define ATARI_REDRAW_SLOTS_H +#include +#include "utils/types.h" + + /* MAX_REDRW_SLOTS This is the number of redraw requests that the slotlist can store. @@ -40,7 +44,10 @@ struct s_redrw_slots }; void redraw_slots_init(struct s_redrw_slots * slots, short size); -void redraw_slot_schedule(struct s_redrw_slots * slots, short x0, short y0, short x1, short y1); - +void redraw_slot_schedule(struct s_redrw_slots * slots, short x0, short y0, + short x1, short y1); +void redraw_slot_schedule_grect(struct s_redrw_slots * slots, GRECT *area); +void redraw_slots_remove_area(struct s_redrw_slots * slots, int i); +void redraw_slots_free(struct s_redrw_slots * slots); #endif diff --git a/atari/rootwin.c b/atari/rootwin.c index 68f1bc00c..c0ad68863 100755 --- a/atari/rootwin.c +++ b/atari/rootwin.c @@ -56,6 +56,7 @@ #include "atari/search.h" #include "atari/osspec.h" #include "atari/encoding.h" +#include "atari/redrawslots.h" #include "atari/toolbar.h" #include "atari/gemtk/gemtk.h" @@ -167,6 +168,7 @@ int window_create(struct gui_window * gw, int err = 0; bool tb, sb; int flags; + short aes_handle; tb = (inflags & WIDGET_TOOLBAR); sb = (inflags & WIDGET_STATUSBAR); @@ -188,10 +190,11 @@ int window_create(struct gui_window * gw, memset( gw->root, 0, sizeof(struct s_gui_win_root) ); gw->root->title = malloc(atari_sysinfo.aes_max_win_title_len+1); // TODO: use desk size - short aes_handle = wind_create(flags, 40, 40, app.w, app.h); + + aes_handle = wind_create(flags, 40, 40, app.w, app.h); if(aes_handle<0) { - free( gw->root->title ); - free( gw->root ); + free(gw->root->title); + free(gw->root); return( -1 ); } gw->root->win = guiwin_add(aes_handle, @@ -209,17 +212,20 @@ int window_create(struct gui_window * gw, gw->browser = browser_create( gw, bw, NULL, CLT_HORIZONTAL, 1, 1 ); /* create statusbar component: */ - if( sb ) { + if(sb) { gw->root->statusbar = sb_create( gw ); } else { gw->root->statusbar = NULL; } + // Setup some window defaults: wind_set_str(aes_handle, WF_ICONTITLE, (char*)"NetSurf"); wind_set(aes_handle, WF_OPTS, 1, WO0_FULLREDRAW, 0, 0); wind_set(aes_handle, WF_OPTS, 1, WO0_NOBLITW, 0, 0); wind_set(aes_handle, WF_OPTS, 1, WO0_NOBLITH, 0, 0); + redraw_slots_init(&gw->root->redraw_slots, 8); + guiwin_set_toolbar(gw->root->win, get_tree(TOOLBAR), 0, 0); struct rootwin_data_s * data = malloc(sizeof(struct rootwin_data_s)); data->rootwin = gw->root; @@ -250,6 +256,7 @@ void window_unref_gui_window(ROOTWIN *rootwin, struct gui_window *gw) } if(input_window == NULL){ // the last gui window for this rootwin was removed: + redraw_slots_free(&rootwin->redraw_slots); window_destroy(rootwin); } } @@ -294,7 +301,7 @@ int window_destroy(ROOTWIN *rootwin) void window_open(ROOTWIN *rootwin, GRECT pos) { - GRECT br; + GRECT br, g; short aes_handle = guiwin_get_handle(rootwin->win); wind_open(aes_handle, pos.g_x, pos.g_y, pos.g_w, pos.g_h ); @@ -304,6 +311,8 @@ void window_open(ROOTWIN *rootwin, GRECT pos) if(rootwin->statusbar != NULL) { sb_attach(rootwin->statusbar, rootwin->active_gui_window); } + guiwin_get_grect(rootwin->win, GUIWIN_AREA_TOOLBAR, &g); + toolbar_set_dimensions(rootwin->toolbar, &g); /*TBD: get already present content and set size? */ input_window = rootwin->active_gui_window; window_set_focus(rootwin, BROWSER, rootwin->active_gui_window->browser); @@ -465,6 +474,67 @@ void window_redraw_favicon(ROOTWIN *rootwin, GRECT *clip) } } +void window_schedule_redraw_grect(ROOTWIN *rootwin, GRECT *area) +{ + GRECT work; + + guiwin_get_grect(rootwin->win, GUIWIN_AREA_WORK, &work); + rc_intersect(area, &work); + redraw_slot_schedule_grect(&rootwin->redraw_slots, &work); +} + +/* +bool window_requires_redraw(ROOTWIN * rootwin) +{ + if (rootwin->redraw_slots.areas_used > 0) + return(true); + + return(false); +} +*/ + +void window_process_redraws(ROOTWIN * rootwin) +{ + GRECT work, visible_ro, tb_area = {0,0,0,0}; + short aes_handle, i; + bool toolbar_rdrw_required; + + aes_handle = guiwin_get_handle(rootwin->win); + + guiwin_get_grect(rootwin->win, GUIWIN_AREA_TOOLBAR, &tb_area); + + while(plot_lock() == false); + + wind_get_grect(aes_handle, WF_FIRSTXYWH, &visible_ro); + while (visible_ro.g_w > 0 && visible_ro.g_h > 0) { + + // TODO: optimze the rectangle list - + // remove rectangles which were completly inside the visible area. + // that way we don't have to loop over again... + for(i=0; iredraw_slots.areas_used; i++){ + + GRECT rdrw_area = { + rootwin->redraw_slots.areas[i].x0, + rootwin->redraw_slots.areas[i].y0, + rootwin->redraw_slots.areas[i].x1 + + rootwin->redraw_slots.areas[i].x0, + rootwin->redraw_slots.areas[i].y1 + + rootwin->redraw_slots.areas[i].y0 + }; + GRECT visible = visible_ro; + + rc_intersect(&rdrw_area, &visible); + if (rc_intersect(&tb_area, &visible)) { + toolbar_redraw(rootwin->toolbar, &visible); + } + } + wind_get_grect(aes_handle, WF_NEXTXYWH, &visible_ro); + } + rootwin->redraw_slots.areas_used = 0; + + plot_unlock(); +} + /* -------------------------------------------------------------------------- */ /* Event Handlers: */ @@ -632,54 +702,16 @@ static void redraw(GUIWIN *win, short msg[8]) GRECT clip = {msg[4], msg[5], msg[6], msg[7]}; window_redraw_favicon(rootwin, &clip); } else { - GRECT content_area, tb_area; - short pxy[8]; - - guiwin_get_grect(win, GUIWIN_AREA_CONTENT, &content_area); - guiwin_get_grect(win, GUIWIN_AREA_TOOLBAR, &tb_area); - - if (rc_intersect(&tb_area, &clip)) { - toolbar_set_dimensions(rootwin->toolbar, &tb_area); - toolbar_redraw(rootwin->toolbar, clip); - } - - CMP_BROWSER browser = rootwin->active_gui_window->browser; - if (browser->reformat_pending == true) { - browser_window_reformat(browser->bw, false, content_area.g_w, - content_area.g_h ); - } else { - if(rc_intersect(&content_area, &clip)){ - - GRECT lclip = content_area; - - /* convert redraw coords to framebuffer coords: */ - lclip.g_x -= content_area.g_x; - lclip.g_y -= content_area.g_y; - - if( lclip.g_x < 0 ) { - lclip.g_w = content_area.g_w + lclip.g_x; - lclip.g_x = 0; - } - - if( lclip.g_y < 0 ) { - lclip.g_h = content_area.g_h + lclip.g_y; - lclip.g_y = 0; - } + window_schedule_redraw_grect(rootwin, &clip); - browser_schedule_redraw(rootwin->active_gui_window, - lclip.g_x, lclip.g_y, - lclip.g_x + lclip.g_w, - lclip.g_y + lclip.g_h); - } - } - - //guiwin_clear(win); + // TODO: remove this call when browser redraw is implemented: + guiwin_clear(win); } } static void resized(GUIWIN *win) { - short x,y,w,h; + GRECT g; short handle; struct gui_window *gw; struct rootwin_data_s *data = guiwin_get_user_data(win); @@ -700,22 +732,23 @@ static void resized(GUIWIN *win) return; //assert( gw != NULL ); - wind_get(handle, WF_CURRXYWH, &x, &y, &w, &h); + wind_get_grect(handle, WF_CURRXYWH, &g); - if (rootwin->loc.g_w != w || rootwin->loc.g_h != h) { + if (rootwin->loc.g_w != g.g_w || rootwin->loc.g_h != g.g_h) { if ( gw->browser->bw->current_content != NULL ) { /* Reformat will happen when redraw is processed: */ + // TODO: call reformat directly, this was introduced because + // of bad AES knowledge, it's ok to call it directly here... rootwin->active_gui_window->browser->reformat_pending = true; } } - if (rootwin->loc.g_x != x || rootwin->loc.g_y != y) { - // moved - } +// if (rootwin->loc.g_x != g.g_x || rootwin->loc.g_y != g.g_y) { +// // moved +// } - rootwin->loc.g_x = x; - rootwin->loc.g_y = y; - rootwin->loc.g_w = w; - rootwin->loc.g_h = h; + rootwin->loc = g; + guiwin_get_grect(win, GUIWIN_AREA_TOOLBAR, &g); + toolbar_set_dimensions(rootwin->toolbar, &g); } static void __CDECL file_dropped(GUIWIN *win, short msg[8]) diff --git a/atari/rootwin.h b/atari/rootwin.h index f7aa7c457..2fa3ec5bb 100755 --- a/atari/rootwin.h +++ b/atari/rootwin.h @@ -68,6 +68,8 @@ void window_set_stauts(struct s_gui_win_root * rootwin, char * text); void window_set_title(struct s_gui_win_root * rootwin, char * text); void window_set_icon(struct s_gui_win_root * rootwin, struct bitmap * bmp ); void window_set_active_gui_window(ROOTWIN *rootwin, struct gui_window *gw); +void window_schedule_redraw_grect(ROOTWIN *rootwin, GRECT *area); +void window_process_redraws(ROOTWIN * rootwin); struct gui_window * window_get_active_gui_window(ROOTWIN * rootwin); void window_redraw_favicon(struct s_gui_win_root * rootwin, GRECT *clip); void window_unref_gui_window(ROOTWIN *rootwin, struct gui_window *gw); diff --git a/atari/schedule.c b/atari/schedule.c index 8040c80a8..a91c510b3 100755 --- a/atari/schedule.c +++ b/atari/schedule.c @@ -158,8 +158,8 @@ schedule_run(void) prev_nscb = NULL; nexttime = cur_nscb->timeout; - while ( cur_nscb != NULL ) { - if ( now > cur_nscb->timeout ) { + while (cur_nscb != NULL) { + if (now > cur_nscb->timeout) { /* scheduled time */ /* remove callback */ @@ -194,7 +194,7 @@ schedule_run(void) /* if the time to the event is sooner than the * currently recorded soonest event record it */ - if( nexttime > cur_nscb->timeout ){ + if (nexttime > cur_nscb->timeout) { nexttime = cur_nscb->timeout; } /* move to next element */ diff --git a/atari/statusbar.c b/atari/statusbar.c index c8f8688c6..d76cf6365 100755 --- a/atari/statusbar.c +++ b/atari/statusbar.c @@ -38,7 +38,7 @@ #include "atari/gui.h" #include "atari/statusbar.h" -#include "atari/rootwin.h" +#include "atari/rootwin.h" #include "atari/misc.h" #include "atari/global_evnt.h" #include "atari/res/netsurf.rsh" @@ -182,7 +182,7 @@ void sb_destroy( CMP_STATUSBAR s ) } } -void sb_set_text( CMP_STATUSBAR sb , char * text ) +void sb_set_text(CMP_STATUSBAR sb , const char * text) { LGRECT work; @@ -221,11 +221,11 @@ void sb_destroy( CMP_STATUSBAR s ) void sb_attach(CMP_STATUSBAR sb, struct gui_window * gw) { - sb->aes_win = gw->root->handle->handle; + sb->aes_win = guiwin_get_handle(gw->root->win); sb->attached = true; } -void sb_set_text(CMP_STATUSBAR sb, char * text ) +void sb_set_text(CMP_STATUSBAR sb, const char * text ) { assert( sb != NULL ); strncpy(sb->text, text, STATUSBAR_MAX_SLEN); diff --git a/atari/statusbar.h b/atari/statusbar.h index fc6749e91..7739c6fed 100755 --- a/atari/statusbar.h +++ b/atari/statusbar.h @@ -36,6 +36,6 @@ struct s_statusbar CMP_STATUSBAR sb_create( struct gui_window * gw ); void sb_destroy( CMP_STATUSBAR s ); -void sb_set_text( CMP_STATUSBAR sb , char * text ); +void sb_set_text( CMP_STATUSBAR sb , const char * text ); void sb_attach(CMP_STATUSBAR sb, struct gui_window * gw); #endif diff --git a/atari/toolbar.c b/atari/toolbar.c index 39025697d..75d7abe28 100644 --- a/atari/toolbar.c +++ b/atari/toolbar.c @@ -116,7 +116,8 @@ struct s_toolbar bool hidden; int btcnt; int style; - bool redraw; + bool redraw; + bool reflow; }; extern char * option_homepage_url; @@ -410,6 +411,8 @@ void toolbar_destroy(struct s_toolbar *tb) static void toolbar_objc_reflow(struct s_toolbar *tb) { + + // position toolbar areas: aes_toolbar->ob_x = tb->area.g_x; aes_toolbar->ob_y = tb->area.g_y; aes_toolbar->ob_width = tb->area.g_w; @@ -421,13 +424,6 @@ static void toolbar_objc_reflow(struct s_toolbar *tb) aes_toolbar[TOOLBAR_URL_AREA].ob_width = tb->area.g_w - (aes_toolbar[TOOLBAR_NAVIGATION_AREA].ob_width + aes_toolbar[TOOLBAR_THROBBER_AREA].ob_width); -} - -void toolbar_redraw(struct s_toolbar *tb, GRECT *clip) -{ - // position toolbar areas: - toolbar_objc_reflow(tb); - objc_draw_grect(aes_toolbar,0,8,clip); // position throbber image: throbber_form[tb->throbber.index].ob_x = tb->area.g_x + @@ -442,10 +438,17 @@ void toolbar_redraw(struct s_toolbar *tb, GRECT *clip) ((aes_toolbar[TOOLBAR_THROBBER_AREA].ob_height - throbber_form[tb->throbber.index].ob_height) >> 1); - printf("x pos: %d, y pos: %d\n", throbber_form[tb->throbber.index].ob_x, - throbber_form[tb->throbber.index].ob_y); - objc_draw_grect(&throbber_form[tb->throbber.index], 0, 1, clip); + tb->reflow = false; +} + +void toolbar_redraw(struct s_toolbar *tb, GRECT *clip) +{ + if(tb->reflow == true) + toolbar_objc_reflow(tb); + objc_draw_grect(aes_toolbar,0,8,clip); + + objc_draw_grect(&throbber_form[tb->throbber.index], 0, 1, clip); } @@ -459,9 +462,7 @@ void toolbar_update_buttons(struct s_toolbar *tb, struct browser_window *bw, void toolbar_set_dimensions(struct s_toolbar *tb, GRECT *area) { tb->area = *area; - if (img_toolbar != 0) { - toolbar_reflow(tb); - } + tb->reflow = true; } diff --git a/atari/toolbar.h b/atari/toolbar.h index 7cc7b92e9..17cb16d08 100644 --- a/atari/toolbar.h +++ b/atari/toolbar.h @@ -27,6 +27,7 @@ void toolbar_update_buttons(struct s_toolbar *tb, struct browser_window *bw, void toolbar_get_grect(struct s_toolbar *tb, short which, short opt, GRECT *g); struct text_area *toolbar_get_textarea(struct s_toolbar *tb, enum toolbar_textarea which); +void toolbar_redraw(struct s_toolbar *tb, GRECT *clip); /* public events handlers: */ void toolbar_back_click(struct s_toolbar *tb); void toolbar_reload_click(struct s_toolbar *tb); -- cgit v1.2.3