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

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

Issue 2425923003: Replaced is_null() with is_valid in SurfaceId and related classes. (Closed)
Patch Set: Removed added printf statements; LocalFrameId::is_valid() no longer checks if nonce is 0. Created 4 years, 2 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>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 factory->GetContextFactory()->AddObserver(this); 80 factory->GetContextFactory()->AddObserver(this);
81 id_allocator_.reset(new cc::SurfaceIdAllocator()); 81 id_allocator_.reset(new cc::SurfaceIdAllocator());
82 factory->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); 82 factory->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_);
83 factory->GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_, 83 factory->GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_,
84 this); 84 this);
85 } 85 }
86 86
87 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { 87 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) {
88 delegated_frame_evictor_->SetVisible(true); 88 delegated_frame_evictor_->SetVisible(true);
89 89
90 if (local_frame_id_.is_null() && !released_front_lock_.get()) { 90 if (!local_frame_id_.is_valid() && !released_front_lock_.get()) {
91 if (compositor_) 91 if (compositor_)
92 released_front_lock_ = compositor_->GetCompositorLock(); 92 released_front_lock_ = compositor_->GetCompositorLock();
93 } 93 }
94 94
95 if (compositor_) { 95 if (compositor_) {
96 compositor_->SetLatencyInfo(latency_info); 96 compositor_->SetLatencyInfo(latency_info);
97 } 97 }
98 } 98 }
99 99
100 bool DelegatedFrameHost::HasSavedFrame() { 100 bool DelegatedFrameHost::HasSavedFrame() {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 209
210 cc::FrameSinkId DelegatedFrameHost::GetFrameSinkId() { 210 cc::FrameSinkId DelegatedFrameHost::GetFrameSinkId() {
211 return frame_sink_id_; 211 return frame_sink_id_;
212 } 212 }
213 213
214 cc::SurfaceId DelegatedFrameHost::SurfaceIdAtPoint( 214 cc::SurfaceId DelegatedFrameHost::SurfaceIdAtPoint(
215 cc::SurfaceHittestDelegate* delegate, 215 cc::SurfaceHittestDelegate* delegate,
216 const gfx::Point& point, 216 const gfx::Point& point,
217 gfx::Point* transformed_point) { 217 gfx::Point* transformed_point) {
218 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_); 218 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_);
219 if (surface_id.is_null()) 219 if (!surface_id.is_valid())
220 return surface_id; 220 return surface_id;
221 cc::SurfaceHittest hittest(delegate, GetSurfaceManager()); 221 cc::SurfaceHittest hittest(delegate, GetSurfaceManager());
222 gfx::Transform target_transform; 222 gfx::Transform target_transform;
223 cc::SurfaceId target_local_frame_id = 223 cc::SurfaceId target_local_frame_id =
224 hittest.GetTargetSurfaceAtPoint(surface_id, point, &target_transform); 224 hittest.GetTargetSurfaceAtPoint(surface_id, point, &target_transform);
225 *transformed_point = point; 225 *transformed_point = point;
226 if (!target_local_frame_id.is_null()) 226 if (target_local_frame_id.is_valid())
227 target_transform.TransformPoint(transformed_point); 227 target_transform.TransformPoint(transformed_point);
228 return target_local_frame_id; 228 return target_local_frame_id;
229 } 229 }
230 230
231 bool DelegatedFrameHost::TransformPointToLocalCoordSpace( 231 bool DelegatedFrameHost::TransformPointToLocalCoordSpace(
232 const gfx::Point& point, 232 const gfx::Point& point,
233 const cc::SurfaceId& original_surface, 233 const cc::SurfaceId& original_surface,
234 gfx::Point* transformed_point) { 234 gfx::Point* transformed_point) {
235 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_); 235 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_);
236 if (surface_id.is_null()) 236 if (!surface_id.is_valid())
237 return false; 237 return false;
238 *transformed_point = point; 238 *transformed_point = point;
239 if (original_surface == surface_id) 239 if (original_surface == surface_id)
240 return true; 240 return true;
241 241
242 cc::SurfaceHittest hittest(nullptr, GetSurfaceManager()); 242 cc::SurfaceHittest hittest(nullptr, GetSurfaceManager());
243 return hittest.TransformPointToTargetSurface(original_surface, surface_id, 243 return hittest.TransformPointToTargetSurface(original_surface, surface_id,
244 transformed_point); 244 transformed_point);
245 } 245 }
246 246
247 bool DelegatedFrameHost::TransformPointToCoordSpaceForView( 247 bool DelegatedFrameHost::TransformPointToCoordSpaceForView(
248 const gfx::Point& point, 248 const gfx::Point& point,
249 RenderWidgetHostViewBase* target_view, 249 RenderWidgetHostViewBase* target_view,
250 gfx::Point* transformed_point) { 250 gfx::Point* transformed_point) {
251 if (local_frame_id_.is_null()) 251 if (!local_frame_id_.is_valid())
252 return false; 252 return false;
253 253
254 return target_view->TransformPointToLocalCoordSpace( 254 return target_view->TransformPointToLocalCoordSpace(
255 point, cc::SurfaceId(frame_sink_id_, local_frame_id_), transformed_point); 255 point, cc::SurfaceId(frame_sink_id_, local_frame_id_), transformed_point);
256 } 256 }
257 257
258 bool DelegatedFrameHost::ShouldSkipFrame(gfx::Size size_in_dip) const { 258 bool DelegatedFrameHost::ShouldSkipFrame(gfx::Size size_in_dip) const {
259 // Should skip a frame only when another frame from the renderer is guaranteed 259 // Should skip a frame only when another frame from the renderer is guaranteed
260 // to replace it. Otherwise may cause hangs when the renderer is waiting for 260 // to replace it. Otherwise may cause hangs when the renderer is waiting for
261 // the completion of latency infos (such as when taking a Snapshot.) 261 // the completion of latency infos (such as when taking a Snapshot.)
(...skipping 14 matching lines...) Expand all
276 } 276 }
277 277
278 SkColor DelegatedFrameHost::GetGutterColor() const { 278 SkColor DelegatedFrameHost::GetGutterColor() const {
279 // In fullscreen mode resizing is uncommon, so it makes more sense to 279 // In fullscreen mode resizing is uncommon, so it makes more sense to
280 // make the initial switch to fullscreen mode look better by using black as 280 // make the initial switch to fullscreen mode look better by using black as
281 // the gutter color. 281 // the gutter color.
282 return client_->DelegatedFrameHostGetGutterColor(background_color_); 282 return client_->DelegatedFrameHostGetGutterColor(background_color_);
283 } 283 }
284 284
285 void DelegatedFrameHost::UpdateGutters() { 285 void DelegatedFrameHost::UpdateGutters() {
286 if (local_frame_id_.is_null()) { 286 if (!local_frame_id_.is_valid()) {
287 right_gutter_.reset(); 287 right_gutter_.reset();
288 bottom_gutter_.reset(); 288 bottom_gutter_.reset();
289 return; 289 return;
290 } 290 }
291 291
292 if (current_frame_size_in_dip_.width() < 292 if (current_frame_size_in_dip_.width() <
293 client_->DelegatedFrameHostDesiredSizeInDIP().width()) { 293 client_->DelegatedFrameHostDesiredSizeInDIP().width()) {
294 right_gutter_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); 294 right_gutter_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
295 right_gutter_->SetColor(GetGutterColor()); 295 right_gutter_->SetColor(GetGutterColor());
296 int width = client_->DelegatedFrameHostDesiredSizeInDIP().width() - 296 int width = client_->DelegatedFrameHostDesiredSizeInDIP().width() -
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 if (frame_size.IsEmpty()) { 474 if (frame_size.IsEmpty()) {
475 DCHECK(frame_data->resource_list.empty()); 475 DCHECK(frame_data->resource_list.empty());
476 EvictDelegatedFrame(); 476 EvictDelegatedFrame();
477 } else { 477 } else {
478 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 478 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
479 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 479 cc::SurfaceManager* manager = factory->GetSurfaceManager();
480 if (!surface_factory_) { 480 if (!surface_factory_) {
481 surface_factory_ = 481 surface_factory_ =
482 base::MakeUnique<cc::SurfaceFactory>(frame_sink_id_, manager, this); 482 base::MakeUnique<cc::SurfaceFactory>(frame_sink_id_, manager, this);
483 } 483 }
484 if (local_frame_id_.is_null() || frame_size != current_surface_size_ || 484 if (!local_frame_id_.is_valid() || frame_size != current_surface_size_ ||
485 frame_size_in_dip != current_frame_size_in_dip_) { 485 frame_size_in_dip != current_frame_size_in_dip_) {
486 if (!local_frame_id_.is_null()) 486 if (local_frame_id_.is_valid())
487 surface_factory_->Destroy(local_frame_id_); 487 surface_factory_->Destroy(local_frame_id_);
488 local_frame_id_ = id_allocator_->GenerateId(); 488 local_frame_id_ = id_allocator_->GenerateId();
489 surface_factory_->Create(local_frame_id_); 489 surface_factory_->Create(local_frame_id_);
490 // manager must outlive compositors using it. 490 // manager must outlive compositors using it.
491 client_->DelegatedFrameHostGetLayer()->SetShowSurface( 491 client_->DelegatedFrameHostGetLayer()->SetShowSurface(
492 cc::SurfaceId(frame_sink_id_, local_frame_id_), 492 cc::SurfaceId(frame_sink_id_, local_frame_id_),
493 base::Bind(&SatisfyCallback, base::Unretained(manager)), 493 base::Bind(&SatisfyCallback, base::Unretained(manager)),
494 base::Bind(&RequireCallback, base::Unretained(manager)), frame_size, 494 base::Bind(&RequireCallback, base::Unretained(manager)), frame_size,
495 frame_device_scale_factor, frame_size_in_dip); 495 frame_device_scale_factor, frame_size_in_dip);
496 current_surface_size_ = frame_size; 496 current_surface_size_ = frame_size;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 } 531 }
532 532
533 // Note that |compositor_| may be reset by SetShowSurface or 533 // Note that |compositor_| may be reset by SetShowSurface or
534 // SetShowDelegatedContent above. 534 // SetShowDelegatedContent above.
535 if (!compositor_ || skip_frame) { 535 if (!compositor_ || skip_frame) {
536 SendReclaimCompositorResources(compositor_frame_sink_id, 536 SendReclaimCompositorResources(compositor_frame_sink_id,
537 true /* is_swap_ack */); 537 true /* is_swap_ack */);
538 } else { 538 } else {
539 can_lock_compositor_ = NO_PENDING_COMMIT; 539 can_lock_compositor_ = NO_PENDING_COMMIT;
540 } 540 }
541 if (!local_frame_id_.is_null()) { 541 if (local_frame_id_.is_valid()) {
542 delegated_frame_evictor_->SwappedFrame( 542 delegated_frame_evictor_->SwappedFrame(
543 client_->DelegatedFrameHostIsVisible()); 543 client_->DelegatedFrameHostIsVisible());
544 } 544 }
545 // Note: the frame may have been evicted immediately. 545 // Note: the frame may have been evicted immediately.
546 } 546 }
547 547
548 void DelegatedFrameHost::ClearDelegatedFrame() { 548 void DelegatedFrameHost::ClearDelegatedFrame() {
549 if (!local_frame_id_.is_null()) 549 if (local_frame_id_.is_valid())
550 EvictDelegatedFrame(); 550 EvictDelegatedFrame();
551 } 551 }
552 552
553 void DelegatedFrameHost::SendReclaimCompositorResources( 553 void DelegatedFrameHost::SendReclaimCompositorResources(
554 uint32_t compositor_frame_sink_id, 554 uint32_t compositor_frame_sink_id,
555 bool is_swap_ack) { 555 bool is_swap_ack) {
556 client_->DelegatedFrameHostSendReclaimCompositorResources( 556 client_->DelegatedFrameHostSendReclaimCompositorResources(
557 compositor_frame_sink_id, is_swap_ack, surface_returned_resources_); 557 compositor_frame_sink_id, is_swap_ack, surface_returned_resources_);
558 surface_returned_resources_.clear(); 558 surface_returned_resources_.clear();
559 if (is_swap_ack) { 559 if (is_swap_ack) {
(...skipping 30 matching lines...) Expand all
590 AttemptFrameSubscriberCapture(damage_rect); 590 AttemptFrameSubscriberCapture(damage_rect);
591 } 591 }
592 592
593 void DelegatedFrameHost::SetBeginFrameSource( 593 void DelegatedFrameHost::SetBeginFrameSource(
594 cc::BeginFrameSource* begin_frame_source) { 594 cc::BeginFrameSource* begin_frame_source) {
595 client_->SetBeginFrameSource(begin_frame_source); 595 client_->SetBeginFrameSource(begin_frame_source);
596 } 596 }
597 597
598 void DelegatedFrameHost::EvictDelegatedFrame() { 598 void DelegatedFrameHost::EvictDelegatedFrame() {
599 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); 599 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent();
600 if (!local_frame_id_.is_null()) { 600 if (local_frame_id_.is_valid()) {
601 surface_factory_->Destroy(local_frame_id_); 601 surface_factory_->Destroy(local_frame_id_);
602 local_frame_id_ = cc::LocalFrameId(); 602 local_frame_id_ = cc::LocalFrameId();
603 } 603 }
604 delegated_frame_evictor_->DiscardedFrame(); 604 delegated_frame_evictor_->DiscardedFrame();
605 UpdateGutters(); 605 UpdateGutters();
606 } 606 }
607 607
608 // static 608 // static
609 void DelegatedFrameHost::ReturnSubscriberTexture( 609 void DelegatedFrameHost::ReturnSubscriberTexture(
610 base::WeakPtr<DelegatedFrameHost> dfh, 610 base::WeakPtr<DelegatedFrameHost> dfh,
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 void DelegatedFrameHost::OnUpdateVSyncParameters(base::TimeTicks timebase, 814 void DelegatedFrameHost::OnUpdateVSyncParameters(base::TimeTicks timebase,
815 base::TimeDelta interval) { 815 base::TimeDelta interval) {
816 vsync_timebase_ = timebase; 816 vsync_timebase_ = timebase;
817 vsync_interval_ = interval; 817 vsync_interval_ = interval;
818 } 818 }
819 819
820 //////////////////////////////////////////////////////////////////////////////// 820 ////////////////////////////////////////////////////////////////////////////////
821 // DelegatedFrameHost, ImageTransportFactoryObserver implementation: 821 // DelegatedFrameHost, ImageTransportFactoryObserver implementation:
822 822
823 void DelegatedFrameHost::OnLostResources() { 823 void DelegatedFrameHost::OnLostResources() {
824 if (!local_frame_id_.is_null()) 824 if (local_frame_id_.is_valid())
825 EvictDelegatedFrame(); 825 EvictDelegatedFrame();
826 idle_frame_subscriber_textures_.clear(); 826 idle_frame_subscriber_textures_.clear();
827 yuv_readback_pipeline_.reset(); 827 yuv_readback_pipeline_.reset();
828 828
829 client_->DelegatedFrameHostOnLostCompositorResources(); 829 client_->DelegatedFrameHostOnLostCompositorResources();
830 } 830 }
831 831
832 //////////////////////////////////////////////////////////////////////////////// 832 ////////////////////////////////////////////////////////////////////////////////
833 // DelegatedFrameHost, private: 833 // DelegatedFrameHost, private:
834 834
835 DelegatedFrameHost::~DelegatedFrameHost() { 835 DelegatedFrameHost::~DelegatedFrameHost() {
836 DCHECK(!compositor_); 836 DCHECK(!compositor_);
837 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 837 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
838 factory->GetContextFactory()->RemoveObserver(this); 838 factory->GetContextFactory()->RemoveObserver(this);
839 839
840 if (!local_frame_id_.is_null()) 840 if (local_frame_id_.is_valid())
841 surface_factory_->Destroy(local_frame_id_); 841 surface_factory_->Destroy(local_frame_id_);
842 factory->GetSurfaceManager()->UnregisterSurfaceFactoryClient(frame_sink_id_); 842 factory->GetSurfaceManager()->UnregisterSurfaceFactoryClient(frame_sink_id_);
843 factory->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); 843 factory->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_);
844 844
845 DCHECK(!vsync_manager_.get()); 845 DCHECK(!vsync_manager_.get());
846 } 846 }
847 847
848 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { 848 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) {
849 DCHECK(!compositor_); 849 DCHECK(!compositor_);
850 if (!compositor) 850 if (!compositor)
(...skipping 19 matching lines...) Expand all
870 if (vsync_manager_) { 870 if (vsync_manager_) {
871 vsync_manager_->RemoveObserver(this); 871 vsync_manager_->RemoveObserver(this);
872 vsync_manager_ = nullptr; 872 vsync_manager_ = nullptr;
873 } 873 }
874 874
875 compositor_->RemoveFrameSink(frame_sink_id_); 875 compositor_->RemoveFrameSink(frame_sink_id_);
876 compositor_ = nullptr; 876 compositor_ = nullptr;
877 } 877 }
878 878
879 void DelegatedFrameHost::LockResources() { 879 void DelegatedFrameHost::LockResources() {
880 DCHECK(!local_frame_id_.is_null()); 880 DCHECK(local_frame_id_.is_valid());
881 delegated_frame_evictor_->LockFrame(); 881 delegated_frame_evictor_->LockFrame();
882 } 882 }
883 883
884 void DelegatedFrameHost::RequestCopyOfOutput( 884 void DelegatedFrameHost::RequestCopyOfOutput(
885 std::unique_ptr<cc::CopyOutputRequest> request) { 885 std::unique_ptr<cc::CopyOutputRequest> request) {
886 if (!request_copy_of_output_callback_for_testing_.is_null()) { 886 if (!request_copy_of_output_callback_for_testing_.is_null()) {
887 request_copy_of_output_callback_for_testing_.Run(std::move(request)); 887 request_copy_of_output_callback_for_testing_.Run(std::move(request));
888 } else { 888 } else {
889 client_->DelegatedFrameHostGetLayer()->RequestCopyOfOutput( 889 client_->DelegatedFrameHostGetLayer()->RequestCopyOfOutput(
890 std::move(request)); 890 std::move(request));
891 } 891 }
892 } 892 }
893 893
894 void DelegatedFrameHost::UnlockResources() { 894 void DelegatedFrameHost::UnlockResources() {
895 DCHECK(!local_frame_id_.is_null()); 895 DCHECK(local_frame_id_.is_valid());
896 delegated_frame_evictor_->UnlockFrame(); 896 delegated_frame_evictor_->UnlockFrame();
897 } 897 }
898 898
899 //////////////////////////////////////////////////////////////////////////////// 899 ////////////////////////////////////////////////////////////////////////////////
900 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation: 900 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation:
901 901
902 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer, 902 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer,
903 ui::Layer* new_layer) { 903 ui::Layer* new_layer) {
904 // The new_layer is the one that will be used by our Window, so that's the one 904 // The new_layer is the one that will be used by our Window, so that's the one
905 // that should keep our frame. old_layer will be returned to the 905 // that should keep our frame. old_layer will be returned to the
906 // RecreateLayer caller, and should have a copy. 906 // RecreateLayer caller, and should have a copy.
907 if (!local_frame_id_.is_null()) { 907 if (local_frame_id_.is_valid()) {
908 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 908 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
909 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 909 cc::SurfaceManager* manager = factory->GetSurfaceManager();
910 new_layer->SetShowSurface( 910 new_layer->SetShowSurface(
911 cc::SurfaceId(frame_sink_id_, local_frame_id_), 911 cc::SurfaceId(frame_sink_id_, local_frame_id_),
912 base::Bind(&SatisfyCallback, base::Unretained(manager)), 912 base::Bind(&SatisfyCallback, base::Unretained(manager)),
913 base::Bind(&RequireCallback, base::Unretained(manager)), 913 base::Bind(&RequireCallback, base::Unretained(manager)),
914 current_surface_size_, current_scale_factor_, 914 current_surface_size_, current_scale_factor_,
915 current_frame_size_in_dip_); 915 current_frame_size_in_dip_);
916 } 916 }
917 } 917 }
918 918
919 } // namespace content 919 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698