Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | Friends | List of all members
SkPixelRef Class Reference

#include <SkPixelRef.h>

Inheritance diagram for SkPixelRef:
SkRefCnt SkRefCntBase

Public Member Functions

 SkPixelRef (int width, int height, void *addr, size_t rowBytes)
 
 ~SkPixelRef () override
 
SkISize dimensions () const
 
int width () const
 
int height () const
 
void * pixels () const
 
size_t rowBytes () const
 
uint32_t getGenerationID () const
 
void notifyPixelsChanged ()
 
bool isImmutable () const
 
void setImmutable ()
 
void addGenIDChangeListener (sk_sp< SkIDChangeListener > listener)
 
void notifyAddedToCache ()
 
virtual SkDiscardableMemorydiagnostic_only_getDiscardable () const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Member Functions

void android_only_reset (int width, int height, size_t rowBytes)
 

Friends

class SkSurface_Raster
 
void SkBitmapCache_setImmutableWithID (SkPixelRef *, uint32_t)
 

Detailed Description

This class is the smart container for pixel memory, and is used with SkBitmap. This class can be shared/accessed between multiple threads.

Definition at line 28 of file SkPixelRef.h.

Constructor & Destructor Documentation

◆ SkPixelRef()

SkPixelRef::SkPixelRef ( int  width,
int  height,
void *  addr,
size_t  rowBytes 
)

Definition at line 32 of file SkPixelRef.cpp.

33 : fWidth(width)
34 , fHeight(height)
35 , fPixels(pixels)
36 , fRowBytes(rowBytes)
37 , fAddedToCache(false)
38{
39 this->needsNewGenID();
40 fMutability = kMutable;
41}
void * pixels() const
Definition: SkPixelRef.h:36
int width() const
Definition: SkPixelRef.h:34
int height() const
Definition: SkPixelRef.h:35
size_t rowBytes() const
Definition: SkPixelRef.h:37

◆ ~SkPixelRef()

SkPixelRef::~SkPixelRef ( )
override

Definition at line 43 of file SkPixelRef.cpp.

43 {
44 this->callGenIDChangeListeners();
45}

Member Function Documentation

◆ addGenIDChangeListener()

void SkPixelRef::addGenIDChangeListener ( sk_sp< SkIDChangeListener listener)

Definition at line 78 of file SkPixelRef.cpp.

78 {
79 if (!listener || !this->genIDIsUnique()) {
80 // No point in tracking this if we're not going to call it.
81 return;
82 }
83 SkASSERT(!listener->shouldDeregister());
84 fGenIDChangeListeners.add(std::move(listener));
85}
#define SkASSERT(cond)
Definition: SkAssert.h:116
void add(sk_sp< SkIDChangeListener > listener) SK_EXCLUDES(fMutex)

◆ android_only_reset()

void SkPixelRef::android_only_reset ( int  width,
int  height,
size_t  rowBytes 
)
protected

Definition at line 48 of file SkPixelRef.cpp.

48 {
49 fWidth = width;
50 fHeight = height;
51 fRowBytes = rowBytes;
52 // note: we do not change fPixels
53
54 // conservative, since its possible the "new" settings are the same as the old.
55 this->notifyPixelsChanged();
56}
void notifyPixelsChanged()
Definition: SkPixelRef.cpp:102

◆ diagnostic_only_getDiscardable()

virtual SkDiscardableMemory * SkPixelRef::diagnostic_only_getDiscardable ( ) const
inlinevirtual

Definition at line 80 of file SkPixelRef.h.

80{ return nullptr; }

◆ dimensions()

SkISize SkPixelRef::dimensions ( ) const
inline

Definition at line 33 of file SkPixelRef.h.

33{ return {fWidth, fHeight}; }

◆ getGenerationID()

uint32_t SkPixelRef::getGenerationID ( ) const

Returns a non-zero, unique value corresponding to the pixels in this pixelref. Each time the pixels are changed (and notifyPixelsChanged is called), a different generation ID will be returned.

Definition at line 63 of file SkPixelRef.cpp.

63 {
64 uint32_t id = fTaggedGenID.load();
65 if (0 == id) {
66 uint32_t next = SkNextID::ImageID() | 1u;
67 if (fTaggedGenID.compare_exchange_strong(id, next)) {
68 id = next; // There was no race or we won the race. fTaggedGenID is next now.
69 } else {
70 // We lost a race to set fTaggedGenID. compare_exchange() filled id with the winner.
71 }
72 // We can't quite SkASSERT(this->genIDIsUnique()). It could be non-unique
73 // if we got here via the else path (pretty unlikely, but possible).
74 }
75 return id & ~1u; // Mask off bottom unique bit.
76}
static float next(float f)
static uint32_t ImageID()
Definition: SkPixelRef.cpp:19

◆ height()

int SkPixelRef::height ( ) const
inline

Definition at line 35 of file SkPixelRef.h.

35{ return fHeight; }

◆ isImmutable()

bool SkPixelRef::isImmutable ( ) const
inline

Returns true if this pixelref is marked as immutable, meaning that the contents of its pixels will not change for the lifetime of the pixelref.

Definition at line 55 of file SkPixelRef.h.

55{ return fMutability != kMutable; }

◆ notifyAddedToCache()

void SkPixelRef::notifyAddedToCache ( )
inline

Definition at line 76 of file SkPixelRef.h.

76 {
77 fAddedToCache.store(true);
78 }

◆ notifyPixelsChanged()

void SkPixelRef::notifyPixelsChanged ( )

Call this if you have changed the contents of the pixels. This will in- turn cause a different generation ID value to be returned from getGenerationID().

Definition at line 102 of file SkPixelRef.cpp.

102 {
103#ifdef SK_DEBUG
104 if (this->isImmutable()) {
105 SkDebugf("========== notifyPixelsChanged called on immutable pixelref");
106 }
107#endif
108 this->callGenIDChangeListeners();
109 this->needsNewGenID();
110}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
bool isImmutable() const
Definition: SkPixelRef.h:55

◆ pixels()

void * SkPixelRef::pixels ( ) const
inline

Definition at line 36 of file SkPixelRef.h.

36{ return fPixels; }

◆ rowBytes()

size_t SkPixelRef::rowBytes ( ) const
inline

Definition at line 37 of file SkPixelRef.h.

37{ return fRowBytes; }

◆ setImmutable()

void SkPixelRef::setImmutable ( )

Marks this pixelref is immutable, meaning that the contents of its pixels will not change for the lifetime of the pixelref. This state can be set on a pixelref, but it cannot be cleared once it is set.

Definition at line 112 of file SkPixelRef.cpp.

112 {
113 fMutability = kImmutable;
114}

◆ width()

int SkPixelRef::width ( ) const
inline

Definition at line 34 of file SkPixelRef.h.

34{ return fWidth; }

Friends And Related Function Documentation

◆ SkBitmapCache_setImmutableWithID

void SkBitmapCache_setImmutableWithID ( SkPixelRef pr,
uint32_t  id 
)
friend

Definition at line 70 of file SkBitmapCache.cpp.

70 {
71 pr->setImmutableWithID(id);
72}

◆ SkSurface_Raster

friend class SkSurface_Raster
friend

Definition at line 111 of file SkPixelRef.h.


The documentation for this class was generated from the following files: