| 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 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, nullptr, nullptr); | 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::queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* color
Space) const { |
| 56 SkYUVColorSpace* colorSpace) { | 56 SkASSERT(sizeInfo); |
| 57 #ifdef SK_DEBUG | |
| 58 // In all cases, we need the sizes array | |
| 59 SkASSERT(sizes); | |
| 60 | 57 |
| 61 bool isValidWithPlanes = (planes) && (rowBytes) && | 58 return this->onQueryYUV8(sizeInfo, colorSpace); |
| 62 ((planes[0]) && (planes[1]) && (planes[2]) && | |
| 63 (0 != rowBytes[0]) && (0 != rowBytes[1]) && (0 != rowBytes[2])); | |
| 64 bool isValidWithoutPlanes = | |
| 65 ((nullptr == planes) || | |
| 66 ((nullptr == planes[0]) && (nullptr == planes[1]) && (nullptr == planes
[2]))) && | |
| 67 ((nullptr == rowBytes) || | |
| 68 ((0 == rowBytes[0]) && (0 == rowBytes[1]) && (0 == rowBytes[2]))); | |
| 69 | |
| 70 // Either we have all planes and rowBytes information or we have none of it | |
| 71 // Having only partial information is not supported | |
| 72 SkASSERT(isValidWithPlanes || isValidWithoutPlanes); | |
| 73 | |
| 74 // If we do have planes information, make sure all sizes are non 0 | |
| 75 // and all rowBytes are valid | |
| 76 SkASSERT(!isValidWithPlanes || | |
| 77 ((sizes[0].fWidth >= 0) && | |
| 78 (sizes[0].fHeight >= 0) && | |
| 79 (sizes[1].fWidth >= 0) && | |
| 80 (sizes[1].fHeight >= 0) && | |
| 81 (sizes[2].fWidth >= 0) && | |
| 82 (sizes[2].fHeight >= 0) && | |
| 83 (rowBytes[0] >= (size_t)sizes[0].fWidth) && | |
| 84 (rowBytes[1] >= (size_t)sizes[1].fWidth) && | |
| 85 (rowBytes[2] >= (size_t)sizes[2].fWidth))); | |
| 86 #endif | |
| 87 | |
| 88 return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace); | |
| 89 } | 59 } |
| 90 | 60 |
| 91 bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t
rowBytes[3]) { | 61 bool SkImageGenerator::getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes
[3]) { |
| 92 return false; | 62 SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth >= 0); |
| 93 } | 63 SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight >= 0); |
| 64 SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kU].fWidth >= 0); |
| 65 SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight >= 0); |
| 66 SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kV].fWidth >= 0); |
| 67 SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kV].fHeight >= 0); |
| 68 SkASSERT(sizeInfo.fWidthBytes[SkYUVSizeInfo::kY] >= |
| 69 (size_t) sizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth); |
| 70 SkASSERT(sizeInfo.fWidthBytes[SkYUVSizeInfo::kU] >= |
| 71 (size_t) sizeInfo.fSizes[SkYUVSizeInfo::kU].fWidth); |
| 72 SkASSERT(sizeInfo.fWidthBytes[SkYUVSizeInfo::kV] >= |
| 73 (size_t) sizeInfo.fSizes[SkYUVSizeInfo::kV].fWidth); |
| 74 SkASSERT(planes && planes[0] && planes[1] && planes[2]); |
| 94 | 75 |
| 95 bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t
rowBytes[3], | 76 return this->onGetYUV8Planes(sizeInfo, planes); |
| 96 SkYUVColorSpace* colorSpace) { | |
| 97 // In order to maintain compatibility with clients that implemented the orig
inal | |
| 98 // onGetYUV8Planes interface, we assume that the color space is JPEG. | |
| 99 // TODO(rileya): remove this and the old onGetYUV8Planes once clients switch
over to | |
| 100 // the new interface. | |
| 101 if (colorSpace) { | |
| 102 *colorSpace = kJPEG_SkYUVColorSpace; | |
| 103 } | |
| 104 return this->onGetYUV8Planes(sizes, planes, rowBytes); | |
| 105 } | 77 } |
| 106 | 78 |
| 107 GrTexture* SkImageGenerator::generateTexture(GrContext* ctx, const SkIRect* subs
et) { | 79 GrTexture* SkImageGenerator::generateTexture(GrContext* ctx, const SkIRect* subs
et) { |
| 108 if (subset && !SkIRect::MakeWH(fInfo.width(), fInfo.height()).contains(*subs
et)) { | 80 if (subset && !SkIRect::MakeWH(fInfo.width(), fInfo.height()).contains(*subs
et)) { |
| 109 return nullptr; | 81 return nullptr; |
| 110 } | 82 } |
| 111 return this->onGenerateTexture(ctx, subset); | 83 return this->onGenerateTexture(ctx, subset); |
| 112 } | 84 } |
| 113 | 85 |
| 114 bool SkImageGenerator::computeScaledDimensions(SkScalar scale, SupportedSizes* s
izes) { | 86 bool SkImageGenerator::computeScaledDimensions(SkScalar scale, SupportedSizes* s
izes) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 if (nullptr == data) { | 210 if (nullptr == data) { |
| 239 return nullptr; | 211 return nullptr; |
| 240 } | 212 } |
| 241 if (gFactory) { | 213 if (gFactory) { |
| 242 if (SkImageGenerator* generator = gFactory(data)) { | 214 if (SkImageGenerator* generator = gFactory(data)) { |
| 243 return generator; | 215 return generator; |
| 244 } | 216 } |
| 245 } | 217 } |
| 246 return SkImageGenerator::NewFromEncodedImpl(data); | 218 return SkImageGenerator::NewFromEncodedImpl(data); |
| 247 } | 219 } |
| OLD | NEW |