OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 SkDeferredCanvas_DEFINED | 8 #ifndef SkDeferredCanvas_DEFINED |
9 #define SkDeferredCanvas_DEFINED | 9 #define SkDeferredCanvas_DEFINED |
10 | 10 |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkPixelRef.h" | 12 #include "SkPixelRef.h" |
13 | 13 |
14 class DeferredDevice; | 14 class DeferredDevice; |
15 class SkImage; | 15 class SkImage; |
16 class SkSurface; | 16 class SkSurface; |
17 | 17 |
| 18 #if !defined(SK_DEFERRED_CANVAS_USES_FACTORIES) |
| 19 // This is temporary, for rolling the API change into Chromium/Blink |
| 20 #define SK_DEFERRED_CANVAS_USES_FACTORIES 0 |
| 21 #endif |
| 22 |
18 /** \class SkDeferredCanvas | 23 /** \class SkDeferredCanvas |
19 Subclass of SkCanvas that encapsulates an SkPicture or SkGPipe for deferred | 24 Subclass of SkCanvas that encapsulates an SkPicture or SkGPipe for deferred |
20 drawing. The main difference between this class and SkPictureRecord (the | 25 drawing. The main difference between this class and SkPictureRecord (the |
21 canvas provided by SkPicture) is that this is a full drop-in replacement | 26 canvas provided by SkPicture) is that this is a full drop-in replacement |
22 for SkCanvas, while SkPictureRecord only supports draw operations. | 27 for SkCanvas, while SkPictureRecord only supports draw operations. |
23 SkDeferredCanvas will transparently trigger the flushing of deferred | 28 SkDeferredCanvas will transparently trigger the flushing of deferred |
24 draw operations when an attempt is made to access the pixel data. | 29 draw operations when an attempt is made to access the pixel data. |
25 */ | 30 */ |
26 class SK_API SkDeferredCanvas : public SkCanvas { | 31 class SK_API SkDeferredCanvas : public SkCanvas { |
27 public: | 32 public: |
28 class NotificationClient; | 33 class NotificationClient; |
29 | 34 |
| 35 /** Construct a canvas with the specified surface to draw into. |
| 36 This factory must be used for newImageSnapshot to work. |
| 37 @param surface Specifies a surface for the canvas to draw into. |
| 38 */ |
| 39 static SkDeferredCanvas* Create(SkSurface* surface); |
| 40 |
| 41 #ifdef SK_DEVELOPER |
| 42 static SkDeferredCanvas* Create(SkDevice* device); // Used for testing |
| 43 #endif |
| 44 |
| 45 #if !SK_DEFERRED_CANVAS_USES_FACTORIES |
| 46 /** DEPRECATED |
| 47 */ |
30 SkDeferredCanvas(); | 48 SkDeferredCanvas(); |
31 | 49 |
32 /** Construct a canvas with the specified device to draw into. | 50 /** DEPRACATED, use create instead |
| 51 Construct a canvas with the specified device to draw into. |
33 Equivalent to calling default constructor, then setDevice. | 52 Equivalent to calling default constructor, then setDevice. |
34 @param device Specifies a device for the canvas to draw into. | 53 @param device Specifies a device for the canvas to draw into. |
35 */ | 54 */ |
36 explicit SkDeferredCanvas(SkDevice* device); | 55 explicit SkDeferredCanvas(SkDevice* device); |
37 | 56 |
38 /** Construct a canvas with the specified surface to draw into. | 57 /** DEPRECATED, use create instead |
| 58 Construct a canvas with the specified surface to draw into. |
39 This constructor must be used for newImageSnapshot to work. | 59 This constructor must be used for newImageSnapshot to work. |
40 @param surface Specifies a surface for the canvas to draw into. | 60 @param surface Specifies a surface for the canvas to draw into. |
41 */ | 61 */ |
42 explicit SkDeferredCanvas(SkSurface* surface); | 62 explicit SkDeferredCanvas(SkSurface* surface); |
| 63 #endif |
43 | 64 |
44 virtual ~SkDeferredCanvas(); | 65 virtual ~SkDeferredCanvas(); |
45 | 66 |
46 /** | 67 /** DEPRECATED |
47 * Specify a device to be used by this canvas. Calling setDevice will | 68 * Specify a device to be used by this canvas. Calling setDevice will |
48 * release the previously set device, if any. Takes a reference on the | 69 * release the previously set device, if any. Takes a reference on the |
49 * device. | 70 * device. |
50 * | 71 * |
51 * @param device The device that the canvas will raw into | 72 * @param device The device that the canvas will raw into |
52 * @return The device argument, for convenience. | 73 * @return The device argument, for convenience. |
53 */ | 74 */ |
54 virtual SkDevice* setDevice(SkDevice* device); | 75 virtual SkDevice* setDevice(SkDevice* device); |
55 | 76 |
56 /** | 77 /** |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 * or completely overwritten by the command currently being recorded. | 268 * or completely overwritten by the command currently being recorded. |
248 */ | 269 */ |
249 virtual void skippedPendingDrawCommands() {} | 270 virtual void skippedPendingDrawCommands() {} |
250 }; | 271 }; |
251 | 272 |
252 protected: | 273 protected: |
253 virtual SkCanvas* canvasForDrawIter(); | 274 virtual SkCanvas* canvasForDrawIter(); |
254 DeferredDevice* getDeferredDevice() const; | 275 DeferredDevice* getDeferredDevice() const; |
255 | 276 |
256 private: | 277 private: |
| 278 SkDeferredCanvas(DeferredDevice*); |
| 279 |
257 void recordedDrawCommand(); | 280 void recordedDrawCommand(); |
258 SkCanvas* drawingCanvas() const; | 281 SkCanvas* drawingCanvas() const; |
259 SkCanvas* immediateCanvas() const; | 282 SkCanvas* immediateCanvas() const; |
260 bool isFullFrame(const SkRect*, const SkPaint*) const; | 283 bool isFullFrame(const SkRect*, const SkPaint*) const; |
261 void validate() const; | 284 void validate() const; |
262 void init(); | 285 void init(); |
263 bool fDeferredDrawing; | 286 bool fDeferredDrawing; |
264 | 287 |
265 friend class SkDeferredCanvasTester; // for unit testing | 288 friend class SkDeferredCanvasTester; // for unit testing |
266 typedef SkCanvas INHERITED; | 289 typedef SkCanvas INHERITED; |
267 }; | 290 }; |
268 | 291 |
269 | 292 |
270 #endif | 293 #endif |
OLD | NEW |