Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 Google Inc. | |
| 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 "SkScaledImageCache.h" | |
| 14 | |
| 15 class SkColorTable; | |
| 16 class SkImageCache; | |
| 17 | |
| 18 /** | |
| 19 * PixelRef which defers decoding until SkBitmap::lockPixels() is | |
| 20 * called. Caches the decoded images in the global | |
| 21 * SkScaledImageCache. When the pixels are unlocked, this cache may | |
| 22 * or be destroyed before the next lock. If so, onLockPixels will | |
| 23 * attempt to re-decode. | |
| 24 * | |
| 25 * Decoding is handled by the pure-virtual functions onDecodeInfo() | |
| 26 * and onDecode(). Subclasses of this class need only provide those | |
| 27 * two functions. | |
| 28 */ | |
| 29 class SkCachingPixelRef : public SkPixelRef { | |
| 30 public: | |
| 31 /** | |
| 32 * Create a new SkCachingPixelRef. If cache is NULL, use the | |
| 33 * default global cache. | |
| 34 * | |
| 35 * Allowing the use of a non-global cache is useful for testing. | |
| 36 * Note that the SkCachingPixelRef does not take ownership of the | |
| 37 * SkScaledImageCache. | |
| 38 */ | |
| 39 explicit SkCachingPixelRef(SkScaledImageCache* cache = NULL); | |
| 40 virtual ~SkCachingPixelRef(); | |
| 41 | |
| 42 protected: | |
| 43 virtual void* onLockPixels(SkColorTable** colorTable) SK_OVERRIDE; | |
| 44 virtual void onUnlockPixels() SK_OVERRIDE; | |
| 45 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } | |
| 46 virtual bool onImplementsDecodeInto() SK_OVERRIDE { return true; } | |
| 47 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; | |
| 48 | |
| 49 /** | |
| 50 * Configure the supplied bitmap for this pixelRef, based on | |
| 51 * information provided by onDecodeInfo(). Does not set the | |
| 52 * bitmap's pixelRef. */ | |
| 53 bool configure(SkBitmap* bitmap); | |
| 54 | |
| 55 /** | |
| 56 * Cache info from onDecodeInfo(). Returns info with negative size | |
| 57 * on failure. | |
| 58 */ | |
| 59 const SkImageInfo& getInfo(); | |
| 60 | |
| 61 /** | |
| 62 * Return some information about the pixels, allowing this class | |
| 63 * to allocate pixels. @return false if anything goes wrong. | |
| 64 */ | |
| 65 virtual bool onDecodeInfo(SkImageInfo* info) = 0; | |
| 66 /** | |
| 67 * Decode into the given pixels, a block of memory of size | |
| 68 * (info->fHeight * fRowBytes) bytes. Should follow the format | |
|
scroggo
2013/11/01 18:27:55
fRowBytes should be rowBytes, since this class kno
hal.canary
2013/11/01 18:52:59
Done.
| |
| 69 * reported by onDecodeInfo(). | |
| 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 SkImageInfo fInfo; | |
| 79 | |
| 80 typedef SkPixelRef INHERITED; | |
| 81 }; | |
| 82 | |
| 83 #endif // SkCachingPixelRef_DEFINED | |
| 84 | |
| OLD | NEW |