Chromium Code Reviews| Index: src/lazy/SkCachingPixelRef.h |
| diff --git a/src/lazy/SkCachingPixelRef.h b/src/lazy/SkCachingPixelRef.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..694879eb6fd5c51989bb2b41cf3d6a8bb6f962e7 |
| --- /dev/null |
| +++ b/src/lazy/SkCachingPixelRef.h |
| @@ -0,0 +1,88 @@ |
| +/* |
| + * 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 SkCachingPixelRef_DEFINED |
| +#define SkCachingPixelRef_DEFINED |
| + |
| +#include "SkImage.h" |
| +#include "SkPixelRef.h" |
| +#include "SkFlattenable.h" |
| +#include "SkScaledImageCache.h" |
| + |
| +class SkColorTable; |
| +class SkImageCache; |
| + |
| +/** |
| + * PixelRef which defers decoding until SkBitmap::lockPixels() is |
| + * called. Caches the decoded images in the global |
| + * SkScaledImageCache. When the pixels are unlocked, this cache may |
| + * or be destroyed before the next lock. If so, the image will be |
|
scroggo
2013/10/31 21:53:06
or may not*
hal.canary
2013/11/01 03:29:24
Done.
|
| + * re-decoded. |
| + * |
| + * Decoding is handled by the pure-virtual functions onDecodeInfo() |
| + * and onDecode(). Subclasses of this class need only provide those |
| + * two functions. |
| + */ |
| +class SkCachingPixelRef : public SkPixelRef { |
| +public: |
| + /** |
| + * Create a new SkCachingPixelRef. If cache is NULL, use the |
| + * default global cache. |
| + * |
| + * Allowing the use of a non-global cache is useful for testing. |
| + */ |
| + explicit SkCachingPixelRef(SkScaledImageCache* cache = NULL); |
|
scroggo
2013/10/31 21:53:06
It may be obvious, but should we point out that Sk
hal.canary
2013/11/01 03:29:24
Done.
|
| + virtual ~SkCachingPixelRef(); |
| + |
| + // No need to flatten this object. When flattening an SkBitmap, |
| + // SkOrderedWriteBuffer will check the encoded data and write that |
|
scroggo
2013/10/31 21:53:06
This statement is only true if you have implemente
hal.canary
2013/11/01 03:29:24
I'll remove this section for now. Since this is a
|
| + // instead. Future implementations of SkFlattenableWriteBuffer |
| + // will need to special case for onRefEncodedData as well. |
| + SK_DECLARE_UNFLATTENABLE_OBJECT() |
| + |
| +protected: |
| + virtual void* onLockPixels(SkColorTable** colorTable) SK_OVERRIDE; |
| + virtual void onUnlockPixels() SK_OVERRIDE; |
| + virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } |
| + virtual bool onImplementsDecodeInto() SK_OVERRIDE { return true; } |
| + virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; |
| + |
| + /** |
| + * Configure the supplied bitmap for this pixelRef, based on |
| + * information provided by onDecodeInfo(). Does not set the |
| + * bitmap's pixelRef. */ |
| + bool configure(SkBitmap* bitmap); |
| + |
| + /** |
| + * Return some information about the pixels, allowing this class |
| + * to allocate pixels. @return false if anything goes wrong. |
| + */ |
| + virtual bool onDecodeInfo(SkISize*, |
| + SkBitmap::Config*, |
| + SkAlphaType*) = 0; |
| + /** |
| + * Decode into the given pixels, a block of memory of size |
| + * (size->fHeight * fRowBytes) bytes. |
| + * @return false if anything goes wrong. |
| + */ |
| + virtual bool onDecode(void* pixels, size_t rowBytes) = 0; |
| + |
| +private: |
| + bool fErrorInDecoding; |
| + SkScaledImageCache* fCache; |
| + SkScaledImageCache::ID* fScaledCacheId; |
| + SkISize fBitmapSize; |
|
scroggo
2013/10/31 21:53:06
Why do you have these three instead of an SkImage:
hal.canary
2013/11/01 03:29:24
I wanted to keep the onDecodeInfo() interface simp
scroggo
2013/11/01 15:48:00
Wouldn't
bool onDecodeInfo(SkImage::Info*)
be si
|
| + SkBitmap::Config fBitmapConfig; |
| + SkAlphaType fBitmapAlphaType; |
| + |
| + // lazily initialized our cached info. Returns NULL on failure. |
|
scroggo
2013/10/31 21:53:06
Returns false on failure.
hal.canary
2013/11/01 03:29:24
Done.
|
| + bool updateInfo(); |
| + |
| + typedef SkPixelRef INHERITED; |
| +}; |
| + |
| +#endif // SkCachingPixelRef_DEFINED |