| 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; |
| 16 class SkSurface; |
| 15 | 17 |
| 16 /** \class SkDeferredCanvas | 18 /** \class SkDeferredCanvas |
| 17 Subclass of SkCanvas that encapsulates an SkPicture or SkGPipe for deferred | 19 Subclass of SkCanvas that encapsulates an SkPicture or SkGPipe for deferred |
| 18 drawing. The main difference between this class and SkPictureRecord (the | 20 drawing. The main difference between this class and SkPictureRecord (the |
| 19 canvas provided by SkPicture) is that this is a full drop-in replacement | 21 canvas provided by SkPicture) is that this is a full drop-in replacement |
| 20 for SkCanvas, while SkPictureRecord only supports draw operations. | 22 for SkCanvas, while SkPictureRecord only supports draw operations. |
| 21 SkDeferredCanvas will transparently trigger the flushing of deferred | 23 SkDeferredCanvas will transparently trigger the flushing of deferred |
| 22 draw operations when an attempt is made to access the pixel data. | 24 draw operations when an attempt is made to access the pixel data. |
| 23 */ | 25 */ |
| 24 class SK_API SkDeferredCanvas : public SkCanvas { | 26 class SK_API SkDeferredCanvas : public SkCanvas { |
| 25 public: | 27 public: |
| 26 class NotificationClient; | 28 class NotificationClient; |
| 27 | 29 |
| 28 SkDeferredCanvas(); | 30 SkDeferredCanvas(); |
| 29 | 31 |
| 30 /** Construct a canvas with the specified device to draw into. | 32 /** Construct a canvas with the specified device to draw into. |
| 31 Equivalent to calling default constructor, then setDevice. | 33 Equivalent to calling default constructor, then setDevice. |
| 32 @param device Specifies a device for the canvas to draw into. | 34 @param device Specifies a device for the canvas to draw into. |
| 33 */ | 35 */ |
| 34 explicit SkDeferredCanvas(SkDevice* device); | 36 explicit SkDeferredCanvas(SkDevice* device); |
| 35 | 37 |
| 38 /** Construct a canvas with the specified surface to draw into. |
| 39 This constructor must be used for newImageSnapshot to work. |
| 40 @param surface Specifies a surface for the canvas to draw into. |
| 41 */ |
| 42 explicit SkDeferredCanvas(SkSurface* surface); |
| 43 |
| 36 virtual ~SkDeferredCanvas(); | 44 virtual ~SkDeferredCanvas(); |
| 37 | 45 |
| 38 /** | 46 /** |
| 39 * Specify a device to be used by this canvas. Calling setDevice will | 47 * Specify a device to be used by this canvas. Calling setDevice will |
| 40 * release the previously set device, if any. Takes a reference on the | 48 * release the previously set device, if any. Takes a reference on the |
| 41 * device. | 49 * device. |
| 42 * | 50 * |
| 43 * @param device The device that the canvas will raw into | 51 * @param device The device that the canvas will raw into |
| 44 * @return The device argument, for convenience. | 52 * @return The device argument, for convenience. |
| 45 */ | 53 */ |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 */ | 94 */ |
| 87 bool isFreshFrame() const; | 95 bool isFreshFrame() const; |
| 88 | 96 |
| 89 /** | 97 /** |
| 90 * Returns true if the canvas has recorded draw commands that have | 98 * Returns true if the canvas has recorded draw commands that have |
| 91 * not yet been played back. | 99 * not yet been played back. |
| 92 */ | 100 */ |
| 93 bool hasPendingCommands() const; | 101 bool hasPendingCommands() const; |
| 94 | 102 |
| 95 /** | 103 /** |
| 104 * Flushes pending draw commands, if any, and returns an image of the |
| 105 * current state of the surface pixels up to this point. Subsequent |
| 106 * changes to the surface (by drawing into its canvas) will not be |
| 107 * reflected in this image. Will return NULL if the deferred canvas |
| 108 * was not constructed from an SkSurface. |
| 109 */ |
| 110 SkImage* newImageShapshot(); |
| 111 |
| 112 /** |
| 96 * Specify the maximum number of bytes to be allocated for the purpose | 113 * Specify the maximum number of bytes to be allocated for the purpose |
| 97 * of recording draw commands to this canvas. The default limit, is | 114 * of recording draw commands to this canvas. The default limit, is |
| 98 * 64MB. | 115 * 64MB. |
| 99 * @param maxStorage The maximum number of bytes to be allocated. | 116 * @param maxStorage The maximum number of bytes to be allocated. |
| 100 */ | 117 */ |
| 101 void setMaxRecordingStorage(size_t maxStorage); | 118 void setMaxRecordingStorage(size_t maxStorage); |
| 102 | 119 |
| 103 /** | 120 /** |
| 104 * Returns the number of bytes currently allocated for the purpose of | 121 * Returns the number of bytes currently allocated for the purpose of |
| 105 * recording draw commands. | 122 * recording draw commands. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 void validate() const; | 251 void validate() const; |
| 235 void init(); | 252 void init(); |
| 236 bool fDeferredDrawing; | 253 bool fDeferredDrawing; |
| 237 | 254 |
| 238 friend class SkDeferredCanvasTester; // for unit testing | 255 friend class SkDeferredCanvasTester; // for unit testing |
| 239 typedef SkCanvas INHERITED; | 256 typedef SkCanvas INHERITED; |
| 240 }; | 257 }; |
| 241 | 258 |
| 242 | 259 |
| 243 #endif | 260 #endif |
| OLD | NEW |