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

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: lint nits 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-decoded.
scroggo 2013/11/01 15:48:00 re-decode.
hal.canary 2013/11/01 16:31:09 Done.
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 * Return some information about the pixels, allowing this class
57 * to allocate pixels. @return false if anything goes wrong.
58 */
59 virtual bool onDecodeInfo(SkISize*,
60 SkBitmap::Config*,
61 SkAlphaType*) = 0;
62 /**
63 * Decode into the given pixels, a block of memory of size
64 * (size->fHeight * fRowBytes) bytes.
65 * @return false if anything goes wrong.
66 */
67 virtual bool onDecode(void* pixels, size_t rowBytes) = 0;
68
69 private:
70 bool fErrorInDecoding;
71 SkScaledImageCache* fCache;
72 SkScaledImageCache::ID* fScaledCacheId;
73 SkISize fBitmapSize;
74 SkBitmap::Config fBitmapConfig;
75 SkAlphaType fBitmapAlphaType;
76
77 // Cache info from onDecodeInfo(). Returns false on failure.
78 bool updateInfo();
79
80 typedef SkPixelRef INHERITED;
81 };
82
83 #endif // SkCachingPixelRef_DEFINED
84
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698