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

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

Issue 68973005: Expand pixelref to return SkImageInfo and rowbytes (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: new convention: require SkImageInfo in constructor Created 7 years 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
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkCachingPixelRef_DEFINED 8 #ifndef SkCachingPixelRef_DEFINED
9 #define SkCachingPixelRef_DEFINED 9 #define SkCachingPixelRef_DEFINED
10 10
11 #include "SkImage.h" 11 #include "SkImage.h"
12 #include "SkPixelRef.h" 12 #include "SkPixelRef.h"
13 13
14 class SkColorTable; 14 class SkColorTable;
15 15
16 /** 16 /**
17 * PixelRef which defers decoding until SkBitmap::lockPixels() is 17 * PixelRef which defers decoding until SkBitmap::lockPixels() is
18 * called. Caches the decoded images in the global 18 * called. Caches the decoded images in the global
19 * SkScaledImageCache. When the pixels are unlocked, this cache may 19 * SkScaledImageCache. When the pixels are unlocked, this cache may
20 * or be destroyed before the next lock. If so, onLockPixels will 20 * or be destroyed before the next lock. If so, onLockPixels will
21 * attempt to re-decode. 21 * attempt to re-decode.
22 * 22 *
23 * Decoding is handled by the pure-virtual functions onDecodeInfo() 23 * Decoding is handled by the pure-virtual functions onDecodeInfo()
24 * and onDecodePixels(). Subclasses of this class need only provide 24 * and onDecodePixels(). Subclasses of this class need only provide
25 * those two functions. 25 * those two functions.
26 */ 26 */
27 class SkCachingPixelRef : public SkPixelRef { 27 class SkCachingPixelRef : public SkPixelRef {
28 public: 28 public:
29 SkCachingPixelRef(); 29 SkCachingPixelRef(const SkImageInfo&);
30 virtual ~SkCachingPixelRef(); 30 virtual ~SkCachingPixelRef();
31 31
32 protected: 32 protected:
33 virtual void* onLockPixels(SkColorTable** colorTable) SK_OVERRIDE; 33 virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
34 virtual void onUnlockPixels() SK_OVERRIDE; 34 virtual void onUnlockPixels() SK_OVERRIDE;
35 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } 35 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; }
36 virtual bool onImplementsDecodeInto() SK_OVERRIDE { return true; } 36 virtual bool onImplementsDecodeInto() SK_OVERRIDE { return true; }
37 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; 37 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE;
38 38
39 /** 39 /**
40 * Configure the supplied bitmap for this pixelRef, based on 40 * Configure the supplied bitmap for this pixelRef, based on
41 * information provided by onDecodeInfo(). Does not set the 41 * information provided by onDecodeInfo(). Does not set the
42 * bitmap's pixelRef. */ 42 * bitmap's pixelRef. */
43 bool configure(SkBitmap* bitmap); 43 bool configure(SkBitmap* bitmap);
44 44
45 /** 45 /**
46 * Cache info from onDecodeInfo(). Returns false on failure.
47 */
48 bool getInfo(SkImageInfo* info);
49
50 /**
51 * Return some information about the pixels, allowing this class
52 * to allocate pixels. @return false if anything goes wrong.
53 */
54 virtual bool onDecodeInfo(SkImageInfo* info) = 0;
55 /**
56 * Decode into the given pixels, a block of memory of size 46 * Decode into the given pixels, a block of memory of size
57 * (info.fHeight - 1) * rowBytes + (info.fWidth * bytesPerPixel) 47 * (info.fHeight - 1) * rowBytes + (info.fWidth * bytesPerPixel)
58 * 48 *
59 * @param info Should be identical to the info returned by 49 * @param info Should be identical to the info returned by
60 * onDecodeInfo so that the implementation can confirm 50 * onDecodeInfo so that the implementation can confirm
61 * that the caller knows what it is asking for (config, 51 * that the caller knows what it is asking for (config,
62 * size). Thiscontract also allows the caller to specify 52 * size). Thiscontract also allows the caller to specify
63 * different output-configs, which the implementation can 53 * different output-configs, which the implementation can
64 * decide to support or not. 54 * decide to support or not.
65 * 55 *
66 * @return false if anything goes wrong. 56 * @return false if anything goes wrong.
67 */ 57 */
68 virtual bool onDecodePixels(const SkImageInfo& info, 58 virtual bool onDecodePixels(void* pixels, size_t rowBytes) = 0;
69 void* pixels,
70 size_t rowBytes) = 0;
71 59
72 private: 60 private:
73 bool fErrorInDecoding; 61 void* fScaledCacheId;
74 void* fScaledCacheId; 62 bool fErrorInDecoding;
75 SkImageInfo fInfo;
76 63
77 typedef SkPixelRef INHERITED; 64 typedef SkPixelRef INHERITED;
78 }; 65 };
79 66
80 #endif // SkCachingPixelRef_DEFINED 67 #endif // SkCachingPixelRef_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698