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

Unified Diff: src/lazy/SkDiscardablePixelRef.cpp

Issue 74793011: Add SkImageGenerator Interface (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: whitespace 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
« no previous file with comments | « src/lazy/SkDiscardablePixelRef.h ('k') | src/ports/SkDiscardableMemory_none.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/lazy/SkDiscardablePixelRef.cpp
diff --git a/src/lazy/SkDiscardablePixelRef.cpp b/src/lazy/SkDiscardablePixelRef.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b6e1b1004ed7096fc180be5945aa44e5dfab1c1c
--- /dev/null
+++ b/src/lazy/SkDiscardablePixelRef.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkDiscardablePixelRef.h"
+#include "SkDiscardableMemory.h"
+
+SkDiscardablePixelRef::SkDiscardablePixelRef(SkImageGenerator* generator,
+ const SkImageInfo& info,
+ size_t size,
+ size_t rowBytes)
+ : fGenerator(generator)
+ , fInfo(info)
+ , fSize(size)
+ , fRowBytes(rowBytes)
+ , fDiscardableMemory(NULL) {
+ SkASSERT(fGenerator != NULL);
+ SkASSERT(fSize > 0);
+ SkASSERT(fRowBytes > 0);
+}
+
+SkDiscardablePixelRef::~SkDiscardablePixelRef() {
+ SkDELETE(fGenerator);
+}
+
+void* SkDiscardablePixelRef::onLockPixels(SkColorTable**) {
+ if (fDiscardableMemory != NULL) {
+ if (fDiscardableMemory->lock()) {
+ return fDiscardableMemory->data();
+ }
+ fDiscardableMemory = NULL;
+ }
+ fDiscardableMemory = SkDiscardableMemory::Create(fSize);
+ if (NULL == fDiscardableMemory) {
+ return NULL; // Memory allocation failed.
+ }
+ void* pixels = fDiscardableMemory->data();
+ if (!fGenerator->getPixels(fInfo, pixels, fRowBytes)) {
+ return NULL; // TODO(halcanary) Find out correct thing to do.
+ }
+ return pixels;
+}
+void SkDiscardablePixelRef::onUnlockPixels() {
+ if (fDiscardableMemory != NULL) {
+ fDiscardableMemory->unlock();
+ }
+}
+
+bool SkDiscardablePixelRef::Install(SkImageGenerator* generator,
+ SkBitmap* dst) {
+ SkImageInfo info;
+ SkASSERT(generator != NULL);
+ if ((NULL == generator)
+ || (!generator->getInfo(&info))
+ || (!dst->setConfig(info, 0))) {
+ SkDELETE(generator);
+ return false;
+ }
+ SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef,
+ (generator, info,
+ dst->getSize(),
+ dst->rowBytes())));
+ dst->setPixelRef(ref);
+ return true;
+}
« no previous file with comments | « src/lazy/SkDiscardablePixelRef.h ('k') | src/ports/SkDiscardableMemory_none.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698