Commit effb8346 authored by Juanmi Huertas's avatar Juanmi Huertas Committed by Commit Bot

Falling down to unaccelerated when the pattern is accelerated

Adding a function to detect when a renderingcontext2d has pattern and if
it is accelerated. Using that to handle the case when the pattern is big
and unaccelerated and it is being copied to an accelerated canvas.
Falling down to unaccelerated.


Bug: 969713
Change-Id: I32fa5170e9a45528bfe1233317f252d396e733b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1671387
Commit-Queue: Juanmi Huertas <juanmihd@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672255}
parent 97fcfec6
...@@ -705,6 +705,14 @@ void BaseRenderingContext2D::fillRect(double x, ...@@ -705,6 +705,14 @@ void BaseRenderingContext2D::fillRect(double x,
float fwidth = clampTo<float>(width); float fwidth = clampTo<float>(width);
float fheight = clampTo<float>(height); float fheight = clampTo<float>(height);
// We are assuming that if the pattern is not accelerated and the current
// canvas is accelerated, we will not be able to hold the pattern into the
// canvas, probably because it does not fit. That's why we disable the
// acceleration to be sure that it will work
if (IsAccelerated() && GetState().HasPattern() &&
!GetState().PatternIsAccelerated())
DisableAcceleration();
SkRect rect = SkRect::MakeXYWH(fx, fy, fwidth, fheight); SkRect rect = SkRect::MakeXYWH(fx, fy, fwidth, fheight);
Draw([&rect](cc::PaintCanvas* c, const PaintFlags* flags) // draw lambda Draw([&rect](cc::PaintCanvas* c, const PaintFlags* flags) // draw lambda
{ c->drawRect(rect, *flags); }, { c->drawRect(rect, *flags); },
......
...@@ -612,4 +612,15 @@ const PaintFlags* CanvasRenderingContext2DState::GetFlags( ...@@ -612,4 +612,15 @@ const PaintFlags* CanvasRenderingContext2DState::GetFlags(
return flags; return flags;
} }
bool CanvasRenderingContext2DState::HasPattern() const {
return FillStyle() && FillStyle()->GetCanvasPattern() &&
FillStyle()->GetCanvasPattern()->GetPattern();
}
// Only to be used if the CanvasRenderingContext2dState has Pattern
bool CanvasRenderingContext2DState::PatternIsAccelerated() const {
DCHECK(HasPattern());
return FillStyle()->GetCanvasPattern()->GetPattern()->IsTextureBacked();
}
} // namespace blink } // namespace blink
...@@ -115,6 +115,11 @@ class CanvasRenderingContext2DState final ...@@ -115,6 +115,11 @@ class CanvasRenderingContext2DState final
void SetFillStyle(CanvasStyle*); void SetFillStyle(CanvasStyle*);
CanvasStyle* FillStyle() const { return fill_style_.Get(); } CanvasStyle* FillStyle() const { return fill_style_.Get(); }
bool HasPattern() const;
// Only to be used if the CanvasRenderingContext2dState has Pattern
bool PatternIsAccelerated() const;
CanvasStyle* Style(PaintType) const; CanvasStyle* Style(PaintType) const;
enum Direction { kDirectionInherit, kDirectionRTL, kDirectionLTR }; enum Direction { kDirectionInherit, kDirectionRTL, kDirectionLTR };
......
<html><body>
</body>
<script>
var canvas = document.createElement('canvas');
canvas.width = 400;
var context = canvas.getContext('2d');
context.fillStyle = '#0f0';
context.fillRect(0, 0, 10, 10);
var dstCanvas = document.createElement('canvas');
var dstContext = dstCanvas.getContext('2d');
var pattern = dstContext.createPattern(canvas, 'repeat');
dstContext.fillStyle = pattern;
dstContext.fillRect(0, 0, dstCanvas.width, dstCanvas.height);
document.body.appendChild(dstCanvas);
</script>
</html>
\ No newline at end of file
<script src="../../resources/testharness.js"></script> <html><body>
<script src="../../resources/testharnessreport.js"></script> </body>
<script> <script>
test(function(t) {
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
canvas.width = 40000; canvas.width = 40000;
var context = canvas.getContext('2d'); var context = canvas.getContext('2d');
context.fillStyle = '#0f0'; context.fillStyle = '#0f0';
context.fillRect(0, 0, 1, 1); context.fillRect(0, 0, 10, 10);
var dstCanvas = document.createElement('canvas'); var dstCanvas = document.createElement('canvas');
var dstContext = dstCanvas.getContext('2d'); var dstContext = dstCanvas.getContext('2d');
var pattern = dstContext.createPattern(canvas, 'repeat'); var pattern = dstContext.createPattern(canvas, 'repeat');
dstContext.fillStyle = pattern; dstContext.fillStyle = pattern;
dstContext.fillRect(0, 0, dstCanvas.width, dstCanvas.height); dstContext.fillRect(0, 0, dstCanvas.width, dstCanvas.height);
document.body.appendChild(dstCanvas);
assert_array_equals(dstContext.getImageData(0, 0, 1, 1).data, [0, 255, 0, 255]);
assert_array_equals(dstContext.getImageData(1, 0, 1, 1).data, [0, 0, 0, 0]);
assert_array_equals(dstContext.getImageData(0, 1, 1, 1).data, [0, 0, 0, 0]);
}, 'Tests createPattern using a source image that is a canvas 40k pixels wide.');
</script> </script>
</html>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment