Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1641)

Unified Diff: src/core/SkAutoPixmapStorage.h

Issue 1787883002: Add SkSpecialImage::extractSubset & NewFromPixmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkPixmap.h ('k') | src/core/SkAutoPixmapStorage.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkAutoPixmapStorage.h
diff --git a/src/core/SkAutoPixmapStorage.h b/src/core/SkAutoPixmapStorage.h
new file mode 100644
index 0000000000000000000000000000000000000000..4379b13d2482ade8ed7c5f8bc48751be460caee6
--- /dev/null
+++ b/src/core/SkAutoPixmapStorage.h
@@ -0,0 +1,87 @@
+
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkAutoPixmapStorage_DEFINED
+#define SkAutoPixmapStorage_DEFINED
+
+#include "SkPixmap.h"
+
+class SK_API 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&);
+
+ /**
+ * Gets the size and optionally the rowBytes that would be allocated by SkAutoPixmapStorage if
+ * alloc/tryAlloc was called.
+ */
+ static size_t AllocSize(const SkImageInfo& info, size_t* rowBytes);
+
+ /**
+ * Returns an SkData object wrapping the allocated pixels memory, and resets the pixmap.
+ * If the storage hasn't been allocated, the result is NULL.
+ */
+ const SkData* SK_WARN_UNUSED_RESULT detachPixelsAsData();
+
+ /**
+ * Whereas 'reset' frees the backing memory and then clears the SkPixmap,
+ * this entry point disowns the backing memory before clearing so the memory
+ * isn't freed. It can be used when the Pixmap has been installed into
+ * an SkBitmap and the SkBitmap should manage the memory's lifetime.
+ */
+ void release();
+
+ // We wrap these so we can clear our internal storage
+
+ void reset() {
+ this->freeStorage();
+ this->INHERITED::reset();
+ }
+ void reset(const SkImageInfo& info, const void* addr, size_t rb, SkColorTable* ctable = NULL) {
+ this->freeStorage();
+ this->INHERITED::reset(info, addr, rb, ctable);
+ }
+ void reset(const SkImageInfo& info) {
+ this->freeStorage();
+ this->INHERITED::reset(info);
+ }
+ bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask) {
+ this->freeStorage();
+ return this->INHERITED::reset(mask);
+ }
+
+private:
+ void* fStorage;
+
+ void freeStorage() {
+ sk_free(fStorage);
+ fStorage = nullptr;
+ }
+
+ typedef SkPixmap INHERITED;
+};
+
+#endif
« no previous file with comments | « include/core/SkPixmap.h ('k') | src/core/SkAutoPixmapStorage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698