summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2016-04-20 19:18:15 +0100
committerVincent Sanders <vince@kyllikki.org>2016-04-20 19:18:15 +0100
commita6dd92c57137eeabf3e5dc92edeb472ac2c60c96 (patch)
tree867c69769d2c093ec5baffd9862b1479f0e39099
parent31de1c251b5c6f6a39f6f7500e28c6086b807953 (diff)
downloadnetsurf-a6dd92c57137eeabf3e5dc92edeb472ac2c60c96.tar.gz
netsurf-a6dd92c57137eeabf3e5dc92edeb472ac2c60c96.tar.bz2
use monotonic clock call for html reflow timing
-rw-r--r--content/content_protected.h6
-rw-r--r--render/html.c19
-rw-r--r--render/html_object.c54
3 files changed, 47 insertions, 32 deletions
diff --git a/content/content_protected.h b/content/content_protected.h
index e901e40df..148dc131e 100644
--- a/content/content_protected.h
+++ b/content/content_protected.h
@@ -130,9 +130,9 @@ struct content {
if LOADING or READY,
otherwise total time. */
- unsigned int reformat_time; /**< Earliest time to attempt a
- period reflow while fetching a
- page's objects. */
+ uint64_t reformat_time; /**< Earliest time to attempt a period
+ * reflow while fetching a page's objects.
+ */
unsigned int size; /**< Estimated size of all data
associated with this content */
diff --git a/render/html.c b/render/html.c
index e7d2c4865..98e3b98de 100644
--- a/render/html.c
+++ b/render/html.c
@@ -27,6 +27,7 @@
#include <string.h>
#include <strings.h>
#include <stdlib.h>
+#include <nsutils/time.h>
#include "utils/config.h"
#include "utils/corestrings.h"
@@ -1373,9 +1374,11 @@ static void html_reformat(struct content *c, int width, int height)
{
html_content *htmlc = (html_content *) c;
struct box *layout;
- unsigned int time_before, time_taken;
+ uint64_t ms_before;
+ uint64_t ms_after;
+ uint64_t ms_next;
- time_before = wallclock();
+ nsu_getmonotonic_ms(&ms_before);
htmlc->reflowing = true;
@@ -1400,10 +1403,14 @@ static void html_reformat(struct content *c, int width, int height)
htmlc->reflowing = false;
- time_taken = wallclock() - time_before;
- c->reformat_time = wallclock() +
- ((time_taken * 3 < nsoption_uint(min_reflow_period) ?
- nsoption_uint(min_reflow_period) : time_taken * 3));
+ /* calculate next reflow time at three times what it took to reflow */
+ nsu_getmonotonic_ms(&ms_after);
+
+ ms_next = (ms_before - ms_after) * 3;
+ if (ms_next < (nsoption_uint(min_reflow_period) * 10)) {
+ ms_next = nsoption_uint(min_reflow_period) * 10;
+ }
+ c->reformat_time = ms_after + ms_next;
}
diff --git a/render/html_object.c b/render/html_object.c
index 9be3339a6..22c9b712a 100644
--- a/render/html_object.c
+++ b/render/html_object.c
@@ -26,8 +26,8 @@
#include <string.h>
#include <strings.h>
#include <stdlib.h>
+#include <nsutils/time.h>
-#include "utils/utils.h"
#include "utils/corestrings.h"
#include "utils/config.h"
#include "utils/log.h"
@@ -434,32 +434,40 @@ html_object_callback(hlcache_handle *object,
break;
}
- if (c->base.status == CONTENT_STATUS_READY && c->base.active == 0 &&
- (event->type == CONTENT_MSG_LOADING ||
- event->type == CONTENT_MSG_DONE ||
- event->type == CONTENT_MSG_ERROR)) {
+ if (c->base.status == CONTENT_STATUS_READY &&
+ c->base.active == 0 &&
+ (event->type == CONTENT_MSG_LOADING ||
+ event->type == CONTENT_MSG_DONE ||
+ event->type == CONTENT_MSG_ERROR)) {
/* all objects have arrived */
content__reformat(&c->base, false, c->base.available_width,
c->base.height);
content_set_done(&c->base);
- }
-
- /* If 1) the configuration option to reflow pages while objects are
- * fetched is set
- * 2) an object is newly fetched & converted,
- * 3) the box's dimensions need to change due to being replaced
- * 4) the object's parent HTML is ready for reformat,
- * 5) the time since the previous reformat is more than the
- * configured minimum time between reformats
- * then reformat the page to display newly fetched objects */
- else if (nsoption_bool(incremental_reflow) &&
- event->type == CONTENT_MSG_DONE &&
- box != NULL && !(box->flags & REPLACE_DIM) &&
- (c->base.status == CONTENT_STATUS_READY ||
- c->base.status == CONTENT_STATUS_DONE) &&
- (wallclock() > c->base.reformat_time)) {
- content__reformat(&c->base, false, c->base.available_width,
- c->base.height);
+ } else if (nsoption_bool(incremental_reflow) &&
+ event->type == CONTENT_MSG_DONE &&
+ box != NULL &&
+ !(box->flags & REPLACE_DIM) &&
+ (c->base.status == CONTENT_STATUS_READY ||
+ c->base.status == CONTENT_STATUS_DONE)) {
+ /* 1) the configuration option to reflow pages while
+ * objects are fetched is set
+ * 2) an object is newly fetched & converted,
+ * 3) the box's dimensions need to change due to being replaced
+ * 4) the object's parent HTML is ready for reformat,
+ */
+ uint64_t ms_now;
+ nsu_getmonotonic_ms(&ms_now);
+ if (ms_now > c->base.reformat_time) {
+ /* The time since the previous reformat is
+ * more than the configured minimum time
+ * between reformats so reformat the page to
+ * display newly fetched objects
+ */
+ content__reformat(&c->base,
+ false,
+ c->base.available_width,
+ c->base.height);
+ }
}
return NSERROR_OK;