From 07e2974f86e3c8c9235a3621773371b6f4c1a47e Mon Sep 17 00:00:00 2001 From: hendrikw Date: Mon, 10 Aug 2015 16:26:38 -0700 Subject: [PATCH] gpu: Allow for null commandline in command_buffer We're in progress of allowing the command buffer to act as a gl target for skia, when this happens, we can't assume that there's a command line Add some null checks. Review URL: https://codereview.chromium.org/1276683009 Cr-Commit-Position: refs/heads/master@{#342732} --- gpu/command_buffer/service/context_group.cc | 7 +++- gpu/command_buffer/service/feature_info.cc | 25 ++++++----- gpu/command_buffer/service/feature_info.h | 2 +- .../service/gles2_cmd_decoder.cc | 41 +++++++++++-------- 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/gpu/command_buffer/service/context_group.cc b/gpu/command_buffer/service/context_group.cc index f575429f9c8a1a..ca8b335a39c4cc 100644 --- a/gpu/command_buffer/service/context_group.cc +++ b/gpu/command_buffer/service/context_group.cc @@ -40,8 +40,11 @@ ContextGroup::ContextGroup( shader_translator_cache_(shader_translator_cache), subscription_ref_set_(subscription_ref_set), pending_valuebuffer_state_(pending_valuebuffer_state), - enforce_gl_minimums_(base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnforceGLMinimums)), + enforce_gl_minimums_( + base::CommandLine::InitializedForCurrentProcess() + ? base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnforceGLMinimums) + : false), bind_generates_resource_(bind_generates_resource), max_vertex_attribs_(0u), max_texture_units_(0u), diff --git a/gpu/command_buffer/service/feature_info.cc b/gpu/command_buffer/service/feature_info.cc index b8737fc40e7a50..b1e92e6e4c5989 100644 --- a/gpu/command_buffer/service/feature_info.cc +++ b/gpu/command_buffer/service/feature_info.cc @@ -185,33 +185,38 @@ FeatureInfo::Workarounds::Workarounds() : } FeatureInfo::FeatureInfo() { - InitializeBasicState(*base::CommandLine::ForCurrentProcess()); + InitializeBasicState(base::CommandLine::InitializedForCurrentProcess() + ? base::CommandLine::ForCurrentProcess() + : nullptr); } FeatureInfo::FeatureInfo(const base::CommandLine& command_line) { - InitializeBasicState(command_line); + InitializeBasicState(&command_line); } -void FeatureInfo::InitializeBasicState(const base::CommandLine& command_line) { - if (command_line.HasSwitch(switches::kGpuDriverBugWorkarounds)) { - std::string types = command_line.GetSwitchValueASCII( +void FeatureInfo::InitializeBasicState(const base::CommandLine* command_line) { + if (!command_line) + return; + + if (command_line->HasSwitch(switches::kGpuDriverBugWorkarounds)) { + std::string types = command_line->GetSwitchValueASCII( switches::kGpuDriverBugWorkarounds); StringToWorkarounds(types, &workarounds_); } feature_flags_.enable_shader_name_hashing = - !command_line.HasSwitch(switches::kDisableShaderNameHashing); + !command_line->HasSwitch(switches::kDisableShaderNameHashing); feature_flags_.is_swiftshader = - (command_line.GetSwitchValueASCII(switches::kUseGL) == "swiftshader"); + (command_line->GetSwitchValueASCII(switches::kUseGL) == "swiftshader"); feature_flags_.enable_subscribe_uniform = - command_line.HasSwitch(switches::kEnableSubscribeUniformExtension); + command_line->HasSwitch(switches::kEnableSubscribeUniformExtension); enable_unsafe_es3_apis_switch_ = - command_line.HasSwitch(switches::kEnableUnsafeES3APIs); + command_line->HasSwitch(switches::kEnableUnsafeES3APIs); enable_gl_path_rendering_switch_ = - command_line.HasSwitch(switches::kEnableGLPathRendering); + command_line->HasSwitch(switches::kEnableGLPathRendering); unsafe_es3_apis_enabled_ = false; } diff --git a/gpu/command_buffer/service/feature_info.h b/gpu/command_buffer/service/feature_info.h index 8c26686c3e6bde..4a55c958fe468b 100644 --- a/gpu/command_buffer/service/feature_info.h +++ b/gpu/command_buffer/service/feature_info.h @@ -145,7 +145,7 @@ class GPU_EXPORT FeatureInfo : public base::RefCounted { ~FeatureInfo(); void AddExtensionString(const char* s); - void InitializeBasicState(const base::CommandLine& command_line); + void InitializeBasicState(const base::CommandLine* command_line); void InitializeFeatures(); Validators validators_; diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index 5c3bf03f02ab61..6e8c92cee9050b 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -2571,8 +2571,10 @@ GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) shader_texture_lod_explicitly_enabled_(false), compile_shader_always_succeeds_(false), lose_context_when_out_of_memory_(false), - service_logging_(base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableGPUServiceLoggingGPU)), + service_logging_(base::CommandLine::InitializedForCurrentProcess() + ? base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableGPUServiceLoggingGPU) + : false), viewport_max_width_(0), viewport_max_height_(0), texture_state_(group_->feature_info() @@ -2595,9 +2597,13 @@ GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) // GL_OES_standard_derivatives on demand). It is used for the unit // tests because GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes // the empty string to CompileShader and this is not a valid shader. + bool disable_translator = + base::CommandLine::InitializedForCurrentProcess() + ? base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableGLSLTranslator) + : false; if (gfx::GetGLImplementation() == gfx::kGLImplementationMockGL || - base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableGLSLTranslator)) { + disable_translator) { use_shader_translator_ = false; } } @@ -2627,19 +2633,21 @@ bool GLES2DecoderImpl::Initialize( set_initialized(); gpu_state_tracer_ = GPUStateTracer::Create(&state_); - if (base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableGPUDebugging)) { - set_debug(true); - } + if (base::CommandLine::InitializedForCurrentProcess()) { + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableGPUDebugging)) { + set_debug(true); + } - if (base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableGPUCommandLogging)) { - set_log_commands(true); - } + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableGPUCommandLogging)) { + set_log_commands(true); + } - compile_shader_always_succeeds_ = - base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kCompileShaderAlwaysSucceeds); + compile_shader_always_succeeds_ = + base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kCompileShaderAlwaysSucceeds); + } // Take ownership of the context and surface. The surface can be replaced with // SetSurface. @@ -3286,7 +3294,8 @@ bool GLES2DecoderImpl::InitializeShaderTranslator() { if (workarounds().remove_pow_with_constant_exponent) driver_bug_workarounds |= SH_REMOVE_POW_WITH_CONSTANT_EXPONENT; - if (base::CommandLine::ForCurrentProcess()->HasSwitch( + if (base::CommandLine::InitializedForCurrentProcess() && + base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kEmulateShaderPrecision)) resources.WEBGL_debug_shader_precision = true;