use monotonic clock call for html reflow timing

This commit is contained in:
Vincent Sanders 2016-04-20 19:18:15 +01:00
parent 31de1c251b
commit a6dd92c571
3 changed files with 47 additions and 32 deletions

View File

@ -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 */

View File

@ -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;
}

View File

@ -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;