diff options
author | csmartdalton <csmartdalton@google.com> | 2017-02-21 12:36:05 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-21 21:45:45 +0000 |
commit | e812d496aaa5e5e9f2117de8f442c297c9cb1367 (patch) | |
tree | 7342c7c6e048e3a226e162d7d1bcbf6ffbcddc55 /tools | |
parent | e026511f4c4b90bfe842f89966d088b663fc8c13 (diff) |
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>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/flags/SkCommonFlagsConfig.cpp | 21 | ||||
-rw-r--r-- | tools/flags/SkCommonFlagsConfig.h | 14 | ||||
-rw-r--r-- | tools/gpu/GrContextFactory.cpp | 29 | ||||
-rw-r--r-- | tools/gpu/GrContextFactory.h | 38 | ||||
-rw-r--r-- | tools/skiaserve/Request.cpp | 8 | ||||
-rw-r--r-- | tools/skpbench/skpbench.cpp | 2 |
6 files changed, 58 insertions, 54 deletions
diff --git a/tools/flags/SkCommonFlagsConfig.cpp b/tools/flags/SkCommonFlagsConfig.cpp index 65ba372d7c..3e5e9b9fff 100644 --- a/tools/flags/SkCommonFlagsConfig.cpp +++ b/tools/flags/SkCommonFlagsConfig.cpp @@ -169,30 +169,31 @@ SkCommandLineConfigGpu::SkCommandLineConfigGpu( sk_sp<SkColorSpace> colorSpace) : SkCommandLineConfig(tag, SkString("gpu"), viaParts) , fContextType(contextType) - , fContextOptions(ContextOptions::kNone) + , fContextOverrides(ContextOverrides::kNone) , fUseDIText(useDIText) , fSamples(samples) , fColorType(colorType) , fColorSpace(std::move(colorSpace)) { 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) { - fContextOptions |= ContextOptions::kUseInstanced; + fContextOverrides |= ContextOverrides::kUseInstanced; } // 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 // 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 - // mode. In that case, we can't allow a context to be created that has sRGB support without - // the ability to disable sRGB decode. Otherwise, all of our sRGB source resources will be - // treated as sRGB textures, but we will be unable to prevent the decode, causing them to be - // too dark. + // mode. In that case, we don't require sRGB capability and we defer to the client to decide on + // sRGB decode control. if (fColorSpace) { - fContextOptions |= ContextOptions::kRequireSRGBSupport; - } else { - fContextOptions |= ContextOptions::kRequireSRGBDecodeDisableSupport; + fContextOverrides |= ContextOverrides::kRequireSRGBSupport; + fContextOverrides |= ContextOverrides::kAllowSRGBWithoutDecodeControl; } } static bool parse_option_int(const SkString& value, int* outInt) { diff --git a/tools/flags/SkCommonFlagsConfig.h b/tools/flags/SkCommonFlagsConfig.h index 2b80397a2a..7336fa7971 100644 --- a/tools/flags/SkCommonFlagsConfig.h +++ b/tools/flags/SkCommonFlagsConfig.h @@ -51,15 +51,19 @@ class SkCommandLineConfig { class SkCommandLineConfigGpu : public SkCommandLineConfig { public: 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, ContextType contextType, bool useNVPR, bool useInstanced, bool useDIText, int samples, SkColorType colorType, sk_sp<SkColorSpace> colorSpace); const SkCommandLineConfigGpu* asConfigGpu() const override { return this; } ContextType getContextType() const { return fContextType; } - ContextOptions getContextOptions() const { return fContextOptions; } - bool getUseNVPR() const { return fContextOptions & ContextOptions::kEnableNVPR; } - bool getUseInstanced() const { return fContextOptions & ContextOptions::kUseInstanced; } + ContextOverrides getContextOverrides() const { return fContextOverrides; } + bool getUseNVPR() const { + SkASSERT(!(fContextOverrides & ContextOverrides::kRequireNVPRSupport) || + !(fContextOverrides & ContextOverrides::kDisableNVPR)); + return fContextOverrides & ContextOverrides::kRequireNVPRSupport; + } + bool getUseInstanced() const { return fContextOverrides & ContextOverrides::kUseInstanced; } bool getUseDIText() const { return fUseDIText; } int getSamples() const { return fSamples; } SkColorType getColorType() const { return fColorType; } @@ -67,7 +71,7 @@ class SkCommandLineConfigGpu : public SkCommandLineConfig { private: ContextType fContextType; - ContextOptions fContextOptions; + ContextOverrides fContextOverrides; bool fUseDIText; int fSamples; SkColorType fColorType; diff --git a/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp index bd745bcfcd..401189a6a3 100644 --- a/tools/gpu/GrContextFactory.cpp +++ b/tools/gpu/GrContextFactory.cpp @@ -43,8 +43,6 @@ GrContextFactory::GrContextFactory() { } GrContextFactory::GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opts) { - // In this factory, instanced rendering is specified with ContextOptions::kUseInstanced. - SkASSERT(!fGlobalOptions.fEnableInstancedRendering); } GrContextFactory::~GrContextFactory() { @@ -105,11 +103,11 @@ const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType = GrContextFactory::kGLES_ContextType; #endif -ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions options) { +ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOverrides overrides) { for (int i = 0; i < fContexts.count(); ++i) { Context& context = fContexts[i]; if (context.fType == type && - context.fOptions == options && + context.fOverrides == overrides && !context.fAbandoned) { context.fTestContext->makeCurrent(); return ContextInfo(context.fBackend, context.fTestContext, context.fGrContext); @@ -156,7 +154,7 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op break; #endif case kNullGL_ContextType: - glCtx = CreateNullGLTestContext(ContextOptions::kEnableNVPR & options); + glCtx = CreateNullGLTestContext(ContextOverrides::kRequireNVPRSupport & overrides); break; case kDebugGL_ContextType: glCtx = CreateDebugGLTestContext(); @@ -169,9 +167,7 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op } testCtx.reset(glCtx); glInterface.reset(SkRef(glCtx->gl())); - // Block NVPR from non-NVPR types. We don't block NVPR from contexts that will use - // instanced rendering because that would prevent us from testing mixed samples. - if (!((ContextOptions::kEnableNVPR | ContextOptions::kUseInstanced) & options)) { + if (ContextOverrides::kDisableNVPR & overrides) { glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface.get())); if (!glInterface) { return ContextInfo(); @@ -183,7 +179,7 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op #ifdef SK_VULKAN case kVulkan_GrBackend: SkASSERT(kVulkan_ContextType == type); - if (ContextOptions::kEnableNVPR & options) { + if (ContextOverrides::kRequireNVPRSupport & overrides) { return ContextInfo(); } testCtx.reset(CreatePlatformVkTestContext()); @@ -209,26 +205,27 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op testCtx->makeCurrent(); SkASSERT(testCtx && testCtx->backend() == backend); GrContextOptions grOptions = fGlobalOptions; - if (ContextOptions::kUseInstanced & options) { + if (ContextOverrides::kUseInstanced & overrides) { grOptions.fEnableInstancedRendering = true; } - grOptions.fRequireDecodeDisableForSRGB = - SkToBool(ContextOptions::kRequireSRGBDecodeDisableSupport & options); + if (ContextOverrides::kAllowSRGBWithoutDecodeControl & overrides) { + grOptions.fRequireDecodeDisableForSRGB = false; + } grCtx.reset(GrContext::Create(backend, backendContext, grOptions)); if (!grCtx.get()) { return ContextInfo(); } - if (ContextOptions::kEnableNVPR & options) { + if (ContextOverrides::kRequireNVPRSupport & overrides) { if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { return ContextInfo(); } } - if (ContextOptions::kUseInstanced & options) { + if (ContextOverrides::kUseInstanced & overrides) { if (GrCaps::InstancedSupport::kNone == grCtx->caps()->instancedSupport()) { return ContextInfo(); } } - if (ContextOptions::kRequireSRGBSupport & options) { + if (ContextOverrides::kRequireSRGBSupport & overrides) { if (!grCtx->caps()->srgbSupport()) { return ContextInfo(); } @@ -239,7 +236,7 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op context.fTestContext = testCtx.release(); context.fGrContext = SkRef(grCtx.get()); context.fType = type; - context.fOptions = options; + context.fOverrides = overrides; context.fAbandoned = false; return ContextInfo(context.fBackend, context.fTestContext, context.fGrContext); } diff --git a/tools/gpu/GrContextFactory.h b/tools/gpu/GrContextFactory.h index a232112d75..48b250d0ea 100644 --- a/tools/gpu/GrContextFactory.h +++ b/tools/gpu/GrContextFactory.h @@ -89,15 +89,17 @@ public: static const int kContextTypeCnt = kLastContextType + 1; /** - * Options for GL context creation. For historical and testing reasons the options will default - * to not using GL_NV_path_rendering extension even when the driver supports it. + * Overrides for the initial GrContextOptions provided at construction time, and required + * features that will cause context creation to fail if not present. */ - enum class ContextOptions { - kNone = 0x0, - kEnableNVPR = 0x1, - kUseInstanced = 0x2, - kRequireSRGBSupport = 0x4, - kRequireSRGBDecodeDisableSupport = 0x8, + enum class ContextOverrides { + kNone = 0x0, + kDisableNVPR = 0x1, + kUseInstanced = 0x2, + kAllowSRGBWithoutDecodeControl = 0x4, + + kRequireNVPRSupport = 0x8, + kRequireSRGBSupport = 0x10 }; 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. */ 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. */ - GrContext* get(ContextType type, ContextOptions options = ContextOptions::kNone) { - return this->getContextInfo(type, options).grContext(); + GrContext* get(ContextType type, ContextOverrides overrides = ContextOverrides::kNone) { + return this->getContextInfo(type, overrides).grContext(); } const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } private: struct Context { - ContextType fType; - ContextOptions fOptions; - GrBackend fBackend; - TestContext* fTestContext; - GrContext* fGrContext; - bool fAbandoned; + ContextType fType; + ContextOverrides fOverrides; + GrBackend fBackend; + TestContext* fTestContext; + GrContext* fGrContext; + bool fAbandoned; }; SkTArray<Context, true> fContexts; std::unique_ptr<GLTestContext> fSentinelGLContext; @@ -168,6 +170,6 @@ private: }; } // 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 diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp index 0fbccc39b3..125302b376 100644 --- a/tools/skiaserve/Request.cpp +++ b/tools/skiaserve/Request.cpp @@ -74,10 +74,10 @@ SkCanvas* Request::getCanvas() { #if SK_SUPPORT_GPU GrContextFactory* factory = fContextFactory; GLTestContext* gl = factory->getContextInfo(GrContextFactory::kNativeGL_ContextType, - GrContextFactory::ContextOptions::kNone).glContext(); + GrContextFactory::ContextOverrides::kNone).glContext(); if (!gl) { gl = factory->getContextInfo(GrContextFactory::kMESA_ContextType, - GrContextFactory::ContextOptions::kNone).glContext(); + GrContextFactory::ContextOverrides::kNone).glContext(); } if (gl) { gl->makeCurrent(); @@ -127,10 +127,10 @@ sk_sp<SkData> Request::writeOutSkp() { GrContext* Request::getContext() { #if SK_SUPPORT_GPU GrContext* result = fContextFactory->get(GrContextFactory::kNativeGL_ContextType, - GrContextFactory::ContextOptions::kNone); + GrContextFactory::ContextOverrides::kNone); if (!result) { result = fContextFactory->get(GrContextFactory::kMESA_ContextType, - GrContextFactory::ContextOptions::kNone); + GrContextFactory::ContextOverrides::kNone); } return result; #else diff --git a/tools/skpbench/skpbench.cpp b/tools/skpbench/skpbench.cpp index 897878e27d..3887c5ea88 100644 --- a/tools/skpbench/skpbench.cpp +++ b/tools/skpbench/skpbench.cpp @@ -273,7 +273,7 @@ int main(int argc, char** argv) { // Create a context. sk_gpu_test::GrContextFactory factory; sk_gpu_test::ContextInfo ctxInfo = - factory.getContextInfo(config->getContextType(), config->getContextOptions()); + factory.getContextInfo(config->getContextType(), config->getContextOverrides()); GrContext* ctx = ctxInfo.grContext(); if (!ctx) { exitf(ExitErr::kUnavailable, "failed to create context for config %s", |