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

Side by Side Diff: src/core/SkRecordDraw.h

Issue 698643002: Expose FillBounds to allow GrPictureUtils::CollectLayers to be layered on top of it (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Layer CollectLayers on top of FillBounds Created 6 years, 1 month 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/core/SkRecordDraw.cpp » ('j') | src/core/SkRecordDraw.cpp » ('J')
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 #ifndef SkRecordDraw_DEFINED 8 #ifndef SkRecordDraw_DEFINED
9 #define SkRecordDraw_DEFINED 9 #define SkRecordDraw_DEFINED
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 p.setColor(c.color); 64 p.setColor(c.color);
65 DrawRect drawRect(p, fClearRect); 65 DrawRect drawRect(p, fClearRect);
66 this->INHERITED::operator()(drawRect); 66 this->INHERITED::operator()(drawRect);
67 } 67 }
68 68
69 private: 69 private:
70 const SkRect fClearRect; 70 const SkRect fClearRect;
71 typedef Draw INHERITED; 71 typedef Draw INHERITED;
72 }; 72 };
73 73
74 // This is an SkRecord visitor that fills an SkBBoxHierarchy.
75 //
76 // The interesting part here is how to calculate bounds for ops which don't
77 // have intrinsic bounds. What is the bounds of a Save or a Translate?
78 //
79 // We answer this by thinking about a particular definition of bounds: if I
80 // don't execute this op, pixels in this rectangle might draw incorrectly. So
81 // the bounds of a Save, a Translate, a Restore, etc. are the union of the
82 // bounds of Draw* ops that they might have an effect on. For any given
83 // Save/Restore block, the bounds of the Save, the Restore, and any other
84 // non-drawing ("control") ops inside are exactly the union of the bounds of
85 // the drawing ops inside that block.
86 //
87 // To implement this, we keep a stack of active Save blocks. As we consume ops
88 // inside the Save/Restore block, drawing ops are unioned with the bounds of
89 // the block, and control ops are stashed away for later. When we finish the
90 // block with a Restore, our bounds are complete, and we go back and fill them
91 // in for all the control ops we stashed away.
92 class FillBounds : SkNoncopyable {
93 public:
94 FillBounds(const SkRecord& record, SkBBoxHierarchy* bbh);
95
96 template <typename T> void operator()(const T& op) {
97 this->updateCTM(op);
98 this->updateClipBounds(op);
99 this->trackBounds(op);
100 }
101
102 protected:
103 // In FillBounds, SkRect are in local coordinates, Bounds are translated bac k to identity space.
104 typedef SkRect Bounds;
105
106 unsigned currentOp() const { return fCurrentOp; }
107 const SkMatrix& ctm() const { return *fCTM; }
108 const Bounds& currentClipBounds() const { return fCurrentClipBounds; }
109
110 Bounds adjustAndMap(SkRect rect, const SkPaint* paint) const;
robertphillips 2014/11/03 15:38:57 getBound is only called when processing a Restore
mtklein 2014/11/03 15:56:46 Let's call it getBounds() for consistency with all
robertphillips 2014/11/03 16:49:18 Done.
111 const Bounds& getBound(unsigned index) const { return fBounds[index]; }
112
113 private:
114 struct SaveBounds {
115 int controlOps; // Number of control ops in this Save block, incl uding the Save.
116 Bounds bounds; // Bounds of everything in the block.
117 const SkPaint* paint; // Unowned. If set, adjusts the bounds of all op s in this block.
118 };
119
120 template <typename T> void updateCTM(const T&);
121 template <typename T> void updateClipBounds(const T&);
122 template <typename T> void trackBounds(const T&);
123 template <typename T> Bounds bounds(const T&) const;
124
125 void updateClipBoundsForClipOp(const SkIRect& devBounds);
126
127 void pushSaveBlock(const SkPaint* paint);
128 static bool PaintMayAffectTransparentBlack(const SkPaint* paint);
mtklein 2014/11/03 15:56:46 Let's make this guy a static function in the .cpp?
robertphillips 2014/11/03 16:49:18 Done.
129 Bounds popSaveBlock();
130 void pushControl();
131 void popControl(const Bounds& bounds);
132 void updateSaveBounds(const Bounds& bounds);
133
134 static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint);
mtklein 2014/11/03 15:56:46 These two too?
robertphillips 2014/11/03 16:49:18 Done.
135 static bool AdjustForPaint(const SkPaint* paint, SkRect* rect);
136 bool adjustForSaveLayerPaints(SkRect* rect, int savesToIgnore = 0) const;
137
138 // Conservative identity-space bounds for each op in the SkRecord.
139 SkAutoTMalloc<Bounds> fBounds;
140
141 // We walk fCurrentOp through the SkRecord, as we go using updateCTM()
142 // and updateClipBounds() to maintain the exact CTM (fCTM) and conservative
143 // identity-space bounds of the current clip (fCurrentClipBounds).
144 unsigned fCurrentOp;
145 const SkMatrix* fCTM;
146 Bounds fCurrentClipBounds;
147
148 // Used to track the bounds of Save/Restore blocks and the control ops insid e them.
149 SkTDArray<SaveBounds> fSaveStack;
150 SkTDArray<unsigned> fControlIndices;
151 };
152
153
74 } // namespace SkRecords 154 } // namespace SkRecords
75 155
76 #endif//SkRecordDraw_DEFINED 156 #endif//SkRecordDraw_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/core/SkRecordDraw.cpp » ('j') | src/core/SkRecordDraw.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698