Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2012 Google Inc. | |
|
scroggo
2013/10/31 21:53:06
2013
hal.canary
2013/11/01 03:29:24
Done.
| |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef SkCachingPixelRef_DEFINED | |
| 9 #define SkCachingPixelRef_DEFINED | |
| 10 | |
| 11 #include "SkImage.h" | |
| 12 #include "SkPixelRef.h" | |
| 13 #include "SkFlattenable.h" | |
| 14 #include "SkScaledImageCache.h" | |
| 15 | |
| 16 class SkColorTable; | |
| 17 class SkImageCache; | |
| 18 | |
| 19 /** | |
| 20 * PixelRef which defers decoding until SkBitmap::lockPixels() is | |
| 21 * called. Caches the decoded images in the global | |
| 22 * SkScaledImageCache. When the pixels are unlocked, this cache may | |
| 23 * 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.
| |
| 24 * re-decoded. | |
| 25 * | |
| 26 * Decoding is handled by the pure-virtual functions onDecodeInfo() | |
| 27 * and onDecode(). Subclasses of this class need only provide those | |
| 28 * two functions. | |
| 29 */ | |
| 30 class SkCachingPixelRef : public SkPixelRef { | |
| 31 public: | |
| 32 /** | |
| 33 * Create a new SkCachingPixelRef. If cache is NULL, use the | |
| 34 * default global cache. | |
| 35 * | |
| 36 * Allowing the use of a non-global cache is useful for testing. | |
| 37 */ | |
| 38 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.
| |
| 39 virtual ~SkCachingPixelRef(); | |
| 40 | |
| 41 // No need to flatten this object. When flattening an SkBitmap, | |
| 42 // 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
| |
| 43 // instead. Future implementations of SkFlattenableWriteBuffer | |
| 44 // will need to special case for onRefEncodedData as well. | |
| 45 SK_DECLARE_UNFLATTENABLE_OBJECT() | |
| 46 | |
| 47 protected: | |
| 48 virtual void* onLockPixels(SkColorTable** colorTable) SK_OVERRIDE; | |
| 49 virtual void onUnlockPixels() SK_OVERRIDE; | |
| 50 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } | |
| 51 virtual bool onImplementsDecodeInto() SK_OVERRIDE { return true; } | |
| 52 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; | |
| 53 | |
| 54 /** | |
| 55 * Configure the supplied bitmap for this pixelRef, based on | |
| 56 * information provided by onDecodeInfo(). Does not set the | |
| 57 * bitmap's pixelRef. */ | |
| 58 bool configure(SkBitmap* bitmap); | |
| 59 | |
| 60 /** | |
| 61 * Return some information about the pixels, allowing this class | |
| 62 * to allocate pixels. @return false if anything goes wrong. | |
| 63 */ | |
| 64 virtual bool onDecodeInfo(SkISize*, | |
| 65 SkBitmap::Config*, | |
| 66 SkAlphaType*) = 0; | |
| 67 /** | |
| 68 * Decode into the given pixels, a block of memory of size | |
| 69 * (size->fHeight * fRowBytes) bytes. | |
| 70 * @return false if anything goes wrong. | |
| 71 */ | |
| 72 virtual bool onDecode(void* pixels, size_t rowBytes) = 0; | |
| 73 | |
| 74 private: | |
| 75 bool fErrorInDecoding; | |
| 76 SkScaledImageCache* fCache; | |
| 77 SkScaledImageCache::ID* fScaledCacheId; | |
| 78 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
| |
| 79 SkBitmap::Config fBitmapConfig; | |
| 80 SkAlphaType fBitmapAlphaType; | |
| 81 | |
| 82 // 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.
| |
| 83 bool updateInfo(); | |
| 84 | |
| 85 typedef SkPixelRef INHERITED; | |
| 86 }; | |
| 87 | |
| 88 #endif // SkCachingPixelRef_DEFINED | |
| OLD | NEW |