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

Side by Side Diff: content/browser/android/in_process/synchronous_compositor_factory_impl.cc

Issue 1253553002: Add switch to use ipc command buffer in Android WebView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 5 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
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 "content/browser/android/in_process/synchronous_compositor_factory_impl .h" 5 #include "content/browser/android/in_process/synchronous_compositor_factory_impl .h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/observer_list.h" 8 #include "base/observer_list.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "content/browser/android/in_process/context_provider_in_process.h" 11 #include "content/browser/android/in_process/context_provider_in_process.h"
12 #include "content/browser/android/in_process/synchronous_compositor_external_beg in_frame_source.h" 12 #include "content/browser/android/in_process/synchronous_compositor_external_beg in_frame_source.h"
13 #include "content/browser/android/in_process/synchronous_compositor_impl.h" 13 #include "content/browser/android/in_process/synchronous_compositor_impl.h"
14 #include "content/browser/android/in_process/synchronous_compositor_output_surfa ce.h" 14 #include "content/browser/android/in_process/synchronous_compositor_output_surfa ce.h"
15 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" 15 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
16 #include "content/common/gpu/client/context_provider_command_buffer.h"
17 #include "content/common/gpu/client/gpu_channel_host.h"
18 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
16 #include "content/gpu/in_process_gpu_thread.h" 19 #include "content/gpu/in_process_gpu_thread.h"
17 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/gpu_data_manager.h" 21 #include "content/public/browser/gpu_data_manager.h"
19 #include "content/renderer/gpu/frame_swap_message_queue.h" 22 #include "content/renderer/gpu/frame_swap_message_queue.h"
23 #include "content/renderer/render_thread_impl.h"
20 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" 24 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h"
21 #include "gpu/command_buffer/client/gl_in_process_context.h" 25 #include "gpu/command_buffer/client/gl_in_process_context.h"
22 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 26 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
23 #include "gpu/command_buffer/service/gpu_switches.h" 27 #include "gpu/command_buffer/service/gpu_switches.h"
24 #include "ui/gl/android/surface_texture.h" 28 #include "ui/gl/android/surface_texture.h"
25 #include "ui/gl/gl_surface.h" 29 #include "ui/gl/gl_surface.h"
26 #include "ui/gl/gl_surface_stub.h" 30 #include "ui/gl/gl_surface_stub.h"
27 31
28 using cc_blink::ContextProviderWebContext; 32 using cc_blink::ContextProviderWebContext;
29 using gpu_blink::WebGraphicsContext3DImpl; 33 using gpu_blink::WebGraphicsContext3DImpl;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 ContextHolder holder; 73 ContextHolder holder;
70 holder.command_buffer = 74 holder.command_buffer =
71 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>( 75 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(
72 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( 76 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext(
73 context.Pass(), attributes)); 77 context.Pass(), attributes));
74 holder.gl_in_process_context = context_ptr; 78 holder.gl_in_process_context = context_ptr;
75 79
76 return holder; 80 return holder;
77 } 81 }
78 82
83 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContext3D(
84 const blink::WebGraphicsContext3D::Attributes& attributes,
85 const content::WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits&
86 mem_limits) {
87 DCHECK(RenderThreadImpl::current());
88 CauseForGpuLaunch cause =
89 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
90 scoped_refptr<GpuChannelHost> gpu_channel_host(
91 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
92 CHECK(gpu_channel_host.get());
93
94 int surface_id = 0;
95 bool lose_context_when_out_of_memory = true;
96 return make_scoped_ptr(new WebGraphicsContext3DCommandBufferImpl(
97 surface_id, GURL(), gpu_channel_host.get(), attributes,
98 lose_context_when_out_of_memory, mem_limits, NULL));
99 }
100
79 } // namespace 101 } // namespace
80 102
81 class SynchronousCompositorFactoryImpl::VideoContextProvider 103 class SynchronousCompositorFactoryImpl::VideoContextProvider
82 : public StreamTextureFactorySynchronousImpl::ContextProvider { 104 : public StreamTextureFactorySynchronousImpl::ContextProvider {
83 public: 105 public:
84 VideoContextProvider( 106 VideoContextProvider(
85 scoped_refptr<cc::ContextProvider> context_provider, 107 scoped_refptr<cc::ContextProvider> context_provider,
86 gpu::GLInProcessContext* gl_in_process_context) 108 gpu::GLInProcessContext* gl_in_process_context)
87 : context_provider_(context_provider), 109 : context_provider_(context_provider),
88 gl_in_process_context_(gl_in_process_context) { 110 gl_in_process_context_(gl_in_process_context) {
(...skipping 27 matching lines...) Expand all
116 friend class base::RefCountedThreadSafe<VideoContextProvider>; 138 friend class base::RefCountedThreadSafe<VideoContextProvider>;
117 ~VideoContextProvider() override {} 139 ~VideoContextProvider() override {}
118 140
119 scoped_refptr<cc::ContextProvider> context_provider_; 141 scoped_refptr<cc::ContextProvider> context_provider_;
120 gpu::GLInProcessContext* gl_in_process_context_; 142 gpu::GLInProcessContext* gl_in_process_context_;
121 base::ObserverList<StreamTextureFactoryContextObserver> observer_list_; 143 base::ObserverList<StreamTextureFactoryContextObserver> observer_list_;
122 144
123 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider); 145 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider);
124 }; 146 };
125 147
126
127 SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() 148 SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl()
128 : record_full_layer_(true), 149 : record_full_layer_(true),
150 use_ipc_command_buffer_(false),
129 num_hardware_compositors_(0) { 151 num_hardware_compositors_(0) {
130 SynchronousCompositorFactory::SetInstance(this); 152 SynchronousCompositorFactory::SetInstance(this);
131 } 153 }
132 154
133 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} 155 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {}
134 156
135 scoped_refptr<base::SingleThreadTaskRunner> 157 scoped_refptr<base::SingleThreadTaskRunner>
136 SynchronousCompositorFactoryImpl::GetCompositorTaskRunner() { 158 SynchronousCompositorFactoryImpl::GetCompositorTaskRunner() {
137 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); 159 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
138 } 160 }
139 161
140 bool 162 bool
141 SynchronousCompositorFactoryImpl::RecordFullLayer() { 163 SynchronousCompositorFactoryImpl::RecordFullLayer() {
142 return record_full_layer_; 164 return record_full_layer_;
143 } 165 }
144 166
145 scoped_ptr<cc::OutputSurface> 167 scoped_ptr<cc::OutputSurface>
146 SynchronousCompositorFactoryImpl::CreateOutputSurface( 168 SynchronousCompositorFactoryImpl::CreateOutputSurface(
147 int routing_id, 169 int routing_id,
148 scoped_refptr<content::FrameSwapMessageQueue> frame_swap_message_queue) { 170 scoped_refptr<content::FrameSwapMessageQueue> frame_swap_message_queue) {
149 scoped_refptr<cc::ContextProvider> onscreen_context = 171 scoped_refptr<cc::ContextProvider> onscreen_context =
150 CreateContextProviderForCompositor(); 172 CreateContextProviderForCompositor(RENDER_COMPOSITOR_CONTEXT);
151 scoped_refptr<cc::ContextProvider> worker_context = 173 scoped_refptr<cc::ContextProvider> worker_context =
152 CreateContextProviderForCompositor(); 174 CreateContextProviderForCompositor(RENDER_WORKER_CONTEXT);
153 175
154 return make_scoped_ptr(new SynchronousCompositorOutputSurface( 176 return make_scoped_ptr(new SynchronousCompositorOutputSurface(
155 onscreen_context, worker_context, routing_id, frame_swap_message_queue)); 177 onscreen_context, worker_context, routing_id, frame_swap_message_queue));
156 } 178 }
157 179
158 InputHandlerManagerClient* 180 InputHandlerManagerClient*
159 SynchronousCompositorFactoryImpl::GetInputHandlerManagerClient() { 181 SynchronousCompositorFactoryImpl::GetInputHandlerManagerClient() {
160 return synchronous_input_event_filter(); 182 return synchronous_input_event_filter();
161 } 183 }
162 184
163 scoped_ptr<cc::BeginFrameSource> 185 scoped_ptr<cc::BeginFrameSource>
164 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource( 186 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource(
165 int routing_id) { 187 int routing_id) {
166 return make_scoped_ptr( 188 return make_scoped_ptr(
167 new SynchronousCompositorExternalBeginFrameSource(routing_id)); 189 new SynchronousCompositorExternalBeginFrameSource(routing_id));
168 } 190 }
169 191
192 bool SynchronousCompositorFactoryImpl::OverrideWithFactory() {
193 return !use_ipc_command_buffer_;
194 }
195
170 scoped_refptr<ContextProviderWebContext> 196 scoped_refptr<ContextProviderWebContext>
171 SynchronousCompositorFactoryImpl::CreateOffscreenContextProvider( 197 SynchronousCompositorFactoryImpl::CreateOffscreenContextProvider(
172 const blink::WebGraphicsContext3D::Attributes& attributes, 198 const blink::WebGraphicsContext3D::Attributes& attributes,
173 const std::string& debug_name) { 199 const std::string& debug_name) {
200 DCHECK(!use_ipc_command_buffer_);
174 ContextHolder holder = 201 ContextHolder holder =
175 CreateContextHolder(attributes, GpuThreadService(), 202 CreateContextHolder(attributes, GpuThreadService(),
176 gpu::GLInProcessContextSharedMemoryLimits(), true); 203 gpu::GLInProcessContextSharedMemoryLimits(), true);
177 return ContextProviderInProcess::Create(holder.command_buffer.Pass(), 204 return ContextProviderInProcess::Create(holder.command_buffer.Pass(),
178 debug_name); 205 debug_name);
179 } 206 }
180 207
181 scoped_refptr<cc::ContextProvider> 208 scoped_refptr<cc::ContextProvider>
182 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor() { 209 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor(
210 CommandBufferContextType type) {
211 // This is half of what RenderWidget uses because synchronous compositor
212 // pipeline is only one frame deep. But twice of half for low end here
213 // because 16bit texture is not supported.
214 unsigned int mapped_memory_reclaim_limit =
215 (base::SysInfo::IsLowEndDevice() ? 2 : 6) * 1024 * 1024;
183 blink::WebGraphicsContext3D::Attributes attributes = GetDefaultAttribs(); 216 blink::WebGraphicsContext3D::Attributes attributes = GetDefaultAttribs();
217
218 if (use_ipc_command_buffer_) {
219 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits mem_limits;
220 mem_limits.mapped_memory_reclaim_limit = mapped_memory_reclaim_limit;
221 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context =
222 CreateContext3D(GetDefaultAttribs(), mem_limits);
223 return ContextProviderCommandBuffer::Create(context.Pass(), type);
224 }
225
184 gpu::GLInProcessContextSharedMemoryLimits mem_limits; 226 gpu::GLInProcessContextSharedMemoryLimits mem_limits;
185 // This is half of what RenderWidget uses because synchronous compositor 227 mem_limits.mapped_memory_reclaim_limit = mapped_memory_reclaim_limit;
186 // pipeline is only one frame deep.
187 if (base::SysInfo::IsLowEndDevice()) {
188 // But twice of half here because 16bit texture is not supported.
189 mem_limits.mapped_memory_reclaim_limit = 2 * 1024 * 1024;
190 } else {
191 mem_limits.mapped_memory_reclaim_limit = 6 * 1024 * 1024;
192 }
193 ContextHolder holder = 228 ContextHolder holder =
194 CreateContextHolder(attributes, GpuThreadService(), mem_limits, true); 229 CreateContextHolder(attributes, GpuThreadService(), mem_limits, true);
195 return ContextProviderInProcess::Create(holder.command_buffer.Pass(), 230 return ContextProviderInProcess::Create(holder.command_buffer.Pass(),
196 "Child-Compositor"); 231 "Child-Compositor");
197 } 232 }
198 233
199 scoped_refptr<StreamTextureFactory> 234 scoped_refptr<StreamTextureFactory>
200 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { 235 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) {
201 scoped_refptr<StreamTextureFactorySynchronousImpl> factory( 236 scoped_refptr<StreamTextureFactorySynchronousImpl> factory(
202 StreamTextureFactorySynchronousImpl::Create( 237 StreamTextureFactorySynchronousImpl::Create(
203 base::Bind( 238 base::Bind(
204 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, 239 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory,
205 base::Unretained(this)), 240 base::Unretained(this)),
206 frame_id)); 241 frame_id));
207 return factory; 242 return factory;
208 } 243 }
209 244
210 WebGraphicsContext3DInProcessCommandBufferImpl* 245 WebGraphicsContext3DInProcessCommandBufferImpl*
211 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( 246 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D(
212 const blink::WebGraphicsContext3D::Attributes& attributes) { 247 const blink::WebGraphicsContext3D::Attributes& attributes) {
248 DCHECK(!use_ipc_command_buffer_);
213 ContextHolder holder = 249 ContextHolder holder =
214 CreateContextHolder(attributes, GpuThreadService(), 250 CreateContextHolder(attributes, GpuThreadService(),
215 gpu::GLInProcessContextSharedMemoryLimits(), true); 251 gpu::GLInProcessContextSharedMemoryLimits(), true);
216 return holder.command_buffer.release(); 252 return holder.command_buffer.release();
217 } 253 }
218 254
219 gpu::GPUInfo SynchronousCompositorFactoryImpl::GetGPUInfo() const { 255 gpu::GPUInfo SynchronousCompositorFactoryImpl::GetGPUInfo() const {
256 DCHECK(!use_ipc_command_buffer_);
220 return content::GpuDataManager::GetInstance()->GetGPUInfo(); 257 return content::GpuDataManager::GetInstance()->GetGPUInfo();
221 } 258 }
222 259
223 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { 260 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() {
224 base::AutoLock lock(num_hardware_compositor_lock_); 261 base::AutoLock lock(num_hardware_compositor_lock_);
225 num_hardware_compositors_++; 262 num_hardware_compositors_++;
226 if (num_hardware_compositors_ == 1 && main_thread_task_runner_.get()) { 263 if (num_hardware_compositors_ == 1 && main_thread_task_runner_.get()) {
227 main_thread_task_runner_->PostTask( 264 main_thread_task_runner_->PostTask(
228 FROM_HERE, 265 FROM_HERE,
229 base::Bind( 266 base::Bind(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 android_view_service_->sync_point_manager()); 341 android_view_service_->sync_point_manager());
305 } 342 }
306 return gpu_thread_service_; 343 return gpu_thread_service_;
307 } 344 }
308 345
309 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( 346 void SynchronousCompositorFactoryImpl::SetRecordFullDocument(
310 bool record_full_document) { 347 bool record_full_document) {
311 record_full_layer_ = record_full_document; 348 record_full_layer_ = record_full_document;
312 } 349 }
313 350
351 void SynchronousCompositorFactoryImpl::SetUseIpcCommandBuffer() {
352 use_ipc_command_buffer_ = true;
353 }
354
314 } // namespace content 355 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698