Index: components/mus/surfaces/surfaces_context_provider.cc |
diff --git a/components/mus/surfaces/surfaces_context_provider.cc b/components/mus/surfaces/surfaces_context_provider.cc |
index e40be15beab6e6a609bfbcc83be98d30ef195f4b..2e91b9897c17332a5a34e6ca830824c1dc2e9684 100644 |
--- a/components/mus/surfaces/surfaces_context_provider.cc |
+++ b/components/mus/surfaces/surfaces_context_provider.cc |
@@ -8,24 +8,59 @@ |
#include "base/bind.h" |
#include "base/bind_helpers.h" |
+#include "base/command_line.h" |
#include "base/synchronization/waitable_event.h" |
+#include "base/threading/thread_task_runner_handle.h" |
+#include "components/mus/common/switches.h" |
#include "components/mus/gles2/command_buffer_driver.h" |
#include "components/mus/gles2/command_buffer_impl.h" |
#include "components/mus/gles2/command_buffer_local.h" |
#include "components/mus/gles2/gpu_state.h" |
+#include "components/mus/gpu/gpu_service_mus.h" |
#include "components/mus/surfaces/surfaces_context_provider_delegate.h" |
#include "gpu/command_buffer/client/gles2_cmd_helper.h" |
#include "gpu/command_buffer/client/gles2_implementation.h" |
#include "gpu/command_buffer/client/shared_memory_limits.h" |
#include "gpu/command_buffer/client/transfer_buffer.h" |
+#include "gpu/ipc/client/command_buffer_proxy_impl.h" |
+#include "ui/gl/gpu_preference.h" |
namespace mus { |
SurfacesContextProvider::SurfacesContextProvider( |
gfx::AcceleratedWidget widget, |
const scoped_refptr<GpuState>& state) |
- : delegate_(nullptr), widget_(widget), command_buffer_local_(nullptr) { |
- command_buffer_local_ = new CommandBufferLocal(this, widget_, state); |
+ : use_chrome_gpu_command_buffer_(false), |
+ delegate_(nullptr), |
+ widget_(widget), |
+ command_buffer_local_(nullptr) { |
+ use_chrome_gpu_command_buffer_ = |
+ base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kUseChromeGpuCommandBufferInMus); |
+ if (!use_chrome_gpu_command_buffer_) { |
+ command_buffer_local_ = new CommandBufferLocal(this, widget_, state); |
+ } else { |
+ GpuServiceMus* service = GpuServiceMus::GetInstance(); |
+ gpu::CommandBufferProxyImpl* shared_command_buffer = nullptr; |
+ gpu::GpuStreamId stream_id = gpu::GpuStreamId::GPU_STREAM_DEFAULT; |
+ gpu::GpuStreamPriority stream_priority = gpu::GpuStreamPriority::NORMAL; |
+ gpu::gles2::ContextCreationAttribHelper attributes; |
+ attributes.alpha_size = -1; |
+ attributes.depth_size = 0; |
+ attributes.stencil_size = 0; |
+ attributes.samples = 0; |
+ attributes.sample_buffers = 0; |
+ attributes.bind_generates_resource = false; |
+ attributes.lose_context_when_out_of_memory = true; |
+ gl::GpuPreference gpu_preference = gl::PreferIntegratedGpu; |
+ GURL active_url; |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
+ base::ThreadTaskRunnerHandle::Get(); |
+ command_buffer_proxy_impl_ = gpu::CommandBufferProxyImpl::Create( |
+ service->gpu_channel_local(), widget, gfx::Size(), |
+ shared_command_buffer, stream_id, stream_priority, attributes, |
+ active_url, gpu_preference, task_runner); |
+ } |
} |
void SurfacesContextProvider::SetDelegate( |
@@ -43,17 +78,27 @@ bool SurfacesContextProvider::BindToCurrentThread() { |
// SurfacesContextProvider should always live on the same thread as the |
// Window Manager. |
DCHECK(CalledOnValidThread()); |
- if (!command_buffer_local_->Initialize()) |
- return false; |
+ gpu::GpuControl* gpu_control = nullptr; |
+ gpu::CommandBuffer* command_buffer = nullptr; |
+ if (!use_chrome_gpu_command_buffer_) { |
+ if (!command_buffer_local_->Initialize()) |
+ return false; |
+ gpu_control = command_buffer_local_; |
+ command_buffer = command_buffer_local_; |
+ } else { |
+ if (!command_buffer_proxy_impl_) |
+ return false; |
+ gpu_control = command_buffer_proxy_impl_.get(); |
+ command_buffer = command_buffer_proxy_impl_.get(); |
+ } |
+ gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer)); |
constexpr gpu::SharedMemoryLimits default_limits; |
- gles2_helper_.reset( |
- new gpu::gles2::GLES2CmdHelper(command_buffer_local_)); |
if (!gles2_helper_->Initialize(default_limits.command_buffer_size)) |
return false; |
gles2_helper_->SetAutomaticFlushes(false); |
transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); |
- capabilities_ = command_buffer_local_->GetCapabilities(); |
+ capabilities_ = gpu_control->GetCapabilities(); |
bool bind_generates_resource = |
!!capabilities_.bind_generates_resource_chromium; |
// TODO(piman): Some contexts (such as compositor) want this to be true, so |
@@ -63,7 +108,7 @@ bool SurfacesContextProvider::BindToCurrentThread() { |
implementation_.reset(new gpu::gles2::GLES2Implementation( |
gles2_helper_.get(), NULL, transfer_buffer_.get(), |
bind_generates_resource, lose_context_when_out_of_memory, |
- support_client_side_arrays, command_buffer_local_)); |
+ support_client_side_arrays, gpu_control)); |
return implementation_->Initialize( |
default_limits.start_transfer_buffer_size, |
default_limits.min_transfer_buffer_size, |
@@ -106,8 +151,11 @@ SurfacesContextProvider::~SurfacesContextProvider() { |
implementation_.reset(); |
transfer_buffer_.reset(); |
gles2_helper_.reset(); |
- command_buffer_local_->Destroy(); |
- command_buffer_local_ = nullptr; |
+ command_buffer_proxy_impl_.reset(); |
+ if (command_buffer_local_) { |
+ command_buffer_local_->Destroy(); |
+ command_buffer_local_ = nullptr; |
+ } |
} |
void SurfacesContextProvider::UpdateVSyncParameters(int64_t timebase, |