Repository navigation
Conversation
|
No actionable comments were generated in the recent review. WalkthroughTexture decoding now uses a shared callback-based path. On supported Chromium versions, it uses ChangesTexture Image Decoding
Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Refactor Sequence Diagram(s)sequenceDiagram
participant GLTFTextureParser
participant ImageDecoder
participant createImageBitmap
participant HTMLImageElement
GLTFTextureParser->>ImageDecoder: _withTextureSource with image data and MIME type
ImageDecoder->>createImageBitmap: Decode with bitmap options
createImageBitmap-->>ImageDecoder: Bitmap or rejection
ImageDecoder->>ImageDecoder: Upload bitmap and close it
ImageDecoder->>HTMLImageElement: Decode image if bitmap creation rejects
Possibly related PRs
Suggested reviewers: Merge Risk:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev/2.0 #3270 +/- ##
========================================
Coverage 89.50% 89.50%
========================================
Files 942 942
Lines 115593 115639 +46
Branches 17928 17935 +7
========================================
+ Hits 103460 103504 +44
- Misses 12010 12012 +2
Partials 123 123
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Decodes embedded 2D textures directly via
createImageBitmapon Chromium >= 112 instead of round-tripping throughHTMLImageElementand blob object URLs (split out from #3266 as an independent, non-breaking PR).Summary
ImageDecoder._withTextureSourceinpackages/loader/src/ImageDecoder.ts:createImageBitmapwithimageOrientation: "from-image",premultiplyAlpha: "none",colorSpaceConversion: "default"), decodes the typed blob to anImageBitmap, runs the synchronous upload callback, and closes the bitmap infinally.HTMLImageElement(ImageDecoder._decodeElement) ifcreateImageBitmaprejects or on non-Chromium browsers (avoiding WebKit translucent RGB rounding differences).GLTFTextureParser._parseTexture,GLTFContentRestorer.restoreContent, andTexture2DDecoder.decodeto upload viaImageDecoder._withTextureSource.tests/src/loader/ImageDecoder.test.tsverifying bitmap decode/disposal, translucent pixel parity with element decode, and fallback behavior.Benchmark & Parity Measurements
Measured on a real multi-GLB scene (405 runtime assets, 179 image textures / 235
texSubImage2Dcalls per startup, 178 images decoded viaImageBitmap, desktop macOS Chromium, identical runtime asset hash8a67b006...).Shipped-Code A/B Retest (4 interleaved runs per arm after warmup)
Baseline (
HTMLImageElement) vs. candidate (b70511175+0587fd6b4, cherry-picked directly into this PR):HTMLImageElement, 0 bitmaps)ImageBitmap, 178 bitmaps)texSubImage2Dsum (235 calls, median)1769 / 1670 / 1683 / 1689)568 / 661 / 561 / 671)WebGLEngine.create→ scene ready, median)3539 / 5144 / 4088 / 3630)2515 / 2968 / 2570 / 3111)(In this paired retest, the Editor host also switched preview-prep shader caching in
galacean/editor#4776, which only affects pre-iframe preparation; the table above isolates in-iframe Engine metrics. Note thattexSubImage2Doverlaps with concurrent asset loads.)Isolated Engine-Only 3-Way Comparison (same Editor, 2 interleaved runs per arm)
ImageBitmap/decode()counttexSubImage2DsumHTMLImageElement(baseline)1,869 / 1,980 ms5,226 / 4,352 msHTMLImageElement.decode()(rejected)3,544 / 4,357 ms6,002 / 7,088 msImageBitmap(this PR)1,179 / 720 ms3,630 / 3,679 msPixel, Color-Profile & EXIF Parity
ImageBitmap): 179/179 base-level textures matched by resource, dimensions, format, and chunked SHA-256 with 0 WebGL errors.readPixelsoutput and dimensions betweenHTMLImageElementandImageBitmap(from-image,premultiplyAlpha: "none",colorSpaceConversion: "default").HTMLImageElementread back[219, 70, 20, 128]vs.ImageBitmap[219, 69, 19, 128], confirming the Chromium-only gate.Browser Gating Rationale & Ecosystem Survey
Why
Chromium >= 112UA Gating Instead of Feature / Runtime Probestypeof createImageBitmap === "function") are insufficient:imageOrientation: "from-image"(added in Chrome 112 / Firefox 111 / Safari 16 per MDN BCD; older Chromium throwsTypeError, as seen in CesiumJS #12846).premultiplyAlpha: "none"RGB rounding difference or Firefox's slowerImageBitmapdecode path.getImageDataprobe (like CesiumJSResource.supportsImageBitmapOptions) still cannot verify WebGL non-premultiplied upload parity.Texture+RenderTarget+readPixelsprobe couplesImageDecoderto a live graphics device, adds startup overhead, and races with early asset loads (PlayCanvas tried this inimg-alpha-test.jsand explicitly removed it inplaycanvas/engine#5235after finding Safari rounded/slowed alpha PNGs and Firefox was slower than<img>).navigator.userAgentvs.navigator.userAgentData:userAgentDatais Secure-Context-only (https/localhost) and unavailable on localhttpdev hosts or some embedded WebViews, whereas Chromium's UA Reduction preserves the major version innavigator.userAgent(Chrome/<major>.0.0.0).Cross-Engine Comparison
!isSafari && typeof ImageBitmap !== 'undefined'(WebGL; includes Chrome & Firefox){ premultiplyAlpha: 'none', colorSpaceConversion: 'none' }(noimageOrientation); applies to all 2D textures (img.js)GLTFLoader)ImageBitmapLoaderexceptSafari < 17,Firefox < 98, or missingcreateImageBitmap{ colorSpaceConversion: 'none', premultiplyAlpha: 'none' }(opened Safari >= 17 inmrdoob/three.js#28560primarily to fix Web Worker texture loading)Resource.supportsImageBitmapOptions)'from-image'back to'flipY'/'none'after Chrome < 112TypeError(#12846)forceBitmapOverHTMLImageElement)HTMLImageElement;createImageBitmapused for WebGPU (fileTools.pure.ts, #18924)Chromium >= 112{ imageOrientation: "from-image", premultiplyAlpha: "none", colorSpaceConversion: "default" }for exact<img>parityMobile & Runtime Coverage
wv+Chrome/<ver>), HarmonyOS NEXT ArkWeb (Chrome/114+), and major in-app WebViews (e.g. WeChat XWeb / Alipay containers) with Blink>= 112hitcreateImageBitmap. Older< 112WebViews, stripped custom UAs, Android Firefox, and mini-game runtimes withoutcreateImageBitmap(blob)safely fall back to_decodeElement.CriOS/,EdgiOS/, in-app containers) run on WebKit and do not containChrome//Chromium/, keeping them onHTMLImageElement(avoiding WebKit translucent RGB rounding and preserving the iOSrAFobject-URL release guard).TextureLoader) andTextureCubeDecoderremain onHTMLImageElementin this PR and can be evaluated separately.Verification
pnpm build(b:module+b:types+validate:engine-knowledge) passed.eslint(0 errors) andprettier --checkpassed on the 4 changed loader source files.pnpm vitest run tests/src/loader/ImageDecoder.test.ts tests/src/loader/GLTFLoader.test.ts: 2 files, 24 tests passed (Chromium).Summary by CodeRabbit