| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource( | 136 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource( |
| 201 int routing_id) { | 137 int routing_id) { |
| 202 return make_scoped_ptr( | 138 return make_scoped_ptr( |
| 203 new SynchronousCompositorExternalBeginFrameSource(routing_id)); | 139 new SynchronousCompositorExternalBeginFrameSource(routing_id)); |
| 204 } | 140 } |
| 205 | 141 |
| 206 scoped_refptr<ContextProviderWebContext> | 142 scoped_refptr<ContextProviderWebContext> |
| 207 SynchronousCompositorFactoryImpl::CreateOffscreenContextProvider( | 143 SynchronousCompositorFactoryImpl::CreateOffscreenContextProvider( |
| 208 const blink::WebGraphicsContext3D::Attributes& attributes, | 144 const blink::WebGraphicsContext3D::Attributes& attributes, |
| 209 const std::string& debug_name) { | 145 const std::string& debug_name) { |
| 210 scoped_ptr<gpu::GLInProcessContext> context = | 146 return callback_.Run(false, attributes, true, |
| 211 CreateOffscreenContext(attributes); | 147 gpu::GLInProcessContextSharedMemoryLimits()) |
| 212 return webkit::gpu::ContextProviderInProcess::Create( | 148 .context_provider; |
| 213 WrapContext(context.Pass()), debug_name); | |
| 214 } | 149 } |
| 215 | 150 |
| 216 scoped_refptr<cc::ContextProvider> | 151 scoped_refptr<cc::ContextProvider> |
| 217 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor() { | 152 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor() { |
| 218 DCHECK(service_.get()); | |
| 219 | |
| 220 gpu::GLInProcessContextSharedMemoryLimits mem_limits; | 153 gpu::GLInProcessContextSharedMemoryLimits mem_limits; |
| 221 // This is half of what RenderWidget uses because synchronous compositor | 154 // This is half of what RenderWidget uses because synchronous compositor |
| 222 // pipeline is only one frame deep. | 155 // pipeline is only one frame deep. |
| 223 mem_limits.mapped_memory_reclaim_limit = 6 * 1024 * 1024; | 156 mem_limits.mapped_memory_reclaim_limit = 6 * 1024 * 1024; |
| 224 return webkit::gpu::ContextProviderInProcess::Create( | 157 return callback_.Run(false, GetDefaultAttribs(), true, mem_limits) |
| 225 WrapContext(CreateContext(nullptr, mem_limits, true, true)), | 158 .context_provider; |
| 226 "Child-Compositor"); | |
| 227 } | 159 } |
| 228 | 160 |
| 229 scoped_refptr<StreamTextureFactory> | 161 scoped_refptr<StreamTextureFactory> |
| 230 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { | 162 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { |
| 231 scoped_refptr<StreamTextureFactorySynchronousImpl> factory( | 163 scoped_refptr<StreamTextureFactorySynchronousImpl> factory( |
| 232 StreamTextureFactorySynchronousImpl::Create( | 164 StreamTextureFactorySynchronousImpl::Create( |
| 233 base::Bind( | 165 base::Bind( |
| 234 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, | 166 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, |
| 235 base::Unretained(this)), | 167 base::Unretained(this)), |
| 236 frame_id)); | 168 frame_id)); |
| 237 return factory; | 169 return factory; |
| 238 } | 170 } |
| 239 | 171 |
| 240 WebGraphicsContext3DInProcessCommandBufferImpl* | 172 WebGraphicsContext3DInProcessCommandBufferImpl* |
| 241 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( | 173 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( |
| 242 const blink::WebGraphicsContext3D::Attributes& attributes) { | 174 const blink::WebGraphicsContext3D::Attributes& attributes) { |
| 243 return WrapContextWithAttributes(CreateOffscreenContext(attributes), | 175 return WrapContextWithAttributes( |
| 244 attributes).release(); | 176 make_scoped_ptr( |
| 177 callback_.Run(false, attributes, true, |
| 178 gpu::GLInProcessContextSharedMemoryLimits()) |
| 179 .context), |
| 180 attributes).release(); |
| 245 } | 181 } |
| 246 | 182 |
| 247 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { | 183 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { |
| 248 base::AutoLock lock(num_hardware_compositor_lock_); | 184 base::AutoLock lock(num_hardware_compositor_lock_); |
| 249 num_hardware_compositors_++; | 185 num_hardware_compositors_++; |
| 250 if (num_hardware_compositors_ == 1 && main_thread_proxy_.get()) { | 186 if (num_hardware_compositors_ == 1 && main_thread_proxy_.get()) { |
| 251 main_thread_proxy_->PostTask( | 187 main_thread_proxy_->PostTask( |
| 252 FROM_HERE, | 188 FROM_HERE, |
| 253 base::Bind( | 189 base::Bind( |
| 254 &SynchronousCompositorFactoryImpl::RestoreContextOnMainThread, | 190 &SynchronousCompositorFactoryImpl::RestoreContextOnMainThread, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 282 // Always fail creation even if |video_context_provider_| is not NULL. | 218 // Always fail creation even if |video_context_provider_| is not NULL. |
| 283 // This is to avoid synchronous calls that may deadlock. Setting | 219 // This is to avoid synchronous calls that may deadlock. Setting |
| 284 // |video_context_provider_| to null is also not safe since it makes | 220 // |video_context_provider_| to null is also not safe since it makes |
| 285 // synchronous destruction uncontrolled and possibly deadlock. | 221 // synchronous destruction uncontrolled and possibly deadlock. |
| 286 if (!CanCreateMainThreadContext()) { | 222 if (!CanCreateMainThreadContext()) { |
| 287 return | 223 return |
| 288 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); | 224 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); |
| 289 } | 225 } |
| 290 | 226 |
| 291 if (!video_context_provider_.get()) { | 227 if (!video_context_provider_.get()) { |
| 292 DCHECK(service_.get()); | 228 blink::WebGraphicsContext3D::Attributes attributes = GetDefaultAttribs(); |
| 293 | 229 attributes.shareResources = true; |
| 294 // This needs to run in on-screen |service_| context due to SurfaceTexture | 230 SynchronousCompositor::ContextHolder holder = callback_.Run( |
| 231 true, attributes, false, gpu::GLInProcessContextSharedMemoryLimits()); |
| 232 // This needs to run in on-screen context due to SurfaceTexture |
| 295 // limitations. | 233 // limitations. |
| 296 video_context_provider_ = new VideoContextProvider(CreateContext( | 234 video_context_provider_ = |
| 297 service_, gpu::GLInProcessContextSharedMemoryLimits(), false, false)); | 235 new VideoContextProvider(holder.context_provider, holder.context); |
| 298 } | 236 } |
| 299 return video_context_provider_; | 237 return video_context_provider_; |
| 300 } | 238 } |
| 301 | 239 |
| 302 void SynchronousCompositorFactoryImpl::SetDeferredGpuService( | 240 void SynchronousCompositorFactoryImpl::SetCreateContextCallback( |
| 303 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { | 241 SynchronousCompositor::CreateContextCallback callback) { |
| 304 DCHECK(!service_.get()); | 242 callback_ = callback; |
| 305 service_ = service; | |
| 306 } | 243 } |
| 307 | 244 |
| 308 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( | 245 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( |
| 309 bool record_full_document) { | 246 bool record_full_document) { |
| 310 record_full_layer_ = record_full_document; | 247 record_full_layer_ = record_full_document; |
| 311 } | 248 } |
| 312 | 249 |
| 313 } // namespace content | 250 } // namespace content |
| OLD | NEW |