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::queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* color
Space) const { | 55 bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t r
owBytes[3], |
56 SkASSERT(sizeInfo); | 56 SkYUVColorSpace* colorSpace) { |
| 57 #ifdef SK_DEBUG |
| 58 // In all cases, we need the sizes array |
| 59 SkASSERT(sizes); |
57 | 60 |
58 return this->onQueryYUV8(sizeInfo, colorSpace); | 61 bool isValidWithPlanes = (planes) && (rowBytes) && |
| 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); |
59 } | 89 } |
60 | 90 |
61 bool SkImageGenerator::getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes
[3]) { | 91 bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t
rowBytes[3]) { |
62 SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth >= 0); | 92 return false; |
63 SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight >= 0); | 93 } |
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]); | |
75 | 94 |
76 return this->onGetYUV8Planes(sizeInfo, planes); | 95 bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t
rowBytes[3], |
| 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); |
77 } | 105 } |
78 | 106 |
79 GrTexture* SkImageGenerator::generateTexture(GrContext* ctx, const SkIRect* subs
et) { | 107 GrTexture* SkImageGenerator::generateTexture(GrContext* ctx, const SkIRect* subs
et) { |
80 if (subset && !SkIRect::MakeWH(fInfo.width(), fInfo.height()).contains(*subs
et)) { | 108 if (subset && !SkIRect::MakeWH(fInfo.width(), fInfo.height()).contains(*subs
et)) { |
81 return nullptr; | 109 return nullptr; |
82 } | 110 } |
83 return this->onGenerateTexture(ctx, subset); | 111 return this->onGenerateTexture(ctx, subset); |
84 } | 112 } |
85 | 113 |
86 bool SkImageGenerator::computeScaledDimensions(SkScalar scale, SupportedSizes* s
izes) { | 114 bool SkImageGenerator::computeScaledDimensions(SkScalar scale, SupportedSizes* s
izes) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 if (nullptr == data) { | 238 if (nullptr == data) { |
211 return nullptr; | 239 return nullptr; |
212 } | 240 } |
213 if (gFactory) { | 241 if (gFactory) { |
214 if (SkImageGenerator* generator = gFactory(data)) { | 242 if (SkImageGenerator* generator = gFactory(data)) { |
215 return generator; | 243 return generator; |
216 } | 244 } |
217 } | 245 } |
218 return SkImageGenerator::NewFromEncodedImpl(data); | 246 return SkImageGenerator::NewFromEncodedImpl(data); |
219 } | 247 } |
OLD | NEW |