2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2008 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkPixelRef_DEFINED
|
|
|
|
#define SkPixelRef_DEFINED
|
|
|
|
|
2015-09-28 18:24:13 +00:00
|
|
|
#include "../private/SkAtomics.h"
|
2016-02-18 16:53:33 +00:00
|
|
|
#include "../private/SkMutex.h"
|
|
|
|
#include "../private/SkTDArray.h"
|
2011-12-02 19:11:17 +00:00
|
|
|
#include "SkBitmap.h"
|
2015-05-22 15:06:21 +00:00
|
|
|
#include "SkFilterQuality.h"
|
2015-02-24 22:38:12 +00:00
|
|
|
#include "SkImageInfo.h"
|
2015-05-22 15:06:21 +00:00
|
|
|
#include "SkPixmap.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkRefCnt.h"
|
2014-07-21 18:37:39 +00:00
|
|
|
#include "SkSize.h"
|
2015-02-24 22:38:12 +00:00
|
|
|
#include "SkString.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
class SkColorTable;
|
2012-12-06 14:26:02 +00:00
|
|
|
class SkData;
|
2011-04-01 19:05:36 +00:00
|
|
|
struct SkIRect;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2013-06-26 19:18:23 +00:00
|
|
|
class GrTexture;
|
2015-08-19 19:25:40 +00:00
|
|
|
class SkDiscardableMemory;
|
2010-09-09 16:01:26 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** \class SkPixelRef
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2014-07-14 16:21:31 +00:00
|
|
|
class SK_API SkPixelRef : public SkRefCnt {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2013-12-06 22:07:17 +00:00
|
|
|
explicit SkPixelRef(const SkImageInfo&);
|
2013-10-24 17:44:27 +00:00
|
|
|
virtual ~SkPixelRef();
|
2011-02-24 18:09:46 +00:00
|
|
|
|
2013-12-09 22:01:03 +00:00
|
|
|
const SkImageInfo& info() const {
|
|
|
|
return fInfo;
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Return the pixel memory returned from lockPixels, or null if the
|
|
|
|
lockCount is 0.
|
|
|
|
*/
|
2014-01-06 17:08:27 +00:00
|
|
|
void* pixels() const { return fRec.fPixels; }
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Return the current colorTable (if any) if pixels are locked, or null.
|
|
|
|
*/
|
2014-01-06 17:08:27 +00:00
|
|
|
SkColorTable* colorTable() const { return fRec.fColorTable; }
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-01-08 15:42:01 +00:00
|
|
|
size_t rowBytes() const { return fRec.fRowBytes; }
|
|
|
|
|
2014-01-03 17:58:57 +00:00
|
|
|
/**
|
|
|
|
* To access the actual pixels of a pixelref, it must be "locked".
|
|
|
|
* Calling lockPixels returns a LockRec struct (on success).
|
|
|
|
*/
|
|
|
|
struct LockRec {
|
2015-05-30 20:41:15 +00:00
|
|
|
LockRec() : fPixels(NULL), fColorTable(NULL) {}
|
|
|
|
|
2014-01-03 17:58:57 +00:00
|
|
|
void* fPixels;
|
|
|
|
SkColorTable* fColorTable;
|
|
|
|
size_t fRowBytes;
|
2014-01-04 07:01:40 +00:00
|
|
|
|
2014-01-03 17:58:57 +00:00
|
|
|
void zero() { sk_bzero(this, sizeof(*this)); }
|
|
|
|
|
|
|
|
bool isZero() const {
|
|
|
|
return NULL == fPixels && NULL == fColorTable && 0 == fRowBytes;
|
|
|
|
}
|
|
|
|
};
|
2014-01-04 07:01:40 +00:00
|
|
|
|
2015-02-20 20:40:40 +00:00
|
|
|
SkDEBUGCODE(bool isLocked() const { return fLockCount > 0; })
|
2012-12-14 13:13:55 +00:00
|
|
|
SkDEBUGCODE(int getLockCount() const { return fLockCount; })
|
|
|
|
|
2014-01-06 17:08:27 +00:00
|
|
|
/**
|
|
|
|
* Call to access the pixel memory. Return true on success. Balance this
|
|
|
|
* with a call to unlockPixels().
|
|
|
|
*/
|
|
|
|
bool lockPixels();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 lockPixels(LockRec* rec);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** 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.)
|
|
|
|
*/
|
|
|
|
void unlockPixels();
|
2011-02-24 18:09:46 +00:00
|
|
|
|
2011-07-07 13:42:37 +00:00
|
|
|
/**
|
|
|
|
* 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.)
|
|
|
|
*/
|
|
|
|
bool lockPixelsAreWritable() const;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** 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.
|
|
|
|
*/
|
|
|
|
uint32_t getGenerationID() const;
|
2011-02-24 18:09:46 +00:00
|
|
|
|
2014-11-25 21:42:12 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
|
|
|
/** Returns a non-zero, unique value corresponding to this SkPixelRef.
|
|
|
|
Unlike the generation ID, this ID remains the same even when the pixels
|
|
|
|
are changed. IDs are not reused (until uint32_t wraps), so it is safe
|
|
|
|
to consider this ID unique even after this SkPixelRef is deleted.
|
|
|
|
|
|
|
|
Can be used as a key which uniquely identifies this SkPixelRef
|
|
|
|
regardless of changes to its pixels or deletion of this object.
|
|
|
|
*/
|
|
|
|
uint32_t getStableID() const { return fStableID; }
|
|
|
|
#endif
|
|
|
|
|
2014-01-27 15:41:07 +00:00
|
|
|
/**
|
|
|
|
* 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().
|
|
|
|
*/
|
2014-01-28 16:05:39 +00:00
|
|
|
void notifyPixelsChanged();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void changeAlphaType(SkAlphaType at);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** 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.
|
|
|
|
*/
|
2015-07-29 18:44:52 +00:00
|
|
|
bool isImmutable() const { return fMutability != kMutable; }
|
2011-02-24 18:09:46 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** 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 setImmutable();
|
|
|
|
|
|
|
|
/** Return the optional URI string associated with this pixelref. May be
|
|
|
|
null.
|
|
|
|
*/
|
|
|
|
const char* getURI() const { return fURI.size() ? fURI.c_str() : NULL; }
|
|
|
|
|
|
|
|
/** Copy a URI string to this pixelref, or clear the URI if the uri is null
|
|
|
|
*/
|
|
|
|
void setURI(const char uri[]) {
|
|
|
|
fURI.set(uri);
|
|
|
|
}
|
2011-02-24 18:09:46 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Copy a URI string to this pixelref
|
|
|
|
*/
|
|
|
|
void setURI(const char uri[], size_t len) {
|
|
|
|
fURI.set(uri, len);
|
|
|
|
}
|
2011-02-24 18:09:46 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Assign a URI string to this pixelref.
|
|
|
|
*/
|
|
|
|
void setURI(const SkString& uri) { fURI = uri; }
|
|
|
|
|
2012-12-06 14:26:02 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
SkData* refEncodedData() {
|
|
|
|
return this->onRefEncodedData();
|
|
|
|
}
|
|
|
|
|
2015-05-22 15:06:21 +00:00
|
|
|
struct LockRequest {
|
|
|
|
SkISize fSize;
|
|
|
|
SkFilterQuality fQuality;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LockResult {
|
2015-05-30 20:41:15 +00:00
|
|
|
LockResult() : fPixels(NULL), fCTable(NULL) {}
|
|
|
|
|
2015-05-22 15:06:21 +00:00
|
|
|
void (*fUnlockProc)(void* ctx);
|
|
|
|
void* fUnlockContext;
|
|
|
|
|
2015-05-30 16:20:29 +00:00
|
|
|
const void* fPixels;
|
2015-05-30 20:41:15 +00:00
|
|
|
SkColorTable* fCTable; // should be NULL unless colortype is kIndex8
|
2015-05-22 15:06:21 +00:00
|
|
|
size_t fRowBytes;
|
|
|
|
SkISize fSize;
|
|
|
|
|
|
|
|
void unlock() {
|
|
|
|
if (fUnlockProc) {
|
|
|
|
fUnlockProc(fUnlockContext);
|
|
|
|
fUnlockProc = NULL; // can't unlock twice!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool requestLock(const LockRequest&, LockResult*);
|
|
|
|
|
2010-09-09 16:01:26 +00:00
|
|
|
/** Are we really wrapping a texture instead of a bitmap?
|
|
|
|
*/
|
2013-06-26 19:18:23 +00:00
|
|
|
virtual GrTexture* getTexture() { return NULL; }
|
2010-09-09 16:01:26 +00:00
|
|
|
|
2014-07-21 18:37:39 +00:00
|
|
|
/**
|
|
|
|
* If any planes or rowBytes is NULL, this should output the sizes and return true
|
|
|
|
* if it can efficiently return YUV planar data. If it cannot, it should return false.
|
|
|
|
*
|
|
|
|
* If all planes and rowBytes are not NULL, then it should copy the associated Y,U,V data
|
|
|
|
* into those planes of memory supplied by the caller. It should validate that the sizes
|
|
|
|
* match what it expected. If the sizes do not match, it should return false.
|
2014-09-13 00:45:58 +00:00
|
|
|
*
|
|
|
|
* If colorSpace is not NULL, the YUV color space of the data should be stored in the address
|
|
|
|
* it points at.
|
2014-07-21 18:37:39 +00:00
|
|
|
*/
|
2014-09-13 00:45:58 +00:00
|
|
|
bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
|
|
|
|
SkYUVColorSpace* colorSpace) {
|
|
|
|
return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace);
|
2014-07-21 18:37:39 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 19:14:17 +00:00
|
|
|
/** Populates dst with the pixels of this pixelRef, converting them to colorType. */
|
|
|
|
bool readPixels(SkBitmap* dst, SkColorType colorType, const SkIRect* subset = NULL);
|
2011-04-01 19:05:36 +00:00
|
|
|
|
2012-12-07 19:14:45 +00:00
|
|
|
/**
|
|
|
|
* Makes a deep copy of this PixelRef, respecting the requested config.
|
2014-06-11 13:09:50 +00:00
|
|
|
* @param colorType Desired colortype.
|
2014-12-22 16:31:49 +00:00
|
|
|
* @param profileType Desired colorprofiletype.
|
2012-12-07 19:14:45 +00:00
|
|
|
* @param subset Subset of this PixelRef to copy. Must be fully contained within the bounds of
|
|
|
|
* of this PixelRef.
|
|
|
|
* @return A new SkPixelRef, or NULL if either there is an error (e.g. the destination could
|
|
|
|
* not be created with the given config), or this PixelRef does not support deep
|
|
|
|
* copies.
|
|
|
|
*/
|
2014-12-22 16:31:49 +00:00
|
|
|
virtual SkPixelRef* deepCopy(SkColorType, SkColorProfileType, const SkIRect* /*subset*/) {
|
2012-12-07 19:14:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-12-02 19:11:17 +00:00
|
|
|
|
2013-10-24 17:44:27 +00:00
|
|
|
// Register a listener that may be called the next time our generation ID changes.
|
|
|
|
//
|
|
|
|
// We'll only call the listener if we're confident that we are the only SkPixelRef with this
|
|
|
|
// generation ID. If our generation ID changes and we decide not to call the listener, we'll
|
|
|
|
// never call it: you must add a new listener for each generation ID change. We also won't call
|
|
|
|
// the listener when we're certain no one knows what our generation ID is.
|
|
|
|
//
|
|
|
|
// This can be used to invalidate caches keyed by SkPixelRef generation ID.
|
|
|
|
struct GenIDChangeListener {
|
|
|
|
virtual ~GenIDChangeListener() {}
|
|
|
|
virtual void onChange() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Takes ownership of listener.
|
|
|
|
void addGenIDChangeListener(GenIDChangeListener* listener);
|
|
|
|
|
2015-02-25 15:17:11 +00:00
|
|
|
// Call when this pixelref is part of the key to a resourcecache entry. This allows the cache
|
|
|
|
// to know automatically those entries can be purged when this pixelref is changed or deleted.
|
|
|
|
void notifyAddedToCache() {
|
2015-02-25 16:27:41 +00:00
|
|
|
fAddedToCache.store(true);
|
2015-02-25 15:17:11 +00:00
|
|
|
}
|
|
|
|
|
2015-08-19 19:25:40 +00:00
|
|
|
virtual SkDiscardableMemory* diagnostic_only_getDiscardable() const { return NULL; }
|
|
|
|
|
2015-08-20 15:47:26 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the pixels are generated on-the-fly (when required).
|
|
|
|
*/
|
|
|
|
bool isLazyGenerated() const { return this->onIsLazyGenerated(); }
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
2014-01-06 17:08:27 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
virtual bool onNewLockPixels(LockRec*) = 0;
|
2013-12-16 07:01:40 +00:00
|
|
|
|
2013-12-13 14:18:14 +00:00
|
|
|
/**
|
2014-01-06 17:08:27 +00:00
|
|
|
* 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.
|
2013-12-13 14:18:14 +00:00
|
|
|
*
|
2014-01-06 17:08:27 +00:00
|
|
|
* The caller will have already acquired a mutex for thread safety, so this
|
|
|
|
* method need not do that.
|
2013-12-13 13:41:14 +00:00
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual void onUnlockPixels() = 0;
|
|
|
|
|
2011-07-07 13:42:37 +00:00
|
|
|
/** Default impl returns true */
|
|
|
|
virtual bool onLockPixelsAreWritable() const;
|
|
|
|
|
2011-04-01 19:05:36 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
*/
|
2016-01-11 19:14:17 +00:00
|
|
|
virtual bool onReadPixels(SkBitmap* dst, SkColorType colorType, const SkIRect* subsetOrNull);
|
2011-04-01 19:05:36 +00:00
|
|
|
|
2012-12-06 14:26:02 +00:00
|
|
|
// default impl returns NULL.
|
|
|
|
virtual SkData* onRefEncodedData();
|
|
|
|
|
2015-06-15 16:48:15 +00:00
|
|
|
// default impl does nothing.
|
|
|
|
virtual void onNotifyPixelsChanged();
|
|
|
|
|
2014-07-21 18:37:39 +00:00
|
|
|
// default impl returns false.
|
2014-09-13 00:45:58 +00:00
|
|
|
virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
|
|
|
|
SkYUVColorSpace* colorSpace);
|
2014-07-21 18:37:39 +00:00
|
|
|
|
2013-12-04 17:06:49 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @return default impl returns 0.
|
|
|
|
*/
|
|
|
|
virtual size_t getAllocatedSizeInBytes() const;
|
|
|
|
|
2015-05-22 15:06:21 +00:00
|
|
|
virtual bool onRequestLock(const LockRequest&, LockResult*);
|
|
|
|
|
2015-08-20 15:47:26 +00:00
|
|
|
virtual bool onIsLazyGenerated() const { return false; }
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Return the mutex associated with this pixelref. This value is assigned
|
|
|
|
in the constructor, and cannot change during the lifetime of the object.
|
|
|
|
*/
|
2015-08-13 21:02:06 +00:00
|
|
|
SkBaseMutex* mutex() const { return &fMutex; }
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-05-17 13:14:52 +00:00
|
|
|
// only call from constructor. Flags this to always be locked, removing
|
|
|
|
// the need to grab the mutex and call onLockPixels/onUnlockPixels.
|
|
|
|
// Performance tweak to avoid those calls (esp. in multi-thread use case).
|
2014-01-06 17:08:27 +00:00
|
|
|
void setPreLocked(void*, size_t rowBytes, SkColorTable*);
|
2012-05-17 13:14:52 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
2015-08-13 21:02:06 +00:00
|
|
|
mutable SkMutex fMutex;
|
2014-01-02 18:07:46 +00:00
|
|
|
|
2014-01-27 15:41:07 +00:00
|
|
|
// mostly const. fInfo.fAlpahType can be changed at runtime.
|
2014-01-02 18:07:46 +00:00
|
|
|
const SkImageInfo fInfo;
|
2013-12-13 15:24:37 +00:00
|
|
|
|
2014-01-06 17:08:27 +00:00
|
|
|
// LockRec is only valid if we're in a locked state (isLocked())
|
|
|
|
LockRec fRec;
|
2008-12-17 15:59:43 +00:00
|
|
|
int fLockCount;
|
2011-02-24 18:09:46 +00:00
|
|
|
|
2015-05-30 20:41:15 +00:00
|
|
|
bool lockPixelsInsideMutex();
|
2015-05-22 15:06:21 +00:00
|
|
|
|
2015-02-25 17:10:57 +00:00
|
|
|
// Bottom bit indicates the Gen ID is unique.
|
|
|
|
bool genIDIsUnique() const { return SkToBool(fTaggedGenID.load() & 1); }
|
|
|
|
mutable SkAtomic<uint32_t> fTaggedGenID;
|
|
|
|
|
2014-11-25 21:42:12 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
|
|
|
const uint32_t fStableID;
|
|
|
|
#endif
|
2011-02-24 18:09:46 +00:00
|
|
|
|
2013-10-24 17:44:27 +00:00
|
|
|
SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owned
|
2012-08-22 15:00:05 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkString fURI;
|
|
|
|
|
2015-02-25 17:10:57 +00:00
|
|
|
// Set true by caches when they cache content that's derived from the current pixels.
|
|
|
|
SkAtomic<bool> fAddedToCache;
|
2015-07-29 18:44:52 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
kMutable, // PixelRefs begin mutable.
|
|
|
|
kTemporarilyImmutable, // Considered immutable, but can revert to mutable.
|
|
|
|
kImmutable, // Once set to this state, it never leaves.
|
|
|
|
} fMutability : 8; // easily fits inside a byte
|
|
|
|
|
2012-05-17 13:14:52 +00:00
|
|
|
// only ever set in constructor, const after that
|
2015-02-25 17:10:57 +00:00
|
|
|
bool fPreLocked;
|
2012-05-17 13:14:52 +00:00
|
|
|
|
2013-10-24 17:44:27 +00:00
|
|
|
void needsNewGenID();
|
|
|
|
void callGenIDChangeListeners();
|
|
|
|
|
2015-07-29 18:44:52 +00:00
|
|
|
void setTemporarilyImmutable();
|
|
|
|
void restoreMutability();
|
|
|
|
friend class SkSurface_Raster; // For the two methods above.
|
|
|
|
|
2015-07-31 03:13:43 +00:00
|
|
|
bool isPreLocked() const { return fPreLocked; }
|
|
|
|
friend class SkImage_Raster;
|
2016-02-04 18:52:42 +00:00
|
|
|
friend class SkSpecialImage_Raster;
|
2015-07-31 03:13:43 +00:00
|
|
|
|
2013-10-24 17:44:27 +00:00
|
|
|
// When copying a bitmap to another with the same shape and config, we can safely
|
|
|
|
// clone the pixelref generation ID too, which makes them equivalent under caching.
|
|
|
|
friend class SkBitmap; // only for cloneGenID
|
|
|
|
void cloneGenID(const SkPixelRef&);
|
|
|
|
|
2015-08-04 15:10:13 +00:00
|
|
|
void setImmutableWithID(uint32_t genID);
|
|
|
|
friend class SkImage_Gpu;
|
2015-08-13 20:32:39 +00:00
|
|
|
friend class SkImageCacherator;
|
2015-08-04 15:10:13 +00:00
|
|
|
|
2014-07-14 16:21:31 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
2014-01-24 18:53:42 +00:00
|
|
|
class SkPixelRefFactory : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Allocate a new pixelref matching the specified ImageInfo, allocating
|
|
|
|
* the memory for the pixels. If the ImageInfo requires a ColorTable,
|
|
|
|
* the pixelref will ref() the colortable.
|
|
|
|
* On failure return NULL.
|
|
|
|
*/
|
2014-07-01 19:48:11 +00:00
|
|
|
virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable*) = 0;
|
2014-01-24 18:53:42 +00:00
|
|
|
};
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#endif
|