Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/mus/surfaces/surfaces_context_provider.h" | 5 #include "components/mus/surfaces/surfaces_context_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | |
| 11 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | |
| 14 #include "components/mus/common/switches.h" | |
| 12 #include "components/mus/gles2/command_buffer_driver.h" | 15 #include "components/mus/gles2/command_buffer_driver.h" |
| 13 #include "components/mus/gles2/command_buffer_impl.h" | 16 #include "components/mus/gles2/command_buffer_impl.h" |
| 14 #include "components/mus/gles2/command_buffer_local.h" | 17 #include "components/mus/gles2/command_buffer_local.h" |
| 15 #include "components/mus/gles2/gpu_state.h" | 18 #include "components/mus/gles2/gpu_state.h" |
| 19 #include "components/mus/gpu/gpu_service_mus.h" | |
| 16 #include "components/mus/surfaces/surfaces_context_provider_delegate.h" | 20 #include "components/mus/surfaces/surfaces_context_provider_delegate.h" |
| 17 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 21 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 18 #include "gpu/command_buffer/client/gles2_implementation.h" | 22 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 19 #include "gpu/command_buffer/client/shared_memory_limits.h" | 23 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 20 #include "gpu/command_buffer/client/transfer_buffer.h" | 24 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 25 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | |
| 26 #include "ui/gl/gpu_preference.h" | |
| 21 | 27 |
| 22 namespace mus { | 28 namespace mus { |
| 23 | 29 |
| 24 SurfacesContextProvider::SurfacesContextProvider( | 30 SurfacesContextProvider::SurfacesContextProvider( |
|
Fady Samuel
2016/05/25 17:06:47
Could we have two ContextProviders instead? I pref
Peng
2016/05/25 19:42:56
I don't think it has too much different. Even if w
| |
| 25 gfx::AcceleratedWidget widget, | 31 gfx::AcceleratedWidget widget, |
| 26 const scoped_refptr<GpuState>& state) | 32 const scoped_refptr<GpuState>& state) |
| 27 : delegate_(nullptr), widget_(widget), command_buffer_local_(nullptr) { | 33 : use_chrome_gpu_command_buffer_(false), |
| 28 command_buffer_local_ = new CommandBufferLocal(this, widget_, state); | 34 delegate_(nullptr), |
| 35 widget_(widget), | |
| 36 command_buffer_local_(nullptr) { | |
| 37 use_chrome_gpu_command_buffer_ = | |
| 38 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 39 switches::kUseChromeGpuCommandBufferInMus); | |
| 40 if (!use_chrome_gpu_command_buffer_) { | |
| 41 command_buffer_local_ = new CommandBufferLocal(this, widget_, state); | |
| 42 } else { | |
| 43 GpuServiceMus* service = GpuServiceMus::GetInstance(); | |
| 44 gpu::CommandBufferProxyImpl* shared_command_buffer = nullptr; | |
| 45 gpu::GpuStreamId stream_id = gpu::GpuStreamId::GPU_STREAM_DEFAULT; | |
| 46 gpu::GpuStreamPriority stream_priority = gpu::GpuStreamPriority::NORMAL; | |
| 47 gpu::gles2::ContextCreationAttribHelper attributes; | |
| 48 attributes.alpha_size = -1; | |
| 49 attributes.depth_size = 0; | |
| 50 attributes.stencil_size = 0; | |
| 51 attributes.samples = 0; | |
| 52 attributes.sample_buffers = 0; | |
| 53 attributes.bind_generates_resource = false; | |
| 54 attributes.lose_context_when_out_of_memory = true; | |
| 55 gfx::GpuPreference gpu_preference = gfx::PreferIntegratedGpu; | |
| 56 GURL active_url; | |
| 57 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | |
| 58 base::ThreadTaskRunnerHandle::Get(); | |
| 59 command_buffer_proxy_impl_ = gpu::CommandBufferProxyImpl::Create( | |
| 60 service->gpu_channel_local(), widget, gfx::Size(), | |
| 61 shared_command_buffer, stream_id, stream_priority, attributes, | |
| 62 active_url, gpu_preference, task_runner); | |
| 63 } | |
| 29 } | 64 } |
| 30 | 65 |
| 31 void SurfacesContextProvider::SetDelegate( | 66 void SurfacesContextProvider::SetDelegate( |
| 32 SurfacesContextProviderDelegate* delegate) { | 67 SurfacesContextProviderDelegate* delegate) { |
| 33 DCHECK(!delegate_); | 68 DCHECK(!delegate_); |
| 34 delegate_ = delegate; | 69 delegate_ = delegate; |
| 35 } | 70 } |
| 36 | 71 |
| 37 // This routine needs to be safe to call more than once. | 72 // This routine needs to be safe to call more than once. |
| 38 // This is called when we have an accelerated widget. | 73 // This is called when we have an accelerated widget. |
| 39 bool SurfacesContextProvider::BindToCurrentThread() { | 74 bool SurfacesContextProvider::BindToCurrentThread() { |
| 40 if (implementation_) | 75 if (implementation_) |
| 41 return true; | 76 return true; |
| 42 | 77 |
| 43 // SurfacesContextProvider should always live on the same thread as the | 78 // SurfacesContextProvider should always live on the same thread as the |
| 44 // Window Manager. | 79 // Window Manager. |
| 45 DCHECK(CalledOnValidThread()); | 80 DCHECK(CalledOnValidThread()); |
| 46 if (!command_buffer_local_->Initialize()) | 81 gpu::GpuControl* gpu_control = nullptr; |
| 47 return false; | 82 gpu::CommandBuffer* command_buffer = nullptr; |
| 83 if (!use_chrome_gpu_command_buffer_) { | |
| 84 if (!command_buffer_local_->Initialize()) | |
| 85 return false; | |
| 86 gpu_control = command_buffer_local_; | |
| 87 command_buffer = command_buffer_local_; | |
| 88 } else { | |
| 89 gpu_control = command_buffer_proxy_impl_.get(); | |
|
piman
2016/05/24 22:46:54
CommandBufferProxyImpl::Create can fail, so you al
Peng
2016/05/25 19:42:56
Done.
| |
| 90 command_buffer = command_buffer_proxy_impl_.get(); | |
| 91 } | |
| 48 | 92 |
| 93 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer)); | |
| 49 constexpr gpu::SharedMemoryLimits default_limits; | 94 constexpr gpu::SharedMemoryLimits default_limits; |
| 50 gles2_helper_.reset( | |
| 51 new gpu::gles2::GLES2CmdHelper(command_buffer_local_)); | |
| 52 if (!gles2_helper_->Initialize(default_limits.command_buffer_size)) | 95 if (!gles2_helper_->Initialize(default_limits.command_buffer_size)) |
| 53 return false; | 96 return false; |
| 54 gles2_helper_->SetAutomaticFlushes(false); | 97 gles2_helper_->SetAutomaticFlushes(false); |
| 55 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); | 98 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); |
| 56 capabilities_ = command_buffer_local_->GetCapabilities(); | 99 capabilities_ = gpu_control->GetCapabilities(); |
| 57 bool bind_generates_resource = | 100 bool bind_generates_resource = |
| 58 !!capabilities_.bind_generates_resource_chromium; | 101 !!capabilities_.bind_generates_resource_chromium; |
| 59 // TODO(piman): Some contexts (such as compositor) want this to be true, so | 102 // TODO(piman): Some contexts (such as compositor) want this to be true, so |
| 60 // this needs to be a public parameter. | 103 // this needs to be a public parameter. |
| 61 bool lose_context_when_out_of_memory = false; | 104 bool lose_context_when_out_of_memory = false; |
| 62 bool support_client_side_arrays = false; | 105 bool support_client_side_arrays = false; |
| 63 implementation_.reset(new gpu::gles2::GLES2Implementation( | 106 implementation_.reset(new gpu::gles2::GLES2Implementation( |
| 64 gles2_helper_.get(), NULL, transfer_buffer_.get(), | 107 gles2_helper_.get(), NULL, transfer_buffer_.get(), |
| 65 bind_generates_resource, lose_context_when_out_of_memory, | 108 bind_generates_resource, lose_context_when_out_of_memory, |
| 66 support_client_side_arrays, command_buffer_local_)); | 109 support_client_side_arrays, gpu_control)); |
| 67 return implementation_->Initialize( | 110 return implementation_->Initialize( |
| 68 default_limits.start_transfer_buffer_size, | 111 default_limits.start_transfer_buffer_size, |
| 69 default_limits.min_transfer_buffer_size, | 112 default_limits.min_transfer_buffer_size, |
| 70 default_limits.max_transfer_buffer_size, | 113 default_limits.max_transfer_buffer_size, |
| 71 default_limits.mapped_memory_reclaim_limit); | 114 default_limits.mapped_memory_reclaim_limit); |
| 72 } | 115 } |
| 73 | 116 |
| 74 gpu::gles2::GLES2Interface* SurfacesContextProvider::ContextGL() { | 117 gpu::gles2::GLES2Interface* SurfacesContextProvider::ContextGL() { |
| 75 DCHECK(implementation_); | 118 DCHECK(implementation_); |
| 76 return implementation_.get(); | 119 return implementation_.get(); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 99 void SurfacesContextProvider::SetLostContextCallback( | 142 void SurfacesContextProvider::SetLostContextCallback( |
| 100 const LostContextCallback& lost_context_callback) { | 143 const LostContextCallback& lost_context_callback) { |
| 101 implementation_->SetLostContextCallback(lost_context_callback); | 144 implementation_->SetLostContextCallback(lost_context_callback); |
| 102 } | 145 } |
| 103 | 146 |
| 104 SurfacesContextProvider::~SurfacesContextProvider() { | 147 SurfacesContextProvider::~SurfacesContextProvider() { |
| 105 implementation_->Flush(); | 148 implementation_->Flush(); |
| 106 implementation_.reset(); | 149 implementation_.reset(); |
| 107 transfer_buffer_.reset(); | 150 transfer_buffer_.reset(); |
| 108 gles2_helper_.reset(); | 151 gles2_helper_.reset(); |
| 109 command_buffer_local_->Destroy(); | 152 command_buffer_proxy_impl_.reset(); |
| 110 command_buffer_local_ = nullptr; | 153 if (command_buffer_local_) { |
| 154 command_buffer_local_->Destroy(); | |
| 155 command_buffer_local_ = nullptr; | |
| 156 } | |
| 111 } | 157 } |
| 112 | 158 |
| 113 void SurfacesContextProvider::UpdateVSyncParameters(int64_t timebase, | 159 void SurfacesContextProvider::UpdateVSyncParameters(int64_t timebase, |
| 114 int64_t interval) { | 160 int64_t interval) { |
| 115 if (delegate_) | 161 if (delegate_) |
| 116 delegate_->OnVSyncParametersUpdated(timebase, interval); | 162 delegate_->OnVSyncParametersUpdated(timebase, interval); |
| 117 } | 163 } |
| 118 | 164 |
| 119 void SurfacesContextProvider::GpuCompletedSwapBuffers(gfx::SwapResult result) { | 165 void SurfacesContextProvider::GpuCompletedSwapBuffers(gfx::SwapResult result) { |
| 120 if (!swap_buffers_completion_callback_.is_null()) { | 166 if (!swap_buffers_completion_callback_.is_null()) { |
| 121 swap_buffers_completion_callback_.Run(result); | 167 swap_buffers_completion_callback_.Run(result); |
| 122 } | 168 } |
| 123 } | 169 } |
| 124 | 170 |
| 125 void SurfacesContextProvider::SetSwapBuffersCompletionCallback( | 171 void SurfacesContextProvider::SetSwapBuffersCompletionCallback( |
| 126 gfx::GLSurface::SwapCompletionCallback callback) { | 172 gfx::GLSurface::SwapCompletionCallback callback) { |
| 127 swap_buffers_completion_callback_ = callback; | 173 swap_buffers_completion_callback_ = callback; |
| 128 } | 174 } |
| 129 | 175 |
| 130 } // namespace mus | 176 } // namespace mus |
| OLD | NEW |