aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2014-08-07 08:39:24 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-07 08:39:24 -0700
commitbb204f4917aff10fcb65d29a2d96e53a9611c559 (patch)
treea31237e666516125d15c79589ecbff497e0289aa /src
parentb8ccc2f6d258a8466f79fc418e9e0a55aeaf58ce (diff)
Clamp SkPictureShader's tile size.
Blink used to clamp the max size for its pattern bitmaps (several SVG pattern tests rely on/verify this behavior). This CL clamps the maximum tile area to a reasonable value (16M pixels), and scales beyond that. R=bsalomon@google.com, reed@google.com, robertphillips@google.com Author: fmalita@chromium.org Review URL: https://codereview.chromium.org/446243002
Diffstat (limited to 'src')
-rw-r--r--src/core/SkPictureShader.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp
index 2a6aae5f4e..65a2cd3222 100644
--- a/src/core/SkPictureShader.cpp
+++ b/src/core/SkPictureShader.cpp
@@ -76,12 +76,21 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri
}
SkSize scaledSize = SkSize::Make(scale.x() * fTile.width(), scale.y() * fTile.height());
+ // Clamp the tile size to about 16M pixels
+ static const SkScalar kMaxTileArea = 4096 * 4096;
+ SkScalar tileArea = SkScalarMul(scaledSize.width(), scaledSize.height());
+ if (tileArea > kMaxTileArea) {
+ SkScalar clampScale = SkScalarSqrt(SkScalarDiv(kMaxTileArea, tileArea));
+ scaledSize.set(SkScalarMul(scaledSize.width(), clampScale),
+ SkScalarMul(scaledSize.height(), clampScale));
+ }
+
SkISize tileSize = scaledSize.toRound();
if (tileSize.isEmpty()) {
return NULL;
}
- // The actual scale, compensating for rounding.
+ // The actual scale, compensating for rounding & clamping.
SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fTile.width(),
SkIntToScalar(tileSize.height()) / fTile.height());