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/renderer_host/delegated_frame_host.h" | 5 #include "content/browser/renderer_host/delegated_frame_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/time/default_tick_clock.h" | 15 #include "base/time/default_tick_clock.h" |
16 #include "cc/output/compositor_frame.h" | 16 #include "cc/output/compositor_frame.h" |
17 #include "cc/output/compositor_frame_ack.h" | 17 #include "cc/output/compositor_frame_ack.h" |
18 #include "cc/output/copy_output_request.h" | 18 #include "cc/output/copy_output_request.h" |
19 #include "cc/resources/single_release_callback.h" | 19 #include "cc/resources/single_release_callback.h" |
20 #include "cc/resources/texture_mailbox.h" | 20 #include "cc/resources/texture_mailbox.h" |
21 #include "cc/surfaces/surface.h" | 21 #include "cc/surfaces/surface.h" |
22 #include "cc/surfaces/surface_factory.h" | 22 #include "cc/surfaces/surface_factory.h" |
23 #include "cc/surfaces/surface_hittest.h" | 23 #include "cc/surfaces/surface_hittest.h" |
24 #include "cc/surfaces/surface_manager.h" | 24 #include "cc/surfaces/surface_manager.h" |
25 #include "components/display_compositor/gl_helper.h" | 25 #include "content/browser/compositor/gl_helper.h" |
26 #include "content/browser/compositor/surface_utils.h" | 26 #include "content/browser/compositor/surface_utils.h" |
27 #include "content/browser/gpu/compositor_util.h" | 27 #include "content/browser/gpu/compositor_util.h" |
28 #include "content/browser/renderer_host/resize_lock.h" | 28 #include "content/browser/renderer_host/resize_lock.h" |
29 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 29 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
30 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
31 #include "media/base/video_frame.h" | 31 #include "media/base/video_frame.h" |
32 #include "media/base/video_util.h" | 32 #include "media/base/video_util.h" |
33 #include "skia/ext/image_operations.h" | 33 #include "skia/ext/image_operations.h" |
34 #include "third_party/skia/include/core/SkCanvas.h" | 34 #include "third_party/skia/include/core/SkCanvas.h" |
35 #include "third_party/skia/include/core/SkPaint.h" | 35 #include "third_party/skia/include/core/SkPaint.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; | 329 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; |
330 if (!frame_subscriber()->ShouldCaptureFrame(damage_rect, present_time, &frame, | 330 if (!frame_subscriber()->ShouldCaptureFrame(damage_rect, present_time, &frame, |
331 &callback)) | 331 &callback)) |
332 return; | 332 return; |
333 | 333 |
334 // Get a texture to re-use; else, create a new one. | 334 // Get a texture to re-use; else, create a new one. |
335 scoped_refptr<OwnedMailbox> subscriber_texture; | 335 scoped_refptr<OwnedMailbox> subscriber_texture; |
336 if (!idle_frame_subscriber_textures_.empty()) { | 336 if (!idle_frame_subscriber_textures_.empty()) { |
337 subscriber_texture = idle_frame_subscriber_textures_.back(); | 337 subscriber_texture = idle_frame_subscriber_textures_.back(); |
338 idle_frame_subscriber_textures_.pop_back(); | 338 idle_frame_subscriber_textures_.pop_back(); |
339 } else if (display_compositor::GLHelper* helper = | 339 } else if (GLHelper* helper = |
340 ImageTransportFactory::GetInstance()->GetGLHelper()) { | 340 ImageTransportFactory::GetInstance()->GetGLHelper()) { |
341 subscriber_texture = new OwnedMailbox(helper); | 341 subscriber_texture = new OwnedMailbox(helper); |
342 } | 342 } |
343 | 343 |
344 std::unique_ptr<cc::CopyOutputRequest> request = | 344 std::unique_ptr<cc::CopyOutputRequest> request = |
345 cc::CopyOutputRequest::CreateRequest(base::Bind( | 345 cc::CopyOutputRequest::CreateRequest(base::Bind( |
346 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo, | 346 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo, |
347 AsWeakPtr(), subscriber_texture, frame, | 347 AsWeakPtr(), subscriber_texture, frame, |
348 base::Bind(callback, present_time))); | 348 base::Bind(callback, present_time))); |
349 // Setting the source in this copy request asks that the layer abort any prior | 349 // Setting the source in this copy request asks that the layer abort any prior |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 scoped_refptr<media::VideoFrame> video_frame, | 585 scoped_refptr<media::VideoFrame> video_frame, |
586 base::WeakPtr<DelegatedFrameHost> dfh, | 586 base::WeakPtr<DelegatedFrameHost> dfh, |
587 const base::Callback<void(bool)>& callback, | 587 const base::Callback<void(bool)>& callback, |
588 scoped_refptr<OwnedMailbox> subscriber_texture, | 588 scoped_refptr<OwnedMailbox> subscriber_texture, |
589 std::unique_ptr<cc::SingleReleaseCallback> release_callback, | 589 std::unique_ptr<cc::SingleReleaseCallback> release_callback, |
590 bool result) { | 590 bool result) { |
591 callback.Run(result); | 591 callback.Run(result); |
592 | 592 |
593 gpu::SyncToken sync_token; | 593 gpu::SyncToken sync_token; |
594 if (result) { | 594 if (result) { |
595 display_compositor::GLHelper* gl_helper = | 595 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
596 ImageTransportFactory::GetInstance()->GetGLHelper(); | |
597 gl_helper->GenerateSyncToken(&sync_token); | 596 gl_helper->GenerateSyncToken(&sync_token); |
598 } | 597 } |
599 if (release_callback) { | 598 if (release_callback) { |
600 // A release callback means the texture came from the compositor, so there | 599 // A release callback means the texture came from the compositor, so there |
601 // should be no |subscriber_texture|. | 600 // should be no |subscriber_texture|. |
602 DCHECK(!subscriber_texture.get()); | 601 DCHECK(!subscriber_texture.get()); |
603 const bool lost_resource = !sync_token.HasData(); | 602 const bool lost_resource = !sync_token.HasData(); |
604 release_callback->Run(sync_token, lost_resource); | 603 release_callback->Run(sync_token, lost_resource); |
605 } | 604 } |
606 ReturnSubscriberTexture(dfh, subscriber_texture, sync_token); | 605 ReturnSubscriberTexture(dfh, subscriber_texture, sync_token); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 media::CopyRGBToVideoFrame( | 659 media::CopyRGBToVideoFrame( |
661 reinterpret_cast<uint8_t*>(scaled_bitmap.getPixels()), | 660 reinterpret_cast<uint8_t*>(scaled_bitmap.getPixels()), |
662 scaled_bitmap.rowBytes(), region_in_frame, video_frame.get()); | 661 scaled_bitmap.rowBytes(), region_in_frame, video_frame.get()); |
663 } | 662 } |
664 ignore_result(scoped_callback_runner.Release()); | 663 ignore_result(scoped_callback_runner.Release()); |
665 callback.Run(region_in_frame, true); | 664 callback.Run(region_in_frame, true); |
666 return; | 665 return; |
667 } | 666 } |
668 | 667 |
669 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 668 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
670 display_compositor::GLHelper* gl_helper = factory->GetGLHelper(); | 669 GLHelper* gl_helper = factory->GetGLHelper(); |
671 if (!gl_helper) | 670 if (!gl_helper) |
672 return; | 671 return; |
673 if (subscriber_texture.get() && !subscriber_texture->texture_id()) | 672 if (subscriber_texture.get() && !subscriber_texture->texture_id()) |
674 return; | 673 return; |
675 | 674 |
676 cc::TextureMailbox texture_mailbox; | 675 cc::TextureMailbox texture_mailbox; |
677 std::unique_ptr<cc::SingleReleaseCallback> release_callback; | 676 std::unique_ptr<cc::SingleReleaseCallback> release_callback; |
678 result->TakeTexture(&texture_mailbox, &release_callback); | 677 result->TakeTexture(&texture_mailbox, &release_callback); |
679 DCHECK(texture_mailbox.IsTexture()); | 678 DCHECK(texture_mailbox.IsTexture()); |
680 | 679 |
681 gfx::Rect result_rect(result->size()); | 680 gfx::Rect result_rect(result->size()); |
682 | 681 |
683 display_compositor::ReadbackYUVInterface* yuv_readback_pipeline = | 682 content::ReadbackYUVInterface* yuv_readback_pipeline = |
684 dfh->yuv_readback_pipeline_.get(); | 683 dfh->yuv_readback_pipeline_.get(); |
685 if (yuv_readback_pipeline == NULL || | 684 if (yuv_readback_pipeline == NULL || |
686 yuv_readback_pipeline->scaler()->SrcSize() != result_rect.size() || | 685 yuv_readback_pipeline->scaler()->SrcSize() != result_rect.size() || |
687 yuv_readback_pipeline->scaler()->SrcSubrect() != result_rect || | 686 yuv_readback_pipeline->scaler()->SrcSubrect() != result_rect || |
688 yuv_readback_pipeline->scaler()->DstSize() != region_in_frame.size()) { | 687 yuv_readback_pipeline->scaler()->DstSize() != region_in_frame.size()) { |
689 // The scaler chosen here is based on performance measurements of full | 688 // The scaler chosen here is based on performance measurements of full |
690 // end-to-end systems. When down-scaling, always use the "fast" scaler | 689 // end-to-end systems. When down-scaling, always use the "fast" scaler |
691 // because it performs well on both low- and high- end machines, provides | 690 // because it performs well on both low- and high- end machines, provides |
692 // decent image quality, and doesn't overwhelm downstream video encoders | 691 // decent image quality, and doesn't overwhelm downstream video encoders |
693 // with too much entropy (which can drastically increase CPU utilization). | 692 // with too much entropy (which can drastically increase CPU utilization). |
694 // When up-scaling, always use "best" because the quality improvement is | 693 // When up-scaling, always use "best" because the quality improvement is |
695 // huge with insignificant performance penalty. Note that this strategy | 694 // huge with insignificant performance penalty. Note that this strategy |
696 // differs from single-frame snapshot capture. | 695 // differs from single-frame snapshot capture. |
697 display_compositor::GLHelper::ScalerQuality quality = | 696 GLHelper::ScalerQuality quality = |
698 ((result_rect.size().width() < region_in_frame.size().width()) && | 697 ((result_rect.size().width() < region_in_frame.size().width()) && |
699 (result_rect.size().height() < region_in_frame.size().height())) | 698 (result_rect.size().height() < region_in_frame.size().height())) |
700 ? display_compositor::GLHelper::SCALER_QUALITY_BEST | 699 ? GLHelper::SCALER_QUALITY_BEST |
701 : display_compositor::GLHelper::SCALER_QUALITY_FAST; | 700 : GLHelper::SCALER_QUALITY_FAST; |
702 | 701 |
703 dfh->yuv_readback_pipeline_.reset(gl_helper->CreateReadbackPipelineYUV( | 702 dfh->yuv_readback_pipeline_.reset(gl_helper->CreateReadbackPipelineYUV( |
704 quality, result_rect.size(), result_rect, region_in_frame.size(), true, | 703 quality, result_rect.size(), result_rect, region_in_frame.size(), true, |
705 true)); | 704 true)); |
706 yuv_readback_pipeline = dfh->yuv_readback_pipeline_.get(); | 705 yuv_readback_pipeline = dfh->yuv_readback_pipeline_.get(); |
707 } | 706 } |
708 | 707 |
709 ignore_result(scoped_callback_runner.Release()); | 708 ignore_result(scoped_callback_runner.Release()); |
710 ignore_result(scoped_return_subscriber_texture.Release()); | 709 ignore_result(scoped_return_subscriber_texture.Release()); |
711 | 710 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 881 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
883 new_layer->SetShowSurface( | 882 new_layer->SetShowSurface( |
884 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), | 883 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
885 base::Bind(&RequireCallback, base::Unretained(manager)), | 884 base::Bind(&RequireCallback, base::Unretained(manager)), |
886 current_surface_size_, current_scale_factor_, | 885 current_surface_size_, current_scale_factor_, |
887 current_frame_size_in_dip_); | 886 current_frame_size_in_dip_); |
888 } | 887 } |
889 } | 888 } |
890 | 889 |
891 } // namespace content | 890 } // namespace content |
OLD | NEW |