Chromium Code Reviews| 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_ColorWHITE), | |
|
danakj
2016/03/08 00:09:43
There's some work to be done to not show the wrong
jbauman
2016/03/08 01:45:29
Actually this initialization isn't really necessar
danakj
2016/03/10 22:53:18
Can you make it some more crazy noticeable color t
| |
| 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 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 76 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 76 factory->AddObserver(this); | 77 factory->AddObserver(this); |
| 77 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator(); | 78 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { | 81 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { |
| 81 delegated_frame_evictor_->SetVisible(true); | 82 delegated_frame_evictor_->SetVisible(true); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 | 247 |
| 247 return size_in_dip != resize_lock_->expected_size(); | 248 return size_in_dip != resize_lock_->expected_size(); |
| 248 } | 249 } |
| 249 | 250 |
| 250 void DelegatedFrameHost::WasResized() { | 251 void DelegatedFrameHost::WasResized() { |
| 251 if (client_->DelegatedFrameHostDesiredSizeInDIP() != | 252 if (client_->DelegatedFrameHostDesiredSizeInDIP() != |
| 252 current_frame_size_in_dip_ && | 253 current_frame_size_in_dip_ && |
| 253 !client_->DelegatedFrameHostIsVisible()) | 254 !client_->DelegatedFrameHostIsVisible()) |
| 254 EvictDelegatedFrame(); | 255 EvictDelegatedFrame(); |
| 255 MaybeCreateResizeLock(); | 256 MaybeCreateResizeLock(); |
| 257 UpdateGutters(); | |
| 258 } | |
| 259 | |
| 260 void DelegatedFrameHost::UpdateGutters() { | |
| 261 if (surface_id_.is_null()) { | |
| 262 right_gutter_.reset(); | |
| 263 bottom_gutter_.reset(); | |
| 264 return; | |
| 265 } | |
| 266 if (current_frame_size_in_dip_.width() < | |
| 267 client_->DelegatedFrameHostDesiredSizeInDIP().width()) { | |
| 268 // The right gutter also include the bottom-right corner, if necessary. | |
|
danakj
2016/03/08 00:09:44
includes
jbauman
2016/03/08 01:45:29
Done.
| |
| 269 right_gutter_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | |
| 270 right_gutter_->SetColor(background_color_); | |
| 271 int width = client_->DelegatedFrameHostDesiredSizeInDIP().width() - | |
| 272 current_frame_size_in_dip_.width(); | |
| 273 right_gutter_->SetBounds( | |
| 274 gfx::Rect(current_frame_size_in_dip_.width(), 0, width, | |
| 275 client_->DelegatedFrameHostDesiredSizeInDIP().height())); | |
|
danakj
2016/03/08 00:09:44
nit: put this value in a temp |height| and move th
jbauman
2016/03/08 01:45:29
Done.
| |
| 276 | |
| 277 client_->DelegatedFrameHostGetLayer()->Add(right_gutter_.get()); | |
|
danakj
2016/03/08 00:09:43
One design question.. could cc::SurfaceLayer just
jbauman
2016/03/08 01:45:29
I've thought about it, but currently the SurfaceLa
| |
| 278 } else { | |
| 279 right_gutter_.reset(); | |
| 280 } | |
| 281 | |
| 282 if (current_frame_size_in_dip_.height() < | |
| 283 client_->DelegatedFrameHostDesiredSizeInDIP().height()) { | |
| 284 bottom_gutter_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | |
| 285 bottom_gutter_->SetColor(background_color_); | |
| 286 int height = client_->DelegatedFrameHostDesiredSizeInDIP().height() - | |
| 287 current_frame_size_in_dip_.height(); | |
| 288 bottom_gutter_->SetBounds(gfx::Rect(0, current_frame_size_in_dip_.height(), | |
| 289 current_frame_size_in_dip_.width(), | |
|
danakj
2016/03/08 00:09:43
nit: put this into a |width| var too, it's nice to
jbauman
2016/03/08 01:45:29
Done.
| |
| 290 height)); | |
| 291 client_->DelegatedFrameHostGetLayer()->Add(bottom_gutter_.get()); | |
| 292 | |
| 293 } else { | |
| 294 bottom_gutter_.reset(); | |
| 295 } | |
| 256 } | 296 } |
| 257 | 297 |
| 258 gfx::Size DelegatedFrameHost::GetRequestedRendererSize() const { | 298 gfx::Size DelegatedFrameHost::GetRequestedRendererSize() const { |
| 259 if (resize_lock_) | 299 if (resize_lock_) |
| 260 return resize_lock_->expected_size(); | 300 return resize_lock_->expected_size(); |
| 261 else | 301 else |
| 262 return client_->DelegatedFrameHostDesiredSizeInDIP(); | 302 return client_->DelegatedFrameHostDesiredSizeInDIP(); |
| 263 } | 303 } |
| 264 | 304 |
| 265 void DelegatedFrameHost::CheckResizeLock() { | 305 void DelegatedFrameHost::CheckResizeLock() { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 | 433 |
| 394 surface_factory_.reset(); | 434 surface_factory_.reset(); |
| 395 if (!surface_returned_resources_.empty()) | 435 if (!surface_returned_resources_.empty()) |
| 396 SendReturnedDelegatedResources(last_output_surface_id_); | 436 SendReturnedDelegatedResources(last_output_surface_id_); |
| 397 | 437 |
| 398 last_output_surface_id_ = output_surface_id; | 438 last_output_surface_id_ = output_surface_id; |
| 399 } | 439 } |
| 400 bool skip_frame = false; | 440 bool skip_frame = false; |
| 401 pending_delegated_ack_count_++; | 441 pending_delegated_ack_count_++; |
| 402 | 442 |
| 443 background_color_ = frame->metadata.root_background_color; | |
| 444 | |
| 403 if (frame_size.IsEmpty()) { | 445 if (frame_size.IsEmpty()) { |
| 404 DCHECK(frame_data->resource_list.empty()); | 446 DCHECK(frame_data->resource_list.empty()); |
| 405 EvictDelegatedFrame(); | 447 EvictDelegatedFrame(); |
| 406 } else { | 448 } else { |
| 407 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 449 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 408 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 450 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
| 409 if (!surface_factory_) { | 451 if (!surface_factory_) { |
| 410 surface_factory_ = | 452 surface_factory_ = |
| 411 make_scoped_ptr(new cc::SurfaceFactory(manager, this)); | 453 make_scoped_ptr(new cc::SurfaceFactory(manager, this)); |
| 412 } | 454 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 440 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, | 482 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, |
| 441 AsWeakPtr(), output_surface_id); | 483 AsWeakPtr(), output_surface_id); |
| 442 } | 484 } |
| 443 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 485 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
| 444 ack_callback); | 486 ack_callback); |
| 445 } | 487 } |
| 446 released_front_lock_ = NULL; | 488 released_front_lock_ = NULL; |
| 447 current_frame_size_in_dip_ = frame_size_in_dip; | 489 current_frame_size_in_dip_ = frame_size_in_dip; |
| 448 CheckResizeLock(); | 490 CheckResizeLock(); |
| 449 | 491 |
| 492 UpdateGutters(); | |
| 493 | |
| 450 if (!damage_rect_in_dip.IsEmpty()) | 494 if (!damage_rect_in_dip.IsEmpty()) |
| 451 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( | 495 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( |
| 452 damage_rect_in_dip); | 496 damage_rect_in_dip); |
|
danakj
2016/03/08 00:09:43
When if ever should damage include the gutters?
jbauman
2016/03/08 01:45:29
Never, AFAIK. This is only supposed to use damage
| |
| 453 | 497 |
| 454 // Note that |compositor_| may be reset by SetShowSurface or | 498 // Note that |compositor_| may be reset by SetShowSurface or |
| 455 // SetShowDelegatedContent above. | 499 // SetShowDelegatedContent above. |
| 456 if (!compositor_ || skip_frame) { | 500 if (!compositor_ || skip_frame) { |
| 457 SendDelegatedFrameAck(output_surface_id); | 501 SendDelegatedFrameAck(output_surface_id); |
| 458 } else { | 502 } else { |
| 459 can_lock_compositor_ = NO_PENDING_COMMIT; | 503 can_lock_compositor_ = NO_PENDING_COMMIT; |
| 460 } | 504 } |
| 461 if (!surface_id_.is_null()) | 505 if (!surface_id_.is_null()) |
| 462 delegated_frame_evictor_->SwappedFrame( | 506 delegated_frame_evictor_->SwappedFrame( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 // TODO(tansell): Hook this up. | 561 // TODO(tansell): Hook this up. |
| 518 } | 562 } |
| 519 | 563 |
| 520 void DelegatedFrameHost::EvictDelegatedFrame() { | 564 void DelegatedFrameHost::EvictDelegatedFrame() { |
| 521 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); | 565 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); |
| 522 if (!surface_id_.is_null()) { | 566 if (!surface_id_.is_null()) { |
| 523 surface_factory_->Destroy(surface_id_); | 567 surface_factory_->Destroy(surface_id_); |
| 524 surface_id_ = cc::SurfaceId(); | 568 surface_id_ = cc::SurfaceId(); |
| 525 } | 569 } |
| 526 delegated_frame_evictor_->DiscardedFrame(); | 570 delegated_frame_evictor_->DiscardedFrame(); |
| 571 UpdateGutters(); | |
| 527 } | 572 } |
| 528 | 573 |
| 529 // static | 574 // static |
| 530 void DelegatedFrameHost::ReturnSubscriberTexture( | 575 void DelegatedFrameHost::ReturnSubscriberTexture( |
| 531 base::WeakPtr<DelegatedFrameHost> dfh, | 576 base::WeakPtr<DelegatedFrameHost> dfh, |
| 532 scoped_refptr<OwnedMailbox> subscriber_texture, | 577 scoped_refptr<OwnedMailbox> subscriber_texture, |
| 533 const gpu::SyncToken& sync_token) { | 578 const gpu::SyncToken& sync_token) { |
| 534 if (!subscriber_texture.get()) | 579 if (!subscriber_texture.get()) |
| 535 return; | 580 return; |
| 536 if (!dfh) | 581 if (!dfh) |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 836 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 881 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
| 837 new_layer->SetShowSurface( | 882 new_layer->SetShowSurface( |
| 838 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), | 883 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
| 839 base::Bind(&RequireCallback, base::Unretained(manager)), | 884 base::Bind(&RequireCallback, base::Unretained(manager)), |
| 840 current_surface_size_, current_scale_factor_, | 885 current_surface_size_, current_scale_factor_, |
| 841 current_frame_size_in_dip_); | 886 current_frame_size_in_dip_); |
| 842 } | 887 } |
| 843 } | 888 } |
| 844 | 889 |
| 845 } // namespace content | 890 } // namespace content |
| OLD | NEW |