Make Mock GrBackendFormat use GrColorType (instead of GrPixelConfig)
The switch to GrColorType does mean that we can no longer represent compressed backend formats in the Mock backend surfaces. This will require a Chrome CL before it can land in Skia. TBR=bsalomon@google.com Change-Id: Ie4e2d4826f960664a21d3de79933eb1cb5d06896 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/225538 Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
0a7cab0f67
commit
a5e78be278
@ -528,6 +528,7 @@ skia_gpu_sources = [
|
||||
"$_src/gpu/mock/GrMockGpuCommandBuffer.h",
|
||||
"$_src/gpu/mock/GrMockStencilAttachment.h",
|
||||
"$_src/gpu/mock/GrMockTexture.h",
|
||||
"$_src/gpu/mock/GrMockTypes.cpp",
|
||||
|
||||
# Sk files
|
||||
"$_src/gpu/SkGpuDevice.cpp",
|
||||
|
@ -66,8 +66,8 @@ public:
|
||||
}
|
||||
#endif
|
||||
|
||||
static GrBackendFormat MakeMock(GrPixelConfig config) {
|
||||
return GrBackendFormat(config);
|
||||
static GrBackendFormat MakeMock(GrColorType colorType, GrSRGBEncoded srgbEncoded) {
|
||||
return GrBackendFormat(colorType, srgbEncoded);
|
||||
}
|
||||
|
||||
bool operator==(const GrBackendFormat& that) const;
|
||||
@ -77,7 +77,7 @@ public:
|
||||
GrTextureType textureType() const { return fTextureType; }
|
||||
|
||||
// If the backend API is GL, these return a pointer to the format and target. Otherwise
|
||||
// it returns nullptr.
|
||||
// they return nullptr.
|
||||
const GrGLenum* getGLFormat() const;
|
||||
const GrGLenum* getGLTarget() const;
|
||||
|
||||
@ -93,9 +93,10 @@ public:
|
||||
const GrMTLPixelFormat* getMtlFormat() const;
|
||||
#endif
|
||||
|
||||
// If the backend API is Mock, this returns a pointer to a GrPixelConfig. Otherwise
|
||||
// it returns nullptr.
|
||||
const GrPixelConfig* getMockFormat() const;
|
||||
// If the backend API is Mock, these return a pointer to the colorType and srgb encoding.
|
||||
// Otherwise they return nullptr.
|
||||
const GrColorType* getMockColorType() const;
|
||||
const GrSRGBEncoded* getMockSRGBEncoded() const;
|
||||
|
||||
// If possible, copies the GrBackendFormat and forces the texture type to be Texture2D. If the
|
||||
// GrBackendFormat was for Vulkan and it originally had a GrVkYcbcrConversionInfo, we will
|
||||
@ -114,7 +115,7 @@ private:
|
||||
GrBackendFormat(const GrMTLPixelFormat mtlFormat);
|
||||
#endif
|
||||
|
||||
GrBackendFormat(const GrPixelConfig config);
|
||||
GrBackendFormat(GrColorType colorType, GrSRGBEncoded srgbEncoded);
|
||||
|
||||
GrBackendApi fBackend = GrBackendApi::kMock;
|
||||
bool fValid = false;
|
||||
@ -128,7 +129,10 @@ private:
|
||||
#ifdef SK_METAL
|
||||
GrMTLPixelFormat fMtlFormat;
|
||||
#endif
|
||||
GrPixelConfig fMockFormat;
|
||||
struct {
|
||||
GrColorType fColorType;
|
||||
GrSRGBEncoded fSRGBEncoded;
|
||||
} fMock;
|
||||
};
|
||||
GrTextureType fTextureType = GrTextureType::kNone;
|
||||
};
|
||||
|
@ -11,22 +11,67 @@
|
||||
#include "include/gpu/GrTypes.h"
|
||||
#include "include/private/GrTypesPriv.h"
|
||||
|
||||
class GrBackendFormat;
|
||||
|
||||
struct GrMockTextureInfo {
|
||||
GrPixelConfig fConfig;
|
||||
int fID;
|
||||
GrMockTextureInfo()
|
||||
: fColorType(GrColorType::kUnknown)
|
||||
, fSRGBEncoded(GrSRGBEncoded::kNo)
|
||||
, fID(0) {}
|
||||
|
||||
GrMockTextureInfo(GrColorType colorType, GrSRGBEncoded srgbEncoded, int id)
|
||||
: fColorType(colorType)
|
||||
, fSRGBEncoded(srgbEncoded)
|
||||
, fID(id) {
|
||||
SkASSERT(fID);
|
||||
}
|
||||
|
||||
bool operator==(const GrMockTextureInfo& that) const {
|
||||
return fConfig == that.fConfig && fID == that.fID;
|
||||
return fColorType == that.fColorType &&
|
||||
fSRGBEncoded == that.fSRGBEncoded &&
|
||||
fID == that.fID;
|
||||
}
|
||||
|
||||
GrPixelConfig pixelConfig() const {
|
||||
return GrColorTypeToPixelConfig(fColorType, fSRGBEncoded);
|
||||
}
|
||||
|
||||
GrBackendFormat getBackendFormat() const;
|
||||
|
||||
GrColorType fColorType;
|
||||
GrSRGBEncoded fSRGBEncoded;
|
||||
int fID;
|
||||
};
|
||||
|
||||
struct GrMockRenderTargetInfo {
|
||||
GrPixelConfig fConfig;
|
||||
int fID;
|
||||
GrMockRenderTargetInfo()
|
||||
: fColorType(GrColorType::kUnknown)
|
||||
, fSRGBEncoded(GrSRGBEncoded::kNo)
|
||||
, fID(0) {}
|
||||
|
||||
GrMockRenderTargetInfo(GrColorType colorType, GrSRGBEncoded srgbEncoded, int id)
|
||||
: fColorType(colorType)
|
||||
, fSRGBEncoded(srgbEncoded)
|
||||
, fID(id) {
|
||||
SkASSERT(fID);
|
||||
}
|
||||
|
||||
bool operator==(const GrMockRenderTargetInfo& that) const {
|
||||
return fConfig == that.fConfig && fID == that.fID;
|
||||
return fColorType == that.fColorType &&
|
||||
fSRGBEncoded == that.fSRGBEncoded &&
|
||||
fID == that.fID;
|
||||
}
|
||||
|
||||
GrPixelConfig pixelConfig() const {
|
||||
return GrColorTypeToPixelConfig(fColorType, fSRGBEncoded);
|
||||
}
|
||||
|
||||
GrBackendFormat getBackendFormat() const;
|
||||
|
||||
private:
|
||||
GrColorType fColorType;
|
||||
GrSRGBEncoded fSRGBEncoded;
|
||||
int fID;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -39,14 +84,12 @@ struct GrMockOptions {
|
||||
using Renderability = ConfigOptions::Renderability;
|
||||
// By default RGBA_8888 and BGRA_8888 are textureable and renderable and
|
||||
// A8 and RGB565 are texturable.
|
||||
fConfigOptions[kRGBA_8888_GrPixelConfig].fRenderability = Renderability::kNonMSAA;
|
||||
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;
|
||||
fConfigOptions[(int)GrColorType::kRGBA_8888].fRenderability = Renderability::kNonMSAA;
|
||||
fConfigOptions[(int)GrColorType::kRGBA_8888].fTexturable = true;
|
||||
fConfigOptions[(int)GrColorType::kAlpha_8].fTexturable = true;
|
||||
fConfigOptions[(int)GrColorType::kBGR_565].fTexturable = true;
|
||||
|
||||
fConfigOptions[kBGRA_8888_GrPixelConfig] = fConfigOptions[kRGBA_8888_GrPixelConfig];
|
||||
fConfigOptions[(int)GrColorType::kBGRA_8888] = fConfigOptions[(int)GrColorType::kRGBA_8888];
|
||||
}
|
||||
|
||||
struct ConfigOptions {
|
||||
@ -62,7 +105,7 @@ struct GrMockOptions {
|
||||
int fMaxTextureSize = 2048;
|
||||
int fMaxRenderTargetSize = 2048;
|
||||
int fMaxVertexAttributes = 16;
|
||||
ConfigOptions fConfigOptions[kGrPixelConfigCnt];
|
||||
ConfigOptions fConfigOptions[kGrColorTypeCnt];
|
||||
|
||||
// GrShaderCaps options.
|
||||
bool fGeometryShaderSupport = false;
|
||||
|
@ -1178,8 +1178,12 @@ enum class GrColorType {
|
||||
// Experimental (for Y416 and mutant P016/P010)
|
||||
kRGBA_16161616, // Not in SkColorType
|
||||
kRG_F16, // Not in SkColorType
|
||||
|
||||
kLast = kRG_F16
|
||||
};
|
||||
|
||||
static const int kGrColorTypeCnt = static_cast<int>(GrColorType::kLast) + 1;
|
||||
|
||||
static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct) {
|
||||
switch (ct) {
|
||||
case GrColorType::kUnknown: return kUnknown_SkColorType;
|
||||
|
@ -45,7 +45,7 @@ GrBackendFormat::GrBackendFormat(const GrBackendFormat& that)
|
||||
break;
|
||||
#endif
|
||||
case GrBackendApi::kMock:
|
||||
fMockFormat = that.fMockFormat;
|
||||
fMock = that.fMock;
|
||||
break;
|
||||
default:
|
||||
SK_ABORT("Unknown GrBackend");
|
||||
@ -154,20 +154,29 @@ const GrMTLPixelFormat* GrBackendFormat::getMtlFormat() const {
|
||||
}
|
||||
#endif
|
||||
|
||||
GrBackendFormat::GrBackendFormat(GrPixelConfig config)
|
||||
GrBackendFormat::GrBackendFormat(GrColorType colorType, GrSRGBEncoded srgbEncoded)
|
||||
: fBackend(GrBackendApi::kMock)
|
||||
, fValid(true)
|
||||
, fMockFormat(config)
|
||||
, fTextureType(GrTextureType::k2D) {
|
||||
fMock.fColorType = colorType;
|
||||
fMock.fSRGBEncoded = srgbEncoded;
|
||||
}
|
||||
|
||||
const GrPixelConfig* GrBackendFormat::getMockFormat() const {
|
||||
const GrColorType* GrBackendFormat::getMockColorType() const {
|
||||
if (this->isValid() && GrBackendApi::kMock == fBackend) {
|
||||
return &fMockFormat;
|
||||
return &fMock.fColorType;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const GrSRGBEncoded* GrBackendFormat::getMockSRGBEncoded() const {
|
||||
if (this->isValid() && GrBackendApi::kMock == fBackend) {
|
||||
return &fMock.fSRGBEncoded;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
GrBackendFormat GrBackendFormat::makeTexture2D() const {
|
||||
GrBackendFormat copy = *this;
|
||||
if (const GrVkYcbcrConversionInfo* ycbcrInfo = this->getVkYcbcrConversionInfo()) {
|
||||
@ -208,7 +217,8 @@ bool GrBackendFormat::operator==(const GrBackendFormat& that) const {
|
||||
#endif
|
||||
break;
|
||||
case GrBackendApi::kMock:
|
||||
return fMockFormat == that.fMockFormat;
|
||||
return fMock.fColorType == that.fMock.fColorType &&
|
||||
fMock.fSRGBEncoded == that.fMock.fSRGBEncoded;
|
||||
default:
|
||||
SK_ABORT("Unknown GrBackend");
|
||||
}
|
||||
@ -299,7 +309,7 @@ GrBackendTexture::GrBackendTexture(int width,
|
||||
: fIsValid(true)
|
||||
, fWidth(width)
|
||||
, fHeight(height)
|
||||
, fConfig(mockInfo.fConfig)
|
||||
, fConfig(mockInfo.pixelConfig())
|
||||
, fMipMapped(mipMapped)
|
||||
, fBackend(GrBackendApi::kMock)
|
||||
, fMockInfo(mockInfo) {}
|
||||
@ -492,7 +502,7 @@ GrBackendFormat GrBackendTexture::getBackendFormat() const {
|
||||
}
|
||||
#endif
|
||||
case GrBackendApi::kMock:
|
||||
return GrBackendFormat::MakeMock(fMockInfo.fConfig);
|
||||
return fMockInfo.getBackendFormat();
|
||||
default:
|
||||
return GrBackendFormat();
|
||||
}
|
||||
@ -625,7 +635,7 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
|
||||
, fHeight(height)
|
||||
, fSampleCnt(SkTMax(1, sampleCnt))
|
||||
, fStencilBits(stencilBits)
|
||||
, fConfig(mockInfo.fConfig)
|
||||
, fConfig(mockInfo.pixelConfig())
|
||||
, fMockInfo(mockInfo) {}
|
||||
|
||||
GrBackendRenderTarget::~GrBackendRenderTarget() {
|
||||
@ -757,7 +767,7 @@ GrBackendFormat GrBackendRenderTarget::getBackendFormat() const {
|
||||
}
|
||||
#endif
|
||||
case GrBackendApi::kMock:
|
||||
return GrBackendFormat::MakeMock(fMockInfo.fConfig);
|
||||
return fMockInfo.getBackendFormat();
|
||||
default:
|
||||
return GrBackendFormat();
|
||||
}
|
||||
|
@ -37,49 +37,41 @@ public:
|
||||
}
|
||||
|
||||
bool isFormatSRGB(const GrBackendFormat& format) const override {
|
||||
if (!format.getMockFormat()) {
|
||||
if (!format.getMockSRGBEncoded()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return kSRGBA_8888_GrPixelConfig == *format.getMockFormat();
|
||||
return GrSRGBEncoded::kYes == *format.getMockSRGBEncoded();
|
||||
}
|
||||
|
||||
bool isFormatTexturable(GrColorType, const GrBackendFormat& format) const override {
|
||||
if (!format.getMockFormat()) {
|
||||
if (!format.getMockColorType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this->isConfigTexturable(*format.getMockFormat());
|
||||
// We are ignoring the srgb encoding here
|
||||
return fOptions.fConfigOptions[(int)*format.getMockColorType()].fTexturable;
|
||||
}
|
||||
|
||||
bool isConfigTexturable(GrPixelConfig config) const override {
|
||||
return fOptions.fConfigOptions[config].fTexturable;
|
||||
GrColorType ct = GrPixelConfigToColorType(config);
|
||||
|
||||
// We are ignoring the srgb encoding here
|
||||
return fOptions.fConfigOptions[(int)ct].fTexturable;
|
||||
}
|
||||
|
||||
bool isFormatCopyable(SkColorType, const GrBackendFormat& format) const override {
|
||||
if (!format.getMockFormat()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this->isConfigCopyable(*format.getMockFormat());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isConfigCopyable(GrPixelConfig config) const override {
|
||||
return false;
|
||||
}
|
||||
|
||||
int getRenderTargetSampleCount(int requestCount,
|
||||
SkColorType, const GrBackendFormat& format) const override {
|
||||
if (!format.getMockFormat()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return this->getRenderTargetSampleCount(requestCount, *format.getMockFormat());
|
||||
}
|
||||
|
||||
int getRenderTargetSampleCount(int requestCount, GrPixelConfig config) const override {
|
||||
int getRenderTargetSampleCount(int requestCount, GrColorType ct) const {
|
||||
requestCount = SkTMax(requestCount, 1);
|
||||
switch (fOptions.fConfigOptions[config].fRenderability) {
|
||||
|
||||
switch (fOptions.fConfigOptions[(int)ct].fRenderability) {
|
||||
case GrMockOptions::ConfigOptions::Renderability::kNo:
|
||||
return 0;
|
||||
case GrMockOptions::ConfigOptions::Renderability::kNonMSAA:
|
||||
@ -90,16 +82,25 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int maxRenderTargetSampleCount(SkColorType, const GrBackendFormat& format) const override {
|
||||
if (!format.getMockFormat()) {
|
||||
int getRenderTargetSampleCount(int requestCount,
|
||||
SkColorType, const GrBackendFormat& format) const override {
|
||||
if (!format.getMockColorType()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return this->maxRenderTargetSampleCount(*format.getMockFormat());
|
||||
// We are ignoring the srgb encoding here
|
||||
return this->getRenderTargetSampleCount(requestCount, *format.getMockColorType());
|
||||
}
|
||||
|
||||
int maxRenderTargetSampleCount(GrPixelConfig config) const override {
|
||||
switch (fOptions.fConfigOptions[config].fRenderability) {
|
||||
int getRenderTargetSampleCount(int requestCount, GrPixelConfig config) const override {
|
||||
GrColorType ct = GrPixelConfigToColorType(config);
|
||||
|
||||
// We are ignoring the srgb encoding here
|
||||
return this->getRenderTargetSampleCount(requestCount, ct);
|
||||
}
|
||||
|
||||
int maxRenderTargetSampleCount(GrColorType ct) const {
|
||||
switch (fOptions.fConfigOptions[(int)ct].fRenderability) {
|
||||
case GrMockOptions::ConfigOptions::Renderability::kNo:
|
||||
return 0;
|
||||
case GrMockOptions::ConfigOptions::Renderability::kNonMSAA:
|
||||
@ -110,6 +111,22 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int maxRenderTargetSampleCount(SkColorType, const GrBackendFormat& format) const override {
|
||||
if (!format.getMockColorType()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// We are ignoring the srgb encoding here
|
||||
return this->maxRenderTargetSampleCount(*format.getMockColorType());
|
||||
}
|
||||
|
||||
int maxRenderTargetSampleCount(GrPixelConfig config) const override {
|
||||
GrColorType ct = GrPixelConfigToColorType(config);
|
||||
|
||||
// We are ignoring the srgb encoding here
|
||||
return this->maxRenderTargetSampleCount(ct);
|
||||
}
|
||||
|
||||
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override {
|
||||
return SurfaceReadPixelsSupport::kSupported;
|
||||
}
|
||||
@ -125,29 +142,20 @@ public:
|
||||
}
|
||||
|
||||
GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat& format) const override {
|
||||
const GrPixelConfig* mockFormat = format.getMockFormat();
|
||||
if (!mockFormat) {
|
||||
if (!format.getMockColorType() || !format.getMockSRGBEncoded()) {
|
||||
return kUnknown_GrPixelConfig;
|
||||
}
|
||||
return *mockFormat;
|
||||
|
||||
return GrColorTypeToPixelConfig(*format.getMockColorType(),
|
||||
*format.getMockSRGBEncoded());
|
||||
}
|
||||
|
||||
GrBackendFormat getBackendFormatFromColorType(GrColorType ct,
|
||||
GrSRGBEncoded srgbEncoded) const override {
|
||||
GrPixelConfig config = GrColorTypeToPixelConfig(ct, srgbEncoded);
|
||||
if (config == kUnknown_GrPixelConfig) {
|
||||
return GrBackendFormat();
|
||||
}
|
||||
return GrBackendFormat::MakeMock(config);
|
||||
return GrBackendFormat::MakeMock(ct, srgbEncoded);
|
||||
}
|
||||
|
||||
GrBackendFormat getBackendFormatFromCompressionType(
|
||||
SkImage::CompressionType compressionType) const override {
|
||||
switch (compressionType) {
|
||||
case SkImage::kETC1_CompressionType:
|
||||
return GrBackendFormat::MakeMock(kRGB_ETC1_GrPixelConfig);
|
||||
}
|
||||
SK_ABORT("Invalid compression type");
|
||||
GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override {
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -171,125 +179,29 @@ private:
|
||||
|
||||
GrPixelConfig onGetConfigFromBackendFormat(const GrBackendFormat& format,
|
||||
GrColorType) const override {
|
||||
const GrPixelConfig* mockFormat = format.getMockFormat();
|
||||
if (!mockFormat) {
|
||||
if (!format.getMockColorType() || !format.getMockSRGBEncoded()) {
|
||||
return kUnknown_GrPixelConfig;
|
||||
}
|
||||
return *mockFormat;
|
||||
|
||||
return GrColorTypeToPixelConfig(*format.getMockColorType(),
|
||||
*format.getMockSRGBEncoded());
|
||||
|
||||
}
|
||||
|
||||
bool onAreColorTypeAndFormatCompatible(GrColorType ct,
|
||||
const GrBackendFormat& format) const override {
|
||||
const GrPixelConfig* mockFormat = format.getMockFormat();
|
||||
if (!mockFormat) {
|
||||
return kUnknown_GrPixelConfig;
|
||||
if (GrColorType::kUnknown == ct) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (ct) {
|
||||
case GrColorType::kUnknown:
|
||||
return false;
|
||||
case GrColorType::kAlpha_8:
|
||||
if (kAlpha_8_GrPixelConfig == *mockFormat ||
|
||||
kAlpha_8_as_Alpha_GrPixelConfig == *mockFormat ||
|
||||
kAlpha_8_as_Red_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kBGR_565:
|
||||
if (kRGB_565_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kABGR_4444:
|
||||
if (kRGBA_4444_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kRGBA_8888:
|
||||
if (kRGBA_8888_GrPixelConfig == *mockFormat ||
|
||||
kSRGBA_8888_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kRGB_888x:
|
||||
if (kRGB_888X_GrPixelConfig == *mockFormat ||
|
||||
kRGB_888_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kRG_88:
|
||||
if (kRG_88_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kBGRA_8888:
|
||||
if (kBGRA_8888_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kRGBA_1010102:
|
||||
if (kRGBA_1010102_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kGray_8:
|
||||
if (kGray_8_GrPixelConfig == *mockFormat ||
|
||||
kGray_8_as_Lum_GrPixelConfig == *mockFormat ||
|
||||
kGray_8_as_Red_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kAlpha_F16:
|
||||
if (kAlpha_half_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
case GrColorType::kRGBA_F16:
|
||||
if (kRGBA_half_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kRGBA_F16_Clamped:
|
||||
if (kRGBA_half_Clamped_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kRG_F32:
|
||||
if (kRG_float_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kRGBA_F32:
|
||||
if (kRGBA_float_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kR_16:
|
||||
if (kR_16_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kRG_1616:
|
||||
if (kRG_1616_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kRGBA_16161616:
|
||||
if (kRGBA_16161616_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GrColorType::kRG_F16:
|
||||
if (kRG_half_GrPixelConfig == *mockFormat) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
const GrColorType* mockColorType = format.getMockColorType();
|
||||
if (!mockColorType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return ct == *mockColorType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const int kMaxSampleCnt = 16;
|
||||
|
||||
GrMockOptions fOptions;
|
||||
|
@ -91,15 +91,17 @@ sk_sp<GrTexture> GrMockGpu::onCreateTexture(const GrSurfaceDesc& desc, SkBudgete
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrSRGBEncoded srgbEncoding;
|
||||
GrColorType ct = GrPixelConfigToColorTypeAndEncoding(desc.fConfig, &srgbEncoding);
|
||||
if (GrColorType::kUnknown == ct) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrMipMapsStatus mipMapsStatus = mipLevelCount > 1 ? GrMipMapsStatus::kValid
|
||||
: GrMipMapsStatus::kNotAllocated;
|
||||
GrMockTextureInfo texInfo;
|
||||
texInfo.fConfig = desc.fConfig;
|
||||
texInfo.fID = NextInternalTextureID();
|
||||
GrMockTextureInfo texInfo(ct, srgbEncoding, NextInternalTextureID());
|
||||
if (desc.fFlags & kRenderTarget_GrSurfaceFlag) {
|
||||
GrMockRenderTargetInfo rtInfo;
|
||||
rtInfo.fConfig = desc.fConfig;
|
||||
rtInfo.fID = NextInternalRenderTargetID();
|
||||
GrMockRenderTargetInfo rtInfo(ct, srgbEncoding, NextInternalRenderTargetID());
|
||||
return sk_sp<GrTexture>(new GrMockTextureRenderTarget(this, budgeted, desc, mipMapsStatus,
|
||||
texInfo, rtInfo));
|
||||
}
|
||||
@ -109,32 +111,19 @@ sk_sp<GrTexture> GrMockGpu::onCreateTexture(const GrSurfaceDesc& desc, SkBudgete
|
||||
sk_sp<GrTexture> GrMockGpu::onCreateCompressedTexture(int width, int height,
|
||||
SkImage::CompressionType compressionType,
|
||||
SkBudgeted budgeted, const void* data) {
|
||||
if (fMockOptions.fFailTextureAllocations) {
|
||||
return nullptr;
|
||||
}
|
||||
GrBackendFormat format = this->caps()->getBackendFormatFromCompressionType(compressionType);
|
||||
|
||||
GrMockTextureInfo texInfo;
|
||||
texInfo.fConfig = *format.getMockFormat();
|
||||
texInfo.fID = NextInternalTextureID();
|
||||
GrSurfaceDesc desc;
|
||||
desc.fConfig = texInfo.fConfig;
|
||||
desc.fWidth = width;
|
||||
desc.fHeight = height;
|
||||
return sk_sp<GrTexture>(
|
||||
new GrMockTexture(this, budgeted, desc, GrMipMapsStatus::kNotAllocated, texInfo));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sk_sp<GrTexture> GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex,
|
||||
GrWrapOwnership ownership,
|
||||
GrWrapCacheable wrapType, GrIOType ioType) {
|
||||
GrMockTextureInfo info;
|
||||
SkAssertResult(tex.getMockTextureInfo(&info));
|
||||
|
||||
GrSurfaceDesc desc;
|
||||
desc.fWidth = tex.width();
|
||||
desc.fHeight = tex.height();
|
||||
|
||||
GrMockTextureInfo info;
|
||||
SkAssertResult(tex.getMockTextureInfo(&info));
|
||||
desc.fConfig = info.fConfig;
|
||||
desc.fConfig = info.pixelConfig();
|
||||
|
||||
GrMipMapsStatus mipMapsStatus = tex.hasMipMaps() ? GrMipMapsStatus::kValid
|
||||
: GrMipMapsStatus::kNotAllocated;
|
||||
@ -146,36 +135,35 @@ sk_sp<GrTexture> GrMockGpu::onWrapRenderableBackendTexture(const GrBackendTextur
|
||||
int sampleCnt,
|
||||
GrWrapOwnership ownership,
|
||||
GrWrapCacheable cacheable) {
|
||||
GrMockTextureInfo texInfo;
|
||||
SkAssertResult(tex.getMockTextureInfo(&texInfo));
|
||||
|
||||
GrSurfaceDesc desc;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
desc.fWidth = tex.width();
|
||||
desc.fHeight = tex.height();
|
||||
|
||||
GrMockTextureInfo texInfo;
|
||||
SkAssertResult(tex.getMockTextureInfo(&texInfo));
|
||||
desc.fConfig = texInfo.fConfig;
|
||||
desc.fConfig = texInfo.pixelConfig();
|
||||
|
||||
GrMipMapsStatus mipMapsStatus =
|
||||
tex.hasMipMaps() ? GrMipMapsStatus::kValid : GrMipMapsStatus::kNotAllocated;
|
||||
|
||||
GrMockRenderTargetInfo rtInfo;
|
||||
rtInfo.fConfig = texInfo.fConfig;
|
||||
// The client gave us the texture ID but we supply the render target ID.
|
||||
rtInfo.fID = NextInternalRenderTargetID();
|
||||
GrMockRenderTargetInfo rtInfo(texInfo.fColorType, texInfo.fSRGBEncoded,
|
||||
NextInternalRenderTargetID());
|
||||
|
||||
return sk_sp<GrTexture>(
|
||||
new GrMockTextureRenderTarget(this, desc, mipMapsStatus, texInfo, rtInfo, cacheable));
|
||||
}
|
||||
|
||||
sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt) {
|
||||
GrMockRenderTargetInfo info;
|
||||
SkAssertResult(rt.getMockRenderTargetInfo(&info));
|
||||
|
||||
GrSurfaceDesc desc;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
desc.fWidth = rt.width();
|
||||
desc.fHeight = rt.height();
|
||||
|
||||
GrMockRenderTargetInfo info;
|
||||
SkAssertResult(rt.getMockRenderTargetInfo(&info));
|
||||
desc.fConfig = info.fConfig;
|
||||
desc.fConfig = info.pixelConfig();
|
||||
|
||||
return sk_sp<GrRenderTarget>(
|
||||
new GrMockRenderTarget(this, GrMockRenderTarget::kWrapped, desc, info));
|
||||
@ -183,20 +171,19 @@ sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRender
|
||||
|
||||
sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
|
||||
int sampleCnt) {
|
||||
GrMockTextureInfo texInfo;
|
||||
SkAssertResult(tex.getMockTextureInfo(&texInfo));
|
||||
|
||||
GrSurfaceDesc desc;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
desc.fWidth = tex.width();
|
||||
desc.fHeight = tex.height();
|
||||
|
||||
GrMockTextureInfo texInfo;
|
||||
SkAssertResult(tex.getMockTextureInfo(&texInfo));
|
||||
desc.fConfig = texInfo.fConfig;
|
||||
desc.fConfig = texInfo.pixelConfig();
|
||||
desc.fSampleCnt = sampleCnt;
|
||||
|
||||
GrMockRenderTargetInfo rtInfo;
|
||||
rtInfo.fConfig = texInfo.fConfig;
|
||||
// The client gave us the texture ID but we supply the render target ID.
|
||||
rtInfo.fID = NextInternalRenderTargetID();
|
||||
GrMockRenderTargetInfo rtInfo(texInfo.fColorType, texInfo.fSRGBEncoded,
|
||||
NextInternalRenderTargetID());
|
||||
|
||||
return sk_sp<GrRenderTarget>(
|
||||
new GrMockRenderTarget(this, GrMockRenderTarget::kWrapped, desc, rtInfo));
|
||||
@ -224,18 +211,20 @@ GrBackendTexture GrMockGpu::createBackendTexture(int w, int h,
|
||||
const SkColor4f* /* color */,
|
||||
GrProtected /* isProtected */) {
|
||||
|
||||
const GrPixelConfig* pixelConfig = format.getMockFormat();
|
||||
if (!pixelConfig) {
|
||||
if (!format.getMockColorType() || !format.getMockSRGBEncoded()) {
|
||||
return GrBackendTexture(); // invalid;
|
||||
}
|
||||
|
||||
GrPixelConfig config = GrColorTypeToPixelConfig(*format.getMockColorType(),
|
||||
*format.getMockSRGBEncoded());
|
||||
|
||||
if (!this->caps()->isConfigTexturable(config)) {
|
||||
return GrBackendTexture(); // invalid
|
||||
}
|
||||
|
||||
if (!this->caps()->isConfigTexturable(*pixelConfig)) {
|
||||
return GrBackendTexture(); // invalid
|
||||
}
|
||||
GrMockTextureInfo info(*format.getMockColorType(), *format.getMockSRGBEncoded(),
|
||||
NextExternalTextureID());
|
||||
|
||||
GrMockTextureInfo info;
|
||||
info.fConfig = *pixelConfig;
|
||||
info.fID = NextExternalTextureID();
|
||||
fOutstandingTestingOnlyTextureIDs.add(info.fID);
|
||||
return GrBackendTexture(w, h, mipMapped, info);
|
||||
}
|
||||
@ -263,14 +252,10 @@ bool GrMockGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const {
|
||||
|
||||
GrBackendRenderTarget GrMockGpu::createTestingOnlyBackendRenderTarget(int w, int h,
|
||||
GrColorType colorType) {
|
||||
auto config = GrColorTypeToPixelConfig(colorType, GrSRGBEncoded::kNo);
|
||||
if (kUnknown_GrPixelConfig == config) {
|
||||
return {};
|
||||
}
|
||||
GrMockRenderTargetInfo info = {config, NextExternalRenderTargetID()};
|
||||
GrMockRenderTargetInfo info(colorType, GrSRGBEncoded::kNo, NextExternalRenderTargetID());
|
||||
static constexpr int kSampleCnt = 1;
|
||||
static constexpr int kStencilBits = 8;
|
||||
return {w, h, kSampleCnt, kStencilBits, info};
|
||||
return GrBackendRenderTarget(w, h, kSampleCnt, kStencilBits, info);
|
||||
}
|
||||
|
||||
void GrMockGpu::deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) {}
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
}
|
||||
|
||||
GrBackendFormat backendFormat() const override {
|
||||
return GrBackendFormat::MakeMock(fInfo.fConfig);
|
||||
return fInfo.getBackendFormat();
|
||||
}
|
||||
|
||||
void textureParamsModified() override {}
|
||||
@ -109,7 +109,7 @@ public:
|
||||
}
|
||||
|
||||
GrBackendFormat backendFormat() const override {
|
||||
return GrBackendFormat::MakeMock(fInfo.fConfig);
|
||||
return fInfo.getBackendFormat();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
18
src/gpu/mock/GrMockTypes.cpp
Normal file
18
src/gpu/mock/GrMockTypes.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2019 Google LLC
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "include/gpu/mock/GrMockTypes.h"
|
||||
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
|
||||
GrBackendFormat GrMockRenderTargetInfo::getBackendFormat() const {
|
||||
return GrBackendFormat::MakeMock(fColorType, fSRGBEncoded);
|
||||
}
|
||||
|
||||
GrBackendFormat GrMockTextureInfo::getBackendFormat() const {
|
||||
return GrBackendFormat::MakeMock(fColorType, fSRGBEncoded);
|
||||
}
|
@ -143,12 +143,12 @@ public:
|
||||
mockOptions.fInstanceAttribSupport = true;
|
||||
mockOptions.fHalfFloatVertexAttributeSupport = true;
|
||||
mockOptions.fMapBufferFlags = GrCaps::kCanMap_MapFlag;
|
||||
mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fRenderability =
|
||||
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fRenderability =
|
||||
GrMockOptions::ConfigOptions::Renderability::kNonMSAA;
|
||||
mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fTexturable = true;
|
||||
mockOptions.fConfigOptions[kAlpha_8_GrPixelConfig].fRenderability =
|
||||
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fTexturable = true;
|
||||
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_8].fRenderability =
|
||||
GrMockOptions::ConfigOptions::Renderability::kNonMSAA;
|
||||
mockOptions.fConfigOptions[kAlpha_8_GrPixelConfig].fTexturable = true;
|
||||
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_8].fTexturable = true;
|
||||
mockOptions.fGeometryShaderSupport = true;
|
||||
mockOptions.fIntegerSupport = true;
|
||||
mockOptions.fFlatInterpolationSupport = true;
|
||||
|
@ -80,40 +80,6 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
|
||||
GrResourceProvider* resourceProvider = context->priv().resourceProvider();
|
||||
const GrCaps* caps = context->priv().caps();
|
||||
|
||||
GrPixelConfig configs[] = {
|
||||
kUnknown_GrPixelConfig,
|
||||
kAlpha_8_GrPixelConfig,
|
||||
kAlpha_8_as_Alpha_GrPixelConfig,
|
||||
kAlpha_8_as_Red_GrPixelConfig,
|
||||
kGray_8_GrPixelConfig,
|
||||
kGray_8_as_Lum_GrPixelConfig,
|
||||
kGray_8_as_Red_GrPixelConfig,
|
||||
kRGB_565_GrPixelConfig,
|
||||
kRGBA_4444_GrPixelConfig,
|
||||
kRGBA_8888_GrPixelConfig,
|
||||
kRGB_888_GrPixelConfig,
|
||||
kRGB_888X_GrPixelConfig,
|
||||
kRG_88_GrPixelConfig,
|
||||
kBGRA_8888_GrPixelConfig,
|
||||
kSRGBA_8888_GrPixelConfig,
|
||||
kRGBA_1010102_GrPixelConfig,
|
||||
kRGBA_float_GrPixelConfig,
|
||||
kRG_float_GrPixelConfig,
|
||||
kAlpha_half_GrPixelConfig,
|
||||
kAlpha_half_as_Red_GrPixelConfig,
|
||||
kRGBA_half_GrPixelConfig,
|
||||
kRGBA_half_Clamped_GrPixelConfig,
|
||||
kRGB_ETC1_GrPixelConfig,
|
||||
|
||||
kR_16_GrPixelConfig,
|
||||
kRG_1616_GrPixelConfig,
|
||||
|
||||
// Experimental (for Y416 and mutant P016/P010)
|
||||
kRGBA_16161616_GrPixelConfig,
|
||||
kRG_half_GrPixelConfig,
|
||||
};
|
||||
GR_STATIC_ASSERT(kGrPixelConfigCnt == SK_ARRAY_COUNT(configs));
|
||||
|
||||
auto createTexture = [](int width, int height, GrPixelConfig config, GrRenderable renderable,
|
||||
GrResourceProvider* rp) -> sk_sp<GrTexture> {
|
||||
if (GrPixelConfigIsCompressed(config)) {
|
||||
@ -150,7 +116,9 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
|
||||
}
|
||||
};
|
||||
|
||||
for (GrPixelConfig config : configs) {
|
||||
for (int c = 0; c <= kLast_GrPixelConfig; ++c) {
|
||||
GrPixelConfig config = static_cast<GrPixelConfig>(c);
|
||||
|
||||
for (GrSurfaceOrigin origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
|
||||
if (config == kUnknown_GrPixelConfig) {
|
||||
// It is not valid to be calling into GrProxyProvider with an unknown pixel config.
|
||||
|
@ -199,9 +199,9 @@ private:
|
||||
|
||||
DEF_GPUTEST(LazyProxyTest, reporter, /* options */) {
|
||||
GrMockOptions mockOptions;
|
||||
mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fRenderability =
|
||||
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fRenderability =
|
||||
GrMockOptions::ConfigOptions::Renderability::kNonMSAA;
|
||||
mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fTexturable = true;
|
||||
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fTexturable = true;
|
||||
sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
|
||||
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
|
||||
for (bool nullTexture : {false, true}) {
|
||||
|
@ -111,16 +111,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
|
||||
|
||||
for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
|
||||
for (auto widthHeight : { 100, 128, 1048576 }) {
|
||||
for (auto config : { kAlpha_8_GrPixelConfig, kRGB_565_GrPixelConfig,
|
||||
kRGBA_8888_GrPixelConfig, kRGBA_1010102_GrPixelConfig,
|
||||
kRGB_ETC1_GrPixelConfig }) {
|
||||
for (auto ct : { GrColorType::kAlpha_8, GrColorType::kBGR_565,
|
||||
GrColorType::kRGBA_8888, GrColorType::kRGBA_1010102 } ) {
|
||||
for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
|
||||
for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
|
||||
for (auto numSamples : {1, 4, 16, 128}) {
|
||||
// We don't have recycling support for compressed textures
|
||||
if (GrPixelConfigIsCompressed(config) && SkBackingFit::kApprox == fit) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto config = GrColorTypeToPixelConfig(ct, GrSRGBEncoded::kNo);
|
||||
SkASSERT(kUnknown_GrPixelConfig != config);
|
||||
|
||||
GrSurfaceDesc desc;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
@ -129,11 +127,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
|
||||
desc.fConfig = config;
|
||||
desc.fSampleCnt = numSamples;
|
||||
|
||||
GrSRGBEncoded srgbEncoded;
|
||||
GrColorType colorType =
|
||||
GrPixelConfigToColorTypeAndEncoding(config, &srgbEncoded);
|
||||
const GrBackendFormat format =
|
||||
caps.getBackendFormatFromColorType(colorType, srgbEncoded);
|
||||
caps.getBackendFormatFromColorType(ct, GrSRGBEncoded::kNo);
|
||||
if (!format.isValid()) {
|
||||
continue;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user