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, if LOADING or READY,
otherwise total time. */ otherwise total time. */
unsigned int reformat_time; /**< Earliest time to attempt a uint64_t reformat_time; /**< Earliest time to attempt a period
period reflow while fetching a * reflow while fetching a page's objects.
page's objects. */ */
unsigned int size; /**< Estimated size of all data unsigned int size; /**< Estimated size of all data
associated with this content */ associated with this content */

View File

@ -27,6 +27,7 @@
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <stdlib.h> #include <stdlib.h>
#include <nsutils/time.h>
#include "utils/config.h" #include "utils/config.h"
#include "utils/corestrings.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; html_content *htmlc = (html_content *) c;
struct box *layout; 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; htmlc->reflowing = true;
@ -1400,10 +1403,14 @@ static void html_reformat(struct content *c, int width, int height)
htmlc->reflowing = false; htmlc->reflowing = false;
time_taken = wallclock() - time_before; /* calculate next reflow time at three times what it took to reflow */
c->reformat_time = wallclock() + nsu_getmonotonic_ms(&ms_after);
((time_taken * 3 < nsoption_uint(min_reflow_period) ?
nsoption_uint(min_reflow_period) : time_taken * 3)); 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 <string.h>
#include <strings.h> #include <strings.h>
#include <stdlib.h> #include <stdlib.h>
#include <nsutils/time.h>
#include "utils/utils.h"
#include "utils/corestrings.h" #include "utils/corestrings.h"
#include "utils/config.h" #include "utils/config.h"
#include "utils/log.h" #include "utils/log.h"
@ -434,32 +434,40 @@ html_object_callback(hlcache_handle *object,
break; break;
} }
if (c->base.status == CONTENT_STATUS_READY && c->base.active == 0 && if (c->base.status == CONTENT_STATUS_READY &&
(event->type == CONTENT_MSG_LOADING || c->base.active == 0 &&
event->type == CONTENT_MSG_DONE || (event->type == CONTENT_MSG_LOADING ||
event->type == CONTENT_MSG_ERROR)) { event->type == CONTENT_MSG_DONE ||
event->type == CONTENT_MSG_ERROR)) {
/* all objects have arrived */ /* all objects have arrived */
content__reformat(&c->base, false, c->base.available_width, content__reformat(&c->base, false, c->base.available_width,
c->base.height); c->base.height);
content_set_done(&c->base); content_set_done(&c->base);
} } else if (nsoption_bool(incremental_reflow) &&
event->type == CONTENT_MSG_DONE &&
/* If 1) the configuration option to reflow pages while objects are box != NULL &&
* fetched is set !(box->flags & REPLACE_DIM) &&
* 2) an object is newly fetched & converted, (c->base.status == CONTENT_STATUS_READY ||
* 3) the box's dimensions need to change due to being replaced c->base.status == CONTENT_STATUS_DONE)) {
* 4) the object's parent HTML is ready for reformat, /* 1) the configuration option to reflow pages while
* 5) the time since the previous reformat is more than the * objects are fetched is set
* configured minimum time between reformats * 2) an object is newly fetched & converted,
* then reformat the page to display newly fetched objects */ * 3) the box's dimensions need to change due to being replaced
else if (nsoption_bool(incremental_reflow) && * 4) the object's parent HTML is ready for reformat,
event->type == CONTENT_MSG_DONE && */
box != NULL && !(box->flags & REPLACE_DIM) && uint64_t ms_now;
(c->base.status == CONTENT_STATUS_READY || nsu_getmonotonic_ms(&ms_now);
c->base.status == CONTENT_STATUS_DONE) && if (ms_now > c->base.reformat_time) {
(wallclock() > c->base.reformat_time)) { /* The time since the previous reformat is
content__reformat(&c->base, false, c->base.available_width, * more than the configured minimum time
c->base.height); * 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; return NSERROR_OK;