Chromium Code Reviews| Index: src/lazy/SkLazyCachingPixelRef.h |
| diff --git a/src/lazy/SkLazyCachingPixelRef.h b/src/lazy/SkLazyCachingPixelRef.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..72442bbf837ed8318f7103abe31b949fc41128ac |
| --- /dev/null |
| +++ b/src/lazy/SkLazyCachingPixelRef.h |
| @@ -0,0 +1,105 @@ |
| +/* |
| + * 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. |
| + */ |
| + |
| +#ifndef SkLazyCachingPixelRef_DEFINED |
| +#define SkLazyCachingPixelRef_DEFINED |
| + |
| +#include "SkCachingPixelRef.h" |
| +#include "SkBitmapFactory.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 |
| + * equivilent 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. Installes a new |
|
scroggo
2013/10/31 21:53:06
Installs.
hal.canary
2013/11/01 03:29:24
Done.
|
| + * 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 |
| + * equivilent 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 |
| + |
| + |
| + |