@luma.gl/core 9.3.2 → 9.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/core",
3
- "version": "9.3.2",
3
+ "version": "9.3.4",
4
4
  "description": "The luma.gl core Device API",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -46,5 +46,5 @@
46
46
  "@probe.gl/stats": "^4.1.1",
47
47
  "@types/offscreencanvas": "^2019.7.3"
48
48
  },
49
- "gitHead": "8f60fca63dc43702af5b16d0381fd97d7ace7dc9"
49
+ "gitHead": "f430daba8be25561034dca6bb0af3ea487c9d1c8"
50
50
  }
@@ -29,6 +29,15 @@ export type CanvasContextProps = {
29
29
  visible?: boolean;
30
30
  /** Whether to size the drawing buffer to the pixel size during auto resize. If a number is provided it is used as a static pixel ratio */
31
31
  useDevicePixels?: boolean | number;
32
+ /**
33
+ * How to derive the tracked device pixel size for HTML canvases when auto-resizing.
34
+ *
35
+ * - `'exact'` uses `ResizeObserver.devicePixelContentBoxSize` when available to match the
36
+ * browser's exact physical pixel coverage.
37
+ * - `'css-dpr'` uses `Math.round(cssSize * devicePixelRatio)` to match overlays and external
38
+ * canvases that still rely on legacy CSS-size times DPR rounding.
39
+ */
40
+ pixelSizeSource?: 'exact' | 'css-dpr';
32
41
  /** Whether to track window resizes. */
33
42
  autoResize?: boolean;
34
43
  /** @see https://developer.mozilla.org/en-US/docs/Web/API/GPUCanvasContext/configure#alphamode */
@@ -66,6 +75,7 @@ export abstract class CanvasSurface {
66
75
  width: 800,
67
76
  height: 600,
68
77
  useDevicePixels: true,
78
+ pixelSizeSource: 'exact',
69
79
  autoResize: true,
70
80
  container: null,
71
81
  visible: true,
@@ -347,13 +357,7 @@ export abstract class CanvasSurface {
347
357
 
348
358
  const oldPixelSize = this.getDevicePixelSize();
349
359
 
350
- const devicePixelWidth =
351
- entry.devicePixelContentBoxSize?.[0]?.inlineSize ||
352
- contentBoxSize.inlineSize * devicePixelRatio;
353
-
354
- const devicePixelHeight =
355
- entry.devicePixelContentBoxSize?.[0]?.blockSize ||
356
- contentBoxSize.blockSize * devicePixelRatio;
360
+ const {devicePixelWidth, devicePixelHeight} = this._getDevicePixelSizeFromResizeEntry(entry);
357
361
 
358
362
  const [maxDevicePixelWidth, maxDevicePixelHeight] = this.getMaxDrawingBufferSize();
359
363
  this.devicePixelWidth = Math.max(1, Math.min(devicePixelWidth, maxDevicePixelWidth));
@@ -385,6 +389,30 @@ export abstract class CanvasSurface {
385
389
  this.updatePosition();
386
390
  }
387
391
 
392
+ protected _getDevicePixelSizeFromResizeEntry(entry: ResizeObserverEntry): {
393
+ devicePixelWidth: number;
394
+ devicePixelHeight: number;
395
+ } {
396
+ const contentBoxSize = assertDefined(entry.contentBoxSize?.[0]);
397
+
398
+ if (this.props.pixelSizeSource === 'css-dpr') {
399
+ const devicePixelRatio = this.getDevicePixelRatio();
400
+ return {
401
+ devicePixelWidth: Math.round(contentBoxSize.inlineSize * devicePixelRatio),
402
+ devicePixelHeight: Math.round(contentBoxSize.blockSize * devicePixelRatio)
403
+ };
404
+ }
405
+
406
+ return {
407
+ devicePixelWidth:
408
+ entry.devicePixelContentBoxSize?.[0]?.inlineSize ||
409
+ contentBoxSize.inlineSize * devicePixelRatio,
410
+ devicePixelHeight:
411
+ entry.devicePixelContentBoxSize?.[0]?.blockSize ||
412
+ contentBoxSize.blockSize * devicePixelRatio
413
+ };
414
+ }
415
+
388
416
  _resizeDrawingBufferIfNeeded() {
389
417
  if (this._needsDrawingBufferResize) {
390
418
  this._needsDrawingBufferResize = false;