OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Implementation notes: This needs to work on a variety of hardware | 5 // Implementation notes: This needs to work on a variety of hardware |
6 // configurations where the speed of the CPU and GPU greatly affect overall | 6 // configurations where the speed of the CPU and GPU greatly affect overall |
7 // performance. Spanning several threads, the process of capturing has been | 7 // performance. Spanning several threads, the process of capturing has been |
8 // split up into four conceptual stages: | 8 // split up into four conceptual stages: |
9 // | 9 // |
10 // 1. Reserve Buffer: Before a frame can be captured, a slot in the client's | 10 // 1. Reserve Buffer: Before a frame can be captured, a slot in the client's |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 timer_subscriber_(VideoCaptureOracle::kTimerPoll, oracle_proxy, | 333 timer_subscriber_(VideoCaptureOracle::kTimerPoll, oracle_proxy, |
334 &delivery_log_), | 334 &delivery_log_), |
335 capture_callback_(capture_callback), | 335 capture_callback_(capture_callback), |
336 timer_(true, true) { | 336 timer_(true, true) { |
337 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 337 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
338 | 338 |
339 RenderWidgetHostView* const view = source.GetView(); | 339 RenderWidgetHostView* const view = source.GetView(); |
340 | 340 |
341 // Subscribe to accelerated presents. These will be serviced directly by the | 341 // Subscribe to accelerated presents. These will be serviced directly by the |
342 // oracle. | 342 // oracle. |
343 if (view && kAcceleratedSubscriberIsSupported) { | 343 if (view) { |
344 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber( | 344 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber( |
345 new FrameSubscriber(VideoCaptureOracle::kCompositorUpdate, | 345 new FrameSubscriber(VideoCaptureOracle::kCompositorUpdate, |
346 oracle_proxy, &delivery_log_)); | 346 oracle_proxy, &delivery_log_)); |
347 view->BeginFrameSubscription(subscriber.Pass()); | 347 view->BeginFrameSubscription(subscriber.Pass()); |
348 } | 348 } |
349 | 349 |
350 // Subscribe to software paint events. This instance will service these by | 350 // Subscribe to software paint events. This instance will service these by |
351 // reflecting them back to the WebContentsCaptureMachine via | 351 // reflecting them back to the WebContentsCaptureMachine via |
352 // |capture_callback|. | 352 // |capture_callback|. |
353 registrar_.Add( | 353 registrar_.Add( |
354 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, | 354 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, |
355 Source<RenderWidgetHost>(&source)); | 355 Source<RenderWidgetHost>(&source)); |
356 | 356 |
357 // Subscribe to timer events. This instance will service these as well. | 357 // Subscribe to timer events. This instance will service these as well. |
358 timer_.Start(FROM_HERE, oracle_proxy->min_capture_period(), | 358 timer_.Start(FROM_HERE, oracle_proxy->min_capture_period(), |
359 base::Bind(&ContentCaptureSubscription::OnTimer, | 359 base::Bind(&ContentCaptureSubscription::OnTimer, |
360 base::Unretained(this))); | 360 base::Unretained(this))); |
361 } | 361 } |
362 | 362 |
363 ContentCaptureSubscription::~ContentCaptureSubscription() { | 363 ContentCaptureSubscription::~ContentCaptureSubscription() { |
364 // If the BrowserThreads have been torn down, then the browser is in the final | 364 // If the BrowserThreads have been torn down, then the browser is in the final |
365 // stages of exiting and it is dangerous to take any further action. We must | 365 // stages of exiting and it is dangerous to take any further action. We must |
366 // return early. http://crbug.com/396413 | 366 // return early. http://crbug.com/396413 |
367 if (!BrowserThread::IsMessageLoopValid(BrowserThread::UI)) | 367 if (!BrowserThread::IsMessageLoopValid(BrowserThread::UI)) |
368 return; | 368 return; |
369 | 369 |
370 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 370 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
371 if (kAcceleratedSubscriberIsSupported) { | 371 RenderWidgetHost* const source = |
372 RenderWidgetHost* const source = | 372 RenderWidgetHost::FromID(render_process_id_, render_widget_id_); |
373 RenderWidgetHost::FromID(render_process_id_, render_widget_id_); | 373 RenderWidgetHostView* const view = source ? source->GetView() : NULL; |
374 RenderWidgetHostView* const view = source ? source->GetView() : NULL; | 374 if (view) |
375 if (view) | 375 view->EndFrameSubscription(); |
376 view->EndFrameSubscription(); | |
377 } | |
378 } | 376 } |
379 | 377 |
380 void ContentCaptureSubscription::Observe( | 378 void ContentCaptureSubscription::Observe( |
381 int type, | 379 int type, |
382 const content::NotificationSource& source, | 380 const content::NotificationSource& source, |
383 const content::NotificationDetails& details) { | 381 const content::NotificationDetails& details) { |
384 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 382 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
385 DCHECK_EQ(NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, type); | 383 DCHECK_EQ(NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, type); |
386 | 384 |
387 RenderWidgetHostImpl* rwh = | 385 RenderWidgetHostImpl* rwh = |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 scoped_ptr<Client> client) { | 783 scoped_ptr<Client> client) { |
786 DVLOG(1) << "Allocating " << params.requested_format.frame_size.ToString(); | 784 DVLOG(1) << "Allocating " << params.requested_format.frame_size.ToString(); |
787 core_->AllocateAndStart(params, client.Pass()); | 785 core_->AllocateAndStart(params, client.Pass()); |
788 } | 786 } |
789 | 787 |
790 void WebContentsVideoCaptureDevice::StopAndDeAllocate() { | 788 void WebContentsVideoCaptureDevice::StopAndDeAllocate() { |
791 core_->StopAndDeAllocate(); | 789 core_->StopAndDeAllocate(); |
792 } | 790 } |
793 | 791 |
794 } // namespace content | 792 } // namespace content |
OLD | NEW |