aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-06 13:34:39 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-06 13:34:39 +0000
commitba82bd11e2c055f885b2327aa230d2dac8b53f03 (patch)
tree8e838e01d55b7a6d9ac811d00826d9a38e290f12 /include/core
parent452eecb4436f27e057d4d2df26e3a70020a817b6 (diff)
Revert "Revert "Revert of https://codereview.chromium.org/110593003/""
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkBitmapDevice.h3
-rw-r--r--include/core/SkMallocPixelRef.h10
-rw-r--r--include/core/SkPixelRef.h57
3 files changed, 26 insertions, 44 deletions
diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h
index f3d40d0ce8..adc8e2b2c1 100644
--- a/include/core/SkBitmapDevice.h
+++ b/include/core/SkBitmapDevice.h
@@ -258,7 +258,8 @@ private:
friend class SkSurface_Raster;
- void init(SkBitmap::Config config, int width, int height, bool isOpaque);
+ // only call from constructor, to try to allocate the pixels
+ void init(SkBitmap::Config, int width, int height, bool isOpaque);
// used to change the backend's pixels (and possibly config/rowbytes)
// but cannot change the width/height, so there should be no change to
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h
index c40afc433a..272dc21fd8 100644
--- a/include/core/SkMallocPixelRef.h
+++ b/include/core/SkMallocPixelRef.h
@@ -32,9 +32,11 @@ public:
/**
* Return a new SkMallocPixelRef, automatically allocating storage for the
- * pixels. If rowBytes are 0, an optimal value will be chosen automatically.
- * If rowBytes is > 0, then it will be respected, or NULL will be returned
- * if rowBytes is invalid for the specified info.
+ * pixels.
+ *
+ * If rowBytes is 0, an optimal value will be chosen automatically.
+ * If rowBytes is > 0, then it will be used, unless it is invald for the
+ * specified info, in which case NULL will be returned (failure).
*
* This pixelref will ref() the specified colortable (if not NULL).
*
@@ -88,7 +90,7 @@ protected:
SkMallocPixelRef(SkFlattenableReadBuffer& buffer);
virtual ~SkMallocPixelRef();
- virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
+ virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE;
virtual void onUnlockPixels() SK_OVERRIDE;
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE;
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index 4811435721..6700eb4def 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -14,11 +14,8 @@
#include "SkRefCnt.h"
#include "SkString.h"
#include "SkFlattenable.h"
-#include "SkImageInfo.h"
#include "SkTDArray.h"
-//#define SK_SUPPORT_LEGACY_ONLOCKPIXELS
-
#ifdef SK_DEBUG
/**
* Defining SK_IGNORE_PIXELREF_SETPRELOCKED will force all pixelref
@@ -63,11 +60,11 @@ public:
/** Return the pixel memory returned from lockPixels, or null if the
lockCount is 0.
*/
- void* pixels() const { return fRec.fPixels; }
+ void* pixels() const { return fPixels; }
/** Return the current colorTable (if any) if pixels are locked, or null.
*/
- SkColorTable* colorTable() const { return fRec.fColorTable; }
+ SkColorTable* colorTable() const { return fColorTable; }
/**
* To access the actual pixels of a pixelref, it must be "locked".
@@ -92,19 +89,10 @@ public:
SkDEBUGCODE(int getLockCount() const { return fLockCount; })
- /**
- * 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);
-
+ /** Call to access the pixel memory, which is returned. Balance with a call
+ to unlockPixels().
+ */
+ void lockPixels();
/** 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
@@ -261,27 +249,18 @@ public:
void addGenIDChangeListener(GenIDChangeListener* listener);
protected:
-#ifdef SK_SUPPORT_LEGACY_ONLOCKPIXELS
- virtual void* onLockPixels(SkColorTable**);
- virtual bool onNewLockPixels(LockRec*);
-#else
- /**
- * 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;
-#endif
+ /** Called when the lockCount goes from 0 to 1. The caller will have already
+ acquire a mutex for thread safety, so this method need not do that.
+ */
+ virtual void* onLockPixels(SkColorTable**) = 0;
/**
- * 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.
+ * Called when the lock count goes from 1 to 0. The caller will have
+ * already acquire a mutex for thread safety, so this method need not do
+ * that.
*
- * The caller will have already acquired a mutex for thread safety, so this
- * method need not do that.
+ * If the previous call to onLockPixels failed (i.e. returned NULL), then
+ * the onUnlockPixels will NOT be called.
*/
virtual void onUnlockPixels() = 0;
@@ -326,15 +305,15 @@ protected:
// 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).
- void setPreLocked(void*, size_t rowBytes, SkColorTable*);
+ void setPreLocked(void* pixels, SkColorTable* ctable);
private:
SkBaseMutex* fMutex; // must remain in scope for the life of this object
const SkImageInfo fInfo;
- // LockRec is only valid if we're in a locked state (isLocked())
- LockRec fRec;
+ void* fPixels;
+ SkColorTable* fColorTable; // we do not track ownership, subclass does
int fLockCount;
mutable uint32_t fGenerationID;