Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: content/browser/android/in_process/synchronous_compositor_factory_impl.cc

Issue 532993002: work-in-progress patch to fix context lost black video (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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();
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 LoseContext() {
142 FOR_EACH_OBSERVER(
143 StreamTextureFactoryContextObserver, observer_list_, OnContextLost());
144 }
145
146 void RestoreContext() {
147 FOR_EACH_OBSERVER(StreamTextureFactoryContextObserver,
148 observer_list_,
149 OnContextRestored());
150 }
151
129 private: 152 private:
130 friend class base::RefCountedThreadSafe<VideoContextProvider>; 153 friend class base::RefCountedThreadSafe<VideoContextProvider>;
131 virtual ~VideoContextProvider() {} 154 virtual ~VideoContextProvider() {}
132 155
133 scoped_refptr<cc::ContextProvider> context_provider_; 156 scoped_refptr<cc::ContextProvider> context_provider_;
134 gpu::GLInProcessContext* gl_in_process_context_; 157 gpu::GLInProcessContext* gl_in_process_context_;
158 ObserverList<StreamTextureFactoryContextObserver> observer_list_;
135 159
136 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider); 160 DISALLOW_COPY_AND_ASSIGN(VideoContextProvider);
137 }; 161 };
138 162
139 } // namespace
140
141 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; 163 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
142 164
143 SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() 165 SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl()
144 : record_full_layer_(true), 166 : record_full_layer_(true),
145 num_hardware_compositors_(0) { 167 num_hardware_compositors_(0) {
146 SynchronousCompositorFactory::SetInstance(this); 168 SynchronousCompositorFactory::SetInstance(this);
147 } 169 }
148 170
149 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {} 171 SynchronousCompositorFactoryImpl::~SynchronousCompositorFactoryImpl() {}
150 172
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 webkit::gpu::WebGraphicsContext3DImpl* 241 webkit::gpu::WebGraphicsContext3DImpl*
220 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( 242 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D(
221 const blink::WebGraphicsContext3D::Attributes& attributes) { 243 const blink::WebGraphicsContext3D::Attributes& attributes) {
222 return WrapContextWithAttributes(CreateOffscreenContext(attributes), 244 return WrapContextWithAttributes(CreateOffscreenContext(attributes),
223 attributes).release(); 245 attributes).release();
224 } 246 }
225 247
226 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { 248 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() {
227 base::AutoLock lock(num_hardware_compositor_lock_); 249 base::AutoLock lock(num_hardware_compositor_lock_);
228 num_hardware_compositors_++; 250 num_hardware_compositors_++;
251 if (num_hardware_compositors_ == 1 && main_thread_proxy_) {
252 main_thread_proxy_->PostTask(
253 FROM_HERE,
254 base::Bind(
255 &SynchronousCompositorFactoryImpl::RestoreContextOnMainThread,
256 base::Unretained(this)));
257 }
229 } 258 }
230 259
231 void SynchronousCompositorFactoryImpl::CompositorReleasedHardwareDraw() { 260 void SynchronousCompositorFactoryImpl::CompositorReleasedHardwareDraw() {
232 base::AutoLock lock(num_hardware_compositor_lock_); 261 base::AutoLock lock(num_hardware_compositor_lock_);
233 DCHECK_GT(num_hardware_compositors_, 0u); 262 DCHECK_GT(num_hardware_compositors_, 0u);
234 num_hardware_compositors_--; 263 num_hardware_compositors_--;
264 if (!num_hardware_compositors_ && main_thread_proxy_) {
265 main_thread_proxy_->PostTask(
266 FROM_HERE,
267 base::Bind(&SynchronousCompositorFactoryImpl::LoseContextOnMainThread,
268 base::Unretained(this)));
269 }
270 }
271
272 void SynchronousCompositorFactoryImpl::LoseContextOnMainThread() {
273 if (video_context_provider_)
274 video_context_provider_->LoseContext();
275 }
276
277 void SynchronousCompositorFactoryImpl::RestoreContextOnMainThread() {
278 if (video_context_provider_)
279 video_context_provider_->RestoreContext();
235 } 280 }
236 281
237 bool SynchronousCompositorFactoryImpl::CanCreateMainThreadContext() { 282 bool SynchronousCompositorFactoryImpl::CanCreateMainThreadContext() {
238 base::AutoLock lock(num_hardware_compositor_lock_); 283 base::AutoLock lock(num_hardware_compositor_lock_);
239 return num_hardware_compositors_ > 0; 284 return num_hardware_compositors_ > 0;
240 } 285 }
241 286
242 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> 287 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>
243 SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() { 288 SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() {
289 {
290 base::AutoLock lock(num_hardware_compositor_lock_);
291 main_thread_proxy_ = base::MessageLoopProxy::current();
292 }
293
244 // Always fail creation even if |video_context_provider_| is not NULL. 294 // Always fail creation even if |video_context_provider_| is not NULL.
245 // This is to avoid synchronous calls that may deadlock. Setting 295 // This is to avoid synchronous calls that may deadlock. Setting
246 // |video_context_provider_| to null is also not safe since it makes 296 // |video_context_provider_| to null is also not safe since it makes
247 // synchronous destruction uncontrolled and possibly deadlock. 297 // synchronous destruction uncontrolled and possibly deadlock.
248 if (!CanCreateMainThreadContext()) { 298 if (!CanCreateMainThreadContext()) {
249 return 299 return
250 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); 300 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>();
251 } 301 }
252 302
253 if (!video_context_provider_) { 303 if (!video_context_provider_) {
(...skipping 13 matching lines...) Expand all
267 DCHECK(!service_); 317 DCHECK(!service_);
268 service_ = service; 318 service_ = service;
269 } 319 }
270 320
271 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( 321 void SynchronousCompositorFactoryImpl::SetRecordFullDocument(
272 bool record_full_document) { 322 bool record_full_document) {
273 record_full_layer_ = record_full_document; 323 record_full_layer_ = record_full_document;
274 } 324 }
275 325
276 } // namespace content 326 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698