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

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

Issue 2119963002: Move mus to //services/ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/mus/surfaces/surfaces_context_provider.h"
6
7 #include <stddef.h>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/command_line.h"
12 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/thread_task_runner_handle.h"
14 #include "build/build_config.h"
15 #include "components/mus/common/switches.h"
16 #include "components/mus/gles2/command_buffer_driver.h"
17 #include "components/mus/gles2/command_buffer_impl.h"
18 #include "components/mus/gles2/command_buffer_local.h"
19 #include "components/mus/gles2/gpu_state.h"
20 #include "components/mus/gpu/gpu_service_mus.h"
21 #include "components/mus/surfaces/surfaces_context_provider_delegate.h"
22 #include "gpu/command_buffer/client/gles2_cmd_helper.h"
23 #include "gpu/command_buffer/client/gles2_implementation.h"
24 #include "gpu/command_buffer/client/shared_memory_limits.h"
25 #include "gpu/command_buffer/client/transfer_buffer.h"
26 #include "gpu/ipc/client/command_buffer_proxy_impl.h"
27 #include "ui/gl/gpu_preference.h"
28
29 namespace mus {
30
31 SurfacesContextProvider::SurfacesContextProvider(
32 gfx::AcceleratedWidget widget,
33 const scoped_refptr<GpuState>& state)
34 : use_chrome_gpu_command_buffer_(false),
35 delegate_(nullptr),
36 widget_(widget),
37 command_buffer_local_(nullptr) {
38 // TODO(penghuang): Kludge: Use mojo command buffer when running on Windows
39 // since Chrome command buffer breaks unit tests
40 #if defined(OS_WIN)
41 use_chrome_gpu_command_buffer_ = false;
42 #else
43 use_chrome_gpu_command_buffer_ =
44 !base::CommandLine::ForCurrentProcess()->HasSwitch(
45 switches::kUseMojoGpuCommandBufferInMus);
46 #endif
47 if (!use_chrome_gpu_command_buffer_) {
48 command_buffer_local_ = new CommandBufferLocal(this, widget_, state);
49 } else {
50 GpuServiceMus* service = GpuServiceMus::GetInstance();
51 gpu::CommandBufferProxyImpl* shared_command_buffer = nullptr;
52 gpu::GpuStreamId stream_id = gpu::GpuStreamId::GPU_STREAM_DEFAULT;
53 gpu::GpuStreamPriority stream_priority = gpu::GpuStreamPriority::NORMAL;
54 gpu::gles2::ContextCreationAttribHelper attributes;
55 attributes.alpha_size = -1;
56 attributes.depth_size = 0;
57 attributes.stencil_size = 0;
58 attributes.samples = 0;
59 attributes.sample_buffers = 0;
60 attributes.bind_generates_resource = false;
61 attributes.lose_context_when_out_of_memory = true;
62 GURL active_url;
63 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
64 base::ThreadTaskRunnerHandle::Get();
65 command_buffer_proxy_impl_ = gpu::CommandBufferProxyImpl::Create(
66 service->gpu_channel_local(), widget, shared_command_buffer, stream_id,
67 stream_priority, attributes, active_url, task_runner);
68 command_buffer_proxy_impl_->SetSwapBuffersCompletionCallback(
69 base::Bind(&SurfacesContextProvider::OnGpuSwapBuffersCompleted,
70 base::Unretained(this)));
71 command_buffer_proxy_impl_->SetUpdateVSyncParametersCallback(
72 base::Bind(&SurfacesContextProvider::OnUpdateVSyncParameters,
73 base::Unretained(this)));
74 }
75 }
76
77 void SurfacesContextProvider::SetDelegate(
78 SurfacesContextProviderDelegate* delegate) {
79 DCHECK(!delegate_);
80 delegate_ = delegate;
81 }
82
83 // This routine needs to be safe to call more than once.
84 // This is called when we have an accelerated widget.
85 bool SurfacesContextProvider::BindToCurrentThread() {
86 if (implementation_)
87 return true;
88
89 // SurfacesContextProvider should always live on the same thread as the
90 // Window Manager.
91 DCHECK(CalledOnValidThread());
92 gpu::GpuControl* gpu_control = nullptr;
93 gpu::CommandBuffer* command_buffer = nullptr;
94 if (!use_chrome_gpu_command_buffer_) {
95 if (!command_buffer_local_->Initialize())
96 return false;
97 gpu_control = command_buffer_local_;
98 command_buffer = command_buffer_local_;
99 } else {
100 if (!command_buffer_proxy_impl_)
101 return false;
102 gpu_control = command_buffer_proxy_impl_.get();
103 command_buffer = command_buffer_proxy_impl_.get();
104 }
105
106 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer));
107 constexpr gpu::SharedMemoryLimits default_limits;
108 if (!gles2_helper_->Initialize(default_limits.command_buffer_size))
109 return false;
110 gles2_helper_->SetAutomaticFlushes(false);
111 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get()));
112 capabilities_ = gpu_control->GetCapabilities();
113 bool bind_generates_resource =
114 !!capabilities_.bind_generates_resource_chromium;
115 // TODO(piman): Some contexts (such as compositor) want this to be true, so
116 // this needs to be a public parameter.
117 bool lose_context_when_out_of_memory = false;
118 bool support_client_side_arrays = false;
119 implementation_.reset(new gpu::gles2::GLES2Implementation(
120 gles2_helper_.get(), NULL, transfer_buffer_.get(),
121 bind_generates_resource, lose_context_when_out_of_memory,
122 support_client_side_arrays, gpu_control));
123 return implementation_->Initialize(
124 default_limits.start_transfer_buffer_size,
125 default_limits.min_transfer_buffer_size,
126 default_limits.max_transfer_buffer_size,
127 default_limits.mapped_memory_reclaim_limit);
128 }
129
130 gpu::gles2::GLES2Interface* SurfacesContextProvider::ContextGL() {
131 DCHECK(implementation_);
132 return implementation_.get();
133 }
134
135 gpu::ContextSupport* SurfacesContextProvider::ContextSupport() {
136 return implementation_.get();
137 }
138
139 class GrContext* SurfacesContextProvider::GrContext() {
140 return NULL;
141 }
142
143 void SurfacesContextProvider::InvalidateGrContext(uint32_t state) {}
144
145 gpu::Capabilities SurfacesContextProvider::ContextCapabilities() {
146 return capabilities_;
147 }
148
149 base::Lock* SurfacesContextProvider::GetLock() {
150 // This context provider is not used on multiple threads.
151 NOTREACHED();
152 return nullptr;
153 }
154
155 void SurfacesContextProvider::SetLostContextCallback(
156 const LostContextCallback& lost_context_callback) {
157 implementation_->SetLostContextCallback(lost_context_callback);
158 }
159
160 SurfacesContextProvider::~SurfacesContextProvider() {
161 implementation_->Flush();
162 implementation_.reset();
163 transfer_buffer_.reset();
164 gles2_helper_.reset();
165 command_buffer_proxy_impl_.reset();
166 if (command_buffer_local_) {
167 command_buffer_local_->Destroy();
168 command_buffer_local_ = nullptr;
169 }
170 }
171
172 void SurfacesContextProvider::UpdateVSyncParameters(
173 const base::TimeTicks& timebase,
174 const base::TimeDelta& interval) {
175 if (delegate_)
176 delegate_->OnVSyncParametersUpdated(timebase, interval);
177 }
178
179 void SurfacesContextProvider::GpuCompletedSwapBuffers(gfx::SwapResult result) {
180 if (!swap_buffers_completion_callback_.is_null()) {
181 swap_buffers_completion_callback_.Run(result);
182 }
183 }
184
185 void SurfacesContextProvider::OnGpuSwapBuffersCompleted(
186 const std::vector<ui::LatencyInfo>& latency_info,
187 gfx::SwapResult result,
188 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) {
189 if (!swap_buffers_completion_callback_.is_null()) {
190 swap_buffers_completion_callback_.Run(result);
191 }
192 }
193
194 void SurfacesContextProvider::OnUpdateVSyncParameters(
195 base::TimeTicks timebase,
196 base::TimeDelta interval) {
197 if (delegate_)
198 delegate_->OnVSyncParametersUpdated(timebase, interval);
199 }
200
201 void SurfacesContextProvider::SetSwapBuffersCompletionCallback(
202 gl::GLSurface::SwapCompletionCallback callback) {
203 swap_buffers_completion_callback_ = callback;
204 }
205
206 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/surfaces/surfaces_context_provider.h ('k') | components/mus/surfaces/surfaces_context_provider_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698