(shouldRequestRenderAfterChanges: boolean)
| 782 | }; |
| 783 | |
| 784 | const resizeInternal = (shouldRequestRenderAfterChanges: boolean): void => { |
| 785 | if (disposed) return; |
| 786 | |
| 787 | const rect = canvas.getBoundingClientRect(); |
| 788 | const dpr = window.devicePixelRatio || 1; |
| 789 | |
| 790 | const maxDimension = gpuContext?.device?.limits.maxTextureDimension2D ?? 8192; |
| 791 | const width = Math.min(maxDimension, Math.max(1, Math.round(rect.width * dpr))); |
| 792 | const height = Math.min(maxDimension, Math.max(1, Math.round(rect.height * dpr))); |
| 793 | |
| 794 | const sizeChanged = canvas.width !== width || canvas.height !== height; |
| 795 | if (sizeChanged) { |
| 796 | canvas.width = width; |
| 797 | canvas.height = height; |
| 798 | } |
| 799 | |
| 800 | const device = gpuContext?.device; |
| 801 | const canvasContext = gpuContext?.canvasContext; |
| 802 | const preferredFormat = gpuContext?.preferredFormat; |
| 803 | |
| 804 | let didConfigure = false; |
| 805 | if (device && canvasContext && preferredFormat) { |
| 806 | const shouldConfigure = |
| 807 | sizeChanged || |
| 808 | !lastConfigured || |
| 809 | lastConfigured.width !== canvas.width || |
| 810 | lastConfigured.height !== canvas.height || |
| 811 | lastConfigured.format !== preferredFormat; |
| 812 | |
| 813 | if (shouldConfigure) { |
| 814 | canvasContext.configure({ |
| 815 | device, |
| 816 | format: preferredFormat, |
| 817 | alphaMode: 'opaque', |
| 818 | }); |
| 819 | lastConfigured = { width: canvas.width, height: canvas.height, format: preferredFormat }; |
| 820 | didConfigure = true; |
| 821 | |
| 822 | // Requirement: if the target format changes, recreate coordinator/pipelines. |
| 823 | if (coordinator && coordinatorTargetFormat !== preferredFormat) { |
| 824 | recreateCoordinator(); |
| 825 | } |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | if (shouldRequestRenderAfterChanges && (sizeChanged || didConfigure)) { |
| 830 | // Requirement: resize() requests a render after size/config changes. |
| 831 | requestRender(); |
| 832 | } |
| 833 | }; |
| 834 | |
| 835 | const resize = (): void => resizeInternal(true); |
| 836 |
no test coverage detected