Rename GrContextFactory::ContextOptions to ContextOverrides

Also changes the behavior of these flags to only override their             
corresponding context options when set, and to leave them unchanged    
when not set.  

BUG=skia:

Change-Id: I09f6be09997594fa888d9045dd4901354ef3f880
Reviewed-on: https://skia-review.googlesource.com/8780
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
csmartdalton 2017-02-21 12:36:05 -07:00 committed by Skia Commit-Bot
parent e026511f4c
commit e812d496aa
13 changed files with 97 additions and 94 deletions

View File

@ -189,11 +189,11 @@ struct GPUTarget : public Target {
0; 0;
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
this->surface = SkSurface::MakeRenderTarget(gGrFactory->get(this->config.ctxType, this->surface = SkSurface::MakeRenderTarget(gGrFactory->get(this->config.ctxType,
this->config.ctxOptions), this->config.ctxOverrides),
SkBudgeted::kNo, info, SkBudgeted::kNo, info,
this->config.samples, &props); this->config.samples, &props);
this->context = gGrFactory->getContextInfo(this->config.ctxType, this->context = gGrFactory->getContextInfo(this->config.ctxType,
this->config.ctxOptions).testContext(); this->config.ctxOverrides).testContext();
if (!this->surface.get()) { if (!this->surface.get()) {
return false; return false;
} }
@ -392,10 +392,10 @@ static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag)
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#define kBogusContextType GrContextFactory::kNativeGL_ContextType #define kBogusContextType GrContextFactory::kNativeGL_ContextType
#define kBogusContextOptions GrContextFactory::ContextOptions::kNone #define kBogusContextOverrides GrContextFactory::ContextOverrides::kNone
#else #else
#define kBogusContextType 0 #define kBogusContextType 0
#define kBogusContextOptions 0 #define kBogusContextOverrides 0
#endif #endif
static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* configs) { static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* configs) {
@ -406,10 +406,10 @@ static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* c
return; return;
const auto ctxType = gpuConfig->getContextType(); const auto ctxType = gpuConfig->getContextType();
const auto ctxOptions = gpuConfig->getContextOptions(); const auto ctxOverrides = gpuConfig->getContextOverrides();
const auto sampleCount = gpuConfig->getSamples(); const auto sampleCount = gpuConfig->getSamples();
if (const GrContext* ctx = gGrFactory->get(ctxType, ctxOptions)) { if (const GrContext* ctx = gGrFactory->get(ctxType, ctxOverrides)) {
const auto maxSampleCount = ctx->caps()->maxSampleCount(); const auto maxSampleCount = ctx->caps()->maxSampleCount();
if (sampleCount > ctx->caps()->maxSampleCount()) { if (sampleCount > ctx->caps()->maxSampleCount()) {
SkDebugf("Configuration sample count %d exceeds maximum %d.\n", SkDebugf("Configuration sample count %d exceeds maximum %d.\n",
@ -429,7 +429,7 @@ static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* c
sk_ref_sp(gpuConfig->getColorSpace()), sk_ref_sp(gpuConfig->getColorSpace()),
sampleCount, sampleCount,
ctxType, ctxType,
ctxOptions, ctxOverrides,
gpuConfig->getUseDIText() gpuConfig->getUseDIText()
}; };
@ -442,7 +442,7 @@ static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* c
if (config->getTag().equals(#name)) { \ if (config->getTag().equals(#name)) { \
Config config = { \ Config config = { \
SkString(#name), Benchmark::backend, color, alpha, colorSpace, \ SkString(#name), Benchmark::backend, color, alpha, colorSpace, \
0, kBogusContextType, kBogusContextOptions, false \ 0, kBogusContextType, kBogusContextOverrides, false \
}; \ }; \
configs->push_back(config); \ configs->push_back(config); \
return; \ return; \
@ -1333,7 +1333,7 @@ int main(int argc, char** argv) {
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (FLAGS_gpuStats && Benchmark::kGPU_Backend == configs[i].backend) { if (FLAGS_gpuStats && Benchmark::kGPU_Backend == configs[i].backend) {
GrContext* context = gGrFactory->get(configs[i].ctxType, GrContext* context = gGrFactory->get(configs[i].ctxType,
configs[i].ctxOptions); configs[i].ctxOverrides);
context->printCacheStats(); context->printCacheStats();
context->printGpuStats(); context->printGpuStats();
} }

View File

@ -30,7 +30,7 @@ struct Config {
int samples; int samples;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
sk_gpu_test::GrContextFactory::ContextType ctxType; sk_gpu_test::GrContextFactory::ContextType ctxType;
sk_gpu_test::GrContextFactory::ContextOptions ctxOptions; sk_gpu_test::GrContextFactory::ContextOverrides ctxOverrides;
bool useDFText; bool useDFText;
#else #else
int bogusInt; int bogusInt;

View File

@ -843,14 +843,14 @@ static Sink* create_sink(const SkCommandLineConfig* config) {
if (gpu_supported()) { if (gpu_supported()) {
if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) { if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
GrContextFactory::ContextType contextType = gpuConfig->getContextType(); GrContextFactory::ContextType contextType = gpuConfig->getContextType();
GrContextFactory::ContextOptions contextOptions = gpuConfig->getContextOptions(); GrContextFactory::ContextOverrides contextOverrides = gpuConfig->getContextOverrides();
GrContextFactory testFactory; GrContextFactory testFactory;
if (!testFactory.get(contextType, contextOptions)) { if (!testFactory.get(contextType, contextOverrides)) {
info("WARNING: can not create GPU context for config '%s'. " info("WARNING: can not create GPU context for config '%s'. "
"GM tests will be skipped.\n", gpuConfig->getTag().c_str()); "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
return nullptr; return nullptr;
} }
return new GPUSink(contextType, contextOptions, gpuConfig->getSamples(), return new GPUSink(contextType, contextOverrides, gpuConfig->getSamples(),
gpuConfig->getUseDIText(), gpuConfig->getColorType(), gpuConfig->getUseDIText(), gpuConfig->getColorType(),
sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading); sk_ref_sp(gpuConfig->getColorSpace()), FLAGS_gpu_threading);
} }
@ -1462,7 +1462,8 @@ void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contex
continue; continue;
} }
} }
ContextInfo ctxInfo = factory->getContextInfo(contextType); ContextInfo ctxInfo = factory->getContextInfo(contextType,
GrContextFactory::ContextOverrides::kDisableNVPR);
if (contextTypeFilter && !(*contextTypeFilter)(contextType)) { if (contextTypeFilter && !(*contextTypeFilter)(contextType)) {
continue; continue;
} }
@ -1471,7 +1472,7 @@ void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contex
(*test)(reporter, ctxInfo); (*test)(reporter, ctxInfo);
} }
ctxInfo = factory->getContextInfo(contextType, ctxInfo = factory->getContextInfo(contextType,
GrContextFactory::ContextOptions::kEnableNVPR); GrContextFactory::ContextOverrides::kRequireNVPRSupport);
if (ctxInfo.grContext()) { if (ctxInfo.grContext()) {
(*test)(reporter, ctxInfo); (*test)(reporter, ctxInfo);
} }

View File

@ -31,13 +31,13 @@ static const bool kGPUDisabled = false;
static inline sk_sp<SkSurface> NewGpuSurface( static inline sk_sp<SkSurface> NewGpuSurface(
sk_gpu_test::GrContextFactory* grFactory, sk_gpu_test::GrContextFactory* grFactory,
sk_gpu_test::GrContextFactory::ContextType type, sk_gpu_test::GrContextFactory::ContextType type,
sk_gpu_test::GrContextFactory::ContextOptions options, sk_gpu_test::GrContextFactory::ContextOverrides overrides,
SkImageInfo info, SkImageInfo info,
int samples, int samples,
bool useDIText) { bool useDIText) {
uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0; uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
return SkSurface::MakeRenderTarget(grFactory->get(type, options), SkBudgeted::kNo, return SkSurface::MakeRenderTarget(grFactory->get(type, overrides), SkBudgeted::kNo,
info, samples, &props); info, samples, &props);
} }
@ -63,7 +63,7 @@ public:
namespace sk_gpu_test { namespace sk_gpu_test {
class GrContextFactory { class GrContextFactory {
public: public:
GrContextFactory() {}; GrContextFactory() {}
explicit GrContextFactory(const GrContextOptions&) {} explicit GrContextFactory(const GrContextOptions&) {}
typedef int ContextType; typedef int ContextType;
@ -80,10 +80,7 @@ public:
kNullGL_ContextType = 0, kNullGL_ContextType = 0,
kVulkan_ContextType = 0; kVulkan_ContextType = 0;
static const int kContextTypeCnt = 1; static const int kContextTypeCnt = 1;
enum ContextOptions { enum class ContextOverrides {};
kNone_ContextOptions = 0,
kEnableNVPR_ContextOptions = 0x1,
};
void destroyContexts() {} void destroyContexts() {}
void abandonContexts() {} void abandonContexts() {}
@ -98,7 +95,7 @@ static const bool kGPUDisabled = true;
static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*, static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*,
sk_gpu_test::GrContextFactory::ContextType, sk_gpu_test::GrContextFactory::ContextType,
sk_gpu_test::GrContextFactory::ContextOptions, sk_gpu_test::GrContextFactory::ContextOverrides,
SkImageInfo, SkImageInfo,
int, int,
bool) { bool) {

View File

@ -1223,14 +1223,14 @@ Error NullSink::draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const {
DEFINE_bool(gpuStats, false, "Append GPU stats to the log for each GPU task?"); DEFINE_bool(gpuStats, false, "Append GPU stats to the log for each GPU task?");
GPUSink::GPUSink(GrContextFactory::ContextType ct, GPUSink::GPUSink(GrContextFactory::ContextType ct,
GrContextFactory::ContextOptions options, GrContextFactory::ContextOverrides overrides,
int samples, int samples,
bool diText, bool diText,
SkColorType colorType, SkColorType colorType,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
bool threaded) bool threaded)
: fContextType(ct) : fContextType(ct)
, fContextOptions(options) , fContextOverrides(overrides)
, fSampleCount(samples) , fSampleCount(samples)
, fUseDIText(diText) , fUseDIText(diText)
, fColorType(colorType) , fColorType(colorType)
@ -1257,7 +1257,7 @@ Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) co
SkImageInfo::Make(size.width(), size.height(), fColorType, SkImageInfo::Make(size.width(), size.height(), fColorType,
kPremul_SkAlphaType, fColorSpace); kPremul_SkAlphaType, fColorSpace);
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
GrContext* context = factory.getContextInfo(fContextType, fContextOptions).grContext(); GrContext* context = factory.getContextInfo(fContextType, fContextOverrides).grContext();
const int maxDimension = context->caps()->maxTextureSize(); const int maxDimension = context->caps()->maxTextureSize();
if (maxDimension < SkTMax(size.width(), size.height())) { if (maxDimension < SkTMax(size.width(), size.height())) {
return Error::Nonfatal("Src too large to create a texture.\n"); return Error::Nonfatal("Src too large to create a texture.\n");
@ -1265,7 +1265,7 @@ Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) co
#endif #endif
auto surface( auto surface(
NewGpuSurface(&factory, fContextType, fContextOptions, info, fSampleCount, fUseDIText)); NewGpuSurface(&factory, fContextType, fContextOverrides, info, fSampleCount, fUseDIText));
if (!surface) { if (!surface) {
return "Could not create a surface."; return "Could not create a surface.";
} }

View File

@ -303,7 +303,7 @@ public:
class GPUSink : public Sink { class GPUSink : public Sink {
public: public:
GPUSink(sk_gpu_test::GrContextFactory::ContextType, GPUSink(sk_gpu_test::GrContextFactory::ContextType,
sk_gpu_test::GrContextFactory::ContextOptions, sk_gpu_test::GrContextFactory::ContextOverrides,
int samples, bool diText, SkColorType colorType, sk_sp<SkColorSpace> colorSpace, int samples, bool diText, SkColorType colorType, sk_sp<SkColorSpace> colorSpace,
bool threaded); bool threaded);
@ -312,13 +312,13 @@ public:
const char* fileExtension() const override { return "png"; } const char* fileExtension() const override { return "png"; }
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect }; } SinkFlags flags() const override { return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect }; }
private: private:
sk_gpu_test::GrContextFactory::ContextType fContextType; sk_gpu_test::GrContextFactory::ContextType fContextType;
sk_gpu_test::GrContextFactory::ContextOptions fContextOptions; sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides;
int fSampleCount; int fSampleCount;
bool fUseDIText; bool fUseDIText;
SkColorType fColorType; SkColorType fColorType;
sk_sp<SkColorSpace> fColorSpace; sk_sp<SkColorSpace> fColorSpace;
bool fThreaded; bool fThreaded;
}; };
class PDFSink : public Sink { class PDFSink : public Sink {

View File

@ -23,7 +23,7 @@ DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter,
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
GrContext* context = testFactory.get(ctxType, GrContext* context = testFactory.get(ctxType,
GrContextFactory::ContextOptions::kEnableNVPR); GrContextFactory::ContextOverrides::kRequireNVPRSupport);
if (!context) { if (!context) {
continue; continue;
} }
@ -33,13 +33,14 @@ DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter,
} }
} }
DEF_GPUTEST(GrContextFactory_NoPathRenderingUnlessNVPRRequested, reporter, /*factory*/) { DEF_GPUTEST(GrContextFactory_NoPathRenderingIfNVPRDisabled, reporter, /*factory*/) {
// Test that if NVPR is not requested, the context never has path rendering support. // Test that if NVPR is explicitly disabled, the context has no path rendering support.
GrContextFactory testFactory; GrContextFactory testFactory;
for (int i = 0; i <= GrContextFactory::kLastContextType; ++i) { for (int i = 0; i <= GrContextFactory::kLastContextType; ++i) {
GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType)i; GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType)i;
GrContext* context = testFactory.get(ctxType); GrContext* context =
testFactory.get(ctxType, GrContextFactory::ContextOverrides::kDisableNVPR);
if (context) { if (context) {
REPORTER_ASSERT( REPORTER_ASSERT(
reporter, reporter,
@ -57,7 +58,7 @@ DEF_GPUTEST(GrContextFactory_RequiredSRGBSupport, reporter, /*factory*/) {
for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
GrContext* context = GrContext* context =
testFactory.get(ctxType, GrContextFactory::ContextOptions::kRequireSRGBSupport); testFactory.get(ctxType, GrContextFactory::ContextOverrides::kRequireSRGBSupport);
if (context) { if (context) {
REPORTER_ASSERT(reporter, context->caps()->srgbSupport()); REPORTER_ASSERT(reporter, context->caps()->srgbSupport());

View File

@ -169,30 +169,31 @@ SkCommandLineConfigGpu::SkCommandLineConfigGpu(
sk_sp<SkColorSpace> colorSpace) sk_sp<SkColorSpace> colorSpace)
: SkCommandLineConfig(tag, SkString("gpu"), viaParts) : SkCommandLineConfig(tag, SkString("gpu"), viaParts)
, fContextType(contextType) , fContextType(contextType)
, fContextOptions(ContextOptions::kNone) , fContextOverrides(ContextOverrides::kNone)
, fUseDIText(useDIText) , fUseDIText(useDIText)
, fSamples(samples) , fSamples(samples)
, fColorType(colorType) , fColorType(colorType)
, fColorSpace(std::move(colorSpace)) { , fColorSpace(std::move(colorSpace)) {
if (useNVPR) { if (useNVPR) {
fContextOptions |= ContextOptions::kEnableNVPR; fContextOverrides |= ContextOverrides::kRequireNVPRSupport;
} else if (!useInstanced) {
// We don't disable NVPR for instanced configs. Otherwise the caps wouldn't use mixed
// samples and we couldn't test the mixed samples backend for simple shapes.
fContextOverrides |= ContextOverrides::kDisableNVPR;
} }
if (useInstanced) { if (useInstanced) {
fContextOptions |= ContextOptions::kUseInstanced; fContextOverrides |= ContextOverrides::kUseInstanced;
} }
// Subtle logic: If the config has a color space attached, we're going to be rendering to sRGB, // Subtle logic: If the config has a color space attached, we're going to be rendering to sRGB,
// so we need that capability. In addition, to get the widest test coverage, we DO NOT require // so we need that capability. In addition, to get the widest test coverage, we DO NOT require
// that we can disable sRGB decode. (That's for rendering sRGB sources to legacy surfaces). // that we can disable sRGB decode. (That's for rendering sRGB sources to legacy surfaces).
// //
// If the config doesn't have a color space attached, we're going to be rendering in legacy // If the config doesn't have a color space attached, we're going to be rendering in legacy
// mode. In that case, we can't allow a context to be created that has sRGB support without // mode. In that case, we don't require sRGB capability and we defer to the client to decide on
// the ability to disable sRGB decode. Otherwise, all of our sRGB source resources will be // sRGB decode control.
// treated as sRGB textures, but we will be unable to prevent the decode, causing them to be
// too dark.
if (fColorSpace) { if (fColorSpace) {
fContextOptions |= ContextOptions::kRequireSRGBSupport; fContextOverrides |= ContextOverrides::kRequireSRGBSupport;
} else { fContextOverrides |= ContextOverrides::kAllowSRGBWithoutDecodeControl;
fContextOptions |= ContextOptions::kRequireSRGBDecodeDisableSupport;
} }
} }
static bool parse_option_int(const SkString& value, int* outInt) { static bool parse_option_int(const SkString& value, int* outInt) {

View File

@ -51,15 +51,19 @@ class SkCommandLineConfig {
class SkCommandLineConfigGpu : public SkCommandLineConfig { class SkCommandLineConfigGpu : public SkCommandLineConfig {
public: public:
typedef sk_gpu_test::GrContextFactory::ContextType ContextType; typedef sk_gpu_test::GrContextFactory::ContextType ContextType;
typedef sk_gpu_test::GrContextFactory::ContextOptions ContextOptions; typedef sk_gpu_test::GrContextFactory::ContextOverrides ContextOverrides;
SkCommandLineConfigGpu(const SkString& tag, const SkTArray<SkString>& viaParts, SkCommandLineConfigGpu(const SkString& tag, const SkTArray<SkString>& viaParts,
ContextType contextType, bool useNVPR, bool useInstanced, bool useDIText, ContextType contextType, bool useNVPR, bool useInstanced, bool useDIText,
int samples, SkColorType colorType, sk_sp<SkColorSpace> colorSpace); int samples, SkColorType colorType, sk_sp<SkColorSpace> colorSpace);
const SkCommandLineConfigGpu* asConfigGpu() const override { return this; } const SkCommandLineConfigGpu* asConfigGpu() const override { return this; }
ContextType getContextType() const { return fContextType; } ContextType getContextType() const { return fContextType; }
ContextOptions getContextOptions() const { return fContextOptions; } ContextOverrides getContextOverrides() const { return fContextOverrides; }
bool getUseNVPR() const { return fContextOptions & ContextOptions::kEnableNVPR; } bool getUseNVPR() const {
bool getUseInstanced() const { return fContextOptions & ContextOptions::kUseInstanced; } SkASSERT(!(fContextOverrides & ContextOverrides::kRequireNVPRSupport) ||
!(fContextOverrides & ContextOverrides::kDisableNVPR));
return fContextOverrides & ContextOverrides::kRequireNVPRSupport;
}
bool getUseInstanced() const { return fContextOverrides & ContextOverrides::kUseInstanced; }
bool getUseDIText() const { return fUseDIText; } bool getUseDIText() const { return fUseDIText; }
int getSamples() const { return fSamples; } int getSamples() const { return fSamples; }
SkColorType getColorType() const { return fColorType; } SkColorType getColorType() const { return fColorType; }
@ -67,7 +71,7 @@ class SkCommandLineConfigGpu : public SkCommandLineConfig {
private: private:
ContextType fContextType; ContextType fContextType;
ContextOptions fContextOptions; ContextOverrides fContextOverrides;
bool fUseDIText; bool fUseDIText;
int fSamples; int fSamples;
SkColorType fColorType; SkColorType fColorType;

View File

@ -43,8 +43,6 @@ GrContextFactory::GrContextFactory() { }
GrContextFactory::GrContextFactory(const GrContextOptions& opts) GrContextFactory::GrContextFactory(const GrContextOptions& opts)
: fGlobalOptions(opts) { : fGlobalOptions(opts) {
// In this factory, instanced rendering is specified with ContextOptions::kUseInstanced.
SkASSERT(!fGlobalOptions.fEnableInstancedRendering);
} }
GrContextFactory::~GrContextFactory() { GrContextFactory::~GrContextFactory() {
@ -105,11 +103,11 @@ const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType =
GrContextFactory::kGLES_ContextType; GrContextFactory::kGLES_ContextType;
#endif #endif
ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions options) { ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOverrides overrides) {
for (int i = 0; i < fContexts.count(); ++i) { for (int i = 0; i < fContexts.count(); ++i) {
Context& context = fContexts[i]; Context& context = fContexts[i];
if (context.fType == type && if (context.fType == type &&
context.fOptions == options && context.fOverrides == overrides &&
!context.fAbandoned) { !context.fAbandoned) {
context.fTestContext->makeCurrent(); context.fTestContext->makeCurrent();
return ContextInfo(context.fBackend, context.fTestContext, context.fGrContext); return ContextInfo(context.fBackend, context.fTestContext, context.fGrContext);
@ -156,7 +154,7 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op
break; break;
#endif #endif
case kNullGL_ContextType: case kNullGL_ContextType:
glCtx = CreateNullGLTestContext(ContextOptions::kEnableNVPR & options); glCtx = CreateNullGLTestContext(ContextOverrides::kRequireNVPRSupport & overrides);
break; break;
case kDebugGL_ContextType: case kDebugGL_ContextType:
glCtx = CreateDebugGLTestContext(); glCtx = CreateDebugGLTestContext();
@ -169,9 +167,7 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op
} }
testCtx.reset(glCtx); testCtx.reset(glCtx);
glInterface.reset(SkRef(glCtx->gl())); glInterface.reset(SkRef(glCtx->gl()));
// Block NVPR from non-NVPR types. We don't block NVPR from contexts that will use if (ContextOverrides::kDisableNVPR & overrides) {
// instanced rendering because that would prevent us from testing mixed samples.
if (!((ContextOptions::kEnableNVPR | ContextOptions::kUseInstanced) & options)) {
glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface.get())); glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface.get()));
if (!glInterface) { if (!glInterface) {
return ContextInfo(); return ContextInfo();
@ -183,7 +179,7 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op
#ifdef SK_VULKAN #ifdef SK_VULKAN
case kVulkan_GrBackend: case kVulkan_GrBackend:
SkASSERT(kVulkan_ContextType == type); SkASSERT(kVulkan_ContextType == type);
if (ContextOptions::kEnableNVPR & options) { if (ContextOverrides::kRequireNVPRSupport & overrides) {
return ContextInfo(); return ContextInfo();
} }
testCtx.reset(CreatePlatformVkTestContext()); testCtx.reset(CreatePlatformVkTestContext());
@ -209,26 +205,27 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op
testCtx->makeCurrent(); testCtx->makeCurrent();
SkASSERT(testCtx && testCtx->backend() == backend); SkASSERT(testCtx && testCtx->backend() == backend);
GrContextOptions grOptions = fGlobalOptions; GrContextOptions grOptions = fGlobalOptions;
if (ContextOptions::kUseInstanced & options) { if (ContextOverrides::kUseInstanced & overrides) {
grOptions.fEnableInstancedRendering = true; grOptions.fEnableInstancedRendering = true;
} }
grOptions.fRequireDecodeDisableForSRGB = if (ContextOverrides::kAllowSRGBWithoutDecodeControl & overrides) {
SkToBool(ContextOptions::kRequireSRGBDecodeDisableSupport & options); grOptions.fRequireDecodeDisableForSRGB = false;
}
grCtx.reset(GrContext::Create(backend, backendContext, grOptions)); grCtx.reset(GrContext::Create(backend, backendContext, grOptions));
if (!grCtx.get()) { if (!grCtx.get()) {
return ContextInfo(); return ContextInfo();
} }
if (ContextOptions::kEnableNVPR & options) { if (ContextOverrides::kRequireNVPRSupport & overrides) {
if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) {
return ContextInfo(); return ContextInfo();
} }
} }
if (ContextOptions::kUseInstanced & options) { if (ContextOverrides::kUseInstanced & overrides) {
if (GrCaps::InstancedSupport::kNone == grCtx->caps()->instancedSupport()) { if (GrCaps::InstancedSupport::kNone == grCtx->caps()->instancedSupport()) {
return ContextInfo(); return ContextInfo();
} }
} }
if (ContextOptions::kRequireSRGBSupport & options) { if (ContextOverrides::kRequireSRGBSupport & overrides) {
if (!grCtx->caps()->srgbSupport()) { if (!grCtx->caps()->srgbSupport()) {
return ContextInfo(); return ContextInfo();
} }
@ -239,7 +236,7 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op
context.fTestContext = testCtx.release(); context.fTestContext = testCtx.release();
context.fGrContext = SkRef(grCtx.get()); context.fGrContext = SkRef(grCtx.get());
context.fType = type; context.fType = type;
context.fOptions = options; context.fOverrides = overrides;
context.fAbandoned = false; context.fAbandoned = false;
return ContextInfo(context.fBackend, context.fTestContext, context.fGrContext); return ContextInfo(context.fBackend, context.fTestContext, context.fGrContext);
} }

View File

@ -89,15 +89,17 @@ public:
static const int kContextTypeCnt = kLastContextType + 1; static const int kContextTypeCnt = kLastContextType + 1;
/** /**
* Options for GL context creation. For historical and testing reasons the options will default * Overrides for the initial GrContextOptions provided at construction time, and required
* to not using GL_NV_path_rendering extension even when the driver supports it. * features that will cause context creation to fail if not present.
*/ */
enum class ContextOptions { enum class ContextOverrides {
kNone = 0x0, kNone = 0x0,
kEnableNVPR = 0x1, kDisableNVPR = 0x1,
kUseInstanced = 0x2, kUseInstanced = 0x2,
kRequireSRGBSupport = 0x4, kAllowSRGBWithoutDecodeControl = 0x4,
kRequireSRGBDecodeDisableSupport = 0x8,
kRequireNVPRSupport = 0x8,
kRequireSRGBSupport = 0x10
}; };
static ContextType NativeContextTypeForBackend(GrBackend backend) { static ContextType NativeContextTypeForBackend(GrBackend backend) {
@ -144,23 +146,23 @@ public:
* Get a context initialized with a type of GL context. It also makes the GL context current. * Get a context initialized with a type of GL context. It also makes the GL context current.
*/ */
ContextInfo getContextInfo(ContextType type, ContextInfo getContextInfo(ContextType type,
ContextOptions options = ContextOptions::kNone); ContextOverrides overrides = ContextOverrides::kNone);
/** /**
* Get a GrContext initialized with a type of GL context. It also makes the GL context current. * Get a GrContext initialized with a type of GL context. It also makes the GL context current.
*/ */
GrContext* get(ContextType type, ContextOptions options = ContextOptions::kNone) { GrContext* get(ContextType type, ContextOverrides overrides = ContextOverrides::kNone) {
return this->getContextInfo(type, options).grContext(); return this->getContextInfo(type, overrides).grContext();
} }
const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; }
private: private:
struct Context { struct Context {
ContextType fType; ContextType fType;
ContextOptions fOptions; ContextOverrides fOverrides;
GrBackend fBackend; GrBackend fBackend;
TestContext* fTestContext; TestContext* fTestContext;
GrContext* fGrContext; GrContext* fGrContext;
bool fAbandoned; bool fAbandoned;
}; };
SkTArray<Context, true> fContexts; SkTArray<Context, true> fContexts;
std::unique_ptr<GLTestContext> fSentinelGLContext; std::unique_ptr<GLTestContext> fSentinelGLContext;
@ -168,6 +170,6 @@ private:
}; };
} // namespace sk_gpu_test } // namespace sk_gpu_test
GR_MAKE_BITFIELD_CLASS_OPS(sk_gpu_test::GrContextFactory::ContextOptions); GR_MAKE_BITFIELD_CLASS_OPS(sk_gpu_test::GrContextFactory::ContextOverrides);
#endif #endif

View File

@ -74,10 +74,10 @@ SkCanvas* Request::getCanvas() {
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
GrContextFactory* factory = fContextFactory; GrContextFactory* factory = fContextFactory;
GLTestContext* gl = factory->getContextInfo(GrContextFactory::kNativeGL_ContextType, GLTestContext* gl = factory->getContextInfo(GrContextFactory::kNativeGL_ContextType,
GrContextFactory::ContextOptions::kNone).glContext(); GrContextFactory::ContextOverrides::kNone).glContext();
if (!gl) { if (!gl) {
gl = factory->getContextInfo(GrContextFactory::kMESA_ContextType, gl = factory->getContextInfo(GrContextFactory::kMESA_ContextType,
GrContextFactory::ContextOptions::kNone).glContext(); GrContextFactory::ContextOverrides::kNone).glContext();
} }
if (gl) { if (gl) {
gl->makeCurrent(); gl->makeCurrent();
@ -127,10 +127,10 @@ sk_sp<SkData> Request::writeOutSkp() {
GrContext* Request::getContext() { GrContext* Request::getContext() {
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
GrContext* result = fContextFactory->get(GrContextFactory::kNativeGL_ContextType, GrContext* result = fContextFactory->get(GrContextFactory::kNativeGL_ContextType,
GrContextFactory::ContextOptions::kNone); GrContextFactory::ContextOverrides::kNone);
if (!result) { if (!result) {
result = fContextFactory->get(GrContextFactory::kMESA_ContextType, result = fContextFactory->get(GrContextFactory::kMESA_ContextType,
GrContextFactory::ContextOptions::kNone); GrContextFactory::ContextOverrides::kNone);
} }
return result; return result;
#else #else

View File

@ -273,7 +273,7 @@ int main(int argc, char** argv) {
// Create a context. // Create a context.
sk_gpu_test::GrContextFactory factory; sk_gpu_test::GrContextFactory factory;
sk_gpu_test::ContextInfo ctxInfo = sk_gpu_test::ContextInfo ctxInfo =
factory.getContextInfo(config->getContextType(), config->getContextOptions()); factory.getContextInfo(config->getContextType(), config->getContextOverrides());
GrContext* ctx = ctxInfo.grContext(); GrContext* ctx = ctxInfo.grContext();
if (!ctx) { if (!ctx) {
exitf(ExitErr::kUnavailable, "failed to create context for config %s", exitf(ExitErr::kUnavailable, "failed to create context for config %s",