Chromium Code Reviews| 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 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 * Regarding the GrTextureParams parameter: | 146 * Regarding the GrTextureParams parameter: |
| 147 * | 147 * |
| 148 * If the context (the provided one or the generator's intrinsic one) deter mines that to | 148 * If the context (the provided one or the generator's intrinsic one) deter mines that to |
| 149 * support the specified usage, it must return a different sized texture it may, | 149 * support the specified usage, it must return a different sized texture it may, |
| 150 * so the caller must inspect the texture's width/height and compare them t o the generator's | 150 * so the caller must inspect the texture's width/height and compare them t o the generator's |
| 151 * getInfo() width/height. For readback usage use GrTextureParams::ClampNoF ilter() | 151 * getInfo() width/height. For readback usage use GrTextureParams::ClampNoF ilter() |
| 152 */ | 152 */ |
| 153 GrTexture* generateTexture(GrContext*, const SkIRect* subset = nullptr); | 153 GrTexture* generateTexture(GrContext*, const SkIRect* subset = nullptr); |
| 154 | 154 |
| 155 /** | 155 /** |
| 156 * Some generators can efficiently scale their contents. If this is support ed, the generator | |
| 157 * may only support certain scaled dimensions. Call this with the desired s cale factor, | |
| 158 * and it will return true if scaling is supported, and in supportedSizes[] it will return | |
| 159 * the two nearest supported dimensions... | |
| 160 * | |
| 161 * If the requested scale is exactly supported, then both entries | |
| 162 * supporedSizes[0] and supportedSizes[1] will hold the same dimensions. | |
| 163 * | |
| 164 * However, often the requested size may result in a fractional resulting w idth/height, | |
| 165 * and or not be natively supported by the generator. (e.g. the scale is 1/ 3, but the | |
| 166 * generator only performs native scaling on powers-of-2 fractions). In thi s case... | |
| 167 * - if the generator can natively scale at a smaller size (e.g. 1/4), that will be returned | |
| 168 * in supportedSizes[0] | |
| 169 * - if the generator can natively scale at a larger size (e.g. 1/2), that will be returned | |
| 170 * in sukpportedSizes[1] | |
|
msarett
2015/10/29 19:50:24
nit: *supported
reed1
2015/11/02 20:52:59
Done.
| |
| 171 * - if the generator can only natively scale smaller, or only larger, than the | |
| 172 * requested scale, then that 1 native size will returned in both [0] a nd [1]. | |
| 173 * | |
| 174 * If no native scaling is supported, or scale is invalid (e.g. scale <= 0 || scale > 1) | |
| 175 * this will return false, and supportedSizes[] will be undefined. | |
| 176 */ | |
| 177 bool computeScaledDimensions(SkScalar scale, SkISize supportedSizes[2]); | |
|
msarett
2015/10/29 19:50:24
I prefer these comments.
reed1
2015/11/02 20:52:59
Done.
| |
| 178 | |
| 179 /** | |
| 180 * Some generators can efficiently scale their contents. If this is support ed, the generator | |
| 181 * may only support certain scaled dimensions. Call this with the desired s cale factor, | |
| 182 * and it will return true if scaling is supported, and in supportedSizes[] it will return | |
| 183 * the two nearest supported dimensions. | |
| 184 * | |
| 185 * requestedWidth = originalWidth * scale | |
| 186 * requestedHeight = originalHeight * scale | |
| 187 * | |
| 188 * The calculated requested dimensions may be fractional, or the generator may not natively | |
| 189 * support scaling to those values (e.g. JPEG typically can only scale by p owers of 2). | |
|
msarett
2015/10/29 19:50:24
JPEG gives us all the eighths. Ex: 1/8, 1/4, 3/8,
reed1
2015/11/02 20:52:59
Gone
| |
| 190 * | |
| 191 * This API allows the generator to report back 2 "suggested" scaled dimens ions, that would | |
| 192 * be natively supported. The generator will try to return one that is <= t he requested | |
| 193 * dimensions, and one that is >= the requested dimension. This allows the caller | |
| 194 * to make the choice of which approximate size to pass to generateScaledPi xels(). | |
| 195 */ | |
| 196 bool computeScaledDimensions(SkScalar scale, SkISize supportedSizes[2]); | |
| 197 | |
| 198 /** | |
| 199 * Request that pixels be scaled to fit into the specified scaledInfo dimen sions. | |
| 200 * If scaledClip is not null, it specifies the subset of the scaled pixels that should | |
| 201 * be returned. It will be in the scaled coordinate system (not the origina l), and is only | |
| 202 * valid if it is entirely contained inside the scaled dimensions... | |
| 203 * | |
| 204 * SkIRect scaledBounds = SkIRect::MakeWH(0, 0, scaledInfo.width(), scaledI nfo.height()); | |
| 205 * bool valid = scaledBounds.contains(scaledClip); | |
| 206 * | |
| 207 * If the requested scaledInfo is not supported by the generator, or it enc ounters an error, | |
| 208 * or the scaledClip is invalid, this returns false and the contents of pix els is undefined. | |
| 209 */ | |
| 210 bool generateScaledPixels(const SkImageInfo& scaledInfo, void* pixels, size_ t rowBytes, | |
|
msarett
2015/10/29 19:50:24
I'm indifferent on this, but I lean towards this A
aleksandar.stojiljkovic
2015/10/29 20:39:35
if SkImageInfo can be supplied here, i.e. 565 or I
reed1
2015/11/02 20:52:59
Done.
reed1
2015/11/02 20:52:59
1. 565
Decoding (generating) into 565 is pretty h
| |
| 211 const SkIRect* scaledClip); | |
| 212 | |
| 213 /** | |
| 214 * Request a scaled version (specified by scaledDimension) of the pixels. | |
| 215 * If the caller wants only a subset of the scaled result, it will put the top/left coordiante | |
| 216 * of the desired subset in offset. | |
| 217 * info.width and info.height are the dimensions of the desired subset. | |
| 218 */ | |
| 219 bool generateScaledPixels(const SkISize& scaledDimensions, const SkIPoint& o ffset, | |
| 220 const SkImageInfo& info, void* pixels, size_t rowB ytes); | |
| 221 | |
| 222 /** | |
| 156 * If the default image decoder system can interpret the specified (encoded ) data, then | 223 * If the default image decoder system can interpret the specified (encoded ) data, then |
| 157 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E ither way | 224 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E ither way |
| 158 * the caller is still responsible for managing their ownership of the data . | 225 * the caller is still responsible for managing their ownership of the data . |
| 159 */ | 226 */ |
| 160 static SkImageGenerator* NewFromEncoded(SkData*); | 227 static SkImageGenerator* NewFromEncoded(SkData*); |
| 161 | 228 |
| 162 /** Return a new image generator backed by the specified picture. If the si ze is empty or | 229 /** Return a new image generator backed by the specified picture. If the si ze is empty or |
| 163 * the picture is NULL, this returns NULL. | 230 * the picture is NULL, this returns NULL. |
| 164 * The optional matrix and paint arguments are passed to drawPicture() at r asterization | 231 * The optional matrix and paint arguments are passed to drawPicture() at r asterization |
| 165 * time. | 232 * time. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 192 virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBy tes, | 259 virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBy tes, |
| 193 SkPMColor ctable[], int* ctableCount); | 260 SkPMColor ctable[], int* ctableCount); |
| 194 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3]); | 261 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3]); |
| 195 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3], | 262 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3], |
| 196 SkYUVColorSpace* colorSpace); | 263 SkYUVColorSpace* colorSpace); |
| 197 | 264 |
| 198 virtual GrTexture* onGenerateTexture(GrContext*, const SkIRect*) { | 265 virtual GrTexture* onGenerateTexture(GrContext*, const SkIRect*) { |
| 199 return nullptr; | 266 return nullptr; |
| 200 } | 267 } |
| 201 | 268 |
| 269 virtual bool onComputeScaledDimensions(SkScalar scale, SkISize supportedSize s[2]) { | |
| 270 return false; | |
| 271 } | |
| 272 virtual bool onGenerateScaledPixels(const SkImageInfo& info, void* pixels, s ize_t rowBytes, | |
| 273 const SkIRect* subset) { | |
| 274 return false; | |
| 275 } | |
| 276 | |
| 202 bool tryGenerateBitmap(SkBitmap* bm, const SkImageInfo* optionalInfo, SkBitm ap::Allocator*); | 277 bool tryGenerateBitmap(SkBitmap* bm, const SkImageInfo* optionalInfo, SkBitm ap::Allocator*); |
| 203 | 278 |
| 204 private: | 279 private: |
| 205 const SkImageInfo fInfo; | 280 const SkImageInfo fInfo; |
| 206 const uint32_t fUniqueID; | 281 const uint32_t fUniqueID; |
| 207 | 282 |
| 208 // This is our default impl, which may be different on different platforms. | 283 // This is our default impl, which may be different on different platforms. |
| 209 // It is called from NewFromEncoded() after it has checked for any runtime f actory. | 284 // It is called from NewFromEncoded() after it has checked for any runtime f actory. |
| 210 // The SkData will never be NULL, as that will have been checked by NewFromE ncoded. | 285 // The SkData will never be NULL, as that will have been checked by NewFromE ncoded. |
| 211 static SkImageGenerator* NewFromEncodedImpl(SkData*); | 286 static SkImageGenerator* NewFromEncodedImpl(SkData*); |
| 212 }; | 287 }; |
| 213 | 288 |
| 214 #endif // SkImageGenerator_DEFINED | 289 #endif // SkImageGenerator_DEFINED |
| OLD | NEW |