diff options
author | brianosman <brianosman@google.com> | 2016-03-17 12:26:37 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-17 12:26:37 -0700 |
commit | 9e3f1bf4e5cd8fc59554f986f36d6b034e99f9eb (patch) | |
tree | 15fc5d36dc3c97fbcb8e634d23f3a87fe48685bc /include/gpu | |
parent | 0e3129d734212089f872f0e7de8f2537861a3f89 (diff) |
sRGB support in Ganesh. Several pieces:
sRGB support now also requires GL_EXT_texture_sRGB_decode, which allows
us to disable sRGB -> Linear conversion when reading textures. This gives
us an easy way to support "legacy" L32 mode. We disable decoding based on
the pixel config of the render target. Textures can override that behavior
(specifically for format-conversion draws where we want that behavior).
Added sBGRA pixel config, which is not-really-a-format. It's just sRGBA
internally, and the external format is BGR order, so TexImage calls will
swizzle correctly. This lets us interact with sRGB raster surfaces on BGR
platforms.
Devices without sRGB support behave like they always have: conversion from
color type and profile type ignores sRGB and always returns linear pixel
configs.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1789663002
Review URL: https://codereview.chromium.org/1789663002
Diffstat (limited to 'include/gpu')
-rw-r--r-- | include/gpu/GrCaps.h | 2 | ||||
-rw-r--r-- | include/gpu/GrColor.h | 17 | ||||
-rw-r--r-- | include/gpu/GrTextureParams.h | 31 | ||||
-rw-r--r-- | include/gpu/GrTypes.h | 23 | ||||
-rw-r--r-- | include/gpu/SkGr.h | 7 |
5 files changed, 68 insertions, 12 deletions
diff --git a/include/gpu/GrCaps.h b/include/gpu/GrCaps.h index 60f213950e..b806dcbabc 100644 --- a/include/gpu/GrCaps.h +++ b/include/gpu/GrCaps.h @@ -137,6 +137,7 @@ public: /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g. only for POT textures) */ bool mipMapSupport() const { return fMipMapSupport; } + bool srgbSupport() const { return fSRGBSupport; } bool twoSidedStencilSupport() const { return fTwoSidedStencilSupport; } bool stencilWrapOpsSupport() const { return fStencilWrapOpsSupport; } bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; } @@ -268,6 +269,7 @@ protected: bool fNPOTTextureTileSupport : 1; bool fMipMapSupport : 1; + bool fSRGBSupport : 1; bool fTwoSidedStencilSupport : 1; bool fStencilWrapOpsSupport : 1; bool fDiscardRenderTargetSupport : 1; diff --git a/include/gpu/GrColor.h b/include/gpu/GrColor.h index 6b83237626..77f1a6cb08 100644 --- a/include/gpu/GrColor.h +++ b/include/gpu/GrColor.h @@ -208,7 +208,6 @@ static inline char GrColorComponentFlagToChar(GrColorComponentFlags component) { } static inline uint32_t GrPixelConfigComponentMask(GrPixelConfig config) { - SkASSERT(config >= 0 && config < kGrPixelConfigCnt); static const uint32_t kFlags[] = { 0, // kUnknown_GrPixelConfig kA_GrColorComponentFlag, // kAlpha_8_GrPixelConfig @@ -218,6 +217,7 @@ static inline uint32_t GrPixelConfigComponentMask(GrPixelConfig config) { kRGBA_GrColorComponentFlags, // kRGBA_8888_GrPixelConfig kRGBA_GrColorComponentFlags, // kBGRA_8888_GrPixelConfig kRGBA_GrColorComponentFlags, // kSRGBA_8888_GrPixelConfig + kRGBA_GrColorComponentFlags, // kSBGRA_8888_GrPixelConfig kRGB_GrColorComponentFlags, // kETC1_GrPixelConfig kA_GrColorComponentFlag, // kLATC_GrPixelConfig kA_GrColorComponentFlag, // kR11_EAC_GrPixelConfig @@ -236,13 +236,14 @@ static inline uint32_t GrPixelConfigComponentMask(GrPixelConfig config) { GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig); - GR_STATIC_ASSERT(8 == kETC1_GrPixelConfig); - GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig); - GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig); - GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig); - GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig); - GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig); - GR_STATIC_ASSERT(14 == kRGBA_half_GrPixelConfig); + GR_STATIC_ASSERT(8 == kSBGRA_8888_GrPixelConfig); + GR_STATIC_ASSERT(9 == kETC1_GrPixelConfig); + GR_STATIC_ASSERT(10 == kLATC_GrPixelConfig); + GR_STATIC_ASSERT(11 == kR11_EAC_GrPixelConfig); + GR_STATIC_ASSERT(12 == kASTC_12x12_GrPixelConfig); + GR_STATIC_ASSERT(13 == kRGBA_float_GrPixelConfig); + GR_STATIC_ASSERT(14 == kAlpha_half_GrPixelConfig); + GR_STATIC_ASSERT(15 == kRGBA_half_GrPixelConfig); GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt); } diff --git a/include/gpu/GrTextureParams.h b/include/gpu/GrTextureParams.h index 3186b1b027..40d9ac5375 100644 --- a/include/gpu/GrTextureParams.h +++ b/include/gpu/GrTextureParams.h @@ -24,6 +24,11 @@ public: static const GrTextureParams gParams(SkShader::kClamp_TileMode, kBilerp_FilterMode); return gParams; } + static const GrTextureParams& ClampNoFilterForceAllowSRGB() { + static const GrTextureParams gParams(SkShader::kClamp_TileMode, kNone_FilterMode, + kForceAllowSRGB_SRGBMode); + return gParams; + } GrTextureParams() { this->reset(); @@ -35,10 +40,19 @@ public: kMipMap_FilterMode }; + enum SRGBMode { + kRespectDestination_SRGBMode, + kForceAllowSRGB_SRGBMode, + }; + GrTextureParams(SkShader::TileMode tileXAndY, FilterMode filterMode) { this->reset(tileXAndY, filterMode); } + GrTextureParams(SkShader::TileMode tileXandY, FilterMode filterMode, SRGBMode srgbMode) { + this->reset(tileXandY, filterMode, srgbMode); + } + GrTextureParams(const SkShader::TileMode tileModes[2], FilterMode filterMode) { this->reset(tileModes, filterMode); } @@ -51,6 +65,7 @@ public: fTileModes[0] = params.fTileModes[0]; fTileModes[1] = params.fTileModes[1]; fFilterMode = params.fFilterMode; + fSRGBMode = params.fSRGBMode; return *this; } @@ -61,12 +76,20 @@ public: void reset(SkShader::TileMode tileXAndY, FilterMode filterMode) { fTileModes[0] = fTileModes[1] = tileXAndY; fFilterMode = filterMode; + fSRGBMode = kRespectDestination_SRGBMode; + } + + void reset(SkShader::TileMode tileXandY, FilterMode filterMode, SRGBMode srgbMode) { + fTileModes[0] = fTileModes[1] = tileXandY; + fFilterMode = filterMode; + fSRGBMode = srgbMode; } void reset(const SkShader::TileMode tileModes[2], FilterMode filterMode) { fTileModes[0] = tileModes[0]; fTileModes[1] = tileModes[1]; fFilterMode = filterMode; + fSRGBMode = kRespectDestination_SRGBMode; } void setClampNoFilter() { @@ -84,6 +107,8 @@ public: void setTileModeY(const SkShader::TileMode tm) { fTileModes[1] = tm; } void setTileModeXAndY(const SkShader::TileMode tm) { fTileModes[0] = fTileModes[1] = tm; } + void setSRGBMode(SRGBMode srgbMode) { fSRGBMode = srgbMode; } + SkShader::TileMode getTileModeX() const { return fTileModes[0]; } SkShader::TileMode getTileModeY() const { return fTileModes[1]; } @@ -95,10 +120,13 @@ public: FilterMode filterMode() const { return fFilterMode; } + SRGBMode srgbMode() const { return fSRGBMode; } + bool operator== (const GrTextureParams& other) const { return fTileModes[0] == other.fTileModes[0] && fTileModes[1] == other.fTileModes[1] && - fFilterMode == other.fFilterMode; + fFilterMode == other.fFilterMode && + fSRGBMode == other.fSRGBMode; } bool operator!= (const GrTextureParams& other) const { return !(*this == other); } @@ -106,5 +134,6 @@ public: private: SkShader::TileMode fTileModes[2]; FilterMode fFilterMode; + SRGBMode fSRGBMode; }; #endif diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h index 3def9aaa99..9be500d3b2 100644 --- a/include/gpu/GrTypes.h +++ b/include/gpu/GrTypes.h @@ -218,6 +218,10 @@ enum GrPixelConfig { */ kSRGBA_8888_GrPixelConfig, /** + * Premultiplied and sRGB. Byte order is b,g,r,a. + */ + kSBGRA_8888_GrPixelConfig, + /** * ETC1 Compressed Data */ kETC1_GrPixelConfig, @@ -268,8 +272,10 @@ static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1; #endif #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) static const GrPixelConfig kSkia8888_GrPixelConfig = kBGRA_8888_GrPixelConfig; + static const GrPixelConfig kSkiaGamma8888_GrPixelConfig = kSBGRA_8888_GrPixelConfig; #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) static const GrPixelConfig kSkia8888_GrPixelConfig = kRGBA_8888_GrPixelConfig; + static const GrPixelConfig kSkiaGamma8888_GrPixelConfig = kSRGBA_8888_GrPixelConfig; #else #error "SK_*32_SHIFT values must correspond to GL_BGRA or GL_RGBA format." #endif @@ -311,6 +317,7 @@ static inline bool GrPixelConfigIs8888(GrPixelConfig config) { case kRGBA_8888_GrPixelConfig: case kBGRA_8888_GrPixelConfig: case kSRGBA_8888_GrPixelConfig: + case kSBGRA_8888_GrPixelConfig: return true; default: return false; @@ -322,6 +329,7 @@ static inline bool GrPixelConfigIs8888(GrPixelConfig config) { static inline bool GrPixelConfigIsSRGB(GrPixelConfig config) { switch (config) { case kSRGBA_8888_GrPixelConfig: + case kSBGRA_8888_GrPixelConfig: return true; default: return false; @@ -336,6 +344,10 @@ static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) { return kRGBA_8888_GrPixelConfig; case kRGBA_8888_GrPixelConfig: return kBGRA_8888_GrPixelConfig; + case kSBGRA_8888_GrPixelConfig: + return kSRGBA_8888_GrPixelConfig; + case kSRGBA_8888_GrPixelConfig: + return kSBGRA_8888_GrPixelConfig; default: return kUnknown_GrPixelConfig; } @@ -353,6 +365,7 @@ static inline size_t GrBytesPerPixel(GrPixelConfig config) { case kRGBA_8888_GrPixelConfig: case kBGRA_8888_GrPixelConfig: case kSRGBA_8888_GrPixelConfig: + case kSBGRA_8888_GrPixelConfig: return 4; case kRGBA_half_GrPixelConfig: return 8; @@ -386,6 +399,16 @@ static inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) { } } +static inline bool GrAllowSRGBForDestinationPixelConfig(GrPixelConfig config) { + switch (config) { + case kRGBA_8888_GrPixelConfig: + case kBGRA_8888_GrPixelConfig: + return false; + default: + return true; + } +} + /** * Optional bitfield flags that can be set on GrSurfaceDesc (below). */ diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h index aacc5d25db..6a73636c69 100644 --- a/include/gpu/SkGr.h +++ b/include/gpu/SkGr.h @@ -15,6 +15,7 @@ #include "SkFilterQuality.h" #include "SkImageInfo.h" +class GrCaps; class GrContext; class GrTexture; class GrTextureParams; @@ -70,10 +71,10 @@ static inline GrColor SkPMColorToGrColor(SkPMColor c) { GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams&); // TODO: Move SkImageInfo2GrPixelConfig to SkGrPriv.h (requires cleanup to SkWindow its subclasses). -GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, SkColorProfileType); +GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, SkColorProfileType, const GrCaps&); -static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info) { - return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(), info.profileType()); +static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info, const GrCaps& caps) { + return SkImageInfo2GrPixelConfig(info.colorType(), info.alphaType(), info.profileType(), caps); } GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality, |