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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 scoped_ptr<gpu::GLInProcessContext> context, | 97 scoped_ptr<gpu::GLInProcessContext> context, |
97 const blink::WebGraphicsContext3D::Attributes& attributes) { | 98 const blink::WebGraphicsContext3D::Attributes& attributes) { |
98 if (!context.get()) | 99 if (!context.get()) |
99 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(); | 100 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(); |
100 | 101 |
101 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>( | 102 return scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>( |
102 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( | 103 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( |
103 context.Pass(), attributes)); | 104 context.Pass(), attributes)); |
104 } | 105 } |
105 | 106 |
106 class VideoContextProvider | 107 } // namespace |
| 108 |
| 109 class SynchronousCompositorFactoryImpl::VideoContextProvider |
107 : public StreamTextureFactorySynchronousImpl::ContextProvider { | 110 : public StreamTextureFactorySynchronousImpl::ContextProvider { |
108 public: | 111 public: |
109 VideoContextProvider( | 112 VideoContextProvider( |
110 scoped_ptr<gpu::GLInProcessContext> gl_in_process_context) | 113 scoped_ptr<gpu::GLInProcessContext> gl_in_process_context) |
111 : gl_in_process_context_(gl_in_process_context.get()) { | 114 : gl_in_process_context_(gl_in_process_context.get()) { |
112 | 115 |
113 context_provider_ = webkit::gpu::ContextProviderInProcess::Create( | 116 context_provider_ = webkit::gpu::ContextProviderInProcess::Create( |
114 WrapContext(gl_in_process_context.Pass()), | 117 WrapContext(gl_in_process_context.Pass()), |
115 "Video-Offscreen-main-thread"); | 118 "Video-Offscreen-main-thread"); |
116 context_provider_->BindToCurrentThread(); | 119 context_provider_->BindToCurrentThread(); |
117 } | 120 } |
118 | 121 |
119 virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( | 122 virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( |
120 uint32 stream_id) OVERRIDE { | 123 uint32 stream_id) OVERRIDE { |
121 return gl_in_process_context_->GetSurfaceTexture(stream_id); | 124 return gl_in_process_context_->GetSurfaceTexture(stream_id); |
122 } | 125 } |
123 | 126 |
124 virtual gpu::gles2::GLES2Interface* ContextGL() OVERRIDE { | 127 virtual gpu::gles2::GLES2Interface* ContextGL() OVERRIDE { |
125 return context_provider_->ContextGL(); | 128 return context_provider_->ContextGL(); |
126 } | 129 } |
127 | 130 |
| 131 virtual void AddObserver(StreamTextureFactoryContextObserver* obs) OVERRIDE { |
| 132 observer_list_.AddObserver(obs); |
| 133 } |
| 134 |
| 135 virtual void RemoveObserver( |
| 136 StreamTextureFactoryContextObserver* obs) OVERRIDE { |
| 137 observer_list_.RemoveObserver(obs); |
| 138 } |
| 139 |
| 140 void RestoreContext() { |
| 141 FOR_EACH_OBSERVER(StreamTextureFactoryContextObserver, |
| 142 observer_list_, |
| 143 ResetStreamTextureProxy()); |
| 144 } |
| 145 |
128 private: | 146 private: |
129 friend class base::RefCountedThreadSafe<VideoContextProvider>; | 147 friend class base::RefCountedThreadSafe<VideoContextProvider>; |
130 virtual ~VideoContextProvider() {} | 148 virtual ~VideoContextProvider() {} |
131 | 149 |
132 scoped_refptr<cc::ContextProvider> context_provider_; | 150 scoped_refptr<cc::ContextProvider> context_provider_; |
133 gpu::GLInProcessContext* gl_in_process_context_; | 151 gpu::GLInProcessContext* gl_in_process_context_; |
| 152 ObserverList<StreamTextureFactoryContextObserver> observer_list_; |
134 | 153 |
135 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider); | 154 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider); |
136 }; | 155 }; |
137 | 156 |
138 } // namespace | |
139 | |
140 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | 157 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; |
141 | 158 |
142 SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() | 159 SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() |
143 : record_full_layer_(true), | 160 : record_full_layer_(true), |
144 num_hardware_compositors_(0) { | 161 num_hardware_compositors_(0) { |
145 SynchronousCompositorFactory::SetInstance(this); | 162 SynchronousCompositorFactory::SetInstance(this); |
146 } | 163 } |
147 | 164 |
148 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} | 165 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} |
149 | 166 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 webkit::gpu::WebGraphicsContext3DImpl* | 226 webkit::gpu::WebGraphicsContext3DImpl* |
210 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( | 227 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( |
211 const blink::WebGraphicsContext3D::Attributes& attributes) { | 228 const blink::WebGraphicsContext3D::Attributes& attributes) { |
212 return WrapContextWithAttributes(CreateOffscreenContext(attributes), | 229 return WrapContextWithAttributes(CreateOffscreenContext(attributes), |
213 attributes).release(); | 230 attributes).release(); |
214 } | 231 } |
215 | 232 |
216 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { | 233 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { |
217 base::AutoLock lock(num_hardware_compositor_lock_); | 234 base::AutoLock lock(num_hardware_compositor_lock_); |
218 num_hardware_compositors_++; | 235 num_hardware_compositors_++; |
| 236 if (num_hardware_compositors_ == 1 && main_thread_proxy_) { |
| 237 main_thread_proxy_->PostTask( |
| 238 FROM_HERE, |
| 239 base::Bind( |
| 240 &SynchronousCompositorFactoryImpl::RestoreContextOnMainThread, |
| 241 base::Unretained(this))); |
| 242 } |
219 } | 243 } |
220 | 244 |
221 void SynchronousCompositorFactoryImpl::CompositorReleasedHardwareDraw() { | 245 void SynchronousCompositorFactoryImpl::CompositorReleasedHardwareDraw() { |
222 base::AutoLock lock(num_hardware_compositor_lock_); | 246 base::AutoLock lock(num_hardware_compositor_lock_); |
223 DCHECK_GT(num_hardware_compositors_, 0u); | 247 DCHECK_GT(num_hardware_compositors_, 0u); |
224 num_hardware_compositors_--; | 248 num_hardware_compositors_--; |
225 } | 249 } |
226 | 250 |
| 251 void SynchronousCompositorFactoryImpl::RestoreContextOnMainThread() { |
| 252 if (CanCreateMainThreadContext() && video_context_provider_ ) |
| 253 video_context_provider_->RestoreContext(); |
| 254 } |
| 255 |
227 bool SynchronousCompositorFactoryImpl::CanCreateMainThreadContext() { | 256 bool SynchronousCompositorFactoryImpl::CanCreateMainThreadContext() { |
228 base::AutoLock lock(num_hardware_compositor_lock_); | 257 base::AutoLock lock(num_hardware_compositor_lock_); |
229 return num_hardware_compositors_ > 0; | 258 return num_hardware_compositors_ > 0; |
230 } | 259 } |
231 | 260 |
232 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> | 261 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> |
233 SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() { | 262 SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() { |
| 263 { |
| 264 base::AutoLock lock(num_hardware_compositor_lock_); |
| 265 main_thread_proxy_ = base::MessageLoopProxy::current(); |
| 266 } |
| 267 |
234 // Always fail creation even if |video_context_provider_| is not NULL. | 268 // Always fail creation even if |video_context_provider_| is not NULL. |
235 // This is to avoid synchronous calls that may deadlock. Setting | 269 // This is to avoid synchronous calls that may deadlock. Setting |
236 // |video_context_provider_| to null is also not safe since it makes | 270 // |video_context_provider_| to null is also not safe since it makes |
237 // synchronous destruction uncontrolled and possibly deadlock. | 271 // synchronous destruction uncontrolled and possibly deadlock. |
238 if (!CanCreateMainThreadContext()) { | 272 if (!CanCreateMainThreadContext()) { |
239 return | 273 return |
240 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); | 274 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); |
241 } | 275 } |
242 | 276 |
243 if (!video_context_provider_) { | 277 if (!video_context_provider_) { |
(...skipping 11 matching lines...) Expand all Loading... |
255 DCHECK(!service_); | 289 DCHECK(!service_); |
256 service_ = service; | 290 service_ = service; |
257 } | 291 } |
258 | 292 |
259 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( | 293 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( |
260 bool record_full_document) { | 294 bool record_full_document) { |
261 record_full_layer_ = record_full_document; | 295 record_full_layer_ = record_full_document; |
262 } | 296 } |
263 | 297 |
264 } // namespace content | 298 } // namespace content |
OLD | NEW |