| 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 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * reasons, simple malloc-based subclasses call setPreLocked() to skip | 24 * reasons, simple malloc-based subclasses call setPreLocked() to skip |
| 25 * the overhead of implementing these calls. | 25 * the overhead of implementing these calls. |
| 26 * | 26 * |
| 27 * This build-flag disables that optimization, to add in debugging our | 27 * This build-flag disables that optimization, to add in debugging our |
| 28 * call-sites, to ensure that they correctly balance their calls of | 28 * call-sites, to ensure that they correctly balance their calls of |
| 29 * lock and unlock. | 29 * lock and unlock. |
| 30 */ | 30 */ |
| 31 // #define SK_IGNORE_PIXELREF_SETPRELOCKED | 31 // #define SK_IGNORE_PIXELREF_SETPRELOCKED |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 #ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE |
| 35 // we only support unflattening, not flattening |
| 36 #define SK_PIXELREF_BASECLASS SkFlattenable |
| 37 #else |
| 38 #define SK_PIXELREF_BASECLASS SkRefCnt |
| 39 #endif |
| 40 |
| 34 class SkColorTable; | 41 class SkColorTable; |
| 35 class SkData; | 42 class SkData; |
| 36 struct SkIRect; | 43 struct SkIRect; |
| 37 class SkMutex; | 44 class SkMutex; |
| 38 | 45 |
| 39 class GrTexture; | 46 class GrTexture; |
| 40 | 47 |
| 41 /** \class SkPixelRef | 48 /** \class SkPixelRef |
| 42 | 49 |
| 43 This class is the smart container for pixel memory, and is used with | 50 This class is the smart container for pixel memory, and is used with |
| 44 SkBitmap. A pixelref is installed into a bitmap, and then the bitmap can | 51 SkBitmap. A pixelref is installed into a bitmap, and then the bitmap can |
| 45 access the actual pixel memory by calling lockPixels/unlockPixels. | 52 access the actual pixel memory by calling lockPixels/unlockPixels. |
| 46 | 53 |
| 47 This class can be shared/accessed between multiple threads. | 54 This class can be shared/accessed between multiple threads. |
| 48 */ | 55 */ |
| 49 class SK_API SkPixelRef : public SkFlattenable { | 56 class SK_API SkPixelRef : public SK_PIXELREF_BASECLASS { |
| 50 public: | 57 public: |
| 51 SK_DECLARE_INST_COUNT(SkPixelRef) | 58 SK_DECLARE_INST_COUNT(SkPixelRef) |
| 52 | 59 |
| 53 explicit SkPixelRef(const SkImageInfo&); | 60 explicit SkPixelRef(const SkImageInfo&); |
| 54 SkPixelRef(const SkImageInfo&, SkBaseMutex* mutex); | 61 SkPixelRef(const SkImageInfo&, SkBaseMutex* mutex); |
| 55 virtual ~SkPixelRef(); | 62 virtual ~SkPixelRef(); |
| 56 | 63 |
| 57 const SkImageInfo& info() const { | 64 const SkImageInfo& info() const { |
| 58 return fInfo; | 65 return fInfo; |
| 59 } | 66 } |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 virtual void globalRef(void* data=NULL); | 250 virtual void globalRef(void* data=NULL); |
| 244 | 251 |
| 245 /** | 252 /** |
| 246 * Release a "global" ref on this object. | 253 * Release a "global" ref on this object. |
| 247 * The default implementation just calls unref(), but subclasses can overri
de | 254 * The default implementation just calls unref(), but subclasses can overri
de |
| 248 * this method to implement additional behavior. | 255 * this method to implement additional behavior. |
| 249 */ | 256 */ |
| 250 virtual void globalUnref(); | 257 virtual void globalUnref(); |
| 251 #endif | 258 #endif |
| 252 | 259 |
| 260 #ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE |
| 253 SK_DEFINE_FLATTENABLE_TYPE(SkPixelRef) | 261 SK_DEFINE_FLATTENABLE_TYPE(SkPixelRef) |
| 262 #endif |
| 254 | 263 |
| 255 // Register a listener that may be called the next time our generation ID ch
anges. | 264 // Register a listener that may be called the next time our generation ID ch
anges. |
| 256 // | 265 // |
| 257 // We'll only call the listener if we're confident that we are the only SkPi
xelRef with this | 266 // We'll only call the listener if we're confident that we are the only SkPi
xelRef with this |
| 258 // generation ID. If our generation ID changes and we decide not to call th
e listener, we'll | 267 // generation ID. If our generation ID changes and we decide not to call th
e listener, we'll |
| 259 // never call it: you must add a new listener for each generation ID change.
We also won't call | 268 // never call it: you must add a new listener for each generation ID change.
We also won't call |
| 260 // the listener when we're certain no one knows what our generation ID is. | 269 // the listener when we're certain no one knows what our generation ID is. |
| 261 // | 270 // |
| 262 // This can be used to invalidate caches keyed by SkPixelRef generation ID. | 271 // This can be used to invalidate caches keyed by SkPixelRef generation ID. |
| 263 struct GenIDChangeListener { | 272 struct GenIDChangeListener { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 */ | 326 */ |
| 318 virtual size_t getAllocatedSizeInBytes() const; | 327 virtual size_t getAllocatedSizeInBytes() const; |
| 319 | 328 |
| 320 /** Return the mutex associated with this pixelref. This value is assigned | 329 /** Return the mutex associated with this pixelref. This value is assigned |
| 321 in the constructor, and cannot change during the lifetime of the object. | 330 in the constructor, and cannot change during the lifetime of the object. |
| 322 */ | 331 */ |
| 323 SkBaseMutex* mutex() const { return fMutex; } | 332 SkBaseMutex* mutex() const { return fMutex; } |
| 324 | 333 |
| 325 // serialization | 334 // serialization |
| 326 SkPixelRef(SkReadBuffer&, SkBaseMutex*); | 335 SkPixelRef(SkReadBuffer&, SkBaseMutex*); |
| 327 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | |
| 328 | 336 |
| 329 // only call from constructor. Flags this to always be locked, removing | 337 // only call from constructor. Flags this to always be locked, removing |
| 330 // the need to grab the mutex and call onLockPixels/onUnlockPixels. | 338 // the need to grab the mutex and call onLockPixels/onUnlockPixels. |
| 331 // Performance tweak to avoid those calls (esp. in multi-thread use case). | 339 // Performance tweak to avoid those calls (esp. in multi-thread use case). |
| 332 void setPreLocked(void*, size_t rowBytes, SkColorTable*); | 340 void setPreLocked(void*, size_t rowBytes, SkColorTable*); |
| 333 | 341 |
| 334 private: | 342 private: |
| 335 SkBaseMutex* fMutex; // must remain in scope for the life of this object | 343 SkBaseMutex* fMutex; // must remain in scope for the life of this object |
| 336 | 344 |
| 337 // mostly const. fInfo.fAlpahType can be changed at runtime. | 345 // mostly const. fInfo.fAlpahType can be changed at runtime. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 356 void needsNewGenID(); | 364 void needsNewGenID(); |
| 357 void callGenIDChangeListeners(); | 365 void callGenIDChangeListeners(); |
| 358 | 366 |
| 359 void setMutex(SkBaseMutex* mutex); | 367 void setMutex(SkBaseMutex* mutex); |
| 360 | 368 |
| 361 // When copying a bitmap to another with the same shape and config, we can s
afely | 369 // When copying a bitmap to another with the same shape and config, we can s
afely |
| 362 // clone the pixelref generation ID too, which makes them equivalent under c
aching. | 370 // clone the pixelref generation ID too, which makes them equivalent under c
aching. |
| 363 friend class SkBitmap; // only for cloneGenID | 371 friend class SkBitmap; // only for cloneGenID |
| 364 void cloneGenID(const SkPixelRef&); | 372 void cloneGenID(const SkPixelRef&); |
| 365 | 373 |
| 366 typedef SkFlattenable INHERITED; | 374 #ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE |
| 375 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE { sk_throw(); } |
| 376 #endif |
| 377 |
| 378 typedef SK_PIXELREF_BASECLASS INHERITED; |
| 367 }; | 379 }; |
| 368 | 380 |
| 369 class SkPixelRefFactory : public SkRefCnt { | 381 class SkPixelRefFactory : public SkRefCnt { |
| 370 public: | 382 public: |
| 371 /** | 383 /** |
| 372 * Allocate a new pixelref matching the specified ImageInfo, allocating | 384 * Allocate a new pixelref matching the specified ImageInfo, allocating |
| 373 * the memory for the pixels. If the ImageInfo requires a ColorTable, | 385 * the memory for the pixels. If the ImageInfo requires a ColorTable, |
| 374 * the pixelref will ref() the colortable. | 386 * the pixelref will ref() the colortable. |
| 375 * On failure return NULL. | 387 * On failure return NULL. |
| 376 */ | 388 */ |
| 377 virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable
*) = 0; | 389 virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable
*) = 0; |
| 378 }; | 390 }; |
| 379 | 391 |
| 380 #endif | 392 #endif |
| OLD | NEW |