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

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

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

Powered by Google App Engine
This is Rietveld 408576698