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