| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef SkPixelRef_DEFINED | 10 #ifndef SkPixelRef_DEFINED |
| 11 #define SkPixelRef_DEFINED | 11 #define SkPixelRef_DEFINED |
| 12 | 12 |
| 13 #include "SkBitmap.h" | 13 #include "SkBitmap.h" |
| 14 #include "SkRefCnt.h" | 14 #include "SkRefCnt.h" |
| 15 #include "SkString.h" | 15 #include "SkString.h" |
| 16 #include "SkFlattenable.h" | 16 #include "SkFlattenable.h" |
| 17 #include "SkTDArray.h" | 17 #include "SkTDArray.h" |
| 18 | 18 |
| 19 //#define SK_SUPPORT_LEGACY_PIXELREF_CONSTRUCTOR | |
| 20 | |
| 21 #ifdef SK_DEBUG | 19 #ifdef SK_DEBUG |
| 22 /** | 20 /** |
| 23 * Defining SK_IGNORE_PIXELREF_SETPRELOCKED will force all pixelref | 21 * Defining SK_IGNORE_PIXELREF_SETPRELOCKED will force all pixelref |
| 24 * subclasses to correctly handle lock/unlock pixels. For performance | 22 * subclasses to correctly handle lock/unlock pixels. For performance |
| 25 * reasons, simple malloc-based subclasses call setPreLocked() to skip | 23 * reasons, simple malloc-based subclasses call setPreLocked() to skip |
| 26 * the overhead of implementing these calls. | 24 * the overhead of implementing these calls. |
| 27 * | 25 * |
| 28 * This build-flag disables that optimization, to add in debugging our | 26 * This build-flag disables that optimization, to add in debugging our |
| 29 * call-sites, to ensure that they correctly balance their calls of | 27 * call-sites, to ensure that they correctly balance their calls of |
| 30 * lock and unlock. | 28 * lock and unlock. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 This class is the smart container for pixel memory, and is used with | 42 This class is the smart container for pixel memory, and is used with |
| 45 SkBitmap. A pixelref is installed into a bitmap, and then the bitmap can | 43 SkBitmap. A pixelref is installed into a bitmap, and then the bitmap can |
| 46 access the actual pixel memory by calling lockPixels/unlockPixels. | 44 access the actual pixel memory by calling lockPixels/unlockPixels. |
| 47 | 45 |
| 48 This class can be shared/accessed between multiple threads. | 46 This class can be shared/accessed between multiple threads. |
| 49 */ | 47 */ |
| 50 class SK_API SkPixelRef : public SkFlattenable { | 48 class SK_API SkPixelRef : public SkFlattenable { |
| 51 public: | 49 public: |
| 52 SK_DECLARE_INST_COUNT(SkPixelRef) | 50 SK_DECLARE_INST_COUNT(SkPixelRef) |
| 53 | 51 |
| 54 #ifdef SK_SUPPORT_LEGACY_PIXELREF_CONSTRUCTOR | |
| 55 // DEPRECATED -- use a constructor that takes SkImageInfo | |
| 56 explicit SkPixelRef(SkBaseMutex* mutex = NULL); | |
| 57 #endif | |
| 58 | |
| 59 explicit SkPixelRef(const SkImageInfo&); | 52 explicit SkPixelRef(const SkImageInfo&); |
| 60 SkPixelRef(const SkImageInfo&, SkBaseMutex* mutex); | 53 SkPixelRef(const SkImageInfo&, SkBaseMutex* mutex); |
| 61 virtual ~SkPixelRef(); | 54 virtual ~SkPixelRef(); |
| 62 | 55 |
| 63 const SkImageInfo& info() const { | 56 const SkImageInfo& info() const { |
| 64 return fInfo; | 57 return fInfo; |
| 65 } | 58 } |
| 66 | 59 |
| 67 /** Return the pixel memory returned from lockPixels, or null if the | 60 /** Return the pixel memory returned from lockPixels, or null if the |
| 68 lockCount is 0. | 61 lockCount is 0. |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 SkPixelRef(SkFlattenableReadBuffer&, SkBaseMutex*); | 286 SkPixelRef(SkFlattenableReadBuffer&, SkBaseMutex*); |
| 294 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; | 287 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; |
| 295 | 288 |
| 296 // only call from constructor. Flags this to always be locked, removing | 289 // only call from constructor. Flags this to always be locked, removing |
| 297 // the need to grab the mutex and call onLockPixels/onUnlockPixels. | 290 // the need to grab the mutex and call onLockPixels/onUnlockPixels. |
| 298 // Performance tweak to avoid those calls (esp. in multi-thread use case). | 291 // Performance tweak to avoid those calls (esp. in multi-thread use case). |
| 299 void setPreLocked(void* pixels, SkColorTable* ctable); | 292 void setPreLocked(void* pixels, SkColorTable* ctable); |
| 300 | 293 |
| 301 private: | 294 private: |
| 302 SkBaseMutex* fMutex; // must remain in scope for the life of this object | 295 SkBaseMutex* fMutex; // must remain in scope for the life of this object |
| 303 // FIXME: fInfo should be const once we remove old constructor that does | 296 |
| 304 // not set it. | 297 const SkImageInfo fInfo; |
| 305 SkImageInfo fInfo; | |
| 306 | 298 |
| 307 void* fPixels; | 299 void* fPixels; |
| 308 SkColorTable* fColorTable; // we do not track ownership, subclass does | 300 SkColorTable* fColorTable; // we do not track ownership, subclass does |
| 309 int fLockCount; | 301 int fLockCount; |
| 310 | 302 |
| 311 mutable uint32_t fGenerationID; | 303 mutable uint32_t fGenerationID; |
| 312 mutable bool fUniqueGenerationID; | 304 mutable bool fUniqueGenerationID; |
| 313 | 305 |
| 314 SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owne
d | 306 SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owne
d |
| 315 | 307 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 327 | 319 |
| 328 // When copying a bitmap to another with the same shape and config, we can s
afely | 320 // When copying a bitmap to another with the same shape and config, we can s
afely |
| 329 // clone the pixelref generation ID too, which makes them equivalent under c
aching. | 321 // clone the pixelref generation ID too, which makes them equivalent under c
aching. |
| 330 friend class SkBitmap; // only for cloneGenID | 322 friend class SkBitmap; // only for cloneGenID |
| 331 void cloneGenID(const SkPixelRef&); | 323 void cloneGenID(const SkPixelRef&); |
| 332 | 324 |
| 333 typedef SkFlattenable INHERITED; | 325 typedef SkFlattenable INHERITED; |
| 334 }; | 326 }; |
| 335 | 327 |
| 336 #endif | 328 #endif |
| OLD | NEW |