| 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 203 |
| 204 Surface::Surface() | 204 Surface::Surface() |
| 205 : window_(new aura::Window(new CustomWindowDelegate(this))), | 205 : window_(new aura::Window(new CustomWindowDelegate(this))), |
| 206 surface_manager_( | 206 surface_manager_( |
| 207 aura::Env::GetInstance()->context_factory()->GetSurfaceManager()), | 207 aura::Env::GetInstance()->context_factory()->GetSurfaceManager()), |
| 208 factory_owner_(new SurfaceFactoryOwner) { | 208 factory_owner_(new SurfaceFactoryOwner) { |
| 209 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | 209 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
| 210 window_->SetName("ExoSurface"); | 210 window_->SetName("ExoSurface"); |
| 211 window_->SetProperty(kSurfaceKey, this); | 211 window_->SetProperty(kSurfaceKey, this); |
| 212 window_->Init(ui::LAYER_SOLID_COLOR); | 212 window_->Init(ui::LAYER_SOLID_COLOR); |
| 213 window_->set_layer_owner_delegate(this); | |
| 214 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); | 213 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); |
| 215 window_->set_owned_by_parent(false); | 214 window_->set_owned_by_parent(false); |
| 216 factory_owner_->surface_ = this; | 215 factory_owner_->surface_ = this; |
| 217 factory_owner_->frame_sink_id_ = | 216 factory_owner_->frame_sink_id_ = |
| 218 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId(); | 217 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId(); |
| 219 factory_owner_->id_allocator_.reset(new cc::SurfaceIdAllocator()); | 218 factory_owner_->id_allocator_.reset(new cc::SurfaceIdAllocator()); |
| 220 surface_manager_->RegisterFrameSinkId(factory_owner_->frame_sink_id_); | 219 surface_manager_->RegisterFrameSinkId(factory_owner_->frame_sink_id_); |
| 221 factory_owner_->surface_factory_.reset(new cc::SurfaceFactory( | 220 factory_owner_->surface_factory_.reset(new cc::SurfaceFactory( |
| 222 factory_owner_->frame_sink_id_, surface_manager_, factory_owner_.get())); | 221 factory_owner_->frame_sink_id_, surface_manager_, factory_owner_.get())); |
| 223 aura::Env::GetInstance()->context_factory()->AddObserver(this); | 222 aura::Env::GetInstance()->context_factory()->AddObserver(this); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 UpdateSurface(true); | 479 UpdateSurface(true); |
| 481 | 480 |
| 482 if (!old_local_frame_id.is_null() && old_local_frame_id != local_frame_id_) { | 481 if (!old_local_frame_id.is_null() && old_local_frame_id != local_frame_id_) { |
| 483 factory_owner_->surface_factory_->SetPreviousFrameSurface( | 482 factory_owner_->surface_factory_->SetPreviousFrameSurface( |
| 484 local_frame_id_, old_local_frame_id); | 483 local_frame_id_, old_local_frame_id); |
| 485 factory_owner_->surface_factory_->Destroy(old_local_frame_id); | 484 factory_owner_->surface_factory_->Destroy(old_local_frame_id); |
| 486 } | 485 } |
| 487 | 486 |
| 488 if (old_local_frame_id != local_frame_id_) { | 487 if (old_local_frame_id != local_frame_id_) { |
| 489 float contents_surface_to_layer_scale = 1.0; | 488 float contents_surface_to_layer_scale = 1.0; |
| 489 // The bounds must be updated before switching to the new surface, because |
| 490 // the layer may be mirrored, in which case a surface change causes the |
| 491 // mirror layer to update its surface using the latest bounds. |
| 492 window_->layer()->SetBounds( |
| 493 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); |
| 490 window_->layer()->SetShowSurface( | 494 window_->layer()->SetShowSurface( |
| 491 cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_), | 495 cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_), |
| 492 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), | 496 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), |
| 493 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), | 497 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), |
| 494 content_size_, contents_surface_to_layer_scale, content_size_); | 498 content_size_, contents_surface_to_layer_scale, content_size_); |
| 495 window_->layer()->SetBounds( | |
| 496 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); | |
| 497 window_->layer()->SetFillsBoundsOpaquely( | 499 window_->layer()->SetFillsBoundsOpaquely( |
| 498 state_.blend_mode == SkXfermode::kSrc_Mode || | 500 state_.blend_mode == SkXfermode::kSrc_Mode || |
| 499 state_.opaque_region.contains( | 501 state_.opaque_region.contains( |
| 500 gfx::RectToSkIRect(gfx::Rect(content_size_)))); | 502 gfx::RectToSkIRect(gfx::Rect(content_size_)))); |
| 501 } | 503 } |
| 502 | 504 |
| 503 // Reset damage. | 505 // Reset damage. |
| 504 pending_damage_.setEmpty(); | 506 pending_damage_.setEmpty(); |
| 505 | 507 |
| 506 DCHECK(!current_resource_.id || | 508 DCHECK(!current_resource_.id || |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 return observers_.HasObserver(observer); | 604 return observers_.HasObserver(observer); |
| 603 } | 605 } |
| 604 | 606 |
| 605 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const { | 607 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const { |
| 606 std::unique_ptr<base::trace_event::TracedValue> value( | 608 std::unique_ptr<base::trace_event::TracedValue> value( |
| 607 new base::trace_event::TracedValue()); | 609 new base::trace_event::TracedValue()); |
| 608 value->SetString("name", window_->layer()->name()); | 610 value->SetString("name", window_->layer()->name()); |
| 609 return value; | 611 return value; |
| 610 } | 612 } |
| 611 | 613 |
| 612 //////////////////////////////////////////////////////////////////////////////// | |
| 613 // ui::LayerOwnerDelegate overrides: | |
| 614 | |
| 615 void Surface::OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) { | |
| 616 if (!current_buffer_.buffer()) | |
| 617 return; | |
| 618 | |
| 619 // TODO(reveman): Give the client a chance to provide new contents. | |
| 620 SetSurfaceLayerContents(new_layer); | |
| 621 } | |
| 622 | |
| 623 void Surface::WillDraw(const cc::LocalFrameId& id) { | 614 void Surface::WillDraw(const cc::LocalFrameId& id) { |
| 624 while (!active_frame_callbacks_.empty()) { | 615 while (!active_frame_callbacks_.empty()) { |
| 625 active_frame_callbacks_.front().Run(base::TimeTicks::Now()); | 616 active_frame_callbacks_.front().Run(base::TimeTicks::Now()); |
| 626 active_frame_callbacks_.pop_front(); | 617 active_frame_callbacks_.pop_front(); |
| 627 } | 618 } |
| 628 } | 619 } |
| 629 | 620 |
| 630 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { | 621 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { |
| 631 if (HasLayerHierarchyChanged()) | 622 if (HasLayerHierarchyChanged()) |
| 632 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); | 623 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 return false; | 678 return false; |
| 688 } | 679 } |
| 689 | 680 |
| 690 void Surface::SetSurfaceHierarchyNeedsCommitToNewSurfaces() { | 681 void Surface::SetSurfaceHierarchyNeedsCommitToNewSurfaces() { |
| 691 needs_commit_to_new_surface_ = true; | 682 needs_commit_to_new_surface_ = true; |
| 692 for (auto& sub_surface_entry : pending_sub_surfaces_) { | 683 for (auto& sub_surface_entry : pending_sub_surfaces_) { |
| 693 sub_surface_entry.first->SetSurfaceHierarchyNeedsCommitToNewSurfaces(); | 684 sub_surface_entry.first->SetSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 694 } | 685 } |
| 695 } | 686 } |
| 696 | 687 |
| 697 void Surface::SetSurfaceLayerContents(ui::Layer* layer) { | |
| 698 if (local_frame_id_.is_null()) | |
| 699 return; | |
| 700 | |
| 701 gfx::Size layer_size = layer->bounds().size(); | |
| 702 float contents_surface_to_layer_scale = 1.0f; | |
| 703 | |
| 704 layer->SetShowSurface( | |
| 705 cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_), | |
| 706 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), | |
| 707 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), | |
| 708 layer_size, contents_surface_to_layer_scale, layer_size); | |
| 709 } | |
| 710 | |
| 711 void Surface::UpdateResource(bool client_usage) { | 688 void Surface::UpdateResource(bool client_usage) { |
| 712 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; | 689 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; |
| 713 | 690 |
| 714 cc::TextureMailbox texture_mailbox; | 691 cc::TextureMailbox texture_mailbox; |
| 715 if (current_buffer_.buffer()) { | 692 if (current_buffer_.buffer()) { |
| 716 texture_mailbox_release_callback = | 693 texture_mailbox_release_callback = |
| 717 current_buffer_.buffer()->ProduceTextureMailbox( | 694 current_buffer_.buffer()->ProduceTextureMailbox( |
| 718 &texture_mailbox, state_.only_visible_on_secure_output, | 695 &texture_mailbox, state_.only_visible_on_secure_output, |
| 719 client_usage); | 696 client_usage); |
| 720 } | 697 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 | 826 |
| 850 int64_t Surface::GetPropertyInternal(const void* key, | 827 int64_t Surface::GetPropertyInternal(const void* key, |
| 851 int64_t default_value) const { | 828 int64_t default_value) const { |
| 852 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); | 829 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); |
| 853 if (iter == prop_map_.end()) | 830 if (iter == prop_map_.end()) |
| 854 return default_value; | 831 return default_value; |
| 855 return iter->second.value; | 832 return iter->second.value; |
| 856 } | 833 } |
| 857 | 834 |
| 858 } // namespace exo | 835 } // namespace exo |
| OLD | NEW |