Index: src/core/SkImageGenerator.cpp |
diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp |
index 0f63db50f637e82633caf9bd6f611979c941ffcb..d7818fdd7e231ca588a914501a712273effb7900 100644 |
--- a/src/core/SkImageGenerator.cpp |
+++ b/src/core/SkImageGenerator.cpp |
@@ -55,6 +55,7 @@ bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t r |
return this->getPixels(info, pixels, rowBytes, NULL, NULL); |
} |
+#ifdef SK_SUPPORT_LEGACY_IMAGEGENERATOR_YUV_API |
bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
SkYUVColorSpace* colorSpace) { |
#ifdef SK_DEBUG |
@@ -90,21 +91,38 @@ bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t r |
return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace); |
} |
+#endif |
-bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3]) { |
- return false; |
+bool SkImageGenerator::queryYUV8(SkISize logicalSizes[3], SkISize optimalAllocationSizes[3]) { |
+ SkISize logicalStorage[3], optimalStorage[3]; |
+ if (!logicalSizes) { |
+ logicalSizes = logicalStorage; |
+ } |
+ if (!optimalAllocationSizes) { |
+ optimalAllocationSizes = optimalStorage; |
+ } |
+ return this->onQueryYUV8(logicalSizes, optimalAllocationSizes); |
} |
-bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
- SkYUVColorSpace* colorSpace) { |
- // In order to maintain compatibility with clients that implemented the original |
- // onGetYUV8Planes interface, we assume that the color space is JPEG. |
- // TODO(rileya): remove this and the old onGetYUV8Planes once clients switch over to |
- // the new interface. |
- if (colorSpace) { |
- *colorSpace = kJPEG_SkYUVColorSpace; |
+bool SkImageGenerator::getYUV8(const SkISize allocationSizes[3], void* planes[3], |
+ SkYUVColorSpace* colorSpace) { |
+ SkASSERT(allocationSizes); |
+ SkASSERT(planes); |
+ |
+ for (int i = 0; i < 3; ++i) { |
+ if (allocationSizes[i].width() <= 0 || allocationSizes[i].height() <= 0) { |
+ return false; |
+ } |
+ if (!planes[i]) { |
+ return false; |
+ } |
} |
- return this->onGetYUV8Planes(sizes, planes, rowBytes); |
+ |
+ SkYUVColorSpace colorSpaceStorage; |
+ if (!colorSpace) { |
+ colorSpace = &colorSpaceStorage; |
+ } |
+ return this->onGetYUV8(allocationSizes, planes, colorSpace); |
} |
///////////////////////////////////////////////////////////////////////////////////////////// |
@@ -120,3 +138,48 @@ bool SkImageGenerator::onGetInfo(SkImageInfo*) { |
bool SkImageGenerator::onGetPixels(const SkImageInfo&, void*, size_t, SkPMColor*, int*) { |
return false; |
} |
+ |
+bool SkImageGenerator::onQueryYUV8(SkISize logicalSizes[3], SkISize optimalAllocationSizes[3]) { |
+#ifdef SK_SUPPORT_LEGACY_IMAGEGENERATOR_YUV_API |
+ if (this->getYUV8Planes(logicalSizes, NULL, NULL, NULL)) { |
+ memcpy(optimalAllocationSizes, logicalSizes, sizeof(SkISize) * 3); |
+ return true; |
+ } |
+#endif |
+ return false; |
+} |
+ |
+bool SkImageGenerator::onGetYUV8(const SkISize allocationSizes[3], void* planes[3], |
+ SkYUVColorSpace* colorSpace) { |
+#ifdef SK_SUPPORT_LEGACY_IMAGEGENERATOR_YUV_API |
+ SkISize tmpSizes[3]; |
+ size_t rowBytes[3]; |
+ for (int i = 0; i < 3; ++i) { |
+ tmpSizes[i] = allocationSizes[i]; |
+ rowBytes[i] = allocationSizes[i].width(); |
+ } |
+ if (this->getYUV8Planes(tmpSizes, planes, rowBytes, colorSpace)) { |
+ return true; |
+ } |
+#endif |
+ return false; |
+} |
+ |
+#ifdef SK_SUPPORT_LEGACY_IMAGEGENERATOR_YUV_API |
+bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3]) { |
+ return false; |
+} |
+ |
+bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
+ SkYUVColorSpace* colorSpace) { |
+ // In order to maintain compatibility with clients that implemented the original |
+ // onGetYUV8Planes interface, we assume that the color space is JPEG. |
+ // TODO(rileya): remove this and the old onGetYUV8Planes once clients switch over to |
+ // the new interface. |
+ if (colorSpace) { |
+ *colorSpace = kJPEG_SkYUVColorSpace; |
+ } |
+ return this->onGetYUV8Planes(sizes, planes, rowBytes); |
+} |
+#endif |
+ |