diff options
author | msarett <msarett@google.com> | 2016-03-07 09:16:52 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-07 09:16:52 -0800 |
commit | 1590f3b32890f6455b30494308633177b54db347 (patch) | |
tree | 5fabc87ced4a0c49bc304d87306068647e8123c2 | |
parent | 54887a6a2e12b0f2c93e039b00678732b6518826 (diff) |
Revert of Update Skia's YUV API (patchset #5 id:160001 of https://codereview.chromium.org/1716523002/ )
Reason for revert:
Blimp failures with manual roll in Chrome.
Original issue's description:
> Update Skia's YUV API
>
> We should match the recently designed API in SkCodec.
> https://codereview.chromium.org/1549473003/
>
> This requires changes in Chromium as well.
>
> BUG=skia:
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1716523002
>
> Committed: https://skia.googlesource.com/skia/+/095d31c8a0eeb5d491febf064bc3c8a44e22b94f
TBR=scroggo@google.com,reed@google.com,bsalomon@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Review URL: https://codereview.chromium.org/1775493002
-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, 286 insertions, 262 deletions
diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h index 3855064f61..7e7503acae 100644 --- a/include/codec/SkCodec.h +++ b/include/codec/SkCodec.h @@ -15,7 +15,6 @@ #include "SkSize.h" #include "SkStream.h" #include "SkTypes.h" -#include "SkYUVSizeInfo.h" class SkColorSpace; class SkData; @@ -286,6 +285,28 @@ 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. @@ -295,7 +316,7 @@ public: * @param colorSpace Output parameter. If non-NULL this is set to kJPEG, * otherwise this is ignored. */ - bool queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { + bool queryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { if (nullptr == sizeInfo) { return false; } @@ -313,7 +334,7 @@ public: * recommendation (but not smaller). * @param planes Memory for each of the Y, U, and V planes. */ - Result getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) { + Result getYUV8Planes(const YUVSizeInfo& sizeInfo, void* planes[3]) { if (nullptr == planes || nullptr == planes[0] || nullptr == planes[1] || nullptr == planes[2]) { return kInvalidInput; @@ -522,11 +543,11 @@ protected: SkPMColor ctable[], int* ctableCount, int* rowsDecoded) = 0; - virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const { + virtual bool onQueryYUV8(YUVSizeInfo*, SkYUVColorSpace*) const { return false; } - virtual Result onGetYUV8Planes(const SkYUVSizeInfo&, void*[3] /*planes*/) { + virtual Result onGetYUV8Planes(const YUVSizeInfo&, void*[3] /*planes*/) { return kUnimplemented; } diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h index 1a46f6b9cd..86e3053a06 100644 --- a/include/core/SkImageGenerator.h +++ b/include/core/SkImageGenerator.h @@ -11,7 +11,6 @@ #include "SkBitmap.h" #include "SkColor.h" #include "SkImageInfo.h" -#include "SkYUVSizeInfo.h" class GrContext; class GrTexture; @@ -130,26 +129,18 @@ public: bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); /** - * If decoding to YUV is supported, this returns true. Otherwise, this - * returns false and does not modify any of the parameters. + * 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. * - * @param sizeInfo Output parameter indicating the sizes and required - * allocation widths of the Y, U, and V planes. - * @param colorSpace Output parameter. + * 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. */ - 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]); + bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], + SkYUVColorSpace* colorSpace); /** * If the generator can natively/efficiently return its pixels as a GPU image (backed by a @@ -257,13 +248,9 @@ protected: virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[], int* ctableCount); - - virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const { - return false; - } - virtual bool onGetYUV8Planes(const SkYUVSizeInfo&, void*[3] /*planes*/) { - return false; - } + 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 GrTexture* onGenerateTexture(GrContext*, const SkIRect*) { return nullptr; diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h index 651176ebbb..e1ce6d4c7f 100644 --- a/include/core/SkPixelRef.h +++ b/include/core/SkPixelRef.h @@ -18,7 +18,6 @@ #include "SkRefCnt.h" #include "SkSize.h" #include "SkString.h" -#include "SkYUVSizeInfo.h" class SkColorTable; class SkData; @@ -211,28 +210,19 @@ public: virtual GrTexture* getTexture() { return NULL; } /** - * If this can efficiently return YUV data, this should return true. - * Otherwise this returns false and does not modify any of the parameters. + * 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. * - * @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 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 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. + * If colorSpace is not NULL, the YUV color space of the data should be stored in the address + * it points at. */ - bool getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) { - return this->onGetYUV8Planes(sizeInfo, planes); + bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], + SkYUVColorSpace* colorSpace) { + return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace); } /** Populates dst with the pixels of this pixelRef, converting them to colorType. */ @@ -318,12 +308,9 @@ protected: // default impl does nothing. virtual void onNotifyPixelsChanged(); - virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const { - return false; - } - virtual bool onGetYUV8Planes(const SkYUVSizeInfo&, void*[3] /*planes*/) { - return false; - } + // default impl returns false. + virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], + SkYUVColorSpace* colorSpace); /** * Returns the size (in bytes) of the internally allocated memory. diff --git a/include/core/SkYUVSizeInfo.h b/include/core/SkYUVSizeInfo.h deleted file mode 100644 index 2c5a51d794..0000000000 --- a/include/core/SkYUVSizeInfo.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 e579da92f6..e6e164ef61 100644 --- a/src/codec/SkCodecImageGenerator.cpp +++ b/src/codec/SkCodecImageGenerator.cpp @@ -28,6 +28,9 @@ 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) { @@ -48,13 +51,47 @@ bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, s } } -bool SkCodecImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const -{ - return fCodec->queryYUV8(sizeInfo, colorSpace); -} +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::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) { + // Set the sizeInfo with the allocated widths + sizeInfo.fYWidthBytes = sizes[0].width(); + sizeInfo.fUWidthBytes = sizes[1].width(); + sizeInfo.fVWidthBytes = sizes[2].width(); 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 6d34223110..d2c74ab482 100644 --- a/src/codec/SkCodecImageGenerator.h +++ b/src/codec/SkCodecImageGenerator.h @@ -26,9 +26,8 @@ protected: bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[], int* ctableCount) override; - bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const override; - - bool onGetYUV8Planes(const SkYUVSizeInfo&, void* planes[3]) override; + bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], + SkYUVColorSpace* colorSpace) override; private: /* @@ -40,5 +39,11 @@ 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 f1b55df06e..b5780c5581 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(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { +bool SkJpegCodec::onQueryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo(); if (!is_yuv_supported(dinfo)) { return false; } - 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; + 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; if (colorSpace) { *colorSpace = kJPEG_SkYUVColorSpace; @@ -617,18 +617,17 @@ bool SkJpegCodec::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpa return true; } -SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) { - SkYUVSizeInfo defaultInfo; +SkCodec::Result SkJpegCodec::onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void* pixels[3]) { + YUVSizeInfo defaultInfo; // This will check is_yuv_supported(), so we don't need to here. bool supportsYUV = this->onQueryYUV8(&defaultInfo, nullptr); - 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]) { + 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) { return fDecoderMgr->returnFailure("onGetYUV8Planes", kInvalidInput); } @@ -652,9 +651,9 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& 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.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); + SkASSERT(sizeInfo.fUSize == sizeInfo.fVSize); + SkASSERT((uint32_t) sizeInfo.fYSize.width() == dinfo->output_width && + (uint32_t) sizeInfo.fYSize.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. @@ -671,20 +670,17 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& 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>(planes[SkYUVSizeInfo::kY], - i * sizeInfo.fWidthBytes[SkYUVSizeInfo::kY]); + rowptrs[i] = SkTAddOffset<JSAMPLE>(pixels[0], i * sizeInfo.fYWidthBytes); } for (int i = 0; i < DCTSIZE; i++) { - 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]); + rowptrs[i + 2 * DCTSIZE] = SkTAddOffset<JSAMPLE>(pixels[1], i * sizeInfo.fUWidthBytes); + rowptrs[i + 3 * DCTSIZE] = SkTAddOffset<JSAMPLE>(pixels[2], i * sizeInfo.fVWidthBytes); } // After each loop iteration, we will increment pointers to Y, U, and V. - size_t blockIncrementY = numYRowsPerBlock * sizeInfo.fWidthBytes[SkYUVSizeInfo::kY]; - size_t blockIncrementU = DCTSIZE * sizeInfo.fWidthBytes[SkYUVSizeInfo::kU]; - size_t blockIncrementV = DCTSIZE * sizeInfo.fWidthBytes[SkYUVSizeInfo::kV]; + size_t blockIncrementY = numYRowsPerBlock * sizeInfo.fYWidthBytes; + size_t blockIncrementU = DCTSIZE * sizeInfo.fUWidthBytes; + size_t blockIncrementV = DCTSIZE * sizeInfo.fVWidthBytes; uint32_t numRowsPerBlock = numYRowsPerBlock; @@ -717,7 +713,7 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& 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.fWidthBytes[SkYUVSizeInfo::kY]); + SkAutoTMalloc<JSAMPLE> dummyRow(sizeInfo.fYWidthBytes); for (int i = remainingRows; i < numYRowsPerBlock; i++) { rowptrs[i] = dummyRow.get(); } diff --git a/src/codec/SkJpegCodec.h b/src/codec/SkJpegCodec.h index 049c3c956a..e3448e9dd1 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(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override; + bool onQueryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override; - Result onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override; + Result onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void* pixels[3]) override; SkEncodedFormat onGetEncodedFormat() const override { return kJPEG_SkEncodedFormat; diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index e9b7f6a82a..ea4d4c2bab 100644 --- a/src/core/SkImageCacherator.cpp +++ b/src/core/SkImageCacherator.cpp @@ -213,11 +213,12 @@ public: Generator_GrYUVProvider(SkImageGenerator* gen) : fGen(gen) {} uint32_t onGetID() override { return fGen->uniqueID(); } - bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override { - return fGen->queryYUV8(sizeInfo, colorSpace); + bool onGetYUVSizes(SkISize sizes[3]) override { + return fGen->getYUV8Planes(sizes, nullptr, nullptr, nullptr); } - bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override { - return fGen->getYUV8Planes(sizeInfo, planes); + bool onGetYUVPlanes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], + SkYUVColorSpace* space) override { + return fGen->getYUV8Planes(sizes, planes, rowBytes, space); } }; diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp index c8c94c2270..7d71b6701c 100644 --- a/src/core/SkImageGenerator.cpp +++ b/src/core/SkImageGenerator.cpp @@ -52,28 +52,56 @@ bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t r return this->getPixels(info, pixels, rowBytes, nullptr, nullptr); } -bool SkImageGenerator::queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { - SkASSERT(sizeInfo); +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 - return this->onQueryYUV8(sizeInfo, colorSpace); + return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace); } -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); +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); } GrTexture* SkImageGenerator::generateTexture(GrContext* ctx, const SkIRect* subset) { diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp index cdc318b2a8..0825760ccd 100644 --- a/src/core/SkPixelRef.cpp +++ b/src/core/SkPixelRef.cpp @@ -323,6 +323,11 @@ 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 1c866a2d2b..a024192d07 100644 --- a/src/core/SkYUVPlanesCache.h +++ b/src/core/SkYUVPlanesCache.h @@ -10,7 +10,6 @@ #include "SkCachedData.h" #include "SkImageInfo.h" -#include "SkYUVSizeInfo.h" class SkResourceCache; @@ -20,11 +19,17 @@ 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. * - * fSizeInfo: fWidth, fHeight, and fWidthBytes of each of the Y, U, and V planes. + * 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). * fColorSpace: color space that will be used for the YUV -> RGB conversion. */ struct Info { - SkYUVSizeInfo fSizeInfo; + SkISize fSize[3]; + size_t fSizeInMemory[3]; + size_t fRowBytes[3]; SkYUVColorSpace fColorSpace; }; /** diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp index 708cbecb11..f889641849 100644 --- a/src/gpu/GrYUVProvider.cpp +++ b/src/gpu/GrYUVProvider.cpp @@ -40,20 +40,21 @@ bool YUVScoper::init(GrYUVProvider* provider, SkYUVPlanesCache::Info* yuvInfo, v if (fCachedData.get()) { planes[0] = (void*)fCachedData->data(); - 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); + planes[1] = (uint8_t*)planes[0] + yuvInfo->fSizeInMemory[0]; + planes[2] = (uint8_t*)planes[1] + yuvInfo->fSizeInMemory[1]; } else { - // Fetch yuv plane sizes for memory allocation. - if (!provider->onQueryYUV8(&yuvInfo->fSizeInfo, &yuvInfo->fColorSpace)) { + // 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)) { return false; } // Allocate the memory for YUV size_t totalSize(0); - for (int i = 0; i < 3; i++) { - totalSize += yuvInfo->fSizeInfo.fWidthBytes[i] * yuvInfo->fSizeInfo.fSizes[i].fHeight; + 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]; } if (useCache) { fCachedData.reset(SkResourceCache::NewCachedData(totalSize)); @@ -62,13 +63,12 @@ bool YUVScoper::init(GrYUVProvider* provider, SkYUVPlanesCache::Info* yuvInfo, v fStorage.reset(totalSize); planes[0] = fStorage.get(); } - 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); + planes[1] = (uint8_t*)planes[0] + yuvInfo->fSizeInMemory[0]; + planes[2] = (uint8_t*)planes[1] + yuvInfo->fSizeInMemory[1]; - // Get the YUV planes. - if (!provider->onGetYUV8Planes(yuvInfo->fSizeInfo, planes)) { + // Get the YUV planes and update plane sizes to actual image size + if (!provider->onGetYUVPlanes(yuvInfo->fSize, planes, yuvInfo->fRowBytes, + &yuvInfo->fColorSpace)) { return false; } @@ -91,21 +91,20 @@ 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.fSizeInfo.fSizes[i].fWidth; - yuvDesc.fHeight = yuvInfo.fSizeInfo.fSizes[i].fHeight; + for (int i = 0; i < 3; ++i) { + yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; + yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; // TODO: why do we need this check? - bool needsExactTexture = - (yuvDesc.fWidth != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth) || - (yuvDesc.fHeight != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); + bool needsExactTexture = (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) || + (yuvDesc.fHeight != yuvInfo.fSize[0].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.fSizeInfo.fWidthBytes[i])) { + !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, + yuvDesc.fConfig, planes[i], yuvInfo.fRowBytes[i])) { return nullptr; } } @@ -127,12 +126,11 @@ GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc GrYUVEffect::CreateYUVToRGB(yuvTextures[0], yuvTextures[1], yuvTextures[2], - yuvInfo.fSizeInfo.fSizes, + yuvInfo.fSize, yuvInfo.fColorSpace)); paint.addColorFragmentProcessor(yuvToRgbProcessor); paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); - const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth, - yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); + const SkRect r = SkRect::MakeIWH(yuvInfo.fSize[0].fWidth, yuvInfo.fSize[0].fHeight); SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(renderTarget)); if (!drawContext) { diff --git a/src/gpu/GrYUVProvider.h b/src/gpu/GrYUVProvider.h index 85b238d098..869e1fd00d 100644 --- a/src/gpu/GrYUVProvider.h +++ b/src/gpu/GrYUVProvider.h @@ -10,7 +10,6 @@ #include "GrTypes.h" #include "SkImageInfo.h" -#include "SkYUVSizeInfo.h" class GrContext; class GrTexture; @@ -39,29 +38,32 @@ 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 /** - * 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. + * 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. */ - virtual bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const = 0; + virtual bool onGetYUVSizes(SkISize sizes[kPlaneCount]) = 0; /** - * 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 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. * - * @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. + * On failure, return false and ignore other parameters. */ - virtual bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) = 0; + virtual bool onGetYUVPlanes(SkISize sizes[kPlaneCount], void* planes[kPlaneCount], + size_t rowBytes[kPlaneCount], SkYUVColorSpace*) = 0; }; #endif diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 963f5e79ab..a3848c77e0 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -178,11 +178,12 @@ public: PixelRef_GrYUVProvider(SkPixelRef* pr) : fPR(pr) {} uint32_t onGetID() override { return fPR->getGenerationID(); } - bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override { - return fPR->queryYUV8(sizeInfo, colorSpace); + bool onGetYUVSizes(SkISize sizes[3]) override { + return fPR->getYUV8Planes(sizes, nullptr, nullptr, nullptr); } - bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override { - return fPR->getYUV8Planes(sizeInfo, planes); + bool onGetYUVPlanes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], + SkYUVColorSpace* space) override { + return fPR->getYUV8Planes(sizes, planes, rowBytes, space); } }; diff --git a/src/lazy/SkDiscardablePixelRef.h b/src/lazy/SkDiscardablePixelRef.h index 73a2b08250..695d441d2b 100644 --- a/src/lazy/SkDiscardablePixelRef.h +++ b/src/lazy/SkDiscardablePixelRef.h @@ -54,22 +54,16 @@ private: size_t rowBytes, SkDiscardableMemory::Factory* factory); - bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override { + bool onGetYUV8Planes(SkISize sizes[3], + void* planes[3], + size_t rowBytes[3], + SkYUVColorSpace* colorSpace) override { // If the image was already decoded with lockPixels(), favor not // re-decoding to YUV8 planes. if (fDiscardableMemory) { return false; } - 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); + return fGenerator->getYUV8Planes(sizes, planes, rowBytes, colorSpace); } friend bool SkDEPRECATED_InstallDiscardablePixelRef(SkImageGenerator*, const SkIRect*, SkBitmap*, diff --git a/tests/ImageGeneratorTest.cpp b/tests/ImageGeneratorTest.cpp index 3d750b2c73..7288ecf0a9 100644 --- a/tests/ImageGeneratorTest.cpp +++ b/tests/ImageGeneratorTest.cpp @@ -46,25 +46,27 @@ public: DEF_TEST(ImageGenerator, reporter) { MyImageGenerator ig; - 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 }; + 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 }; SkYUVColorSpace colorSpace; // Check that the YUV decoding API does not cause any crashes - ig.queryYUV8(&sizeInfo, nullptr); - ig.queryYUV8(&sizeInfo, &colorSpace); - sizeInfo.fWidthBytes[SkYUVSizeInfo::kY] = 250; - sizeInfo.fWidthBytes[SkYUVSizeInfo::kU] = 250; - sizeInfo.fWidthBytes[SkYUVSizeInfo::kV] = 250; + 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); + int dummy; - planes[SkYUVSizeInfo::kY] = planes[SkYUVSizeInfo::kU] = planes[SkYUVSizeInfo::kV] = &dummy; - ig.getYUV8Planes(sizeInfo, planes); + planes[0] = planes[1] = planes[2] = &dummy; + rowBytes[0] = rowBytes[1] = rowBytes[2] = 250; + + ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace); // 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 b34cf060a5..f3a09f116b 100644 --- a/tests/YUVCacheTest.cpp +++ b/tests/YUVCacheTest.cpp @@ -32,10 +32,11 @@ DEF_TEST(YUVPlanesCache, reporter) { SkResourceCache cache(1024); SkYUVPlanesCache::Info yuvInfo; - 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; + 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; } yuvInfo.fColorSpace = kRec601_SkYUVColorSpace; @@ -60,12 +61,10 @@ 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.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.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.fColorSpace == yuvInfoRead.fColorSpace); diff --git a/tests/YUVTest.cpp b/tests/YUVTest.cpp index e1d8961205..b8c4e3598e 100644 --- a/tests/YUVTest.cpp +++ b/tests/YUVTest.cpp @@ -9,7 +9,6 @@ #include "Resources.h" #include "SkStream.h" #include "SkTemplates.h" -#include "SkYUVSizeInfo.h" #include "Test.h" static SkStreamAsset* resource(const char path[]) { @@ -32,7 +31,7 @@ static void codec_yuv(skiatest::Reporter* reporter, } // Test queryYUV8() - SkYUVSizeInfo info; + SkCodec::YUVSizeInfo info; bool success = codec->queryYUV8(nullptr, nullptr); REPORTER_ASSERT(reporter, !success); success = codec->queryYUV8(&info, nullptr); @@ -42,36 +41,27 @@ 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.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, 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())); 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.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, 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, kJPEG_SkYUVColorSpace == colorSpace); // Allocate the memory for the YUV decode - 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(); + size_t totalBytes = info.fYWidthBytes * info.fYSize.height() + + info.fUWidthBytes * info.fUSize.height() + + info.fVWidthBytes * info.fVSize.height(); SkAutoMalloc storage(totalBytes); void* planes[3]; planes[0] = storage.get(); - 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()); + planes[1] = SkTAddOffset<void>(planes[0], info.fYWidthBytes * info.fYSize.height()); + planes[2] = SkTAddOffset<void>(planes[1], info.fUWidthBytes * info.fUSize.height()); // Test getYUV8Planes() REPORTER_ASSERT(reporter, SkCodec::kInvalidInput == |