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

Side by Side Diff: content/browser/renderer_host/delegated_frame_host.cc

Issue 2873243002: Move components/display_compositor to components/viz/display_compositor (Closed)
Patch Set: Rebase Created 3 years, 7 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/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/base/switches.h" 16 #include "cc/base/switches.h"
17 #include "cc/output/compositor_frame.h" 17 #include "cc/output/compositor_frame.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/compositor_frame_sink_support.h" 21 #include "cc/surfaces/compositor_frame_sink_support.h"
22 #include "cc/surfaces/surface.h" 22 #include "cc/surfaces/surface.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 "components/viz/display_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/compositor_resize_lock.h" 28 #include "content/browser/renderer_host/compositor_resize_lock.h"
29 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber .h" 29 #include "content/browser/renderer_host/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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; 341 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback;
342 if (!frame_subscriber()->ShouldCaptureFrame(damage_rect, present_time, &frame, 342 if (!frame_subscriber()->ShouldCaptureFrame(damage_rect, present_time, &frame,
343 &callback)) 343 &callback))
344 return; 344 return;
345 345
346 // Get a texture to re-use; else, create a new one. 346 // Get a texture to re-use; else, create a new one.
347 scoped_refptr<OwnedMailbox> subscriber_texture; 347 scoped_refptr<OwnedMailbox> subscriber_texture;
348 if (!idle_frame_subscriber_textures_.empty()) { 348 if (!idle_frame_subscriber_textures_.empty()) {
349 subscriber_texture = idle_frame_subscriber_textures_.back(); 349 subscriber_texture = idle_frame_subscriber_textures_.back();
350 idle_frame_subscriber_textures_.pop_back(); 350 idle_frame_subscriber_textures_.pop_back();
351 } else if (display_compositor::GLHelper* helper = 351 } else if (viz::GLHelper* helper =
352 ImageTransportFactory::GetInstance()->GetGLHelper()) { 352 ImageTransportFactory::GetInstance()->GetGLHelper()) {
353 subscriber_texture = new OwnedMailbox(helper); 353 subscriber_texture = new OwnedMailbox(helper);
354 } 354 }
355 355
356 std::unique_ptr<cc::CopyOutputRequest> request = 356 std::unique_ptr<cc::CopyOutputRequest> request =
357 cc::CopyOutputRequest::CreateRequest(base::Bind( 357 cc::CopyOutputRequest::CreateRequest(base::Bind(
358 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo, 358 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo,
359 AsWeakPtr(), subscriber_texture, frame, 359 AsWeakPtr(), subscriber_texture, frame,
360 base::Bind(callback, present_time))); 360 base::Bind(callback, present_time)));
361 // Setting the source in this copy request asks that the layer abort any prior 361 // Setting the source in this copy request asks that the layer abort any prior
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 scoped_refptr<media::VideoFrame> video_frame, 549 scoped_refptr<media::VideoFrame> video_frame,
550 base::WeakPtr<DelegatedFrameHost> dfh, 550 base::WeakPtr<DelegatedFrameHost> dfh,
551 const base::Callback<void(bool)>& callback, 551 const base::Callback<void(bool)>& callback,
552 scoped_refptr<OwnedMailbox> subscriber_texture, 552 scoped_refptr<OwnedMailbox> subscriber_texture,
553 std::unique_ptr<cc::SingleReleaseCallback> release_callback, 553 std::unique_ptr<cc::SingleReleaseCallback> release_callback,
554 bool result) { 554 bool result) {
555 callback.Run(result); 555 callback.Run(result);
556 556
557 gpu::SyncToken sync_token; 557 gpu::SyncToken sync_token;
558 if (result) { 558 if (result) {
559 display_compositor::GLHelper* gl_helper = 559 viz::GLHelper* gl_helper =
560 ImageTransportFactory::GetInstance()->GetGLHelper(); 560 ImageTransportFactory::GetInstance()->GetGLHelper();
561 gl_helper->GenerateSyncToken(&sync_token); 561 gl_helper->GenerateSyncToken(&sync_token);
562 } 562 }
563 if (release_callback) { 563 if (release_callback) {
564 // A release callback means the texture came from the compositor, so there 564 // A release callback means the texture came from the compositor, so there
565 // should be no |subscriber_texture|. 565 // should be no |subscriber_texture|.
566 DCHECK(!subscriber_texture.get()); 566 DCHECK(!subscriber_texture.get());
567 const bool lost_resource = !sync_token.HasData(); 567 const bool lost_resource = !sync_token.HasData();
568 release_callback->Run(sync_token, lost_resource); 568 release_callback->Run(sync_token, lost_resource);
569 } 569 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 media::CopyRGBToVideoFrame( 621 media::CopyRGBToVideoFrame(
622 reinterpret_cast<uint8_t*>(scaled_bitmap.getPixels()), 622 reinterpret_cast<uint8_t*>(scaled_bitmap.getPixels()),
623 scaled_bitmap.rowBytes(), region_in_frame, video_frame.get()); 623 scaled_bitmap.rowBytes(), region_in_frame, video_frame.get());
624 624
625 ignore_result(scoped_callback_runner.Release()); 625 ignore_result(scoped_callback_runner.Release());
626 callback.Run(region_in_frame, true); 626 callback.Run(region_in_frame, true);
627 return; 627 return;
628 } 628 }
629 629
630 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 630 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
631 display_compositor::GLHelper* gl_helper = factory->GetGLHelper(); 631 viz::GLHelper* gl_helper = factory->GetGLHelper();
632 if (!gl_helper) 632 if (!gl_helper)
633 return; 633 return;
634 if (subscriber_texture.get() && !subscriber_texture->texture_id()) 634 if (subscriber_texture.get() && !subscriber_texture->texture_id())
635 return; 635 return;
636 636
637 cc::TextureMailbox texture_mailbox; 637 cc::TextureMailbox texture_mailbox;
638 std::unique_ptr<cc::SingleReleaseCallback> release_callback; 638 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
639 result->TakeTexture(&texture_mailbox, &release_callback); 639 result->TakeTexture(&texture_mailbox, &release_callback);
640 DCHECK(texture_mailbox.IsTexture()); 640 DCHECK(texture_mailbox.IsTexture());
641 641
642 gfx::Rect result_rect(result->size()); 642 gfx::Rect result_rect(result->size());
643 643
644 display_compositor::ReadbackYUVInterface* yuv_readback_pipeline = 644 viz::ReadbackYUVInterface* yuv_readback_pipeline =
645 dfh->yuv_readback_pipeline_.get(); 645 dfh->yuv_readback_pipeline_.get();
646 if (yuv_readback_pipeline == NULL || 646 if (yuv_readback_pipeline == NULL ||
647 yuv_readback_pipeline->scaler()->SrcSize() != result_rect.size() || 647 yuv_readback_pipeline->scaler()->SrcSize() != result_rect.size() ||
648 yuv_readback_pipeline->scaler()->SrcSubrect() != result_rect || 648 yuv_readback_pipeline->scaler()->SrcSubrect() != result_rect ||
649 yuv_readback_pipeline->scaler()->DstSize() != region_in_frame.size()) { 649 yuv_readback_pipeline->scaler()->DstSize() != region_in_frame.size()) {
650 // The scaler chosen here is based on performance measurements of full 650 // The scaler chosen here is based on performance measurements of full
651 // end-to-end systems. When down-scaling, always use the "fast" scaler 651 // end-to-end systems. When down-scaling, always use the "fast" scaler
652 // because it performs well on both low- and high- end machines, provides 652 // because it performs well on both low- and high- end machines, provides
653 // decent image quality, and doesn't overwhelm downstream video encoders 653 // decent image quality, and doesn't overwhelm downstream video encoders
654 // with too much entropy (which can drastically increase CPU utilization). 654 // with too much entropy (which can drastically increase CPU utilization).
655 // When up-scaling, always use "best" because the quality improvement is 655 // When up-scaling, always use "best" because the quality improvement is
656 // huge with insignificant performance penalty. Note that this strategy 656 // huge with insignificant performance penalty. Note that this strategy
657 // differs from single-frame snapshot capture. 657 // differs from single-frame snapshot capture.
658 display_compositor::GLHelper::ScalerQuality quality = 658 viz::GLHelper::ScalerQuality quality =
659 ((result_rect.size().width() < region_in_frame.size().width()) && 659 ((result_rect.size().width() < region_in_frame.size().width()) &&
660 (result_rect.size().height() < region_in_frame.size().height())) 660 (result_rect.size().height() < region_in_frame.size().height()))
661 ? display_compositor::GLHelper::SCALER_QUALITY_BEST 661 ? viz::GLHelper::SCALER_QUALITY_BEST
662 : display_compositor::GLHelper::SCALER_QUALITY_FAST; 662 : viz::GLHelper::SCALER_QUALITY_FAST;
663 663
664 DVLOG(1) << "Re-creating YUV readback pipeline for source rect " 664 DVLOG(1) << "Re-creating YUV readback pipeline for source rect "
665 << result_rect.ToString() << " and destination size " 665 << result_rect.ToString() << " and destination size "
666 << region_in_frame.size().ToString(); 666 << region_in_frame.size().ToString();
667 667
668 dfh->yuv_readback_pipeline_.reset(gl_helper->CreateReadbackPipelineYUV( 668 dfh->yuv_readback_pipeline_.reset(gl_helper->CreateReadbackPipelineYUV(
669 quality, result_rect.size(), result_rect, region_in_frame.size(), true, 669 quality, result_rect.size(), result_rect, region_in_frame.size(), true,
670 true)); 670 true));
671 yuv_readback_pipeline = dfh->yuv_readback_pipeline_.get(); 671 yuv_readback_pipeline = dfh->yuv_readback_pipeline_.get();
672 } 672 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 } 862 }
863 863
864 if (!skipped_frames_) { 864 if (!skipped_frames_) {
865 latest_confirmed_begin_frame_source_id_ = ack.source_id; 865 latest_confirmed_begin_frame_source_id_ = ack.source_id;
866 latest_confirmed_begin_frame_sequence_number_ = 866 latest_confirmed_begin_frame_sequence_number_ =
867 ack.latest_confirmed_sequence_number; 867 ack.latest_confirmed_sequence_number;
868 } 868 }
869 } 869 }
870 870
871 } // namespace content 871 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698