From bd3d8d39b3e73398ab37e4a58bd9de6dd462008c Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Tue, 2 Jul 2019 09:16:28 -0400 Subject: [PATCH] Remove GrPixelConfig from GrColorSpaceInfo. Replace GrColorInfo with GrColorSpaceInfo. Change-Id: I7abe28203dd7f22162d68c4eee41293f483bb1aa Reviewed-on: https://skia-review.googlesource.com/c/skia/+/225036 Commit-Queue: Brian Salomon Reviewed-by: Robert Phillips --- include/private/GrTypesPriv.h | 143 ++++++++++++++++++++++ src/atlastext/SkAtlasTextTarget.cpp | 4 +- src/effects/SkTableColorFilter.cpp | 2 +- src/gpu/GrBitmapTextureMaker.cpp | 2 +- src/gpu/GrColorSpaceInfo.cpp | 9 +- src/gpu/GrColorSpaceInfo.h | 15 +-- src/gpu/GrDataUtils.h | 35 +----- src/gpu/GrImageTextureMaker.cpp | 3 +- src/gpu/GrRenderTargetContext.cpp | 7 +- src/gpu/GrSurfaceContext.cpp | 5 +- src/gpu/GrSurfaceContext.h | 6 +- src/gpu/GrTestUtils.cpp | 3 +- src/gpu/GrTextureAdjuster.cpp | 6 +- src/gpu/GrTextureContext.cpp | 6 +- src/gpu/GrTextureProducer.h | 2 +- src/gpu/SkGpuDevice.cpp | 23 ++-- src/gpu/SkGr.cpp | 61 ++++----- src/gpu/gradients/GrGradientShader.cpp | 2 +- src/gpu/vk/GrVkSecondaryCBDrawContext.cpp | 21 ++-- src/image/SkSurface_Gpu.cpp | 27 ++-- src/shaders/SkPictureShader.cpp | 6 +- tests/TessellatingPathRendererTests.cpp | 3 +- 22 files changed, 236 insertions(+), 155 deletions(-) diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h index 6a0902f05f..01ed7e3948 100644 --- a/include/private/GrTypesPriv.h +++ b/include/private/GrTypesPriv.h @@ -1253,6 +1253,149 @@ static constexpr uint32_t GrColorTypeComponentFlags(GrColorType ct) { SkUNREACHABLE; } +/** + * Describes the encoding of channel data in a GrColorType. + */ +enum class GrColorTypeEncoding { + kUnorm, + // kSRGBUnorm, + // kSnorm, + kFloat, + // kSint + // kUint +}; + +/** + * Describes a GrColorType by how many bits are used for each color component and how they are + * encoded. Currently all the non-zero channels share a single GrColorTypeEncoding. This could be + * expanded to store separate encodings and to indicate which bits belong to which components. + */ +struct GrColorTypeDesc { +public: + static constexpr GrColorTypeDesc MakeRGBA(int rgba, GrColorTypeEncoding e) { + return {rgba, rgba, rgba, rgba, 0, e}; + } + + static constexpr GrColorTypeDesc MakeRGBA(int rgb, int a, GrColorTypeEncoding e) { + return {rgb, rgb, rgb, a, 0, e}; + } + + static constexpr GrColorTypeDesc MakeRGB(int rgb, GrColorTypeEncoding e) { + return {rgb, rgb, rgb, 0, 0, e}; + } + + static constexpr GrColorTypeDesc MakeRGB(int r, int g, int b, GrColorTypeEncoding e) { + return {r, g, b, 0, 0, e}; + } + + static constexpr GrColorTypeDesc MakeAlpha(int a, GrColorTypeEncoding e) { + return {0, 0, 0, a, 0, e}; + } + + static constexpr GrColorTypeDesc MakeR(int r, GrColorTypeEncoding e) { + return {r, 0, 0, 0, 0, e}; + } + + static constexpr GrColorTypeDesc MakeRG(int rg, GrColorTypeEncoding e) { + return {rg, rg, 0, 0, 0, e}; + } + + static constexpr GrColorTypeDesc MakeGray(int grayBits, GrColorTypeEncoding e) { + return {0, 0, 0, 0, grayBits, e}; + } + + static constexpr GrColorTypeDesc MakeInvalid() { return {}; } + + constexpr int r() const { return fRBits; } + constexpr int g() const { return fGBits; } + constexpr int b() const { return fBBits; } + constexpr int a() const { return fABits; } + + constexpr int gray() const { return fGrayBits; } + + constexpr GrColorTypeEncoding encoding() const { return fEncoding; } + +private: + int fRBits = 0; + int fGBits = 0; + int fBBits = 0; + int fABits = 0; + int fGrayBits = 0; + GrColorTypeEncoding fEncoding = GrColorTypeEncoding::kUnorm; + + constexpr GrColorTypeDesc() = default; + + constexpr GrColorTypeDesc(int r, int g, int b, int a, int gray, GrColorTypeEncoding encoding) + : fRBits(r), fGBits(g), fBBits(b), fABits(a), fGrayBits(gray), fEncoding(encoding) { + SkASSERT(r >= 0 && g >= 0 && b >= 0 && a >= 0 && gray >= 0); + SkASSERT(!gray || (!r && !g && !b)); + SkASSERT(r || g || b || a || gray); + } +}; + +static constexpr GrColorTypeDesc GrGetColorTypeDesc(GrColorType ct) { + switch (ct) { + case GrColorType::kUnknown: + return GrColorTypeDesc::MakeInvalid(); + case GrColorType::kAlpha_8: + return GrColorTypeDesc::MakeAlpha(8, GrColorTypeEncoding::kUnorm); + case GrColorType::kBGR_565: + return GrColorTypeDesc::MakeRGB(5, 6, 5, GrColorTypeEncoding::kUnorm); + case GrColorType::kABGR_4444: + return GrColorTypeDesc::MakeRGBA(4, GrColorTypeEncoding::kUnorm); + case GrColorType::kRGBA_8888: + return GrColorTypeDesc::MakeRGBA(8, GrColorTypeEncoding::kUnorm); + case GrColorType::kRGB_888x: + return GrColorTypeDesc::MakeRGB(8, GrColorTypeEncoding::kUnorm); + case GrColorType::kRG_88: + return GrColorTypeDesc::MakeRG(8, GrColorTypeEncoding::kUnorm); + case GrColorType::kBGRA_8888: + return GrColorTypeDesc::MakeRGBA(8, GrColorTypeEncoding::kUnorm); + case GrColorType::kRGBA_1010102: + return GrColorTypeDesc::MakeRGBA(10, 2, GrColorTypeEncoding::kUnorm); + case GrColorType::kGray_8: + return GrColorTypeDesc::MakeGray(8, GrColorTypeEncoding::kUnorm); + case GrColorType::kAlpha_F16: + return GrColorTypeDesc::MakeAlpha(16, GrColorTypeEncoding::kFloat); + case GrColorType::kRGBA_F16: + return GrColorTypeDesc::MakeRGBA(16, GrColorTypeEncoding::kFloat); + case GrColorType::kRGBA_F16_Clamped: + return GrColorTypeDesc::MakeRGBA(16, GrColorTypeEncoding::kFloat); + case GrColorType::kRG_F32: + return GrColorTypeDesc::MakeRG(32, GrColorTypeEncoding::kFloat); + case GrColorType::kRGBA_F32: + return GrColorTypeDesc::MakeRGBA(32, GrColorTypeEncoding::kFloat); + case GrColorType::kR_16: + return GrColorTypeDesc::MakeR(16, GrColorTypeEncoding::kUnorm); + case GrColorType::kRG_1616: + return GrColorTypeDesc::MakeRG(16, GrColorTypeEncoding::kUnorm); + case GrColorType::kRGBA_16161616: + return GrColorTypeDesc::MakeRGBA(16, GrColorTypeEncoding::kUnorm); + case GrColorType::kRG_F16: + return GrColorTypeDesc::MakeRG(16, GrColorTypeEncoding::kFloat); + } + SkUNREACHABLE; +} + +static constexpr GrClampType GrColorTypeClampType(GrColorType colorType) { + if (GrGetColorTypeDesc(colorType).encoding() == GrColorTypeEncoding::kUnorm) { + return GrClampType::kAuto; + } + return GrColorType::kRGBA_F16_Clamped == colorType ? GrClampType::kManual : GrClampType::kNone; +} + +// Consider a color type "wider" than n if it has more than n bits for any its representable +// channels. +static constexpr bool GrColorTypeIsWiderThan(GrColorType colorType, int n) { + SkASSERT(n > 0); + auto desc = GrGetColorTypeDesc(colorType); + return (desc.r() && desc.r() > n )|| + (desc.g() && desc.g() > n) || + (desc.b() && desc.b() > n) || + (desc.a() && desc.a() > n) || + (desc.gray() && desc.gray() > n); +} + static constexpr bool GrColorTypeIsAlphaOnly(GrColorType ct) { return kAlpha_SkColorTypeComponentFlag == GrColorTypeComponentFlags(ct); } diff --git a/src/atlastext/SkAtlasTextTarget.cpp b/src/atlastext/SkAtlasTextTarget.cpp index 468a44f1bc..1adae89b53 100644 --- a/src/atlastext/SkAtlasTextTarget.cpp +++ b/src/atlastext/SkAtlasTextTarget.cpp @@ -73,8 +73,8 @@ void SkAtlasTextTarget::concat(const SkMatrix& matrix) { this->accessCTM()->preC ////////////////////////////////////////////////////////////////////////////// -static const GrColorSpaceInfo kColorSpaceInfo(GrColorType::kRGBA_8888, kPremul_SkAlphaType, nullptr, - kRGBA_8888_GrPixelConfig); +static const GrColorSpaceInfo kColorSpaceInfo(GrColorType::kRGBA_8888, kPremul_SkAlphaType, + nullptr); static const SkSurfaceProps kProps( SkSurfaceProps::kUseDistanceFieldFonts_Flag, kUnknown_SkPixelGeometry); diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index 6fdbcf1c31..304babd2dc 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -400,7 +400,7 @@ std::unique_ptr ColorTableEffect::TestCreate(GrProcessorTes sk_sp colorSpace = GrTest::TestColorSpace(d->fRandom); auto fp = filter->asFragmentProcessor( d->context(), GrColorSpaceInfo(GrColorType::kRGBA_8888, kUnknown_SkAlphaType, - std::move(colorSpace), kRGBA_8888_GrPixelConfig)); + std::move(colorSpace))); SkASSERT(fp); return fp; } diff --git a/src/gpu/GrBitmapTextureMaker.cpp b/src/gpu/GrBitmapTextureMaker.cpp index b114b7cf6f..016b907b82 100644 --- a/src/gpu/GrBitmapTextureMaker.cpp +++ b/src/gpu/GrBitmapTextureMaker.cpp @@ -19,7 +19,7 @@ static GrColorSpaceInfo make_info(const SkBitmap& bm) { return GrColorSpaceInfo(SkColorTypeToGrColorType(bm.colorType()), bm.alphaType(), - bm.refColorSpace(), SkImageInfo2GrPixelConfig(bm.info())); + bm.refColorSpace()); } GrBitmapTextureMaker::GrBitmapTextureMaker(GrRecordingContext* context, const SkBitmap& bitmap, diff --git a/src/gpu/GrColorSpaceInfo.cpp b/src/gpu/GrColorSpaceInfo.cpp index a560ffd2be..179e754725 100644 --- a/src/gpu/GrColorSpaceInfo.cpp +++ b/src/gpu/GrColorSpaceInfo.cpp @@ -10,13 +10,8 @@ GrColorSpaceInfo::GrColorSpaceInfo(GrColorType colorType, SkAlphaType alphaType, - sk_sp colorSpace, - GrPixelConfig config) - : fColorSpace(std::move(colorSpace)) - , fColorType(colorType) - , fAlphaType(alphaType) - , fConfig(config) - , fInitializedColorSpaceXformFromSRGB(false) {} + sk_sp colorSpace) + : fColorSpace(std::move(colorSpace)), fColorType(colorType), fAlphaType(alphaType) {} GrColorSpaceXform* GrColorSpaceInfo::colorSpaceXformFromSRGB() const { // TODO: Make this atomic if we start accessing this on multiple threads. diff --git a/src/gpu/GrColorSpaceInfo.h b/src/gpu/GrColorSpaceInfo.h index 039d1084d0..672430a099 100644 --- a/src/gpu/GrColorSpaceInfo.h +++ b/src/gpu/GrColorSpaceInfo.h @@ -16,7 +16,8 @@ /** Describes the color space properties of a surface context. */ class GrColorSpaceInfo { public: - GrColorSpaceInfo(GrColorType, SkAlphaType, sk_sp, GrPixelConfig); + GrColorSpaceInfo() = default; + GrColorSpaceInfo(GrColorType, SkAlphaType, sk_sp); bool isLinearlyBlended() const { return fColorSpace && fColorSpace->gammaIsLinear(); } @@ -31,16 +32,16 @@ public: GrColorType colorType() const { return fColorType; } SkAlphaType alphaType() const { return fAlphaType; } - // TODO: Remove. - GrPixelConfig config() const { return fConfig; } + bool isValid() const { + return fColorType != GrColorType::kUnknown && fAlphaType != kUnknown_SkAlphaType; + } private: sk_sp fColorSpace; mutable sk_sp fColorXformFromSRGB; - GrColorType fColorType; - SkAlphaType fAlphaType; - GrPixelConfig fConfig; - mutable bool fInitializedColorSpaceXformFromSRGB; + GrColorType fColorType = GrColorType::kUnknown; + SkAlphaType fAlphaType = kUnknown_SkAlphaType; + mutable bool fInitializedColorSpaceXformFromSRGB = false; }; #endif diff --git a/src/gpu/GrDataUtils.h b/src/gpu/GrDataUtils.h index 2b8b6914de..a1f4eeb7e7 100644 --- a/src/gpu/GrDataUtils.h +++ b/src/gpu/GrDataUtils.h @@ -10,6 +10,7 @@ #include "include/core/SkColor.h" #include "include/private/GrTypesPriv.h" +#include "src/gpu/GrColorSpaceInfo.h" #include "src/gpu/GrSwizzle.h" size_t GrCompressedDataSize(SkImage::CompressionType, int w, int h); @@ -25,38 +26,6 @@ void GrFillInData(GrPixelConfig, int baseWidth, int baseHeight, void GrFillInCompressedData(SkImage::CompressionType, int width, int height, char* dest, const SkColor4f& color); - -// TODO: Replace with GrColorSpaceInfo once GrPixelConfig is excised from that type. -class GrColorInfo { -public: - GrColorInfo() = default; - - GrColorInfo(GrColorType ct, SkAlphaType at, sk_sp cs) - : fColorSpace(std::move(cs)), fColorType(ct), fAlphaType(at) {} - - GrColorInfo(const GrColorInfo&) = default; - GrColorInfo(GrColorInfo&&) = default; - GrColorInfo& operator=(const GrColorInfo&) = default; - GrColorInfo& operator=(GrColorInfo&&) = default; - - GrColorType colorType() const { return fColorType; } - - SkAlphaType alphaType() const { return fAlphaType; } - - SkColorSpace* colorSpace() const { return fColorSpace.get(); } - - sk_sp refColorSpace() const { return fColorSpace; } - - bool isValid() const { - return fColorType != GrColorType::kUnknown && fAlphaType != kUnknown_SkAlphaType; - } - -private: - sk_sp fColorSpace; - GrColorType fColorType = GrColorType::kUnknown; - SkAlphaType fAlphaType = kUnknown_SkAlphaType; -}; - class GrPixelInfo { public: GrPixelInfo() = default; @@ -126,7 +95,7 @@ public: bool isValid() const { return fColorInfo.isValid() && fWidth > 0 && fHeight > 0; } private: - GrColorInfo fColorInfo = {}; + GrColorSpaceInfo fColorInfo = {}; int fWidth = 0; int fHeight = 0; }; diff --git a/src/gpu/GrImageTextureMaker.cpp b/src/gpu/GrImageTextureMaker.cpp index 0752e487bc..9378b9cc7c 100644 --- a/src/gpu/GrImageTextureMaker.cpp +++ b/src/gpu/GrImageTextureMaker.cpp @@ -16,8 +16,7 @@ static GrColorSpaceInfo make_info(const SkImage*& image) { return GrColorSpaceInfo(SkColorTypeToGrColorType(image->colorType()), image->alphaType(), - image->refColorSpace(), - SkImageInfo2GrPixelConfig(image->imageInfo())); + image->refColorSpace()); } GrImageTextureMaker::GrImageTextureMaker(GrRecordingContext* context, const SkImage* client, diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index fb9bd38b7f..cf5b6f958f 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -147,8 +147,7 @@ GrRenderTargetContext::GrRenderTargetContext(GrRecordingContext* context, sk_sp colorSpace, const SkSurfaceProps* surfaceProps, bool managedOpList) - : GrSurfaceContext(context, colorType, kPremul_SkAlphaType, std::move(colorSpace), - rtp->config()) + : GrSurfaceContext(context, colorType, kPremul_SkAlphaType, std::move(colorSpace)) , fRenderTargetProxy(std::move(rtp)) , fOpList(sk_ref_sp(fRenderTargetProxy->getLastRenderTargetOpList())) , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) @@ -833,7 +832,7 @@ void GrRenderTargetContext::setNeedsStencil(bool multisampled) { // mixed samples. SkASSERT(fRenderTargetProxy->canUseMixedSamples(*this->caps())); numRequiredSamples = this->caps()->internalMultisampleCount( - this->colorSpaceInfo().config()); + this->asSurfaceProxy()->config()); } SkASSERT(numRequiredSamples > 0); @@ -2615,7 +2614,7 @@ void GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptr 0)); - GrClampType clampType = GrPixelConfigClampType(this->colorSpaceInfo().config()); + GrClampType clampType = GrColorTypeClampType(this->colorSpaceInfo().colorType()); // MIXED SAMPLES TODO: If we start using mixed samples for clips we will need to check the clip // here as well. bool hasMixedSampledCoverage = (usesHWAA && this->numSamples() <= 1); diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp index 82498dde84..395772b099 100644 --- a/src/gpu/GrSurfaceContext.cpp +++ b/src/gpu/GrSurfaceContext.cpp @@ -34,9 +34,8 @@ GrSurfaceContext::GrSurfaceContext(GrRecordingContext* context, GrColorType colorType, SkAlphaType alphaType, - sk_sp colorSpace, - GrPixelConfig config) - : fContext(context), fColorSpaceInfo(colorType, alphaType, std::move(colorSpace), config) {} + sk_sp colorSpace) + : fContext(context), fColorSpaceInfo(colorType, alphaType, std::move(colorSpace)) {} GrAuditTrail* GrSurfaceContext::auditTrail() { return fContext->priv().auditTrail(); diff --git a/src/gpu/GrSurfaceContext.h b/src/gpu/GrSurfaceContext.h index 5bac870165..8ef1450da1 100644 --- a/src/gpu/GrSurfaceContext.h +++ b/src/gpu/GrSurfaceContext.h @@ -99,11 +99,7 @@ public: protected: friend class GrSurfaceContextPriv; - GrSurfaceContext(GrRecordingContext*, - GrColorType, - SkAlphaType, - sk_sp, - GrPixelConfig); + GrSurfaceContext(GrRecordingContext*, GrColorType, SkAlphaType, sk_sp); GrDrawingManager* drawingManager(); const GrDrawingManager* drawingManager() const; diff --git a/src/gpu/GrTestUtils.cpp b/src/gpu/GrTestUtils.cpp index 0c15e6b839..c6e95a3f50 100644 --- a/src/gpu/GrTestUtils.cpp +++ b/src/gpu/GrTestUtils.cpp @@ -339,8 +339,7 @@ sk_sp TestColorXform(SkRandom* random) { TestAsFPArgs::TestAsFPArgs(GrProcessorTestData* d) : fViewMatrixStorage(TestMatrix(d->fRandom)) , fColorSpaceInfoStorage(skstd::make_unique( - GrColorType::kRGBA_8888, kPremul_SkAlphaType, TestColorSpace(d->fRandom), - kRGBA_8888_GrPixelConfig)) + GrColorType::kRGBA_8888, kPremul_SkAlphaType, TestColorSpace(d->fRandom))) , fArgs(d->context(), &fViewMatrixStorage, kNone_SkFilterQuality, fColorSpaceInfoStorage.get()) {} diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp index c299fed9f9..05f839690b 100644 --- a/src/gpu/GrTextureAdjuster.cpp +++ b/src/gpu/GrTextureAdjuster.cpp @@ -21,11 +21,7 @@ GrTextureAdjuster::GrTextureAdjuster(GrRecordingContext* context, SkColorSpace* cs, bool useDecal) : INHERITED(context, original->width(), original->height(), - GrColorSpaceInfo(colorType, - alphaType, - sk_ref_sp(cs), - original->config()), - useDecal) + GrColorSpaceInfo(colorType, alphaType, sk_ref_sp(cs)), useDecal) , fOriginal(std::move(original)) , fUniqueID(uniqueID) {} diff --git a/src/gpu/GrTextureContext.cpp b/src/gpu/GrTextureContext.cpp index c9e5fa5c94..1ba12438b9 100644 --- a/src/gpu/GrTextureContext.cpp +++ b/src/gpu/GrTextureContext.cpp @@ -21,11 +21,7 @@ GrTextureContext::GrTextureContext(GrRecordingContext* context, GrColorType colorType, SkAlphaType alphaType, sk_sp colorSpace) - : GrSurfaceContext(context, - colorType, - alphaType, - std::move(colorSpace), - textureProxy->config()) + : GrSurfaceContext(context, colorType, alphaType, std::move(colorSpace)) , fTextureProxy(std::move(textureProxy)) , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) { SkDEBUGCODE(this->validate();) diff --git a/src/gpu/GrTextureProducer.h b/src/gpu/GrTextureProducer.h index d73ed2543c..806ddad4f9 100644 --- a/src/gpu/GrTextureProducer.h +++ b/src/gpu/GrTextureProducer.h @@ -107,7 +107,7 @@ public: GrColorType colorType() const { return fColorSpaceInfo.colorType(); } SkAlphaType alphaType() const { return fColorSpaceInfo.alphaType(); } SkColorSpace* colorSpace() const { return fColorSpaceInfo.colorSpace(); } - bool isAlphaOnly() const { return GrPixelConfigIsAlphaOnly(fColorSpaceInfo.config()); } + bool isAlphaOnly() const { return GrColorTypeIsAlphaOnly(fColorSpaceInfo.colorType()); } bool domainNeedsDecal() const { return fDomainNeedsDecal; } // If the "texture" samples multiple images that have different resolutions (e.g. YUV420) virtual bool hasMixedResolutions() const { return false; } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index e9e3d7a57b..39b0ca9e38 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -116,10 +116,7 @@ sk_sp SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, } static SkImageInfo make_info(GrRenderTargetContext* context, int w, int h, bool opaque) { - SkColorType colorType; - if (!GrPixelConfigToColorType(context->colorSpaceInfo().config(), &colorType)) { - colorType = kUnknown_SkColorType; - } + SkColorType colorType = GrColorTypeToSkColorType(context->colorSpaceInfo().colorType()); return SkImageInfo::Make(w, h, colorType, opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType, context->colorSpaceInfo().refColorSpace()); } @@ -183,9 +180,10 @@ sk_sp SkGpuDevice::filterTexture(SkSpecialImage* srcImg, matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); const SkIRect clipBounds = this->devClipBounds().makeOffset(-left, -top); sk_sp cache(this->getImageFilterCache()); - SkColorType colorType; - if (!GrPixelConfigToColorType(fRenderTargetContext->colorSpaceInfo().config(), &colorType)) { - colorType = kN32_SkColorType; + SkColorType colorType = + GrColorTypeToSkColorType(fRenderTargetContext->colorSpaceInfo().colorType()); + if (colorType == kUnknown_SkColorType) { + colorType = kRGBA_8888_SkColorType; } SkImageFilter::OutputProperties outputProperties( colorType, fRenderTargetContext->colorSpaceInfo().colorSpace()); @@ -1666,20 +1664,21 @@ SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint SkBackingFit fit = kNever_TileUsage == cinfo.fTileUsage ? SkBackingFit::kApprox : SkBackingFit::kExact; - GrPixelConfig config = fRenderTargetContext->colorSpaceInfo().config(); + GrColorType colorType = fRenderTargetContext->colorSpaceInfo().colorType(); const GrBackendFormat& origFormat = fRenderTargetContext->asSurfaceProxy()->backendFormat(); GrBackendFormat format = origFormat.makeTexture2D(); if (!format.isValid()) { return nullptr; } - if (kRGBA_1010102_GrPixelConfig == config) { + if (colorType == GrColorType::kRGBA_1010102) { // If the original device is 1010102, fall back to 8888 so that we have a usable alpha // channel in the layer. - config = kRGBA_8888_GrPixelConfig; - format = - fContext->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); + colorType = GrColorType::kRGBA_8888; + format = fContext->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); } + auto config = fContext->priv().caps()->getConfigFromBackendFormat( + format, GrColorTypeToSkColorType(colorType)); sk_sp rtc(fContext->priv().makeDeferredRenderTargetContext( format, fit, diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index fcc12ba3fe..0709ca30b5 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -285,43 +285,34 @@ static inline bool blend_requires_shader(const SkBlendMode mode) { } #ifndef SK_IGNORE_GPU_DITHER -static inline int32_t dither_range_type_for_config(GrPixelConfig dstConfig) { - switch (dstConfig) { - case kGray_8_GrPixelConfig: - case kGray_8_as_Lum_GrPixelConfig: - case kGray_8_as_Red_GrPixelConfig: - case kRGBA_8888_GrPixelConfig: - case kRGB_888_GrPixelConfig: - case kRGB_888X_GrPixelConfig: - case kRG_88_GrPixelConfig: - case kBGRA_8888_GrPixelConfig: - case kR_16_GrPixelConfig: - case kRG_1616_GrPixelConfig: +static inline int32_t dither_range_type_for_config(GrColorType dstColorType) { + switch (dstColorType) { + case GrColorType::kGray_8: + case GrColorType::kRGBA_8888: + case GrColorType::kRGB_888x: + case GrColorType::kRG_88: + case GrColorType::kBGRA_8888: + case GrColorType::kR_16: + case GrColorType::kRG_1616: // Experimental (for Y416 and mutant P016/P010) - case kRGBA_16161616_GrPixelConfig: - case kRG_half_GrPixelConfig: + case GrColorType::kRGBA_16161616: + case GrColorType::kRG_F16: return 0; - case kRGB_565_GrPixelConfig: + case GrColorType::kBGR_565: return 1; - case kRGBA_4444_GrPixelConfig: + case GrColorType::kABGR_4444: return 2; - case kUnknown_GrPixelConfig: - case kSRGBA_8888_GrPixelConfig: - case kRGBA_1010102_GrPixelConfig: - case kAlpha_half_GrPixelConfig: - case kAlpha_half_as_Red_GrPixelConfig: - case kRGBA_float_GrPixelConfig: - case kRG_float_GrPixelConfig: - case kRGBA_half_GrPixelConfig: - case kRGBA_half_Clamped_GrPixelConfig: - case kRGB_ETC1_GrPixelConfig: - case kAlpha_8_GrPixelConfig: - case kAlpha_8_as_Alpha_GrPixelConfig: - case kAlpha_8_as_Red_GrPixelConfig: + case GrColorType::kUnknown: + case GrColorType::kRGBA_1010102: + case GrColorType::kAlpha_F16: + case GrColorType::kRGBA_F32: + case GrColorType::kRG_F32: + case GrColorType::kRGBA_F16: + case GrColorType::kRGBA_F16_Clamped: + case GrColorType::kAlpha_8: return -1; } - SkASSERT(false); - return 0; + SkUNREACHABLE; } #endif @@ -454,10 +445,10 @@ static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context, #ifndef SK_IGNORE_GPU_DITHER // Conservative default, in case GrPixelConfigToColorType() fails. - SkColorType ct = SkColorType::kRGB_565_SkColorType; - GrPixelConfigToColorType(colorSpaceInfo.config(), &ct); - if (SkPaintPriv::ShouldDither(skPaint, ct) && grPaint->numColorFragmentProcessors() > 0) { - int32_t ditherRange = dither_range_type_for_config(colorSpaceInfo.config()); + GrColorType ct = colorSpaceInfo.colorType(); + if (SkPaintPriv::ShouldDither(skPaint, GrColorTypeToSkColorType(ct)) && + grPaint->numColorFragmentProcessors() > 0) { + int32_t ditherRange = dither_range_type_for_config(ct); if (ditherRange >= 0) { static int ditherIndex = GrSkSLFP::NewIndex(); auto ditherFP = GrSkSLFP::Make(context, ditherIndex, "Dither", SKSL_DITHER_SRC, diff --git a/src/gpu/gradients/GrGradientShader.cpp b/src/gpu/gradients/GrGradientShader.cpp index 9571a8f8f8..03649c84af 100644 --- a/src/gpu/gradients/GrGradientShader.cpp +++ b/src/gpu/gradients/GrGradientShader.cpp @@ -45,7 +45,7 @@ static std::unique_ptr make_textured_colorizer(const SkPMCo // Use 8888 or F16, depending on the destination config. // TODO: Use 1010102 for opaque gradients, at least if destination is 1010102? SkColorType colorType = kRGBA_8888_SkColorType; - if (kLow_GrSLPrecision != GrSLSamplerPrecision(args.fDstColorSpaceInfo->config()) && + if (GrColorTypeIsWiderThan(args.fDstColorSpaceInfo->colorType(), 8) && args.fContext->priv().caps()->isConfigTexturable(kRGBA_half_GrPixelConfig)) { colorType = kRGBA_F16_SkColorType; } diff --git a/src/gpu/vk/GrVkSecondaryCBDrawContext.cpp b/src/gpu/vk/GrVkSecondaryCBDrawContext.cpp index c52684815a..3772292b28 100644 --- a/src/gpu/vk/GrVkSecondaryCBDrawContext.cpp +++ b/src/gpu/vk/GrVkSecondaryCBDrawContext.cpp @@ -88,18 +88,17 @@ bool GrVkSecondaryCBDrawContext::characterize(SkSurfaceCharacterization* charact // We current don't support textured GrVkSecondaryCBDrawContexts. SkASSERT(!rtc->asTextureProxy()); - // TODO: the addition of colorType to the surfaceContext should remove this calculation - SkColorType ct; - if (!GrPixelConfigToColorType(rtc->colorSpaceInfo().config(), &ct)) { + SkColorType ct = GrColorTypeToSkColorType(rtc->colorSpaceInfo().colorType()); + if (ct == kUnknown_SkColorType) { return false; } SkImageInfo ii = SkImageInfo::Make(rtc->width(), rtc->height(), ct, kPremul_SkAlphaType, rtc->colorSpaceInfo().refColorSpace()); - characterization->set(ctx->threadSafeProxy(), maxResourceBytes, ii, rtc->origin(), - rtc->colorSpaceInfo().config(), rtc->numSamples(), - SkSurfaceCharacterization::Textureable(false), + GrPixelConfig config = rtc->asSurfaceProxy()->config(); + characterization->set(ctx->threadSafeProxy(), maxResourceBytes, ii, rtc->origin(), config, + rtc->numSamples(), SkSurfaceCharacterization::Textureable(false), SkSurfaceCharacterization::MipMapped(false), SkSurfaceCharacterization::UsesGLFBO0(false), SkSurfaceCharacterization::VulkanSecondaryCBCompatible(true), @@ -137,19 +136,19 @@ bool GrVkSecondaryCBDrawContext::isCompatible( return false; } - // TODO: the addition of colorType to the surfaceContext should remove this calculation - SkColorType rtcColorType; - if (!GrPixelConfigToColorType(rtc->colorSpaceInfo().config(), &rtcColorType)) { + SkColorType rtColorType = GrColorTypeToSkColorType(rtc->colorSpaceInfo().colorType()); + if (rtColorType == kUnknown_SkColorType) { return false; } + GrPixelConfig config = rtc->asSurfaceProxy()->config(); return characterization.contextInfo() && characterization.contextInfo()->priv().matches(ctx) && characterization.cacheMaxResourceBytes() <= maxResourceBytes && characterization.origin() == rtc->origin() && - characterization.config() == rtc->colorSpaceInfo().config() && + characterization.config() == config && characterization.width() == rtc->width() && characterization.height() == rtc->height() && - characterization.colorType() == rtcColorType && + characterization.colorType() == rtColorType && characterization.sampleCount() == rtc->numSamples() && SkColorSpace::Equals(characterization.colorSpace(), rtc->colorSpaceInfo().colorSpace()) && diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index 5a6e388db4..19b08e8034 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -195,9 +195,8 @@ bool SkSurface_Gpu::onCharacterize(SkSurfaceCharacterization* characterization) bool mipmapped = rtc->asTextureProxy() ? GrMipMapped::kYes == rtc->asTextureProxy()->mipMapped() : false; - // TODO: the addition of colorType to the surfaceContext should remove this calculation - SkColorType ct; - if (!GrPixelConfigToColorType(rtc->colorSpaceInfo().config(), &ct)) { + SkColorType ct = GrColorTypeToSkColorType(rtc->colorSpaceInfo().colorType()); + if (ct == kUnknown_SkColorType) { return false; } @@ -209,13 +208,13 @@ bool SkSurface_Gpu::onCharacterize(SkSurfaceCharacterization* characterization) SkImageInfo ii = SkImageInfo::Make(rtc->width(), rtc->height(), ct, kPremul_SkAlphaType, rtc->colorSpaceInfo().refColorSpace()); - characterization->set(ctx->threadSafeProxy(), maxResourceBytes, ii, rtc->origin(), - rtc->colorSpaceInfo().config(), rtc->numSamples(), - SkSurfaceCharacterization::Textureable(SkToBool(rtc->asTextureProxy())), - SkSurfaceCharacterization::MipMapped(mipmapped), - SkSurfaceCharacterization::UsesGLFBO0(usesGLFBO0), - SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false), - this->props()); + GrPixelConfig config = rtc->asSurfaceProxy()->config(); + characterization->set( + ctx->threadSafeProxy(), maxResourceBytes, ii, rtc->origin(), config, rtc->numSamples(), + SkSurfaceCharacterization::Textureable(SkToBool(rtc->asTextureProxy())), + SkSurfaceCharacterization::MipMapped(mipmapped), + SkSurfaceCharacterization::UsesGLFBO0(usesGLFBO0), + SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false), this->props()); return true; } @@ -295,16 +294,16 @@ bool SkSurface_Gpu::onIsCompatible(const SkSurfaceCharacterization& characteriza return false; } - // TODO: the addition of colorType to the surfaceContext should remove this calculation - SkColorType rtcColorType; - if (!GrPixelConfigToColorType(rtc->colorSpaceInfo().config(), &rtcColorType)) { + SkColorType rtcColorType = GrColorTypeToSkColorType(rtc->colorSpaceInfo().colorType()); + if (rtcColorType == kUnknown_SkColorType) { return false; } + GrPixelConfig config = rtc->asSurfaceProxy()->config(); return characterization.contextInfo() && characterization.contextInfo()->priv().matches(ctx) && characterization.cacheMaxResourceBytes() <= maxResourceBytes && characterization.origin() == rtc->origin() && - characterization.config() == rtc->colorSpaceInfo().config() && + characterization.config() == config && characterization.width() == rtc->width() && characterization.height() == rtc->height() && characterization.colorType() == rtcColorType && diff --git a/src/shaders/SkPictureShader.cpp b/src/shaders/SkPictureShader.cpp index 16ae398e2b..568c5ffbf4 100644 --- a/src/shaders/SkPictureShader.cpp +++ b/src/shaders/SkPictureShader.cpp @@ -345,8 +345,10 @@ std::unique_ptr SkPictureShader::asFragmentProcessor( } auto lm = this->totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix); - SkColorType dstColorType = kN32_SkColorType; - GrPixelConfigToColorType(args.fDstColorSpaceInfo->config(), &dstColorType); + SkColorType dstColorType = GrColorTypeToSkColorType(args.fDstColorSpaceInfo->colorType()); + if (dstColorType == kUnknown_SkColorType) { + dstColorType = kRGBA_8888_SkColorType; + } sk_sp bitmapShader(this->refBitmapShader(*args.fViewMatrix, &lm, dstColorType, args.fDstColorSpaceInfo->colorSpace(), maxTextureSize)); diff --git a/tests/TessellatingPathRendererTests.cpp b/tests/TessellatingPathRendererTests.cpp index c7fe8151f4..9e6ef212c1 100644 --- a/tests/TessellatingPathRendererTests.cpp +++ b/tests/TessellatingPathRendererTests.cpp @@ -693,8 +693,7 @@ static std::unique_ptr create_linear_gradient_processor(GrC SkColor colors[2] = { SK_ColorGREEN, SK_ColorBLUE }; sk_sp shader = SkGradientShader::MakeLinear( pts, colors, nullptr, SK_ARRAY_COUNT(colors), SkTileMode::kClamp); - GrColorSpaceInfo colorSpaceInfo(GrColorType::kRGBA_8888, kPremul_SkAlphaType, nullptr, - kRGBA_8888_GrPixelConfig); + GrColorSpaceInfo colorSpaceInfo(GrColorType::kRGBA_8888, kPremul_SkAlphaType, nullptr); GrFPArgs args(ctx, &SkMatrix::I(), SkFilterQuality::kLow_SkFilterQuality, &colorSpaceInfo); return as_SB(shader)->asFragmentProcessor(args); }