aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2017-11-15 14:22:10 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-15 20:02:43 +0000
commit33d17cbb003975fff895954435183756f9893c17 (patch)
tree1317eec2ffe56bd384a592e749511abf3cbc6bf1
parentd8d984ecc99d8b7fc37a742e22acbe831f315142 (diff)
Add private grpixelconfigs for alpha_8 and alpha_half
Bug: skia: Change-Id: I5191b6e045aea2a5af2b305b5972ad1e638a7ace Reviewed-on: https://skia-review.googlesource.com/71763 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
-rw-r--r--include/gpu/GrTypes.h7
-rw-r--r--include/gpu/mock/GrMockTypes.h3
-rw-r--r--include/private/GrTypesPriv.h42
-rw-r--r--src/gpu/GrCaps.cpp4
-rw-r--r--src/gpu/GrShaderCaps.cpp34
-rw-r--r--src/gpu/SkGr.cpp4
-rw-r--r--src/gpu/effects/GrDitherEffect.fp4
-rw-r--r--src/gpu/effects/GrDitherEffect.h4
-rw-r--r--src/gpu/gl/GrGLCaps.cpp129
-rw-r--r--src/gpu/gl/GrGLGpu.cpp4
-rw-r--r--src/gpu/mtl/GrMtlUtil.mm12
-rw-r--r--src/gpu/vk/GrVkCaps.cpp5
-rw-r--r--src/gpu/vk/GrVkUtil.cpp10
-rw-r--r--tests/GrSurfaceTest.cpp4
14 files changed, 194 insertions, 72 deletions
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
index 57f32f2504..c47cfc8f86 100644
--- a/include/gpu/GrTypes.h
+++ b/include/gpu/GrTypes.h
@@ -343,7 +343,12 @@ enum GrPixelConfig {
*/
kRGBA_half_GrPixelConfig,
- kLast_GrPixelConfig = kRGBA_half_GrPixelConfig
+ kPrivateConfig1_GrPixelConfig,
+ kPrivateConfig2_GrPixelConfig,
+ kPrivateConfig3_GrPixelConfig,
+ kPrivateConfig4_GrPixelConfig,
+
+ kLast_GrPixelConfig = kPrivateConfig4_GrPixelConfig
};
static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1;
diff --git a/include/gpu/mock/GrMockTypes.h b/include/gpu/mock/GrMockTypes.h
index 3ad0fc3b9a..35bb5efe23 100644
--- a/include/gpu/mock/GrMockTypes.h
+++ b/include/gpu/mock/GrMockTypes.h
@@ -9,6 +9,7 @@
#define GrMockOptions_DEFINED
#include "GrTypes.h"
+#include "../private/GrTypesPriv.h"
struct GrMockTextureInfo {
int fID;
@@ -25,6 +26,8 @@ struct GrMockOptions {
fConfigOptions[kRGBA_8888_GrPixelConfig].fRenderable[0] = true;
fConfigOptions[kRGBA_8888_GrPixelConfig].fTexturable = true;
fConfigOptions[kAlpha_8_GrPixelConfig].fTexturable = true;
+ fConfigOptions[kAlpha_8_as_Alpha_GrPixelConfig].fTexturable = true;
+ fConfigOptions[kAlpha_8_as_Red_GrPixelConfig].fTexturable = true;
fConfigOptions[kRGB_565_GrPixelConfig].fTexturable = true;
}
diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h
index 9922f4cbc0..9f379f6efb 100644
--- a/include/private/GrTypesPriv.h
+++ b/include/private/GrTypesPriv.h
@@ -801,6 +801,15 @@ enum class GrMipMapsStatus {
GR_MAKE_BITFIELD_CLASS_OPS(GpuPathRenderers)
/**
+ * We want to extend the GrPixelConfig enum to add cases for dealing with alpha_8 which is
+ * internally either alpha8 or red8
+ */
+static constexpr GrPixelConfig kAlpha_8_as_Alpha_GrPixelConfig = kPrivateConfig1_GrPixelConfig;
+static constexpr GrPixelConfig kAlpha_8_as_Red_GrPixelConfig = kPrivateConfig2_GrPixelConfig;
+static constexpr GrPixelConfig kAlpha_half_as_Alpha_GrPixelConfig = kPrivateConfig3_GrPixelConfig;
+static constexpr GrPixelConfig kAlpha_half_as_Red_GrPixelConfig = kPrivateConfig4_GrPixelConfig;
+
+/**
* Utility functions for GrPixelConfig
*/
// Returns true if the pixel config is 32 bits per pixel
@@ -813,6 +822,8 @@ static inline bool GrPixelConfigIs8888Unorm(GrPixelConfig config) {
return true;
case kUnknown_GrPixelConfig:
case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_as_Alpha_GrPixelConfig:
+ case kAlpha_8_as_Red_GrPixelConfig:
case kGray_8_GrPixelConfig:
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
@@ -820,6 +831,8 @@ static inline bool GrPixelConfigIs8888Unorm(GrPixelConfig config) {
case kRGBA_float_GrPixelConfig:
case kRG_float_GrPixelConfig:
case kAlpha_half_GrPixelConfig:
+ case kAlpha_half_as_Alpha_GrPixelConfig:
+ case kAlpha_half_as_Red_GrPixelConfig:
case kRGBA_half_GrPixelConfig:
return false;
}
@@ -836,6 +849,8 @@ static inline bool GrPixelConfigIsSRGB(GrPixelConfig config) {
return true;
case kUnknown_GrPixelConfig:
case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_as_Alpha_GrPixelConfig:
+ case kAlpha_8_as_Red_GrPixelConfig:
case kGray_8_GrPixelConfig:
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
@@ -845,6 +860,8 @@ static inline bool GrPixelConfigIsSRGB(GrPixelConfig config) {
case kRGBA_float_GrPixelConfig:
case kRG_float_GrPixelConfig:
case kAlpha_half_GrPixelConfig:
+ case kAlpha_half_as_Alpha_GrPixelConfig:
+ case kAlpha_half_as_Red_GrPixelConfig:
case kRGBA_half_GrPixelConfig:
return false;
}
@@ -866,6 +883,8 @@ static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) {
return kSBGRA_8888_GrPixelConfig;
case kUnknown_GrPixelConfig:
case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_as_Alpha_GrPixelConfig:
+ case kAlpha_8_as_Red_GrPixelConfig:
case kGray_8_GrPixelConfig:
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
@@ -873,6 +892,8 @@ static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) {
case kRGBA_float_GrPixelConfig:
case kRG_float_GrPixelConfig:
case kAlpha_half_GrPixelConfig:
+ case kAlpha_half_as_Alpha_GrPixelConfig:
+ case kAlpha_half_as_Red_GrPixelConfig:
case kRGBA_half_GrPixelConfig:
return kUnknown_GrPixelConfig;
}
@@ -883,11 +904,15 @@ static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) {
static inline size_t GrBytesPerPixel(GrPixelConfig config) {
switch (config) {
case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_as_Alpha_GrPixelConfig:
+ case kAlpha_8_as_Red_GrPixelConfig:
case kGray_8_GrPixelConfig:
return 1;
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
case kAlpha_half_GrPixelConfig:
+ case kAlpha_half_as_Alpha_GrPixelConfig:
+ case kAlpha_half_as_Red_GrPixelConfig:
return 2;
case kRGBA_8888_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
@@ -915,8 +940,12 @@ static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) {
case kRG_float_GrPixelConfig:
return true;
case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_as_Alpha_GrPixelConfig:
+ case kAlpha_8_as_Red_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
case kAlpha_half_GrPixelConfig:
+ case kAlpha_half_as_Alpha_GrPixelConfig:
+ case kAlpha_half_as_Red_GrPixelConfig:
case kRGBA_8888_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
case kSRGBA_8888_GrPixelConfig:
@@ -934,7 +963,11 @@ static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) {
static inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) {
switch (config) {
case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_as_Alpha_GrPixelConfig:
+ case kAlpha_8_as_Red_GrPixelConfig:
case kAlpha_half_GrPixelConfig:
+ case kAlpha_half_as_Alpha_GrPixelConfig:
+ case kAlpha_half_as_Red_GrPixelConfig:
return true;
case kUnknown_GrPixelConfig:
case kGray_8_GrPixelConfig:
@@ -959,10 +992,14 @@ static inline bool GrPixelConfigIsFloatingPoint(GrPixelConfig config) {
case kRGBA_float_GrPixelConfig:
case kRG_float_GrPixelConfig:
case kAlpha_half_GrPixelConfig:
+ case kAlpha_half_as_Alpha_GrPixelConfig:
+ case kAlpha_half_as_Red_GrPixelConfig:
case kRGBA_half_GrPixelConfig:
return true;
case kUnknown_GrPixelConfig:
case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_as_Alpha_GrPixelConfig:
+ case kAlpha_8_as_Red_GrPixelConfig:
case kGray_8_GrPixelConfig:
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
@@ -984,6 +1021,8 @@ static inline bool GrPixelConfigIsSint(GrPixelConfig config) {
static inline bool GrPixelConfigIsUnorm(GrPixelConfig config) {
switch (config) {
case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_as_Alpha_GrPixelConfig:
+ case kAlpha_8_as_Red_GrPixelConfig:
case kGray_8_GrPixelConfig:
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
@@ -994,6 +1033,8 @@ static inline bool GrPixelConfigIsUnorm(GrPixelConfig config) {
return true;
case kUnknown_GrPixelConfig:
case kAlpha_half_GrPixelConfig:
+ case kAlpha_half_as_Alpha_GrPixelConfig:
+ case kAlpha_half_as_Red_GrPixelConfig:
case kRGBA_8888_sint_GrPixelConfig:
case kRGBA_float_GrPixelConfig:
case kRG_float_GrPixelConfig:
@@ -1009,5 +1050,4 @@ static inline GrPixelConfigIsClamped GrGetPixelConfigIsClamped(GrPixelConfig con
: GrPixelConfigIsClamped::kYes;
}
-
#endif
diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp
index 2e25845876..482542be25 100644
--- a/src/gpu/GrCaps.cpp
+++ b/src/gpu/GrCaps.cpp
@@ -14,6 +14,8 @@ static const char* pixel_config_name(GrPixelConfig config) {
switch (config) {
case kUnknown_GrPixelConfig: return "Unknown";
case kAlpha_8_GrPixelConfig: return "Alpha8";
+ case kAlpha_8_as_Alpha_GrPixelConfig: return "Alpha8_asAlpha";
+ case kAlpha_8_as_Red_GrPixelConfig: return "Alpha8_asRed";
case kGray_8_GrPixelConfig: return "Gray8";
case kRGB_565_GrPixelConfig: return "RGB565";
case kRGBA_4444_GrPixelConfig: return "RGBA444";
@@ -25,6 +27,8 @@ static const char* pixel_config_name(GrPixelConfig config) {
case kRGBA_float_GrPixelConfig: return "RGBAFloat";
case kRG_float_GrPixelConfig: return "RGFloat";
case kAlpha_half_GrPixelConfig: return "AlphaHalf";
+ case kAlpha_half_as_Alpha_GrPixelConfig: return "AlphaHalf_asAlpha";
+ case kAlpha_half_as_Red_GrPixelConfig: return "AlphaHalf_asRed";
case kRGBA_half_GrPixelConfig: return "RGBAHalf";
}
SK_ABORT("Invalid pixel config");
diff --git a/src/gpu/GrShaderCaps.cpp b/src/gpu/GrShaderCaps.cpp
index 7e44188074..0a612db335 100644
--- a/src/gpu/GrShaderCaps.cpp
+++ b/src/gpu/GrShaderCaps.cpp
@@ -220,22 +220,24 @@ void GrShaderCaps::initSamplerPrecisionTable() {
}
uint8_t* table = fSamplerPrecisions[visibility];
- table[kUnknown_GrPixelConfig] = lowp;
- table[kAlpha_8_GrPixelConfig] = lowp;
- table[kGray_8_GrPixelConfig] = lowp;
- table[kRGB_565_GrPixelConfig] = lowp;
- table[kRGBA_4444_GrPixelConfig] = lowp;
- table[kRGBA_8888_GrPixelConfig] = lowp;
- table[kBGRA_8888_GrPixelConfig] = lowp;
- table[kSRGBA_8888_GrPixelConfig] = lowp;
- table[kSBGRA_8888_GrPixelConfig] = lowp;
- table[kRGBA_8888_sint_GrPixelConfig] = lowp;
- table[kRGBA_float_GrPixelConfig] = kHigh_GrSLPrecision;
- table[kRG_float_GrPixelConfig] = kHigh_GrSLPrecision;
- table[kAlpha_half_GrPixelConfig] = mediump;
- table[kRGBA_half_GrPixelConfig] = mediump;
-
- GR_STATIC_ASSERT(14 == kGrPixelConfigCnt);
+ table[kUnknown_GrPixelConfig] = lowp;
+ table[kAlpha_8_GrPixelConfig] = lowp;
+ table[kAlpha_8_as_Alpha_GrPixelConfig] = lowp;
+ table[kAlpha_8_as_Red_GrPixelConfig] = lowp;
+ table[kGray_8_GrPixelConfig] = lowp;
+ table[kRGB_565_GrPixelConfig] = lowp;
+ table[kRGBA_4444_GrPixelConfig] = lowp;
+ table[kRGBA_8888_GrPixelConfig] = lowp;
+ table[kBGRA_8888_GrPixelConfig] = lowp;
+ table[kSRGBA_8888_GrPixelConfig] = lowp;
+ table[kSBGRA_8888_GrPixelConfig] = lowp;
+ table[kRGBA_8888_sint_GrPixelConfig] = lowp;
+ table[kRGBA_float_GrPixelConfig] = kHigh_GrSLPrecision;
+ table[kRG_float_GrPixelConfig] = kHigh_GrSLPrecision;
+ table[kAlpha_half_GrPixelConfig] = mediump;
+ table[kAlpha_half_as_Alpha_GrPixelConfig] = mediump;
+ table[kAlpha_half_as_Red_GrPixelConfig] = mediump;
+ table[kRGBA_half_GrPixelConfig] = mediump;
}
}
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 026a7482b4..63d0f260b0 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -368,7 +368,9 @@ GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info, const GrCaps& c
bool GrPixelConfigToColorType(GrPixelConfig config, SkColorType* ctOut) {
SkColorType ct;
switch (config) {
- case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_GrPixelConfig: // fall through
+ case kAlpha_8_as_Alpha_GrPixelConfig: // fall through
+ case kAlpha_8_as_Red_GrPixelConfig:
ct = kAlpha_8_SkColorType;
break;
case kGray_8_GrPixelConfig:
diff --git a/src/gpu/effects/GrDitherEffect.fp b/src/gpu/effects/GrDitherEffect.fp
index f2d54cf2eb..22c371ea37 100644
--- a/src/gpu/effects/GrDitherEffect.fp
+++ b/src/gpu/effects/GrDitherEffect.fp
@@ -20,11 +20,15 @@ layout(key) in int rangeType;
break;
case kUnknown_GrPixelConfig:
case kAlpha_half_GrPixelConfig:
+ case kAlpha_half_as_Alpha_GrPixelConfig:
+ case kAlpha_half_as_Red_GrPixelConfig:
case kRGBA_8888_sint_GrPixelConfig:
case kRGBA_float_GrPixelConfig:
case kRG_float_GrPixelConfig:
case kRGBA_half_GrPixelConfig:
case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_as_Alpha_GrPixelConfig:
+ case kAlpha_8_as_Red_GrPixelConfig:
return nullptr;
}
return std::unique_ptr<GrFragmentProcessor>(new GrDitherEffect(rangeType));
diff --git a/src/gpu/effects/GrDitherEffect.h b/src/gpu/effects/GrDitherEffect.h
index deb20852ca..1b1357baff 100644
--- a/src/gpu/effects/GrDitherEffect.h
+++ b/src/gpu/effects/GrDitherEffect.h
@@ -36,11 +36,15 @@ public:
break;
case kUnknown_GrPixelConfig:
case kAlpha_half_GrPixelConfig:
+ case kAlpha_half_as_Alpha_GrPixelConfig:
+ case kAlpha_half_as_Red_GrPixelConfig:
case kRGBA_8888_sint_GrPixelConfig:
case kRGBA_float_GrPixelConfig:
case kRG_float_GrPixelConfig:
case kRGBA_half_GrPixelConfig:
case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_as_Alpha_GrPixelConfig:
+ case kAlpha_8_as_Red_GrPixelConfig:
return nullptr;
}
return std::unique_ptr<GrFragmentProcessor>(new GrDitherEffect(rangeType));
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 2212459e68..f245d0f551 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -1947,33 +1947,46 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
}
fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
- fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
- fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
- fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
+ ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
+ alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
+ alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
+ if (kGL_GrGLStandard== standard || version <= GR_GL_VER(3, 0)) {
+ alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
+ }
+ alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
+ alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
+ alphaInfo.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_ALPHA;
+ alphaInfo.fSwizzle = GrSwizzle::AAAA();
+ if (fAlpha8IsRenderable && kGL_GrGLStandard== standard) {
+ alphaInfo.fFlags |= allRenderFlags;
+ }
+
+ ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
+ redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
+ redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
+ redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
+ redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
+ redInfo.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_RED;
+ redInfo.fSwizzle = GrSwizzle::RRRR();
+
+ // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
+ if (texStorageSupported && !isCommandBufferES2) {
+ alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
+ redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
+ }
+
if (this->textureRedSupport()) {
- fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
- fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
- fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
- GR_GL_RED;
- fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
+ redInfo.fFlags = ConfigInfo::kTextureable_Flag;
if (texelBufferSupport) {
- fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
+ redInfo.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
}
- fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
+ redInfo.fFlags |= allRenderFlags;
+
+ fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
} else {
- fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
- fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
- fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
- GR_GL_ALPHA;
- fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
- if (fAlpha8IsRenderable) {
- fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
- }
- }
+ redInfo.fFlags = 0;
- // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
- if (texStorageSupported && !isCommandBufferES2) {
- fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
+ fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
}
fConfigTable[kGray_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
@@ -2068,44 +2081,60 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
}
- if (this->textureRedSupport()) {
- fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
- fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
- fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
- = GR_GL_RED;
- fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
- if (texelBufferSupport) {
- fConfigTable[kAlpha_half_GrPixelConfig].fFlags |=
- ConfigInfo::kCanUseWithTexelBuffer_Flag;
- }
- } else {
- fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
- fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
- fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
- = GR_GL_ALPHA;
- fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
- }
-
+ GrGLenum alphaHalfExternalType;
if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
- fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
+ alphaHalfExternalType = GR_GL_HALF_FLOAT;
} else {
- fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
+ alphaHalfExternalType = GR_GL_HALF_FLOAT_OES;
}
- fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
+
+ ConfigInfo& alphaHalf = fConfigTable[kAlpha_half_as_Alpha_GrPixelConfig];
+ alphaHalf.fFormats.fExternalType = alphaHalfExternalType;
+ alphaHalf.fFormatType = kFloat_FormatType;
+ alphaHalf.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
+ alphaHalf.fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
+ alphaHalf.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_ALPHA;
+ alphaHalf.fSwizzle = GrSwizzle::AAAA();
+
+ ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
+ redHalf.fFormats.fExternalType = alphaHalfExternalType;
+ redHalf.fFormatType = kFloat_FormatType;
+ redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
+ redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
+ redHalf.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_RED;
+ redHalf.fSwizzle = GrSwizzle::RRRR();
+
if (texStorageSupported) {
- fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
+ alphaHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
+ redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
}
if (hasHalfFPTextures) {
- fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
- // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
- // GL_RED internal format.
+ if (kGL_GrGLStandard == standard || version <= GR_GL_VER(3, 0)) {
+ alphaHalf.fFlags = ConfigInfo::kTextureable_Flag;
+ }
+ redHalf.fFlags = ConfigInfo::kTextureable_Flag;
if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 2) ||
(this->textureRedSupport() &&
ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
- fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
+ if (kGL_GrGLStandard == standard) {
+ alphaHalf.fFlags |= fpRenderFlags;
+ }
+ redHalf.fFlags |= fpRenderFlags;
}
}
+ if (this->textureRedSupport()) {
+ if (texelBufferSupport) {
+ redHalf.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
+ }
+
+ fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
+ } else {
+ redHalf.fFlags = 0;
+
+ fConfigTable[kAlpha_half_GrPixelConfig] = alphaHalf;
+ }
+
fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
@@ -2157,8 +2186,12 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
// kAlpha_8_GrPixelConfig. Alpha8 is not a valid signed internal format so we must use the base
// internal format for that config when doing TexImage calls.
if(kGalliumLLVM_GrGLRenderer == ctxInfo.renderer()) {
+ SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat ==
+ fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat);
fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
+ fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
+ fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
}
// OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 3b39b20f0e..ad13516ce6 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -785,11 +785,15 @@ bool GrGLGpu::onWritePixels(GrSurface* surface, GrSurfaceOrigin origin,
static inline GrGLint config_alignment(GrPixelConfig config) {
switch (config) {
case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_as_Alpha_GrPixelConfig:
+ case kAlpha_8_as_Red_GrPixelConfig:
case kGray_8_GrPixelConfig:
return 1;
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
case kAlpha_half_GrPixelConfig:
+ case kAlpha_half_as_Alpha_GrPixelConfig:
+ case kAlpha_half_as_Red_GrPixelConfig:
case kRGBA_half_GrPixelConfig:
return 2;
case kRGBA_8888_GrPixelConfig:
diff --git a/src/gpu/mtl/GrMtlUtil.mm b/src/gpu/mtl/GrMtlUtil.mm
index 24643669ea..9e6c632638 100644
--- a/src/gpu/mtl/GrMtlUtil.mm
+++ b/src/gpu/mtl/GrMtlUtil.mm
@@ -7,6 +7,8 @@
#include "GrMtlUtil.h"
+#include "GrTypesPriv.h"
+
bool GrPixelConfigToMTLFormat(GrPixelConfig config, MTLPixelFormat* format) {
MTLPixelFormat dontCare;
if (!format) {
@@ -45,9 +47,12 @@ bool GrPixelConfigToMTLFormat(GrPixelConfig config, MTLPixelFormat* format) {
#else
return false;
#endif
- case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_GrPixelConfig: // fall through
+ case kAlpha_8_as_Red_GrPixelConfig:
*format = MTLPixelFormatR8Unorm;
return true;
+ case kAlpha_8_as_Alpha_GrPixelConfig:
+ return false;
case kGray_8_GrPixelConfig:
*format = MTLPixelFormatR8Unorm;
return true;
@@ -60,9 +65,12 @@ bool GrPixelConfigToMTLFormat(GrPixelConfig config, MTLPixelFormat* format) {
case kRGBA_half_GrPixelConfig:
*format = MTLPixelFormatRGBA16Float;
return true;
- case kAlpha_half_GrPixelConfig:
+ case kAlpha_half_GrPixelConfig: // fall through
+ case kAlpha_half_as_Red_GrPixelConfig:
*format = MTLPixelFormatR16Float;
return true;
+ case kAlpha_half_as_Alpha_GrPixelConfig:
+ return false;
}
SK_ABORT("Unexpected config");
return false;
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index 2b24205af8..6804aeb22f 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -208,7 +208,10 @@ void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties, uint
// fConfigOutputSwizzle will default to RGBA so we only need to set it for alpha only config.
for (int i = 0; i < kGrPixelConfigCnt; ++i) {
GrPixelConfig config = static_cast<GrPixelConfig>(i);
- if (GrPixelConfigIsAlphaOnly(config)) {
+ // Vulkan doesn't support a single channel format stored in alpha.
+ if (GrPixelConfigIsAlphaOnly(config) &&
+ kAlpha_8_as_Alpha_GrPixelConfig != config &&
+ kAlpha_half_as_Alpha_GrPixelConfig != config) {
shaderCaps->fConfigTextureSwizzle[i] = GrSwizzle::RRRR();
shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
} else {
diff --git a/src/gpu/vk/GrVkUtil.cpp b/src/gpu/vk/GrVkUtil.cpp
index 0ce47cb962..729804bd32 100644
--- a/src/gpu/vk/GrVkUtil.cpp
+++ b/src/gpu/vk/GrVkUtil.cpp
@@ -42,9 +42,12 @@ bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format) {
// store the data is if it was B4G4R4A4 and swizzle in shaders
*format = VK_FORMAT_B4G4R4A4_UNORM_PACK16;
return true;
- case kAlpha_8_GrPixelConfig:
+ case kAlpha_8_GrPixelConfig: // fall through
+ case kAlpha_8_as_Red_GrPixelConfig:
*format = VK_FORMAT_R8_UNORM;
return true;
+ case kAlpha_8_as_Alpha_GrPixelConfig:
+ return false;
case kGray_8_GrPixelConfig:
*format = VK_FORMAT_R8_UNORM;
return true;
@@ -57,9 +60,12 @@ bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format) {
case kRGBA_half_GrPixelConfig:
*format = VK_FORMAT_R16G16B16A16_SFLOAT;
return true;
- case kAlpha_half_GrPixelConfig:
+ case kAlpha_half_GrPixelConfig: // fall through
+ case kAlpha_half_as_Red_GrPixelConfig:
*format = VK_FORMAT_R16_SFLOAT;
return true;
+ case kAlpha_half_as_Alpha_GrPixelConfig:
+ return false;
}
SK_ABORT("Unexpected config");
return false;
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
index eff8c2584e..7c0171d2ec 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -82,6 +82,8 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
GrPixelConfig configs[] = {
kUnknown_GrPixelConfig,
kAlpha_8_GrPixelConfig,
+ kAlpha_8_as_Alpha_GrPixelConfig,
+ kAlpha_8_as_Red_GrPixelConfig,
kGray_8_GrPixelConfig,
kRGB_565_GrPixelConfig,
kRGBA_4444_GrPixelConfig,
@@ -93,6 +95,8 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
kRGBA_float_GrPixelConfig,
kRG_float_GrPixelConfig,
kAlpha_half_GrPixelConfig,
+ kAlpha_half_as_Alpha_GrPixelConfig,
+ kAlpha_half_as_Red_GrPixelConfig,
kRGBA_half_GrPixelConfig,
};
SkASSERT(kGrPixelConfigCnt == SK_ARRAY_COUNT(configs));