| <!DOCTYPE html> |
| <script> |
| if (window.testRunner) { testRunner.dumpAsText(); testRunner.waitUntilDone(); } |
| |
| // This test verifies that copyExternalImageToTexture correctly handles |
| // EXIF-rotated images (rdar://170649679) where dimensions are swapped. |
| |
| onload = async () => { |
| try { |
| const adapter = await navigator.gpu.requestAdapter(); |
| if (!adapter) { |
| console.log("FAIL: No WebGPU adapter available"); |
| if (window.testRunner) testRunner.notifyDone(); |
| return; |
| } |
| |
| const device = await adapter.requestDevice(); |
| |
| // Create a 20x10 pixel image (wider than tall) |
| const canvas = document.createElement('canvas'); |
| canvas.width = 20; |
| canvas.height = 10; |
| const ctx = canvas.getContext('2d'); |
| ctx.fillStyle = 'blue'; |
| ctx.fillRect(0, 0, 20, 10); |
| |
| const img = document.createElement('img'); |
| img.src = canvas.toDataURL(); |
| await new Promise(resolve => img.onload = resolve); |
| |
| // Create texture matching the intrinsic dimensions |
| // For a 90° rotated image, the oriented dimensions would be swapped (10x20) |
| // but the pixel buffer is still 20x10 |
| const texture = device.createTexture({ |
| size: { width: 20, height: 10 }, |
| format: 'rgba8unorm', |
| usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING, |
| }); |
| |
| // Copy should succeed using intrinsic dimensions |
| device.queue.copyExternalImageToTexture( |
| { source: img }, |
| { texture: texture }, |
| { width: 20, height: 10 } |
| ); |
| |
| await device.queue.onSubmittedWorkDone(); |
| |
| console.log("PASS: copyExternalImageToTexture handled image dimensions correctly"); |
| |
| } catch (e) { |
| console.log("FAIL: " + e.message); |
| } |
| |
| if (window.testRunner) testRunner.notifyDone(); |
| }; |
| </script> |
| This test passes if it does not crash and prints PASS. |
| |