Skip to content

Commit 128f932

Browse files
committed
Website updates
1 parent 9850290 commit 128f932

File tree

9 files changed

+49
-13
lines changed

9 files changed

+49
-13
lines changed

dist/en/main/examples/common.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/examples/common.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/examples/offscreen-canvas.worker.worker.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/examples/offscreen-canvas.worker.worker.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/ol/dist/ol.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/ol/dist/ol.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/ol/render/canvas/ExecutorGroup.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/en/main/ol/render/canvas/ExecutorGroup.js

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,41 @@ export const NON_DECLUTTER = ALL.filter(
4040
(builderType) => !DECLUTTER.includes(builderType),
4141
);
4242

43+
/** @type {boolean|undefined} */
44+
let willReadFrequently = false;
45+
46+
/** @type {boolean|undefined} */
47+
let canvasReadsBenchmarked = false;
48+
49+
/** Determine if canvas read operations are faster with willReadFrequently set to true or false */
50+
function benchmarkCanvasReads() {
51+
let bestResult = 0;
52+
/**
53+
* @param {boolean} willReadFrequently Will read frequently.
54+
* @return {number} Operation count.
55+
*/
56+
const measure = (willReadFrequently) => {
57+
const context = createCanvasContext2D(1, 1, null, {willReadFrequently});
58+
let count = 0;
59+
const start = performance.now();
60+
for (; performance.now() - start < 50; ++count) {
61+
context.fillStyle = `rgba(255,0,${count % 256},1)`;
62+
context.fillRect(0, 0, 1, 1);
63+
context.getImageData(0, 0, 1, 1);
64+
}
65+
bestResult = count > bestResult ? count : bestResult;
66+
return count;
67+
};
68+
69+
const measures = {
70+
[measure(true)]: true,
71+
[measure(false)]: false,
72+
[measure(undefined)]: undefined,
73+
};
74+
willReadFrequently = measures[bestResult];
75+
canvasReadsBenchmarked = true;
76+
}
77+
4378
class ExecutorGroup {
4479
/**
4580
* @param {import("../../extent.js").Extent} maxExtent Max extent for clipping. When a
@@ -201,6 +236,10 @@ class ExecutorGroup {
201236
callback,
202237
declutteredFeatures,
203238
) {
239+
if (canvasReadsBenchmarked === false) {
240+
benchmarkCanvasReads();
241+
}
242+
204243
hitTolerance = Math.round(hitTolerance);
205244
const contextSize = hitTolerance * 2 + 1;
206245
const transform = composeTransform(
@@ -216,14 +255,11 @@ class ExecutorGroup {
216255

217256
const newContext = !this.hitDetectionContext_;
218257
if (newContext) {
219-
// Refrain from adding a 'willReadFrequently' hint in the options here.
220-
// While it will remove the "Canvas2D: Multiple readback operations using
221-
// getImageData are faster with the willReadFrequently attribute set
222-
// to true" warnings in the console, it makes hitDetection extremely
223-
// slow in Chrome when there are many features on the map
224258
this.hitDetectionContext_ = createCanvasContext2D(
225259
contextSize,
226260
contextSize,
261+
null,
262+
{willReadFrequently},
227263
);
228264
}
229265
const context = this.hitDetectionContext_;

dist/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)