| 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 "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" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 ContextHolder holder; | 74 ContextHolder holder; |
| 75 holder.command_buffer = | 75 holder.command_buffer = |
| 76 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>( | 76 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>( |
| 77 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( | 77 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( |
| 78 context.Pass(), attributes)); | 78 context.Pass(), attributes)); |
| 79 holder.gl_in_process_context = context_ptr; | 79 holder.gl_in_process_context = context_ptr; |
| 80 | 80 |
| 81 return holder; | 81 return holder; |
| 82 } | 82 } |
| 83 | 83 |
| 84 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContext3D( | |
| 85 int surface_id, | |
| 86 const blink::WebGraphicsContext3D::Attributes& attributes, | |
| 87 const content::WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits& | |
| 88 mem_limits) { | |
| 89 DCHECK(RenderThreadImpl::current()); | |
| 90 CauseForGpuLaunch cause = | |
| 91 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | |
| 92 scoped_refptr<GpuChannelHost> gpu_channel_host( | |
| 93 RenderThreadImpl::current()->EstablishGpuChannelSync(cause)); | |
| 94 CHECK(gpu_channel_host.get()); | |
| 95 | |
| 96 bool lose_context_when_out_of_memory = true; | |
| 97 return make_scoped_ptr(new WebGraphicsContext3DCommandBufferImpl( | |
| 98 surface_id, GURL(), gpu_channel_host.get(), attributes, | |
| 99 lose_context_when_out_of_memory, mem_limits, NULL)); | |
| 100 } | |
| 101 | |
| 102 } // namespace | 84 } // namespace |
| 103 | 85 |
| 104 class SynchronousCompositorFactoryImpl::VideoContextProvider | 86 class SynchronousCompositorFactoryImpl::VideoContextProvider |
| 105 : public StreamTextureFactorySynchronousImpl::ContextProvider { | 87 : public StreamTextureFactorySynchronousImpl::ContextProvider { |
| 106 public: | 88 public: |
| 107 VideoContextProvider( | 89 VideoContextProvider( |
| 108 scoped_refptr<cc::ContextProvider> context_provider, | 90 scoped_refptr<cc::ContextProvider> context_provider, |
| 109 gpu::GLInProcessContext* gl_in_process_context) | 91 gpu::GLInProcessContext* gl_in_process_context) |
| 110 : context_provider_(context_provider), | 92 : context_provider_(context_provider), |
| 111 gl_in_process_context_(gl_in_process_context) { | 93 gl_in_process_context_(gl_in_process_context) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} | 140 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} |
| 159 | 141 |
| 160 scoped_refptr<base::SingleThreadTaskRunner> | 142 scoped_refptr<base::SingleThreadTaskRunner> |
| 161 SynchronousCompositorFactoryImpl::GetCompositorTaskRunner() { | 143 SynchronousCompositorFactoryImpl::GetCompositorTaskRunner() { |
| 162 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | 144 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
| 163 } | 145 } |
| 164 | 146 |
| 165 scoped_ptr<cc::OutputSurface> | 147 scoped_ptr<cc::OutputSurface> |
| 166 SynchronousCompositorFactoryImpl::CreateOutputSurface( | 148 SynchronousCompositorFactoryImpl::CreateOutputSurface( |
| 167 int routing_id, | 149 int routing_id, |
| 168 scoped_refptr<content::FrameSwapMessageQueue> frame_swap_message_queue) { | 150 const scoped_refptr<FrameSwapMessageQueue>& frame_swap_message_queue, |
| 169 scoped_refptr<cc::ContextProvider> onscreen_context = | 151 const scoped_refptr<cc::ContextProvider>& onscreen_context, |
| 170 CreateContextProviderForCompositor(0, RENDER_COMPOSITOR_CONTEXT); | 152 const scoped_refptr<cc::ContextProvider>& worker_context) { |
| 171 scoped_refptr<cc::ContextProvider> worker_context = | |
| 172 GetSharedWorkerContextProvider(); | |
| 173 return make_scoped_ptr(new SynchronousCompositorOutputSurface( | 153 return make_scoped_ptr(new SynchronousCompositorOutputSurface( |
| 174 onscreen_context, worker_context, routing_id, | 154 onscreen_context, worker_context, routing_id, |
| 175 SynchronousCompositorRegistryInProc::GetInstance(), | 155 SynchronousCompositorRegistryInProc::GetInstance(), |
| 176 frame_swap_message_queue)); | 156 frame_swap_message_queue)); |
| 177 } | 157 } |
| 178 | 158 |
| 179 InputHandlerManagerClient* | 159 InputHandlerManagerClient* |
| 180 SynchronousCompositorFactoryImpl::GetInputHandlerManagerClient() { | 160 SynchronousCompositorFactoryImpl::GetInputHandlerManagerClient() { |
| 181 return synchronous_input_event_filter(); | 161 return synchronous_input_event_filter(); |
| 182 } | 162 } |
| 183 | 163 |
| 184 scoped_ptr<cc::BeginFrameSource> | 164 scoped_ptr<cc::BeginFrameSource> |
| 185 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource( | 165 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource( |
| 186 int routing_id) { | 166 int routing_id) { |
| 187 return make_scoped_ptr(new SynchronousCompositorExternalBeginFrameSource( | 167 return make_scoped_ptr(new SynchronousCompositorExternalBeginFrameSource( |
| 188 routing_id, SynchronousCompositorRegistryInProc::GetInstance())); | 168 routing_id, SynchronousCompositorRegistryInProc::GetInstance())); |
| 189 } | 169 } |
| 190 | 170 |
| 191 scoped_refptr<cc::ContextProvider> | |
| 192 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor( | |
| 193 int surface_id, | |
| 194 CommandBufferContextType type) { | |
| 195 // This is half of what RenderWidget uses because synchronous compositor | |
| 196 // pipeline is only one frame deep. But twice of half for low end here | |
| 197 // because 16bit texture is not supported. | |
| 198 // TODO(reveman): This limit is based on the usage required by async | |
| 199 // uploads. Determine what a good limit is now that async uploads are | |
| 200 // no longer used. | |
| 201 unsigned int mapped_memory_reclaim_limit = | |
| 202 (base::SysInfo::IsLowEndDevice() ? 2 : 6) * 1024 * 1024; | |
| 203 blink::WebGraphicsContext3D::Attributes attributes = GetDefaultAttribs(); | |
| 204 | |
| 205 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits mem_limits; | |
| 206 mem_limits.mapped_memory_reclaim_limit = mapped_memory_reclaim_limit; | |
| 207 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context = | |
| 208 CreateContext3D(surface_id, GetDefaultAttribs(), mem_limits); | |
| 209 return ContextProviderCommandBuffer::Create(context.Pass(), type); | |
| 210 } | |
| 211 | |
| 212 scoped_refptr<cc::ContextProvider> | |
| 213 SynchronousCompositorFactoryImpl::GetSharedWorkerContextProvider() { | |
| 214 // TODO(reveman): This limit is based on the usage required by async | |
| 215 // uploads. Determine what a good limit is now that async uploads are | |
| 216 // no longer used. | |
| 217 unsigned int mapped_memory_reclaim_limit = | |
| 218 (base::SysInfo::IsLowEndDevice() ? 2 : 6) * 1024 * 1024; | |
| 219 | |
| 220 bool shared_worker_context_lost = false; | |
| 221 if (shared_worker_context_) { | |
| 222 // Note: If context is lost, we delete reference after releasing the lock. | |
| 223 base::AutoLock lock(*shared_worker_context_->GetLock()); | |
| 224 if (shared_worker_context_->ContextGL()->GetGraphicsResetStatusKHR() != | |
| 225 GL_NO_ERROR) { | |
| 226 shared_worker_context_lost = true; | |
| 227 } | |
| 228 } | |
| 229 if (!shared_worker_context_ || shared_worker_context_lost) { | |
| 230 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits mem_limits; | |
| 231 mem_limits.mapped_memory_reclaim_limit = mapped_memory_reclaim_limit; | |
| 232 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context = | |
| 233 CreateContext3D(0, GetDefaultAttribs(), mem_limits); | |
| 234 shared_worker_context_ = ContextProviderCommandBuffer::Create( | |
| 235 context.Pass(), RENDER_WORKER_CONTEXT); | |
| 236 if (!shared_worker_context_->BindToCurrentThread()) | |
| 237 shared_worker_context_ = nullptr; | |
| 238 if (shared_worker_context_) | |
| 239 shared_worker_context_->SetupLock(); | |
| 240 } | |
| 241 | |
| 242 return shared_worker_context_; | |
| 243 } | |
| 244 | |
| 245 scoped_refptr<StreamTextureFactory> | 171 scoped_refptr<StreamTextureFactory> |
| 246 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { | 172 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { |
| 247 scoped_refptr<StreamTextureFactorySynchronousImpl> factory( | 173 scoped_refptr<StreamTextureFactorySynchronousImpl> factory( |
| 248 StreamTextureFactorySynchronousImpl::Create( | 174 StreamTextureFactorySynchronousImpl::Create( |
| 249 base::Bind( | 175 base::Bind( |
| 250 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, | 176 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, |
| 251 base::Unretained(this)), | 177 base::Unretained(this)), |
| 252 frame_id)); | 178 frame_id)); |
| 253 return factory; | 179 return factory; |
| 254 } | 180 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 248 } |
| 323 | 249 |
| 324 base::Thread* SynchronousCompositorFactoryImpl::CreateInProcessGpuThread( | 250 base::Thread* SynchronousCompositorFactoryImpl::CreateInProcessGpuThread( |
| 325 const InProcessChildThreadParams& params) { | 251 const InProcessChildThreadParams& params) { |
| 326 DCHECK(android_view_service_.get()); | 252 DCHECK(android_view_service_.get()); |
| 327 return new InProcessGpuThread(params, | 253 return new InProcessGpuThread(params, |
| 328 android_view_service_->sync_point_manager()); | 254 android_view_service_->sync_point_manager()); |
| 329 } | 255 } |
| 330 | 256 |
| 331 } // namespace content | 257 } // namespace content |
| OLD | NEW |