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 "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 "content/browser/android/in_process/synchronous_compositor_external_beg in_frame_source.h" | 9 #include "content/browser/android/in_process/synchronous_compositor_external_beg in_frame_source.h" |
| 10 #include "content/browser/android/in_process/synchronous_compositor_impl.h" | 10 #include "content/browser/android/in_process/synchronous_compositor_impl.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 blink::WebGraphicsContext3D::Attributes attributes; | 32 blink::WebGraphicsContext3D::Attributes attributes; |
| 33 attributes.antialias = false; | 33 attributes.antialias = false; |
| 34 attributes.depth = false; | 34 attributes.depth = false; |
| 35 attributes.stencil = false; | 35 attributes.stencil = false; |
| 36 attributes.shareResources = true; | 36 attributes.shareResources = true; |
| 37 attributes.noAutomaticFlushes = true; | 37 attributes.noAutomaticFlushes = true; |
| 38 | 38 |
| 39 return attributes; | 39 return attributes; |
| 40 } | 40 } |
| 41 | 41 |
| 42 scoped_ptr<gpu::GLInProcessContext> CreateOffscreenContext( | |
| 43 const blink::WebGraphicsContext3D::Attributes& attributes) { | |
| 44 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | |
| 45 | |
| 46 gpu::gles2::ContextCreationAttribHelper in_process_attribs; | |
| 47 WebGraphicsContext3DImpl::ConvertAttributes( | |
| 48 attributes, &in_process_attribs); | |
| 49 in_process_attribs.lose_context_when_out_of_memory = true; | |
| 50 | |
| 51 scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create( | |
| 52 NULL /* service */, | |
| 53 NULL /* surface */, | |
| 54 true /* is_offscreen */, | |
| 55 gfx::kNullAcceleratedWidget, | |
| 56 gfx::Size(1, 1), | |
| 57 NULL /* share_context */, | |
| 58 attributes.shareResources, | |
| 59 in_process_attribs, | |
| 60 gpu_preference, | |
| 61 gpu::GLInProcessContextSharedMemoryLimits(), | |
| 62 nullptr, | |
| 63 nullptr)); | |
| 64 return context.Pass(); | |
| 65 } | |
| 66 | |
| 67 scoped_ptr<gpu::GLInProcessContext> CreateContext( | |
| 68 scoped_refptr<gpu::InProcessCommandBuffer::Service> service, | |
| 69 const gpu::GLInProcessContextSharedMemoryLimits& mem_limits, | |
| 70 bool is_offscreen, | |
| 71 bool share_resources) { | |
| 72 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | |
| 73 gpu::gles2::ContextCreationAttribHelper in_process_attribs; | |
| 74 WebGraphicsContext3DImpl::ConvertAttributes( | |
| 75 GetDefaultAttribs(), &in_process_attribs); | |
| 76 in_process_attribs.lose_context_when_out_of_memory = true; | |
| 77 | |
| 78 scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create( | |
| 79 service, | |
| 80 NULL /* surface */, | |
| 81 is_offscreen, | |
| 82 gfx::kNullAcceleratedWidget, | |
| 83 gfx::Size(1, 1), | |
| 84 NULL /* share_context */, | |
| 85 share_resources /* share_resources */, | |
| 86 in_process_attribs, | |
| 87 gpu_preference, | |
| 88 mem_limits, | |
| 89 nullptr, | |
| 90 nullptr)); | |
| 91 return context.Pass(); | |
| 92 } | |
| 93 | |
| 94 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> WrapContext( | |
| 95 scoped_ptr<gpu::GLInProcessContext> context) { | |
| 96 if (!context.get()) | |
| 97 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(); | |
| 98 | |
| 99 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>( | |
| 100 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( | |
| 101 context.Pass(), GetDefaultAttribs())); | |
| 102 } | |
| 103 | |
| 104 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> | 42 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> |
| 105 WrapContextWithAttributes( | 43 WrapContextWithAttributes( |
| 106 scoped_ptr<gpu::GLInProcessContext> context, | 44 scoped_ptr<gpu::GLInProcessContext> context, |
| 107 const blink::WebGraphicsContext3D::Attributes& attributes) { | 45 const blink::WebGraphicsContext3D::Attributes& attributes) { |
| 108 if (!context.get()) | 46 if (!context.get()) |
| 109 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(); | 47 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(); |
| 110 | 48 |
| 111 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>( | 49 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>( |
| 112 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( | 50 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( |
| 113 context.Pass(), attributes)); | 51 context.Pass(), attributes)); |
| 114 } | 52 } |
| 115 | 53 |
| 116 } // namespace | 54 } // namespace |
| 117 | 55 |
| 118 class SynchronousCompositorFactoryImpl::VideoContextProvider | 56 class SynchronousCompositorFactoryImpl::VideoContextProvider |
| 119 : public StreamTextureFactorySynchronousImpl::ContextProvider { | 57 : public StreamTextureFactorySynchronousImpl::ContextProvider { |
| 120 public: | 58 public: |
| 121 VideoContextProvider( | 59 VideoContextProvider( |
| 122 scoped_ptr<gpu::GLInProcessContext> gl_in_process_context) | 60 scoped_refptr<ContextProviderWebContext> context_provider, |
| 123 : gl_in_process_context_(gl_in_process_context.get()) { | 61 gpu::GLInProcessContext* context) |
| 124 | 62 : context_provider_(context_provider), |
| 125 context_provider_ = webkit::gpu::ContextProviderInProcess::Create( | 63 gl_in_process_context_(context) { |
| 126 WrapContext(gl_in_process_context.Pass()), | |
| 127 "Video-Offscreen-main-thread"); | |
| 128 context_provider_->BindToCurrentThread(); | 64 context_provider_->BindToCurrentThread(); |
| 129 } | 65 } |
| 130 | 66 |
| 131 scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( | 67 scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( |
| 132 uint32 stream_id) override { | 68 uint32 stream_id) override { |
| 133 return gl_in_process_context_->GetSurfaceTexture(stream_id); | 69 return gl_in_process_context_->GetSurfaceTexture(stream_id); |
| 134 } | 70 } |
| 135 | 71 |
| 136 gpu::gles2::GLES2Interface* ContextGL() override { | 72 gpu::gles2::GLES2Interface* ContextGL() override { |
| 137 return context_provider_->ContextGL(); | 73 return context_provider_->ContextGL(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 148 void RestoreContext() { | 84 void RestoreContext() { |
| 149 FOR_EACH_OBSERVER(StreamTextureFactoryContextObserver, | 85 FOR_EACH_OBSERVER(StreamTextureFactoryContextObserver, |
| 150 observer_list_, | 86 observer_list_, |
| 151 ResetStreamTextureProxy()); | 87 ResetStreamTextureProxy()); |
| 152 } | 88 } |
| 153 | 89 |
| 154 private: | 90 private: |
| 155 friend class base::RefCountedThreadSafe<VideoContextProvider>; | 91 friend class base::RefCountedThreadSafe<VideoContextProvider>; |
| 156 ~VideoContextProvider() override {} | 92 ~VideoContextProvider() override {} |
| 157 | 93 |
| 158 scoped_refptr<cc::ContextProvider> context_provider_; | 94 scoped_refptr<ContextProviderWebContext> context_provider_; |
|
boliu
2015/03/09 02:17:54
nit: This doesn't need to change
| |
| 159 gpu::GLInProcessContext* gl_in_process_context_; | 95 gpu::GLInProcessContext* gl_in_process_context_; |
| 160 ObserverList<StreamTextureFactoryContextObserver> observer_list_; | 96 ObserverList<StreamTextureFactoryContextObserver> observer_list_; |
| 161 | 97 |
| 162 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider); | 98 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider); |
| 163 }; | 99 }; |
| 164 | 100 |
| 165 | 101 |
| 166 SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() | 102 SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() |
| 167 : record_full_layer_(true), | 103 : record_full_layer_(true), |
| 168 num_hardware_compositors_(0) { | 104 num_hardware_compositors_(0) { |
| 169 SynchronousCompositorFactory::SetInstance(this); | 105 SynchronousCompositorFactory::SetInstance(this); |
| 170 } | 106 } |
| 171 | 107 |
| 172 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} | 108 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} |
| 173 | 109 |
| 174 scoped_refptr<base::MessageLoopProxy> | 110 scoped_refptr<base::MessageLoopProxy> |
| 175 SynchronousCompositorFactoryImpl::GetCompositorMessageLoop() { | 111 SynchronousCompositorFactoryImpl::GetCompositorMessageLoop() { |
| 176 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | 112 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
| 177 } | 113 } |
| 178 | 114 |
| 179 bool | 115 bool SynchronousCompositorFactoryImpl::RecordFullLayer() { |
| 180 SynchronousCompositorFactoryImpl::RecordFullLayer() { | |
| 181 return record_full_layer_; | 116 return record_full_layer_; |
| 182 } | 117 } |
| 183 | 118 |
| 184 scoped_ptr<cc::OutputSurface> | 119 scoped_ptr<cc::OutputSurface> |
| 185 SynchronousCompositorFactoryImpl::CreateOutputSurface( | 120 SynchronousCompositorFactoryImpl::CreateOutputSurface( |
| 186 int routing_id, | 121 int routing_id, |
| 187 scoped_refptr<content::FrameSwapMessageQueue> frame_swap_message_queue) { | 122 scoped_refptr<content::FrameSwapMessageQueue> frame_swap_message_queue) { |
| 188 scoped_ptr<SynchronousCompositorOutputSurface> output_surface( | 123 scoped_ptr<SynchronousCompositorOutputSurface> output_surface( |
| 189 new SynchronousCompositorOutputSurface(routing_id, | 124 new SynchronousCompositorOutputSurface(routing_id, |
| 190 frame_swap_message_queue)); | 125 frame_swap_message_queue)); |
| 191 return output_surface.Pass(); | 126 return output_surface.Pass(); |
| 192 } | 127 } |
| 193 | 128 |
| 194 InputHandlerManagerClient* | 129 InputHandlerManagerClient* |
| 195 SynchronousCompositorFactoryImpl::GetInputHandlerManagerClient() { | 130 SynchronousCompositorFactoryImpl::GetInputHandlerManagerClient() { |
| 196 return synchronous_input_event_filter(); | 131 return synchronous_input_event_filter(); |
| 197 } | 132 } |
| 198 | 133 |
| 199 scoped_ptr<cc::BeginFrameSource> | 134 scoped_ptr<cc::BeginFrameSource> |
| 200 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource( | 135 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource( |
| 201 int routing_id) { | 136 int routing_id) { |
| 202 return make_scoped_ptr( | 137 return make_scoped_ptr( |
| 203 new SynchronousCompositorExternalBeginFrameSource(routing_id)); | 138 new SynchronousCompositorExternalBeginFrameSource(routing_id)); |
| 204 } | 139 } |
| 205 | 140 |
| 206 scoped_refptr<ContextProviderWebContext> | 141 scoped_refptr<ContextProviderWebContext> |
| 207 SynchronousCompositorFactoryImpl::CreateOffscreenContextProvider( | 142 SynchronousCompositorFactoryImpl::CreateOffscreenContextProvider( |
| 208 const blink::WebGraphicsContext3D::Attributes& attributes, | 143 const blink::WebGraphicsContext3D::Attributes& attributes, |
| 209 const std::string& debug_name) { | 144 const std::string& debug_name) { |
| 210 scoped_ptr<gpu::GLInProcessContext> context = | 145 return callback_.Run(false, attributes, true, |
| 211 CreateOffscreenContext(attributes); | 146 gpu::GLInProcessContextSharedMemoryLimits()) |
| 212 return webkit::gpu::ContextProviderInProcess::Create( | 147 .context_provider; |
| 213 WrapContext(context.Pass()), debug_name); | |
| 214 } | 148 } |
| 215 | 149 |
| 216 scoped_refptr<cc::ContextProvider> | 150 scoped_refptr<cc::ContextProvider> |
| 217 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor() { | 151 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor() { |
| 218 DCHECK(service_.get()); | |
| 219 | |
| 220 gpu::GLInProcessContextSharedMemoryLimits mem_limits; | 152 gpu::GLInProcessContextSharedMemoryLimits mem_limits; |
| 221 // This is half of what RenderWidget uses because synchronous compositor | 153 // This is half of what RenderWidget uses because synchronous compositor |
| 222 // pipeline is only one frame deep. | 154 // pipeline is only one frame deep. |
| 223 mem_limits.mapped_memory_reclaim_limit = 6 * 1024 * 1024; | 155 mem_limits.mapped_memory_reclaim_limit = 6 * 1024 * 1024; |
| 224 return webkit::gpu::ContextProviderInProcess::Create( | 156 return callback_.Run(false, GetDefaultAttribs(), true, mem_limits) |
| 225 WrapContext(CreateContext(nullptr, mem_limits, true, true)), | 157 .context_provider; |
| 226 "Child-Compositor"); | |
| 227 } | 158 } |
| 228 | 159 |
| 229 scoped_refptr<StreamTextureFactory> | 160 scoped_refptr<StreamTextureFactory> |
| 230 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { | 161 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { |
| 231 scoped_refptr<StreamTextureFactorySynchronousImpl> factory( | 162 scoped_refptr<StreamTextureFactorySynchronousImpl> factory( |
| 232 StreamTextureFactorySynchronousImpl::Create( | 163 StreamTextureFactorySynchronousImpl::Create( |
| 233 base::Bind( | 164 base::Bind( |
| 234 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, | 165 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, |
| 235 base::Unretained(this)), | 166 base::Unretained(this)), |
| 236 frame_id)); | 167 frame_id)); |
| 237 return factory; | 168 return factory; |
| 238 } | 169 } |
| 239 | 170 |
| 240 WebGraphicsContext3DInProcessCommandBufferImpl* | 171 WebGraphicsContext3DInProcessCommandBufferImpl* |
| 241 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( | 172 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( |
| 242 const blink::WebGraphicsContext3D::Attributes& attributes) { | 173 const blink::WebGraphicsContext3D::Attributes& attributes) { |
| 243 return WrapContextWithAttributes(CreateOffscreenContext(attributes), | 174 return WrapContextWithAttributes( |
| 244 attributes).release(); | 175 make_scoped_ptr( |
| 176 callback_.Run(false, attributes, true, | |
| 177 gpu::GLInProcessContextSharedMemoryLimits()) | |
| 178 .context), | |
| 179 attributes).release(); | |
| 245 } | 180 } |
| 246 | 181 |
| 247 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { | 182 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { |
| 248 base::AutoLock lock(num_hardware_compositor_lock_); | 183 base::AutoLock lock(num_hardware_compositor_lock_); |
| 249 num_hardware_compositors_++; | 184 num_hardware_compositors_++; |
| 250 if (num_hardware_compositors_ == 1 && main_thread_proxy_.get()) { | 185 if (num_hardware_compositors_ == 1 && main_thread_proxy_.get()) { |
| 251 main_thread_proxy_->PostTask( | 186 main_thread_proxy_->PostTask( |
| 252 FROM_HERE, | 187 FROM_HERE, |
| 253 base::Bind( | 188 base::Bind( |
| 254 &SynchronousCompositorFactoryImpl::RestoreContextOnMainThread, | 189 &SynchronousCompositorFactoryImpl::RestoreContextOnMainThread, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 277 { | 212 { |
| 278 base::AutoLock lock(num_hardware_compositor_lock_); | 213 base::AutoLock lock(num_hardware_compositor_lock_); |
| 279 main_thread_proxy_ = base::MessageLoopProxy::current(); | 214 main_thread_proxy_ = base::MessageLoopProxy::current(); |
| 280 } | 215 } |
| 281 | 216 |
| 282 // Always fail creation even if |video_context_provider_| is not NULL. | 217 // Always fail creation even if |video_context_provider_| is not NULL. |
| 283 // This is to avoid synchronous calls that may deadlock. Setting | 218 // This is to avoid synchronous calls that may deadlock. Setting |
| 284 // |video_context_provider_| to null is also not safe since it makes | 219 // |video_context_provider_| to null is also not safe since it makes |
| 285 // synchronous destruction uncontrolled and possibly deadlock. | 220 // synchronous destruction uncontrolled and possibly deadlock. |
| 286 if (!CanCreateMainThreadContext()) { | 221 if (!CanCreateMainThreadContext()) { |
| 287 return | 222 return scoped_refptr< |
| 288 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); | 223 StreamTextureFactorySynchronousImpl::ContextProvider>(); |
| 289 } | 224 } |
| 290 | 225 |
| 291 if (!video_context_provider_.get()) { | 226 if (!video_context_provider_.get()) { |
| 292 DCHECK(service_.get()); | 227 blink::WebGraphicsContext3D::Attributes attributes = GetDefaultAttribs(); |
| 293 | 228 attributes.shareResources = true; |
| 294 // This needs to run in on-screen |service_| context due to SurfaceTexture | 229 SynchronousCompositor::ContextHolder holder = callback_.Run( |
| 230 true, attributes, false, gpu::GLInProcessContextSharedMemoryLimits()); | |
| 231 // This needs to run in on-screen context due to SurfaceTexture | |
| 295 // limitations. | 232 // limitations. |
| 296 video_context_provider_ = new VideoContextProvider(CreateContext( | 233 video_context_provider_ = |
| 297 service_, gpu::GLInProcessContextSharedMemoryLimits(), false, false)); | 234 new VideoContextProvider(holder.context_provider, holder.context); |
| 298 } | 235 } |
| 299 return video_context_provider_; | 236 return video_context_provider_; |
| 300 } | 237 } |
| 301 | 238 |
| 302 void SynchronousCompositorFactoryImpl::SetDeferredGpuService( | 239 void SynchronousCompositorFactoryImpl::SetCreateContextCallback( |
| 303 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { | 240 SynchronousCompositor::CreateContextCallback callback) { |
| 304 DCHECK(!service_.get()); | 241 callback_ = callback; |
| 305 service_ = service; | |
| 306 } | 242 } |
| 307 | 243 |
| 308 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( | 244 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( |
| 309 bool record_full_document) { | 245 bool record_full_document) { |
| 310 record_full_layer_ = record_full_document; | 246 record_full_layer_ = record_full_document; |
| 311 } | 247 } |
| 312 | 248 |
| 313 } // namespace content | 249 } // namespace content |
| OLD | NEW |