| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 auto it = release_callbacks_.find(resource.id); | 176 auto it = release_callbacks_.find(resource.id); |
| 177 DCHECK(it != release_callbacks_.end()); | 177 DCHECK(it != release_callbacks_.end()); |
| 178 it->second.second->Run(resource.sync_token, resource.lost); | 178 it->second.second->Run(resource.sync_token, resource.lost); |
| 179 release_callbacks_.erase(it); | 179 release_callbacks_.erase(it); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 void SurfaceFactoryOwner::WillDrawSurface(const cc::LocalFrameId& id, | 183 void SurfaceFactoryOwner::WillDrawSurface(const cc::LocalFrameId& id, |
| 184 const gfx::Rect& damage_rect) { | 184 const gfx::Rect& damage_rect) { |
| 185 if (surface_) | 185 if (surface_) |
| 186 surface_->WillDraw(id); | 186 surface_->WillDraw(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void SurfaceFactoryOwner::SetBeginFrameSource( | 189 void SurfaceFactoryOwner::SetBeginFrameSource( |
| 190 cc::BeginFrameSource* begin_frame_source) {} | 190 cc::BeginFrameSource* begin_frame_source) { |
| 191 if (surface_) |
| 192 surface_->SetBeginFrameSource(begin_frame_source); |
| 193 } |
| 191 | 194 |
| 192 //////////////////////////////////////////////////////////////////////////////// | 195 //////////////////////////////////////////////////////////////////////////////// |
| 193 // SurfaceFactoryOwner, private: | 196 // SurfaceFactoryOwner, private: |
| 194 | 197 |
| 195 SurfaceFactoryOwner::~SurfaceFactoryOwner() { | 198 SurfaceFactoryOwner::~SurfaceFactoryOwner() { |
| 196 if (surface_factory_->manager()) { | 199 if (surface_factory_->manager()) |
| 197 surface_factory_->manager()->InvalidateFrameSinkId(frame_sink_id_); | 200 surface_factory_->manager()->InvalidateFrameSinkId(frame_sink_id_); |
| 198 } | |
| 199 } | 201 } |
| 200 | 202 |
| 201 //////////////////////////////////////////////////////////////////////////////// | 203 //////////////////////////////////////////////////////////////////////////////// |
| 202 // Surface, public: | 204 // Surface, public: |
| 203 | 205 |
| 204 Surface::Surface() | 206 Surface::Surface() |
| 205 : window_(new aura::Window(new CustomWindowDelegate(this))), | 207 : window_(new aura::Window(new CustomWindowDelegate(this))), |
| 206 surface_manager_( | 208 surface_manager_( |
| 207 aura::Env::GetInstance()->context_factory()->GetSurfaceManager()), | 209 aura::Env::GetInstance()->context_factory()->GetSurfaceManager()), |
| 208 factory_owner_(new SurfaceFactoryOwner) { | 210 factory_owner_(new SurfaceFactoryOwner) { |
| 209 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | 211 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
| 210 window_->SetName("ExoSurface"); | 212 window_->SetName("ExoSurface"); |
| 211 window_->SetProperty(kSurfaceKey, this); | 213 window_->SetProperty(kSurfaceKey, this); |
| 212 window_->Init(ui::LAYER_SOLID_COLOR); | 214 window_->Init(ui::LAYER_SOLID_COLOR); |
| 213 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); | 215 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); |
| 214 window_->set_owned_by_parent(false); | 216 window_->set_owned_by_parent(false); |
| 217 window_->AddObserver(this); |
| 215 factory_owner_->surface_ = this; | 218 factory_owner_->surface_ = this; |
| 216 factory_owner_->frame_sink_id_ = | 219 factory_owner_->frame_sink_id_ = |
| 217 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId(); | 220 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId(); |
| 218 factory_owner_->id_allocator_.reset(new cc::SurfaceIdAllocator()); | 221 factory_owner_->id_allocator_.reset(new cc::SurfaceIdAllocator()); |
| 219 surface_manager_->RegisterFrameSinkId(factory_owner_->frame_sink_id_); | 222 surface_manager_->RegisterFrameSinkId(factory_owner_->frame_sink_id_); |
| 223 surface_manager_->RegisterSurfaceFactoryClient(factory_owner_->frame_sink_id_, |
| 224 factory_owner_.get()); |
| 220 factory_owner_->surface_factory_.reset(new cc::SurfaceFactory( | 225 factory_owner_->surface_factory_.reset(new cc::SurfaceFactory( |
| 221 factory_owner_->frame_sink_id_, surface_manager_, factory_owner_.get())); | 226 factory_owner_->frame_sink_id_, surface_manager_, factory_owner_.get())); |
| 222 aura::Env::GetInstance()->context_factory()->AddObserver(this); | 227 aura::Env::GetInstance()->context_factory()->AddObserver(this); |
| 223 } | 228 } |
| 224 | 229 |
| 225 Surface::~Surface() { | 230 Surface::~Surface() { |
| 226 aura::Env::GetInstance()->context_factory()->RemoveObserver(this); | 231 aura::Env::GetInstance()->context_factory()->RemoveObserver(this); |
| 227 for (SurfaceObserver& observer : observers_) | 232 for (SurfaceObserver& observer : observers_) |
| 228 observer.OnSurfaceDestroying(this); | 233 observer.OnSurfaceDestroying(this); |
| 229 | 234 |
| 235 window_->RemoveObserver(this); |
| 230 window_->layer()->SetShowSolidColorContent(); | 236 window_->layer()->SetShowSolidColorContent(); |
| 231 | 237 |
| 232 factory_owner_->surface_ = nullptr; | 238 factory_owner_->surface_ = nullptr; |
| 233 | 239 |
| 234 // Call pending frame callbacks with a null frame time to indicate that they | 240 // Call pending frame callbacks with a null frame time to indicate that they |
| 235 // have been cancelled. | 241 // have been cancelled. |
| 236 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); | 242 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); |
| 237 active_frame_callbacks_.splice(active_frame_callbacks_.end(), | 243 active_frame_callbacks_.splice(active_frame_callbacks_.end(), |
| 238 frame_callbacks_); | 244 frame_callbacks_); |
| 239 for (const auto& frame_callback : active_frame_callbacks_) | 245 for (const auto& frame_callback : active_frame_callbacks_) |
| 240 frame_callback.Run(base::TimeTicks()); | 246 frame_callback.Run(base::TimeTicks()); |
| 241 | 247 |
| 248 if (begin_frame_source_) |
| 249 begin_frame_source_->RemoveObserver(this); |
| 250 |
| 242 if (!local_frame_id_.is_null()) | 251 if (!local_frame_id_.is_null()) |
| 243 factory_owner_->surface_factory_->Destroy(local_frame_id_); | 252 factory_owner_->surface_factory_->Destroy(local_frame_id_); |
| 253 |
| 254 surface_manager_->UnregisterSurfaceFactoryClient( |
| 255 factory_owner_->frame_sink_id_); |
| 244 } | 256 } |
| 245 | 257 |
| 246 // static | 258 // static |
| 247 Surface* Surface::AsSurface(const aura::Window* window) { | 259 Surface* Surface::AsSurface(const aura::Window* window) { |
| 248 return window->GetProperty(kSurfaceKey); | 260 return window->GetProperty(kSurfaceKey); |
| 249 } | 261 } |
| 250 | 262 |
| 251 cc::SurfaceId Surface::GetSurfaceId() const { | 263 cc::SurfaceId Surface::GetSurfaceId() const { |
| 252 return cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_); | 264 return cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_); |
| 253 } | 265 } |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 } | 450 } |
| 439 | 451 |
| 440 if (delegate_) { | 452 if (delegate_) { |
| 441 delegate_->OnSurfaceCommit(); | 453 delegate_->OnSurfaceCommit(); |
| 442 } else { | 454 } else { |
| 443 CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); | 455 CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 444 CommitSurfaceHierarchy(); | 456 CommitSurfaceHierarchy(); |
| 445 } | 457 } |
| 446 } | 458 } |
| 447 | 459 |
| 448 void Surface::OnLostResources() { | |
| 449 if (local_frame_id_.is_null()) | |
| 450 return; | |
| 451 | |
| 452 UpdateResource(false); | |
| 453 UpdateSurface(false); | |
| 454 } | |
| 455 | |
| 456 void Surface::CommitSurfaceHierarchy() { | 460 void Surface::CommitSurfaceHierarchy() { |
| 457 DCHECK(needs_commit_surface_hierarchy_); | 461 DCHECK(needs_commit_surface_hierarchy_); |
| 458 needs_commit_surface_hierarchy_ = false; | 462 needs_commit_surface_hierarchy_ = false; |
| 459 has_pending_layer_changes_ = false; | 463 has_pending_layer_changes_ = false; |
| 460 | 464 |
| 461 state_ = pending_state_; | 465 state_ = pending_state_; |
| 462 pending_state_.only_visible_on_secure_output = false; | 466 pending_state_.only_visible_on_secure_output = false; |
| 463 | 467 |
| 464 // We update contents if Attach() has been called since last commit. | 468 // We update contents if Attach() has been called since last commit. |
| 465 if (has_pending_contents_) { | 469 if (has_pending_contents_) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 state_.opaque_region.contains( | 506 state_.opaque_region.contains( |
| 503 gfx::RectToSkIRect(gfx::Rect(content_size_)))); | 507 gfx::RectToSkIRect(gfx::Rect(content_size_)))); |
| 504 } | 508 } |
| 505 | 509 |
| 506 // Reset damage. | 510 // Reset damage. |
| 507 pending_damage_.setEmpty(); | 511 pending_damage_.setEmpty(); |
| 508 | 512 |
| 509 DCHECK(!current_resource_.id || | 513 DCHECK(!current_resource_.id || |
| 510 factory_owner_->release_callbacks_.count(current_resource_.id)); | 514 factory_owner_->release_callbacks_.count(current_resource_.id)); |
| 511 | 515 |
| 512 // Move pending frame callbacks to the end of active_frame_callbacks_ | 516 // Move pending frame callbacks to the end of frame_callbacks_. |
| 513 active_frame_callbacks_.splice(active_frame_callbacks_.end(), | 517 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); |
| 514 pending_frame_callbacks_); | |
| 515 | 518 |
| 516 // Synchronize window hierarchy. This will position and update the stacking | 519 // Synchronize window hierarchy. This will position and update the stacking |
| 517 // order of all sub-surfaces after committing all pending state of sub-surface | 520 // order of all sub-surfaces after committing all pending state of sub-surface |
| 518 // descendants. | 521 // descendants. |
| 519 aura::Window* stacking_target = nullptr; | 522 aura::Window* stacking_target = nullptr; |
| 520 for (auto& sub_surface_entry : pending_sub_surfaces_) { | 523 for (auto& sub_surface_entry : pending_sub_surfaces_) { |
| 521 Surface* sub_surface = sub_surface_entry.first; | 524 Surface* sub_surface = sub_surface_entry.first; |
| 522 | 525 |
| 523 // Synchronsouly commit all pending state of the sub-surface and its | 526 // Synchronsouly commit all pending state of the sub-surface and its |
| 524 // decendents. | 527 // decendents. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 return observers_.HasObserver(observer); | 608 return observers_.HasObserver(observer); |
| 606 } | 609 } |
| 607 | 610 |
| 608 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const { | 611 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const { |
| 609 std::unique_ptr<base::trace_event::TracedValue> value( | 612 std::unique_ptr<base::trace_event::TracedValue> value( |
| 610 new base::trace_event::TracedValue()); | 613 new base::trace_event::TracedValue()); |
| 611 value->SetString("name", window_->layer()->name()); | 614 value->SetString("name", window_->layer()->name()); |
| 612 return value; | 615 return value; |
| 613 } | 616 } |
| 614 | 617 |
| 615 void Surface::WillDraw(const cc::LocalFrameId& id) { | 618 void Surface::WillDraw() { |
| 616 while (!active_frame_callbacks_.empty()) { | 619 active_frame_callbacks_.splice(active_frame_callbacks_.end(), |
| 617 active_frame_callbacks_.front().Run(base::TimeTicks::Now()); | 620 frame_callbacks_); |
| 618 active_frame_callbacks_.pop_front(); | 621 UpdateNeedsBeginFrame(); |
| 619 } | 622 } |
| 623 |
| 624 void Surface::SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) { |
| 625 begin_frame_source_ = begin_frame_source; |
| 626 UpdateNeedsBeginFrame(); |
| 620 } | 627 } |
| 621 | 628 |
| 622 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { | 629 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { |
| 623 if (HasLayerHierarchyChanged()) | 630 if (HasLayerHierarchyChanged()) |
| 624 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); | 631 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 625 } | 632 } |
| 626 | 633 |
| 634 void Surface::OnLostResources() { |
| 635 if (local_frame_id_.is_null()) |
| 636 return; |
| 637 |
| 638 UpdateResource(false); |
| 639 UpdateSurface(false); |
| 640 } |
| 641 |
| 642 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { |
| 643 window->layer()->GetCompositor()->AddFrameSink( |
| 644 factory_owner_->frame_sink_id_); |
| 645 } |
| 646 |
| 647 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, |
| 648 aura::Window* new_root) { |
| 649 window->layer()->GetCompositor()->RemoveFrameSink( |
| 650 factory_owner_->frame_sink_id_); |
| 651 } |
| 652 |
| 653 void Surface::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| 654 while (!active_frame_callbacks_.empty()) { |
| 655 active_frame_callbacks_.front().Run(args.frame_time); |
| 656 active_frame_callbacks_.pop_front(); |
| 657 } |
| 658 last_begin_frame_args_ = args; |
| 659 } |
| 660 |
| 661 const cc::BeginFrameArgs& Surface::LastUsedBeginFrameArgs() const { |
| 662 return last_begin_frame_args_; |
| 663 } |
| 664 |
| 627 Surface::State::State() : input_region(SkIRect::MakeLargest()) {} | 665 Surface::State::State() : input_region(SkIRect::MakeLargest()) {} |
| 628 | 666 |
| 629 Surface::State::~State() = default; | 667 Surface::State::~State() = default; |
| 630 | 668 |
| 631 bool Surface::State::operator==(const State& other) { | 669 bool Surface::State::operator==(const State& other) { |
| 632 return (other.crop == crop && alpha == other.alpha && | 670 return (other.crop == crop && alpha == other.alpha && |
| 633 other.blend_mode == blend_mode && other.viewport == viewport && | 671 other.blend_mode == blend_mode && other.viewport == viewport && |
| 634 other.opaque_region == opaque_region && | 672 other.opaque_region == opaque_region && |
| 635 other.buffer_scale == buffer_scale && | 673 other.buffer_scale == buffer_scale && |
| 636 other.input_region == input_region); | 674 other.input_region == input_region); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); | 835 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); |
| 798 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false); | 836 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false); |
| 799 } | 837 } |
| 800 | 838 |
| 801 frame.render_pass_list.push_back(std::move(render_pass)); | 839 frame.render_pass_list.push_back(std::move(render_pass)); |
| 802 | 840 |
| 803 factory_owner_->surface_factory_->SubmitCompositorFrame( | 841 factory_owner_->surface_factory_->SubmitCompositorFrame( |
| 804 local_frame_id_, std::move(frame), cc::SurfaceFactory::DrawCallback()); | 842 local_frame_id_, std::move(frame), cc::SurfaceFactory::DrawCallback()); |
| 805 } | 843 } |
| 806 | 844 |
| 845 void Surface::UpdateNeedsBeginFrame() { |
| 846 if (!begin_frame_source_) { |
| 847 needs_begin_frame_ = false; |
| 848 return; |
| 849 } |
| 850 |
| 851 bool needs_begin_frame = !active_frame_callbacks_.empty(); |
| 852 if (needs_begin_frame == needs_begin_frame_) |
| 853 return; |
| 854 |
| 855 needs_begin_frame_ = needs_begin_frame; |
| 856 if (needs_begin_frame) |
| 857 begin_frame_source_->AddObserver(this); |
| 858 else |
| 859 begin_frame_source_->RemoveObserver(this); |
| 860 } |
| 861 |
| 807 int64_t Surface::SetPropertyInternal(const void* key, | 862 int64_t Surface::SetPropertyInternal(const void* key, |
| 808 const char* name, | 863 const char* name, |
| 809 PropertyDeallocator deallocator, | 864 PropertyDeallocator deallocator, |
| 810 int64_t value, | 865 int64_t value, |
| 811 int64_t default_value) { | 866 int64_t default_value) { |
| 812 int64_t old = GetPropertyInternal(key, default_value); | 867 int64_t old = GetPropertyInternal(key, default_value); |
| 813 if (value == default_value) { | 868 if (value == default_value) { |
| 814 prop_map_.erase(key); | 869 prop_map_.erase(key); |
| 815 } else { | 870 } else { |
| 816 Value prop_value; | 871 Value prop_value; |
| 817 prop_value.name = name; | 872 prop_value.name = name; |
| 818 prop_value.value = value; | 873 prop_value.value = value; |
| 819 prop_value.deallocator = deallocator; | 874 prop_value.deallocator = deallocator; |
| 820 prop_map_[key] = prop_value; | 875 prop_map_[key] = prop_value; |
| 821 } | 876 } |
| 822 return old; | 877 return old; |
| 823 } | 878 } |
| 824 | 879 |
| 825 int64_t Surface::GetPropertyInternal(const void* key, | 880 int64_t Surface::GetPropertyInternal(const void* key, |
| 826 int64_t default_value) const { | 881 int64_t default_value) const { |
| 827 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); | 882 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); |
| 828 if (iter == prop_map_.end()) | 883 if (iter == prop_map_.end()) |
| 829 return default_value; | 884 return default_value; |
| 830 return iter->second.value; | 885 return iter->second.value; |
| 831 } | 886 } |
| 832 | 887 |
| 833 } // namespace exo | 888 } // namespace exo |
| OLD | NEW |