OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Android Open Source Project | 2 * Copyright 2010 The Android Open Source Project |
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 SkDevice_DEFINED | 8 #ifndef SkDevice_DEFINED |
9 #define SkDevice_DEFINED | 9 #define SkDevice_DEFINED |
10 | 10 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 const SkIPoint& getOrigin() const { return fOrigin; } | 97 const SkIPoint& getOrigin() const { return fOrigin; } |
98 | 98 |
99 /** | 99 /** |
100 * onAttachToCanvas is invoked whenever a device is installed in a canvas | 100 * onAttachToCanvas is invoked whenever a device is installed in a canvas |
101 * (i.e., setDevice, saveLayer (for the new device created by the save), | 101 * (i.e., setDevice, saveLayer (for the new device created by the save), |
102 * and SkCanvas' SkBaseDevice & SkBitmap -taking ctors). It allows the | 102 * and SkCanvas' SkBaseDevice & SkBitmap -taking ctors). It allows the |
103 * devices to prepare for drawing (e.g., locking their pixels, etc.) | 103 * devices to prepare for drawing (e.g., locking their pixels, etc.) |
104 */ | 104 */ |
105 virtual void onAttachToCanvas(SkCanvas*) { | 105 virtual void onAttachToCanvas(SkCanvas*) { |
106 SkASSERT(!fAttachedToCanvas); | 106 SkASSERT(!fAttachedToCanvas); |
107 this->lockPixels(); | |
108 #ifdef SK_DEBUG | 107 #ifdef SK_DEBUG |
109 fAttachedToCanvas = true; | 108 fAttachedToCanvas = true; |
110 #endif | 109 #endif |
111 }; | 110 }; |
112 | 111 |
113 /** | 112 /** |
114 * onDetachFromCanvas notifies a device that it will no longer be drawn to. | 113 * onDetachFromCanvas notifies a device that it will no longer be drawn to. |
115 * It gives the device a chance to clean up (e.g., unlock its pixels). It | 114 * It gives the device a chance to clean up (e.g., unlock its pixels). It |
116 * is invoked from setDevice (for the displaced device), restore and | 115 * is invoked from setDevice (for the displaced device), restore and |
117 * possibly from SkCanvas' dtor. | 116 * possibly from SkCanvas' dtor. |
118 */ | 117 */ |
119 virtual void onDetachFromCanvas() { | 118 virtual void onDetachFromCanvas() { |
120 SkASSERT(fAttachedToCanvas); | 119 SkASSERT(fAttachedToCanvas); |
121 this->unlockPixels(); | |
122 #ifdef SK_DEBUG | 120 #ifdef SK_DEBUG |
123 fAttachedToCanvas = false; | 121 fAttachedToCanvas = false; |
124 #endif | 122 #endif |
125 }; | 123 }; |
126 | 124 |
127 protected: | 125 protected: |
128 enum TileUsage { | 126 enum TileUsage { |
129 kPossible_TileUsage, //!< the created device may be drawn tiled | 127 kPossible_TileUsage, //!< the created device may be drawn tiled |
130 kNever_TileUsage, //!< the created device will never be drawn tile
d | 128 kNever_TileUsage, //!< the created device will never be drawn tile
d |
131 }; | 129 }; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 bool readPixels(const SkImageInfo&, void* dst, size_t rowBytes, int x, int y
); | 242 bool readPixels(const SkImageInfo&, void* dst, size_t rowBytes, int x, int y
); |
245 | 243 |
246 /////////////////////////////////////////////////////////////////////////// | 244 /////////////////////////////////////////////////////////////////////////// |
247 | 245 |
248 /** Update as needed the pixel value in the bitmap, so that the caller can | 246 /** Update as needed the pixel value in the bitmap, so that the caller can |
249 access the pixels directly. | 247 access the pixels directly. |
250 @return The device contents as a bitmap | 248 @return The device contents as a bitmap |
251 */ | 249 */ |
252 virtual const SkBitmap& onAccessBitmap() = 0; | 250 virtual const SkBitmap& onAccessBitmap() = 0; |
253 | 251 |
254 /** Called when this device is installed into a Canvas. Balanced by a call | |
255 to unlockPixels() when the device is removed from a Canvas. | |
256 */ | |
257 virtual void lockPixels() {} | |
258 virtual void unlockPixels() {} | |
259 | |
260 /** | 252 /** |
261 * Override and return true for filters that the device can handle | 253 * Override and return true for filters that the device can handle |
262 * intrinsically. Doing so means that SkCanvas will pass-through this | 254 * intrinsically. Doing so means that SkCanvas will pass-through this |
263 * filter to drawSprite and drawDevice (and potentially filterImage). | 255 * filter to drawSprite and drawDevice (and potentially filterImage). |
264 * Returning false means the SkCanvas will have apply the filter itself, | 256 * Returning false means the SkCanvas will have apply the filter itself, |
265 * and just pass the resulting image to the device. | 257 * and just pass the resulting image to the device. |
266 */ | 258 */ |
267 virtual bool canHandleImageFilter(const SkImageFilter*) { return false; } | 259 virtual bool canHandleImageFilter(const SkImageFilter*) { return false; } |
268 | 260 |
269 /** | 261 /** |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 SkDeviceProperties* fLeakyProperties; // will always exist. | 392 SkDeviceProperties* fLeakyProperties; // will always exist. |
401 | 393 |
402 #ifdef SK_DEBUG | 394 #ifdef SK_DEBUG |
403 bool fAttachedToCanvas; | 395 bool fAttachedToCanvas; |
404 #endif | 396 #endif |
405 | 397 |
406 typedef SkRefCnt INHERITED; | 398 typedef SkRefCnt INHERITED; |
407 }; | 399 }; |
408 | 400 |
409 #endif | 401 #endif |
OLD | NEW |