diff --git a/flamechart-minimap-view.tsx b/flamechart-minimap-view.tsx index 0b5261f..e362e6a 100644 --- a/flamechart-minimap-view.tsx +++ b/flamechart-minimap-view.tsx @@ -9,8 +9,6 @@ import {FontFamily, FontSize, Colors} from './style' import {CanvasContext} from './canvas-context' import {TextureCachedRenderer} from './texture-cached-renderer' -const DEVICE_PIXEL_RATIO = window.devicePixelRatio - interface FlamechartMinimapViewProps { flamechart: Flamechart configSpaceViewportRect: Rect @@ -44,7 +42,7 @@ export class FlamechartMinimapView extends Component { + this.onBeforeFrame() + } + componentWillReceiveProps(nextProps: FlamechartMinimapViewProps) { if (this.props.flamechart !== nextProps.flamechart) { if (this.cachedRenderer) { @@ -199,10 +201,12 @@ export class FlamechartMinimapView extends Component(it: Iterable, f: (a: U, b: T) => U, init: U): // NOTE: This blindly assumes the same result across contexts. const measureTextCache = new Map() + +let lastDevicePixelRatio = -1 export function cachedMeasureTextWidth(ctx: CanvasRenderingContext2D, text: string): number { + if (window.devicePixelRatio !== lastDevicePixelRatio) { + // This cache is no longer valid! + measureTextCache.clear() + lastDevicePixelRatio = window.devicePixelRatio + } if (!measureTextCache.has(text)) { measureTextCache.set(text, ctx.measureText(text).width) }