OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 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 SkPixelRef_DEFINED | 8 #ifndef SkPixelRef_DEFINED |
9 #define SkPixelRef_DEFINED | 9 #define SkPixelRef_DEFINED |
10 | 10 |
11 #include "SkAtomics.h" | 11 #include "SkAtomics.h" |
12 #include "SkBitmap.h" | 12 #include "SkBitmap.h" |
| 13 #include "SkFilterQuality.h" |
13 #include "SkImageInfo.h" | 14 #include "SkImageInfo.h" |
14 #include "SkMutex.h" | 15 #include "SkMutex.h" |
| 16 #include "SkPixmap.h" |
15 #include "SkRefCnt.h" | 17 #include "SkRefCnt.h" |
16 #include "SkSize.h" | 18 #include "SkSize.h" |
17 #include "SkString.h" | 19 #include "SkString.h" |
18 #include "SkTDArray.h" | 20 #include "SkTDArray.h" |
19 | 21 |
20 //#define xed | |
21 | |
22 #ifdef SK_DEBUG | 22 #ifdef SK_DEBUG |
23 /** | 23 /** |
24 * Defining SK_IGNORE_PIXELREF_SETPRELOCKED will force all pixelref | 24 * Defining SK_IGNORE_PIXELREF_SETPRELOCKED will force all pixelref |
25 * subclasses to correctly handle lock/unlock pixels. For performance | 25 * subclasses to correctly handle lock/unlock pixels. For performance |
26 * reasons, simple malloc-based subclasses call setPreLocked() to skip | 26 * reasons, simple malloc-based subclasses call setPreLocked() to skip |
27 * the overhead of implementing these calls. | 27 * the overhead of implementing these calls. |
28 * | 28 * |
29 * This build-flag disables that optimization, to add in debugging our | 29 * This build-flag disables that optimization, to add in debugging our |
30 * call-sites, to ensure that they correctly balance their calls of | 30 * call-sites, to ensure that they correctly balance their calls of |
31 * lock and unlock. | 31 * lock and unlock. |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 * return a ref to its data. If the pixelRef | 186 * return a ref to its data. If the pixelRef |
187 * is uncompressed or otherwise does not have this form, return NULL. | 187 * is uncompressed or otherwise does not have this form, return NULL. |
188 * | 188 * |
189 * If non-null is returned, the caller is responsible for calling unref() | 189 * If non-null is returned, the caller is responsible for calling unref() |
190 * on the data when it is finished. | 190 * on the data when it is finished. |
191 */ | 191 */ |
192 SkData* refEncodedData() { | 192 SkData* refEncodedData() { |
193 return this->onRefEncodedData(); | 193 return this->onRefEncodedData(); |
194 } | 194 } |
195 | 195 |
| 196 struct LockRequest { |
| 197 SkISize fSize; |
| 198 SkFilterQuality fQuality; |
| 199 }; |
| 200 |
| 201 struct LockResult { |
| 202 void (*fUnlockProc)(void* ctx); |
| 203 void* fUnlockContext; |
| 204 |
| 205 SkColorTable* fCTable; // should be NULL unless colortype is kIndex8 |
| 206 const void* fPixels; |
| 207 size_t fRowBytes; |
| 208 SkISize fSize; |
| 209 |
| 210 void unlock() { |
| 211 if (fUnlockProc) { |
| 212 fUnlockProc(fUnlockContext); |
| 213 fUnlockProc = NULL; // can't unlock twice! |
| 214 } |
| 215 } |
| 216 }; |
| 217 |
| 218 bool requestLock(const LockRequest&, LockResult*); |
| 219 |
196 /** Are we really wrapping a texture instead of a bitmap? | 220 /** Are we really wrapping a texture instead of a bitmap? |
197 */ | 221 */ |
198 virtual GrTexture* getTexture() { return NULL; } | 222 virtual GrTexture* getTexture() { return NULL; } |
199 | 223 |
200 /** | 224 /** |
201 * If any planes or rowBytes is NULL, this should output the sizes and retu
rn true | 225 * If any planes or rowBytes is NULL, this should output the sizes and retu
rn true |
202 * if it can efficiently return YUV planar data. If it cannot, it should re
turn false. | 226 * if it can efficiently return YUV planar data. If it cannot, it should re
turn false. |
203 * | 227 * |
204 * If all planes and rowBytes are not NULL, then it should copy the associa
ted Y,U,V data | 228 * If all planes and rowBytes are not NULL, then it should copy the associa
ted Y,U,V data |
205 * into those planes of memory supplied by the caller. It should validate t
hat the sizes | 229 * into those planes of memory supplied by the caller. It should validate t
hat the sizes |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 /** | 316 /** |
293 * Returns the size (in bytes) of the internally allocated memory. | 317 * Returns the size (in bytes) of the internally allocated memory. |
294 * This should be implemented in all serializable SkPixelRef derived classe
s. | 318 * This should be implemented in all serializable SkPixelRef derived classe
s. |
295 * SkBitmap::fPixelRefOffset + SkBitmap::getSafeSize() should never overflo
w this value, | 319 * SkBitmap::fPixelRefOffset + SkBitmap::getSafeSize() should never overflo
w this value, |
296 * otherwise the rendering code may attempt to read memory out of bounds. | 320 * otherwise the rendering code may attempt to read memory out of bounds. |
297 * | 321 * |
298 * @return default impl returns 0. | 322 * @return default impl returns 0. |
299 */ | 323 */ |
300 virtual size_t getAllocatedSizeInBytes() const; | 324 virtual size_t getAllocatedSizeInBytes() const; |
301 | 325 |
| 326 virtual bool onRequestLock(const LockRequest&, LockResult*); |
| 327 |
302 /** Return the mutex associated with this pixelref. This value is assigned | 328 /** Return the mutex associated with this pixelref. This value is assigned |
303 in the constructor, and cannot change during the lifetime of the object. | 329 in the constructor, and cannot change during the lifetime of the object. |
304 */ | 330 */ |
305 SkBaseMutex* mutex() const { return fMutex; } | 331 SkBaseMutex* mutex() const { return fMutex; } |
306 | 332 |
307 // only call from constructor. Flags this to always be locked, removing | 333 // only call from constructor. Flags this to always be locked, removing |
308 // the need to grab the mutex and call onLockPixels/onUnlockPixels. | 334 // the need to grab the mutex and call onLockPixels/onUnlockPixels. |
309 // Performance tweak to avoid those calls (esp. in multi-thread use case). | 335 // Performance tweak to avoid those calls (esp. in multi-thread use case). |
310 void setPreLocked(void*, size_t rowBytes, SkColorTable*); | 336 void setPreLocked(void*, size_t rowBytes, SkColorTable*); |
311 | 337 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 /** | 382 /** |
357 * Allocate a new pixelref matching the specified ImageInfo, allocating | 383 * Allocate a new pixelref matching the specified ImageInfo, allocating |
358 * the memory for the pixels. If the ImageInfo requires a ColorTable, | 384 * the memory for the pixels. If the ImageInfo requires a ColorTable, |
359 * the pixelref will ref() the colortable. | 385 * the pixelref will ref() the colortable. |
360 * On failure return NULL. | 386 * On failure return NULL. |
361 */ | 387 */ |
362 virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable
*) = 0; | 388 virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable
*) = 0; |
363 }; | 389 }; |
364 | 390 |
365 #endif | 391 #endif |
OLD | NEW |