aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/lazy/SkBitmapFactory.h
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-22 21:38:35 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-22 21:38:35 +0000
commitf8d7d2731318cdf510ab68e6b3f5ec68ab22c8e2 (patch)
treeb62a29fabe0b0af3f8f17ffbe8d607508c1d2c00 /include/lazy/SkBitmapFactory.h
parent5c90e291425b2788f47679266d9584845ceefc2e (diff)
Create SkLazyPixelRef which performs lazy decoding.
The new pixel ref behaves similarly to SkImageRef, with some key differences: It does not depend on the images project. It requires an SkImageCache, which handles allocation and caching of the pixel memory. It takes a function signature for decoding which decodes into already allocated pixel memory rather than into an SkBitmap. Add two implementations of SkImageCache: SkLruImageCache and SkAshmemImageCache. Replace SkSerializationHelpers::DecodeBitmap with SkPicture::InstallPixelRefProc, and update sites that referenced it. SkBitmapFactory now sets the pixel ref to a new object of the new class SkLazyPixelRef, provided it has an SkImageCache for caching. Provide an option to do lazy decodes in render_pictures and bench_pictures. SkPicture: Eliminate the default parameters in the constructor. If a proc for decoding bitmaps is installed, use it to decode any encoded data in subpictures. When parsing deserializing subpictures, check for success. When serializing subpictures, pass the picture's bitmap encoder to the subpicture's call to serialize. Update BitmapFactoryTest to test its new behavior. BUG=https://code.google.com/p/skia/issues/detail?id=1008 BUG=https://code.google.com/p/skia/issues/detail?id=1009 Review URL: https://codereview.appspot.com/7060052 git-svn-id: http://skia.googlecode.com/svn/trunk@7835 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/lazy/SkBitmapFactory.h')
-rw-r--r--include/lazy/SkBitmapFactory.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/include/lazy/SkBitmapFactory.h b/include/lazy/SkBitmapFactory.h
new file mode 100644
index 0000000000..bebd3a7cee
--- /dev/null
+++ b/include/lazy/SkBitmapFactory.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkBitmapFactory_DEFINED
+#define SkBitmapFactory_DEFINED
+
+#include "SkImage.h"
+#include "SkTypes.h"
+
+class SkBitmap;
+class SkData;
+class SkImageCache;
+
+/**
+ * Factory for creating a bitmap from encoded data.
+ */
+class SkBitmapFactory {
+
+public:
+ /**
+ * Struct containing information about a pixel destination.
+ */
+ struct Target {
+ /**
+ * Pre-allocated memory.
+ */
+ void* fAddr;
+
+ /**
+ * Rowbytes of the allocated memory.
+ */
+ size_t fRowBytes;
+ };
+
+ /**
+ * Signature for a function to decode an image from encoded data.
+ */
+ typedef bool (*DecodeProc)(const void* data, size_t length, SkImage::Info*, const Target*);
+
+ /**
+ * Create a bitmap factory which uses DecodeProc for decoding.
+ * @param DecodeProc Must not be NULL.
+ */
+ SkBitmapFactory(DecodeProc);
+
+ ~SkBitmapFactory();
+
+ /**
+ * Set an image cache to use on pixelrefs provided by installPixelRef. Mutually exclusive
+ * with fCacheSelector.
+ */
+ void setImageCache(SkImageCache* cache);
+
+ /**
+ * Sets up an SkBitmap from encoded data. On success, the SkBitmap will have its Config,
+ * width, height, rowBytes and pixelref set. If fImageCache is non-NULL, or if fCacheSelector
+ * is set and returns non-NULL, the pixelref will lazily decode, and that SkImageCache will
+ * handle the pixel memory. Otherwise installPixelRef will do an immediate decode.
+ * @param SkData Encoded data.
+ * @param SkBitmap to install the pixel ref on.
+ * @return bool Whether or not a pixel ref was successfully installed.
+ */
+ bool installPixelRef(SkData*, SkBitmap*);
+
+ /**
+ * A function for selecting an SkImageCache to use based on an SkImage::Info.
+ */
+ typedef SkImageCache* (*CacheSelector)(const SkImage::Info&);
+
+ /**
+ * Set the function to be used to select which SkImageCache to use. Mutually exclusive with
+ * fImageCache.
+ */
+ void setCacheSelector(CacheSelector);
+
+private:
+ DecodeProc fDecodeProc;
+ SkImageCache* fImageCache;
+ CacheSelector fCacheSelector;
+};
+
+#endif // SkBitmapFactory_DEFINED