Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: src/core/SkPictureShader.cpp

Issue 446243002: Clamp SkPictureShader's tile size. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: updated comment (16M not 16K) Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPictureShader.cpp
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp
index 2a6aae5f4ed477db2daf3c781d6d98c1ada11851..65a2cd322291d2236754e3c965a81738d17aac1a 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());
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698