Skip to content

Commit

Permalink
gpu: Allow for null commandline in command_buffer
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
hendrikw authored and Commit bot committed Aug 10, 2015
1 parent efbf1fb commit 07e2974
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 29 deletions.
7 changes: 5 additions & 2 deletions gpu/command_buffer/service/context_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
25 changes: 15 additions & 10 deletions gpu/command_buffer/service/feature_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/service/feature_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class GPU_EXPORT FeatureInfo : public base::RefCounted<FeatureInfo> {
~FeatureInfo();

void AddExtensionString(const char* s);
void InitializeBasicState(const base::CommandLine& command_line);
void InitializeBasicState(const base::CommandLine* command_line);
void InitializeFeatures();

Validators validators_;
Expand Down
41 changes: 25 additions & 16 deletions gpu/command_buffer/service/gles2_cmd_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 07e2974

Please sign in to comment.