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

Unified Diff: src/core/SkRecordDraw.cpp

Issue 469213007: Start actually bounding some draw ops. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: ) 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 | tests/RecordDrawTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkRecordDraw.cpp
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index e7c9575aefca3c3378544722da5cdfeb026beb66..bc5e7eb63feef19b231e4834f6c5a0ef3a8a1949 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -238,11 +238,92 @@ private:
}
}
- // TODO: Remove this default when done bounding all ops.
+ // TODO(mtklein): Remove this default when done bounding all ops.
template <typename T> SkIRect bounds(const T&) const { return fCurrentClipBounds; }
SkIRect bounds(const Clear&) const { return SkIRect::MakeLargest(); } // Ignores the clip
SkIRect bounds(const NoOp&) const { return SkIRect::MakeEmpty(); } // NoOps don't draw.
+ SkIRect bounds(const DrawRect& op) const { return this->adjustAndMap(op.rect, &op.paint); }
+ SkIRect bounds(const DrawOval& op) const { return this->adjustAndMap(op.oval, &op.paint); }
+ SkIRect bounds(const DrawRRect& op) const {
+ return this->adjustAndMap(op.rrect.rect(), &op.paint);
+ }
+ SkIRect bounds(const DrawDRRect& op) const {
+ return this->adjustAndMap(op.outer.rect(), &op.paint);
+ }
+
+ SkIRect bounds(const DrawBitmapRectToRect& op) const {
+ return this->adjustAndMap(op.dst, op.paint);
+ }
+ SkIRect bounds(const DrawBitmapNine& op) const {
+ return this->adjustAndMap(op.dst, op.paint);
+ }
+ SkIRect bounds(const DrawBitmap& op) const {
+ const SkBitmap& bm = op.bitmap;
+ return this->adjustAndMap(SkRect::MakeXYWH(op.left, op.top, bm.width(), bm.height()),
+ op.paint);
+ }
+ SkIRect bounds(const DrawBitmapMatrix& op) const {
+ const SkBitmap& bm = op.bitmap;
+ SkRect dst = SkRect::MakeWH(bm.width(), bm.height());
+ op.matrix.mapRect(&dst);
+ return this->adjustAndMap(dst, op.paint);
+ }
+
+ SkIRect bounds(const DrawPath& op) const {
+ return op.path.isInverseFillType() ? fCurrentClipBounds
+ : this->adjustAndMap(op.path.getBounds(), &op.paint);
+ }
+ SkIRect bounds(const DrawPoints& op) const {
+ SkRect dst;
+ dst.set(op.pts, op.count);
+
+ // Pad the bounding box a little to make sure hairline points' bounds aren't empty.
+ SkScalar stroke = SkMaxScalar(op.paint.getStrokeWidth(), 0.01f);
+ dst.outset(stroke/2, stroke/2);
+
+ return this->adjustAndMap(dst, &op.paint);
+ }
+
+ SkIRect bounds(const DrawPosText& op) const {
+ const int N = op.paint.countText(op.text, op.byteLength);
+ if (N == 0) {
+ return SkIRect::MakeEmpty();
+ }
+
+ SkRect dst;
+ dst.set(op.pos, op.paint.countText(op.text, N));
+ AdjustTextForFontMetrics(&dst, op.paint);
+ return this->adjustAndMap(dst, &op.paint);
+ }
+ SkIRect bounds(const DrawPosTextH& op) const {
+ const int N = op.paint.countText(op.text, op.byteLength);
+ if (N == 0) {
+ return SkIRect::MakeEmpty();
+ }
+
+ SkScalar left = op.xpos[0], right = op.xpos[0];
+ for (int i = 1; i < N; i++) {
+ left = SkMinScalar(left, op.xpos[i]);
+ right = SkMaxScalar(right, op.xpos[i]);
+ }
+ SkRect dst = { left, op.y, right, op.y };
+ AdjustTextForFontMetrics(&dst, op.paint);
+ return this->adjustAndMap(dst, &op.paint);
+ }
+
+ static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) {
+ // FIXME: These bounds should be tight (and correct), but reading SkFontMetrics is likely
+ // a performance bottleneck. It's safe to overapproximate these metrics for speed. E.g.
+ // fTop <= 1.5 * paint.getTextSize(), fXMax <= 8 * fTop, etc.
+ SkPaint::FontMetrics metrics;
+ paint.getFontMetrics(&metrics);
+ rect->fLeft += metrics.fXMin;
+ rect->fTop += metrics.fTop;
+ rect->fRight += metrics.fXMax;
+ rect->fBottom += metrics.fBottom;
+ }
+
// Returns true if rect was meaningfully adjusted for the effects of paint,
// false if the paint could affect the rect in unknown ways.
static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) {
« no previous file with comments | « no previous file | tests/RecordDrawTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698