| 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'll need to call SkPaint::computeFastBounds() later, so bail out if tha
t's not possible. |
| 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 adjust the text bounds. We don't care about left and right
here, so we use |
| 93 // 0 and 1 respectively just so the bounds rectangle isn't empty. |
| 94 SkRect bounds; |
| 95 bounds.set(0, -buffer, SK_Scalar1, buffer); |
| 96 SkRect adjusted = p.computeFastBounds(bounds, &bounds); |
| 97 return c.quickRejectY(minY + adjusted.fTop, maxY + adjusted.fBottom); |
| 92 } | 98 } |
| 93 | 99 |
| 94 template <> bool Draw::canSkip(const SkRecords::DrawPosTextH& r) const { | 100 template <> bool Draw::canSkip(const SkRecords::DrawPosTextH& r) const { |
| 95 return fClipEmpty || can_skip_text(*fCanvas, r.paint, r.y, r.y); | 101 return fClipEmpty || can_skip_text(*fCanvas, r.paint, r.y, r.y); |
| 96 } | 102 } |
| 97 | 103 |
| 98 template <> bool Draw::canSkip(const SkRecords::DrawPosText& r) const { | 104 template <> bool Draw::canSkip(const SkRecords::DrawPosText& r) const { |
| 99 if (fClipEmpty) { | 105 if (fClipEmpty) { |
| 100 return true; | 106 return true; |
| 101 } | 107 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 163 } |
| 158 } | 164 } |
| 159 | 165 |
| 160 } // namespace | 166 } // namespace |
| 161 | 167 |
| 162 void SkRecordDraw(const SkRecord& record, SkCanvas* canvas) { | 168 void SkRecordDraw(const SkRecord& record, SkCanvas* canvas) { |
| 163 for (Draw draw(canvas); draw.index() < record.count(); draw.next()) { | 169 for (Draw draw(canvas); draw.index() < record.count(); draw.next()) { |
| 164 record.visit(draw.index(), draw); | 170 record.visit(draw.index(), draw); |
| 165 } | 171 } |
| 166 } | 172 } |
| OLD | NEW |