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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 This class is the smart container for pixel memory, and is used with | 30 This class is the smart container for pixel memory, and is used with |
31 SkBitmap. A pixelref is installed into a bitmap, and then the bitmap can | 31 SkBitmap. A pixelref is installed into a bitmap, and then the bitmap can |
32 access the actual pixel memory by calling lockPixels/unlockPixels. | 32 access the actual pixel memory by calling lockPixels/unlockPixels. |
33 | 33 |
34 This class can be shared/accessed between multiple threads. | 34 This class can be shared/accessed between multiple threads. |
35 */ | 35 */ |
36 class SK_API SkPixelRef : public SkRefCnt { | 36 class SK_API SkPixelRef : public SkRefCnt { |
37 public: | 37 public: |
38 explicit SkPixelRef(const SkImageInfo&); | 38 explicit SkPixelRef(const SkImageInfo&); |
39 SkPixelRef(const SkImageInfo&, SkBaseMutex* mutex); | |
40 virtual ~SkPixelRef(); | 39 virtual ~SkPixelRef(); |
41 | 40 |
42 const SkImageInfo& info() const { | 41 const SkImageInfo& info() const { |
43 return fInfo; | 42 return fInfo; |
44 } | 43 } |
45 | 44 |
46 /** Return the pixel memory returned from lockPixels, or null if the | 45 /** Return the pixel memory returned from lockPixels, or null if the |
47 lockCount is 0. | 46 lockCount is 0. |
48 */ | 47 */ |
49 void* pixels() const { return fRec.fPixels; } | 48 void* pixels() const { return fRec.fPixels; } |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 * | 311 * |
313 * @return default impl returns 0. | 312 * @return default impl returns 0. |
314 */ | 313 */ |
315 virtual size_t getAllocatedSizeInBytes() const; | 314 virtual size_t getAllocatedSizeInBytes() const; |
316 | 315 |
317 virtual bool onRequestLock(const LockRequest&, LockResult*); | 316 virtual bool onRequestLock(const LockRequest&, LockResult*); |
318 | 317 |
319 /** Return the mutex associated with this pixelref. This value is assigned | 318 /** Return the mutex associated with this pixelref. This value is assigned |
320 in the constructor, and cannot change during the lifetime of the object. | 319 in the constructor, and cannot change during the lifetime of the object. |
321 */ | 320 */ |
322 SkBaseMutex* mutex() const { return fMutex; } | 321 SkBaseMutex* mutex() const { return &fMutex; } |
323 | 322 |
324 // only call from constructor. Flags this to always be locked, removing | 323 // only call from constructor. Flags this to always be locked, removing |
325 // the need to grab the mutex and call onLockPixels/onUnlockPixels. | 324 // the need to grab the mutex and call onLockPixels/onUnlockPixels. |
326 // Performance tweak to avoid those calls (esp. in multi-thread use case). | 325 // Performance tweak to avoid those calls (esp. in multi-thread use case). |
327 void setPreLocked(void*, size_t rowBytes, SkColorTable*); | 326 void setPreLocked(void*, size_t rowBytes, SkColorTable*); |
328 | 327 |
329 private: | 328 private: |
330 SkBaseMutex* fMutex; // must remain in scope for the life of this object | 329 mutable SkMutex fMutex; |
331 | 330 |
332 // mostly const. fInfo.fAlpahType can be changed at runtime. | 331 // mostly const. fInfo.fAlpahType can be changed at runtime. |
333 const SkImageInfo fInfo; | 332 const SkImageInfo fInfo; |
334 | 333 |
335 // LockRec is only valid if we're in a locked state (isLocked()) | 334 // LockRec is only valid if we're in a locked state (isLocked()) |
336 LockRec fRec; | 335 LockRec fRec; |
337 int fLockCount; | 336 int fLockCount; |
338 | 337 |
339 bool lockPixelsInsideMutex(); | 338 bool lockPixelsInsideMutex(); |
340 | 339 |
(...skipping 17 matching lines...) Expand all Loading... |
358 kTemporarilyImmutable, // Considered immutable, but can revert to mutab
le. | 357 kTemporarilyImmutable, // Considered immutable, but can revert to mutab
le. |
359 kImmutable, // Once set to this state, it never leaves. | 358 kImmutable, // Once set to this state, it never leaves. |
360 } fMutability : 8; // easily fits inside a byte | 359 } fMutability : 8; // easily fits inside a byte |
361 | 360 |
362 // only ever set in constructor, const after that | 361 // only ever set in constructor, const after that |
363 bool fPreLocked; | 362 bool fPreLocked; |
364 | 363 |
365 void needsNewGenID(); | 364 void needsNewGenID(); |
366 void callGenIDChangeListeners(); | 365 void callGenIDChangeListeners(); |
367 | 366 |
368 void setMutex(SkBaseMutex* mutex); | |
369 | |
370 void setTemporarilyImmutable(); | 367 void setTemporarilyImmutable(); |
371 void restoreMutability(); | 368 void restoreMutability(); |
372 friend class SkSurface_Raster; // For the two methods above. | 369 friend class SkSurface_Raster; // For the two methods above. |
373 | 370 |
374 bool isPreLocked() const { return fPreLocked; } | 371 bool isPreLocked() const { return fPreLocked; } |
375 friend class SkImage_Raster; | 372 friend class SkImage_Raster; |
376 | 373 |
377 // When copying a bitmap to another with the same shape and config, we can s
afely | 374 // When copying a bitmap to another with the same shape and config, we can s
afely |
378 // clone the pixelref generation ID too, which makes them equivalent under c
aching. | 375 // clone the pixelref generation ID too, which makes them equivalent under c
aching. |
379 friend class SkBitmap; // only for cloneGenID | 376 friend class SkBitmap; // only for cloneGenID |
(...skipping 10 matching lines...) Expand all Loading... |
390 /** | 387 /** |
391 * Allocate a new pixelref matching the specified ImageInfo, allocating | 388 * Allocate a new pixelref matching the specified ImageInfo, allocating |
392 * the memory for the pixels. If the ImageInfo requires a ColorTable, | 389 * the memory for the pixels. If the ImageInfo requires a ColorTable, |
393 * the pixelref will ref() the colortable. | 390 * the pixelref will ref() the colortable. |
394 * On failure return NULL. | 391 * On failure return NULL. |
395 */ | 392 */ |
396 virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable
*) = 0; | 393 virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable
*) = 0; |
397 }; | 394 }; |
398 | 395 |
399 #endif | 396 #endif |
OLD | NEW |