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

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: Rebase Created 4 years, 1 month 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( 85 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(
86 frame_sink_id_, factory->GetSurfaceManager(), this); 86 frame_sink_id_, factory->GetSurfaceManager(), this);
87 } 87 }
88 88
89 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { 89 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) {
90 delegated_frame_evictor_->SetVisible(true); 90 delegated_frame_evictor_->SetVisible(true);
91 91
92 if (local_frame_id_.is_null() && !released_front_lock_.get()) { 92 if (!local_frame_id_.is_valid() && !released_front_lock_.get()) {
93 if (compositor_) 93 if (compositor_)
94 released_front_lock_ = compositor_->GetCompositorLock(); 94 released_front_lock_ = compositor_->GetCompositorLock();
95 } 95 }
96 96
97 if (compositor_) { 97 if (compositor_) {
98 compositor_->SetLatencyInfo(latency_info); 98 compositor_->SetLatencyInfo(latency_info);
99 } 99 }
100 } 100 }
101 101
102 bool DelegatedFrameHost::HasSavedFrame() { 102 bool DelegatedFrameHost::HasSavedFrame() {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 211
212 cc::FrameSinkId DelegatedFrameHost::GetFrameSinkId() { 212 cc::FrameSinkId DelegatedFrameHost::GetFrameSinkId() {
213 return frame_sink_id_; 213 return frame_sink_id_;
214 } 214 }
215 215
216 cc::SurfaceId DelegatedFrameHost::SurfaceIdAtPoint( 216 cc::SurfaceId DelegatedFrameHost::SurfaceIdAtPoint(
217 cc::SurfaceHittestDelegate* delegate, 217 cc::SurfaceHittestDelegate* delegate,
218 const gfx::Point& point, 218 const gfx::Point& point,
219 gfx::Point* transformed_point) { 219 gfx::Point* transformed_point) {
220 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_); 220 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_);
221 if (surface_id.is_null()) 221 if (!surface_id.is_valid())
222 return surface_id; 222 return surface_id;
223 cc::SurfaceHittest hittest(delegate, GetSurfaceManager()); 223 cc::SurfaceHittest hittest(delegate, GetSurfaceManager());
224 gfx::Transform target_transform; 224 gfx::Transform target_transform;
225 cc::SurfaceId target_local_frame_id = 225 cc::SurfaceId target_local_frame_id =
226 hittest.GetTargetSurfaceAtPoint(surface_id, point, &target_transform); 226 hittest.GetTargetSurfaceAtPoint(surface_id, point, &target_transform);
227 *transformed_point = point; 227 *transformed_point = point;
228 if (!target_local_frame_id.is_null()) 228 if (target_local_frame_id.is_valid())
229 target_transform.TransformPoint(transformed_point); 229 target_transform.TransformPoint(transformed_point);
230 return target_local_frame_id; 230 return target_local_frame_id;
231 } 231 }
232 232
233 bool DelegatedFrameHost::TransformPointToLocalCoordSpace( 233 bool DelegatedFrameHost::TransformPointToLocalCoordSpace(
234 const gfx::Point& point, 234 const gfx::Point& point,
235 const cc::SurfaceId& original_surface, 235 const cc::SurfaceId& original_surface,
236 gfx::Point* transformed_point) { 236 gfx::Point* transformed_point) {
237 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_); 237 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_);
238 if (surface_id.is_null()) 238 if (!surface_id.is_valid())
239 return false; 239 return false;
240 *transformed_point = point; 240 *transformed_point = point;
241 if (original_surface == surface_id) 241 if (original_surface == surface_id)
242 return true; 242 return true;
243 243
244 cc::SurfaceHittest hittest(nullptr, GetSurfaceManager()); 244 cc::SurfaceHittest hittest(nullptr, GetSurfaceManager());
245 return hittest.TransformPointToTargetSurface(original_surface, surface_id, 245 return hittest.TransformPointToTargetSurface(original_surface, surface_id,
246 transformed_point); 246 transformed_point);
247 } 247 }
248 248
249 bool DelegatedFrameHost::TransformPointToCoordSpaceForView( 249 bool DelegatedFrameHost::TransformPointToCoordSpaceForView(
250 const gfx::Point& point, 250 const gfx::Point& point,
251 RenderWidgetHostViewBase* target_view, 251 RenderWidgetHostViewBase* target_view,
252 gfx::Point* transformed_point) { 252 gfx::Point* transformed_point) {
253 if (local_frame_id_.is_null()) 253 if (!local_frame_id_.is_valid())
254 return false; 254 return false;
255 255
256 return target_view->TransformPointToLocalCoordSpace( 256 return target_view->TransformPointToLocalCoordSpace(
257 point, cc::SurfaceId(frame_sink_id_, local_frame_id_), transformed_point); 257 point, cc::SurfaceId(frame_sink_id_, local_frame_id_), transformed_point);
258 } 258 }
259 259
260 bool DelegatedFrameHost::ShouldSkipFrame(gfx::Size size_in_dip) const { 260 bool DelegatedFrameHost::ShouldSkipFrame(gfx::Size size_in_dip) const {
261 // Should skip a frame only when another frame from the renderer is guaranteed 261 // Should skip a frame only when another frame from the renderer is guaranteed
262 // to replace it. Otherwise may cause hangs when the renderer is waiting for 262 // to replace it. Otherwise may cause hangs when the renderer is waiting for
263 // the completion of latency infos (such as when taking a Snapshot.) 263 // the completion of latency infos (such as when taking a Snapshot.)
(...skipping 14 matching lines...) Expand all
278 } 278 }
279 279
280 SkColor DelegatedFrameHost::GetGutterColor() const { 280 SkColor DelegatedFrameHost::GetGutterColor() const {
281 // In fullscreen mode resizing is uncommon, so it makes more sense to 281 // In fullscreen mode resizing is uncommon, so it makes more sense to
282 // make the initial switch to fullscreen mode look better by using black as 282 // make the initial switch to fullscreen mode look better by using black as
283 // the gutter color. 283 // the gutter color.
284 return client_->DelegatedFrameHostGetGutterColor(background_color_); 284 return client_->DelegatedFrameHostGetGutterColor(background_color_);
285 } 285 }
286 286
287 void DelegatedFrameHost::UpdateGutters() { 287 void DelegatedFrameHost::UpdateGutters() {
288 if (local_frame_id_.is_null()) { 288 if (!local_frame_id_.is_valid()) {
289 right_gutter_.reset(); 289 right_gutter_.reset();
290 bottom_gutter_.reset(); 290 bottom_gutter_.reset();
291 return; 291 return;
292 } 292 }
293 293
294 if (current_frame_size_in_dip_.width() < 294 if (current_frame_size_in_dip_.width() <
295 client_->DelegatedFrameHostDesiredSizeInDIP().width()) { 295 client_->DelegatedFrameHostDesiredSizeInDIP().width()) {
296 right_gutter_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); 296 right_gutter_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
297 right_gutter_->SetColor(GetGutterColor()); 297 right_gutter_->SetColor(GetGutterColor());
298 int width = client_->DelegatedFrameHostDesiredSizeInDIP().width() - 298 int width = client_->DelegatedFrameHostDesiredSizeInDIP().width() -
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // DelegatedFrameHost (e.g., a call to CopyFromCompositingSurface() for 382 // DelegatedFrameHost (e.g., a call to CopyFromCompositingSurface() for
383 // screenshots) since those copy requests do not specify |frame_subscriber()| 383 // screenshots) since those copy requests do not specify |frame_subscriber()|
384 // as a source. 384 // as a source.
385 request->set_source(frame_subscriber()); 385 request->set_source(frame_subscriber());
386 if (subscriber_texture.get()) { 386 if (subscriber_texture.get()) {
387 request->SetTextureMailbox(cc::TextureMailbox( 387 request->SetTextureMailbox(cc::TextureMailbox(
388 subscriber_texture->mailbox(), subscriber_texture->sync_token(), 388 subscriber_texture->mailbox(), subscriber_texture->sync_token(),
389 subscriber_texture->target())); 389 subscriber_texture->target()));
390 } 390 }
391 391
392 if (!local_frame_id_.is_null()) { 392 if (local_frame_id_.is_valid()) {
393 // To avoid unnecessary composites, go directly to the Surface rather than 393 // To avoid unnecessary composites, go directly to the Surface rather than
394 // through RequestCopyOfOutput (which goes through the browser 394 // through RequestCopyOfOutput (which goes through the browser
395 // compositor). 395 // compositor).
396 if (!request_copy_of_output_callback_for_testing_.is_null()) 396 if (!request_copy_of_output_callback_for_testing_.is_null())
397 request_copy_of_output_callback_for_testing_.Run(std::move(request)); 397 request_copy_of_output_callback_for_testing_.Run(std::move(request));
398 else 398 else
399 surface_factory_->RequestCopyOfSurface(local_frame_id_, 399 surface_factory_->RequestCopyOfSurface(local_frame_id_,
400 std::move(request)); 400 std::move(request));
401 } else { 401 } else {
402 request->set_area(gfx::Rect(current_frame_size_in_dip_)); 402 request->set_area(gfx::Rect(current_frame_size_in_dip_));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 pending_delegated_ack_count_++; 469 pending_delegated_ack_count_++;
470 470
471 background_color_ = frame.metadata.root_background_color; 471 background_color_ = frame.metadata.root_background_color;
472 472
473 if (frame_size.IsEmpty()) { 473 if (frame_size.IsEmpty()) {
474 DCHECK(frame.resource_list.empty()); 474 DCHECK(frame.resource_list.empty());
475 EvictDelegatedFrame(); 475 EvictDelegatedFrame();
476 } else { 476 } else {
477 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 477 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
478 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 478 cc::SurfaceManager* manager = factory->GetSurfaceManager();
479 if (local_frame_id_.is_null() || frame_size != current_surface_size_ || 479 if (!local_frame_id_.is_valid() || frame_size != current_surface_size_ ||
480 frame_size_in_dip != current_frame_size_in_dip_) { 480 frame_size_in_dip != current_frame_size_in_dip_) {
481 if (!local_frame_id_.is_null()) 481 if (local_frame_id_.is_valid())
482 surface_factory_->Destroy(local_frame_id_); 482 surface_factory_->Destroy(local_frame_id_);
483 local_frame_id_ = id_allocator_->GenerateId(); 483 local_frame_id_ = id_allocator_->GenerateId();
484 surface_factory_->Create(local_frame_id_); 484 surface_factory_->Create(local_frame_id_);
485 // manager must outlive compositors using it. 485 // manager must outlive compositors using it.
486 client_->DelegatedFrameHostGetLayer()->SetShowSurface( 486 client_->DelegatedFrameHostGetLayer()->SetShowSurface(
487 cc::SurfaceId(frame_sink_id_, local_frame_id_), 487 cc::SurfaceId(frame_sink_id_, local_frame_id_),
488 base::Bind(&SatisfyCallback, base::Unretained(manager)), 488 base::Bind(&SatisfyCallback, base::Unretained(manager)),
489 base::Bind(&RequireCallback, base::Unretained(manager)), frame_size, 489 base::Bind(&RequireCallback, base::Unretained(manager)), frame_size,
490 frame_device_scale_factor, frame_size_in_dip); 490 frame_device_scale_factor, frame_size_in_dip);
491 current_surface_size_ = frame_size; 491 current_surface_size_ = frame_size;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 526 }
527 527
528 // Note that |compositor_| may be reset by SetShowSurface or 528 // Note that |compositor_| may be reset by SetShowSurface or
529 // SetShowDelegatedContent above. 529 // SetShowDelegatedContent above.
530 if (!compositor_ || skip_frame) { 530 if (!compositor_ || skip_frame) {
531 SendReclaimCompositorResources(compositor_frame_sink_id, 531 SendReclaimCompositorResources(compositor_frame_sink_id,
532 true /* is_swap_ack */); 532 true /* is_swap_ack */);
533 } else { 533 } else {
534 can_lock_compositor_ = NO_PENDING_COMMIT; 534 can_lock_compositor_ = NO_PENDING_COMMIT;
535 } 535 }
536 if (!local_frame_id_.is_null()) { 536 if (local_frame_id_.is_valid()) {
537 delegated_frame_evictor_->SwappedFrame( 537 delegated_frame_evictor_->SwappedFrame(
538 client_->DelegatedFrameHostIsVisible()); 538 client_->DelegatedFrameHostIsVisible());
539 } 539 }
540 // Note: the frame may have been evicted immediately. 540 // Note: the frame may have been evicted immediately.
541 } 541 }
542 542
543 void DelegatedFrameHost::ClearDelegatedFrame() { 543 void DelegatedFrameHost::ClearDelegatedFrame() {
544 if (!local_frame_id_.is_null()) 544 if (local_frame_id_.is_valid())
545 EvictDelegatedFrame(); 545 EvictDelegatedFrame();
546 } 546 }
547 547
548 void DelegatedFrameHost::SendReclaimCompositorResources( 548 void DelegatedFrameHost::SendReclaimCompositorResources(
549 uint32_t compositor_frame_sink_id, 549 uint32_t compositor_frame_sink_id,
550 bool is_swap_ack) { 550 bool is_swap_ack) {
551 client_->DelegatedFrameHostSendReclaimCompositorResources( 551 client_->DelegatedFrameHostSendReclaimCompositorResources(
552 compositor_frame_sink_id, is_swap_ack, surface_returned_resources_); 552 compositor_frame_sink_id, is_swap_ack, surface_returned_resources_);
553 surface_returned_resources_.clear(); 553 surface_returned_resources_.clear();
554 if (is_swap_ack) { 554 if (is_swap_ack) {
(...skipping 30 matching lines...) Expand all
585 AttemptFrameSubscriberCapture(damage_rect); 585 AttemptFrameSubscriberCapture(damage_rect);
586 } 586 }
587 587
588 void DelegatedFrameHost::SetBeginFrameSource( 588 void DelegatedFrameHost::SetBeginFrameSource(
589 cc::BeginFrameSource* begin_frame_source) { 589 cc::BeginFrameSource* begin_frame_source) {
590 client_->SetBeginFrameSource(begin_frame_source); 590 client_->SetBeginFrameSource(begin_frame_source);
591 } 591 }
592 592
593 void DelegatedFrameHost::EvictDelegatedFrame() { 593 void DelegatedFrameHost::EvictDelegatedFrame() {
594 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); 594 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent();
595 if (!local_frame_id_.is_null()) { 595 if (local_frame_id_.is_valid()) {
596 surface_factory_->Destroy(local_frame_id_); 596 surface_factory_->Destroy(local_frame_id_);
597 local_frame_id_ = cc::LocalFrameId(); 597 local_frame_id_ = cc::LocalFrameId();
598 } 598 }
599 delegated_frame_evictor_->DiscardedFrame(); 599 delegated_frame_evictor_->DiscardedFrame();
600 UpdateGutters(); 600 UpdateGutters();
601 } 601 }
602 602
603 // static 603 // static
604 void DelegatedFrameHost::ReturnSubscriberTexture( 604 void DelegatedFrameHost::ReturnSubscriberTexture(
605 base::WeakPtr<DelegatedFrameHost> dfh, 605 base::WeakPtr<DelegatedFrameHost> dfh,
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 void DelegatedFrameHost::OnUpdateVSyncParameters(base::TimeTicks timebase, 807 void DelegatedFrameHost::OnUpdateVSyncParameters(base::TimeTicks timebase,
808 base::TimeDelta interval) { 808 base::TimeDelta interval) {
809 vsync_timebase_ = timebase; 809 vsync_timebase_ = timebase;
810 vsync_interval_ = interval; 810 vsync_interval_ = interval;
811 } 811 }
812 812
813 //////////////////////////////////////////////////////////////////////////////// 813 ////////////////////////////////////////////////////////////////////////////////
814 // DelegatedFrameHost, ImageTransportFactoryObserver implementation: 814 // DelegatedFrameHost, ImageTransportFactoryObserver implementation:
815 815
816 void DelegatedFrameHost::OnLostResources() { 816 void DelegatedFrameHost::OnLostResources() {
817 if (!local_frame_id_.is_null()) 817 if (local_frame_id_.is_valid())
818 EvictDelegatedFrame(); 818 EvictDelegatedFrame();
819 idle_frame_subscriber_textures_.clear(); 819 idle_frame_subscriber_textures_.clear();
820 yuv_readback_pipeline_.reset(); 820 yuv_readback_pipeline_.reset();
821 } 821 }
822 822
823 //////////////////////////////////////////////////////////////////////////////// 823 ////////////////////////////////////////////////////////////////////////////////
824 // DelegatedFrameHost, private: 824 // DelegatedFrameHost, private:
825 825
826 DelegatedFrameHost::~DelegatedFrameHost() { 826 DelegatedFrameHost::~DelegatedFrameHost() {
827 DCHECK(!compositor_); 827 DCHECK(!compositor_);
828 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 828 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
829 factory->GetContextFactory()->RemoveObserver(this); 829 factory->GetContextFactory()->RemoveObserver(this);
830 830
831 if (!local_frame_id_.is_null()) 831 if (local_frame_id_.is_valid())
832 surface_factory_->Destroy(local_frame_id_); 832 surface_factory_->Destroy(local_frame_id_);
833 factory->GetSurfaceManager()->UnregisterSurfaceFactoryClient(frame_sink_id_); 833 factory->GetSurfaceManager()->UnregisterSurfaceFactoryClient(frame_sink_id_);
834 factory->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); 834 factory->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_);
835 835
836 DCHECK(!vsync_manager_.get()); 836 DCHECK(!vsync_manager_.get());
837 } 837 }
838 838
839 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { 839 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) {
840 DCHECK(!compositor_); 840 DCHECK(!compositor_);
841 if (!compositor) 841 if (!compositor)
(...skipping 19 matching lines...) Expand all
861 if (vsync_manager_) { 861 if (vsync_manager_) {
862 vsync_manager_->RemoveObserver(this); 862 vsync_manager_->RemoveObserver(this);
863 vsync_manager_ = nullptr; 863 vsync_manager_ = nullptr;
864 } 864 }
865 865
866 compositor_->RemoveFrameSink(frame_sink_id_); 866 compositor_->RemoveFrameSink(frame_sink_id_);
867 compositor_ = nullptr; 867 compositor_ = nullptr;
868 } 868 }
869 869
870 void DelegatedFrameHost::LockResources() { 870 void DelegatedFrameHost::LockResources() {
871 DCHECK(!local_frame_id_.is_null()); 871 DCHECK(local_frame_id_.is_valid());
872 delegated_frame_evictor_->LockFrame(); 872 delegated_frame_evictor_->LockFrame();
873 } 873 }
874 874
875 void DelegatedFrameHost::RequestCopyOfOutput( 875 void DelegatedFrameHost::RequestCopyOfOutput(
876 std::unique_ptr<cc::CopyOutputRequest> request) { 876 std::unique_ptr<cc::CopyOutputRequest> request) {
877 if (!request_copy_of_output_callback_for_testing_.is_null()) { 877 if (!request_copy_of_output_callback_for_testing_.is_null()) {
878 request_copy_of_output_callback_for_testing_.Run(std::move(request)); 878 request_copy_of_output_callback_for_testing_.Run(std::move(request));
879 } else { 879 } else {
880 client_->DelegatedFrameHostGetLayer()->RequestCopyOfOutput( 880 client_->DelegatedFrameHostGetLayer()->RequestCopyOfOutput(
881 std::move(request)); 881 std::move(request));
882 } 882 }
883 } 883 }
884 884
885 void DelegatedFrameHost::UnlockResources() { 885 void DelegatedFrameHost::UnlockResources() {
886 DCHECK(!local_frame_id_.is_null()); 886 DCHECK(local_frame_id_.is_valid());
887 delegated_frame_evictor_->UnlockFrame(); 887 delegated_frame_evictor_->UnlockFrame();
888 } 888 }
889 889
890 } // namespace content 890 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698