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

Unified Diff: src/lazy/SkLazyCachingPixelRef.cpp

Issue 54203006: Break up SkLazyPixelRef functionally into class hierarchy. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: changes for reed and scroggo 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/lazy/SkLazyCachingPixelRef.cpp
diff --git a/src/lazy/SkLazyCachingPixelRef.cpp b/src/lazy/SkLazyCachingPixelRef.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..fbd0089472db7af189c106e2114d48983388ca3e
--- /dev/null
+++ b/src/lazy/SkLazyCachingPixelRef.cpp
@@ -0,0 +1,63 @@
+/*
+ * 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 "Sk64.h"
+#include "SkColorTable.h"
+#include "SkData.h"
+#include "SkImageDecoder.h"
+#include "SkImagePriv.h"
+#include "SkLazyCachingPixelRef.h"
+#include "SkPostConfig.h"
+#include "SkScaledImageCache.h"
+
+SkLazyCachingPixelRef::SkLazyCachingPixelRef(SkData* data,
+ SkBitmapFactory::DecodeProc proc,
+ SkScaledImageCache* cache)
+ : INHERITED(cache)
+ , fDecodeProc(proc) {
+ if (NULL == data) {
+ fData = SkData::NewEmpty();
+ } else {
+ fData = data;
+ fData->ref();
+ }
+ if (NULL == fDecodeProc) { // use a reasonable default.
+ fDecodeProc = SkImageDecoder::DecodeMemoryToTarget;
+ }
+ this->setImmutable();
+}
+
+SkLazyCachingPixelRef::~SkLazyCachingPixelRef() {
+ SkASSERT(fData != NULL);
+ fData->unref();
+}
+
+bool SkLazyCachingPixelRef::onDecodeInfo(SkImageInfo* info) {
+ SkASSERT(info);
+ return fDecodeProc(fData->data(), fData->size(), info, NULL);
+}
+
+bool SkLazyCachingPixelRef::onDecode(void* pixels, size_t rowBytes) {
+ SkASSERT(pixels);
+ const SkImageInfo* infoPtr = this->getInfo();
+ if (NULL == infoPtr) { // getInfo() failed
+ return false;
+ }
+ SkImageInfo info = *infoPtr; // local copy of info.
+ SkBitmapFactory::Target target = {pixels, rowBytes};
+ return fDecodeProc(fData->data(), fData->size(), &info, &target);
+}
+
+bool SkLazyCachingPixelRef::Install(SkBitmapFactory::DecodeProc proc,
+ SkData* data,
+ SkBitmap* destination,
+ SkScaledImageCache* cache) {
+ SkAutoTUnref<SkLazyCachingPixelRef> ref(
+ SkNEW_ARGS(SkLazyCachingPixelRef, (data, proc, cache)));
+ return ref->configure(destination) && destination->setPixelRef(ref);
+}
+

Powered by Google App Engine
This is Rietveld 408576698