OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkImageRef_DEFINED | 10 #ifndef SkImageRef_DEFINED |
11 #define SkImageRef_DEFINED | 11 #define SkImageRef_DEFINED |
12 | 12 |
13 #include "SkPixelRef.h" | 13 #include "SkPixelRef.h" |
14 #include "SkBitmap.h" | 14 #include "SkBitmap.h" |
15 #include "SkImageDecoder.h" | 15 #include "SkImageDecoder.h" |
16 #include "SkString.h" | 16 #include "SkString.h" |
17 | 17 |
18 class SkImageRefPool; | 18 class SkImageRefPool; |
19 class SkStream; | 19 class SkStreamRewindable; |
20 | 20 |
21 // define this to enable dumping whenever we add/remove/purge an imageref | 21 // define this to enable dumping whenever we add/remove/purge an imageref |
22 //#define DUMP_IMAGEREF_LIFECYCLE | 22 //#define DUMP_IMAGEREF_LIFECYCLE |
23 | 23 |
24 class SkImageRef : public SkPixelRef { | 24 class SkImageRef : public SkPixelRef { |
25 public: | 25 public: |
26 /** Create a new imageref from a stream. NOTE: the stream is not copied, but | 26 /** Create a new imageref from a stream. NOTE: the stream is not copied, but |
27 since it may be accessed from another thread, the caller must ensure | 27 since it may be accessed from another thread, the caller must ensure |
28 that this imageref is the only owner of the stream. i.e. - sole | 28 that this imageref is the only owner of the stream. i.e. - sole |
29 ownership of the stream object is transferred to this imageref object. | 29 ownership of the stream object is transferred to this imageref object. |
30 | 30 |
31 @param stream The stream containing the encoded image data. This may be | 31 @param stream The stream containing the encoded image data. This may be |
32 retained (by calling ref()), so the caller should not | 32 retained (by calling ref()), so the caller should not |
33 explicitly delete it. | 33 explicitly delete it. |
34 @param config The preferred config of the decoded bitmap. | 34 @param config The preferred config of the decoded bitmap. |
35 @param sampleSize Requested sampleSize for decoding. Defaults to 1. | 35 @param sampleSize Requested sampleSize for decoding. Defaults to 1. |
36 */ | 36 */ |
37 SkImageRef(SkStream*, SkBitmap::Config config, int sampleSize = 1, SkBaseMut
ex* mutex = NULL); | 37 SkImageRef(SkStreamRewindable*, SkBitmap::Config config, int sampleSize = 1, |
| 38 SkBaseMutex* mutex = NULL); |
38 virtual ~SkImageRef(); | 39 virtual ~SkImageRef(); |
39 | 40 |
40 /** this value is passed onto the decoder. Default is true | 41 /** this value is passed onto the decoder. Default is true |
41 */ | 42 */ |
42 void setDitherImage(bool dither) { fDoDither = dither; } | 43 void setDitherImage(bool dither) { fDoDither = dither; } |
43 | 44 |
44 /** Return true if the image can be decoded. If so, and bitmap is non-null, | 45 /** Return true if the image can be decoded. If so, and bitmap is non-null, |
45 call its setConfig() with the corresponding values, but explicitly will | 46 call its setConfig() with the corresponding values, but explicitly will |
46 not set its pixels or colortable. Use SkPixelRef::lockPixels() for that. | 47 not set its pixels or colortable. Use SkPixelRef::lockPixels() for that. |
47 | 48 |
48 If there has been an error decoding the bitmap, this will return false | 49 If there has been an error decoding the bitmap, this will return false |
49 and ignore the bitmap parameter. | 50 and ignore the bitmap parameter. |
50 */ | 51 */ |
51 bool getInfo(SkBitmap* bm); | 52 bool getInfo(SkBitmap* bm); |
52 | 53 |
53 /** Return true if the image can be decoded and is opaque. Calling this | 54 /** Return true if the image can be decoded and is opaque. Calling this |
54 method will decode and set the pixels in the specified bitmap and | 55 method will decode and set the pixels in the specified bitmap and |
55 sets the isOpaque flag. | 56 sets the isOpaque flag. |
56 */ | 57 */ |
57 bool isOpaque(SkBitmap* bm); | 58 bool isOpaque(SkBitmap* bm); |
58 | 59 |
59 SkImageDecoderFactory* getDecoderFactory() const { return fFactory; } | 60 SkImageDecoderFactory* getDecoderFactory() const { return fFactory; } |
60 // returns the factory parameter | 61 // returns the factory parameter |
61 SkImageDecoderFactory* setDecoderFactory(SkImageDecoderFactory*); | 62 SkImageDecoderFactory* setDecoderFactory(SkImageDecoderFactory*); |
62 | 63 |
63 protected: | 64 protected: |
64 /** Override if you want to install a custom allocator. | 65 /** Override if you want to install a custom allocator. |
65 When this is called we will have already acquired the mutex! | 66 When this is called we will have already acquired the mutex! |
66 */ | 67 */ |
67 virtual bool onDecode(SkImageDecoder* codec, SkStream*, SkBitmap*, | 68 virtual bool onDecode(SkImageDecoder* codec, SkStreamRewindable*, SkBitmap*, |
68 SkBitmap::Config, SkImageDecoder::Mode); | 69 SkBitmap::Config, SkImageDecoder::Mode); |
69 | 70 |
70 /* Overrides from SkPixelRef | 71 /* Overrides from SkPixelRef |
71 When these are called, we will have already acquired the mutex! | 72 When these are called, we will have already acquired the mutex! |
72 */ | 73 */ |
73 | 74 |
74 virtual void* onLockPixels(SkColorTable**); | 75 virtual void* onLockPixels(SkColorTable**); |
75 // override this in your subclass to clean up when we're unlocking pixels | 76 // override this in your subclass to clean up when we're unlocking pixels |
76 virtual void onUnlockPixels() {} | 77 virtual void onUnlockPixels() {} |
77 | 78 |
78 SkImageRef(SkFlattenableReadBuffer&, SkBaseMutex* mutex = NULL); | 79 SkImageRef(SkFlattenableReadBuffer&, SkBaseMutex* mutex = NULL); |
79 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; | 80 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; |
80 | 81 |
81 SkBitmap fBitmap; | 82 SkBitmap fBitmap; |
82 | 83 |
83 private: | 84 private: |
84 SkStream* setStream(SkStream*); | 85 SkStreamRewindable* setStream(SkStreamRewindable*); |
85 // called with mutex already held. returns true if the bitmap is in the | 86 // called with mutex already held. returns true if the bitmap is in the |
86 // requested state (or further, i.e. has pixels) | 87 // requested state (or further, i.e. has pixels) |
87 bool prepareBitmap(SkImageDecoder::Mode); | 88 bool prepareBitmap(SkImageDecoder::Mode); |
88 | 89 |
89 SkImageDecoderFactory* fFactory; // may be null | 90 SkImageDecoderFactory* fFactory; // may be null |
90 SkStream* fStream; | 91 SkStreamRewindable* fStream; |
91 SkBitmap::Config fConfig; | 92 SkBitmap::Config fConfig; |
92 int fSampleSize; | 93 int fSampleSize; |
93 bool fDoDither; | 94 bool fDoDither; |
94 bool fErrorInDecoding; | 95 bool fErrorInDecoding; |
95 | 96 |
96 friend class SkImageRefPool; | 97 friend class SkImageRefPool; |
97 | 98 |
98 SkImageRef* fPrev, *fNext; | 99 SkImageRef* fPrev, *fNext; |
99 size_t ramUsed() const; | 100 size_t ramUsed() const; |
100 | 101 |
101 typedef SkPixelRef INHERITED; | 102 typedef SkPixelRef INHERITED; |
102 }; | 103 }; |
103 | 104 |
104 #endif | 105 #endif |
OLD | NEW |