Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
HARP-7916: Skip NewLabels pass if labels are not updated.
Browse files Browse the repository at this point in the history
New Labels pass will be skipped unless one of the following is true:

- Labels were updated in the frame (new tiles or changed labels).
- Some label is still loading resources (glyphs or icon).
- Some label group was evicted from cache, potentially freeing
screen space for labels not yet placed.

Signed-off-by: Andres Mandado <andres.mandado-almajano@here.com>
  • Loading branch information
atomicsulfate committed Dec 2, 2019
1 parent a863497 commit c86a113
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 deletions @here/harp-mapview/lib/text/TextElementStateCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,24 @@ export class TextElementStateCache {
* @param time The current time.
* @param clearVisited `True` to clear visited flag in group states.
* @param disableFading `True` if fading is currently disabled, `false` otherwise.
* @returns `True` if any textElementGroup was evicted from cache, false otherwise.
*/
update(time: number, clearVisited: boolean, disableFading: boolean) {
let anyEviction = false;
for (const [key, groupState] of this.m_referenceMap.entries()) {
const visible = groupState.updateFading(time, disableFading);
const keep: boolean = visible || groupState.visited;

if (!keep) {
this.m_referenceMap.delete(key);
this.m_sortedGroupStates = undefined;
anyEviction = true;
} else if (clearVisited) {
groupState.visited = false;
}
}
this.m_textMap.clear();
return anyEviction;
}

/**
Expand Down
39 changes: 29 additions & 10 deletions @here/harp-mapview/lib/text/TextElementsRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import {
AdditionParameters,
DEFAULT_TEXT_CANVAS_LAYER,
FontCatalog,
HorizontalAlignment,
MeasurementParameters,
TextBufferAdditionParameters,
TextCanvas,
TextLayoutStyle,
TextRenderStyle,
VerticalAlignment
TextRenderStyle
} from "@here/harp-text-canvas";
import {
assert,
Expand Down Expand Up @@ -227,6 +225,7 @@ export class TextElementsRenderer {
private m_tmpVector = new THREE.Vector2();
private m_overloaded: boolean = false;
private m_cacheInvalidated: boolean = false;
private m_forceNewLabelsPass: boolean = false;
private m_catalogsLoading: number = 0;

private readonly m_textElementStateCache: TextElementStateCache = new TextElementStateCache();
Expand Down Expand Up @@ -360,7 +359,7 @@ export class TextElementsRenderer {
);

const clearVisitedGroups = updateTextElements;
this.m_textElementStateCache.update(
const anyTextGroupEvicted = this.m_textElementStateCache.update(
time,
clearVisitedGroups,
this.m_options.disableFading!
Expand All @@ -372,7 +371,8 @@ export class TextElementsRenderer {

this.reset();
this.prepopulateScreenWithBlockingElements(dataSourceTileList);
this.placeTextElements(time);
const placeNewTextElements = updateTextElements || anyTextGroupEvicted;
this.placeTextElements(time, placeNewTextElements);
this.placeOverlayTextElements();
this.updateTextRenderers();
}
Expand Down Expand Up @@ -730,6 +730,9 @@ export class TextElementsRenderer {
.loadCharset(textElement.text, textElement.renderStyle)
.then(() => {
textElement.loadingState = LoadingState.Loaded;
// Ensure that text elements that were loading glyphs get a chance
// to be rendered if there's no text element updates in the next frames.
this.m_forceNewLabelsPass = true;
this.m_viewUpdateCallback();
});
}
Expand Down Expand Up @@ -1171,7 +1174,7 @@ export class TextElementsRenderer {
}
}

private placeTextElements(time: number) {
private placeTextElements(time: number, placeNewTextElements: boolean) {
const renderParams: RenderParams = {
numRenderedTextElements: 0,
fadeAnimationRunning: false,
Expand All @@ -1190,6 +1193,13 @@ export class TextElementsRenderer {
return;
}

const placeNew = this.m_forceNewLabelsPass || placeNewTextElements;
if (this.m_forceNewLabelsPass) {
if (!placeNewTextElements) {
logger.debug("Force new label pass");
}
this.m_forceNewLabelsPass = false;
}
const maxNumPlacedTextElements = this.m_options.maxNumVisibleLabels!;

// TODO: HARP-7648. Potential performance improvement. Place persistent labels + rejected
Expand All @@ -1208,7 +1218,7 @@ export class TextElementsRenderer {
}

const newPriority = textElementGroupState.priority;
if (currentPriority !== newPriority) {
if (placeNew && currentPriority !== newPriority) {
// Place all new labels of the previous priority before placing the persistent
// labels of this priority.
this.placeNewTextElements(currentPriorityBegin, i, renderParams);
Expand All @@ -1234,8 +1244,10 @@ export class TextElementsRenderer {
}
}

// Place new text elements of the last priority.
this.placeNewTextElements(currentPriorityBegin, groupStates.length, renderParams);
if (placeNew) {
// Place new text elements of the last priority.
this.placeNewTextElements(currentPriorityBegin, groupStates.length, renderParams);
}

if (placementStats) {
placementStats.numRenderedTextElements = renderParams.numRenderedTextElements;
Expand Down Expand Up @@ -1527,7 +1539,10 @@ export class TextElementsRenderer {
) &&
poiInfo!.isValid !== false;

if (renderIcon && poiRenderer.prepareRender(pointLabel, this.m_viewState.zoomLevel)) {
const iconReady =
renderIcon && poiRenderer.prepareRender(pointLabel, this.m_viewState.zoomLevel);

if (iconReady) {
const iconIsVisible = poiRenderer.computeScreenBox(
poiInfo!,
tempPoiScreenPosition,
Expand Down Expand Up @@ -1592,6 +1607,10 @@ export class TextElementsRenderer {
iconRenderState.startFadeOut(this.m_viewState.frameNumber, renderParams.time);
iconRenderState.lastFrameNumber = this.m_viewState.frameNumber;
}
} else if (renderIcon && poiInfo!.isValid !== false) {
// Ensure that text elements still loading icons get a chance to be rendered if
// there's no text element updates in the next frames.
this.m_forceNewLabelsPass = true;
}

// Check if label should be rendered at this zoomLevel
Expand Down

0 comments on commit c86a113

Please sign in to comment.