Skip to content

Commit

Permalink
Use GpuPreferences to avoid directly accessing switches in gpu relate…
Browse files Browse the repository at this point in the history
…d code

BUG=586369
CQ_INCLUDE_TRYBOTS=tryserver.chromium.win:win_optional_gpu_tests_rel

Review URL: https://codereview.chromium.org/1716813002

Cr-Commit-Position: refs/heads/master@{#378305}
  • Loading branch information
phuang authored and Commit bot committed Feb 29, 2016
1 parent 071c61a commit 7404df9
Show file tree
Hide file tree
Showing 43 changed files with 532 additions and 172 deletions.
87 changes: 84 additions & 3 deletions android_webview/browser/deferred_gpu_command_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,96 @@

#include "android_webview/browser/gl_view_renderer_manager.h"
#include "android_webview/browser/shared_renderer_state.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/lock.h"
#include "base/trace_event/trace_event.h"
#include "content/public/browser/android/synchronous_compositor.h"
#include "content/public/common/content_switches.h"
#include "gpu/command_buffer/service/framebuffer_completeness_cache.h"
#include "gpu/command_buffer/service/gpu_preferences.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/command_buffer/service/shader_translator_cache.h"
#include "gpu/command_buffer/service/sync_point_manager.h"
#include "gpu/config/gpu_switches.h"
#include "ui/gl/gl_switches.h"

namespace android_webview {

namespace {
base::LazyInstance<scoped_refptr<DeferredGpuCommandService> >
g_service = LAZY_INSTANCE_INITIALIZER;

bool GetSizeTFromSwitch(const base::CommandLine* command_line,
const base::StringPiece& switch_string,
size_t* value) {
if (!command_line->HasSwitch(switch_string))
return false;
std::string switch_value(command_line->GetSwitchValueASCII(switch_string));
return base::StringToSizeT(switch_value, value);
}

gpu::GpuPreferences GetGpuPreferencesFromCommandLine() {
// TODO(penghuang): share below code with content/gpu/gpu_child_thread.cc
// http://crbug.com/590825
DCHECK(base::CommandLine::InitializedForCurrentProcess());
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
gpu::GpuPreferences gpu_preferences;
gpu_preferences.single_process =
command_line->HasSwitch(switches::kSingleProcess);
gpu_preferences.in_process_gpu =
command_line->HasSwitch(switches::kInProcessGPU);
gpu_preferences.ui_prioritize_in_gpu_process =
command_line->HasSwitch(switches::kUIPrioritizeInGpuProcess);
gpu_preferences.compile_shader_always_succeeds =
command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds);
gpu_preferences.disable_gl_error_limit =
command_line->HasSwitch(switches::kDisableGLErrorLimit);
gpu_preferences.disable_glsl_translator =
command_line->HasSwitch(switches::kDisableGLSLTranslator);
gpu_preferences.disable_gpu_driver_bug_workarounds =
command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds);
gpu_preferences.disable_shader_name_hashing =
command_line->HasSwitch(switches::kDisableShaderNameHashing);
gpu_preferences.enable_gpu_command_logging =
command_line->HasSwitch(switches::kEnableGPUCommandLogging);
gpu_preferences.enable_gpu_debugging =
command_line->HasSwitch(switches::kEnableGPUDebugging);
gpu_preferences.enable_gpu_service_logging_gpu =
command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU);
gpu_preferences.disable_gpu_program_cache =
command_line->HasSwitch(switches::kDisableGpuProgramCache);
gpu_preferences.enforce_gl_minimums =
command_line->HasSwitch(switches::kEnforceGLMinimums);
if (GetSizeTFromSwitch(command_line, switches::kForceGpuMemAvailableMb,
&gpu_preferences.force_gpu_mem_available)) {
gpu_preferences.force_gpu_mem_available *= 1024 * 1024;
}
if (GetSizeTFromSwitch(command_line, switches::kGpuProgramCacheSizeKb,
&gpu_preferences.gpu_program_cache_size)) {
gpu_preferences.gpu_program_cache_size *= 1024;
}
gpu_preferences.enable_share_group_async_texture_upload =
command_line->HasSwitch(switches::kEnableShareGroupAsyncTextureUpload);
gpu_preferences.enable_subscribe_uniform_extension =
command_line->HasSwitch(switches::kEnableSubscribeUniformExtension);
gpu_preferences.enable_threaded_texture_mailboxes =
command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes);
gpu_preferences.gl_shader_interm_output =
command_line->HasSwitch(switches::kGLShaderIntermOutput);
gpu_preferences.emulate_shader_precision =
command_line->HasSwitch(switches::kEmulateShaderPrecision);
gpu_preferences.enable_gpu_service_logging =
command_line->HasSwitch(switches::kEnableGPUServiceLogging);
gpu_preferences.enable_gpu_service_tracing =
command_line->HasSwitch(switches::kEnableGPUServiceTracing);
gpu_preferences.enable_unsafe_es3_apis =
command_line->HasSwitch(switches::kEnableUnsafeES3APIs);
return gpu_preferences;
}

} // namespace

base::LazyInstance<base::ThreadLocalBoolean> ScopedAllowGL::allow_gl;
Expand Down Expand Up @@ -63,7 +140,9 @@ DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() {
}

DeferredGpuCommandService::DeferredGpuCommandService()
: sync_point_manager_(new gpu::SyncPointManager(true)) {}
: gpu::InProcessCommandBuffer::Service(GetGpuPreferencesFromCommandLine()),
sync_point_manager_(new gpu::SyncPointManager(true)) {
}

DeferredGpuCommandService::~DeferredGpuCommandService() {
base::AutoLock lock(tasks_lock_);
Expand Down Expand Up @@ -149,8 +228,10 @@ bool DeferredGpuCommandService::UseVirtualizedGLContexts() { return true; }

scoped_refptr<gpu::gles2::ShaderTranslatorCache>
DeferredGpuCommandService::shader_translator_cache() {
if (!shader_translator_cache_.get())
shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache;
if (!shader_translator_cache_.get()) {
shader_translator_cache_ =
new gpu::gles2::ShaderTranslatorCache(gpu_preferences());
}
return shader_translator_cache_;
}

Expand Down
5 changes: 3 additions & 2 deletions components/mus/gles2/command_buffer_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ bool CommandBufferDriver::Initialize(
const bool bind_generates_resource = attrib_helper.bind_generates_resource;
scoped_refptr<gpu::gles2::ContextGroup> context_group =
new gpu::gles2::ContextGroup(
gpu_state_->mailbox_manager(), new GpuMemoryTracker,
new gpu::gles2::ShaderTranslatorCache,
gpu_state_->gpu_preferences(), gpu_state_->mailbox_manager(),
new GpuMemoryTracker,
new gpu::gles2::ShaderTranslatorCache(gpu_state_->gpu_preferences()),
new gpu::gles2::FramebufferCompletenessCache, nullptr, nullptr,
nullptr, bind_generates_resource);

Expand Down
6 changes: 6 additions & 0 deletions components/mus/gles2/gpu_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/threading/thread.h"
#include "components/mus/gles2/command_buffer_driver_manager.h"
#include "components/mus/gles2/command_buffer_task_runner.h"
#include "gpu/command_buffer/service/gpu_preferences.h"
#include "gpu/command_buffer/service/mailbox_manager_impl.h"
#include "gpu/command_buffer/service/sync_point_manager.h"
#include "gpu/config/gpu_info.h"
Expand All @@ -37,6 +38,10 @@ class GpuState : public base::RefCountedThreadSafe<GpuState> {

void StopThreads();

const gpu::GpuPreferences& gpu_preferences() const {
return gpu_preferences_;
}

CommandBufferTaskRunner* command_buffer_task_runner() const {
return command_buffer_task_runner_.get();
}
Expand Down Expand Up @@ -74,6 +79,7 @@ class GpuState : public base::RefCountedThreadSafe<GpuState> {
// |control_thread_| is for mojo incoming calls of CommandBufferImpl.
base::Thread control_thread_;

gpu::GpuPreferences gpu_preferences_;
scoped_refptr<CommandBufferTaskRunner> command_buffer_task_runner_;
scoped_ptr<CommandBufferDriverManager> driver_manager_;
scoped_ptr<gpu::SyncPointManager> sync_point_manager_;
Expand Down
13 changes: 8 additions & 5 deletions content/browser/android/synchronous_compositor_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ class SynchronousCompositorClient;

namespace {

gpu::SyncPointManager* g_sync_point_manager = nullptr;
base::LazyInstance<scoped_refptr<gpu::InProcessCommandBuffer::Service>>
g_gpu_service = LAZY_INSTANCE_INITIALIZER;

base::Thread* CreateInProcessGpuThreadForSynchronousCompositor(
const InProcessChildThreadParams& params) {
DCHECK(g_sync_point_manager);
return new InProcessGpuThread(params, g_sync_point_manager);
DCHECK(g_gpu_service.Get());
return new InProcessGpuThread(params,
g_gpu_service.Get()->gpu_preferences(),
g_gpu_service.Get()->sync_point_manager());
}

} // namespace

void SynchronousCompositor::SetGpuService(
scoped_refptr<gpu::InProcessCommandBuffer::Service> service) {
DCHECK(!g_sync_point_manager);
g_sync_point_manager = service->sync_point_manager();
DCHECK(!g_gpu_service.Get());
g_gpu_service.Get() = service;
GpuProcessHost::RegisterGpuMainThreadFactory(
CreateInProcessGpuThreadForSynchronousCompositor);
}
Expand Down
26 changes: 12 additions & 14 deletions content/common/gpu/gpu_channel_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <utility>

#include "base/bind.h"
#include "base/command_line.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
Expand All @@ -20,17 +19,13 @@
#include "content/common/gpu/gpu_memory_manager.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/common/gpu/image_transport_surface.h"
#include "content/public/common/content_switches.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "gpu/command_buffer/common/value_state.h"
#include "gpu/command_buffer/service/feature_info.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
#include "gpu/command_buffer/service/memory_program_cache.h"
#include "gpu/command_buffer/service/shader_translator_cache.h"
#include "gpu/command_buffer/service/sync_point_manager.h"
#include "ipc/message_filter.h"
#include "ipc/message_router.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_share_group.h"

Expand All @@ -52,6 +47,7 @@ const int kMaxKeepAliveTimeMs = 200;
}

GpuChannelManager::GpuChannelManager(
const gpu::GpuPreferences& gpu_preferences,
GpuChannelManagerDelegate* delegate,
GpuWatchdog* watchdog,
base::SingleThreadTaskRunner* task_runner,
Expand All @@ -61,11 +57,12 @@ GpuChannelManager::GpuChannelManager(
GpuMemoryBufferFactory* gpu_memory_buffer_factory)
: task_runner_(task_runner),
io_task_runner_(io_task_runner),
gpu_preferences_(gpu_preferences),
delegate_(delegate),
watchdog_(watchdog),
shutdown_event_(shutdown_event),
share_group_(new gfx::GLShareGroup),
mailbox_manager_(gpu::gles2::MailboxManager::Create()),
mailbox_manager_(gpu::gles2::MailboxManager::Create(gpu_preferences)),
gpu_memory_manager_(this),
sync_point_manager_(sync_point_manager),
sync_point_client_waiter_(
Expand All @@ -74,9 +71,7 @@ GpuChannelManager::GpuChannelManager(
weak_factory_(this) {
DCHECK(task_runner);
DCHECK(io_task_runner);
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kUIPrioritizeInGpuProcess))
if (gpu_preferences_.ui_prioritize_in_gpu_process)
preemption_flag_ = new gpu::PreemptionFlag;
}

Expand All @@ -93,17 +88,20 @@ gpu::gles2::ProgramCache* GpuChannelManager::program_cache() {
if (!program_cache_.get() &&
(gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary ||
gfx::g_driver_gl.ext.b_GL_OES_get_program_binary) &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableGpuProgramCache)) {
program_cache_.reset(new gpu::gles2::MemoryProgramCache());
!gpu_preferences_.disable_gpu_program_cache) {
program_cache_.reset(new gpu::gles2::MemoryProgramCache(
gpu_preferences_.gpu_program_cache_size,
gpu_preferences_.disable_gpu_shader_disk_cache));
}
return program_cache_.get();
}

gpu::gles2::ShaderTranslatorCache*
GpuChannelManager::shader_translator_cache() {
if (!shader_translator_cache_.get())
shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache;
if (!shader_translator_cache_.get()) {
shader_translator_cache_ =
new gpu::gles2::ShaderTranslatorCache(gpu_preferences_);
}
return shader_translator_cache_.get();
}

Expand Down
9 changes: 8 additions & 1 deletion content/common/gpu/gpu_channel_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class GLShareGroup;
}

namespace gpu {
struct GpuPreferences;
class PreemptionFlag;
class SyncPointClient;
class SyncPointManager;
Expand Down Expand Up @@ -69,7 +70,8 @@ struct BufferPresentedParams;
// browser process to them based on the corresponding renderer ID.
class CONTENT_EXPORT GpuChannelManager {
public:
GpuChannelManager(GpuChannelManagerDelegate* delegate,
GpuChannelManager(const gpu::GpuPreferences& gpu_preferences,
GpuChannelManagerDelegate* delegate,
GpuWatchdog* watchdog,
base::SingleThreadTaskRunner* task_runner,
base::SingleThreadTaskRunner* io_task_runner,
Expand Down Expand Up @@ -106,6 +108,9 @@ class CONTENT_EXPORT GpuChannelManager {
void BufferPresented(const BufferPresentedParams& params);
#endif

const gpu::GpuPreferences& gpu_preferences() const {
return gpu_preferences_;
}
gpu::gles2::ProgramCache* program_cache();
gpu::gles2::ShaderTranslatorCache* shader_translator_cache();
gpu::gles2::FramebufferCompletenessCache* framebuffer_completeness_cache();
Expand Down Expand Up @@ -169,6 +174,8 @@ class CONTENT_EXPORT GpuChannelManager {
void DoWakeUpGpu();
#endif

const gpu::GpuPreferences& gpu_preferences_;

GpuChannelManagerDelegate* const delegate_;
#if defined(OS_MACOSX)
IDMap<ImageTransportHelper> image_transport_map_;
Expand Down
7 changes: 5 additions & 2 deletions content/common/gpu/gpu_channel_test_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ void TestGpuChannelManagerDelegate::SendAcceleratedSurfaceCreatedChildWindow(
#endif

TestGpuChannelManager::TestGpuChannelManager(
const gpu::GpuPreferences& gpu_preferences,
GpuChannelManagerDelegate* delegate,
base::SingleThreadTaskRunner* task_runner,
base::SingleThreadTaskRunner* io_task_runner,
gpu::SyncPointManager* sync_point_manager,
GpuMemoryBufferFactory* gpu_memory_buffer_factory)
: GpuChannelManager(delegate,
: GpuChannelManager(gpu_preferences,
delegate,
nullptr,
task_runner,
io_task_runner,
Expand Down Expand Up @@ -146,7 +148,8 @@ GpuChannelTestCommon::GpuChannelTestCommon()
sync_point_manager_(new gpu::SyncPointManager(false)),
channel_manager_delegate_(new TestGpuChannelManagerDelegate()),
channel_manager_(
new TestGpuChannelManager(channel_manager_delegate_.get(),
new TestGpuChannelManager(gpu_preferences_,
channel_manager_delegate_.get(),
task_runner_.get(),
io_task_runner_.get(),
sync_point_manager_.get(),
Expand Down
5 changes: 4 additions & 1 deletion content/common/gpu/gpu_channel_test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "content/common/gpu/gpu_channel.h"
#include "content/common/gpu/gpu_channel_manager.h"
#include "content/common/gpu/gpu_channel_manager_delegate.h"
#include "gpu/command_buffer/service/gpu_preferences.h"
#include "ipc/ipc_test_sink.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand Down Expand Up @@ -64,7 +65,8 @@ class TestGpuChannelManagerDelegate : public GpuChannelManagerDelegate {

class TestGpuChannelManager : public GpuChannelManager {
public:
TestGpuChannelManager(GpuChannelManagerDelegate* delegate,
TestGpuChannelManager(const gpu::GpuPreferences& gpu_preferences,
GpuChannelManagerDelegate* delegate,
base::SingleThreadTaskRunner* task_runner,
base::SingleThreadTaskRunner* io_task_runner,
gpu::SyncPointManager* sync_point_manager,
Expand Down Expand Up @@ -121,6 +123,7 @@ class GpuChannelTestCommon : public testing::Test {
base::TestSimpleTaskRunner* task_runner() { return task_runner_.get(); }

private:
gpu::GpuPreferences gpu_preferences_;
scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
scoped_refptr<base::TestSimpleTaskRunner> io_task_runner_;
scoped_ptr<gpu::SyncPointManager> sync_point_manager_;
Expand Down
Loading

0 comments on commit 7404df9

Please sign in to comment.