aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-24 18:53:42 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-24 18:53:42 +0000
commit9ebcac54635cde63110d73ad7c43d70772e7872f (patch)
tree59ed546835d806d958e25892d79097724efbf983 /include
parentbde4ba2ce6994a57f1b4e820ac83e9d27caf75de (diff)
add installPixels
BUG=skia: R=halcanary@google.com Review URL: https://codereview.chromium.org/143073008 git-svn-id: http://skia.googlecode.com/svn/trunk@13174 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r--include/core/SkBitmap.h32
-rw-r--r--include/core/SkMallocPixelRef.h6
-rw-r--r--include/core/SkPixelRef.h11
3 files changed, 48 insertions, 1 deletions
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index f53a0a7e45..af0c8b87e7 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -18,6 +18,7 @@ struct SkIRect;
struct SkRect;
class SkPaint;
class SkPixelRef;
+class SkPixelRefFactory;
class SkRegion;
class SkString;
@@ -250,6 +251,35 @@ public:
bool setConfig(const SkImageInfo& info, size_t rowBytes = 0);
/**
+ * Allocate a pixelref to match the specified image info. If the Factory
+ * is non-null, call it to allcoate the pixelref. If the ImageInfo requires
+ * a colortable, then ColorTable must be non-null, and will be ref'd.
+ * On failure, the bitmap will be set to empty and return false.
+ */
+ bool allocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*);
+
+ /**
+ * Allocate a pixelref to match the specified image info, using the default
+ * allocator.
+ * On success, the bitmap's pixels will be "locked", and return true.
+ * On failure, the bitmap will be set to empty and return false.
+ */
+ bool allocPixels(const SkImageInfo& info) {
+ return this->allocPixels(info, NULL, NULL);
+ }
+
+ /**
+ * Install a pixelref that wraps the specified pixels and rowBytes, and
+ * optional ReleaseProc and context. When the pixels are no longer
+ * referenced, if ReleaseProc is not null, it will be called with the
+ * pixels and context as parameters.
+ * On failure, the bitmap will be set to empty and return false.
+ */
+ bool installPixels(const SkImageInfo&, void* pixels, size_t rowBytes,
+ void (*ReleaseProc)(void* addr, void* context),
+ void* context);
+
+ /**
* If the bitmap's config can be represented as SkImageInfo, return true,
* and if info is not-null, set it to the bitmap's info. If it cannot be
* represented as SkImageInfo, return false and ignore the info parameter.
@@ -637,7 +667,7 @@ public:
*/
class HeapAllocator : public Allocator {
public:
- virtual bool allocPixelRef(SkBitmap*, SkColorTable*);
+ virtual bool allocPixelRef(SkBitmap*, SkColorTable*) SK_OVERRIDE;
};
class RLEPixels {
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h
index 6642af57bb..4607fa2843 100644
--- a/include/core/SkMallocPixelRef.h
+++ b/include/core/SkMallocPixelRef.h
@@ -79,6 +79,12 @@ public:
void* getAddr() const { return fStorage; }
+ class PRFactory : public SkPixelRefFactory {
+ public:
+ virtual SkPixelRef* create(const SkImageInfo&,
+ SkColorTable*) SK_OVERRIDE;
+ };
+
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef)
protected:
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index fc0feb042a..e65f4a04c5 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -364,4 +364,15 @@ private:
typedef SkFlattenable INHERITED;
};
+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.
+ */
+ virtual SkPixelRef* create(const SkImageInfo&, SkColorTable*) = 0;
+};
+
#endif