aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-06-05 14:33:17 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-05 14:33:17 -0700
commit183b57f3093ccca79a171bd2e8d3ec58adadac5d (patch)
tree424f19699e3b95fc1452350d0ab962635f70edd4 /include
parent6e764859dabf265fae03066376e7446a87e0ad09 (diff)
add extractSubset and SkAutoPixmapStorage
extracted from larger CL in progress: https://codereview.chromium.org/1148793007 BUG=skia: TBR= Review URL: https://codereview.chromium.org/1162013008
Diffstat (limited to 'include')
-rw-r--r--include/core/SkPixmap.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h
index 275fcd0dca..913d007c4d 100644
--- a/include/core/SkPixmap.h
+++ b/include/core/SkPixmap.h
@@ -11,6 +11,7 @@
#include "SkImageInfo.h"
class SkColorTable;
+struct SkMask;
/**
* Pairs SkImageInfo with actual pixels and rowbytes. This class does not try to manage the
@@ -36,6 +37,23 @@ public:
void reset();
void reset(const SkImageInfo& info, const void* addr, size_t rowBytes,
SkColorTable* ctable = NULL);
+ void reset(const SkImageInfo& info) {
+ this->reset(info, NULL, 0, NULL);
+ }
+
+ /**
+ * If supported, set this pixmap to point to the pixels in the specified mask and return true.
+ * On failure, return false and set this pixmap to empty.
+ */
+ bool SK_WARN_UNUSED_RESULT reset(const SkMask&);
+
+ /**
+ * Computes the intersection of area and this pixmap. If that intersection is non-empty,
+ * set subset to that intersection and return true.
+ *
+ * On failure, return false and ignore the subset parameter.
+ */
+ bool SK_WARN_UNUSED_RESULT extractSubset(SkPixmap* subset, const SkIRect& area) const;
const SkImageInfo& info() const { return fInfo; }
size_t rowBytes() const { return fRowBytes; }
@@ -124,6 +142,35 @@ private:
/////////////////////////////////////////////////////////////////////////////////////////////
+class SkAutoPixmapStorage : public SkPixmap {
+public:
+ SkAutoPixmapStorage();
+ ~SkAutoPixmapStorage();
+
+ /**
+ * Try to allocate memory for the pixels needed to match the specified Info. On success
+ * return true and fill out the pixmap to point to that memory. The storage will be freed
+ * when this object is destroyed, or if another call to tryAlloc() or alloc() is made.
+ *
+ * On failure, return false and reset() the pixmap to empty.
+ */
+ bool tryAlloc(const SkImageInfo&);
+
+ /**
+ * Allocate memory for the pixels needed to match the specified Info and fill out the pixmap
+ * to point to that memory. The storage will be freed when this object is destroyed,
+ * or if another call to tryAlloc() or alloc() is made.
+ *
+ * If the memory cannot be allocated, calls sk_throw().
+ */
+ void alloc(const SkImageInfo&);
+
+private:
+ void* fStorage;
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////////
+
class SkAutoPixmapUnlock : ::SkNoncopyable {
public:
SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {}