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 27 matching lines...) Expand all Loading... | |
| 38 /** | 38 /** |
| 39 * On success, installs a discardable pixelref into destination, based on encod ed data. | 39 * 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. | 40 * Regardless of success or failure, the caller must still balance their owners hip of encoded. |
| 41 */ | 41 */ |
| 42 SK_API bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* destination) ; | 42 SK_API bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* destination) ; |
| 43 | 43 |
| 44 /** | 44 /** |
| 45 * An interface that allows a purgeable PixelRef (such as a | 45 * An interface that allows a purgeable PixelRef (such as a |
| 46 * SkDiscardablePixelRef) to decode and re-decode an image as needed. | 46 * SkDiscardablePixelRef) to decode and re-decode an image as needed. |
| 47 */ | 47 */ |
| 48 class SK_API SkImageGenerator { | 48 class SK_API SkImageGenerator : public SkNoncopyable { |
|
scroggo
2015/02/11 16:01:25
Hal, was this previously deliberately copyable?
| |
| 49 public: | 49 public: |
| 50 /** | 50 /** |
| 51 * The PixelRef which takes ownership of this SkImageGenerator | 51 * The PixelRef which takes ownership of this SkImageGenerator |
| 52 * will call the image generator's destructor. | 52 * will call the image generator's destructor. |
| 53 */ | 53 */ |
| 54 virtual ~SkImageGenerator() { } | 54 virtual ~SkImageGenerator() { } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * Return a ref to the encoded (i.e. compressed) representation, | 57 * Return a ref to the encoded (i.e. compressed) representation, |
| 58 * of this data. | 58 * of this data. |
| 59 * | 59 * |
| 60 * If non-NULL is returned, the caller is responsible for calling | 60 * If non-NULL is returned, the caller is responsible for calling |
| 61 * unref() on the data when it is finished. | 61 * unref() on the data when it is finished. |
| 62 */ | 62 */ |
| 63 SkData* refEncodedData() { return this->onRefEncodedData(); } | 63 SkData* refEncodedData() { return this->onRefEncodedData(); } |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * Return some information about the image, allowing the owner of | 66 * Return some information about the image, allowing the owner of |
| 67 * this object to allocate pixels. | 67 * this object to allocate pixels. |
| 68 * | 68 * |
| 69 * Repeated calls to this function should give the same results, | 69 * Repeated calls to this function should give the same results, |
| 70 * allowing the PixelRef to be immutable. | 70 * allowing the PixelRef to be immutable. |
| 71 * | 71 * |
| 72 * @return false if anything goes wrong. | 72 * @return false if anything goes wrong. |
| 73 */ | 73 */ |
| 74 bool getInfo(SkImageInfo* info); | 74 bool getInfo(SkImageInfo* info); |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * Used to describe the result of a call to getPixels(). | |
| 78 * | |
| 79 * Result is the union of possible results from subclasses. | |
| 80 */ | |
| 81 enum Result { | |
| 82 /** | |
| 83 * The generator cannot convert to match the request. | |
|
hal.canary
2015/02/12 14:54:59
/** The generator cannot convert ColorType to mat
scroggo
2015/02/12 15:28:36
I don't think that's quite accurate. The AlphaType
| |
| 84 */ | |
| 85 kInvalidConversion, | |
| 86 /** | |
| 87 * The generator cannot scale to requested size. | |
| 88 */ | |
| 89 kInvalidScale, | |
| 90 /** | |
| 91 * Parameters (besides info) are invalid. e.g. NULL pixels, rowBytes | |
| 92 * too small, etc. | |
| 93 */ | |
| 94 kInvalidParameters, | |
|
scroggo
2015/02/11 16:01:25
We could have more specific enums (e.g. kNullPixel
| |
| 95 /** | |
| 96 * The input did not contain a valid image. | |
| 97 */ | |
| 98 kInvalidInput, | |
| 99 /** | |
| 100 * Fulfilling this request requires rewinding the input, which is not | |
| 101 * supported for this input. | |
| 102 */ | |
| 103 kCouldNotRewind, | |
| 104 /** | |
| 105 * This method is not implemented by this generator. | |
| 106 */ | |
| 107 kUnimplemented, | |
| 108 /** | |
| 109 * The input is incomplete. A partial image was generated. | |
| 110 */ | |
| 111 kIncompleteInput, | |
|
scroggo
2015/02/11 16:01:25
For SkImageDecoder::Result, I made incomplete and
| |
| 112 /** | |
| 113 * General return value for success. | |
| 114 */ | |
| 115 kSuccess, | |
| 116 }; | |
| 117 | |
| 118 /** | |
| 77 * Decode into the given pixels, a block of memory of size at | 119 * Decode into the given pixels, a block of memory of size at |
| 78 * least (info.fHeight - 1) * rowBytes + (info.fWidth * | 120 * least (info.fHeight - 1) * rowBytes + (info.fWidth * |
| 79 * bytesPerPixel) | 121 * bytesPerPixel) |
| 80 * | 122 * |
| 81 * Repeated calls to this function should give the same results, | 123 * Repeated calls to this function should give the same results, |
| 82 * allowing the PixelRef to be immutable. | 124 * allowing the PixelRef to be immutable. |
| 83 * | 125 * |
| 84 * @param info A description of the format (config, size) | 126 * @param info A description of the format (config, size) |
| 85 * expected by the caller. This can simply be identical | 127 * expected by the caller. This can simply be identical |
| 86 * to the info returned by getInfo(). | 128 * to the info returned by getInfo(). |
| 87 * | 129 * |
| 88 * This contract also allows the caller to specify | 130 * This contract also allows the caller to specify |
| 89 * different output-configs, which the implementation can | 131 * different output-configs, which the implementation can |
| 90 * decide to support or not. | 132 * decide to support or not. |
| 91 * | 133 * |
| 134 * A size that does not match getInfo() implies a request | |
| 135 * to scale. | |
|
djsollen
2015/02/12 14:22:15
add a little more info here that the generator can
scroggo
2015/02/12 15:28:36
Done.
| |
| 136 * | |
| 92 * If info is kIndex8_SkColorType, then the caller must provide storage for up to 256 | 137 * 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, | 138 * 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. | 139 * (where N is the logical number of table entries) and set ctableCount to N. |
| 95 * | 140 * |
| 96 * If info is not kIndex8_SkColorType, then the last two parameters may be NULL. If ctableCount | 141 * 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. | 142 * is not null, it will be set to 0. |
| 98 * | 143 * |
| 99 * @return false if anything goes wrong or if the image info is | 144 * @return false if anything goes wrong or if the image info is |
| 100 * unsupported. | 145 * unsupported. |
| 101 */ | 146 */ |
| 102 bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, | 147 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
|
reed1
2015/02/12 14:46:08
perhaps for a diff CL -- but I think it is more co
scroggo
2015/02/12 15:28:36
Interesting... I just looked at the the definition
| |
| 103 SkPMColor ctable[], int* ctableCount); | 148 SkPMColor ctable[], int* ctableCount); |
| 104 | 149 |
| 105 /** | 150 /** |
| 106 * Simplified version of getPixels() that asserts that info is NOT kIndex8_ SkColorType. | 151 * Simplified version of getPixels() that asserts that info is NOT kIndex8_ SkColorType. |
| 107 */ | 152 */ |
| 108 bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); | 153 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); |
| 109 | 154 |
| 110 /** | 155 /** |
| 111 * If planes or rowBytes is NULL or if any entry in planes is NULL or if an y entry in rowBytes | 156 * 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 | 157 * 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 | 158 * 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 | 159 * 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. | 160 * entries only. Having only partial planes/rowBytes information is not sup ported. |
| 116 * | 161 * |
| 117 * If all planes and rowBytes entries are non NULL or non 0, then it should copy the | 162 * 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 | 163 * 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. | 164 * that the sizes match what it expected. If the sizes do not match, it sho uld return false. |
| 120 */ | 165 */ |
| 121 bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], | 166 bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
| 122 SkYUVColorSpace* colorSpace); | 167 SkYUVColorSpace* colorSpace); |
| 123 | 168 |
| 124 /** | 169 /** |
| 125 * If the default image decoder system can interpret the specified (encoded ) data, then | 170 * 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 | 171 * 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 . | 172 * the caller is still responsible for managing their ownership of the data . |
| 128 */ | 173 */ |
| 129 static SkImageGenerator* NewFromData(SkData*); | 174 static SkImageGenerator* NewFromData(SkData*); |
| 130 | 175 |
| 131 protected: | 176 protected: |
| 132 virtual SkData* onRefEncodedData(); | 177 virtual SkData* onRefEncodedData(); |
| 133 virtual bool onGetInfo(SkImageInfo* info); | 178 virtual bool onGetInfo(SkImageInfo* info); |
| 134 virtual bool onGetPixels(const SkImageInfo& info, | 179 virtual Result onGetPixels(const SkImageInfo& info, |
| 135 void* pixels, size_t rowBytes, | 180 void* pixels, size_t rowBytes, |
| 136 SkPMColor ctable[], int* ctableCount); | 181 SkPMColor ctable[], int* ctableCount); |
| 137 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3]); | 182 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], | 183 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3], |
| 139 SkYUVColorSpace* colorSpace); | 184 SkYUVColorSpace* colorSpace); |
| 140 }; | 185 }; |
| 141 | 186 |
| 142 #endif // SkImageGenerator_DEFINED | 187 #endif // SkImageGenerator_DEFINED |
| OLD | NEW |