-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Canvas with relative width does not repaint correctly on parent resize #44463
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
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
31 changes: 31 additions & 0 deletions
31
LayoutTests/compositing/tiling/huge-layer-canvas-resize-expected.txt
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 @@ | ||
| (repaint rects | ||
| (rect 0 0 3400 2000) | ||
| (rect 2500 0 900 2028) | ||
| (rect 2500 0 900 2041) | ||
| ) | ||
| (GraphicsLayer | ||
| (anchor 0.00 0.00) | ||
| (bounds 3400.00 2041.00) | ||
| (children 1 | ||
| (GraphicsLayer | ||
| (bounds 3400.00 2041.00) | ||
| (contentsOpaque 1) | ||
| (children 1 | ||
| (GraphicsLayer | ||
| (bounds 3400.00 2000.00) | ||
| (children 1 | ||
| (GraphicsLayer | ||
| (bounds 3400.00 2000.00) | ||
| (usingTiledLayer 1) | ||
| (drawsContent 1) | ||
| (repaint rects | ||
| (rect 0.00 0.00 2500.00 2000.00) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
75 changes: 75 additions & 0 deletions
75
LayoutTests/compositing/tiling/huge-layer-canvas-resize.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,75 @@ | ||
| <!DOCTYPE html> | ||
| <head> | ||
| <style> | ||
| body { | ||
| margin: 0; | ||
| } | ||
| #container { | ||
| width: 2500px; | ||
| height: 2000px; | ||
| } | ||
| #layer { | ||
| width: 100%; | ||
| height: 100%; | ||
| -webkit-transform:translateZ(0); | ||
| } | ||
| #target { | ||
| display: block; | ||
| width: 100%; | ||
| height: 100%; | ||
| } | ||
| </style> | ||
| <script type="text/javascript" charset="utf-8"> | ||
| if (window.testRunner) { | ||
| testRunner.dumpAsText(); | ||
| testRunner.waitUntilDone(); | ||
| } | ||
|
|
||
| function testOnLoad() | ||
| { | ||
| var canvas = document.getElementById('target'); | ||
| var context = canvas.getContext('2d'); | ||
|
|
||
| const gradient = context.createLinearGradient(0, 0, canvas.width, 0); | ||
| gradient.addColorStop(0, "white"); | ||
| gradient.addColorStop(1, "black"); | ||
| context.fillStyle = gradient; | ||
| context.fillRect(0, 0, canvas.width, canvas.height); | ||
| context.moveTo(0, canvas.height); | ||
| context.lineTo(canvas.width, 0); | ||
| context.moveTo(0, 0); | ||
| context.lineTo(canvas.width, canvas.height); | ||
| context.lineWidth = 20; | ||
| context.strokeStyle = "red"; | ||
| context.stroke(); | ||
|
|
||
| setTimeout(() => { | ||
| if (window.internals) | ||
| window.internals.startTrackingRepaints(); | ||
| document.getElementById('container').style.width = "3400px"; | ||
| if (window.internals) { | ||
| document.getElementById('layers').textContent = window.internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_REPAINT_RECTS); | ||
| window.internals.stopTrackingRepaints(); | ||
| } | ||
| if (window.testRunner) | ||
| testRunner.notifyDone(); | ||
| }, 1000); | ||
| } | ||
|
|
||
| window.addEventListener('load', testOnLoad, false); | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <!-- | ||
| If the size of canvas changes, it should trigger full repaint. | ||
| The repaint issue is only revealed on tiled layer, for untiled layer, | ||
| a full repaint is triggered by GraphicsLayerCA::shouldRepaintOnSizeChange. | ||
| --> | ||
| <div id="container"> | ||
| <div id="layer"> | ||
| <canvas id="target" width="2500" height="2000"></canvas> | ||
| </div> | ||
| </div> | ||
| <pre id="layers">Layer tree including repaint rects appears here in DRT.</pre> | ||
| </body> | ||
| </html> | ||
27 changes: 27 additions & 0 deletions
27
LayoutTests/compositing/tiling/huge-layer-img-resize-expected.txt
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,27 @@ | ||
|
|
||
| (repaint rects | ||
| (rect 0 0 3400 2000) | ||
| (rect 2500 0 900 2028) | ||
| (rect 2500 0 900 2041) | ||
| ) | ||
| (GraphicsLayer | ||
| (anchor 0.00 0.00) | ||
| (bounds 3400.00 2041.00) | ||
| (children 1 | ||
| (GraphicsLayer | ||
| (bounds 3400.00 2041.00) | ||
| (contentsOpaque 1) | ||
| (children 1 | ||
| (GraphicsLayer | ||
| (bounds 3400.00 2000.00) | ||
| (usingTiledLayer 1) | ||
| (drawsContent 1) | ||
| (repaint rects | ||
| (rect 0.00 0.00 2500.00 2000.00) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
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,83 @@ | ||
| <!DOCTYPE html> | ||
| <head> | ||
| <style> | ||
| body { | ||
| margin: 0; | ||
| } | ||
| #container { | ||
| width: 2500px; | ||
| height: 2000px; | ||
| } | ||
| #layer { | ||
| width: 100%; | ||
| height: 100%; | ||
| -webkit-transform:translateZ(0); | ||
| } | ||
| img { | ||
| display: block; | ||
| width: 100%; | ||
| height: 100%; | ||
| } | ||
| </style> | ||
| <script type="text/javascript" charset="utf-8"> | ||
| if (window.testRunner) { | ||
| testRunner.dumpAsText(); | ||
| testRunner.waitUntilDone(); | ||
| } | ||
|
|
||
| function testOnLoad() | ||
| { | ||
| var canvas = document.createElement('canvas'); | ||
| var img = document.getElementById("image"); | ||
| canvas.width = img.width; | ||
| canvas.height = img.height; | ||
| var context = canvas.getContext('2d'); | ||
|
|
||
| const gradient = context.createLinearGradient(0, 0, canvas.width, 0); | ||
| gradient.addColorStop(0, "white"); | ||
| gradient.addColorStop(1, "black"); | ||
| context.fillStyle = gradient; | ||
| context.fillRect(0, 0, canvas.width, canvas.height); | ||
| context.moveTo(0, canvas.height); | ||
| context.lineTo(canvas.width, 0); | ||
| context.moveTo(0, 0); | ||
| context.lineTo(canvas.width, canvas.height); | ||
| context.lineWidth = 20; | ||
| context.strokeStyle = "red"; | ||
| context.stroke(); | ||
|
|
||
| img.src = canvas.toDataURL(); | ||
| } | ||
|
|
||
| async function onImageLoad() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this function marked as |
||
| { | ||
| setTimeout(() => { | ||
| if (window.internals) | ||
| window.internals.startTrackingRepaints(); | ||
| document.getElementById('container').style.width = "3400px"; | ||
| if (window.internals) { | ||
| document.getElementById('layers').textContent = window.internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_REPAINT_RECTS); | ||
| window.internals.stopTrackingRepaints(); | ||
| } | ||
| if (window.testRunner) | ||
| testRunner.notifyDone(); | ||
| }, 1000); | ||
| } | ||
|
|
||
| window.addEventListener('load', testOnLoad, false); | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <!-- | ||
| If the size of image changes, it should trigger full repaint. | ||
| The repaint issue is only revealed on tiled layer, for untiled layer, | ||
| a full repaint is triggered by GraphicsLayerCA::shouldRepaintOnSizeChange. | ||
| --> | ||
| <div id="container"> | ||
| <div id="layer"> | ||
| <img onload="onImageLoad()" id="image"> | ||
| </div> | ||
| </div> | ||
| <pre id="layers">Layer tree including repaint rects appears here in DRT.</pre> | ||
| </body> | ||
| </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
31 changes: 31 additions & 0 deletions
31
LayoutTests/platform/ios/compositing/tiling/huge-layer-canvas-resize-expected.txt
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 @@ | ||
| (repaint rects | ||
| (rect 0 0 3400 2000) | ||
| (rect 2500 0 900 2027) | ||
| (rect 2500 0 900 2040) | ||
| ) | ||
| (GraphicsLayer | ||
| (anchor 0.00 0.00) | ||
| (bounds 3400.00 2040.00) | ||
| (children 1 | ||
| (GraphicsLayer | ||
| (bounds 3400.00 2040.00) | ||
| (contentsOpaque 1) | ||
| (children 1 | ||
| (GraphicsLayer | ||
| (bounds 3400.00 2000.00) | ||
| (children 1 | ||
| (GraphicsLayer | ||
| (bounds 3400.00 2000.00) | ||
| (usingTiledLayer 1) | ||
| (drawsContent 1) | ||
| (repaint rects | ||
| (rect 0.00 0.00 2500.00 2000.00) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
27 changes: 27 additions & 0 deletions
27
LayoutTests/platform/ios/compositing/tiling/huge-layer-img-resize-expected.txt
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,27 @@ | ||
|
|
||
| (repaint rects | ||
| (rect 0 0 3400 2000) | ||
| (rect 2500 0 900 2027) | ||
| (rect 2500 0 900 2040) | ||
| ) | ||
| (GraphicsLayer | ||
| (anchor 0.00 0.00) | ||
| (bounds 3400.00 2040.00) | ||
| (children 1 | ||
| (GraphicsLayer | ||
| (bounds 3400.00 2040.00) | ||
| (contentsOpaque 1) | ||
| (children 1 | ||
| (GraphicsLayer | ||
| (bounds 3400.00 2000.00) | ||
| (usingTiledLayer 1) | ||
| (drawsContent 1) | ||
| (repaint rects | ||
| (rect 0.00 0.00 2500.00 2000.00) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
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
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 |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| #include "RenderElementInlines.h" | ||
| #include "RenderFlexibleBox.h" | ||
| #include "RenderFragmentedFlow.h" | ||
| #include "RenderHTMLCanvas.h" | ||
| #include "RenderHighlight.h" | ||
| #include "RenderImage.h" | ||
| #include "RenderLayer.h" | ||
|
|
@@ -114,6 +115,19 @@ void RenderReplaced::styleDidChange(StyleDifference diff, const RenderStyle* old | |
| intrinsicSizeChanged(); | ||
| } | ||
|
|
||
| static void issueFullRepaintOnSizeChangeIfNeeded(RenderReplaced& renderer) | ||
| { | ||
| auto shouldRepaintOnSizeChange = [&] { | ||
| if (is<RenderHTMLCanvas>(renderer)) | ||
| return true; | ||
| if (auto* renderImage = dynamicDowncast<RenderImage>(renderer); renderImage && !is<RenderMedia>(*renderImage) && !renderImage->isShowingMissingOrImageError()) | ||
| return true; | ||
| return false; | ||
| }; | ||
| if (shouldRepaintOnSizeChange()) | ||
| renderer.repaint(); | ||
| } | ||
|
|
||
| void RenderReplaced::layout() | ||
| { | ||
| StackStats::LayoutCheckPoint layoutCheckPoint; | ||
|
|
@@ -132,12 +146,13 @@ void RenderReplaced::layout() | |
| addVisualEffectOverflow(); | ||
| updateLayerTransform(); | ||
| invalidateBackgroundObscurationStatus(); | ||
|
|
||
| repainter.repaintAfterLayout(); | ||
| clearNeedsLayout(); | ||
|
|
||
| if (replacedContentRect() != oldContentRect) | ||
| if (replacedContentRect() != oldContentRect) { | ||
| setPreferredLogicalWidthsDirty(true); | ||
| issueFullRepaintOnSizeChangeIfNeeded(*this); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a long name for a function. Could it be just? |
||
| } | ||
| } | ||
|
|
||
| void RenderReplaced::intrinsicSizeChanged() | ||
|
|
||
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.
What exactly are you waiting 1000ms for? This makes the behavior of the test un-deterministic. Besides one second is too long time to wait. Can not it be replaced by
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.
We need to make sure the repaint rects before css change has flashed, so I added 1000 ms.
requestAnimationFrameseems not long enough, especially in stress mode.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.
Rego suggested me to use two
requestAnimationFrame, it works! I have created a PR to address the code review comments. Please take a look, thanks:) #45040