diff options
-rw-r--r-- | include/codec/SkCodec.h | 31 | ||||
-rw-r--r-- | include/core/SkImageGenerator.h | 39 | ||||
-rw-r--r-- | include/core/SkPixelRef.h | 39 | ||||
-rw-r--r-- | include/core/SkYUVSizeInfo.h | 34 | ||||
-rw-r--r-- | src/codec/SkCodecImageGenerator.cpp | 47 | ||||
-rw-r--r-- | src/codec/SkCodecImageGenerator.h | 11 | ||||
-rw-r--r-- | src/codec/SkJpegCodec.cpp | 60 | ||||
-rw-r--r-- | src/codec/SkJpegCodec.h | 4 | ||||
-rw-r--r-- | src/core/SkImageCacherator.cpp | 9 | ||||
-rw-r--r-- | src/core/SkImageGenerator.cpp | 66 | ||||
-rw-r--r-- | src/core/SkPixelRef.cpp | 5 | ||||
-rw-r--r-- | src/core/SkYUVPlanesCache.h | 11 | ||||
-rw-r--r-- | src/gpu/GrYUVProvider.cpp | 48 | ||||
-rw-r--r-- | src/gpu/GrYUVProvider.h | 34 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 9 | ||||
-rw-r--r-- | src/lazy/SkDiscardablePixelRef.h | 16 | ||||
-rw-r--r-- | tests/ImageGeneratorTest.cpp | 32 | ||||
-rw-r--r-- | tests/YUVCacheTest.cpp | 19 | ||||
-rw-r--r-- | tests/YUVTest.cpp | 34 |
19 files changed, 262 insertions, 286 deletions
diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h index 7e7503acae..3855064f61 100644 --- a/include/codec/SkCodec.h +++ b/include/codec/SkCodec.h @@ -15,6 +15,7 @@ #include "SkSize.h" #include "SkStream.h" #include "SkTypes.h" +#include "SkYUVSizeInfo.h" class SkColorSpace; class SkData; @@ -285,28 +286,6 @@ public: */ Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); - struct YUVSizeInfo { - SkISize fYSize; - SkISize fUSize; - SkISize fVSize; - - /** - * While the widths of the Y, U, and V planes are not restricted, the - * implementation requires that the width of the memory allocated for - * each plane be a multiple of DCTSIZE (which is always 8). - * - * This struct allows us to inform the client how many "widthBytes" - * that we need. Note that we use the new idea of "widthBytes" - * because this idea is distinct from "rowBytes" (used elsewhere in - * Skia). "rowBytes" allow the last row of the allocation to not - * include any extra padding, while, in this case, every single row of - * the allocation must be at least "widthBytes". - */ - size_t fYWidthBytes; - size_t fUWidthBytes; - size_t fVWidthBytes; - }; - /** * If decoding to YUV is supported, this returns true. Otherwise, this * returns false and does not modify any of the parameters. @@ -316,7 +295,7 @@ public: * @param colorSpace Output parameter. If non-NULL this is set to kJPEG, * otherwise this is ignored. */ - bool queryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { + bool queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { if (nullptr == sizeInfo) { return false; } @@ -334,7 +313,7 @@ public: * recommendation (but not smaller). * @param planes Memory for each of the Y, U, and V planes. */ - Result getYUV8Planes(const YUVSizeInfo& sizeInfo, void* planes[3]) { + Result getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) { if (nullptr == planes || nullptr == planes[0] || nullptr == planes[1] || nullptr == planes[2]) { return kInvalidInput; @@ -543,11 +522,11 @@ protected: SkPMColor ctable[], int* ctableCount, int* rowsDecoded) = 0; - virtual bool onQueryYUV8(YUVSizeInfo*, SkYUVColorSpace*) const { + virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const { return false; } - virtual Result onGetYUV8Planes(const YUVSizeInfo&, void*[3] /*planes*/) { + virtual Result onGetYUV8Planes(const SkYUVSizeInfo&, void*[3] /*planes*/) { return kUnimplemented; } diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h index 86e3053a06..1a46f6b9cd 100644 --- a/include/core/SkImageGenerator.h +++ b/include/core/SkImageGenerator.h @@ -11,6 +11,7 @@ #include "SkBitmap.h" #include "SkColor.h" #include "SkImageInfo.h" +#include "SkYUVSizeInfo.h" class GrContext; class GrTexture; @@ -129,18 +130,26 @@ public: bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); /** - * If planes or rowBytes is NULL or if any entry in planes is NULL or if any entry in rowBytes - * is 0, this imagegenerator should output the sizes and return true if it can efficiently - * return YUV planar data. If it cannot, it should return false. Note that either planes and - * rowBytes are both fully defined and non NULL/non 0 or they are both NULL or have NULL or 0 - * entries only. Having only partial planes/rowBytes information is not supported. + * If decoding to YUV is supported, this returns true. Otherwise, this + * returns false and does not modify any of the parameters. * - * If all planes and rowBytes entries are non NULL or non 0, then it should copy the - * associated YUV data into those planes of memory supplied by the caller. It should validate - * that the sizes match what it expected. If the sizes do not match, it should return false. + * @param sizeInfo Output parameter indicating the sizes and required + * allocation widths of the Y, U, and V planes. + * @param colorSpace Output parameter. */ - bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], - SkYUVColorSpace* colorSpace); + bool queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const; + + /** + * Returns true on success and false on failure. + * This always attempts to perform a full decode. If the client only + * wants size, it should call queryYUV8(). + * + * @param sizeInfo Needs to exactly match the values returned by the + * query, except the WidthBytes may be larger than the + * recommendation (but not smaller). + * @param planes Memory for each of the Y, U, and V planes. + */ + bool getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]); /** * If the generator can natively/efficiently return its pixels as a GPU image (backed by a @@ -248,9 +257,13 @@ protected: virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[], int* ctableCount); - virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3]); - virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], - SkYUVColorSpace* colorSpace); + + virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const { + return false; + } + virtual bool onGetYUV8Planes(const SkYUVSizeInfo&, void*[3] /*planes*/) { + return false; + } virtual GrTexture* onGenerateTexture(GrContext*, const SkIRect*) { return nullptr; diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h index e1ce6d4c7f..651176ebbb 100644 --- a/include/core/SkPixelRef.h +++ b/include/core/SkPixelRef.h @@ -18,6 +18,7 @@ #include "SkRefCnt.h" #include "SkSize.h" #include "SkString.h" +#include "SkYUVSizeInfo.h" class SkColorTable; class SkData; @@ -210,19 +211,28 @@ public: virtual GrTexture* getTexture() { return NULL; } /** - * If any planes or rowBytes is NULL, this should output the sizes and return true - * if it can efficiently return YUV planar data. If it cannot, it should return false. + * If this can efficiently return YUV data, this should return true. + * Otherwise this returns false and does not modify any of the parameters. * - * If all planes and rowBytes are not NULL, then it should copy the associated Y,U,V data - * into those planes of memory supplied by the caller. It should validate that the sizes - * match what it expected. If the sizes do not match, it should return false. + * @param sizeInfo Output parameter indicating the sizes and required + * allocation widths of the Y, U, and V planes. + * @param colorSpace Output parameter. + */ + bool queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { + return this->onQueryYUV8(sizeInfo, colorSpace); + } + + /** + * Returns true on success and false on failure. + * Copies YUV data into the provided YUV planes. * - * If colorSpace is not NULL, the YUV color space of the data should be stored in the address - * it points at. + * @param sizeInfo Needs to exactly match the values returned by the + * query, except the WidthBytes may be larger than the + * recommendation (but not smaller). + * @param planes Memory for each of the Y, U, and V planes. */ - bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], - SkYUVColorSpace* colorSpace) { - return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace); + bool getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) { + return this->onGetYUV8Planes(sizeInfo, planes); } /** Populates dst with the pixels of this pixelRef, converting them to colorType. */ @@ -308,9 +318,12 @@ protected: // default impl does nothing. virtual void onNotifyPixelsChanged(); - // default impl returns false. - virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], - SkYUVColorSpace* colorSpace); + virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const { + return false; + } + virtual bool onGetYUV8Planes(const SkYUVSizeInfo&, void*[3] /*planes*/) { + return false; + } /** * Returns the size (in bytes) of the internally allocated memory. diff --git a/include/core/SkYUVSizeInfo.h b/include/core/SkYUVSizeInfo.h new file mode 100644 index 0000000000..2c5a51d794 --- /dev/null +++ b/include/core/SkYUVSizeInfo.h @@ -0,0 +1,34 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkYUVSizeInfo_DEFINED +#define SkYUVSizeInfo_DEFINED + +struct SkYUVSizeInfo { + enum { + kY = 0, + kU = 1, + kV = 2, + }; + SkISize fSizes[3]; + + /** + * While the widths of the Y, U, and V planes are not restricted, the + * implementation often requires that the width of the memory allocated + * for each plane be a multiple of 8. + * + * This struct allows us to inform the client how many "widthBytes" + * that we need. Note that we use the new idea of "widthBytes" + * because this idea is distinct from "rowBytes" (used elsewhere in + * Skia). "rowBytes" allow the last row of the allocation to not + * include any extra padding, while, in this case, every single row of + * the allocation must be at least "widthBytes". + */ + size_t fWidthBytes[3]; +}; + +#endif // SkYUVSizeInfo_DEFINED diff --git a/src/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp index e6e164ef61..e579da92f6 100644 --- a/src/codec/SkCodecImageGenerator.cpp +++ b/src/codec/SkCodecImageGenerator.cpp @@ -28,9 +28,6 @@ SkCodecImageGenerator::SkCodecImageGenerator(SkCodec* codec, SkData* data) : INHERITED(make_premul(codec->getInfo())) , fCodec(codec) , fData(SkRef(data)) - , fYWidth(0) - , fUWidth(0) - , fVWidth(0) {} SkData* SkCodecImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) { @@ -51,47 +48,13 @@ bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, s } } -bool SkCodecImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], - SkYUVColorSpace* colorSpace) { - // TODO (msarett): Change the YUV API in ImageGenerator to match SkCodec. - // This function is currently a hack to match the implementation - // in SkCodec with the old API. - SkCodec::YUVSizeInfo sizeInfo; - - // If planes is NULL, we just need to return the size. - if (nullptr == planes) { - bool result = fCodec->queryYUV8(&sizeInfo, colorSpace); - if (result) { - // Save the true widths - fYWidth = sizeInfo.fYSize.width(); - fUWidth = sizeInfo.fUSize.width(); - fVWidth = sizeInfo.fVSize.width(); - - // Set the sizes so that the client allocates enough memory - sizes[0].fWidth = (int) sizeInfo.fYWidthBytes; - sizes[0].fHeight = sizeInfo.fYSize.height(); - sizes[1].fWidth = (int) sizeInfo.fUWidthBytes; - sizes[1].fHeight = sizeInfo.fUSize.height(); - sizes[2].fWidth = (int) sizeInfo.fVWidthBytes; - sizes[2].fHeight = sizeInfo.fVSize.height(); - } - return result; - } - - // Set the sizeInfo with the true widths and heights - SkASSERT(fYWidth != 0 && fUWidth != 0 && fVWidth != 0); - sizeInfo.fYSize.set(fYWidth, sizes[0].height()); - sizeInfo.fUSize.set(fUWidth, sizes[1].height()); - sizeInfo.fVSize.set(fVWidth, sizes[2].height()); +bool SkCodecImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const +{ + return fCodec->queryYUV8(sizeInfo, colorSpace); +} - // Set the sizeInfo with the allocated widths - sizeInfo.fYWidthBytes = sizes[0].width(); - sizeInfo.fUWidthBytes = sizes[1].width(); - sizeInfo.fVWidthBytes = sizes[2].width(); +bool SkCodecImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) { SkCodec::Result result = fCodec->getYUV8Planes(sizeInfo, planes); - if ((result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput) && colorSpace) { - *colorSpace = kJPEG_SkYUVColorSpace; - } switch (result) { case SkCodec::kSuccess: diff --git a/src/codec/SkCodecImageGenerator.h b/src/codec/SkCodecImageGenerator.h index d2c74ab482..6d34223110 100644 --- a/src/codec/SkCodecImageGenerator.h +++ b/src/codec/SkCodecImageGenerator.h @@ -26,8 +26,9 @@ protected: bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[], int* ctableCount) override; - bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], - SkYUVColorSpace* colorSpace) override; + bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const override; + + bool onGetYUV8Planes(const SkYUVSizeInfo&, void* planes[3]) override; private: /* @@ -39,11 +40,5 @@ private: SkAutoTDelete<SkCodec> fCodec; SkAutoTUnref<SkData> fData; - // FIXME: These fields are necessary only until we change the API of SkImageGenerator - // to match SkCodec. Once the API is changed, they should be removed. - int fYWidth; - int fUWidth; - int fVWidth; - typedef SkImageGenerator INHERITED; }; diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp index b5780c5581..f1b55df06e 100644 --- a/src/codec/SkJpegCodec.cpp +++ b/src/codec/SkJpegCodec.cpp @@ -594,21 +594,21 @@ static bool is_yuv_supported(jpeg_decompress_struct* dinfo) { (4 == hSampY && 2 == vSampY); } -bool SkJpegCodec::onQueryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { +bool SkJpegCodec::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo(); if (!is_yuv_supported(dinfo)) { return false; } - sizeInfo->fYSize.set(dinfo->comp_info[0].downsampled_width, - dinfo->comp_info[0].downsampled_height); - sizeInfo->fUSize.set(dinfo->comp_info[1].downsampled_width, - dinfo->comp_info[1].downsampled_height); - sizeInfo->fVSize.set(dinfo->comp_info[2].downsampled_width, - dinfo->comp_info[2].downsampled_height); - sizeInfo->fYWidthBytes = dinfo->comp_info[0].width_in_blocks * DCTSIZE; - sizeInfo->fUWidthBytes = dinfo->comp_info[1].width_in_blocks * DCTSIZE; - sizeInfo->fVWidthBytes = dinfo->comp_info[2].width_in_blocks * DCTSIZE; + sizeInfo->fSizes[SkYUVSizeInfo::kY].set(dinfo->comp_info[0].downsampled_width, + dinfo->comp_info[0].downsampled_height); + sizeInfo->fSizes[SkYUVSizeInfo::kU].set(dinfo->comp_info[1].downsampled_width, + dinfo->comp_info[1].downsampled_height); + sizeInfo->fSizes[SkYUVSizeInfo::kV].set(dinfo->comp_info[2].downsampled_width, + dinfo->comp_info[2].downsampled_height); + sizeInfo->fWidthBytes[SkYUVSizeInfo::kY] = dinfo->comp_info[0].width_in_blocks * DCTSIZE; + sizeInfo->fWidthBytes[SkYUVSizeInfo::kU] = dinfo->comp_info[1].width_in_blocks * DCTSIZE; + sizeInfo->fWidthBytes[SkYUVSizeInfo::kV] = dinfo->comp_info[2].width_in_blocks * DCTSIZE; if (colorSpace) { *colorSpace = kJPEG_SkYUVColorSpace; @@ -617,17 +617,18 @@ bool SkJpegCodec::onQueryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace return true; } -SkCodec::Result SkJpegCodec::onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void* pixels[3]) { - YUVSizeInfo defaultInfo; +SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) { + SkYUVSizeInfo defaultInfo; // This will check is_yuv_supported(), so we don't need to here. bool supportsYUV = this->onQueryYUV8(&defaultInfo, nullptr); - if (!supportsYUV || sizeInfo.fYSize != defaultInfo.fYSize || - sizeInfo.fUSize != defaultInfo.fUSize || - sizeInfo.fVSize != defaultInfo.fVSize || - sizeInfo.fYWidthBytes < defaultInfo.fYWidthBytes || - sizeInfo.fUWidthBytes < defaultInfo.fUWidthBytes || - sizeInfo.fVWidthBytes < defaultInfo.fVWidthBytes) { + if (!supportsYUV || + sizeInfo.fSizes[SkYUVSizeInfo::kY] != defaultInfo.fSizes[SkYUVSizeInfo::kY] || + sizeInfo.fSizes[SkYUVSizeInfo::kU] != defaultInfo.fSizes[SkYUVSizeInfo::kU] || + sizeInfo.fSizes[SkYUVSizeInfo::kV] != defaultInfo.fSizes[SkYUVSizeInfo::kV] || + sizeInfo.fWidthBytes[SkYUVSizeInfo::kY] < defaultInfo.fWidthBytes[SkYUVSizeInfo::kY] || + sizeInfo.fWidthBytes[SkYUVSizeInfo::kU] < defaultInfo.fWidthBytes[SkYUVSizeInfo::kU] || + sizeInfo.fWidthBytes[SkYUVSizeInfo::kV] < defaultInfo.fWidthBytes[SkYUVSizeInfo::kV]) { return fDecoderMgr->returnFailure("onGetYUV8Planes", kInvalidInput); } @@ -651,9 +652,9 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void* // Currently, we require that the Y plane dimensions match the image dimensions // and that the U and V planes are the same dimensions. - SkASSERT(sizeInfo.fUSize == sizeInfo.fVSize); - SkASSERT((uint32_t) sizeInfo.fYSize.width() == dinfo->output_width && - (uint32_t) sizeInfo.fYSize.height() == dinfo->output_height); + SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kU] == sizeInfo.fSizes[SkYUVSizeInfo::kV]); + SkASSERT((uint32_t) sizeInfo.fSizes[SkYUVSizeInfo::kY].width() == dinfo->output_width && + (uint32_t) sizeInfo.fSizes[SkYUVSizeInfo::kY].height() == dinfo->output_height); // Build a JSAMPIMAGE to handle output from libjpeg-turbo. A JSAMPIMAGE has // a 2-D array of pixels for each of the components (Y, U, V) in the image. @@ -670,17 +671,20 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void* // Initialize rowptrs. int numYRowsPerBlock = DCTSIZE * dinfo->comp_info[0].v_samp_factor; for (int i = 0; i < numYRowsPerBlock; i++) { - rowptrs[i] = SkTAddOffset<JSAMPLE>(pixels[0], i * sizeInfo.fYWidthBytes); + rowptrs[i] = SkTAddOffset<JSAMPLE>(planes[SkYUVSizeInfo::kY], + i * sizeInfo.fWidthBytes[SkYUVSizeInfo::kY]); } for (int i = 0; i < DCTSIZE; i++) { - rowptrs[i + 2 * DCTSIZE] = SkTAddOffset<JSAMPLE>(pixels[1], i * sizeInfo.fUWidthBytes); - rowptrs[i + 3 * DCTSIZE] = SkTAddOffset<JSAMPLE>(pixels[2], i * sizeInfo.fVWidthBytes); + rowptrs[i + 2 * DCTSIZE] = SkTAddOffset<JSAMPLE>(planes[SkYUVSizeInfo::kU], + i * sizeInfo.fWidthBytes[SkYUVSizeInfo::kU]); + rowptrs[i + 3 * DCTSIZE] = SkTAddOffset<JSAMPLE>(planes[SkYUVSizeInfo::kV], + i * sizeInfo.fWidthBytes[SkYUVSizeInfo::kV]); } // After each loop iteration, we will increment pointers to Y, U, and V. - size_t blockIncrementY = numYRowsPerBlock * sizeInfo.fYWidthBytes; - size_t blockIncrementU = DCTSIZE * sizeInfo.fUWidthBytes; - size_t blockIncrementV = DCTSIZE * sizeInfo.fVWidthBytes; + size_t blockIncrementY = numYRowsPerBlock * sizeInfo.fWidthBytes[SkYUVSizeInfo::kY]; + size_t blockIncrementU = DCTSIZE * sizeInfo.fWidthBytes[SkYUVSizeInfo::kU]; + size_t blockIncrementV = DCTSIZE * sizeInfo.fWidthBytes[SkYUVSizeInfo::kV]; uint32_t numRowsPerBlock = numYRowsPerBlock; @@ -713,7 +717,7 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void* // this requirement using a dummy row buffer. // FIXME: Should SkCodec have an extra memory buffer that can be shared among // all of the implementations that use temporary/garbage memory? - SkAutoTMalloc<JSAMPLE> dummyRow(sizeInfo.fYWidthBytes); + SkAutoTMalloc<JSAMPLE> dummyRow(sizeInfo.fWidthBytes[SkYUVSizeInfo::kY]); for (int i = remainingRows; i < numYRowsPerBlock; i++) { rowptrs[i] = dummyRow.get(); } diff --git a/src/codec/SkJpegCodec.h b/src/codec/SkJpegCodec.h index e3448e9dd1..049c3c956a 100644 --- a/src/codec/SkJpegCodec.h +++ b/src/codec/SkJpegCodec.h @@ -46,9 +46,9 @@ protected: Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options&, SkPMColor*, int*, int*) override; - bool onQueryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override; + bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override; - Result onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void* pixels[3]) override; + Result onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override; SkEncodedFormat onGetEncodedFormat() const override { return kJPEG_SkEncodedFormat; diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index ea4d4c2bab..e9b7f6a82a 100644 --- a/src/core/SkImageCacherator.cpp +++ b/src/core/SkImageCacherator.cpp @@ -213,12 +213,11 @@ public: Generator_GrYUVProvider(SkImageGenerator* gen) : fGen(gen) {} uint32_t onGetID() override { return fGen->uniqueID(); } - bool onGetYUVSizes(SkISize sizes[3]) override { - return fGen->getYUV8Planes(sizes, nullptr, nullptr, nullptr); + bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override { + return fGen->queryYUV8(sizeInfo, colorSpace); } - bool onGetYUVPlanes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], - SkYUVColorSpace* space) override { - return fGen->getYUV8Planes(sizes, planes, rowBytes, space); + bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override { + return fGen->getYUV8Planes(sizeInfo, planes); } }; diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp index 7d71b6701c..c8c94c2270 100644 --- a/src/core/SkImageGenerator.cpp +++ b/src/core/SkImageGenerator.cpp @@ -52,56 +52,28 @@ bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t r return this->getPixels(info, pixels, rowBytes, nullptr, nullptr); } -bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], - SkYUVColorSpace* colorSpace) { -#ifdef SK_DEBUG - // In all cases, we need the sizes array - SkASSERT(sizes); - - bool isValidWithPlanes = (planes) && (rowBytes) && - ((planes[0]) && (planes[1]) && (planes[2]) && - (0 != rowBytes[0]) && (0 != rowBytes[1]) && (0 != rowBytes[2])); - bool isValidWithoutPlanes = - ((nullptr == planes) || - ((nullptr == planes[0]) && (nullptr == planes[1]) && (nullptr == planes[2]))) && - ((nullptr == rowBytes) || - ((0 == rowBytes[0]) && (0 == rowBytes[1]) && (0 == rowBytes[2]))); - - // Either we have all planes and rowBytes information or we have none of it - // Having only partial information is not supported - SkASSERT(isValidWithPlanes || isValidWithoutPlanes); - - // If we do have planes information, make sure all sizes are non 0 - // and all rowBytes are valid - SkASSERT(!isValidWithPlanes || - ((sizes[0].fWidth >= 0) && - (sizes[0].fHeight >= 0) && - (sizes[1].fWidth >= 0) && - (sizes[1].fHeight >= 0) && - (sizes[2].fWidth >= 0) && - (sizes[2].fHeight >= 0) && - (rowBytes[0] >= (size_t)sizes[0].fWidth) && - (rowBytes[1] >= (size_t)sizes[1].fWidth) && - (rowBytes[2] >= (size_t)sizes[2].fWidth))); -#endif +bool SkImageGenerator::queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { + SkASSERT(sizeInfo); - return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace); + return this->onQueryYUV8(sizeInfo, colorSpace); } -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); +bool SkImageGenerator::getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) { + SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth >= 0); + SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight >= 0); + SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kU].fWidth >= 0); + SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight >= 0); + SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kV].fWidth >= 0); + SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kV].fHeight >= 0); + SkASSERT(sizeInfo.fWidthBytes[SkYUVSizeInfo::kY] >= + (size_t) sizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth); + SkASSERT(sizeInfo.fWidthBytes[SkYUVSizeInfo::kU] >= + (size_t) sizeInfo.fSizes[SkYUVSizeInfo::kU].fWidth); + SkASSERT(sizeInfo.fWidthBytes[SkYUVSizeInfo::kV] >= + (size_t) sizeInfo.fSizes[SkYUVSizeInfo::kV].fWidth); + SkASSERT(planes && planes[0] && planes[1] && planes[2]); + + return this->onGetYUV8Planes(sizeInfo, planes); } GrTexture* SkImageGenerator::generateTexture(GrContext* ctx, const SkIRect* subset) { diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp index 0825760ccd..cdc318b2a8 100644 --- a/src/core/SkPixelRef.cpp +++ b/src/core/SkPixelRef.cpp @@ -323,11 +323,6 @@ SkData* SkPixelRef::onRefEncodedData() { return nullptr; } -bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], - SkYUVColorSpace* colorSpace) { - return false; -} - size_t SkPixelRef::getAllocatedSizeInBytes() const { return 0; } diff --git a/src/core/SkYUVPlanesCache.h b/src/core/SkYUVPlanesCache.h index a024192d07..1c866a2d2b 100644 --- a/src/core/SkYUVPlanesCache.h +++ b/src/core/SkYUVPlanesCache.h @@ -10,6 +10,7 @@ #include "SkCachedData.h" #include "SkImageInfo.h" +#include "SkYUVSizeInfo.h" class SkResourceCache; @@ -19,17 +20,11 @@ public: * The Info struct contains data about the 3 Y, U and V planes of memory stored * contiguously, in that order, as a single block of memory within SkYUVPlanesCache. * - * fSize: Width and height of each of the 3 planes (in pixels). - * fSizeInMemory: Amount of memory allocated for each plane (may be different from - "height * rowBytes", depending on the jpeg decoder's block size). - * The sum of these is the total size stored within SkYUVPlanesCache. - * fRowBytes: rowBytes for each of the 3 planes (in bytes). + * fSizeInfo: fWidth, fHeight, and fWidthBytes of each of the Y, U, and V planes. * fColorSpace: color space that will be used for the YUV -> RGB conversion. */ struct Info { - SkISize fSize[3]; - size_t fSizeInMemory[3]; - size_t fRowBytes[3]; + SkYUVSizeInfo fSizeInfo; SkYUVColorSpace fColorSpace; }; /** diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp index f889641849..708cbecb11 100644 --- a/src/gpu/GrYUVProvider.cpp +++ b/src/gpu/GrYUVProvider.cpp @@ -40,21 +40,20 @@ bool YUVScoper::init(GrYUVProvider* provider, SkYUVPlanesCache::Info* yuvInfo, v if (fCachedData.get()) { planes[0] = (void*)fCachedData->data(); - planes[1] = (uint8_t*)planes[0] + yuvInfo->fSizeInMemory[0]; - planes[2] = (uint8_t*)planes[1] + yuvInfo->fSizeInMemory[1]; + planes[1] = (uint8_t*)planes[0] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kY] * + yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); + planes[2] = (uint8_t*)planes[1] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kU] * + yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight); } else { - // Fetch yuv plane sizes for memory allocation. Here, width and height can be - // rounded up to JPEG block size and be larger than the image's width and height. - if (!provider->onGetYUVSizes(yuvInfo->fSize)) { + // Fetch yuv plane sizes for memory allocation. + if (!provider->onQueryYUV8(&yuvInfo->fSizeInfo, &yuvInfo->fColorSpace)) { return false; } // Allocate the memory for YUV size_t totalSize(0); - for (int i = 0; i < GrYUVProvider::kPlaneCount; ++i) { - yuvInfo->fRowBytes[i] = yuvInfo->fSize[i].fWidth; // we assume snug fit: rb == width - yuvInfo->fSizeInMemory[i] = yuvInfo->fRowBytes[i] * yuvInfo->fSize[i].fHeight; - totalSize += yuvInfo->fSizeInMemory[i]; + for (int i = 0; i < 3; i++) { + totalSize += yuvInfo->fSizeInfo.fWidthBytes[i] * yuvInfo->fSizeInfo.fSizes[i].fHeight; } if (useCache) { fCachedData.reset(SkResourceCache::NewCachedData(totalSize)); @@ -63,12 +62,13 @@ bool YUVScoper::init(GrYUVProvider* provider, SkYUVPlanesCache::Info* yuvInfo, v fStorage.reset(totalSize); planes[0] = fStorage.get(); } - planes[1] = (uint8_t*)planes[0] + yuvInfo->fSizeInMemory[0]; - planes[2] = (uint8_t*)planes[1] + yuvInfo->fSizeInMemory[1]; + planes[1] = (uint8_t*)planes[0] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kY] * + yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); + planes[2] = (uint8_t*)planes[1] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kU] * + yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight); - // Get the YUV planes and update plane sizes to actual image size - if (!provider->onGetYUVPlanes(yuvInfo->fSize, planes, yuvInfo->fRowBytes, - &yuvInfo->fColorSpace)) { + // Get the YUV planes. + if (!provider->onGetYUV8Planes(yuvInfo->fSizeInfo, planes)) { return false; } @@ -91,20 +91,21 @@ GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc GrSurfaceDesc yuvDesc; yuvDesc.fConfig = kAlpha_8_GrPixelConfig; SkAutoTUnref<GrTexture> yuvTextures[3]; - for (int i = 0; i < 3; ++i) { - yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; - yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; + for (int i = 0; i < 3; i++) { + yuvDesc.fWidth = yuvInfo.fSizeInfo.fSizes[i].fWidth; + yuvDesc.fHeight = yuvInfo.fSizeInfo.fSizes[i].fHeight; // TODO: why do we need this check? - bool needsExactTexture = (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) || - (yuvDesc.fHeight != yuvInfo.fSize[0].fHeight); + bool needsExactTexture = + (yuvDesc.fWidth != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth) || + (yuvDesc.fHeight != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); if (needsExactTexture) { yuvTextures[i].reset(ctx->textureProvider()->createTexture(yuvDesc, SkBudgeted::kYes)); } else { yuvTextures[i].reset(ctx->textureProvider()->createApproxTexture(yuvDesc)); } if (!yuvTextures[i] || - !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, - yuvDesc.fConfig, planes[i], yuvInfo.fRowBytes[i])) { + !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, yuvDesc.fConfig, + planes[i], yuvInfo.fSizeInfo.fWidthBytes[i])) { return nullptr; } } @@ -126,11 +127,12 @@ GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc GrYUVEffect::CreateYUVToRGB(yuvTextures[0], yuvTextures[1], yuvTextures[2], - yuvInfo.fSize, + yuvInfo.fSizeInfo.fSizes, yuvInfo.fColorSpace)); paint.addColorFragmentProcessor(yuvToRgbProcessor); paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); - const SkRect r = SkRect::MakeIWH(yuvInfo.fSize[0].fWidth, yuvInfo.fSize[0].fHeight); + const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth, + yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(renderTarget)); if (!drawContext) { diff --git a/src/gpu/GrYUVProvider.h b/src/gpu/GrYUVProvider.h index 869e1fd00d..85b238d098 100644 --- a/src/gpu/GrYUVProvider.h +++ b/src/gpu/GrYUVProvider.h @@ -10,6 +10,7 @@ #include "GrTypes.h" #include "SkImageInfo.h" +#include "SkYUVSizeInfo.h" class GrContext; class GrTexture; @@ -38,32 +39,29 @@ public: virtual uint32_t onGetID() = 0; - enum { - kY_Index = 0, - kU_Index = 1, - kV_Index = 2, - - kPlaneCount = 3 - }; - // These are not meant to be called by a client, only by the implementation /** - * Return the 3 dimensions for each plane and return true. On failure, return false and - * ignore the sizes parameter. Typical failure is that the provider does not contain YUV - * data, and may just be an RGB src. + * If decoding to YUV is supported, this returns true. Otherwise, this + * returns false and does not modify any of the parameters. + * + * @param sizeInfo Output parameter indicating the sizes and required + * allocation widths of the Y, U, and V planes. + * @param colorSpace Output parameter. */ - virtual bool onGetYUVSizes(SkISize sizes[kPlaneCount]) = 0; + virtual bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const = 0; /** - * On success, return true, and set sizes, rowbytes and colorspace to the appropriate values. - * planes[] will have already been allocated by the client (based on the worst-case sizes - * returned by onGetYUVSizes(). This method copies its planar data into those buffers. + * Returns true on success and false on failure. + * This always attempts to perform a full decode. If the client only + * wants size, it should call onQueryYUV8(). * - * On failure, return false and ignore other parameters. + * @param sizeInfo Needs to exactly match the values returned by the + * query, except the WidthBytes may be larger than the + * recommendation (but not smaller). + * @param planes Memory for each of the Y, U, and V planes. */ - virtual bool onGetYUVPlanes(SkISize sizes[kPlaneCount], void* planes[kPlaneCount], - size_t rowBytes[kPlaneCount], SkYUVColorSpace*) = 0; + virtual bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) = 0; }; #endif diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 81a3502455..1463336c49 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -173,12 +173,11 @@ public: PixelRef_GrYUVProvider(SkPixelRef* pr) : fPR(pr) {} uint32_t onGetID() override { return fPR->getGenerationID(); } - bool onGetYUVSizes(SkISize sizes[3]) override { - return fPR->getYUV8Planes(sizes, nullptr, nullptr, nullptr); + bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override { + return fPR->queryYUV8(sizeInfo, colorSpace); } - bool onGetYUVPlanes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], - SkYUVColorSpace* space) override { - return fPR->getYUV8Planes(sizes, planes, rowBytes, space); + bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override { + return fPR->getYUV8Planes(sizeInfo, planes); } }; diff --git a/src/lazy/SkDiscardablePixelRef.h b/src/lazy/SkDiscardablePixelRef.h index 695d441d2b..73a2b08250 100644 --- a/src/lazy/SkDiscardablePixelRef.h +++ b/src/lazy/SkDiscardablePixelRef.h @@ -54,16 +54,22 @@ private: size_t rowBytes, SkDiscardableMemory::Factory* factory); - bool onGetYUV8Planes(SkISize sizes[3], - void* planes[3], - size_t rowBytes[3], - SkYUVColorSpace* colorSpace) override { + bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override { // If the image was already decoded with lockPixels(), favor not // re-decoding to YUV8 planes. if (fDiscardableMemory) { return false; } - return fGenerator->getYUV8Planes(sizes, planes, rowBytes, colorSpace); + return fGenerator->queryYUV8(sizeInfo, colorSpace); + } + + bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override { + // If the image was already decoded with lockPixels(), favor not + // re-decoding to YUV8 planes. + if (fDiscardableMemory) { + return false; + } + return fGenerator->getYUV8Planes(sizeInfo, planes); } friend bool SkDEPRECATED_InstallDiscardablePixelRef(SkImageGenerator*, const SkIRect*, SkBitmap*, diff --git a/tests/ImageGeneratorTest.cpp b/tests/ImageGeneratorTest.cpp index 7288ecf0a9..3d750b2c73 100644 --- a/tests/ImageGeneratorTest.cpp +++ b/tests/ImageGeneratorTest.cpp @@ -46,27 +46,25 @@ public: DEF_TEST(ImageGenerator, reporter) { MyImageGenerator ig; - SkISize sizes[3]; - sizes[0] = SkISize::Make(200, 200); - sizes[1] = SkISize::Make(100, 100); - sizes[2] = SkISize::Make( 50, 50); - void* planes[3] = { nullptr }; - size_t rowBytes[3] = { 0 }; + SkYUVSizeInfo sizeInfo; + sizeInfo.fSizes[SkYUVSizeInfo::kY] = SkISize::Make(200, 200); + sizeInfo.fSizes[SkYUVSizeInfo::kU] = SkISize::Make(100, 100); + sizeInfo.fSizes[SkYUVSizeInfo::kV] = SkISize::Make( 50, 50); + sizeInfo.fWidthBytes[SkYUVSizeInfo::kY] = 0; + sizeInfo.fWidthBytes[SkYUVSizeInfo::kU] = 0; + sizeInfo.fWidthBytes[SkYUVSizeInfo::kV] = 0; + void* planes[3] = { nullptr }; SkYUVColorSpace colorSpace; // Check that the YUV decoding API does not cause any crashes - ig.getYUV8Planes(sizes, nullptr, nullptr, &colorSpace); - ig.getYUV8Planes(sizes, nullptr, nullptr, nullptr); - ig.getYUV8Planes(sizes, planes, nullptr, nullptr); - ig.getYUV8Planes(sizes, nullptr, rowBytes, nullptr); - ig.getYUV8Planes(sizes, planes, rowBytes, nullptr); - ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace); - + ig.queryYUV8(&sizeInfo, nullptr); + ig.queryYUV8(&sizeInfo, &colorSpace); + sizeInfo.fWidthBytes[SkYUVSizeInfo::kY] = 250; + sizeInfo.fWidthBytes[SkYUVSizeInfo::kU] = 250; + sizeInfo.fWidthBytes[SkYUVSizeInfo::kV] = 250; int dummy; - planes[0] = planes[1] = planes[2] = &dummy; - rowBytes[0] = rowBytes[1] = rowBytes[2] = 250; - - ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace); + planes[SkYUVSizeInfo::kY] = planes[SkYUVSizeInfo::kU] = planes[SkYUVSizeInfo::kV] = &dummy; + ig.getYUV8Planes(sizeInfo, planes); // Suppressed due to https://code.google.com/p/skia/issues/detail?id=4339 if (false) { diff --git a/tests/YUVCacheTest.cpp b/tests/YUVCacheTest.cpp index f3a09f116b..b34cf060a5 100644 --- a/tests/YUVCacheTest.cpp +++ b/tests/YUVCacheTest.cpp @@ -32,11 +32,10 @@ DEF_TEST(YUVPlanesCache, reporter) { SkResourceCache cache(1024); SkYUVPlanesCache::Info yuvInfo; - for (int i = 0; i < 3; ++i) { - yuvInfo.fSize[i].fWidth = 20 * i; - yuvInfo.fSize[i].fHeight = 10 * i; - yuvInfo.fSizeInMemory[i] = 800 * i; - yuvInfo.fRowBytes[i] = 80 * i; + for (int i = 0; i < 3; i++) { + yuvInfo.fSizeInfo.fSizes[i].fWidth = 20 * i; + yuvInfo.fSizeInfo.fSizes[i].fHeight = 10 * i; + yuvInfo.fSizeInfo.fWidthBytes[i] = 80 * i; } yuvInfo.fColorSpace = kRec601_SkYUVColorSpace; @@ -61,10 +60,12 @@ DEF_TEST(YUVPlanesCache, reporter) { REPORTER_ASSERT(reporter, data); REPORTER_ASSERT(reporter, data->size() == size); for (int i = 0; i < 3; ++i) { - REPORTER_ASSERT(reporter, yuvInfo.fSize[i].fWidth == yuvInfoRead.fSize[i].fWidth); - REPORTER_ASSERT(reporter, yuvInfo.fSize[i].fHeight == yuvInfoRead.fSize[i].fHeight); - REPORTER_ASSERT(reporter, yuvInfo.fSizeInMemory[i] == yuvInfoRead.fSizeInMemory[i]); - REPORTER_ASSERT(reporter, yuvInfo.fRowBytes[i] == yuvInfoRead.fRowBytes[i]); + REPORTER_ASSERT(reporter, yuvInfo.fSizeInfo.fSizes[i].fWidth == + yuvInfoRead.fSizeInfo.fSizes[i].fWidth); + REPORTER_ASSERT(reporter, yuvInfo.fSizeInfo.fSizes[i].fHeight == + yuvInfoRead.fSizeInfo.fSizes[i].fHeight); + REPORTER_ASSERT(reporter, yuvInfo.fSizeInfo.fWidthBytes[i] == + yuvInfoRead.fSizeInfo.fWidthBytes[i]); } REPORTER_ASSERT(reporter, yuvInfo.fColorSpace == yuvInfoRead.fColorSpace); diff --git a/tests/YUVTest.cpp b/tests/YUVTest.cpp index b8c4e3598e..e1d8961205 100644 --- a/tests/YUVTest.cpp +++ b/tests/YUVTest.cpp @@ -9,6 +9,7 @@ #include "Resources.h" #include "SkStream.h" #include "SkTemplates.h" +#include "SkYUVSizeInfo.h" #include "Test.h" static SkStreamAsset* resource(const char path[]) { @@ -31,7 +32,7 @@ static void codec_yuv(skiatest::Reporter* reporter, } // Test queryYUV8() - SkCodec::YUVSizeInfo info; + SkYUVSizeInfo info; bool success = codec->queryYUV8(nullptr, nullptr); REPORTER_ASSERT(reporter, !success); success = codec->queryYUV8(&info, nullptr); @@ -41,27 +42,36 @@ static void codec_yuv(skiatest::Reporter* reporter, } REPORTER_ASSERT(reporter, 0 == memcmp((const void*) &info, (const void*) expectedSizes, 3 * sizeof(SkISize))); - REPORTER_ASSERT(reporter, info.fYWidthBytes == (uint32_t) SkAlign8(info.fYSize.width())); - REPORTER_ASSERT(reporter, info.fUWidthBytes == (uint32_t) SkAlign8(info.fUSize.width())); - REPORTER_ASSERT(reporter, info.fVWidthBytes == (uint32_t) SkAlign8(info.fVSize.width())); + REPORTER_ASSERT(reporter, info.fWidthBytes[SkYUVSizeInfo::kY] == + (uint32_t) SkAlign8(info.fSizes[SkYUVSizeInfo::kY].width())); + REPORTER_ASSERT(reporter, info.fWidthBytes[SkYUVSizeInfo::kU] == + (uint32_t) SkAlign8(info.fSizes[SkYUVSizeInfo::kU].width())); + REPORTER_ASSERT(reporter, info.fWidthBytes[SkYUVSizeInfo::kV] == + (uint32_t) SkAlign8(info.fSizes[SkYUVSizeInfo::kV].width())); SkYUVColorSpace colorSpace; success = codec->queryYUV8(&info, &colorSpace); REPORTER_ASSERT(reporter, 0 == memcmp((const void*) &info, (const void*) expectedSizes, 3 * sizeof(SkISize))); - REPORTER_ASSERT(reporter, info.fYWidthBytes == (uint32_t) SkAlign8(info.fYSize.width())); - REPORTER_ASSERT(reporter, info.fUWidthBytes == (uint32_t) SkAlign8(info.fUSize.width())); - REPORTER_ASSERT(reporter, info.fVWidthBytes == (uint32_t) SkAlign8(info.fVSize.width())); + REPORTER_ASSERT(reporter, info.fWidthBytes[SkYUVSizeInfo::kY] == + (uint32_t) SkAlign8(info.fSizes[SkYUVSizeInfo::kY].width())); + REPORTER_ASSERT(reporter, info.fWidthBytes[SkYUVSizeInfo::kU] == + (uint32_t) SkAlign8(info.fSizes[SkYUVSizeInfo::kU].width())); + REPORTER_ASSERT(reporter, info.fWidthBytes[SkYUVSizeInfo::kV] == + (uint32_t) SkAlign8(info.fSizes[SkYUVSizeInfo::kV].width())); REPORTER_ASSERT(reporter, kJPEG_SkYUVColorSpace == colorSpace); // Allocate the memory for the YUV decode - size_t totalBytes = info.fYWidthBytes * info.fYSize.height() + - info.fUWidthBytes * info.fUSize.height() + - info.fVWidthBytes * info.fVSize.height(); + size_t totalBytes = + info.fWidthBytes[SkYUVSizeInfo::kY] * info.fSizes[SkYUVSizeInfo::kY].height() + + info.fWidthBytes[SkYUVSizeInfo::kU] * info.fSizes[SkYUVSizeInfo::kU].height() + + info.fWidthBytes[SkYUVSizeInfo::kV] * info.fSizes[SkYUVSizeInfo::kV].height(); SkAutoMalloc storage(totalBytes); void* planes[3]; planes[0] = storage.get(); - planes[1] = SkTAddOffset<void>(planes[0], info.fYWidthBytes * info.fYSize.height()); - planes[2] = SkTAddOffset<void>(planes[1], info.fUWidthBytes * info.fUSize.height()); + planes[1] = SkTAddOffset<void>(planes[0], + info.fWidthBytes[SkYUVSizeInfo::kY] * info.fSizes[SkYUVSizeInfo::kY].height()); + planes[2] = SkTAddOffset<void>(planes[1], + info.fWidthBytes[SkYUVSizeInfo::kU] * info.fSizes[SkYUVSizeInfo::kU].height()); // Test getYUV8Planes() REPORTER_ASSERT(reporter, SkCodec::kInvalidInput == |