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 "SkCanvasPriv.h" | 9 #include "SkCanvasPriv.h" |
10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
11 #include "SkDraw.h" | 11 #include "SkDraw.h" |
12 #include "SkPaintPriv.h" | 12 #include "SkPaintPriv.h" |
13 #include "SkPictureData.h" | 13 #include "SkPictureData.h" |
14 #include "SkPicturePlayback.h" | 14 #include "SkPicturePlayback.h" |
15 | 15 |
16 SkPicture::AccelData::Key GPUAccelData::ComputeAccelDataKey() { | 16 SkPicture::AccelData::Key GrAccelData::ComputeAccelDataKey() { |
17 static const SkPicture::AccelData::Key gGPUID = SkPicture::AccelData::Genera
teDomain(); | 17 static const SkPicture::AccelData::Key gGPUID = SkPicture::AccelData::Genera
teDomain(); |
18 | 18 |
19 return gGPUID; | 19 return gGPUID; |
20 } | 20 } |
21 | 21 |
22 // The GrGather device performs GPU-backend-specific preprocessing on | 22 // The GrGather device performs GPU-backend-specific preprocessing on |
23 // a picture. The results are stored in a GPUAccelData. | 23 // a picture. The results are stored in a GrAccelData. |
24 // | 24 // |
25 // Currently the only interesting work is done in drawDevice (i.e., when a | 25 // Currently the only interesting work is done in drawDevice (i.e., when a |
26 // saveLayer is collapsed back into its parent) and, maybe, in onCreateDevice. | 26 // saveLayer is collapsed back into its parent) and, maybe, in onCreateDevice. |
27 // All the current work could be done much more efficiently by just traversing t
he | 27 // All the current work could be done much more efficiently by just traversing t
he |
28 // raw op codes in the SkPicture (although we would still need to replay all the | 28 // raw op codes in the SkPicture (although we would still need to replay all the |
29 // clip calls). | 29 // clip calls). |
30 class GrGatherDevice : public SkBaseDevice { | 30 class GrGatherDevice : public SkBaseDevice { |
31 public: | 31 public: |
32 SK_DECLARE_INST_COUNT(GrGatherDevice) | 32 SK_DECLARE_INST_COUNT(GrGatherDevice) |
33 | 33 |
34 GrGatherDevice(int width, int height, SkPicturePlayback* playback, GPUAccelD
ata* accelData, | 34 GrGatherDevice(int width, int height, SkPicturePlayback* playback, GrAccelDa
ta* accelData, |
35 int saveLayerDepth) { | 35 int saveLayerDepth) { |
36 fPlayback = playback; | 36 fPlayback = playback; |
37 fSaveLayerDepth = saveLayerDepth; | 37 fSaveLayerDepth = saveLayerDepth; |
38 fInfo.fValid = true; | 38 fInfo.fValid = true; |
39 fInfo.fSize.set(width, height); | 39 fInfo.fSize.set(width, height); |
40 fInfo.fPaint = NULL; | 40 fInfo.fPaint = NULL; |
41 fInfo.fSaveLayerOpID = fPlayback->curOpID(); | 41 fInfo.fSaveLayerOpID = fPlayback->curOpID(); |
42 fInfo.fRestoreOpID = 0; | 42 fInfo.fRestoreOpID = 0; |
43 fInfo.fHasNestedLayers = false; | 43 fInfo.fHasNestedLayers = false; |
44 fInfo.fIsNested = (2 == fSaveLayerDepth); | 44 fInfo.fIsNested = (2 == fSaveLayerDepth); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 return false; | 164 return false; |
165 } | 165 } |
166 | 166 |
167 private: | 167 private: |
168 // The playback object driving this rendering | 168 // The playback object driving this rendering |
169 SkPicturePlayback *fPlayback; | 169 SkPicturePlayback *fPlayback; |
170 | 170 |
171 SkBitmap fEmptyBitmap; // legacy -- need to remove | 171 SkBitmap fEmptyBitmap; // legacy -- need to remove |
172 | 172 |
173 // All information gathered during the gather process is stored here | 173 // All information gathered during the gather process is stored here |
174 GPUAccelData* fAccelData; | 174 GrAccelData* fAccelData; |
175 | 175 |
176 // true if this device has already been drawn back to its parent(s) at least | 176 // true if this device has already been drawn back to its parent(s) at least |
177 // once. | 177 // once. |
178 bool fAlreadyDrawn; | 178 bool fAlreadyDrawn; |
179 | 179 |
180 // The information regarding the saveLayer call this device represents. | 180 // The information regarding the saveLayer call this device represents. |
181 GPUAccelData::SaveLayerInfo fInfo; | 181 GrAccelData::SaveLayerInfo fInfo; |
182 | 182 |
183 // The depth of this device in the saveLayer stack | 183 // The depth of this device in the saveLayer stack |
184 int fSaveLayerDepth; | 184 int fSaveLayerDepth; |
185 | 185 |
186 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRI
DE { | 186 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRI
DE { |
187 NotSupported(); | 187 NotSupported(); |
188 } | 188 } |
189 | 189 |
190 virtual SkBaseDevice* onCreateDevice(const SkImageInfo& info, Usage usage) S
K_OVERRIDE { | 190 virtual SkBaseDevice* onCreateDevice(const SkImageInfo& info, Usage usage) S
K_OVERRIDE { |
191 // we expect to only get called via savelayer, in which case it is fine. | 191 // we expect to only get called via savelayer, in which case it is fine. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 picture->draw(this); | 252 picture->draw(this); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 private: | 256 private: |
257 typedef SkCanvas INHERITED; | 257 typedef SkCanvas INHERITED; |
258 }; | 258 }; |
259 | 259 |
260 // GatherGPUInfo is only intended to be called within the context of SkGpuDevice
's | 260 // GatherGPUInfo is only intended to be called within the context of SkGpuDevice
's |
261 // EXPERIMENTAL_optimize method. | 261 // EXPERIMENTAL_optimize method. |
262 void GatherGPUInfo(const SkPicture* pict, GPUAccelData* accelData) { | 262 void GatherGPUInfo(const SkPicture* pict, GrAccelData* accelData) { |
263 if (NULL == pict || 0 == pict->width() || 0 == pict->height()) { | 263 if (NULL == pict || 0 == pict->width() || 0 == pict->height()) { |
264 return ; | 264 return ; |
265 } | 265 } |
266 | 266 |
267 // BBH-based rendering doesn't re-issue many of the operations the gather | 267 // BBH-based rendering doesn't re-issue many of the operations the gather |
268 // process cares about (e.g., saves and restores) so it must be disabled. | 268 // process cares about (e.g., saves and restores) so it must be disabled. |
269 SkPicturePlayback playback(pict); | 269 SkPicturePlayback playback(pict); |
270 playback.setUseBBH(false); | 270 playback.setUseBBH(false); |
271 | 271 |
272 GrGatherDevice device(pict->width(), pict->height(), &playback, accelData, 0
); | 272 GrGatherDevice device(pict->width(), pict->height(), &playback, accelData, 0
); |
273 GrGatherCanvas canvas(&device); | 273 GrGatherCanvas canvas(&device); |
274 | 274 |
275 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(pict->width()), | 275 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(pict->width()), |
276 SkIntToScalar(pict->height())), | 276 SkIntToScalar(pict->height())), |
277 SkRegion::kIntersect_Op, false); | 277 SkRegion::kIntersect_Op, false); |
278 playback.draw(&canvas, NULL); | 278 playback.draw(&canvas, NULL); |
279 } | 279 } |
OLD | NEW |