OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/exo/surface.h" | 5 #include "components/exo/surface.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 UpdateSurface(true); | 477 UpdateSurface(true); |
478 | 478 |
479 if (!old_surface_id.is_null() && old_surface_id != surface_id_) { | 479 if (!old_surface_id.is_null() && old_surface_id != surface_id_) { |
480 factory_owner_->surface_factory_->SetPreviousFrameSurface(surface_id_, | 480 factory_owner_->surface_factory_->SetPreviousFrameSurface(surface_id_, |
481 old_surface_id); | 481 old_surface_id); |
482 factory_owner_->surface_factory_->Destroy(old_surface_id); | 482 factory_owner_->surface_factory_->Destroy(old_surface_id); |
483 } | 483 } |
484 | 484 |
485 if (old_surface_id != surface_id_) { | 485 if (old_surface_id != surface_id_) { |
486 float contents_surface_to_layer_scale = 1.0; | 486 float contents_surface_to_layer_scale = 1.0; |
| 487 // The bounds must be updated before switching to the new surface, because |
| 488 // the layer may be mirrored, in which case a surface change causes the |
| 489 // mirror layer to update its surface using the latest bounds. |
| 490 window_->layer()->SetBounds( |
| 491 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); |
487 window_->layer()->SetShowSurface( | 492 window_->layer()->SetShowSurface( |
488 surface_id_, | 493 surface_id_, |
489 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), | 494 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), |
490 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), | 495 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), |
491 content_size_, contents_surface_to_layer_scale, content_size_); | 496 content_size_, contents_surface_to_layer_scale, content_size_); |
492 window_->layer()->SetBounds( | |
493 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); | |
494 window_->layer()->SetFillsBoundsOpaquely( | 497 window_->layer()->SetFillsBoundsOpaquely( |
495 state_.blend_mode == SkXfermode::kSrc_Mode || | 498 state_.blend_mode == SkXfermode::kSrc_Mode || |
496 state_.opaque_region.contains( | 499 state_.opaque_region.contains( |
497 gfx::RectToSkIRect(gfx::Rect(content_size_)))); | 500 gfx::RectToSkIRect(gfx::Rect(content_size_)))); |
498 } | 501 } |
499 | 502 |
500 // Reset damage. | 503 // Reset damage. |
501 pending_damage_.setEmpty(); | 504 pending_damage_.setEmpty(); |
502 | 505 |
503 DCHECK(!current_resource_.id || | 506 DCHECK(!current_resource_.id || |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 std::unique_ptr<base::trace_event::TracedValue> value( | 606 std::unique_ptr<base::trace_event::TracedValue> value( |
604 new base::trace_event::TracedValue()); | 607 new base::trace_event::TracedValue()); |
605 value->SetString("name", window_->layer()->name()); | 608 value->SetString("name", window_->layer()->name()); |
606 return value; | 609 return value; |
607 } | 610 } |
608 | 611 |
609 //////////////////////////////////////////////////////////////////////////////// | 612 //////////////////////////////////////////////////////////////////////////////// |
610 // ui::LayerOwnerDelegate overrides: | 613 // ui::LayerOwnerDelegate overrides: |
611 | 614 |
612 void Surface::OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) { | 615 void Surface::OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) { |
613 if (!current_buffer_.buffer()) | 616 SetSurfaceLayerContents(new_layer); |
614 return; | 617 } |
615 | 618 |
616 // TODO(reveman): Give the client a chance to provide new contents. | 619 void Surface::OnLayerMirrored(ui::Layer* mirror) { |
617 SetSurfaceLayerContents(new_layer); | 620 SetSurfaceLayerContents(mirror); |
618 } | 621 } |
619 | 622 |
620 void Surface::WillDraw(const cc::SurfaceId& id) { | 623 void Surface::WillDraw(const cc::SurfaceId& id) { |
621 while (!active_frame_callbacks_.empty()) { | 624 while (!active_frame_callbacks_.empty()) { |
622 active_frame_callbacks_.front().Run(base::TimeTicks::Now()); | 625 active_frame_callbacks_.front().Run(base::TimeTicks::Now()); |
623 active_frame_callbacks_.pop_front(); | 626 active_frame_callbacks_.pop_front(); |
624 } | 627 } |
625 } | 628 } |
626 | 629 |
627 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { | 630 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 } | 688 } |
686 | 689 |
687 void Surface::SetSurfaceHierarchyNeedsCommitToNewSurfaces() { | 690 void Surface::SetSurfaceHierarchyNeedsCommitToNewSurfaces() { |
688 needs_commit_to_new_surface_ = true; | 691 needs_commit_to_new_surface_ = true; |
689 for (auto& sub_surface_entry : pending_sub_surfaces_) { | 692 for (auto& sub_surface_entry : pending_sub_surfaces_) { |
690 sub_surface_entry.first->SetSurfaceHierarchyNeedsCommitToNewSurfaces(); | 693 sub_surface_entry.first->SetSurfaceHierarchyNeedsCommitToNewSurfaces(); |
691 } | 694 } |
692 } | 695 } |
693 | 696 |
694 void Surface::SetSurfaceLayerContents(ui::Layer* layer) { | 697 void Surface::SetSurfaceLayerContents(ui::Layer* layer) { |
695 if (surface_id_.is_null()) | 698 if (!current_buffer_.buffer() || surface_id_.is_null()) |
696 return; | 699 return; |
697 | 700 |
698 gfx::Size layer_size = layer->bounds().size(); | 701 gfx::Size layer_size = layer->bounds().size(); |
699 float contents_surface_to_layer_scale = 1.0f; | 702 float contents_surface_to_layer_scale = 1.0f; |
700 | 703 |
| 704 // TODO(reveman): Give the client a chance to provide new contents. |
701 layer->SetShowSurface( | 705 layer->SetShowSurface( |
702 surface_id_, | 706 surface_id_, |
703 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), | 707 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), |
704 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), | 708 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), |
705 layer_size, contents_surface_to_layer_scale, layer_size); | 709 layer_size, contents_surface_to_layer_scale, layer_size); |
706 } | 710 } |
707 | 711 |
708 void Surface::UpdateResource(bool client_usage) { | 712 void Surface::UpdateResource(bool client_usage) { |
709 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; | 713 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; |
710 | 714 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 | 850 |
847 int64_t Surface::GetPropertyInternal(const void* key, | 851 int64_t Surface::GetPropertyInternal(const void* key, |
848 int64_t default_value) const { | 852 int64_t default_value) const { |
849 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); | 853 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); |
850 if (iter == prop_map_.end()) | 854 if (iter == prop_map_.end()) |
851 return default_value; | 855 return default_value; |
852 return iter->second.value; | 856 return iter->second.value; |
853 } | 857 } |
854 | 858 |
855 } // namespace exo | 859 } // namespace exo |
OLD | NEW |