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_SUPPORT_LEGACY_IMAGE_GENERATOR_RETURN |
| 19 |
18 /** | 20 /** |
19 * Takes ownership of SkImageGenerator. If this method fails for | 21 * Takes ownership of SkImageGenerator. If this method fails for |
20 * whatever reason, it will return false and immediatetely delete | 22 * whatever reason, it will return false and immediatetely delete |
21 * the generator. If it succeeds, it will modify destination | 23 * the generator. If it succeeds, it will modify destination |
22 * bitmap. | 24 * bitmap. |
23 * | 25 * |
24 * If generator is NULL, will safely return false. | 26 * If generator is NULL, will safely return false. |
25 * | 27 * |
26 * If this fails or when the SkDiscardablePixelRef that is | 28 * If this fails or when the SkDiscardablePixelRef that is |
27 * installed into destination is destroyed, it will call | 29 * installed into destination is destroyed, it will call |
(...skipping 10 matching lines...) Expand all Loading... |
38 /** | 40 /** |
39 * On success, installs a discardable pixelref into destination, based on encod
ed data. | 41 * On success, installs a discardable pixelref into destination, based on encod
ed data. |
40 * Regardless of success or failure, the caller must still balance their owners
hip of encoded. | 42 * Regardless of success or failure, the caller must still balance their owners
hip of encoded. |
41 */ | 43 */ |
42 SK_API bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* destination)
; | 44 SK_API bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* destination)
; |
43 | 45 |
44 /** | 46 /** |
45 * An interface that allows a purgeable PixelRef (such as a | 47 * An interface that allows a purgeable PixelRef (such as a |
46 * SkDiscardablePixelRef) to decode and re-decode an image as needed. | 48 * SkDiscardablePixelRef) to decode and re-decode an image as needed. |
47 */ | 49 */ |
48 class SK_API SkImageGenerator { | 50 class SK_API SkImageGenerator : public SkNoncopyable { |
49 public: | 51 public: |
50 /** | 52 /** |
51 * The PixelRef which takes ownership of this SkImageGenerator | 53 * The PixelRef which takes ownership of this SkImageGenerator |
52 * will call the image generator's destructor. | 54 * will call the image generator's destructor. |
53 */ | 55 */ |
54 virtual ~SkImageGenerator() { } | 56 virtual ~SkImageGenerator() { } |
55 | 57 |
56 /** | 58 /** |
57 * Return a ref to the encoded (i.e. compressed) representation, | 59 * Return a ref to the encoded (i.e. compressed) representation, |
58 * of this data. | 60 * of this data. |
59 * | 61 * |
60 * If non-NULL is returned, the caller is responsible for calling | 62 * If non-NULL is returned, the caller is responsible for calling |
61 * unref() on the data when it is finished. | 63 * unref() on the data when it is finished. |
62 */ | 64 */ |
63 SkData* refEncodedData() { return this->onRefEncodedData(); } | 65 SkData* refEncodedData() { return this->onRefEncodedData(); } |
64 | 66 |
65 /** | 67 /** |
66 * Return some information about the image, allowing the owner of | 68 * Return some information about the image, allowing the owner of |
67 * this object to allocate pixels. | 69 * this object to allocate pixels. |
68 * | 70 * |
69 * Repeated calls to this function should give the same results, | 71 * Repeated calls to this function should give the same results, |
70 * allowing the PixelRef to be immutable. | 72 * allowing the PixelRef to be immutable. |
71 * | 73 * |
72 * @return false if anything goes wrong. | 74 * @return false if anything goes wrong. |
73 */ | 75 */ |
74 bool getInfo(SkImageInfo* info); | 76 bool getInfo(SkImageInfo* info); |
75 | 77 |
76 /** | 78 /** |
| 79 * Used to describe the result of a call to getPixels(). |
| 80 * |
| 81 * Result is the union of possible results from subclasses. |
| 82 */ |
| 83 enum Result { |
| 84 /** |
| 85 * General return value for success. |
| 86 */ |
| 87 kSuccess, |
| 88 /** |
| 89 * The input is incomplete. A partial image was generated. |
| 90 */ |
| 91 kIncompleteInput, |
| 92 /** |
| 93 * The generator cannot convert to match the request, ignoring |
| 94 * dimensions. |
| 95 */ |
| 96 kInvalidConversion, |
| 97 /** |
| 98 * The generator cannot scale to requested size. |
| 99 */ |
| 100 kInvalidScale, |
| 101 /** |
| 102 * Parameters (besides info) are invalid. e.g. NULL pixels, rowBytes |
| 103 * too small, etc. |
| 104 */ |
| 105 kInvalidParameters, |
| 106 /** |
| 107 * The input did not contain a valid image. |
| 108 */ |
| 109 kInvalidInput, |
| 110 /** |
| 111 * Fulfilling this request requires rewinding the input, which is not |
| 112 * supported for this input. |
| 113 */ |
| 114 kCouldNotRewind, |
| 115 /** |
| 116 * This method is not implemented by this generator. |
| 117 */ |
| 118 kUnimplemented, |
| 119 }; |
| 120 |
| 121 /** |
77 * Decode into the given pixels, a block of memory of size at | 122 * Decode into the given pixels, a block of memory of size at |
78 * least (info.fHeight - 1) * rowBytes + (info.fWidth * | 123 * least (info.fHeight - 1) * rowBytes + (info.fWidth * |
79 * bytesPerPixel) | 124 * bytesPerPixel) |
80 * | 125 * |
81 * Repeated calls to this function should give the same results, | 126 * Repeated calls to this function should give the same results, |
82 * allowing the PixelRef to be immutable. | 127 * allowing the PixelRef to be immutable. |
83 * | 128 * |
84 * @param info A description of the format (config, size) | 129 * @param info A description of the format (config, size) |
85 * expected by the caller. This can simply be identical | 130 * expected by the caller. This can simply be identical |
86 * to the info returned by getInfo(). | 131 * to the info returned by getInfo(). |
87 * | 132 * |
88 * This contract also allows the caller to specify | 133 * This contract also allows the caller to specify |
89 * different output-configs, which the implementation can | 134 * different output-configs, which the implementation can |
90 * decide to support or not. | 135 * decide to support or not. |
91 * | 136 * |
| 137 * A size that does not match getInfo() implies a request |
| 138 * to scale. If the generator cannot perform this scale, |
| 139 * it will return kInvalidScale. |
| 140 * |
92 * If info is kIndex8_SkColorType, then the caller must provide storage for
up to 256 | 141 * If info is kIndex8_SkColorType, then the caller must provide storage for
up to 256 |
93 * SkPMColor values in ctable. On success the generator must copy N colors
into that storage, | 142 * SkPMColor values in ctable. On success the generator must copy N colors
into that storage, |
94 * (where N is the logical number of table entries) and set ctableCount to
N. | 143 * (where N is the logical number of table entries) and set ctableCount to
N. |
95 * | 144 * |
96 * If info is not kIndex8_SkColorType, then the last two parameters may be
NULL. If ctableCount | 145 * If info is not kIndex8_SkColorType, then the last two parameters may be
NULL. If ctableCount |
97 * is not null, it will be set to 0. | 146 * is not null, it will be set to 0. |
98 * | 147 * |
99 * @return false if anything goes wrong or if the image info is | 148 * @return Result kSuccess, or another value explaining the type of failure
. |
100 * unsupported. | |
101 */ | 149 */ |
102 bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, | 150 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
103 SkPMColor ctable[], int* ctableCount); | 151 SkPMColor ctable[], int* ctableCount); |
104 | 152 |
105 /** | 153 /** |
106 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType. | 154 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType. |
107 */ | 155 */ |
108 bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); | 156 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); |
109 | 157 |
110 /** | 158 /** |
111 * If planes or rowBytes is NULL or if any entry in planes is NULL or if an
y entry in rowBytes | 159 * If planes or rowBytes is NULL or if any entry in planes is NULL or if an
y entry in rowBytes |
112 * is 0, this imagegenerator should output the sizes and return true if it
can efficiently | 160 * is 0, this imagegenerator should output the sizes and return true if it
can efficiently |
113 * return YUV planar data. If it cannot, it should return false. Note that
either planes and | 161 * return YUV planar data. If it cannot, it should return false. Note that
either planes and |
114 * rowBytes are both fully defined and non NULL/non 0 or they are both NULL
or have NULL or 0 | 162 * rowBytes are both fully defined and non NULL/non 0 or they are both NULL
or have NULL or 0 |
115 * entries only. Having only partial planes/rowBytes information is not sup
ported. | 163 * entries only. Having only partial planes/rowBytes information is not sup
ported. |
116 * | 164 * |
117 * If all planes and rowBytes entries are non NULL or non 0, then it should
copy the | 165 * If all planes and rowBytes entries are non NULL or non 0, then it should
copy the |
118 * associated YUV data into those planes of memory supplied by the caller.
It should validate | 166 * associated YUV data into those planes of memory supplied by the caller.
It should validate |
119 * that the sizes match what it expected. If the sizes do not match, it sho
uld return false. | 167 * that the sizes match what it expected. If the sizes do not match, it sho
uld return false. |
120 */ | 168 */ |
121 bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], | 169 bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
122 SkYUVColorSpace* colorSpace); | 170 SkYUVColorSpace* colorSpace); |
123 | 171 |
124 /** | 172 /** |
125 * If the default image decoder system can interpret the specified (encoded
) data, then | 173 * If the default image decoder system can interpret the specified (encoded
) data, then |
126 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E
ither way | 174 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E
ither way |
127 * the caller is still responsible for managing their ownership of the data
. | 175 * the caller is still responsible for managing their ownership of the data
. |
128 */ | 176 */ |
129 static SkImageGenerator* NewFromData(SkData*); | 177 static SkImageGenerator* NewFromData(SkData*); |
130 | 178 |
131 protected: | 179 protected: |
132 virtual SkData* onRefEncodedData(); | 180 virtual SkData* onRefEncodedData(); |
133 virtual bool onGetInfo(SkImageInfo* info); | 181 virtual bool onGetInfo(SkImageInfo* info); |
| 182 #ifdef SK_SUPPORT_LEGACY_IMAGE_GENERATOR_RETURN |
134 virtual bool onGetPixels(const SkImageInfo& info, | 183 virtual bool onGetPixels(const SkImageInfo& info, |
135 void* pixels, size_t rowBytes, | 184 void* pixels, size_t rowBytes, |
136 SkPMColor ctable[], int* ctableCount); | 185 SkPMColor ctable[], int* ctableCount); |
| 186 #endif |
| 187 // TODO (scroggo): rename to onGetPixels. |
| 188 virtual Result onGetPixelsEnum(const SkImageInfo& info, |
| 189 void* pixels, size_t rowBytes, |
| 190 SkPMColor ctable[], int* ctableCount); |
137 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3]); | 191 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3]); |
138 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], | 192 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], |
139 SkYUVColorSpace* colorSpace); | 193 SkYUVColorSpace* colorSpace); |
140 }; | 194 }; |
141 | 195 |
142 #endif // SkImageGenerator_DEFINED | 196 #endif // SkImageGenerator_DEFINED |
OLD | NEW |