|
| 1 | +export const description = ` |
| 2 | +copyExternalImageToTexture from ImageFiles like *.png, *.jpg source. |
| 3 | +`; |
| 4 | + |
| 5 | +import { makeTestGroup } from '../../../common/framework/test_group.js'; |
| 6 | +import { TextureUploadingUtils } from '../../util/copy_to_texture.js'; |
| 7 | +import { |
| 8 | + convertToUnorm8, |
| 9 | + GetSourceFromImageFile, |
| 10 | + kImageNames, |
| 11 | + kImageInfo, |
| 12 | + kImageExpectedColors, |
| 13 | + kObjectTypeFromFiles, |
| 14 | +} from '../util.js'; |
| 15 | + |
| 16 | +export const g = makeTestGroup(TextureUploadingUtils); |
| 17 | + |
| 18 | +g.test('from_orientation_metadata_file') |
| 19 | + .desc( |
| 20 | + ` |
| 21 | + Test HTMLImageElements with rotation metadata can be copied to WebGPU texture correctly. |
| 22 | +
|
| 23 | + It creates an ImageBitmap or HTMLImageElement using images in the 'resources' folder. |
| 24 | +
|
| 25 | + Then call copyExternalImageToTexture() to do a full copy to the 0 mipLevel |
| 26 | + of dst texture, and read one pixel out to compare with the manually documented expected color. |
| 27 | +
|
| 28 | + If 'flipY' in 'GPUCopyExternalImageSourceInfo' is set to 'true', copy will ensure the result |
| 29 | + is flipped. |
| 30 | +
|
| 31 | + The tests covers: |
| 32 | + - Image with rotation metadata |
| 33 | + - Valid 'flipY' config in 'GPUCopyExternalImageSourceInfo' (named 'srcDoFlipYDuringCopy' in cases) |
| 34 | + - TODO: partial copy tests should be added |
| 35 | + - TODO: all valid dstColorFormat tests should be added. |
| 36 | + - TODO(#4108): Make this work in service workers (see GetSourceFromImageFile) |
| 37 | + ` |
| 38 | + ) |
| 39 | + .params(u => |
| 40 | + u // |
| 41 | + .combine('imageName', kImageNames) |
| 42 | + .combine('objectTypeFromFile', kObjectTypeFromFiles) |
| 43 | + .combine('srcDoFlipYDuringCopy', [true, false]) |
| 44 | + ) |
| 45 | + .fn(async t => { |
| 46 | + const { imageName, objectTypeFromFile, srcDoFlipYDuringCopy } = t.params; |
| 47 | + const kColorFormat = 'rgba8unorm'; |
| 48 | + |
| 49 | + // Load image file. |
| 50 | + const source = await GetSourceFromImageFile(t, imageName, objectTypeFromFile); |
| 51 | + const width = source.width; |
| 52 | + const height = source.height; |
| 53 | + |
| 54 | + const dstTexture = t.createTextureTracked({ |
| 55 | + size: { width, height }, |
| 56 | + format: kColorFormat, |
| 57 | + usage: |
| 58 | + GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC | GPUTextureUsage.RENDER_ATTACHMENT, |
| 59 | + }); |
| 60 | + |
| 61 | + t.device.queue.copyExternalImageToTexture( |
| 62 | + { |
| 63 | + source, |
| 64 | + flipY: srcDoFlipYDuringCopy, |
| 65 | + }, |
| 66 | + { |
| 67 | + texture: dstTexture, |
| 68 | + }, |
| 69 | + { |
| 70 | + width, |
| 71 | + height, |
| 72 | + } |
| 73 | + ); |
| 74 | + |
| 75 | + const expect = kImageInfo[imageName].display; |
| 76 | + const presentColors = kImageExpectedColors.srgb; |
| 77 | + |
| 78 | + if (srcDoFlipYDuringCopy) { |
| 79 | + t.expectSinglePixelComparisonsAreOkInTexture({ texture: dstTexture }, [ |
| 80 | + // Flipped top-left. |
| 81 | + { |
| 82 | + coord: { x: width * 0.25, y: height * 0.25 }, |
| 83 | + exp: convertToUnorm8(presentColors[expect.bottomLeftColor]), |
| 84 | + }, |
| 85 | + // Flipped top-right. |
| 86 | + { |
| 87 | + coord: { x: width * 0.75, y: height * 0.25 }, |
| 88 | + exp: convertToUnorm8(presentColors[expect.bottomRightColor]), |
| 89 | + }, |
| 90 | + // Flipped bottom-left. |
| 91 | + { |
| 92 | + coord: { x: width * 0.25, y: height * 0.75 }, |
| 93 | + exp: convertToUnorm8(presentColors[expect.topLeftColor]), |
| 94 | + }, |
| 95 | + // Flipped bottom-right. |
| 96 | + { |
| 97 | + coord: { x: width * 0.75, y: height * 0.75 }, |
| 98 | + exp: convertToUnorm8(presentColors[expect.topRightColor]), |
| 99 | + }, |
| 100 | + ]); |
| 101 | + } else { |
| 102 | + t.expectSinglePixelComparisonsAreOkInTexture({ texture: dstTexture }, [ |
| 103 | + // Top-left. |
| 104 | + { |
| 105 | + coord: { x: width * 0.25, y: height * 0.25 }, |
| 106 | + exp: convertToUnorm8(presentColors[expect.topLeftColor]), |
| 107 | + }, |
| 108 | + // Top-right. |
| 109 | + { |
| 110 | + coord: { x: width * 0.75, y: height * 0.25 }, |
| 111 | + exp: convertToUnorm8(presentColors[expect.topRightColor]), |
| 112 | + }, |
| 113 | + // Bottom-left. |
| 114 | + { |
| 115 | + coord: { x: width * 0.25, y: height * 0.75 }, |
| 116 | + exp: convertToUnorm8(presentColors[expect.bottomLeftColor]), |
| 117 | + }, |
| 118 | + // Bottom-right. |
| 119 | + { |
| 120 | + coord: { x: width * 0.75, y: height * 0.75 }, |
| 121 | + exp: convertToUnorm8(presentColors[expect.bottomRightColor]), |
| 122 | + }, |
| 123 | + ]); |
| 124 | + } |
| 125 | + }); |
0 commit comments