8 #ifndef SkPixelRef_DEFINED
9 #define SkPixelRef_DEFINED
11 #include "../private/SkAtomics.h"
12 #include "../private/SkMutex.h"
13 #include "../private/SkTDArray.h"
15 #include "SkFilterQuality.h"
16 #include "SkImageInfo.h"
21 #include "SkYUVSizeInfo.h"
28 class SkDiscardableMemory;
50 void*
pixels()
const {
return fRec.fPixels; }
56 size_t rowBytes()
const {
return fRec.fRowBytes; }
63 LockRec() : fPixels(NULL), fColorTable(NULL) {}
69 void zero() { sk_bzero(
this,
sizeof(*
this)); }
72 return NULL == fPixels && NULL == fColorTable && 0 == fRowBytes;
76 SkDEBUGCODE(
bool isLocked()
const {
return fLockCount > 0; })
77 SkDEBUGCODE(
int getLockCount()
const {
return fLockCount; })
90 bool lockPixels(LockRec* rec);
105 bool lockPixelsAreWritable()
const;
111 uint32_t getGenerationID()
const;
113 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
122 uint32_t getStableID()
const {
return fStableID; }
130 void notifyPixelsChanged();
137 void changeAlphaType(SkAlphaType at);
153 const char*
getURI()
const {
return fURI.size() ? fURI.c_str() : NULL; }
163 void setURI(
const char uri[],
size_t len) {
180 return this->onRefEncodedData();
185 SkFilterQuality fQuality;
189 LockResult() : fPixels(NULL), fCTable(NULL) {}
191 void (*fUnlockProc)(
void* ctx);
192 void* fUnlockContext;
201 fUnlockProc(fUnlockContext);
218 return this->onQueryYUV8(sizeInfo, colorSpace);
231 return this->onGetYUV8Planes(sizeInfo, planes);
235 bool readPixels(
SkBitmap* dst, SkColorType colorType,
const SkIRect* subset = NULL);
247 virtual void onChange() = 0;
255 void notifyAddedToCache() {
256 fAddedToCache.store(
true);
259 virtual SkDiscardableMemory* diagnostic_only_getDiscardable()
const {
return NULL; }
274 virtual bool onNewLockPixels(LockRec*) = 0;
284 virtual void onUnlockPixels() = 0;
287 virtual bool onLockPixelsAreWritable()
const;
295 virtual bool onReadPixels(
SkBitmap* dst, SkColorType colorType,
const SkIRect* subsetOrNull);
298 virtual SkData* onRefEncodedData();
301 virtual void onNotifyPixelsChanged();
303 virtual bool onQueryYUV8(
SkYUVSizeInfo*, SkYUVColorSpace*)
const {
306 virtual bool onGetYUV8Planes(
const SkYUVSizeInfo&,
void*[3] ) {
318 virtual size_t getAllocatedSizeInBytes()
const;
320 virtual bool onRequestLock(
const LockRequest&, LockResult*);
322 virtual bool onIsLazyGenerated()
const {
return false; }
327 SkBaseMutex*
mutex()
const {
return &fMutex; }
332 void setPreLocked(
void*,
size_t rowBytes,
SkColorTable*);
335 mutable SkMutex fMutex;
344 bool lockPixelsInsideMutex();
347 bool genIDIsUnique()
const {
return SkToBool(fTaggedGenID.load() & 1); }
348 mutable SkAtomic<uint32_t> fTaggedGenID;
350 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
351 const uint32_t fStableID;
354 SkTDArray<GenIDChangeListener*> fGenIDChangeListeners;
359 SkAtomic<bool> fAddedToCache;
363 kTemporarilyImmutable,
370 void needsNewGenID();
371 void callGenIDChangeListeners();
373 void setTemporarilyImmutable();
374 void restoreMutability();
375 friend class SkSurface_Raster;
377 bool isPreLocked()
const {
return fPreLocked; }
378 friend class SkImage_Raster;
379 friend class SkSpecialImage_Raster;
386 void setImmutableWithID(uint32_t genID);
387 friend class SkImage_Gpu;
388 friend class SkImageCacherator;
389 friend class SkSpecialImage_Gpu;
Definition: SkPixelRef.h:183
void setURI(const char uri[], size_t len)
Copy a URI string to this pixelref.
Definition: SkPixelRef.h:163
Describe an image's dimensions and pixel type.
Definition: SkImageInfo.h:181
virtual SkPixelRef * create(const SkImageInfo &, size_t rowBytes, SkColorTable *)=0
Allocate a new pixelref matching the specified ImageInfo, allocating the memory for the pixels...
SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by 8-bit bitmaps...
Definition: SkColorTable.h:25
SkColorTable * colorTable() const
Return the current colorTable (if any) if pixels are locked, or null.
Definition: SkPixelRef.h:54
bool isLazyGenerated() const
Returns true if the pixels are generated on-the-fly (when required).
Definition: SkPixelRef.h:264
Definition: SkRefCnt.h:135
void setURI(const char uri[])
Copy a URI string to this pixelref, or clear the URI if the uri is null.
Definition: SkPixelRef.h:157
SkBaseMutex * mutex() const
Return the mutex associated with this pixelref.
Definition: SkPixelRef.h:327
SkData holds an immutable data buffer.
Definition: SkData.h:22
#define SkToBool(cond)
Returns 0 or 1 based on the condition.
Definition: SkTypes.h:287
bool queryYUV8(SkYUVSizeInfo *sizeInfo, SkYUVColorSpace *colorSpace) const
If this can efficiently return YUV data, this should return true.
Definition: SkPixelRef.h:217
void * pixels() const
Return the pixel memory returned from lockPixels, or null if the lockCount is 0.
Definition: SkPixelRef.h:50
The SkBitmap class specifies a raster bitmap.
Definition: SkBitmap.h:41
Definition: SkYUVSizeInfo.h:11
This class is the smart container for pixel memory, and is used with SkBitmap.
Definition: SkPixelRef.h:38
Definition: SkPixelRef.h:245
To access the actual pixels of a pixelref, it must be "locked".
Definition: SkPixelRef.h:62
bool isImmutable() const
Returns true if this pixelref is marked as immutable, meaning that the contents of its pixels will no...
Definition: SkPixelRef.h:142
void setURI(const SkString &uri)
Assign a URI string to this pixelref.
Definition: SkPixelRef.h:169
const char * getURI() const
Return the optional URI string associated with this pixelref.
Definition: SkPixelRef.h:153
Definition: SkPixelRef.h:394
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
Definition: SkPixelRef.h:188
Definition: GrTexture.h:19
SkData * refEncodedData()
If the pixelRef has an encoded (i.e.
Definition: SkPixelRef.h:179
Light weight class for managing strings.
Definition: SkString.h:121
bool getYUV8Planes(const SkYUVSizeInfo &sizeInfo, void *planes[3])
Returns true on success and false on failure.
Definition: SkPixelRef.h:230