From b212e59a20f304132e8c6636771d250ac7998ad3 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Thu, 6 Nov 2003 19:41:41 +0000 Subject: [project @ 2003-11-06 19:41:41 by bursa] Mask null polls and use PollIdle when appropriate. svn path=/import/netsurf/; revision=406 --- content/fetch.c | 6 ++++++ content/fetch.h | 2 ++ desktop/gui.h | 3 ++- desktop/netsurf.c | 55 +++++++++++++++++++++++++++++++++++-------------------- desktop/netsurf.h | 4 ++-- riscos/gui.c | 39 ++++++++++++++++++++++++--------------- riscos/menus.c | 2 +- riscos/plugin.c | 10 +++++----- 8 files changed, 77 insertions(+), 44 deletions(-) diff --git a/content/fetch.c b/content/fetch.c index a5673a08c..a3ff6e190 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -35,6 +35,8 @@ #include "netsurf/utils/utils.h" +bool fetch_active; /**< Fetches in progress, please call fetch_poll(). */ + /** Information for a single fetch. */ struct fetch { CURL * curl_handle; /**< cURL handle if being fetched, or 0. */ @@ -209,6 +211,7 @@ struct fetch * fetch_start(char *url, char *referer, if (fetch_list != 0) fetch_list->prev = fetch; fetch_list = fetch; + fetch_active = true; /* create the curl easy handle */ fetch->curl_handle = curl_easy_init(); @@ -468,6 +471,9 @@ void fetch_poll(void) } curl_msg = curl_multi_info_read(curl_multi, &queue); } + + if (!fetch_list) + fetch_active = false; } diff --git a/content/fetch.h b/content/fetch.h index 492645df9..fad1f50f0 100644 --- a/content/fetch.h +++ b/content/fetch.h @@ -20,6 +20,8 @@ struct content; struct fetch; struct form_successful_control; +extern bool fetch_active; + void fetch_init(void); struct fetch * fetch_start(char *url, char *referer, void (*callback)(fetch_msg msg, void *p, char *data, unsigned long size), diff --git a/desktop/gui.h b/desktop/gui.h index bb52979c2..aa87b6681 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -15,6 +15,7 @@ typedef enum { SAFE, UNSAFE } gui_safety; struct gui_window; typedef struct gui_window gui_window; +#include #include "netsurf/desktop/browser.h" struct gui_message @@ -51,7 +52,7 @@ void gui_download_window_error(gui_window *g, const char *error); void gui_init(int argc, char** argv); void gui_multitask(void); -void gui_poll(void); +void gui_poll(bool active); gui_safety gui_window_set_redraw_safety(gui_window* g, gui_safety s); diff --git a/desktop/netsurf.c b/desktop/netsurf.c index 0392d986a..ebc364612 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -6,6 +6,8 @@ * Copyright 2003 James Bursa */ +#include +#include #include "netsurf/desktop/options.h" #include "netsurf/desktop/netsurf.h" #include "netsurf/desktop/browser.h" @@ -13,21 +15,35 @@ #include "netsurf/content/cache.h" #include "netsurf/content/fetch.h" #include "netsurf/utils/log.h" -#include -int netsurf_quit = 0; +bool netsurf_quit = false; static void netsurf_init(int argc, char** argv); +static void netsurf_poll(void); static void netsurf_exit(void); -void netsurf_poll(void) +/** + * Gui NetSurf main(). + */ + +int main(int argc, char** argv) { - gui_poll(); - fetch_poll(); + netsurf_init(argc, argv); + + while (!netsurf_quit) + netsurf_poll(); + + netsurf_exit(); + + return EXIT_SUCCESS; } +/** + * Initialise components used by gui NetSurf. + */ + void netsurf_init(int argc, char** argv) { stdout = stderr; @@ -41,24 +57,23 @@ void netsurf_init(int argc, char** argv) } -void netsurf_exit(void) -{ - cache_quit(); - fetch_quit(); -} - +/** + * Poll components which require it. + */ -int main(int argc, char** argv) +void netsurf_poll(void) { - netsurf_init(argc, argv); + gui_poll(fetch_active); + fetch_poll(); +} - while (netsurf_quit == 0) - netsurf_poll(); - LOG(("Netsurf quit!")); - netsurf_exit(); +/** + * Clean up components used by gui NetSurf. + */ - return 0; +void netsurf_exit(void) +{ + cache_quit(); + fetch_quit(); } - - diff --git a/desktop/netsurf.h b/desktop/netsurf.h index 67329e164..aa3bf8b54 100644 --- a/desktop/netsurf.h +++ b/desktop/netsurf.h @@ -8,9 +8,9 @@ #ifndef _NETSURF_DESKTOP_NETSURF_H_ #define _NETSURF_DESKTOP_NETSURF_H_ -extern int netsurf_quit; +#include -void netsurf_poll(void); +extern bool netsurf_quit; #endif diff --git a/riscos/gui.c b/riscos/gui.c index 400fb26da..712244842 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -112,6 +112,7 @@ wimp_t task_handle; wimp_i ro_gui_iconbar_i; gui_window* over_window = NULL; +bool gui_reformat_pending = false; int ro_x_units(unsigned long browser_units) { @@ -470,6 +471,7 @@ void ro_gui_window_open(gui_window* g, wimp_open* open) g->data.browser.bw->current_content->height); g->data.browser.old_width = width; g->data.browser.reformat_pending = true; + gui_reformat_pending = true; } } wimp_open_window(open); @@ -990,7 +992,7 @@ void gui_multitask(void) break; case message_QUIT : - netsurf_quit = 1; + netsurf_quit = true; break; default: @@ -1072,7 +1074,7 @@ void ro_gui_keypress(wimp_key* key) return; } -void gui_poll(void) +void gui_poll(bool active) { wimp_event_no event; wimp_block block; @@ -1083,7 +1085,15 @@ void gui_poll(void) { if (ro_gui_poll_queued_blocks == NULL) { - event = wimp_poll(wimp_MASK_LOSE | wimp_MASK_GAIN, &block, 0); + const wimp_poll_flags mask = wimp_MASK_LOSE | wimp_MASK_GAIN; + if (active) { + event = wimp_poll(mask, &block, 0); + } else if (over_window || gui_reformat_pending) { + os_t t = os_read_monotonic_time(); + event = wimp_poll_idle(mask, &block, t + 10, 0); + } else { + event = wimp_poll(wimp_MASK_NULL | mask, &block, 0); + } finished = 1; } else @@ -1108,12 +1118,15 @@ void gui_poll(void) wimp_get_pointer_info(&pointer); ro_gui_window_mouse_at(&pointer); } - for (g = window_list; g; g = g->next) { - if (g->type == GUI_BROWSER_WINDOW && g->data.browser.reformat_pending) { - content_reformat(g->data.browser.bw->current_content, - browser_x_units(g->data.browser.old_width), 1000); - g->data.browser.reformat_pending = false; + if (gui_reformat_pending) { + for (g = window_list; g; g = g->next) { + if (g->type == GUI_BROWSER_WINDOW && g->data.browser.reformat_pending) { + content_reformat(g->data.browser.bw->current_content, + browser_x_units(g->data.browser.old_width), 1000); + g->data.browser.reformat_pending = false; + } } + gui_reformat_pending = false; } break; @@ -1156,15 +1169,11 @@ void gui_poll(void) break; case wimp_POINTER_LEAVING_WINDOW : - g = ro_lookup_gui_from_w(block.leaving.w); - if (g == over_window) - over_window = NULL; + over_window = NULL; break; case wimp_POINTER_ENTERING_WINDOW : - g = ro_lookup_gui_from_w(block.entering.w); - if (g != NULL) - over_window = g; + over_window = ro_lookup_gui_from_w(block.entering.w); break; case wimp_MOUSE_CLICK : @@ -1261,7 +1270,7 @@ void gui_poll(void) break; case message_QUIT : - netsurf_quit = 1; + netsurf_quit = true; break; } break; diff --git a/riscos/menus.c b/riscos/menus.c index 523185c2c..0ac15431a 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -173,7 +173,7 @@ void ro_gui_menu_selection(wimp_selection *selection) ro_gui_open_help_page(); break; case 3: /* Quit */ - netsurf_quit = 1; + netsurf_quit = true; break; } diff --git a/riscos/plugin.c b/riscos/plugin.c index 02db64676..e64fc8b21 100644 --- a/riscos/plugin.c +++ b/riscos/plugin.c @@ -211,7 +211,7 @@ void plugin_add_instance(struct content *c, struct browser_window *bw, otherwise we'll be stuck in this loop forever */ while(temp->poll == 0) - gui_poll(); + gui_poll(true); if(temp->plugin != 0 && temp->reply != 0) { @@ -256,7 +256,7 @@ void plugin_add_instance(struct content *c, struct browser_window *bw, otherwise we'll be stuck in this loop forever */ while(temp->poll == 0) - gui_poll(); + gui_poll(true); if(temp->plugin != 0 && temp->reply != 0) { @@ -370,7 +370,7 @@ void plugin_remove_instance(struct content *c, struct browser_window *bw, otherwise we'll be stuck in this loop forever */ while (temp == 0) - gui_poll(); + gui_poll(true); if (temp->reply != 0){ @@ -789,7 +789,7 @@ void plugin_create_stream(struct browser_window *bw, struct object_params *param otherwise we'll be stuck in this loop forever */ while(temp->poll == 0) - gui_poll(); + gui_poll(true); pmsn = (plugin_message_stream_new*)&temp->reply->m->data; params->browser_stream = params->browser; @@ -851,7 +851,7 @@ void plugin_write_stream(struct browser_window *bw, struct object_params *params otherwise we'll be stuck in this loop forever */ while(temp->poll == 0) - gui_poll(); + gui_poll(true); pmswt = (plugin_message_stream_written*)&temp->reply->m->data; if(pmswt->length > 0) { -- cgit v1.2.3