Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(679)

Side by Side Diff: components/mus/surfaces/surfaces_context_provider.cc

Issue 1976703003: Impl mus::mojom::GpuService to enable using Chrome IPC version gpu CmdBuf in mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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(
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 gl::GpuPreference gpu_preference = gl::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 if (!command_buffer_proxy_impl_)
90 return false;
91 gpu_control = command_buffer_proxy_impl_.get();
92 command_buffer = command_buffer_proxy_impl_.get();
93 }
48 94
95 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer));
49 constexpr gpu::SharedMemoryLimits default_limits; 96 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)) 97 if (!gles2_helper_->Initialize(default_limits.command_buffer_size))
53 return false; 98 return false;
54 gles2_helper_->SetAutomaticFlushes(false); 99 gles2_helper_->SetAutomaticFlushes(false);
55 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); 100 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get()));
56 capabilities_ = command_buffer_local_->GetCapabilities(); 101 capabilities_ = gpu_control->GetCapabilities();
57 bool bind_generates_resource = 102 bool bind_generates_resource =
58 !!capabilities_.bind_generates_resource_chromium; 103 !!capabilities_.bind_generates_resource_chromium;
59 // TODO(piman): Some contexts (such as compositor) want this to be true, so 104 // TODO(piman): Some contexts (such as compositor) want this to be true, so
60 // this needs to be a public parameter. 105 // this needs to be a public parameter.
61 bool lose_context_when_out_of_memory = false; 106 bool lose_context_when_out_of_memory = false;
62 bool support_client_side_arrays = false; 107 bool support_client_side_arrays = false;
63 implementation_.reset(new gpu::gles2::GLES2Implementation( 108 implementation_.reset(new gpu::gles2::GLES2Implementation(
64 gles2_helper_.get(), NULL, transfer_buffer_.get(), 109 gles2_helper_.get(), NULL, transfer_buffer_.get(),
65 bind_generates_resource, lose_context_when_out_of_memory, 110 bind_generates_resource, lose_context_when_out_of_memory,
66 support_client_side_arrays, command_buffer_local_)); 111 support_client_side_arrays, gpu_control));
67 return implementation_->Initialize( 112 return implementation_->Initialize(
68 default_limits.start_transfer_buffer_size, 113 default_limits.start_transfer_buffer_size,
69 default_limits.min_transfer_buffer_size, 114 default_limits.min_transfer_buffer_size,
70 default_limits.max_transfer_buffer_size, 115 default_limits.max_transfer_buffer_size,
71 default_limits.mapped_memory_reclaim_limit); 116 default_limits.mapped_memory_reclaim_limit);
72 } 117 }
73 118
74 gpu::gles2::GLES2Interface* SurfacesContextProvider::ContextGL() { 119 gpu::gles2::GLES2Interface* SurfacesContextProvider::ContextGL() {
75 DCHECK(implementation_); 120 DCHECK(implementation_);
76 return implementation_.get(); 121 return implementation_.get();
(...skipping 22 matching lines...) Expand all
99 void SurfacesContextProvider::SetLostContextCallback( 144 void SurfacesContextProvider::SetLostContextCallback(
100 const LostContextCallback& lost_context_callback) { 145 const LostContextCallback& lost_context_callback) {
101 implementation_->SetLostContextCallback(lost_context_callback); 146 implementation_->SetLostContextCallback(lost_context_callback);
102 } 147 }
103 148
104 SurfacesContextProvider::~SurfacesContextProvider() { 149 SurfacesContextProvider::~SurfacesContextProvider() {
105 implementation_->Flush(); 150 implementation_->Flush();
106 implementation_.reset(); 151 implementation_.reset();
107 transfer_buffer_.reset(); 152 transfer_buffer_.reset();
108 gles2_helper_.reset(); 153 gles2_helper_.reset();
109 command_buffer_local_->Destroy(); 154 command_buffer_proxy_impl_.reset();
110 command_buffer_local_ = nullptr; 155 if (command_buffer_local_) {
156 command_buffer_local_->Destroy();
157 command_buffer_local_ = nullptr;
158 }
111 } 159 }
112 160
113 void SurfacesContextProvider::UpdateVSyncParameters(int64_t timebase, 161 void SurfacesContextProvider::UpdateVSyncParameters(int64_t timebase,
114 int64_t interval) { 162 int64_t interval) {
115 if (delegate_) 163 if (delegate_)
116 delegate_->OnVSyncParametersUpdated(timebase, interval); 164 delegate_->OnVSyncParametersUpdated(timebase, interval);
117 } 165 }
118 166
119 void SurfacesContextProvider::GpuCompletedSwapBuffers(gfx::SwapResult result) { 167 void SurfacesContextProvider::GpuCompletedSwapBuffers(gfx::SwapResult result) {
120 if (!swap_buffers_completion_callback_.is_null()) { 168 if (!swap_buffers_completion_callback_.is_null()) {
121 swap_buffers_completion_callback_.Run(result); 169 swap_buffers_completion_callback_.Run(result);
122 } 170 }
123 } 171 }
124 172
125 void SurfacesContextProvider::SetSwapBuffersCompletionCallback( 173 void SurfacesContextProvider::SetSwapBuffersCompletionCallback(
126 gl::GLSurface::SwapCompletionCallback callback) { 174 gl::GLSurface::SwapCompletionCallback callback) {
127 swap_buffers_completion_callback_ = callback; 175 swap_buffers_completion_callback_ = callback;
128 } 176 }
129 177
130 } // namespace mus 178 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/surfaces/surfaces_context_provider.h ('k') | content/renderer/mus/render_widget_mus_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698