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

Unified Diff: src/core/SkMallocPixelRef.cpp

Issue 83663006: Modify SkLazyPixelRef to use SkImageGenerator. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: reupload Created 7 years, 1 month 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
Index: src/core/SkMallocPixelRef.cpp
diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp
index f229e9de34d0fa8dbdd29304dd0ac0f7a78e5611..ae783998a914b2e28654fc97fc0f31f67257a319 100644
--- a/src/core/SkMallocPixelRef.cpp
+++ b/src/core/SkMallocPixelRef.cpp
@@ -8,6 +8,7 @@
#include "SkMallocPixelRef.h"
#include "SkBitmap.h"
#include "SkFlattenableBuffers.h"
+#include "SkImageGenerator.h"
SkMallocPixelRef::SkMallocPixelRef(void* storage, size_t size,
SkColorTable* ctable, bool ownPixels) {
@@ -31,6 +32,34 @@ SkMallocPixelRef::~SkMallocPixelRef() {
}
}
+bool SkMallocPixelRef::Install(SkImageGenerator* generator,
+ SkBitmap* destination) {
+ SkASSERT(generator != NULL);
+ SkAutoTDelete<SkImageGenerator> autodel(generator);
+ // Always gets deleted by this function.
+ SkImageInfo info;
+ SkBitmap tmp;
+ if ((NULL == generator)
+ || (!generator->getInfo(&info))
+ || (!tmp.setConfig(info, 0))) {
+ return false;
+ }
+ size_t rowBytes = tmp.rowBytes();
+ size_t size = tmp.getSize();
+ void* pixels = sk_malloc_throw(size);
reed1 2013/11/25 18:06:56 Can we change this to sk_malloc_flags() so we can
+ if (!generator->getPixels(info, pixels, rowBytes)) {
+ sk_free(pixels);
+ return false;
+ }
+ SkAutoTUnref<SkMallocPixelRef> ref(SkNEW_ARGS(SkMallocPixelRef,
+ (pixels, size, NULL, true)));
+ *destination = tmp; // copy config, size, rowbytes.
+ destination->setPixelRef(ref);
+ destination->lockPixels(); // Since we're already allocated, we lock
+ // right away, just like HeapAllocator.
+ return true;
+}
+
void* SkMallocPixelRef::onLockPixels(SkColorTable** ct) {
*ct = fCTable;
return fStorage;

Powered by Google App Engine
This is Rietveld 408576698