OLD | NEW |
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 SkImageGenerator_DEFINED | 8 #ifndef SkImageGenerator_DEFINED |
9 #define SkImageGenerator_DEFINED | 9 #define SkImageGenerator_DEFINED |
10 | 10 |
11 #include "SkColor.h" | 11 #include "SkColor.h" |
12 #include "SkImageInfo.h" | 12 #include "SkImageInfo.h" |
13 | 13 |
14 class SkBitmap; | 14 class SkBitmap; |
15 class SkData; | 15 class SkData; |
16 class SkImageGenerator; | 16 class SkImageGenerator; |
17 | 17 |
18 //#define SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS | |
19 | |
20 /** | 18 /** |
21 * Takes ownership of SkImageGenerator. If this method fails for | 19 * Takes ownership of SkImageGenerator. If this method fails for |
22 * whatever reason, it will return false and immediatetely delete | 20 * whatever reason, it will return false and immediatetely delete |
23 * the generator. If it succeeds, it will modify destination | 21 * the generator. If it succeeds, it will modify destination |
24 * bitmap. | 22 * bitmap. |
25 * | 23 * |
26 * If generator is NULL, will safely return false. | 24 * If generator is NULL, will safely return false. |
27 * | 25 * |
28 * If this fails or when the SkDiscardablePixelRef that is | 26 * If this fails or when the SkDiscardablePixelRef that is |
29 * installed into destination is destroyed, it will call | 27 * installed into destination is destroyed, it will call |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 * If non-NULL is returned, the caller is responsible for calling | 60 * If non-NULL is returned, the caller is responsible for calling |
63 * unref() on the data when it is finished. | 61 * unref() on the data when it is finished. |
64 */ | 62 */ |
65 SkData* refEncodedData() { return this->onRefEncodedData(); } | 63 SkData* refEncodedData() { return this->onRefEncodedData(); } |
66 | 64 |
67 /** | 65 /** |
68 * Return the ImageInfo associated with this generator. | 66 * Return the ImageInfo associated with this generator. |
69 */ | 67 */ |
70 const SkImageInfo& getInfo() const { return fInfo; } | 68 const SkImageInfo& getInfo() const { return fInfo; } |
71 | 69 |
72 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS | |
73 /** | |
74 * Used to describe the result of a call to getPixels(). | |
75 * | |
76 * Result is the union of possible results from subclasses. | |
77 */ | |
78 enum Result { | |
79 /** | |
80 * General return value for success. | |
81 */ | |
82 kSuccess, | |
83 /** | |
84 * The input is incomplete. A partial image was generated. | |
85 */ | |
86 kIncompleteInput, | |
87 /** | |
88 * The generator cannot convert to match the request, ignoring | |
89 * dimensions. | |
90 */ | |
91 kInvalidConversion, | |
92 /** | |
93 * The generator cannot scale to requested size. | |
94 */ | |
95 kInvalidScale, | |
96 /** | |
97 * Parameters (besides info) are invalid. e.g. NULL pixels, rowBytes | |
98 * too small, etc. | |
99 */ | |
100 kInvalidParameters, | |
101 /** | |
102 * The input did not contain a valid image. | |
103 */ | |
104 kInvalidInput, | |
105 /** | |
106 * Fulfilling this request requires rewinding the input, which is not | |
107 * supported for this input. | |
108 */ | |
109 kCouldNotRewind, | |
110 /** | |
111 * This method is not implemented by this generator. | |
112 */ | |
113 kUnimplemented, | |
114 }; | |
115 | |
116 /** | |
117 * Whether or not the memory passed to getPixels is zero initialized. | |
118 */ | |
119 enum ZeroInitialized { | |
120 /** | |
121 * The memory passed to getPixels is zero initialized. The SkCodec | |
122 * may take advantage of this by skipping writing zeroes. | |
123 */ | |
124 kYes_ZeroInitialized, | |
125 /** | |
126 * The memory passed to getPixels has not been initialized to zero, | |
127 * so the SkCodec must write all zeroes to memory. | |
128 * | |
129 * This is the default. It will be used if no Options struct is used. | |
130 */ | |
131 kNo_ZeroInitialized, | |
132 }; | |
133 | |
134 /** | |
135 * Additional options to pass to getPixels. | |
136 */ | |
137 struct Options { | |
138 Options() | |
139 : fZeroInitialized(kNo_ZeroInitialized) {} | |
140 | |
141 ZeroInitialized fZeroInitialized; | |
142 }; | |
143 #endif | |
144 | |
145 /** | 70 /** |
146 * Decode into the given pixels, a block of memory of size at | 71 * Decode into the given pixels, a block of memory of size at |
147 * least (info.fHeight - 1) * rowBytes + (info.fWidth * | 72 * least (info.fHeight - 1) * rowBytes + (info.fWidth * |
148 * bytesPerPixel) | 73 * bytesPerPixel) |
149 * | 74 * |
150 * Repeated calls to this function should give the same results, | 75 * Repeated calls to this function should give the same results, |
151 * allowing the PixelRef to be immutable. | 76 * allowing the PixelRef to be immutable. |
152 * | 77 * |
153 * @param info A description of the format (config, size) | 78 * @param info A description of the format (config, size) |
154 * expected by the caller. This can simply be identical | 79 * expected by the caller. This can simply be identical |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E
ither way | 124 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E
ither way |
200 * the caller is still responsible for managing their ownership of the data
. | 125 * the caller is still responsible for managing their ownership of the data
. |
201 */ | 126 */ |
202 static SkImageGenerator* NewFromEncoded(SkData*); | 127 static SkImageGenerator* NewFromEncoded(SkData*); |
203 | 128 |
204 protected: | 129 protected: |
205 SkImageGenerator(const SkImageInfo& info) : fInfo(info) {} | 130 SkImageGenerator(const SkImageInfo& info) : fInfo(info) {} |
206 | 131 |
207 virtual SkData* onRefEncodedData(); | 132 virtual SkData* onRefEncodedData(); |
208 | 133 |
209 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS | |
210 virtual Result onGetPixels(const SkImageInfo& info, | |
211 void* pixels, size_t rowBytes, const Options&, | |
212 SkPMColor ctable[], int* ctableCount); | |
213 #else | |
214 virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBy
tes, | 134 virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBy
tes, |
215 SkPMColor ctable[], int* ctableCount); | 135 SkPMColor ctable[], int* ctableCount); |
216 #endif | |
217 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3]); | 136 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3]); |
218 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], | 137 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], |
219 SkYUVColorSpace* colorSpace); | 138 SkYUVColorSpace* colorSpace); |
220 | 139 |
221 private: | 140 private: |
222 const SkImageInfo fInfo; | 141 const SkImageInfo fInfo; |
223 | 142 |
224 // This is our default impl, which may be different on different platforms. | 143 // This is our default impl, which may be different on different platforms. |
225 // It is called from NewFromEncoded() after it has checked for any runtime f
actory. | 144 // It is called from NewFromEncoded() after it has checked for any runtime f
actory. |
226 // The SkData will never be NULL, as that will have been checked by NewFromE
ncoded. | 145 // The SkData will never be NULL, as that will have been checked by NewFromE
ncoded. |
227 static SkImageGenerator* NewFromEncodedImpl(SkData*); | 146 static SkImageGenerator* NewFromEncodedImpl(SkData*); |
228 }; | 147 }; |
229 | 148 |
230 #endif // SkImageGenerator_DEFINED | 149 #endif // SkImageGenerator_DEFINED |
OLD | NEW |