Skip to content
Permalink
Browse files
Fix strokeStyle changes not being applied for successive stroke line …
…operations.

https://bugs.webkit.org/show_bug.cgi?id=245465

Reviewed by Darin Adler.

The recordStrokeLineWithColorAndThickness optimised path skips serialising the state object, but fails to mark that we've applied the necessary changes.

This means that you can then change state back to it's original value, and we won't detect that it changed.

* LayoutTests/fast/canvas/canvas-strokePath-strokeStyle-expected.html: Added.
* LayoutTests/fast/canvas/canvas-strokePath-strokeStyle.html: Added.
* Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp:
(WebCore::DisplayList::Recorder::strokePath):

Canonical link: https://commits.webkit.org/254889@main
  • Loading branch information
mattwoodrow committed Sep 27, 2022
1 parent dc5502f commit aabdfc49a52bb7286b4325975ccfaabdcf74d907
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<body>
<script>
var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
var ctx = canvas.getContext('2d');

canvas.width = 200;
canvas.height = 200;

ctx.fillStyle = "#f00";
ctx.fillRect(0, 0, 100, 200);

ctx.fillStyle = "#000";
ctx.fillRect(100, 0, 100, 200);

</script>
</body>
</html>
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<body>
<script>
var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
var ctx = canvas.getContext('2d');

canvas.width = 200;
canvas.height = 200;
ctx.lineWidth = 100;

ctx.clearRect(0, 0, 200, 200);

// draw red line
ctx.strokeStyle = "#f00";
ctx.beginPath();
ctx.moveTo(50, 0);
ctx.lineTo(50, 200);
ctx.stroke();

// draw green line
ctx.strokeStyle = "#000";
ctx.beginPath();
ctx.moveTo(150, 0);
ctx.lineTo(150, 200);
ctx.stroke();
</script>
</body>
</html>
@@ -473,6 +473,8 @@ void Recorder::strokePath(const Path& path)
auto& state = currentState().state;
if (state.changes() && state.containsOnlyInlineChanges() && !state.changes().contains(GraphicsContextState::Change::FillBrush) && path.hasInlineData() && path.hasInlineData<LineData>()) {
recordStrokeLineWithColorAndThickness(*strokeColor().tryGetAsSRGBABytes(), strokeThickness(), path.inlineData<LineData>());
state.didApplyChanges();
currentState().lastDrawingState = state;
return;
}

0 comments on commit aabdfc4

Please sign in to comment.