Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: components/exo/surface.cc

Issue 2493223002: Change exo::SurfaceFactoryOwner to exo::ExoCompositorFrameSink (Closed)
Patch Set: Undid a change on an if condition in exo::Surface::CommitSurfaceHierarchy() Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (!surface) { 155 if (!surface) {
156 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; 156 LOG(ERROR) << "Attempting to require callback on nonexistent surface";
157 return; 157 return;
158 } 158 }
159 surface->AddDestructionDependency(sequence); 159 surface->AddDestructionDependency(sequence);
160 } 160 }
161 161
162 } // namespace 162 } // namespace
163 163
164 //////////////////////////////////////////////////////////////////////////////// 164 ////////////////////////////////////////////////////////////////////////////////
165 // SurfaceFactoryOwner, public:
166
167 SurfaceFactoryOwner::SurfaceFactoryOwner() {}
168
169 ////////////////////////////////////////////////////////////////////////////////
170 // cc::SurfaceFactoryClient overrides:
171
172 void SurfaceFactoryOwner::ReturnResources(
173 const cc::ReturnedResourceArray& resources) {
174 scoped_refptr<SurfaceFactoryOwner> holder(this);
175 for (auto& resource : resources) {
176 auto it = release_callbacks_.find(resource.id);
177 DCHECK(it != release_callbacks_.end());
178 it->second.second->Run(resource.sync_token, resource.lost);
179 release_callbacks_.erase(it);
180 }
181 }
182
183 void SurfaceFactoryOwner::WillDrawSurface(const cc::LocalFrameId& id,
184 const gfx::Rect& damage_rect) {
185 if (surface_)
186 surface_->WillDraw();
187 }
188
189 void SurfaceFactoryOwner::SetBeginFrameSource(
190 cc::BeginFrameSource* begin_frame_source) {
191 if (surface_)
192 surface_->SetBeginFrameSource(begin_frame_source);
193 }
194
195 ////////////////////////////////////////////////////////////////////////////////
196 // SurfaceFactoryOwner, private:
197
198 SurfaceFactoryOwner::~SurfaceFactoryOwner() {
199 if (surface_factory_->manager())
200 surface_factory_->manager()->InvalidateFrameSinkId(frame_sink_id_);
201 }
202
203 ////////////////////////////////////////////////////////////////////////////////
204 // Surface, public: 165 // Surface, public:
205 166
206 Surface::Surface() 167 Surface::Surface()
207 : window_(new aura::Window(new CustomWindowDelegate(this))), 168 : window_(new aura::Window(new CustomWindowDelegate(this))),
169 frame_sink_id_(
170 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId()),
208 surface_manager_( 171 surface_manager_(
209 aura::Env::GetInstance()->context_factory()->GetSurfaceManager()), 172 aura::Env::GetInstance()->context_factory()->GetSurfaceManager()),
210 factory_owner_(new SurfaceFactoryOwner) { 173 weak_ptr_factory_(this) {
174 cc::mojom::MojoCompositorFrameSinkClientPtr pholder;
175 cc::mojom::MojoCompositorFrameSinkClientRequest request =
176 mojo::GetProxy(&pholder);
177 std::unique_ptr<ExoCompositorFrameSink> compositor_frame_sink(
178 new ExoCompositorFrameSink(frame_sink_id_, surface_manager_,
179 std::move(pholder)));
180 compositor_frame_sink_holder_ = new CompositorFrameSinkHolder(
181 std::move(compositor_frame_sink), weak_ptr_factory_.GetWeakPtr(),
182 std::move(request));
211 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); 183 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
212 window_->SetName("ExoSurface"); 184 window_->SetName("ExoSurface");
213 window_->SetProperty(kSurfaceKey, this); 185 window_->SetProperty(kSurfaceKey, this);
214 window_->Init(ui::LAYER_SOLID_COLOR); 186 window_->Init(ui::LAYER_SOLID_COLOR);
215 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); 187 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter));
216 window_->set_owned_by_parent(false); 188 window_->set_owned_by_parent(false);
217 window_->AddObserver(this); 189 window_->AddObserver(this);
218 factory_owner_->surface_ = this;
219 factory_owner_->frame_sink_id_ =
220 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId();
221 factory_owner_->id_allocator_.reset(new cc::SurfaceIdAllocator());
222 surface_manager_->RegisterFrameSinkId(factory_owner_->frame_sink_id_);
223 surface_manager_->RegisterSurfaceFactoryClient(factory_owner_->frame_sink_id_,
224 factory_owner_.get());
225 factory_owner_->surface_factory_.reset(new cc::SurfaceFactory(
226 factory_owner_->frame_sink_id_, surface_manager_, factory_owner_.get()));
227 aura::Env::GetInstance()->context_factory()->AddObserver(this); 190 aura::Env::GetInstance()->context_factory()->AddObserver(this);
228 } 191 }
229 192
230 Surface::~Surface() { 193 Surface::~Surface() {
231 aura::Env::GetInstance()->context_factory()->RemoveObserver(this); 194 aura::Env::GetInstance()->context_factory()->RemoveObserver(this);
232 for (SurfaceObserver& observer : observers_) 195 for (SurfaceObserver& observer : observers_)
233 observer.OnSurfaceDestroying(this); 196 observer.OnSurfaceDestroying(this);
234 197
235 window_->RemoveObserver(this); 198 window_->RemoveObserver(this);
236 window_->layer()->SetShowSolidColorContent(); 199 window_->layer()->SetShowSolidColorContent();
237 200
238 factory_owner_->surface_ = nullptr; 201 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
202 compositor_frame_sink_holder_->ActivateFrameCallbacks(frame_callbacks_);
Fady Samuel 2016/11/30 16:41:57 This is a weird API. I really don't understand wha
Alex Z. 2016/11/30 19:04:04 The comments in surface.h says these callbacks not
203 compositor_frame_sink_holder_->CancelFrameCallbacks();
239 204
240 // Call pending frame callbacks with a null frame time to indicate that they 205 compositor_frame_sink_holder_->EvictFrame();
241 // have been cancelled.
242 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
243 active_frame_callbacks_.splice(active_frame_callbacks_.end(),
244 frame_callbacks_);
245 for (const auto& frame_callback : active_frame_callbacks_)
246 frame_callback.Run(base::TimeTicks());
247 if (begin_frame_source_ && needs_begin_frame_)
248 begin_frame_source_->RemoveObserver(this);
249
250 factory_owner_->surface_factory_->EvictSurface();
251
252 surface_manager_->UnregisterSurfaceFactoryClient(
253 factory_owner_->frame_sink_id_);
254 } 206 }
255 207
256 // static 208 // static
257 Surface* Surface::AsSurface(const aura::Window* window) { 209 Surface* Surface::AsSurface(const aura::Window* window) {
258 return window->GetProperty(kSurfaceKey); 210 return window->GetProperty(kSurfaceKey);
259 } 211 }
260 212
261 cc::SurfaceId Surface::GetSurfaceId() const { 213 cc::SurfaceId Surface::GetSurfaceId() const {
262 return cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_); 214 return cc::SurfaceId(frame_sink_id_, local_frame_id_);
263 } 215 }
264 216
265 void Surface::Attach(Buffer* buffer) { 217 void Surface::Attach(Buffer* buffer) {
266 TRACE_EVENT1("exo", "Surface::Attach", "buffer", 218 TRACE_EVENT1("exo", "Surface::Attach", "buffer",
267 buffer ? buffer->GetSize().ToString() : "null"); 219 buffer ? buffer->GetSize().ToString() : "null");
268 220
269 has_pending_contents_ = true; 221 has_pending_contents_ = true;
270 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>()); 222 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>());
271 } 223 }
272 224
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 has_pending_contents_ = false; 421 has_pending_contents_ = false;
470 422
471 current_buffer_ = std::move(pending_buffer_); 423 current_buffer_ = std::move(pending_buffer_);
472 424
473 UpdateResource(true); 425 UpdateResource(true);
474 } 426 }
475 427
476 cc::LocalFrameId old_local_frame_id = local_frame_id_; 428 cc::LocalFrameId old_local_frame_id = local_frame_id_;
477 if (needs_commit_to_new_surface_ || !local_frame_id_.is_valid()) { 429 if (needs_commit_to_new_surface_ || !local_frame_id_.is_valid()) {
478 needs_commit_to_new_surface_ = false; 430 needs_commit_to_new_surface_ = false;
479 local_frame_id_ = factory_owner_->id_allocator_->GenerateId(); 431 local_frame_id_ = id_allocator_.GenerateId();
480 } 432 }
481 433
482 UpdateSurface(true); 434 UpdateSurface(true);
483 435
484 if (old_local_frame_id != local_frame_id_) { 436 if (old_local_frame_id != local_frame_id_) {
437 needs_commit_to_new_surface_ = false;
485 float contents_surface_to_layer_scale = 1.0; 438 float contents_surface_to_layer_scale = 1.0;
486 // The bounds must be updated before switching to the new surface, because 439 // The bounds must be updated before switching to the new surface, because
487 // the layer may be mirrored, in which case a surface change causes the 440 // the layer may be mirrored, in which case a surface change causes the
488 // mirror layer to update its surface using the latest bounds. 441 // mirror layer to update its surface using the latest bounds.
489 window_->layer()->SetBounds( 442 window_->layer()->SetBounds(
490 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); 443 gfx::Rect(window_->layer()->bounds().origin(), content_size_));
491 window_->layer()->SetShowSurface( 444 window_->layer()->SetShowSurface(
492 cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_), 445 cc::SurfaceId(frame_sink_id_, local_frame_id_),
493 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), 446 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)),
494 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), 447 base::Bind(&RequireCallback, base::Unretained(surface_manager_)),
495 content_size_, contents_surface_to_layer_scale, content_size_); 448 content_size_, contents_surface_to_layer_scale, content_size_);
496 window_->layer()->SetFillsBoundsOpaquely( 449 window_->layer()->SetFillsBoundsOpaquely(
497 state_.blend_mode == SkBlendMode::kSrc || 450 state_.blend_mode == SkBlendMode::kSrc ||
498 state_.opaque_region.contains( 451 state_.opaque_region.contains(
499 gfx::RectToSkIRect(gfx::Rect(content_size_)))); 452 gfx::RectToSkIRect(gfx::Rect(content_size_))));
500 } 453 }
501 454
502 // Reset damage. 455 // Reset damage.
503 pending_damage_.setEmpty(); 456 pending_damage_.setEmpty();
504 457
505 DCHECK(!current_resource_.id || 458 DCHECK(
506 factory_owner_->release_callbacks_.count(current_resource_.id)); 459 !current_resource_.id ||
460 compositor_frame_sink_holder_->HasReleaseCallbacks(current_resource_.id));
507 461
508 // Move pending frame callbacks to the end of frame_callbacks_. 462 // Move pending frame callbacks to the end of frame_callbacks_.
509 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); 463 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
510 464
511 // Synchronize window hierarchy. This will position and update the stacking 465 // Synchronize window hierarchy. This will position and update the stacking
512 // order of all sub-surfaces after committing all pending state of sub-surface 466 // order of all sub-surfaces after committing all pending state of sub-surface
513 // descendants. 467 // descendants.
514 aura::Window* stacking_target = nullptr; 468 aura::Window* stacking_target = nullptr;
515 for (auto& sub_surface_entry : pending_sub_surfaces_) { 469 for (auto& sub_surface_entry : pending_sub_surfaces_) {
516 Surface* sub_surface = sub_surface_entry.first; 470 Surface* sub_surface = sub_surface_entry.first;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 } 555 }
602 556
603 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const { 557 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const {
604 std::unique_ptr<base::trace_event::TracedValue> value( 558 std::unique_ptr<base::trace_event::TracedValue> value(
605 new base::trace_event::TracedValue()); 559 new base::trace_event::TracedValue());
606 value->SetString("name", window_->layer()->name()); 560 value->SetString("name", window_->layer()->name());
607 return value; 561 return value;
608 } 562 }
609 563
610 void Surface::WillDraw() { 564 void Surface::WillDraw() {
611 active_frame_callbacks_.splice(active_frame_callbacks_.end(), 565 compositor_frame_sink_holder_->ActivateFrameCallbacks(frame_callbacks_);
612 frame_callbacks_); 566 compositor_frame_sink_holder_->UpdateNeedsBeginFrame();
Fady Samuel 2016/11/30 16:41:57 I don't think you should expose this?
Alex Z. 2016/11/30 20:00:30 Done.
613 UpdateNeedsBeginFrame();
614 }
615
616 void Surface::SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) {
617 if (begin_frame_source_ && needs_begin_frame_) {
618 begin_frame_source_->RemoveObserver(this);
619 needs_begin_frame_ = false;
620 }
621 begin_frame_source_ = begin_frame_source;
622 UpdateNeedsBeginFrame();
623 } 567 }
624 568
625 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { 569 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() {
626 if (HasLayerHierarchyChanged()) 570 if (HasLayerHierarchyChanged())
627 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); 571 SetSurfaceHierarchyNeedsCommitToNewSurfaces();
628 } 572 }
629 573
630 void Surface::OnLostResources() { 574 void Surface::OnLostResources() {
631 if (!local_frame_id_.is_valid()) 575 if (!local_frame_id_.is_valid())
632 return; 576 return;
633 577
634 UpdateResource(false); 578 UpdateResource(false);
635 UpdateSurface(false); 579 UpdateSurface(false);
636 } 580 }
637 581
638 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { 582 void Surface::OnWindowAddedToRootWindow(aura::Window* window) {
639 window->layer()->GetCompositor()->AddFrameSink( 583 window->layer()->GetCompositor()->AddFrameSink(frame_sink_id_);
640 factory_owner_->frame_sink_id_);
641 } 584 }
642 585
643 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, 586 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window,
644 aura::Window* new_root) { 587 aura::Window* new_root) {
645 window->layer()->GetCompositor()->RemoveFrameSink( 588 window->layer()->GetCompositor()->RemoveFrameSink(frame_sink_id_);
646 factory_owner_->frame_sink_id_);
647 }
648
649 void Surface::OnBeginFrame(const cc::BeginFrameArgs& args) {
650 while (!active_frame_callbacks_.empty()) {
651 active_frame_callbacks_.front().Run(args.frame_time);
652 active_frame_callbacks_.pop_front();
653 }
654 last_begin_frame_args_ = args;
655 }
656
657 const cc::BeginFrameArgs& Surface::LastUsedBeginFrameArgs() const {
658 return last_begin_frame_args_;
659 } 589 }
660 590
661 Surface::State::State() : input_region(SkIRect::MakeLargest()) {} 591 Surface::State::State() : input_region(SkIRect::MakeLargest()) {}
662 592
663 Surface::State::~State() = default; 593 Surface::State::~State() = default;
664 594
665 bool Surface::State::operator==(const State& other) { 595 bool Surface::State::operator==(const State& other) {
666 return (other.crop == crop && alpha == other.alpha && 596 return (other.crop == crop && alpha == other.alpha &&
667 other.blend_mode == blend_mode && other.viewport == viewport && 597 other.blend_mode == blend_mode && other.viewport == viewport &&
668 other.opaque_region == opaque_region && 598 other.opaque_region == opaque_region &&
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 resource.id = next_resource_id_++; 666 resource.id = next_resource_id_++;
737 resource.format = cc::RGBA_8888; 667 resource.format = cc::RGBA_8888;
738 resource.filter = 668 resource.filter =
739 texture_mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR; 669 texture_mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR;
740 resource.size = texture_mailbox.size_in_pixels(); 670 resource.size = texture_mailbox.size_in_pixels();
741 resource.mailbox_holder = gpu::MailboxHolder(texture_mailbox.mailbox(), 671 resource.mailbox_holder = gpu::MailboxHolder(texture_mailbox.mailbox(),
742 texture_mailbox.sync_token(), 672 texture_mailbox.sync_token(),
743 texture_mailbox.target()); 673 texture_mailbox.target());
744 resource.is_overlay_candidate = texture_mailbox.is_overlay_candidate(); 674 resource.is_overlay_candidate = texture_mailbox.is_overlay_candidate();
745 675
746 factory_owner_->release_callbacks_[resource.id] = std::make_pair( 676 compositor_frame_sink_holder_->AddResourceReleaseCallback(
747 factory_owner_, std::move(texture_mailbox_release_callback)); 677 resource.id, std::move(texture_mailbox_release_callback));
748 current_resource_ = resource; 678 current_resource_ = resource;
749 } else { 679 } else {
750 current_resource_.id = 0; 680 current_resource_.id = 0;
751 current_resource_.size = gfx::Size(); 681 current_resource_.size = gfx::Size();
752 } 682 }
753 } 683 }
754 684
755 void Surface::UpdateSurface(bool full_damage) { 685 void Surface::UpdateSurface(bool full_damage) {
756 gfx::Size buffer_size = current_resource_.size; 686 gfx::Size buffer_size = current_resource_.size;
757 gfx::SizeF scaled_buffer_size( 687 gfx::SizeF scaled_buffer_size(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 texture_quad->set_resource_size_in_pixels(current_resource_.size); 756 texture_quad->set_resource_size_in_pixels(current_resource_.size);
827 frame.resource_list.push_back(current_resource_); 757 frame.resource_list.push_back(current_resource_);
828 } 758 }
829 } else { 759 } else {
830 cc::SolidColorDrawQuad* solid_quad = 760 cc::SolidColorDrawQuad* solid_quad =
831 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); 761 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>();
832 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false); 762 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false);
833 } 763 }
834 764
835 frame.render_pass_list.push_back(std::move(render_pass)); 765 frame.render_pass_list.push_back(std::move(render_pass));
836 766 compositor_frame_sink_holder_->SetNeedsBeginFrame(true);
Fady Samuel 2016/11/30 16:41:57 I don't think this line is necessary anymore?
Alex Z. 2016/11/30 20:00:30 Done.
837 factory_owner_->surface_factory_->SubmitCompositorFrame( 767 compositor_frame_sink_holder_->SubmitCompositorFrame(local_frame_id_,
838 local_frame_id_, std::move(frame), cc::SurfaceFactory::DrawCallback()); 768 std::move(frame));
839 }
840
841 void Surface::UpdateNeedsBeginFrame() {
842 if (!begin_frame_source_)
843 return;
844
845 bool needs_begin_frame = !active_frame_callbacks_.empty();
846 if (needs_begin_frame == needs_begin_frame_)
847 return;
848
849 needs_begin_frame_ = needs_begin_frame;
850 if (needs_begin_frame)
851 begin_frame_source_->AddObserver(this);
852 else
853 begin_frame_source_->RemoveObserver(this);
854 } 769 }
855 770
856 int64_t Surface::SetPropertyInternal(const void* key, 771 int64_t Surface::SetPropertyInternal(const void* key,
857 const char* name, 772 const char* name,
858 PropertyDeallocator deallocator, 773 PropertyDeallocator deallocator,
859 int64_t value, 774 int64_t value,
860 int64_t default_value) { 775 int64_t default_value) {
861 int64_t old = GetPropertyInternal(key, default_value); 776 int64_t old = GetPropertyInternal(key, default_value);
862 if (value == default_value) { 777 if (value == default_value) {
863 prop_map_.erase(key); 778 prop_map_.erase(key);
864 } else { 779 } else {
865 Value prop_value; 780 Value prop_value;
866 prop_value.name = name; 781 prop_value.name = name;
867 prop_value.value = value; 782 prop_value.value = value;
868 prop_value.deallocator = deallocator; 783 prop_value.deallocator = deallocator;
869 prop_map_[key] = prop_value; 784 prop_map_[key] = prop_value;
870 } 785 }
871 return old; 786 return old;
872 } 787 }
873 788
874 int64_t Surface::GetPropertyInternal(const void* key, 789 int64_t Surface::GetPropertyInternal(const void* key,
875 int64_t default_value) const { 790 int64_t default_value) const {
876 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); 791 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key);
877 if (iter == prop_map_.end()) 792 if (iter == prop_map_.end())
878 return default_value; 793 return default_value;
879 return iter->second.value; 794 return iter->second.value;
880 } 795 }
881 796
882 } // namespace exo 797 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698