| 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/compositor/delegated_frame_host.h" | 5 #include "content/browser/compositor/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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 //////////////////////////////////////////////////////////////////////////////// | 62 //////////////////////////////////////////////////////////////////////////////// |
| 63 // DelegatedFrameHost | 63 // DelegatedFrameHost |
| 64 | 64 |
| 65 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client) | 65 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client) |
| 66 : client_(client), | 66 : client_(client), |
| 67 compositor_(nullptr), | 67 compositor_(nullptr), |
| 68 tick_clock_(new base::DefaultTickClock()), | 68 tick_clock_(new base::DefaultTickClock()), |
| 69 last_output_surface_id_(0), | 69 last_output_surface_id_(0), |
| 70 pending_delegated_ack_count_(0), | 70 pending_delegated_ack_count_(0), |
| 71 skipped_frames_(false), | 71 skipped_frames_(false), |
| 72 background_color_(SK_ColorRED), |
| 72 current_scale_factor_(1.f), | 73 current_scale_factor_(1.f), |
| 73 can_lock_compositor_(YES_CAN_LOCK), | 74 can_lock_compositor_(YES_CAN_LOCK), |
| 74 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), | 75 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), |
| 75 begin_frame_source_(nullptr) { | 76 begin_frame_source_(nullptr) { |
| 76 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 77 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 77 factory->AddObserver(this); | 78 factory->AddObserver(this); |
| 78 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator(); | 79 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator(); |
| 79 factory->GetSurfaceManager()->RegisterSurfaceFactoryClient( | 80 factory->GetSurfaceManager()->RegisterSurfaceFactoryClient( |
| 80 id_allocator_->id_namespace(), this); | 81 id_allocator_->id_namespace(), this); |
| 81 } | 82 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 250 |
| 250 return size_in_dip != resize_lock_->expected_size(); | 251 return size_in_dip != resize_lock_->expected_size(); |
| 251 } | 252 } |
| 252 | 253 |
| 253 void DelegatedFrameHost::WasResized() { | 254 void DelegatedFrameHost::WasResized() { |
| 254 if (client_->DelegatedFrameHostDesiredSizeInDIP() != | 255 if (client_->DelegatedFrameHostDesiredSizeInDIP() != |
| 255 current_frame_size_in_dip_ && | 256 current_frame_size_in_dip_ && |
| 256 !client_->DelegatedFrameHostIsVisible()) | 257 !client_->DelegatedFrameHostIsVisible()) |
| 257 EvictDelegatedFrame(); | 258 EvictDelegatedFrame(); |
| 258 MaybeCreateResizeLock(); | 259 MaybeCreateResizeLock(); |
| 260 UpdateGutters(); |
| 261 } |
| 262 |
| 263 void DelegatedFrameHost::UpdateGutters() { |
| 264 if (surface_id_.is_null()) { |
| 265 right_gutter_.reset(); |
| 266 bottom_gutter_.reset(); |
| 267 return; |
| 268 } |
| 269 if (current_frame_size_in_dip_.width() < |
| 270 client_->DelegatedFrameHostDesiredSizeInDIP().width()) { |
| 271 right_gutter_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
| 272 right_gutter_->SetColor(background_color_); |
| 273 int width = client_->DelegatedFrameHostDesiredSizeInDIP().width() - |
| 274 current_frame_size_in_dip_.width(); |
| 275 // The right gutter also includes the bottom-right corner, if necessary. |
| 276 int height = client_->DelegatedFrameHostDesiredSizeInDIP().height(); |
| 277 right_gutter_->SetBounds( |
| 278 gfx::Rect(current_frame_size_in_dip_.width(), 0, width, height)); |
| 279 |
| 280 client_->DelegatedFrameHostGetLayer()->Add(right_gutter_.get()); |
| 281 } else { |
| 282 right_gutter_.reset(); |
| 283 } |
| 284 |
| 285 if (current_frame_size_in_dip_.height() < |
| 286 client_->DelegatedFrameHostDesiredSizeInDIP().height()) { |
| 287 bottom_gutter_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
| 288 bottom_gutter_->SetColor(background_color_); |
| 289 int width = current_frame_size_in_dip_.width(); |
| 290 int height = client_->DelegatedFrameHostDesiredSizeInDIP().height() - |
| 291 current_frame_size_in_dip_.height(); |
| 292 bottom_gutter_->SetBounds( |
| 293 gfx::Rect(0, current_frame_size_in_dip_.height(), width, height)); |
| 294 client_->DelegatedFrameHostGetLayer()->Add(bottom_gutter_.get()); |
| 295 |
| 296 } else { |
| 297 bottom_gutter_.reset(); |
| 298 } |
| 259 } | 299 } |
| 260 | 300 |
| 261 gfx::Size DelegatedFrameHost::GetRequestedRendererSize() const { | 301 gfx::Size DelegatedFrameHost::GetRequestedRendererSize() const { |
| 262 if (resize_lock_) | 302 if (resize_lock_) |
| 263 return resize_lock_->expected_size(); | 303 return resize_lock_->expected_size(); |
| 264 else | 304 else |
| 265 return client_->DelegatedFrameHostDesiredSizeInDIP(); | 305 return client_->DelegatedFrameHostDesiredSizeInDIP(); |
| 266 } | 306 } |
| 267 | 307 |
| 268 void DelegatedFrameHost::CheckResizeLock() { | 308 void DelegatedFrameHost::CheckResizeLock() { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 | 436 |
| 397 surface_factory_.reset(); | 437 surface_factory_.reset(); |
| 398 if (!surface_returned_resources_.empty()) | 438 if (!surface_returned_resources_.empty()) |
| 399 SendReturnedDelegatedResources(last_output_surface_id_); | 439 SendReturnedDelegatedResources(last_output_surface_id_); |
| 400 | 440 |
| 401 last_output_surface_id_ = output_surface_id; | 441 last_output_surface_id_ = output_surface_id; |
| 402 } | 442 } |
| 403 bool skip_frame = false; | 443 bool skip_frame = false; |
| 404 pending_delegated_ack_count_++; | 444 pending_delegated_ack_count_++; |
| 405 | 445 |
| 446 background_color_ = frame->metadata.root_background_color; |
| 447 |
| 406 if (frame_size.IsEmpty()) { | 448 if (frame_size.IsEmpty()) { |
| 407 DCHECK(frame_data->resource_list.empty()); | 449 DCHECK(frame_data->resource_list.empty()); |
| 408 EvictDelegatedFrame(); | 450 EvictDelegatedFrame(); |
| 409 } else { | 451 } else { |
| 410 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 452 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 411 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 453 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
| 412 if (!surface_factory_) { | 454 if (!surface_factory_) { |
| 413 surface_factory_ = | 455 surface_factory_ = |
| 414 make_scoped_ptr(new cc::SurfaceFactory(manager, this)); | 456 make_scoped_ptr(new cc::SurfaceFactory(manager, this)); |
| 415 } | 457 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 443 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, | 485 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, |
| 444 AsWeakPtr(), output_surface_id); | 486 AsWeakPtr(), output_surface_id); |
| 445 } | 487 } |
| 446 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 488 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
| 447 ack_callback); | 489 ack_callback); |
| 448 } | 490 } |
| 449 released_front_lock_ = NULL; | 491 released_front_lock_ = NULL; |
| 450 current_frame_size_in_dip_ = frame_size_in_dip; | 492 current_frame_size_in_dip_ = frame_size_in_dip; |
| 451 CheckResizeLock(); | 493 CheckResizeLock(); |
| 452 | 494 |
| 495 UpdateGutters(); |
| 496 |
| 453 if (!damage_rect_in_dip.IsEmpty()) | 497 if (!damage_rect_in_dip.IsEmpty()) |
| 454 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( | 498 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( |
| 455 damage_rect_in_dip); | 499 damage_rect_in_dip); |
| 456 | 500 |
| 457 // Note that |compositor_| may be reset by SetShowSurface or | 501 // Note that |compositor_| may be reset by SetShowSurface or |
| 458 // SetShowDelegatedContent above. | 502 // SetShowDelegatedContent above. |
| 459 if (!compositor_ || skip_frame) { | 503 if (!compositor_ || skip_frame) { |
| 460 SendDelegatedFrameAck(output_surface_id); | 504 SendDelegatedFrameAck(output_surface_id); |
| 461 } else { | 505 } else { |
| 462 can_lock_compositor_ = NO_PENDING_COMMIT; | 506 can_lock_compositor_ = NO_PENDING_COMMIT; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 // the renderer as an external begin frame source. | 564 // the renderer as an external begin frame source. |
| 521 } | 565 } |
| 522 | 566 |
| 523 void DelegatedFrameHost::EvictDelegatedFrame() { | 567 void DelegatedFrameHost::EvictDelegatedFrame() { |
| 524 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); | 568 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); |
| 525 if (!surface_id_.is_null()) { | 569 if (!surface_id_.is_null()) { |
| 526 surface_factory_->Destroy(surface_id_); | 570 surface_factory_->Destroy(surface_id_); |
| 527 surface_id_ = cc::SurfaceId(); | 571 surface_id_ = cc::SurfaceId(); |
| 528 } | 572 } |
| 529 delegated_frame_evictor_->DiscardedFrame(); | 573 delegated_frame_evictor_->DiscardedFrame(); |
| 574 UpdateGutters(); |
| 530 } | 575 } |
| 531 | 576 |
| 532 // static | 577 // static |
| 533 void DelegatedFrameHost::ReturnSubscriberTexture( | 578 void DelegatedFrameHost::ReturnSubscriberTexture( |
| 534 base::WeakPtr<DelegatedFrameHost> dfh, | 579 base::WeakPtr<DelegatedFrameHost> dfh, |
| 535 scoped_refptr<OwnedMailbox> subscriber_texture, | 580 scoped_refptr<OwnedMailbox> subscriber_texture, |
| 536 const gpu::SyncToken& sync_token) { | 581 const gpu::SyncToken& sync_token) { |
| 537 if (!subscriber_texture.get()) | 582 if (!subscriber_texture.get()) |
| 538 return; | 583 return; |
| 539 if (!dfh) | 584 if (!dfh) |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 898 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
| 854 new_layer->SetShowSurface( | 899 new_layer->SetShowSurface( |
| 855 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), | 900 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
| 856 base::Bind(&RequireCallback, base::Unretained(manager)), | 901 base::Bind(&RequireCallback, base::Unretained(manager)), |
| 857 current_surface_size_, current_scale_factor_, | 902 current_surface_size_, current_scale_factor_, |
| 858 current_frame_size_in_dip_); | 903 current_frame_size_in_dip_); |
| 859 } | 904 } |
| 860 } | 905 } |
| 861 | 906 |
| 862 } // namespace content | 907 } // namespace content |
| OLD | NEW |