Skia
2DGraphicsLibrary
|
This class is the smart container for pixel memory, and is used with SkBitmap. More...
#include <SkPixelRef.h>
Classes | |
struct | GenIDChangeListener |
struct | LockRec |
To access the actual pixels of a pixelref, it must be "locked". More... | |
struct | LockRequest |
struct | LockResult |
Public Member Functions | |
SkPixelRef (const SkImageInfo &) | |
const SkImageInfo & | info () const |
void * | pixels () const |
Return the pixel memory returned from lockPixels, or null if the lockCount is 0. | |
SkColorTable * | colorTable () const |
Return the current colorTable (if any) if pixels are locked, or null. | |
size_t | rowBytes () const |
bool | isLocked () const |
int | getLockCount () const |
bool | lockPixels () |
Call to access the pixel memory. More... | |
bool | lockPixels (LockRec *rec) |
Call to access the pixel memory. More... | |
void | unlockPixels () |
Call to balanace a previous call to lockPixels(). More... | |
bool | lockPixelsAreWritable () const |
Some bitmaps can return a copy of their pixels for lockPixels(), but that copy, if modified, will not be pushed back. More... | |
uint32_t | getGenerationID () const |
Returns a non-zero, unique value corresponding to the pixels in this pixelref. More... | |
void | notifyPixelsChanged () |
Call this if you have changed the contents of the pixels. More... | |
void | changeAlphaType (SkAlphaType at) |
Change the info's AlphaType. More... | |
bool | isImmutable () const |
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. | |
void | setImmutable () |
Marks this pixelref is immutable, meaning that the contents of its pixels will not change for the lifetime of the pixelref. More... | |
const char * | getURI () const |
Return the optional URI string associated with this pixelref. More... | |
void | setURI (const char uri[]) |
Copy a URI string to this pixelref, or clear the URI if the uri is null. | |
void | setURI (const char uri[], size_t len) |
Copy a URI string to this pixelref. | |
void | setURI (const SkString &uri) |
Assign a URI string to this pixelref. | |
SkData * | refEncodedData () |
If the pixelRef has an encoded (i.e. More... | |
bool | requestLock (const LockRequest &, LockResult *) |
bool | queryYUV8 (SkYUVSizeInfo *sizeInfo, SkYUVColorSpace *colorSpace) const |
If this can efficiently return YUV data, this should return true. More... | |
bool | getYUV8Planes (const SkYUVSizeInfo &sizeInfo, void *planes[3]) |
Returns true on success and false on failure. More... | |
bool | readPixels (SkBitmap *dst, SkColorType colorType, const SkIRect *subset=NULL) |
Populates dst with the pixels of this pixelRef, converting them to colorType. More... | |
void | addGenIDChangeListener (GenIDChangeListener *listener) |
void | notifyAddedToCache () |
virtual SkDiscardableMemory * | diagnostic_only_getDiscardable () const |
bool | isLazyGenerated () const |
Returns true if the pixels are generated on-the-fly (when required). | |
Public Member Functions inherited from SkRefCntBase | |
SkRefCntBase () | |
Default construct, initializing the reference count to 1. | |
virtual | ~SkRefCntBase () |
Destruct, asserting that the reference count is 1. | |
int32_t | getRefCnt () const |
Return the reference count. More... | |
void | validate () const |
bool | unique () const |
May return true if the caller is the only owner. More... | |
void | ref () const |
Increment the reference count. More... | |
void | unref () const |
Decrement the reference count. More... | |
Protected Member Functions | |
virtual bool | onNewLockPixels (LockRec *)=0 |
On success, returns true and fills out the LockRec for the pixels. More... | |
virtual void | onUnlockPixels ()=0 |
Balancing the previous successful call to onNewLockPixels. More... | |
virtual bool | onLockPixelsAreWritable () const |
Default impl returns true. | |
virtual bool | onReadPixels (SkBitmap *dst, SkColorType colorType, const SkIRect *subsetOrNull) |
For pixelrefs that don't have access to their raw pixels, they may be able to make a copy of them (e.g. More... | |
virtual SkData * | onRefEncodedData () |
virtual void | onNotifyPixelsChanged () |
virtual bool | onQueryYUV8 (SkYUVSizeInfo *, SkYUVColorSpace *) const |
virtual bool | onGetYUV8Planes (const SkYUVSizeInfo &, void *[3]) |
virtual size_t | getAllocatedSizeInBytes () const |
Returns the size (in bytes) of the internally allocated memory. More... | |
virtual bool | onRequestLock (const LockRequest &, LockResult *) |
virtual bool | onIsLazyGenerated () const |
SkBaseMutex * | mutex () const |
Return the mutex associated with this pixelref. More... | |
void | setPreLocked (void *, size_t rowBytes, SkColorTable *) |
Protected Member Functions inherited from SkRefCntBase | |
void | internal_dispose_restore_refcnt_to_1 () const |
Allow subclasses to call this if they've overridden internal_dispose so they can reset fRefCnt before the destructor is called or if they choose not to call the destructor (e.g. More... | |
Private Types | |
enum | { kMutable, kTemporarilyImmutable, kImmutable } |
typedef SkRefCnt | INHERITED |
Private Member Functions | |
bool | lockPixelsInsideMutex () |
bool | genIDIsUnique () const |
void | needsNewGenID () |
void | callGenIDChangeListeners () |
void | setTemporarilyImmutable () |
void | restoreMutability () |
bool | isPreLocked () const |
void | cloneGenID (const SkPixelRef &) |
void | setImmutableWithID (uint32_t genID) |
Private Attributes | |
SkMutex | fMutex |
const SkImageInfo | fInfo |
LockRec | fRec |
int | fLockCount |
SkAtomic< uint32_t > | fTaggedGenID |
SkTDArray< GenIDChangeListener * > | fGenIDChangeListeners |
SkString | fURI |
SkAtomic< bool > | fAddedToCache |
enum SkPixelRef:: { ... } | fMutability |
bool | fPreLocked |
Friends | |
class | SkSurface_Raster |
class | SkImage_Raster |
class | SkSpecialImage_Raster |
class | SkBitmap |
class | SkImage_Gpu |
class | SkImageCacherator |
class | SkSpecialImage_Gpu |
This class is the smart container for pixel memory, and is used with SkBitmap.
A pixelref is installed into a bitmap, and then the bitmap can access the actual pixel memory by calling lockPixels/unlockPixels.
This class can be shared/accessed between multiple threads.
void SkPixelRef::changeAlphaType | ( | SkAlphaType | at | ) |
Change the info's AlphaType.
Note that this does not automatically invalidate the generation ID. If the pixel values themselves have changed, then you must explicitly call notifyPixelsChanged() as well.
|
protectedvirtual |
Returns the size (in bytes) of the internally allocated memory.
This should be implemented in all serializable SkPixelRef derived classes. SkBitmap::fPixelRefOffset + SkBitmap::getSafeSize() should never overflow this value, otherwise the rendering code may attempt to read memory out of bounds.
Reimplemented in SkMallocPixelRef.
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.
|
inline |
Return the optional URI string associated with this pixelref.
May be null.
|
inline |
Returns true on success and false on failure.
Copies YUV data into the provided YUV planes.
sizeInfo | Needs to exactly match the values returned by the query, except the WidthBytes may be larger than the recommendation (but not smaller). |
planes | Memory for each of the Y, U, and V planes. |
bool SkPixelRef::lockPixels | ( | ) |
Call to access the pixel memory.
Return true on success. Balance this with a call to unlockPixels().
bool SkPixelRef::lockPixels | ( | LockRec * | rec | ) |
Call to access the pixel memory.
On success, return true and fill out the specified rec. On failure, return false and ignore the rec parameter. Balance this with a call to unlockPixels().
bool SkPixelRef::lockPixelsAreWritable | ( | ) | const |
Some bitmaps can return a copy of their pixels for lockPixels(), but that copy, if modified, will not be pushed back.
These bitmaps should not be used as targets for a raster device/canvas (since all pixels modifications will be lost when unlockPixels() is called.)
|
inlineprotected |
Return the mutex associated with this pixelref.
This value is assigned in the constructor, and cannot change during the lifetime of the object.
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().
|
protectedpure virtual |
On success, returns true and fills out the LockRec for the pixels.
On failure returns false and ignores the LockRec parameter.
The caller will have already acquired a mutex for thread safety, so this method need not do that.
Implemented in SkMallocPixelRef.
|
protectedvirtual |
For pixelrefs that don't have access to their raw pixels, they may be able to make a copy of them (e.g.
if the pixels are on the GPU).
The base class implementation returns false;
|
protectedpure virtual |
Balancing the previous successful call to onNewLockPixels.
The locked pixel address will no longer be referenced, so the subclass is free to move or discard that memory.
The caller will have already acquired a mutex for thread safety, so this method need not do that.
Implemented in SkMallocPixelRef.
|
inline |
If this can efficiently return YUV data, this should return true.
Otherwise this returns false and does not modify any of the parameters.
sizeInfo | Output parameter indicating the sizes and required allocation widths of the Y, U, and V planes. |
colorSpace | Output parameter. |
bool SkPixelRef::readPixels | ( | SkBitmap * | dst, |
SkColorType | colorType, | ||
const SkIRect * | subset = NULL |
||
) |
Populates dst with the pixels of this pixelRef, converting them to colorType.
|
inline |
If the pixelRef has an encoded (i.e.
compressed) representation, return a ref to its data. If the pixelRef is uncompressed or otherwise does not have this form, return NULL.
If non-null is returned, the caller is responsible for calling unref() on the data when it is finished.
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.
void SkPixelRef::unlockPixels | ( | ) |
Call to balanace a previous call to lockPixels().
Returns the pixels (or null) after the unlock. NOTE: lock calls can be nested, but the matching number of unlock calls must be made in order to free the memory (if the subclass implements caching/deferred-decoding.)