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

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

Issue 1902463002: Introduce components/display_compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove bot changes. Will do in a separate CL Created 4 years, 8 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/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 "content/browser/compositor/gl_helper.h" 25 #include "components/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/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
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 (GLHelper* helper = 339 } else if (display_compositor::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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 scoped_refptr<media::VideoFrame> video_frame, 589 scoped_refptr<media::VideoFrame> video_frame,
590 base::WeakPtr<DelegatedFrameHost> dfh, 590 base::WeakPtr<DelegatedFrameHost> dfh,
591 const base::Callback<void(bool)>& callback, 591 const base::Callback<void(bool)>& callback,
592 scoped_refptr<OwnedMailbox> subscriber_texture, 592 scoped_refptr<OwnedMailbox> subscriber_texture,
593 std::unique_ptr<cc::SingleReleaseCallback> release_callback, 593 std::unique_ptr<cc::SingleReleaseCallback> release_callback,
594 bool result) { 594 bool result) {
595 callback.Run(result); 595 callback.Run(result);
596 596
597 gpu::SyncToken sync_token; 597 gpu::SyncToken sync_token;
598 if (result) { 598 if (result) {
599 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); 599 display_compositor::GLHelper* gl_helper =
600 ImageTransportFactory::GetInstance()->GetGLHelper();
600 gl_helper->GenerateSyncToken(&sync_token); 601 gl_helper->GenerateSyncToken(&sync_token);
601 } 602 }
602 if (release_callback) { 603 if (release_callback) {
603 // A release callback means the texture came from the compositor, so there 604 // A release callback means the texture came from the compositor, so there
604 // should be no |subscriber_texture|. 605 // should be no |subscriber_texture|.
605 DCHECK(!subscriber_texture.get()); 606 DCHECK(!subscriber_texture.get());
606 const bool lost_resource = !sync_token.HasData(); 607 const bool lost_resource = !sync_token.HasData();
607 release_callback->Run(sync_token, lost_resource); 608 release_callback->Run(sync_token, lost_resource);
608 } 609 }
609 ReturnSubscriberTexture(dfh, subscriber_texture, sync_token); 610 ReturnSubscriberTexture(dfh, subscriber_texture, sync_token);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 media::CopyRGBToVideoFrame( 664 media::CopyRGBToVideoFrame(
664 reinterpret_cast<uint8_t*>(scaled_bitmap.getPixels()), 665 reinterpret_cast<uint8_t*>(scaled_bitmap.getPixels()),
665 scaled_bitmap.rowBytes(), region_in_frame, video_frame.get()); 666 scaled_bitmap.rowBytes(), region_in_frame, video_frame.get());
666 } 667 }
667 ignore_result(scoped_callback_runner.Release()); 668 ignore_result(scoped_callback_runner.Release());
668 callback.Run(region_in_frame, true); 669 callback.Run(region_in_frame, true);
669 return; 670 return;
670 } 671 }
671 672
672 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 673 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
673 GLHelper* gl_helper = factory->GetGLHelper(); 674 display_compositor::GLHelper* gl_helper = factory->GetGLHelper();
674 if (!gl_helper) 675 if (!gl_helper)
675 return; 676 return;
676 if (subscriber_texture.get() && !subscriber_texture->texture_id()) 677 if (subscriber_texture.get() && !subscriber_texture->texture_id())
677 return; 678 return;
678 679
679 cc::TextureMailbox texture_mailbox; 680 cc::TextureMailbox texture_mailbox;
680 std::unique_ptr<cc::SingleReleaseCallback> release_callback; 681 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
681 result->TakeTexture(&texture_mailbox, &release_callback); 682 result->TakeTexture(&texture_mailbox, &release_callback);
682 DCHECK(texture_mailbox.IsTexture()); 683 DCHECK(texture_mailbox.IsTexture());
683 684
684 gfx::Rect result_rect(result->size()); 685 gfx::Rect result_rect(result->size());
685 686
686 content::ReadbackYUVInterface* yuv_readback_pipeline = 687 display_compositor::ReadbackYUVInterface* yuv_readback_pipeline =
687 dfh->yuv_readback_pipeline_.get(); 688 dfh->yuv_readback_pipeline_.get();
688 if (yuv_readback_pipeline == NULL || 689 if (yuv_readback_pipeline == NULL ||
689 yuv_readback_pipeline->scaler()->SrcSize() != result_rect.size() || 690 yuv_readback_pipeline->scaler()->SrcSize() != result_rect.size() ||
690 yuv_readback_pipeline->scaler()->SrcSubrect() != result_rect || 691 yuv_readback_pipeline->scaler()->SrcSubrect() != result_rect ||
691 yuv_readback_pipeline->scaler()->DstSize() != region_in_frame.size()) { 692 yuv_readback_pipeline->scaler()->DstSize() != region_in_frame.size()) {
692 // The scaler chosen here is based on performance measurements of full 693 // The scaler chosen here is based on performance measurements of full
693 // end-to-end systems. When down-scaling, always use the "fast" scaler 694 // end-to-end systems. When down-scaling, always use the "fast" scaler
694 // because it performs well on both low- and high- end machines, provides 695 // because it performs well on both low- and high- end machines, provides
695 // decent image quality, and doesn't overwhelm downstream video encoders 696 // decent image quality, and doesn't overwhelm downstream video encoders
696 // with too much entropy (which can drastically increase CPU utilization). 697 // with too much entropy (which can drastically increase CPU utilization).
697 // When up-scaling, always use "best" because the quality improvement is 698 // When up-scaling, always use "best" because the quality improvement is
698 // huge with insignificant performance penalty. Note that this strategy 699 // huge with insignificant performance penalty. Note that this strategy
699 // differs from single-frame snapshot capture. 700 // differs from single-frame snapshot capture.
700 GLHelper::ScalerQuality quality = 701 display_compositor::GLHelper::ScalerQuality quality =
701 ((result_rect.size().width() < region_in_frame.size().width()) && 702 ((result_rect.size().width() < region_in_frame.size().width()) &&
702 (result_rect.size().height() < region_in_frame.size().height())) 703 (result_rect.size().height() < region_in_frame.size().height()))
703 ? GLHelper::SCALER_QUALITY_BEST 704 ? display_compositor::GLHelper::SCALER_QUALITY_BEST
704 : GLHelper::SCALER_QUALITY_FAST; 705 : display_compositor::GLHelper::SCALER_QUALITY_FAST;
705 706
706 dfh->yuv_readback_pipeline_.reset(gl_helper->CreateReadbackPipelineYUV( 707 dfh->yuv_readback_pipeline_.reset(gl_helper->CreateReadbackPipelineYUV(
707 quality, result_rect.size(), result_rect, region_in_frame.size(), true, 708 quality, result_rect.size(), result_rect, region_in_frame.size(), true,
708 true)); 709 true));
709 yuv_readback_pipeline = dfh->yuv_readback_pipeline_.get(); 710 yuv_readback_pipeline = dfh->yuv_readback_pipeline_.get();
710 } 711 }
711 712
712 ignore_result(scoped_callback_runner.Release()); 713 ignore_result(scoped_callback_runner.Release());
713 ignore_result(scoped_return_subscriber_texture.Release()); 714 ignore_result(scoped_return_subscriber_texture.Release());
714 715
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 886 cc::SurfaceManager* manager = factory->GetSurfaceManager();
886 new_layer->SetShowSurface( 887 new_layer->SetShowSurface(
887 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), 888 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)),
888 base::Bind(&RequireCallback, base::Unretained(manager)), 889 base::Bind(&RequireCallback, base::Unretained(manager)),
889 current_surface_size_, current_scale_factor_, 890 current_surface_size_, current_scale_factor_,
890 current_frame_size_in_dip_); 891 current_frame_size_in_dip_);
891 } 892 }
892 } 893 }
893 894
894 } // namespace content 895 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698