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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 /** | 145 /** |
146 * Change the info's AlphaType. Note that this does not automatically | 146 * Change the info's AlphaType. Note that this does not automatically |
147 * invalidate the generation ID. If the pixel values themselves have | 147 * invalidate the generation ID. If the pixel values themselves have |
148 * changed, then you must explicitly call notifyPixelsChanged() as well. | 148 * changed, then you must explicitly call notifyPixelsChanged() as well. |
149 */ | 149 */ |
150 void changeAlphaType(SkAlphaType at); | 150 void changeAlphaType(SkAlphaType at); |
151 | 151 |
152 /** Returns true if this pixelref is marked as immutable, meaning that the | 152 /** Returns true if this pixelref is marked as immutable, meaning that the |
153 contents of its pixels will not change for the lifetime of the pixelref. | 153 contents of its pixels will not change for the lifetime of the pixelref. |
154 */ | 154 */ |
155 bool isImmutable() const { return fIsImmutable; } | 155 bool isImmutable() const { return fMutability != kMutable; } |
156 | 156 |
157 /** Marks this pixelref is immutable, meaning that the contents of its | 157 /** Marks this pixelref is immutable, meaning that the contents of its |
158 pixels will not change for the lifetime of the pixelref. This state can | 158 pixels will not change for the lifetime of the pixelref. This state can |
159 be set on a pixelref, but it cannot be cleared once it is set. | 159 be set on a pixelref, but it cannot be cleared once it is set. |
160 */ | 160 */ |
161 void setImmutable(); | 161 void setImmutable(); |
162 | 162 |
163 /** Return the optional URI string associated with this pixelref. May be | 163 /** Return the optional URI string associated with this pixelref. May be |
164 null. | 164 null. |
165 */ | 165 */ |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 359 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
360 const uint32_t fStableID; | 360 const uint32_t fStableID; |
361 #endif | 361 #endif |
362 | 362 |
363 SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owne
d | 363 SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owne
d |
364 | 364 |
365 SkString fURI; | 365 SkString fURI; |
366 | 366 |
367 // Set true by caches when they cache content that's derived from the curren
t pixels. | 367 // Set true by caches when they cache content that's derived from the curren
t pixels. |
368 SkAtomic<bool> fAddedToCache; | 368 SkAtomic<bool> fAddedToCache; |
369 // can go from false to true, but never from true to false | 369 |
370 bool fIsImmutable; | 370 enum { |
| 371 kMutable, // PixelRefs begin mutable. |
| 372 kTemporarilyImmutable, // Considered immutable, but can revert to mutab
le. |
| 373 kImmutable, // Once set to this state, it never leaves. |
| 374 } fMutability : 8; // easily fits inside a byte |
| 375 |
371 // only ever set in constructor, const after that | 376 // only ever set in constructor, const after that |
372 bool fPreLocked; | 377 bool fPreLocked; |
373 | 378 |
374 void needsNewGenID(); | 379 void needsNewGenID(); |
375 void callGenIDChangeListeners(); | 380 void callGenIDChangeListeners(); |
376 | 381 |
377 void setMutex(SkBaseMutex* mutex); | 382 void setMutex(SkBaseMutex* mutex); |
378 | 383 |
| 384 void setTemporarilyImmutable(); |
| 385 void restoreMutability(); |
| 386 friend class SkSurface_Raster; // For the two methods above. |
| 387 |
379 // When copying a bitmap to another with the same shape and config, we can s
afely | 388 // When copying a bitmap to another with the same shape and config, we can s
afely |
380 // clone the pixelref generation ID too, which makes them equivalent under c
aching. | 389 // clone the pixelref generation ID too, which makes them equivalent under c
aching. |
381 friend class SkBitmap; // only for cloneGenID | 390 friend class SkBitmap; // only for cloneGenID |
382 void cloneGenID(const SkPixelRef&); | 391 void cloneGenID(const SkPixelRef&); |
383 | 392 |
384 typedef SkRefCnt INHERITED; | 393 typedef SkRefCnt INHERITED; |
385 }; | 394 }; |
386 | 395 |
387 class SkPixelRefFactory : public SkRefCnt { | 396 class SkPixelRefFactory : public SkRefCnt { |
388 public: | 397 public: |
389 /** | 398 /** |
390 * Allocate a new pixelref matching the specified ImageInfo, allocating | 399 * Allocate a new pixelref matching the specified ImageInfo, allocating |
391 * the memory for the pixels. If the ImageInfo requires a ColorTable, | 400 * the memory for the pixels. If the ImageInfo requires a ColorTable, |
392 * the pixelref will ref() the colortable. | 401 * the pixelref will ref() the colortable. |
393 * On failure return NULL. | 402 * On failure return NULL. |
394 */ | 403 */ |
395 virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable
*) = 0; | 404 virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable
*) = 0; |
396 }; | 405 }; |
397 | 406 |
398 #endif | 407 #endif |
OLD | NEW |