Commit 8bc3e706 authored by Juanmi Huertas's avatar Juanmi Huertas Committed by Commit Bot

Reland "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: I4fc30fe2f79bb525a25fbedd11dfb5da73277cfd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1678550
Commit-Queue: Juanmi Huertas <juanmihd@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#673443}
parent ba611c04
...@@ -705,6 +705,15 @@ void BaseRenderingContext2D::fillRect(double x, ...@@ -705,6 +705,15 @@ 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, the texture of the pattern will not be able to be
// moved to the texture of the canvas receiving the pattern (because if the
// pattern was unaccelerated is because it was not possible to hold that image
// in an accelerated texture - that is, into the GPU). 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
...@@ -117,6 +117,11 @@ class CanvasRenderingContext2DState final ...@@ -117,6 +117,11 @@ class CanvasRenderingContext2DState final
CanvasStyle* Style(PaintType) const; CanvasStyle* Style(PaintType) const;
bool HasPattern() const;
// Only to be used if the CanvasRenderingContext2dState has Pattern
bool PatternIsAccelerated() const;
enum Direction { kDirectionInherit, kDirectionRTL, kDirectionLTR }; enum Direction { kDirectionInherit, kDirectionRTL, kDirectionLTR };
void SetDirection(Direction direction) { direction_ = direction; } void SetDirection(Direction direction) { direction_ = direction; }
......
<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