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

Unified Diff: src/lazy/SkLazyCachingPixelRef.h

Issue 54203006: Break up SkLazyPixelRef functionally into class hierarchy. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: lint nits 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.h
diff --git a/src/lazy/SkLazyCachingPixelRef.h b/src/lazy/SkLazyCachingPixelRef.h
new file mode 100644
index 0000000000000000000000000000000000000000..24bc53bd182046866ffa431a6e2b2323121a5ea7
--- /dev/null
+++ b/src/lazy/SkLazyCachingPixelRef.h
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkLazyCachingPixelRef_DEFINED
+#define SkLazyCachingPixelRef_DEFINED
+
+#include "SkBitmapFactory.h"
+#include "SkCachingPixelRef.h"
+
+class SkData;
+
+/**
+ * PixelRef which defers decoding until SkBitmap::lockPixels() is
+ * called. Makes use of a supplied decode procedure. Will decode at
+ * the procedure's preferred size.
+ */
+class SkLazyCachingPixelRef : public SkCachingPixelRef {
+public:
+ /**
+ * @param data Encoded data representing the pixels. NULL is
+ * equivalent to an empty data, and will be passed to
+ * DecodeProc with length zero.
+ *
+ * @param procedure Called to decode the pixels when
+ * needed. If NULL, use SkImageDecoder::DecodeMemoryToTarget.
+ *
+ * @param cache If NULL, use the default global cache.
+ */
+ SkLazyCachingPixelRef(SkData* data,
+ SkBitmapFactory::DecodeProc procedure,
+ SkScaledImageCache* cache = NULL);
+
+ virtual ~SkLazyCachingPixelRef();
+
+ virtual SkData* onRefEncodedData() SK_OVERRIDE { return SkSafeRef(fData); }
+
+ /**
+ * A simplified version of SkBitmapFactory. Installs a new
+ * SkLazyCachingPixelRef into the provided bitmap. Will
+ * immediately call onDecodeInfo() to configure the bitmap, but
+ * will defer decoding until the first time the bitmap's pixels
+ * are locked.
+ *
+ * @param data Encoded data representing the pixels. NULL is
+ * equivalent to an empty data, and will be passed to
+ * DecodeProc with length zero.
+ *
+ * @param procedure Called to decode the pixels when
+ * needed. If NULL, use SkImageDecoder::DecodeMemoryToTarget.
+ *
+ * @param destination Bitmap that will be modified on success.
+ *
+ * @param cache If NULL, use the default global cache.
+ *
+ * @returns true on success.
+ */
+ static bool Install(SkBitmapFactory::DecodeProc procedure,
+ SkData* data,
+ SkBitmap* destination,
+ SkScaledImageCache* cache = NULL);
+
+ // No need to flatten this object. When flattening an SkBitmap,
+ // SkOrderedWriteBuffer will check the encoded data and write that
+ // instead.
+ // Future implementations of SkFlattenableWriteBuffer will need to
+ // special case for onRefEncodedData as well.
+ SK_DECLARE_UNFLATTENABLE_OBJECT()
+
+protected:
+ /**
+ * Return some information about the pixels, allowing this class
+ * to allocate pixels. @return false if anything goes wrong.
+ *
+ * This implementation calls SkBitmapFactory::DecodeProc with a
+ * NULL target.
+ */
+ virtual bool onDecodeInfo(SkISize*,
+ SkBitmap::Config*,
+ SkAlphaType*) SK_OVERRIDE;
+ /**
+ * Decode into the given pixels.
+ * @return false if anything goes wrong.
+ *
+ * This implementation calls SkBitmapFactory::DecodeProc with a
+ * target containing pixels and rowBytes.
+ */
+ virtual bool onDecode(void* pixels,
+ size_t rowBytes) SK_OVERRIDE;
+
+private:
+ SkData* fData;
+ SkBitmapFactory::DecodeProc fDecodeProc;
+ SkImage::Info fLazilyCachedInfo;
+
+ typedef SkCachingPixelRef INHERITED;
+};
+
+#endif // SkLazyCachingPixelRef_DEFINED
+

Powered by Google App Engine
This is Rietveld 408576698