Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 SkScanlineDecoder_DEFINED | 8 #ifndef SkScanlineDecoder_DEFINED |
| 9 #define SkScanlineDecoder_DEFINED | 9 #define SkScanlineDecoder_DEFINED |
| 10 | 10 |
| 11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
| 12 #include "SkTemplates.h" | 12 #include "SkTemplates.h" |
| 13 #include "SkImageGenerator.h" | 13 #include "SkImageGenerator.h" |
| 14 #include "SkImageInfo.h" | 14 #include "SkImageInfo.h" |
| 15 | 15 |
| 16 class SkScanlineDecoder : public SkNoncopyable { | 16 class SkScanlineDecoder : public SkNoncopyable { |
| 17 public: | 17 public: |
| 18 // Note for implementations: An SkScanlineDecoder will be deleted by (and | 18 /** |
| 19 // therefore *before*) its associated SkCodec, in case the order matters. | 19 * Clean up after reading/skipping scanlines. |
| 20 * | |
| 21 * It is possible that not all scanlines will have been read/skipped. In | |
| 22 * fact, in the case of subset decodes, it is likely that there will be | |
| 23 * scanlines at the bottom of the image that have been ignored. | |
| 24 * | |
| 25 * Note for implementations: An SkScanlineDecoder will be deleted by (and | |
| 26 * therefore *before*) its associated SkCodec, in case the order matters. | |
| 27 * However, while the SkCodec base class maintains ownership of the | |
| 28 * SkScanlineDecoder, the subclass will be deleted before the scanline | |
| 29 * decoder. If this is an issue, detachScanlineDecoder() provides | |
| 30 * a means for the subclass to take ownership of the SkScanlineDecoder. | |
| 31 */ | |
| 20 virtual ~SkScanlineDecoder() {} | 32 virtual ~SkScanlineDecoder() {} |
|
scroggo
2015/06/30 20:59:58
Do any clients override this? Maybe we can leave i
msarett
2015/06/30 21:33:00
No clients override this. My original response wa
| |
| 21 | 33 |
| 22 /** | 34 /** |
| 23 * Write the next countLines scanlines into dst. | 35 * Write the next countLines scanlines into dst. |
| 24 * | 36 * |
| 25 * @param dst Must be non-null, and large enough to hold countLines | 37 * @param dst Must be non-null, and large enough to hold countLines |
| 26 * scanlines of size rowBytes. | 38 * scanlines of size rowBytes. |
| 27 * @param countLines Number of lines to write. | 39 * @param countLines Number of lines to write. |
| 28 * @param rowBytes Number of bytes per row. Must be large enough to hold | 40 * @param rowBytes Number of bytes per row. Must be large enough to hold |
| 29 * a scanline based on the SkImageInfo used to create this object. | 41 * a scanline based on the SkImageInfo used to create this object. |
| 30 */ | 42 */ |
| 31 SkImageGenerator::Result getScanlines(void* dst, int countLines, size_t rowB ytes) { | 43 SkImageGenerator::Result getScanlines(void* dst, int countLines, size_t rowB ytes) { |
| 32 if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <= 0 | 44 if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <= 0 |
| 33 || fCurrScanline + countLines > fDstInfo.height()) { | 45 || fCurrScanline + countLines > fDstInfo.height()) { |
| 34 return SkImageGenerator::kInvalidParameters; | 46 return SkImageGenerator::kInvalidParameters; |
| 35 } | 47 } |
| 36 const SkImageGenerator::Result result = this->onGetScanlines(dst, countL ines, rowBytes); | 48 const SkImageGenerator::Result result = this->onGetScanlines(dst, countL ines, rowBytes); |
| 37 this->checkForFinish(countLines); | 49 fCurrScanline += countLines; |
| 38 return result; | 50 return result; |
| 39 } | 51 } |
| 40 | 52 |
| 41 /** | 53 /** |
| 42 * Skip count scanlines. | 54 * Skip count scanlines. |
| 43 * | 55 * |
| 44 * The default version just calls onGetScanlines and discards the dst. | 56 * The default version just calls onGetScanlines and discards the dst. |
| 45 * NOTE: If skipped lines are the only lines with alpha, this default | 57 * NOTE: If skipped lines are the only lines with alpha, this default |
| 46 * will make reallyHasAlpha return true, when it could have returned | 58 * will make reallyHasAlpha return true, when it could have returned |
| 47 * false. | 59 * false. |
| 48 */ | 60 */ |
| 49 SkImageGenerator::Result skipScanlines(int countLines) { | 61 SkImageGenerator::Result skipScanlines(int countLines) { |
| 50 if (fCurrScanline + countLines > fDstInfo.height()) { | 62 if (fCurrScanline + countLines > fDstInfo.height()) { |
| 51 // Arguably, we could just skip the scanlines which are remaining, | 63 // Arguably, we could just skip the scanlines which are remaining, |
| 52 // and return kSuccess. We choose to return invalid so the client | 64 // and return kSuccess. We choose to return invalid so the client |
| 53 // can catch their bug. | 65 // can catch their bug. |
| 54 return SkImageGenerator::kInvalidParameters; | 66 return SkImageGenerator::kInvalidParameters; |
| 55 } | 67 } |
| 56 const SkImageGenerator::Result result = this->onSkipScanlines(countLines ); | 68 const SkImageGenerator::Result result = this->onSkipScanlines(countLines ); |
| 57 this->checkForFinish(countLines); | 69 fCurrScanline += countLines; |
| 58 return result; | 70 return result; |
| 59 } | 71 } |
| 60 | 72 |
| 61 /** | 73 /** |
| 62 * Some images may initially report that they have alpha due to the format | 74 * Some images may initially report that they have alpha due to the format |
| 63 * of the encoded data, but then never use any colors which have alpha | 75 * of the encoded data, but then never use any colors which have alpha |
| 64 * less than 100%. This function can be called *after* decoding to | 76 * less than 100%. This function can be called *after* decoding to |
| 65 * determine if such an image truly had alpha. Calling it before decoding | 77 * determine if such an image truly had alpha. Calling it before decoding |
| 66 * is undefined. | 78 * is undefined. |
| 67 * FIXME: see skbug.com/3582. | 79 * FIXME: see skbug.com/3582. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 90 // Also note that while getScanlines checks that rowBytes is big enough, | 102 // Also note that while getScanlines checks that rowBytes is big enough, |
| 91 // onGetScanlines bypasses that check. | 103 // onGetScanlines bypasses that check. |
| 92 // Calling the virtual method also means we do not double count | 104 // Calling the virtual method also means we do not double count |
| 93 // countLines. | 105 // countLines. |
| 94 return this->onGetScanlines(storage.get(), countLines, 0); | 106 return this->onGetScanlines(storage.get(), countLines, 0); |
| 95 } | 107 } |
| 96 | 108 |
| 97 virtual SkImageGenerator::Result onGetScanlines(void* dst, int countLines, | 109 virtual SkImageGenerator::Result onGetScanlines(void* dst, int countLines, |
| 98 size_t rowBytes) = 0; | 110 size_t rowBytes) = 0; |
| 99 | 111 |
| 100 /** | |
| 101 * Called after any set of scanlines read/skipped. Updates fCurrScanline, | |
| 102 * and, if we are at the end, calls onFinish(). | |
| 103 */ | |
| 104 void checkForFinish(int countLines) { | |
| 105 fCurrScanline += countLines; | |
| 106 if (fCurrScanline >= fDstInfo.height()) { | |
| 107 this->onFinish(); | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 /** | |
| 112 * This function will be called after reading/skipping all scanlines to do | |
| 113 * any necessary cleanups. | |
| 114 */ | |
| 115 virtual void onFinish() {} // Default does nothing. | |
| 116 }; | 112 }; |
| 117 #endif // SkScanlineDecoder_DEFINED | 113 #endif // SkScanlineDecoder_DEFINED |
| OLD | NEW |