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

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: Created 7 years, 2 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
Index: src/lazy/SkLazyCachingPixelRef.cpp
diff --git a/src/lazy/SkLazyCachingPixelRef.cpp b/src/lazy/SkLazyCachingPixelRef.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..7e3d2739704ed49d1e30bf2251bca934e26b4c6d
--- /dev/null
+++ b/src/lazy/SkLazyCachingPixelRef.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2012 Google Inc.
scroggo 2013/10/31 21:53:06 2013
hal.canary 2013/11/01 03:29:24 Done.
+ *
+ * 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 "SkImagePriv.h"
+#include "SkLazyCachingPixelRef.h"
+#include "SkScaledImageCache.h"
+#include "SkPostConfig.h"
+#include "SkImageDecoder.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();
+ }
+ memset(&fLazilyCachedInfo, 0xFF, sizeof(fLazilyCachedInfo));
+
+ if (NULL == fDecodeProc) { // use a reasonable default.
+ fDecodeProc = SkImageDecoder::DecodeMemoryToTarget;
+ }
+ this->setImmutable();
+}
+
+SkLazyCachingPixelRef::~SkLazyCachingPixelRef() {
+ SkASSERT(fData != NULL);
+ fData->unref();
+}
+
+bool SkLazyCachingPixelRef::onDecodeInfo(SkISize* size,
+ SkBitmap::Config* config,
+ SkAlphaType* alphaType) {
+ SkASSERT(size && config &&alphaType);
+ if (fLazilyCachedInfo.fWidth < 0) {
+ SkImage::Info info;
+ if (!fDecodeProc(fData->data(), fData->size(), &info, NULL)) {
+ return false;
+ }
+ fLazilyCachedInfo = info;
+ }
+ size->set(fLazilyCachedInfo.fWidth, fLazilyCachedInfo.fHeight);
+ *config = SkImageInfoToBitmapConfig(fLazilyCachedInfo);
+ *alphaType = fLazilyCachedInfo.fAlphaType;
+ return true;
+}
+
+bool SkLazyCachingPixelRef::onDecode(void* pixels, size_t rowBytes) {
+ SkASSERT(pixels);
+ if (fLazilyCachedInfo.fWidth <= 0) {
+ SkISize size;
+ SkBitmap::Config config;
+ SkAlphaType alphaType;
+ // The side effect of this is to set fLazilyCachedInfo
+ this->onDecodeInfo(&size, &config, &alphaType);
+ }
+ SkBitmapFactory::Target target = {pixels, rowBytes};
+ return fDecodeProc(fData->data(), fData->size(),
+ &fLazilyCachedInfo, &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