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

Side by Side Diff: src/record/SkRecordDraw.cpp

Issue 235983015: SkRecord bug fixes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add regression test for leaking refs Created 6 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/record/SkRecords.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkRecordDraw.h" 8 #include "SkRecordDraw.h"
9 9
10 namespace { 10 namespace {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 #define CAN_SKIP(T) template <> bool Draw::canSkip(const SkRecords::T& r) const \ 69 #define CAN_SKIP(T) template <> bool Draw::canSkip(const SkRecords::T& r) const \
70 { return fClipEmpty && SkRegion::kIntersect_Op == r.op; } 70 { return fClipEmpty && SkRegion::kIntersect_Op == r.op; }
71 CAN_SKIP(ClipPath); 71 CAN_SKIP(ClipPath);
72 CAN_SKIP(ClipRRect); 72 CAN_SKIP(ClipRRect);
73 CAN_SKIP(ClipRect); 73 CAN_SKIP(ClipRect);
74 CAN_SKIP(ClipRegion); 74 CAN_SKIP(ClipRegion);
75 #undef CAN_SKIP 75 #undef CAN_SKIP
76 76
77 static bool can_skip_text(const SkCanvas& c, const SkPaint& p, SkScalar minY, Sk Scalar maxY) { 77 static bool can_skip_text(const SkCanvas& c, const SkPaint& p, SkScalar minY, Sk Scalar maxY) {
78 // If we're drawing vertical text, none of the checks we're about to do make any sense. 78 // If we're drawing vertical text, none of the checks we're about to do make any sense.
79 // We use canComputeFastBounds as a proxy for "is this text going to be rect angular?". 79 // We need to call computeFastBounds() to adjust the text bounds for paint e ffects.
tomhudson 2014/04/15 13:41:36 This edited comment really belongs below with adju
80 if (p.isVerticalText() || !p.canComputeFastBounds()) { 80 if (p.isVerticalText() || !p.canComputeFastBounds()) {
81 return false; 81 return false;
82 } 82 }
83 83
84 // Rather than checking the top and bottom font metrics, we guess. Actually looking up the top 84 // Rather than checking the top and bottom font metrics, we guess. Actually looking up the top
85 // and bottom metrics is slow, and this overapproximation should be good eno ugh. 85 // and bottom metrics is slow, and this overapproximation should be good eno ugh.
86 const SkScalar buffer = p.getTextSize() * 1.5f; 86 const SkScalar buffer = p.getTextSize() * 1.5f;
87 SkDEBUGCODE(SkPaint::FontMetrics metrics;) 87 SkDEBUGCODE(SkPaint::FontMetrics metrics;)
88 SkDEBUGCODE(p.getFontMetrics(&metrics);) 88 SkDEBUGCODE(p.getFontMetrics(&metrics);)
89 SkASSERT(-buffer <= metrics.fTop); 89 SkASSERT(-buffer <= metrics.fTop);
90 SkASSERT(+buffer >= metrics.fBottom); 90 SkASSERT(+buffer >= metrics.fBottom);
91 return c.quickRejectY(minY - buffer, maxY + buffer); 91
92 // Let the paint have its say of any extra efect. 0,1 for left,right makes the rect non-empty.
tomhudson 2014/04/15 13:41:36 spelling: effect. Also, meaning of the entire comm
93 SkRect bounds;
94 bounds.set(0, -buffer, SK_Scalar1, buffer);
95 SkRect adjusted = p.computeFastBounds(bounds, &bounds);
96 return c.quickRejectY(minY + adjusted.fTop, maxY + adjusted.fBottom);
92 } 97 }
93 98
94 template <> bool Draw::canSkip(const SkRecords::DrawPosTextH& r) const { 99 template <> bool Draw::canSkip(const SkRecords::DrawPosTextH& r) const {
95 return fClipEmpty || can_skip_text(*fCanvas, r.paint, r.y, r.y); 100 return fClipEmpty || can_skip_text(*fCanvas, r.paint, r.y, r.y);
96 } 101 }
97 102
98 template <> bool Draw::canSkip(const SkRecords::DrawPosText& r) const { 103 template <> bool Draw::canSkip(const SkRecords::DrawPosText& r) const {
99 if (fClipEmpty) { 104 if (fClipEmpty) {
100 return true; 105 return true;
101 } 106 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 162 }
158 } 163 }
159 164
160 } // namespace 165 } // namespace
161 166
162 void SkRecordDraw(const SkRecord& record, SkCanvas* canvas) { 167 void SkRecordDraw(const SkRecord& record, SkCanvas* canvas) {
163 for (Draw draw(canvas); draw.index() < record.count(); draw.next()) { 168 for (Draw draw(canvas); draw.index() < record.count(); draw.next()) {
164 record.visit(draw.index(), draw); 169 record.visit(draw.index(), draw);
165 } 170 }
166 } 171 }
OLDNEW
« no previous file with comments | « no previous file | src/record/SkRecords.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698