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 "GrPictureUtils.h" | 8 #include "GrPictureUtils.h" |
9 | 9 |
10 #include "SkPaintPriv.h" | 10 #include "SkPaintPriv.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 void trackSaveLayers(const SkRecords::DrawPicture& dp) { | 103 void trackSaveLayers(const SkRecords::DrawPicture& dp) { |
104 // For sub-pictures, we wrap their layer information within the parent | 104 // For sub-pictures, we wrap their layer information within the parent |
105 // picture's rendering hierarchy | 105 // picture's rendering hierarchy |
106 const GrAccelData* childData = GPUOptimize(dp.picture); | 106 const GrAccelData* childData = GPUOptimize(dp.picture); |
107 | 107 |
108 for (int i = 0; i < childData->numSaveLayers(); ++i) { | 108 for (int i = 0; i < childData->numSaveLayers(); ++i) { |
109 const GrAccelData::SaveLayerInfo& src = childData->saveLayerInfo(i); | 109 const GrAccelData::SaveLayerInfo& src = childData->saveLayerInfo(i); |
110 | 110 |
111 this->updateStackForSaveLayer(); | 111 this->updateStackForSaveLayer(); |
112 | 112 |
113 GrAccelData::SaveLayerInfo dst; | |
114 | |
115 // TODO: need to store an SkRect in GrAccelData::SaveLayerInfo? | 113 // TODO: need to store an SkRect in GrAccelData::SaveLayerInfo? |
116 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(src.fOffset.fX), | 114 SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(src.fOffset.fX), |
117 SkIntToScalar(src.fOffset.fY), | 115 SkIntToScalar(src.fOffset.fY), |
118 SkIntToScalar(src.fSize.width()), | 116 SkIntToScalar(src.fSize.width()), |
119 SkIntToScalar(src.fSize.height()))
; | 117 SkIntToScalar(src.fSize.height()))
; |
120 SkIRect newClip(fCurrentClipBounds); | 118 SkIRect newClip(fCurrentClipBounds); |
121 newClip.intersect(this->adjustAndMap(srcRect, dp.paint)); | 119 newClip.intersect(this->adjustAndMap(srcRect, dp.paint)); |
122 | 120 |
| 121 GrAccelData::SaveLayerInfo& dst = fAccelData->addSaveLayerInfo(); |
| 122 |
123 dst.fValid = true; | 123 dst.fValid = true; |
124 dst.fPictureID = dp.picture->uniqueID(); | 124 // If src.fPicture is NULL the layer is in dp.picture; otherwise |
| 125 // it belongs to a sub-picture. |
| 126 dst.fPicture = src.fPicture ? src.fPicture : static_cast<const SkPic
ture*>(dp.picture); |
| 127 dst.fPicture->ref(); |
125 dst.fSize = SkISize::Make(newClip.width(), newClip.height()); | 128 dst.fSize = SkISize::Make(newClip.width(), newClip.height()); |
126 dst.fOffset = SkIPoint::Make(newClip.fLeft, newClip.fTop); | 129 dst.fOffset = SkIPoint::Make(newClip.fLeft, newClip.fTop); |
127 dst.fOriginXform = *fCTM; | 130 dst.fOriginXform = *fCTM; |
128 dst.fOriginXform.postConcat(src.fOriginXform); | 131 dst.fOriginXform.postConcat(src.fOriginXform); |
129 | 132 if (src.fPaint) { |
130 if (NULL == src.fPaint) { | |
131 dst.fPaint = NULL; | |
132 } else { | |
133 dst.fPaint = SkNEW_ARGS(SkPaint, (*src.fPaint)); | 133 dst.fPaint = SkNEW_ARGS(SkPaint, (*src.fPaint)); |
134 } | 134 } |
135 | |
136 dst.fSaveLayerOpID = src.fSaveLayerOpID; | 135 dst.fSaveLayerOpID = src.fSaveLayerOpID; |
137 dst.fRestoreOpID = src.fRestoreOpID; | 136 dst.fRestoreOpID = src.fRestoreOpID; |
138 dst.fHasNestedLayers = src.fHasNestedLayers; | 137 dst.fHasNestedLayers = src.fHasNestedLayers; |
139 dst.fIsNested = fSaveLayersInStack > 0 || src.fIsNested; | 138 dst.fIsNested = fSaveLayersInStack > 0 || src.fIsNested; |
140 | |
141 fAccelData->addSaveLayerInfo(dst); | |
142 } | 139 } |
143 } | 140 } |
144 | 141 |
145 void pushSaveBlock() { | 142 void pushSaveBlock() { |
146 fSaveStack.push(SaveInfo(fCurrentOp, false, NULL, SkIRect::MakeEmpty()))
; | 143 fSaveStack.push(SaveInfo(fCurrentOp, false, NULL, SkIRect::MakeEmpty()))
; |
147 } | 144 } |
148 | 145 |
149 // Inform all the saveLayers already on the stack that they now have a | 146 // Inform all the saveLayers already on the stack that they now have a |
150 // nested saveLayer inside them | 147 // nested saveLayer inside them |
151 void updateStackForSaveLayer() { | 148 void updateStackForSaveLayer() { |
(...skipping 23 matching lines...) Expand all Loading... |
175 | 172 |
176 SaveInfo si; | 173 SaveInfo si; |
177 fSaveStack.pop(&si); | 174 fSaveStack.pop(&si); |
178 | 175 |
179 if (!si.fIsSaveLayer) { | 176 if (!si.fIsSaveLayer) { |
180 return; | 177 return; |
181 } | 178 } |
182 | 179 |
183 --fSaveLayersInStack; | 180 --fSaveLayersInStack; |
184 | 181 |
185 GrAccelData::SaveLayerInfo slInfo; | 182 GrAccelData::SaveLayerInfo& slInfo = fAccelData->addSaveLayerInfo(); |
186 | 183 |
187 slInfo.fValid = true; | 184 slInfo.fValid = true; |
188 slInfo.fPictureID = fPictureID; | 185 SkASSERT(NULL == slInfo.fPicture); // This layer is in the top-most pic
ture |
189 slInfo.fSize = SkISize::Make(si.fBounds.width(), si.fBounds.height()); | 186 slInfo.fSize = SkISize::Make(si.fBounds.width(), si.fBounds.height()); |
190 slInfo.fOffset = SkIPoint::Make(si.fBounds.fLeft, si.fBounds.fTop); | 187 slInfo.fOffset = SkIPoint::Make(si.fBounds.fLeft, si.fBounds.fTop); |
191 slInfo.fOriginXform = *fCTM; | 188 slInfo.fOriginXform = *fCTM; |
192 | 189 if (si.fPaint) { |
193 if (NULL == si.fPaint) { | |
194 slInfo.fPaint = NULL; | |
195 } else { | |
196 slInfo.fPaint = SkNEW_ARGS(SkPaint, (*si.fPaint)); | 190 slInfo.fPaint = SkNEW_ARGS(SkPaint, (*si.fPaint)); |
197 } | 191 } |
198 | |
199 slInfo.fSaveLayerOpID = si.fStartIndex; | 192 slInfo.fSaveLayerOpID = si.fStartIndex; |
200 slInfo.fRestoreOpID = fCurrentOp; | 193 slInfo.fRestoreOpID = fCurrentOp; |
201 slInfo.fHasNestedLayers = si.fHasNestedSaveLayer; | 194 slInfo.fHasNestedLayers = si.fHasNestedSaveLayer; |
202 slInfo.fIsNested = fSaveLayersInStack > 0; | 195 slInfo.fIsNested = fSaveLayersInStack > 0; |
203 | |
204 fAccelData->addSaveLayerInfo(slInfo); | |
205 } | 196 } |
206 | 197 |
207 // Returns true if rect was meaningfully adjusted for the effects of paint, | 198 // Returns true if rect was meaningfully adjusted for the effects of paint, |
208 // false if the paint could affect the rect in unknown ways. | 199 // false if the paint could affect the rect in unknown ways. |
209 static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) { | 200 static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) { |
210 if (paint) { | 201 if (paint) { |
211 if (paint->canComputeFastBounds()) { | 202 if (paint->canComputeFastBounds()) { |
212 *rect = paint->computeFastBounds(*rect, rect); | 203 *rect = paint->computeFastBounds(*rect, rect); |
213 return true; | 204 return true; |
214 } | 205 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } | 256 } |
266 | 257 |
267 SkAutoTUnref<GrAccelData> data(SkNEW_ARGS(GrAccelData, (key))); | 258 SkAutoTUnref<GrAccelData> data(SkNEW_ARGS(GrAccelData, (key))); |
268 | 259 |
269 pict->EXPERIMENTAL_addAccelData(data); | 260 pict->EXPERIMENTAL_addAccelData(data); |
270 | 261 |
271 CollectLayers collector(pict, data); | 262 CollectLayers collector(pict, data); |
272 | 263 |
273 return data; | 264 return data; |
274 } | 265 } |
OLD | NEW |