Draft for fixing dimensionless SVG#13495
Conversation
|
Thank you for the pull request, @javagl! ✅ We can confirm we have a CLA on file for you. |
| const ctx = canvas.getContext("2d"); | ||
| ctx.drawImage(image, 0, 0); |
There was a problem hiding this comment.
Someone else will have to dig into whether this is actually a factor but at first glance I'd be cautious about reading back data from a canvas element given counter-fingerprinting protections like #12480
There was a problem hiding this comment.
There are some aspects that I haven't looked into - beyond the currently failing tests, and beyond the workarounds listed in the PR description.
During the first investigation pass, I was hoping that there could be a place where some
if (svg.width === undefined) svg.width = 42;
at the right place could trivially fix all this. But I didn't find an obvious place where this could be inserted.
It would be nice if this was an option, though. Every other solution could easily turn into some whack-a-mole situation, where every fix and/or the attempt to carefully roll back the existing workarounds could cause further regressions. The pointer to the fingerprinting may be an important one (even though I don't know exactly where this will kick in). But I'd see this as another reason why it could be nice to try and fix this "in the source data", by inserting some default size...
Not supposed to be merged!
Description
When an SVG does not contain
widthandheightattributes, then it is rendered as black squares in Chrome 148, and prints a WebGL error in the console:This can be reproduced with the image from issue 13479 and the following trivial sandcastle:
<!-- Include screenshots if appropriate -->Sure, here's a screenshot of the rendered SVG:
🤡
This sill worked in Chrome 147. One could consider this to be a form of regression, but ... who would dare to blame Google here?
<!-- Describe your changes in detail -->A general recommendation seems to be to not pass
imgelements toglTexSubImage2D, because it can cause all sorts of trouble and inconsistencies. Instead, one should draw the SVG into a canvas of the desired size, and use that canvas for theglTexSubImage2Dinstead.The change here is a DRAFT that "works" with a local test. But it is by no means clear whether this is the right place for the change. The change is in the
loadImageElementfunction, and for the record, I'll quote the full documentation of this function, its purpose, and its parameters here:The code part itself and its call site link to...
to explain (or rather justify) what is done there, but 1. didn't backtrack through all these links (and some appear to be broken), and 2. any change will likely cause some form regression, given that there are several layers of workarounds stacked on top of each other.
For now, the purpose of this PR is only to illustrate that trying to load SVG directly appears to be prone to issues, and we should consider using the canvas-based approach instead.
Issue number and link
#13479
Testing plan
n/a
Author checklist
CONTRIBUTORS.mdCHANGES.mdwith a short summary of my changeAI acknowledgment
If yes, I used the following Tools(s) and/or Service(s):
I think it's called "Gemini"...
If yes, I used the following Model(s):
Well...