| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "SkImageGenerator.h" | 8 #include "SkImageGenerator.h" |
| 9 #include "SkNextID.h" | 9 #include "SkNextID.h" |
| 10 | 10 |
| 11 SkImageGenerator::SkImageGenerator(const SkImageInfo& info) | 11 SkImageGenerator::SkImageGenerator(const SkImageInfo& info) |
| 12 : fInfo(info) | 12 : fInfo(info) |
| 13 , fUniqueID(SkNextID::ImageID()) | 13 , fUniqueID(SkNextID::ImageID()) |
| 14 {} | 14 {} |
| 15 | 15 |
| 16 bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t r
owBytes, | 16 bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t r
owBytes, |
| 17 SkPMColor ctable[], int* ctableCount) { | 17 SkPMColor ctable[], int* ctableCount) { |
| 18 if (kUnknown_SkColorType == info.colorType()) { | 18 if (kUnknown_SkColorType == info.colorType()) { |
| 19 return false; | 19 return false; |
| 20 } | 20 } |
| 21 if (NULL == pixels) { | 21 if (nullptr == pixels) { |
| 22 return false; | 22 return false; |
| 23 } | 23 } |
| 24 if (rowBytes < info.minRowBytes()) { | 24 if (rowBytes < info.minRowBytes()) { |
| 25 return false; | 25 return false; |
| 26 } | 26 } |
| 27 | 27 |
| 28 if (kIndex_8_SkColorType == info.colorType()) { | 28 if (kIndex_8_SkColorType == info.colorType()) { |
| 29 if (NULL == ctable || NULL == ctableCount) { | 29 if (nullptr == ctable || nullptr == ctableCount) { |
| 30 return false; | 30 return false; |
| 31 } | 31 } |
| 32 } else { | 32 } else { |
| 33 if (ctableCount) { | 33 if (ctableCount) { |
| 34 *ctableCount = 0; | 34 *ctableCount = 0; |
| 35 } | 35 } |
| 36 ctableCount = NULL; | 36 ctableCount = nullptr; |
| 37 ctable = NULL; | 37 ctable = nullptr; |
| 38 } | 38 } |
| 39 | 39 |
| 40 const bool success = this->onGetPixels(info, pixels, rowBytes, ctable, ctabl
eCount); | 40 const bool success = this->onGetPixels(info, pixels, rowBytes, ctable, ctabl
eCount); |
| 41 if (success && ctableCount) { | 41 if (success && ctableCount) { |
| 42 SkASSERT(*ctableCount >= 0 && *ctableCount <= 256); | 42 SkASSERT(*ctableCount >= 0 && *ctableCount <= 256); |
| 43 } | 43 } |
| 44 return success; | 44 return success; |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t r
owBytes) { | 47 bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t r
owBytes) { |
| 48 SkASSERT(kIndex_8_SkColorType != info.colorType()); | 48 SkASSERT(kIndex_8_SkColorType != info.colorType()); |
| 49 if (kIndex_8_SkColorType == info.colorType()) { | 49 if (kIndex_8_SkColorType == info.colorType()) { |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 return this->getPixels(info, pixels, rowBytes, NULL, NULL); | 52 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr); |
| 53 } | 53 } |
| 54 | 54 |
| 55 bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t r
owBytes[3], | 55 bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t r
owBytes[3], |
| 56 SkYUVColorSpace* colorSpace) { | 56 SkYUVColorSpace* colorSpace) { |
| 57 #ifdef SK_DEBUG | 57 #ifdef SK_DEBUG |
| 58 // In all cases, we need the sizes array | 58 // In all cases, we need the sizes array |
| 59 SkASSERT(sizes); | 59 SkASSERT(sizes); |
| 60 | 60 |
| 61 bool isValidWithPlanes = (planes) && (rowBytes) && | 61 bool isValidWithPlanes = (planes) && (rowBytes) && |
| 62 ((planes[0]) && (planes[1]) && (planes[2]) && | 62 ((planes[0]) && (planes[1]) && (planes[2]) && |
| 63 (0 != rowBytes[0]) && (0 != rowBytes[1]) && (0 != rowBytes[2])); | 63 (0 != rowBytes[0]) && (0 != rowBytes[1]) && (0 != rowBytes[2])); |
| 64 bool isValidWithoutPlanes = | 64 bool isValidWithoutPlanes = |
| 65 ((NULL == planes) || | 65 ((nullptr == planes) || |
| 66 ((NULL == planes[0]) && (NULL == planes[1]) && (NULL == planes[2]))) && | 66 ((nullptr == planes[0]) && (nullptr == planes[1]) && (nullptr == planes
[2]))) && |
| 67 ((NULL == rowBytes) || | 67 ((nullptr == rowBytes) || |
| 68 ((0 == rowBytes[0]) && (0 == rowBytes[1]) && (0 == rowBytes[2]))); | 68 ((0 == rowBytes[0]) && (0 == rowBytes[1]) && (0 == rowBytes[2]))); |
| 69 | 69 |
| 70 // Either we have all planes and rowBytes information or we have none of it | 70 // Either we have all planes and rowBytes information or we have none of it |
| 71 // Having only partial information is not supported | 71 // Having only partial information is not supported |
| 72 SkASSERT(isValidWithPlanes || isValidWithoutPlanes); | 72 SkASSERT(isValidWithPlanes || isValidWithoutPlanes); |
| 73 | 73 |
| 74 // If we do have planes information, make sure all sizes are non 0 | 74 // If we do have planes information, make sure all sizes are non 0 |
| 75 // and all rowBytes are valid | 75 // and all rowBytes are valid |
| 76 SkASSERT(!isValidWithPlanes || | 76 SkASSERT(!isValidWithPlanes || |
| 77 ((sizes[0].fWidth >= 0) && | 77 ((sizes[0].fWidth >= 0) && |
| (...skipping 30 matching lines...) Expand all Loading... |
| 108 const SkIRect* subset) { | 108 const SkIRect* subset) { |
| 109 if (subset && !SkIRect::MakeWH(fInfo.width(), fInfo.height()).contains(*subs
et)) { | 109 if (subset && !SkIRect::MakeWH(fInfo.width(), fInfo.height()).contains(*subs
et)) { |
| 110 return nullptr; | 110 return nullptr; |
| 111 } | 111 } |
| 112 return this->onGenerateTexture(ctx, usage, subset); | 112 return this->onGenerateTexture(ctx, usage, subset); |
| 113 } | 113 } |
| 114 | 114 |
| 115 ////////////////////////////////////////////////////////////////////////////////
///////////// | 115 ////////////////////////////////////////////////////////////////////////////////
///////////// |
| 116 | 116 |
| 117 SkData* SkImageGenerator::onRefEncodedData() { | 117 SkData* SkImageGenerator::onRefEncodedData() { |
| 118 return NULL; | 118 return nullptr; |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool SkImageGenerator::onGetPixels(const SkImageInfo& info, void* dst, size_t rb
, | 121 bool SkImageGenerator::onGetPixels(const SkImageInfo& info, void* dst, size_t rb
, |
| 122 SkPMColor* colors, int* colorCount) { | 122 SkPMColor* colors, int* colorCount) { |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| 125 | 125 |
| 126 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 126 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 127 | 127 |
| 128 #include "SkGraphics.h" | 128 #include "SkGraphics.h" |
| 129 | 129 |
| 130 static SkGraphics::ImageGeneratorFromEncodedFactory gFactory; | 130 static SkGraphics::ImageGeneratorFromEncodedFactory gFactory; |
| 131 | 131 |
| 132 SkGraphics::ImageGeneratorFromEncodedFactory | 132 SkGraphics::ImageGeneratorFromEncodedFactory |
| 133 SkGraphics::SetImageGeneratorFromEncodedFactory(ImageGeneratorFromEncodedFactory
factory) | 133 SkGraphics::SetImageGeneratorFromEncodedFactory(ImageGeneratorFromEncodedFactory
factory) |
| 134 { | 134 { |
| 135 ImageGeneratorFromEncodedFactory prev = gFactory; | 135 ImageGeneratorFromEncodedFactory prev = gFactory; |
| 136 gFactory = factory; | 136 gFactory = factory; |
| 137 return prev; | 137 return prev; |
| 138 } | 138 } |
| 139 | 139 |
| 140 SkImageGenerator* SkImageGenerator::NewFromEncoded(SkData* data) { | 140 SkImageGenerator* SkImageGenerator::NewFromEncoded(SkData* data) { |
| 141 if (NULL == data) { | 141 if (nullptr == data) { |
| 142 return NULL; | 142 return nullptr; |
| 143 } | 143 } |
| 144 if (gFactory) { | 144 if (gFactory) { |
| 145 if (SkImageGenerator* generator = gFactory(data)) { | 145 if (SkImageGenerator* generator = gFactory(data)) { |
| 146 return generator; | 146 return generator; |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 return SkImageGenerator::NewFromEncodedImpl(data); | 149 return SkImageGenerator::NewFromEncodedImpl(data); |
| 150 } | 150 } |
| OLD | NEW |