aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-11 21:15:58 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-11 21:15:58 +0000
commita0d183d89160e31962e99475abe8a77c30626a40 (patch)
treec557c0b40852c2c924c517a4d09f2a8a885cda08 /include/core
parentff9c6c92e5f962b34f7421e67ac112f81a018bd3 (diff)
This reverts commit 947e6a3142af66b750f1247ef933b11ed8455dd4. BUG= Review URL: https://codereview.chromium.org/112963003 git-svn-id: http://skia.googlecode.com/svn/trunk@12630 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkBitmapDevice.h2
-rw-r--r--include/core/SkMallocPixelRef.h51
-rw-r--r--include/core/SkPicture.h3
-rw-r--r--include/core/SkPixelRef.h76
4 files changed, 96 insertions, 36 deletions
diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h
index 83f480c60c..f3d40d0ce8 100644
--- a/include/core/SkBitmapDevice.h
+++ b/include/core/SkBitmapDevice.h
@@ -258,6 +258,8 @@ private:
friend class SkSurface_Raster;
+ void init(SkBitmap::Config 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
// any clip information.
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h
index 100a15d90a..5ef70d69bc 100644
--- a/include/core/SkMallocPixelRef.h
+++ b/include/core/SkMallocPixelRef.h
@@ -17,33 +17,52 @@
*/
class SkMallocPixelRef : public SkPixelRef {
public:
- /** Allocate the specified buffer for pixels. The memory is freed when the
- last owner of this pixelref is gone. If addr is NULL, sk_malloc_throw()
- is called to allocate it.
+ /**
+ * Return a new SkMallocPixelRef with the provided pixel storage, rowBytes,
+ * and optional colortable. The caller is responsible for managing the
+ * lifetime of the pixel storage buffer, as the pixelref will not try
+ * to delete the storage.
+ *
+ * This pixelref will ref() the specified colortable (if not NULL).
+ *
+ * Returns NULL on failure.
*/
- SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable, bool ownPixels = true);
- virtual ~SkMallocPixelRef();
+ static SkMallocPixelRef* NewDirect(const SkImageInfo&, void* addr,
+ size_t rowBytes, SkColorTable*);
+
+ /**
+ * 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.
+ *
+ * This pixelref will ref() the specified colortable (if not NULL).
+ *
+ * Returns NULL on failure.
+ */
+ static SkMallocPixelRef* NewAllocate(const SkImageInfo& info,
+ size_t rowBytes, SkColorTable*);
void* getAddr() const { return fStorage; }
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef)
protected:
- // overrides from SkPixelRef
- virtual void* onLockPixels(SkColorTable**);
- virtual void onUnlockPixels();
-
- SkMallocPixelRef(SkFlattenableReadBuffer& buffer);
+ virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
+ virtual void onUnlockPixels() SK_OVERRIDE;
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
+ virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE;
- // Returns the allocation size for the pixels
- virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE { return fSize; }
+ SkMallocPixelRef(SkFlattenableReadBuffer& buffer);
+ SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
+ bool ownsPixels);
+ virtual ~SkMallocPixelRef();
private:
- void* fStorage;
- size_t fSize;
- SkColorTable* fCTable;
- bool fOwnPixels;
+ void* fStorage;
+ SkColorTable* fCTable;
+ size_t fRB;
+ const bool fOwnPixels;
typedef SkPixelRef INHERITED;
};
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index bce343ec04..cd6b3bcbb1 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -220,10 +220,11 @@ protected:
// V14: Add flags word to PathRef serialization
// V15: Remove A1 bitmpa config (and renumber remaining configs)
// V16: Move SkPath's isOval flag to SkPathRef
+ // V17: Changes to PixelRef to store SkImageInfo
#ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TOO
static const uint32_t PRIOR_PICTURE_VERSION = 15; // TODO: remove when .skps regenerated
#endif
- static const uint32_t PICTURE_VERSION = 16;
+ static const uint32_t PICTURE_VERSION = 17;
// fPlayback, fRecord, fWidth & fHeight are protected to allow derived classes to
// install their own SkPicturePlayback-derived players,SkPictureRecord-derived
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index b87b0dc114..472599eeb3 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -14,9 +14,12 @@
#include "SkRefCnt.h"
#include "SkString.h"
#include "SkFlattenable.h"
+#include "SkImageInfo.h"
#include "SkTDArray.h"
-#define SK_SUPPORT_LEGACY_PIXELREF_CONSTRUCTOR
+//#define SK_SUPPORT_LEGACY_PIXELREF_CONSTRUCTOR
+
+#define SK_SUPPORT_LEGACY_ONLOCKPIXELS
#ifdef SK_DEBUG
/**
@@ -67,23 +70,44 @@ public:
/** Return the pixel memory returned from lockPixels, or null if the
lockCount is 0.
*/
- void* pixels() const { return fPixels; }
+ void* pixels() const { return fRec.fPixels; }
/** Return the current colorTable (if any) if pixels are locked, or null.
*/
- SkColorTable* colorTable() const { return fColorTable; }
+ SkColorTable* colorTable() const { return fRec.fColorTable; }
/**
+ * To access the actual pixels of a pixelref, it must be "locked".
+ * Calling lockPixels returns a LockRec struct (on success).
+ */
+ struct LockRec {
+ void* fPixels;
+ SkColorTable* fColorTable;
+ size_t fRowBytes;
+
+ void zero() { sk_bzero(this, sizeof(*this)); }
+ };
+
+ /**
* Returns true if the lockcount > 0
*/
bool isLocked() const { return fLockCount > 0; }
SkDEBUGCODE(int getLockCount() const { return fLockCount; })
- /** Call to access the pixel memory, which is returned. Balance with a call
- to unlockPixels().
- */
- void lockPixels();
+ /**
+ * 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 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
@@ -240,14 +264,28 @@ public:
void addGenIDChangeListener(GenIDChangeListener* listener);
protected:
- /** 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;
- /** 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.
- */
+#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
+
+ /**
+ * 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.
+ */
virtual void onUnlockPixels() = 0;
/** Default impl returns true */
@@ -291,14 +329,14 @@ 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* pixels, SkColorTable* ctable);
+ void setPreLocked(void*, size_t rowBytes, SkColorTable*);
private:
SkBaseMutex* fMutex; // must remain in scope for the life of this object
SkImageInfo fInfo;
-
- void* fPixels;
- SkColorTable* fColorTable; // we do not track ownership, subclass does
+
+ // LockRec is only valid if we're in a locked state (isLocked())
+ LockRec fRec;
int fLockCount;
mutable uint32_t fGenerationID;