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

Unified Diff: src/lazy/SkCachingPixelRef.cpp

Issue 1359393004: Revert of remove unused SkCachingPixelRef (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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 | « src/lazy/SkCachingPixelRef.h ('k') | tests/CachedDecodingPixelRefTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/lazy/SkCachingPixelRef.cpp
diff --git a/src/lazy/SkCachingPixelRef.cpp b/src/lazy/SkCachingPixelRef.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..692e4ea3d6715564545f1c93352771e5b095cc9a
--- /dev/null
+++ b/src/lazy/SkCachingPixelRef.cpp
@@ -0,0 +1,74 @@
+/*
+ * 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 "SkCachingPixelRef.h"
+#include "SkBitmapCache.h"
+#include "SkRect.h"
+
+bool SkCachingPixelRef::Install(SkImageGenerator* generator,
+ SkBitmap* dst) {
+ SkASSERT(dst != nullptr);
+ if (nullptr == generator) {
+ return false;
+ }
+ const SkImageInfo info = generator->getInfo();
+ if (!dst->setInfo(info)) {
+ delete generator;
+ return false;
+ }
+ SkAutoTUnref<SkCachingPixelRef> ref(new SkCachingPixelRef(info, generator, dst->rowBytes()));
+ dst->setPixelRef(ref);
+ return true;
+}
+
+SkCachingPixelRef::SkCachingPixelRef(const SkImageInfo& info,
+ SkImageGenerator* generator,
+ size_t rowBytes)
+ : INHERITED(info)
+ , fImageGenerator(generator)
+ , fErrorInDecoding(false)
+ , fRowBytes(rowBytes) {
+ SkASSERT(fImageGenerator != nullptr);
+}
+SkCachingPixelRef::~SkCachingPixelRef() {
+ delete fImageGenerator;
+ // Assert always unlock before unref.
+}
+
+bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) {
+ if (fErrorInDecoding) {
+ return false; // don't try again.
+ }
+
+ const SkImageInfo& info = this->info();
+ if (!SkBitmapCache::Find(
+ this->getGenerationID(), info.bounds(), &fLockedBitmap)) {
+ // Cache has been purged, must re-decode.
+ if (!fLockedBitmap.tryAllocPixels(info, fRowBytes)) {
+ fErrorInDecoding = true;
+ return false;
+ }
+ if (!fImageGenerator->getPixels(info, fLockedBitmap.getPixels(), fRowBytes)) {
+ fErrorInDecoding = true;
+ return false;
+ }
+ fLockedBitmap.setImmutable();
+ SkBitmapCache::Add(this, info.bounds(), fLockedBitmap);
+ }
+
+ // Now bitmap should contain a concrete PixelRef of the decoded image.
+ void* pixels = fLockedBitmap.getPixels();
+ SkASSERT(pixels != nullptr);
+ rec->fPixels = pixels;
+ rec->fColorTable = nullptr;
+ rec->fRowBytes = fLockedBitmap.rowBytes();
+ return true;
+}
+
+void SkCachingPixelRef::onUnlockPixels() {
+ fLockedBitmap.reset();
+}
« no previous file with comments | « src/lazy/SkCachingPixelRef.h ('k') | tests/CachedDecodingPixelRefTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698