Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/lazy/SkCachingPixelRef.h

Issue 54203006: Break up SkLazyPixelRef functionally into class hierarchy. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: changes for reed and scroggo Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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);
reed1 2013/11/01 21:41:10 Do we have a use-case in mind for taking the cache
hal.canary 2013/11/04 13:38:49 I restored the use-case in the unit test.
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 NULL on failure.
57 */
58 const SkImageInfo* getInfo();
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(SkImageInfo* info) = 0;
65 /**
66 * Decode into the given pixels, a block of memory of size
67 * (info->fHeight * rowBytes) bytes. Should follow the format
68 * reported by onDecodeInfo().
69 * @return false if anything goes wrong.
70 */
71 virtual bool onDecode(void* pixels, size_t rowBytes) = 0;
72
73 private:
74 bool fErrorInDecoding;
75 SkScaledImageCache* fCache;
76 SkScaledImageCache::ID* fScaledCacheId;
77 SkImageInfo fInfo;
78
79 typedef SkPixelRef INHERITED;
80 };
81
82 #endif // SkCachingPixelRef_DEFINED
83
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698