-
Notifications
You must be signed in to change notification settings - Fork 3.4k
More SVG as image with subresources test coverage #51850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
svg/embedded/image-embedding-nested-data-url-from-canvas-post-window-load.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!doctype html> | ||
<html class=reftest-wait> | ||
<title>Drawing SVG image with data: URL subresources (after window load event)</title> | ||
<link rel="match" href="reference/image-with-nested-rects.html"> | ||
<style> | ||
img { | ||
width: 200px; | ||
height: 200px; | ||
background-color: red; | ||
} | ||
</style> | ||
<img id="result" src=""> | ||
<script> | ||
const canvas = document.createElement('canvas'); | ||
canvas.width = 200; | ||
canvas.height = 200; | ||
const context = canvas.getContext('2d'); | ||
|
||
context.fillStyle = "red"; | ||
context.fillRect(0, 0, canvas.width, canvas.height); | ||
|
||
window.onload = () => { | ||
const image = new Image(); | ||
image.src = "support/image-with-nested-data-url-images.svg?" + Math.random().toString(); | ||
image.onload = () => { | ||
context.drawImage(image, 0, 0, canvas.width, canvas.height); | ||
const resultImage = document.getElementById("result"); | ||
resultImage.src = canvas.toDataURL(); | ||
resultImage.onload = () => document.documentElement.className = ""; | ||
} | ||
}; | ||
</script> |
31 changes: 31 additions & 0 deletions
31
svg/embedded/image-embedding-nested-data-url-from-canvas-window-load.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!doctype html> | ||
<html class=reftest-wait> | ||
<title>Drawing SVG image with data: URL subresources (window load event)</title> | ||
<link rel="match" href="reference/image-with-nested-rects.html"> | ||
<style> | ||
img { | ||
width: 200px; | ||
height: 200px; | ||
background-color: red; | ||
} | ||
</style> | ||
<img id="result" src=""> | ||
<script> | ||
const canvas = document.createElement('canvas'); | ||
canvas.width = 200; | ||
canvas.height = 200; | ||
const context = canvas.getContext('2d'); | ||
|
||
context.fillStyle = "red"; | ||
context.fillRect(0, 0, canvas.width, canvas.height); | ||
|
||
const image = new Image(); | ||
image.src = "support/image-with-nested-data-url-images.svg?" + Math.random().toString(); | ||
|
||
window.onload = () => { | ||
context.drawImage(image, 0, 0, canvas.width, canvas.height); | ||
const resultImage = document.getElementById("result"); | ||
resultImage.src = canvas.toDataURL(); | ||
resultImage.onload = () => document.documentElement.className = ""; | ||
}; | ||
</script> |
31 changes: 31 additions & 0 deletions
31
svg/embedded/image-embedding-nested-data-url-from-canvas.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!doctype html> | ||
<html class=reftest-wait> | ||
<title>Drawing SVG image with data: URL subresources (image load event)</title> | ||
<link rel="match" href="reference/image-with-nested-rects.html"> | ||
<style> | ||
img { | ||
width: 200px; | ||
height: 200px; | ||
background-color: red; | ||
} | ||
</style> | ||
<img id="result" src=""> | ||
<script> | ||
const canvas = document.createElement('canvas'); | ||
canvas.width = 200; | ||
canvas.height = 200; | ||
const context = canvas.getContext('2d'); | ||
|
||
context.fillStyle = "red"; | ||
context.fillRect(0, 0, canvas.width, canvas.height); | ||
|
||
const image = new Image(); | ||
image.src = "support/image-with-nested-data-url-images.svg?" + Math.random().toString(); | ||
|
||
image.onload = () => { | ||
context.drawImage(image, 0, 0, canvas.width, canvas.height); | ||
const resultImage = document.getElementById("result"); | ||
resultImage.src = canvas.toDataURL(); | ||
resultImage.onload = () => document.documentElement.className = ""; | ||
}; | ||
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!doctype html> | ||
<style> | ||
img { | ||
width: 200px; | ||
height: 200px; | ||
background-color: red; | ||
} | ||
</style> | ||
<img src="../support/image-with-nested-rects.svg"> |
63 changes: 63 additions & 0 deletions
63
svg/embedded/support/image-with-nested-data-url-images.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, are you sure per spec this works? Shouldn't you
image.decode().then(
? What guarantees that the inner image:Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the web developer should not worry about loading or decoding internal images. An image should be looked at as one entity especially if you do not have access to its internal structures (like the image in this test case). So for an image there should have only one loading time and only one decoding time.
For drawing an image into a canvas, I think this should force sync decoding. Unlike
HTMLImageElement
in the page, the image will be drawn into the canvas only once. If the image is not drawn because it has not been decoded yet,HTMLImageElement
in the page will be repainted once it is ready. But canvas can't repaint the image.So I think
image.onload()
should be enough to guarantee the image can be drawn to the canvas regardless of whether it contains internal images or not and regardless itsdecoding
attribute issync
orasync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, Firefox probably needs to synchronously decode the nested images as part of painting the SVG, once the load event has fired (or delay the load event until they're decoded).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latter is what WebKit is doing.