Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 } |
| OLD | NEW |