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 #ifndef SkRecordDraw_DEFINED | 8 #ifndef SkRecordDraw_DEFINED |
9 #define SkRecordDraw_DEFINED | 9 #define SkRecordDraw_DEFINED |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 p.setColor(c.color); | 67 p.setColor(c.color); |
68 DrawRect drawRect(p, fClearRect); | 68 DrawRect drawRect(p, fClearRect); |
69 this->INHERITED::operator()(drawRect); | 69 this->INHERITED::operator()(drawRect); |
70 } | 70 } |
71 | 71 |
72 private: | 72 private: |
73 const SkRect fClearRect; | 73 const SkRect fClearRect; |
74 typedef Draw INHERITED; | 74 typedef Draw INHERITED; |
75 }; | 75 }; |
76 | 76 |
| 77 // This is an SkRecord visitor that fills an SkBBoxHierarchy. |
| 78 // |
| 79 // The interesting part here is how to calculate bounds for ops which don't |
| 80 // have intrinsic bounds. What is the bounds of a Save or a Translate? |
| 81 // |
| 82 // We answer this by thinking about a particular definition of bounds: if I |
| 83 // don't execute this op, pixels in this rectangle might draw incorrectly. So |
| 84 // the bounds of a Save, a Translate, a Restore, etc. are the union of the |
| 85 // bounds of Draw* ops that they might have an effect on. For any given |
| 86 // Save/Restore block, the bounds of the Save, the Restore, and any other |
| 87 // non-drawing ("control") ops inside are exactly the union of the bounds of |
| 88 // the drawing ops inside that block. |
| 89 // |
| 90 // To implement this, we keep a stack of active Save blocks. As we consume ops |
| 91 // inside the Save/Restore block, drawing ops are unioned with the bounds of |
| 92 // the block, and control ops are stashed away for later. When we finish the |
| 93 // block with a Restore, our bounds are complete, and we go back and fill them |
| 94 // in for all the control ops we stashed away. |
| 95 class FillBounds : SkNoncopyable { |
| 96 public: |
| 97 FillBounds(const SkRect& cullRect, const SkRecord& record, SkBBoxHierarchy*
bbh); |
| 98 |
| 99 void setCurrentOp(unsigned currentOp) { fCurrentOp = currentOp; } |
| 100 void cleanUp(); |
| 101 |
| 102 template <typename T> void operator()(const T& op) { |
| 103 this->updateCTM(op); |
| 104 this->updateClipBounds(op); |
| 105 this->trackBounds(op); |
| 106 } |
| 107 |
| 108 // In FillBounds, SkRect are in local coordinates, Bounds are translated bac
k to identity space. |
| 109 typedef SkRect Bounds; |
| 110 |
| 111 unsigned currentOp() const { return fCurrentOp; } |
| 112 const SkMatrix& ctm() const { return *fCTM; } |
| 113 const Bounds& currentClipBounds() const { return fCurrentClipBounds; } |
| 114 |
| 115 Bounds adjustAndMap(SkRect rect, const SkPaint* paint) const; |
| 116 const Bounds& getBounds(unsigned index) const { return fBounds[index]; } |
| 117 |
| 118 private: |
| 119 struct SaveBounds { |
| 120 int controlOps; // Number of control ops in this Save block, incl
uding the Save. |
| 121 Bounds bounds; // Bounds of everything in the block. |
| 122 const SkPaint* paint; // Unowned. If set, adjusts the bounds of all op
s in this block. |
| 123 }; |
| 124 |
| 125 template <typename T> void updateCTM(const T&); |
| 126 template <typename T> void updateClipBounds(const T&); |
| 127 template <typename T> void trackBounds(const T&); |
| 128 template <typename T> Bounds bounds(const T&) const; |
| 129 |
| 130 void updateClipBoundsForClipOp(const SkIRect& devBounds); |
| 131 |
| 132 void pushSaveBlock(const SkPaint* paint); |
| 133 Bounds popSaveBlock(); |
| 134 void pushControl(); |
| 135 void popControl(const Bounds& bounds); |
| 136 void updateSaveBounds(const Bounds& bounds); |
| 137 |
| 138 bool adjustForSaveLayerPaints(SkRect* rect, int savesToIgnore = 0) const; |
| 139 |
| 140 const unsigned int fNumRecords; |
| 141 |
| 142 // The BBH being filled in |
| 143 SkBBoxHierarchy* fBBH; |
| 144 |
| 145 // We do not guarantee anything for operations outside of the cull rect |
| 146 const SkRect fCullRect; |
| 147 |
| 148 // Conservative identity-space bounds for each op in the SkRecord. |
| 149 SkAutoTMalloc<Bounds> fBounds; |
| 150 |
| 151 // We walk fCurrentOp through the SkRecord, as we go using updateCTM() |
| 152 // and updateClipBounds() to maintain the exact CTM (fCTM) and conservative |
| 153 // identity-space bounds of the current clip (fCurrentClipBounds). |
| 154 unsigned fCurrentOp; |
| 155 const SkMatrix* fCTM; |
| 156 Bounds fCurrentClipBounds; |
| 157 |
| 158 // Used to track the bounds of Save/Restore blocks and the control ops insid
e them. |
| 159 SkTDArray<SaveBounds> fSaveStack; |
| 160 SkTDArray<unsigned> fControlIndices; |
| 161 }; |
| 162 |
| 163 |
77 } // namespace SkRecords | 164 } // namespace SkRecords |
78 | 165 |
79 #endif//SkRecordDraw_DEFINED | 166 #endif//SkRecordDraw_DEFINED |
OLD | NEW |