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

Unified Diff: src/lazy/SkLazyCachingPixelRef.h

Issue 68973005: Expand pixelref to return SkImageInfo and rowbytes (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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..65bca776a196b26b49658bc956fca602e35c0f08
--- /dev/null
+++ b/src/lazy/SkLazyCachingPixelRef.h
@@ -0,0 +1,89 @@
+/*
+ * 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 {
scroggo 2013/12/06 14:50:33 I think Hal deleted this file?
reed1 2013/12/06 15:48:46 Done.
+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.
+ */
+ SkLazyCachingPixelRef(const SkImageInfo&, SkData* data,
+ SkBitmapFactory::DecodeProc procedure);
+
+ 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.
+ *
+ * @returns true on success.
+ */
+ static bool Install(SkBitmapFactory::DecodeProc procedure,
+ SkData* data,
+ SkBitmap* destination);
+
+ // 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:
+ /**
+ * Decode into the given pixels, a block of memory of size
+ * (info.fHeight * rowBytes) bytes.
+ *
+ * @param info Should be identical to the info returned by
+ * onDecodeInfo so that the implementation can confirm
+ * that the caller knows what its asking for (config,
+ * size).
+ *
+ * @return false if anything goes wrong.
+ */
+ virtual bool onDecodePixels(void* pixels,
+ size_t rowBytes) SK_OVERRIDE;
+
+private:
+ SkData* fData;
+ SkBitmapFactory::DecodeProc fDecodeProc;
+
+ typedef SkCachingPixelRef INHERITED;
+};
+
+#endif // SkLazyCachingPixelRef_DEFINED

Powered by Google App Engine
This is Rietveld 408576698