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/observer_list.h" | |
7 #include "content/browser/android/in_process/synchronous_compositor_output_surfa ce.h" | 8 #include "content/browser/android/in_process/synchronous_compositor_output_surfa ce.h" |
8 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
9 #include "content/renderer/gpu/frame_swap_message_queue.h" | 10 #include "content/renderer/gpu/frame_swap_message_queue.h" |
10 #include "gpu/command_buffer/client/gl_in_process_context.h" | 11 #include "gpu/command_buffer/client/gl_in_process_context.h" |
11 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 12 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
12 #include "ui/gl/android/surface_texture.h" | 13 #include "ui/gl/android/surface_texture.h" |
13 #include "ui/gl/gl_surface.h" | 14 #include "ui/gl/gl_surface.h" |
14 #include "ui/gl/gl_surface_stub.h" | 15 #include "ui/gl/gl_surface_stub.h" |
15 #include "webkit/common/gpu/context_provider_in_process.h" | 16 #include "webkit/common/gpu/context_provider_in_process.h" |
16 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" | 17 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 scoped_ptr<gpu::GLInProcessContext> context, | 98 scoped_ptr<gpu::GLInProcessContext> context, |
98 const blink::WebGraphicsContext3D::Attributes& attributes) { | 99 const blink::WebGraphicsContext3D::Attributes& attributes) { |
99 if (!context.get()) | 100 if (!context.get()) |
100 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(); | 101 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(); |
101 | 102 |
102 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>( | 103 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>( |
103 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( | 104 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( |
104 context.Pass(), attributes)); | 105 context.Pass(), attributes)); |
105 } | 106 } |
106 | 107 |
107 class VideoContextProvider | 108 } // namespace |
109 | |
110 class SynchronousCompositorFactoryImpl::VideoContextProvider | |
108 : public StreamTextureFactorySynchronousImpl::ContextProvider { | 111 : public StreamTextureFactorySynchronousImpl::ContextProvider { |
109 public: | 112 public: |
110 VideoContextProvider( | 113 VideoContextProvider( |
111 scoped_ptr<gpu::GLInProcessContext> gl_in_process_context) | 114 scoped_ptr<gpu::GLInProcessContext> gl_in_process_context) |
112 : gl_in_process_context_(gl_in_process_context.get()) { | 115 : gl_in_process_context_(gl_in_process_context.get()) { |
113 | 116 |
114 context_provider_ = webkit::gpu::ContextProviderInProcess::Create( | 117 context_provider_ = webkit::gpu::ContextProviderInProcess::Create( |
115 WrapContext(gl_in_process_context.Pass()), | 118 WrapContext(gl_in_process_context.Pass()), |
116 "Video-Offscreen-main-thread"); | 119 "Video-Offscreen-main-thread"); |
117 context_provider_->BindToCurrentThread(); | 120 context_provider_->BindToCurrentThread(); |
no sievers
2014/09/04 22:06:36
You can call context_provider_->SetLostContextCall
| |
118 } | 121 } |
119 | 122 |
120 virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( | 123 virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( |
121 uint32 stream_id) OVERRIDE { | 124 uint32 stream_id) OVERRIDE { |
122 return gl_in_process_context_->GetSurfaceTexture(stream_id); | 125 return gl_in_process_context_->GetSurfaceTexture(stream_id); |
123 } | 126 } |
124 | 127 |
125 virtual gpu::gles2::GLES2Interface* ContextGL() OVERRIDE { | 128 virtual gpu::gles2::GLES2Interface* ContextGL() OVERRIDE { |
126 return context_provider_->ContextGL(); | 129 return context_provider_->ContextGL(); |
127 } | 130 } |
128 | 131 |
132 virtual void AddObserver(StreamTextureFactoryContextObserver* obs) OVERRIDE { | |
133 observer_list_.AddObserver(obs); | |
134 } | |
135 | |
136 virtual void RemoveObserver( | |
137 StreamTextureFactoryContextObserver* obs) OVERRIDE { | |
138 observer_list_.RemoveObserver(obs); | |
139 } | |
140 | |
141 void RestoreContext() { | |
142 FOR_EACH_OBSERVER(StreamTextureFactoryContextObserver, | |
143 observer_list_, | |
144 ResetStreamTextureProxy()); | |
145 } | |
146 | |
129 private: | 147 private: |
130 friend class base::RefCountedThreadSafe<VideoContextProvider>; | 148 friend class base::RefCountedThreadSafe<VideoContextProvider>; |
131 virtual ~VideoContextProvider() {} | 149 virtual ~VideoContextProvider() {} |
132 | 150 |
133 scoped_refptr<cc::ContextProvider> context_provider_; | 151 scoped_refptr<cc::ContextProvider> context_provider_; |
134 gpu::GLInProcessContext* gl_in_process_context_; | 152 gpu::GLInProcessContext* gl_in_process_context_; |
153 ObserverList<StreamTextureFactoryContextObserver> observer_list_; | |
135 | 154 |
136 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider); | 155 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider); |
137 }; | 156 }; |
138 | 157 |
139 } // namespace | |
140 | |
141 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | 158 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; |
142 | 159 |
143 SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() | 160 SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() |
144 : record_full_layer_(true), | 161 : record_full_layer_(true), |
145 num_hardware_compositors_(0) { | 162 num_hardware_compositors_(0) { |
146 SynchronousCompositorFactory::SetInstance(this); | 163 SynchronousCompositorFactory::SetInstance(this); |
147 } | 164 } |
148 | 165 |
149 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} | 166 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} |
150 | 167 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 webkit::gpu::WebGraphicsContext3DImpl* | 236 webkit::gpu::WebGraphicsContext3DImpl* |
220 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( | 237 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( |
221 const blink::WebGraphicsContext3D::Attributes& attributes) { | 238 const blink::WebGraphicsContext3D::Attributes& attributes) { |
222 return WrapContextWithAttributes(CreateOffscreenContext(attributes), | 239 return WrapContextWithAttributes(CreateOffscreenContext(attributes), |
223 attributes).release(); | 240 attributes).release(); |
224 } | 241 } |
225 | 242 |
226 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { | 243 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { |
227 base::AutoLock lock(num_hardware_compositor_lock_); | 244 base::AutoLock lock(num_hardware_compositor_lock_); |
228 num_hardware_compositors_++; | 245 num_hardware_compositors_++; |
246 if (num_hardware_compositors_ == 1 && main_thread_proxy_) { | |
247 main_thread_proxy_->PostTask( | |
248 FROM_HERE, | |
249 base::Bind( | |
250 &SynchronousCompositorFactoryImpl::RestoreContextOnMainThread, | |
251 base::Unretained(this))); | |
252 } | |
229 } | 253 } |
230 | 254 |
231 void SynchronousCompositorFactoryImpl::CompositorReleasedHardwareDraw() { | 255 void SynchronousCompositorFactoryImpl::CompositorReleasedHardwareDraw() { |
232 base::AutoLock lock(num_hardware_compositor_lock_); | 256 base::AutoLock lock(num_hardware_compositor_lock_); |
233 DCHECK_GT(num_hardware_compositors_, 0u); | 257 DCHECK_GT(num_hardware_compositors_, 0u); |
234 num_hardware_compositors_--; | 258 num_hardware_compositors_--; |
235 } | 259 } |
236 | 260 |
261 void SynchronousCompositorFactoryImpl::RestoreContextOnMainThread() { | |
262 if (CanCreateMainThreadContext() && video_context_provider_ ) | |
263 video_context_provider_->RestoreContext(); | |
264 } | |
265 | |
237 bool SynchronousCompositorFactoryImpl::CanCreateMainThreadContext() { | 266 bool SynchronousCompositorFactoryImpl::CanCreateMainThreadContext() { |
238 base::AutoLock lock(num_hardware_compositor_lock_); | 267 base::AutoLock lock(num_hardware_compositor_lock_); |
239 return num_hardware_compositors_ > 0; | 268 return num_hardware_compositors_ > 0; |
240 } | 269 } |
241 | 270 |
242 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> | 271 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> |
243 SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() { | 272 SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() { |
273 { | |
274 base::AutoLock lock(num_hardware_compositor_lock_); | |
275 main_thread_proxy_ = base::MessageLoopProxy::current(); | |
276 } | |
277 | |
244 // Always fail creation even if |video_context_provider_| is not NULL. | 278 // Always fail creation even if |video_context_provider_| is not NULL. |
245 // This is to avoid synchronous calls that may deadlock. Setting | 279 // This is to avoid synchronous calls that may deadlock. Setting |
246 // |video_context_provider_| to null is also not safe since it makes | 280 // |video_context_provider_| to null is also not safe since it makes |
247 // synchronous destruction uncontrolled and possibly deadlock. | 281 // synchronous destruction uncontrolled and possibly deadlock. |
248 if (!CanCreateMainThreadContext()) { | 282 if (!CanCreateMainThreadContext()) { |
249 return | 283 return |
250 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); | 284 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); |
251 } | 285 } |
252 | 286 |
253 if (!video_context_provider_) { | 287 if (!video_context_provider_) { |
(...skipping 13 matching lines...) Expand all Loading... | |
267 DCHECK(!service_); | 301 DCHECK(!service_); |
268 service_ = service; | 302 service_ = service; |
269 } | 303 } |
270 | 304 |
271 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( | 305 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( |
272 bool record_full_document) { | 306 bool record_full_document) { |
273 record_full_layer_ = record_full_document; | 307 record_full_layer_ = record_full_document; |
274 } | 308 } |
275 | 309 |
276 } // namespace content | 310 } // namespace content |
OLD | NEW |