From e0735529fa3458d7919aee5286ad9a9a47a99ef5 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Fri, 31 Jan 2020 11:03:32 -0500 Subject: [PATCH] Minor GM cleanup This CL: 1) Makes the compressed_textures GM use a red outline to indicate decompression (instead of a color rotation) 2) Disallows GPU resizing of textures w/ alpha in the wacky_yuv_formats GM 3) Guards GrTwoColorBC1Compress with GR_TEST_UTILS to make it clear that it is just a testing utility 4) Fixes the wacky_yuv_formats GM on platforms with RGBA PM color order Change-Id: I3942c4ab1d2c1fab3c8d39c6c99136b75ba10132 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/268119 Reviewed-by: Greg Daniel Commit-Queue: Robert Phillips --- gm/compressed_textures.cpp | 28 ++++++++++------------------ gm/wacky_yuv_formats.cpp | 29 ++++++++++++++++++++--------- src/gpu/GrDataUtils.cpp | 4 ++++ src/gpu/GrDataUtils.h | 2 ++ 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/gm/compressed_textures.cpp b/gm/compressed_textures.cpp index 37eb8956cf..3ae4d746df 100644 --- a/gm/compressed_textures.cpp +++ b/gm/compressed_textures.cpp @@ -31,17 +31,6 @@ class GrContext; class GrRenderTargetContext; -static sk_sp make_color_filter() { - // rotate R, G and B - float colorMatrix[20] = { - 0, 1, 0, 0, 0, - 0, 0, 1, 0, 0, - 1, 0, 0, 0, 0, - 0, 0, 0, 1, 0 - }; - return SkColorFilters::Matrix(colorMatrix); -} - static SkPoint gen_pt(float angle, const SkVector& scale) { SkScalar s = SkScalarSin(angle); SkScalar c = SkScalarCos(angle); @@ -258,8 +247,8 @@ private: int numMipLevels = SkMipMap::ComputeLevelCount(levelDimensions.width(), levelDimensions.height()) + 1; - SkPaint paint; - paint.setFilterQuality(kHigh_SkFilterQuality); // to force mipmapping + SkPaint imagePaint; + imagePaint.setFilterQuality(kHigh_SkFilterQuality); // to force mipmapping bool isCompressed = false; if (image->isTextureBacked()) { @@ -269,16 +258,19 @@ private: isCompressed = caps->isFormatCompressed(proxy->backendFormat()); } - if (!isCompressed) { - // Make it obvious which drawImages used decompressed images - paint.setColorFilter(make_color_filter()); - } + SkPaint redStrokePaint; + redStrokePaint.setColor(SK_ColorRED); + redStrokePaint.setStyle(SkPaint::kStroke_Style); for (int i = 0; i < numMipLevels; ++i) { SkRect r = SkRect::MakeXYWH(offset.fX, offset.fY, levelDimensions.width(), levelDimensions.height()); - canvas->drawImageRect(image, r, &paint); + canvas->drawImageRect(image, r, &imagePaint); + if (!isCompressed) { + // Make it obvious which drawImages used decompressed images + canvas->drawRect(r, redStrokePaint); + } if (i == 0) { offset.fX += levelDimensions.width()+1; diff --git a/gm/wacky_yuv_formats.cpp b/gm/wacky_yuv_formats.cpp index ba527830a5..6b613eee0d 100644 --- a/gm/wacky_yuv_formats.cpp +++ b/gm/wacky_yuv_formats.cpp @@ -425,7 +425,7 @@ static SkPMColor convert_yuva_to_rgba(const float mtx[20], uint8_t g = SkScalarPin(SkScalarRoundToInt(mtx[ 5]*y + mtx[ 6]*u + mtx[ 7]*v + mtx[ 9]*255), 0, 255); uint8_t b = SkScalarPin(SkScalarRoundToInt(mtx[10]*y + mtx[11]*u + mtx[12]*v + mtx[14]*255), 0, 255); - return SkPremultiplyARGBInline(a, b, g, r); + return SkPremultiplyARGBInline(a, r, g, b); } static void extract_planes(const SkBitmap& bm, SkYUVColorSpace yuvColorSpace, PlaneData* planes) { @@ -821,6 +821,7 @@ protected: if (kUnknown_SkColorType == fFlattened.colorType()) { fFlattened.allocPixels(info); + SkASSERT(kN32_SkColorType == info.colorType()); SkASSERT(kPremul_SkAlphaType == info.alphaType()); float mtx[20]; @@ -1155,6 +1156,13 @@ protected: return nullptr; } + if (ct == kRGBA_8888_SkColorType || ct == kRGBA_1010102_SkColorType) { + // We disallow resizing AYUV and Y410 formats on the GPU bc resizing them w/ a + // premul draw combines the YUV channels w/ the A channel in an inappropriate + // manner. + return nullptr; + } + SkISize shrunkPlaneSize = { yuvaTextures[i].width() / 2, yuvaTextures[i].height() / 2 }; sk_sp wrappedOrig = SkImage::MakeFromTexture(context, yuvaTextures[i], @@ -1294,11 +1302,14 @@ protected: ++counter; } } else { - fImages[opaque][cs][format] = make_yuv_gen_image( - fOriginalBMs[opaque].info(), - (SkYUVColorSpace) cs, - yuvaIndices, - resultBMs); + SkImageInfo ii = SkImageInfo::MakeN32(fOriginalBMs[opaque].width(), + fOriginalBMs[opaque].height(), + kPremul_SkAlphaType); + + fImages[opaque][cs][format] = make_yuv_gen_image(ii, + (SkYUVColorSpace) cs, + yuvaIndices, + resultBMs); } } } @@ -1640,9 +1651,9 @@ protected: void onDraw(SkCanvas* canvas) override { SkYUVAIndex indices[4]; - indices[SkYUVAIndex::kY_Index] = {0, SkColorChannel::kR}; - indices[SkYUVAIndex::kU_Index] = {1, SkColorChannel::kR}; - indices[SkYUVAIndex::kV_Index] = {2, SkColorChannel::kR}; + indices[SkYUVAIndex::kY_Index] = {0, SkColorChannel::kR}; + indices[SkYUVAIndex::kU_Index] = {1, SkColorChannel::kR}; + indices[SkYUVAIndex::kV_Index] = {2, SkColorChannel::kR}; indices[SkYUVAIndex::kA_Index] = {-1, SkColorChannel::kR}; canvas->translate(fOrig->width(), 0); diff --git a/src/gpu/GrDataUtils.cpp b/src/gpu/GrDataUtils.cpp index fcd881ca5f..eca5ac86ac 100644 --- a/src/gpu/GrDataUtils.cpp +++ b/src/gpu/GrDataUtils.cpp @@ -209,6 +209,8 @@ static void fillin_BC1_with_color(SkISize dimensions, const SkColor4f& colorf, c } } +#if GR_TEST_UTILS + // Fill in 'dstPixels' with BC1 blocks derived from the 'pixmap'. void GrTwoColorBC1Compress(const SkPixmap& pixmap, SkColor otherColor, char* dstPixels) { BC1Block* dstBlocks = reinterpret_cast(dstPixels); @@ -250,6 +252,8 @@ void GrTwoColorBC1Compress(const SkPixmap& pixmap, SkColor otherColor, char* dst } } +#endif + size_t GrComputeTightCombinedBufferSize(size_t bytesPerPixel, SkISize baseDimensions, SkTArray* individualMipOffsets, int mipLevelCount) { SkASSERT(individualMipOffsets && !individualMipOffsets->count()); diff --git a/src/gpu/GrDataUtils.h b/src/gpu/GrDataUtils.h index e97be45544..98915b6a92 100644 --- a/src/gpu/GrDataUtils.h +++ b/src/gpu/GrDataUtils.h @@ -40,6 +40,7 @@ bool GrConvertPixels(const GrImageInfo& dstInfo, void* dst, size_t dstRB, /** Clears the dst image to a constant color. */ bool GrClearImage(const GrImageInfo& dstInfo, void* dst, size_t dstRB, SkColor4f color); +#if GR_TEST_UTILS /** * BC1 compress an image that contains only either opaque black or transparent black and one * other color. @@ -47,5 +48,6 @@ bool GrClearImage(const GrImageInfo& dstInfo, void* dst, size_t dstRB, SkColor4f * transparent pixmaps -> kBC1_RGBA8_UNORM */ void GrTwoColorBC1Compress(const SkPixmap& pixmap, SkColor otherColor, char* dstPixels); +#endif #endif