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 #include "SkDevice.h" | 9 #include "SkDevice.h" |
10 #include "SkDraw.h" | 10 #include "SkDraw.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // | 22 // |
23 // Currently the only interesting work is done in drawDevice (i.e., when a | 23 // Currently the only interesting work is done in drawDevice (i.e., when a |
24 // saveLayer is collapsed back into its parent) and, maybe, in onCreateDevice. | 24 // saveLayer is collapsed back into its parent) and, maybe, in onCreateDevice. |
25 // All the current work could be done much more efficiently by just traversing t
he | 25 // All the current work could be done much more efficiently by just traversing t
he |
26 // raw op codes in the SkPicture (although we would still need to replay all the | 26 // raw op codes in the SkPicture (although we would still need to replay all the |
27 // clip calls). | 27 // clip calls). |
28 class GrGatherDevice : public SkBaseDevice { | 28 class GrGatherDevice : public SkBaseDevice { |
29 public: | 29 public: |
30 SK_DECLARE_INST_COUNT(GrGatherDevice) | 30 SK_DECLARE_INST_COUNT(GrGatherDevice) |
31 | 31 |
32 GrGatherDevice(int width, int height, SkPicture* picture, GPUAccelData* acce
lData, | 32 GrGatherDevice(int width, int height, const SkPicture* picture, GPUAccelData
* accelData, |
33 int saveLayerDepth) { | 33 int saveLayerDepth) { |
34 fPicture = picture; | 34 fPicture = picture; |
35 fSaveLayerDepth = saveLayerDepth; | 35 fSaveLayerDepth = saveLayerDepth; |
36 fInfo.fValid = true; | 36 fInfo.fValid = true; |
37 fInfo.fSize.set(width, height); | 37 fInfo.fSize.set(width, height); |
38 fInfo.fPaint = NULL; | 38 fInfo.fPaint = NULL; |
39 fInfo.fSaveLayerOpID = fPicture->EXPERIMENTAL_curOpID(); | 39 fInfo.fSaveLayerOpID = fPicture->EXPERIMENTAL_curOpID(); |
40 fInfo.fRestoreOpID = 0; | 40 fInfo.fRestoreOpID = 0; |
41 fInfo.fHasNestedLayers = false; | 41 fInfo.fHasNestedLayers = false; |
42 fInfo.fIsNested = (2 == fSaveLayerDepth); | 42 fInfo.fIsNested = (2 == fSaveLayerDepth); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 virtual void unlockPixels() SK_OVERRIDE { NothingToDo(); } | 165 virtual void unlockPixels() SK_OVERRIDE { NothingToDo(); } |
166 virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE { return fal
se; } | 166 virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE { return fal
se; } |
167 virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE { return
false; } | 167 virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE { return
false; } |
168 virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImag
eFilter::Context&, | 168 virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImag
eFilter::Context&, |
169 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE { | 169 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE { |
170 return false; | 170 return false; |
171 } | 171 } |
172 | 172 |
173 private: | 173 private: |
174 // The picture being processed | 174 // The picture being processed |
175 SkPicture *fPicture; | 175 const SkPicture *fPicture; |
176 | 176 |
177 SkBitmap fEmptyBitmap; // legacy -- need to remove | 177 SkBitmap fEmptyBitmap; // legacy -- need to remove |
178 | 178 |
179 // All information gathered during the gather process is stored here | 179 // All information gathered during the gather process is stored here |
180 GPUAccelData* fAccelData; | 180 GPUAccelData* fAccelData; |
181 | 181 |
182 // true if this device has already been drawn back to its parent(s) at least | 182 // true if this device has already been drawn back to its parent(s) at least |
183 // once. | 183 // once. |
184 bool fAlreadyDrawn; | 184 bool fAlreadyDrawn; |
185 | 185 |
(...skipping 30 matching lines...) Expand all Loading... |
216 // The GrGatherCanvas allows saveLayers but simplifies clipping. It is really | 216 // The GrGatherCanvas allows saveLayers but simplifies clipping. It is really |
217 // only intended to be used as: | 217 // only intended to be used as: |
218 // | 218 // |
219 // GrGatherDevice dev(w, h, picture, accelData); | 219 // GrGatherDevice dev(w, h, picture, accelData); |
220 // GrGatherCanvas canvas(..., picture); | 220 // GrGatherCanvas canvas(..., picture); |
221 // canvas.gather(); | 221 // canvas.gather(); |
222 // | 222 // |
223 // which is all just to fill in 'accelData' | 223 // which is all just to fill in 'accelData' |
224 class SK_API GrGatherCanvas : public SkCanvas { | 224 class SK_API GrGatherCanvas : public SkCanvas { |
225 public: | 225 public: |
226 GrGatherCanvas(GrGatherDevice* device, SkPicture* pict) | 226 GrGatherCanvas(GrGatherDevice* device, const SkPicture* pict) |
227 : INHERITED(device) | 227 : INHERITED(device) |
228 , fPicture(pict) { | 228 , fPicture(pict) { |
229 } | 229 } |
230 | 230 |
231 void gather() { | 231 void gather() { |
232 if (NULL == fPicture || 0 == fPicture->width() || 0 == fPicture->height(
)) { | 232 if (NULL == fPicture || 0 == fPicture->width() || 0 == fPicture->height(
)) { |
233 return; | 233 return; |
234 } | 234 } |
235 | 235 |
236 this->clipRect(SkRect::MakeWH(SkIntToScalar(fPicture->width()), | 236 this->clipRect(SkRect::MakeWH(SkIntToScalar(fPicture->width()), |
237 SkIntToScalar(fPicture->height())), | 237 SkIntToScalar(fPicture->height())), |
238 SkRegion::kIntersect_Op, false); | 238 SkRegion::kIntersect_Op, false); |
239 this->drawPicture(*fPicture); | 239 this->drawPicture(fPicture); |
240 } | 240 } |
241 | 241 |
242 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE { | |
243 // BBH-based rendering doesn't re-issue many of the operations the gathe
r | |
244 // process cares about (e.g., saves and restores) so it must be disabled
. | |
245 if (NULL != picture.fPlayback) { | |
246 picture.fPlayback->setUseBBH(false); | |
247 } | |
248 picture.draw(this); | |
249 if (NULL != picture.fPlayback) { | |
250 picture.fPlayback->setUseBBH(true); | |
251 } | |
252 } | |
253 protected: | 242 protected: |
254 // disable aa for speed | 243 // disable aa for speed |
255 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle)
SK_OVERRIDE { | 244 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle)
SK_OVERRIDE { |
256 this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle); | 245 this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle); |
257 } | 246 } |
258 | 247 |
259 // for speed, just respect the bounds, and disable AA. May give us a few | 248 // for speed, just respect the bounds, and disable AA. May give us a few |
260 // false positives and negatives. | 249 // false positives and negatives. |
261 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle)
SK_OVERRIDE { | 250 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle)
SK_OVERRIDE { |
262 this->updateClipConservativelyUsingBounds(path.getBounds(), op, | 251 this->updateClipConservativelyUsingBounds(path.getBounds(), op, |
263 path.isInverseFillType()); | 252 path.isInverseFillType()); |
264 } | 253 } |
265 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl
e) SK_OVERRIDE { | 254 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl
e) SK_OVERRIDE { |
266 this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false); | 255 this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false); |
267 } | 256 } |
268 | 257 |
| 258 virtual void onDrawPicture(const SkPicture* picture) SK_OVERRIDE { |
| 259 // BBH-based rendering doesn't re-issue many of the operations the gathe
r |
| 260 // process cares about (e.g., saves and restores) so it must be disabled
. |
| 261 if (NULL != picture->fPlayback) { |
| 262 picture->fPlayback->setUseBBH(false); |
| 263 } |
| 264 picture->draw(this); |
| 265 if (NULL != picture->fPlayback) { |
| 266 picture->fPlayback->setUseBBH(true); |
| 267 } |
| 268 } |
| 269 |
269 private: | 270 private: |
270 SkPicture* fPicture; | 271 const SkPicture* fPicture; |
271 | 272 |
272 typedef SkCanvas INHERITED; | 273 typedef SkCanvas INHERITED; |
273 }; | 274 }; |
274 | 275 |
275 // GatherGPUInfo is only intended to be called within the context of SkGpuDevice
's | 276 // GatherGPUInfo is only intended to be called within the context of SkGpuDevice
's |
276 // EXPERIMENTAL_optimize method. | 277 // EXPERIMENTAL_optimize method. |
277 void GatherGPUInfo(SkPicture* pict, GPUAccelData* accelData) { | 278 void GatherGPUInfo(const SkPicture* pict, GPUAccelData* accelData) { |
278 if (0 == pict->width() || 0 == pict->height()) { | 279 if (0 == pict->width() || 0 == pict->height()) { |
279 return ; | 280 return ; |
280 } | 281 } |
281 | 282 |
282 GrGatherDevice device(pict->width(), pict->height(), pict, accelData, 0); | 283 GrGatherDevice device(pict->width(), pict->height(), pict, accelData, 0); |
283 GrGatherCanvas canvas(&device, pict); | 284 GrGatherCanvas canvas(&device, pict); |
284 | 285 |
285 canvas.gather(); | 286 canvas.gather(); |
286 } | 287 } |
OLD | NEW |