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

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

Issue 2066493004: exo: Remove TextureLayer implementation of Surface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 void SurfaceFactoryOwner::SetBeginFrameSource( 183 void SurfaceFactoryOwner::SetBeginFrameSource(
184 cc::BeginFrameSource* begin_frame_source) {} 184 cc::BeginFrameSource* begin_frame_source) {}
185 185
186 //////////////////////////////////////////////////////////////////////////////// 186 ////////////////////////////////////////////////////////////////////////////////
187 // Surface, public: 187 // Surface, public:
188 188
189 Surface::Surface() 189 Surface::Surface()
190 : window_(new aura::Window(new CustomWindowDelegate(this))), 190 : window_(new aura::Window(new CustomWindowDelegate(this))),
191 has_pending_contents_(false), 191 has_pending_contents_(false),
192 needs_commit_surface_hierarchy_(false), 192 needs_commit_surface_hierarchy_(false),
193 update_contents_after_successful_compositing_(false),
194 compositor_(nullptr),
195 delegate_(nullptr) { 193 delegate_(nullptr) {
196 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); 194 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
197 window_->SetName("ExoSurface"); 195 window_->SetName("ExoSurface");
198 window_->SetProperty(kSurfaceKey, this); 196 window_->SetProperty(kSurfaceKey, this);
199 window_->Init(ui::LAYER_SOLID_COLOR); 197 window_->Init(ui::LAYER_SOLID_COLOR);
200 window_->set_layer_owner_delegate(this); 198 window_->set_layer_owner_delegate(this);
201 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); 199 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter));
202 window_->set_owned_by_parent(false); 200 window_->set_owned_by_parent(false);
203 surface_manager_ = 201 surface_manager_ =
204 aura::Env::GetInstance()->context_factory()->GetSurfaceManager(); 202 aura::Env::GetInstance()->context_factory()->GetSurfaceManager();
205 if (use_surface_layer_) { 203 factory_owner_ = make_scoped_refptr(new SurfaceFactoryOwner);
reveman 2016/06/15 19:05:08 nit: move to initializer list
206 factory_owner_ = make_scoped_refptr(new SurfaceFactoryOwner); 204 factory_owner_->surface_ = this;
207 factory_owner_->surface_ = this; 205 factory_owner_->id_allocator_ =
208 factory_owner_->id_allocator_ = 206 aura::Env::GetInstance()->context_factory()->CreateSurfaceIdAllocator();
209 aura::Env::GetInstance()->context_factory()->CreateSurfaceIdAllocator(); 207 factory_owner_->surface_factory_.reset(
210 factory_owner_->surface_factory_.reset( 208 new cc::SurfaceFactory(surface_manager_, factory_owner_.get()));
211 new cc::SurfaceFactory(surface_manager_, factory_owner_.get()));
212 }
213
214 if (!factory_owner_) {
215 window_->AddObserver(this);
216 }
217 } 209 }
218 210
219 Surface::~Surface() { 211 Surface::~Surface() {
220 FOR_EACH_OBSERVER(SurfaceObserver, observers_, OnSurfaceDestroying(this)); 212 FOR_EACH_OBSERVER(SurfaceObserver, observers_, OnSurfaceDestroying(this));
221 213
222 window_->layer()->SetShowSolidColorContent(); 214 window_->layer()->SetShowSolidColorContent();
223 215
224 if (factory_owner_) { 216 factory_owner_->surface_ = nullptr;
225 factory_owner_->surface_ = nullptr;
226 } else {
227 window_->RemoveObserver(this);
228 }
229 if (compositor_)
230 compositor_->RemoveObserver(this);
231 217
232 // Call pending frame callbacks with a null frame time to indicate that they 218 // Call pending frame callbacks with a null frame time to indicate that they
233 // have been cancelled. 219 // have been cancelled.
234 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); 220 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
235 active_frame_callbacks_.splice(active_frame_callbacks_.end(), 221 active_frame_callbacks_.splice(active_frame_callbacks_.end(),
236 frame_callbacks_); 222 frame_callbacks_);
237 for (const auto& frame_callback : active_frame_callbacks_) 223 for (const auto& frame_callback : active_frame_callbacks_)
238 frame_callback.Run(base::TimeTicks()); 224 frame_callback.Run(base::TimeTicks());
239 225
240 if (!surface_id_.is_null()) 226 if (!surface_id_.is_null())
241 factory_owner_->surface_factory_->Destroy(surface_id_); 227 factory_owner_->surface_factory_->Destroy(surface_id_);
242 } 228 }
243 229
244 // static 230 // static
245 Surface* Surface::AsSurface(const aura::Window* window) { 231 Surface* Surface::AsSurface(const aura::Window* window) {
246 return window->GetProperty(kSurfaceKey); 232 return window->GetProperty(kSurfaceKey);
247 } 233 }
248 234
249 // static
250 void Surface::SetUseSurfaceLayer(bool use_surface_layer) {
251 use_surface_layer_ = use_surface_layer;
252 }
253
254 void Surface::Attach(Buffer* buffer) { 235 void Surface::Attach(Buffer* buffer) {
255 TRACE_EVENT1("exo", "Surface::Attach", "buffer", 236 TRACE_EVENT1("exo", "Surface::Attach", "buffer",
256 buffer ? buffer->GetSize().ToString() : "null"); 237 buffer ? buffer->GetSize().ToString() : "null");
257 238
258 has_pending_contents_ = true; 239 has_pending_contents_ = true;
259 pending_buffer_ = buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>(); 240 pending_buffer_ = buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>();
260 } 241 }
261 242
262 void Surface::Damage(const gfx::Rect& damage) { 243 void Surface::Damage(const gfx::Rect& damage) {
263 TRACE_EVENT1("exo", "Surface::Damage", "damage", damage.ToString()); 244 TRACE_EVENT1("exo", "Surface::Damage", "damage", damage.ToString());
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 } 426 }
446 427
447 void Surface::CommitSurfaceHierarchy() { 428 void Surface::CommitSurfaceHierarchy() {
448 DCHECK(needs_commit_surface_hierarchy_); 429 DCHECK(needs_commit_surface_hierarchy_);
449 needs_commit_surface_hierarchy_ = false; 430 needs_commit_surface_hierarchy_ = false;
450 has_pending_layer_changes_ = false; 431 has_pending_layer_changes_ = false;
451 432
452 state_ = pending_state_; 433 state_ = pending_state_;
453 pending_state_.only_visible_on_secure_output = false; 434 pending_state_.only_visible_on_secure_output = false;
454 435
455 if (factory_owner_) { 436 CommitSurfaceContents();
reveman 2016/06/15 19:05:08 nit: can we just move the implementation of this f
reveman 2016/06/15 19:05:08 nit: can we just move the impl of CommitSurfaceCon
456 CommitSurfaceContents();
457 } else {
458 CommitTextureContents();
459 }
460 437
461 // Synchronize window hierarchy. This will position and update the stacking 438 // Synchronize window hierarchy. This will position and update the stacking
462 // order of all sub-surfaces after committing all pending state of sub-surface 439 // order of all sub-surfaces after committing all pending state of sub-surface
463 // descendants. 440 // descendants.
464 aura::Window* stacking_target = nullptr; 441 aura::Window* stacking_target = nullptr;
465 for (auto& sub_surface_entry : pending_sub_surfaces_) { 442 for (auto& sub_surface_entry : pending_sub_surfaces_) {
466 Surface* sub_surface = sub_surface_entry.first; 443 Surface* sub_surface = sub_surface_entry.first;
467 444
468 // Synchronsouly commit all pending state of the sub-surface and its 445 // Synchronsouly commit all pending state of the sub-surface and its
469 // decendents. 446 // decendents.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 } 528 }
552 529
553 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const { 530 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const {
554 std::unique_ptr<base::trace_event::TracedValue> value( 531 std::unique_ptr<base::trace_event::TracedValue> value(
555 new base::trace_event::TracedValue()); 532 new base::trace_event::TracedValue());
556 value->SetString("name", window_->layer()->name()); 533 value->SetString("name", window_->layer()->name());
557 return value; 534 return value;
558 } 535 }
559 536
560 //////////////////////////////////////////////////////////////////////////////// 537 ////////////////////////////////////////////////////////////////////////////////
561 // aura::WindowObserver overrides:
562
563 void Surface::OnWindowAddedToRootWindow(aura::Window* window) {
564 DCHECK(!compositor_);
565 DCHECK(!factory_owner_);
566 compositor_ = window_->layer()->GetCompositor();
567 compositor_->AddObserver(this);
568 }
569
570 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window,
571 aura::Window* new_root) {
572 DCHECK(compositor_);
573 compositor_->RemoveObserver(this);
574 compositor_ = nullptr;
575 }
576
577 ////////////////////////////////////////////////////////////////////////////////
578 // ui::LayerOwnerDelegate overrides: 538 // ui::LayerOwnerDelegate overrides:
579 539
580 void Surface::OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) { 540 void Surface::OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) {
581 if (!current_buffer_) 541 if (!current_buffer_)
582 return; 542 return;
583 543
584 // TODO(reveman): Give the client a chance to provide new contents. 544 // TODO(reveman): Give the client a chance to provide new contents.
585 if (factory_owner_) { 545 SetSurfaceLayerContents(new_layer);
586 SetSurfaceLayerContents(new_layer);
587 } else {
588 SetTextureLayerContents(new_layer);
589 }
590 }
591
592 ////////////////////////////////////////////////////////////////////////////////
593 // ui::CompositorObserver overrides:
594
595 void Surface::OnCompositingDidCommit(ui::Compositor* compositor) {
596 DCHECK(!factory_owner_);
597 // Move frame callbacks to the end of |active_frame_callbacks_|.
598 active_frame_callbacks_.splice(active_frame_callbacks_.end(),
599 frame_callbacks_);
600 }
601
602 void Surface::OnCompositingStarted(ui::Compositor* compositor,
603 base::TimeTicks start_time) {
604 last_compositing_start_time_ = start_time;
605 }
606
607 void Surface::OnCompositingEnded(ui::Compositor* compositor) {
608 // Run all frame callbacks associated with the compositor's active tree.
609 while (!active_frame_callbacks_.empty()) {
610 active_frame_callbacks_.front().Run(last_compositing_start_time_);
611 active_frame_callbacks_.pop_front();
612 }
613
614 // Nothing more to do in here unless this has been set.
615 if (!update_contents_after_successful_compositing_)
616 return;
617
618 update_contents_after_successful_compositing_ = false;
619
620 // Early out if no contents is currently assigned to the surface.
621 if (!current_buffer_)
622 return;
623
624 // Update contents by producing a new texture mailbox for the current buffer.
reveman 2016/06/15 19:05:09 nit: this could was here to handle lost context si
625 SetTextureLayerContents(window_->layer());
626 }
627
628 void Surface::OnCompositingAborted(ui::Compositor* compositor) {
629 // The contents of this surface might be lost if compositing aborted because
630 // of a lost graphics context. We recover from this by updating the contents
631 // of the surface next time the compositor successfully ends compositing.
632 update_contents_after_successful_compositing_ = true;
633 }
634
635 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) {
636 compositor->RemoveObserver(this);
637 compositor_ = nullptr;
638 } 546 }
639 547
640 void Surface::WillDraw(cc::SurfaceId id) { 548 void Surface::WillDraw(cc::SurfaceId id) {
641 while (!active_frame_callbacks_.empty()) { 549 while (!active_frame_callbacks_.empty()) {
642 active_frame_callbacks_.front().Run(base::TimeTicks::Now()); 550 active_frame_callbacks_.front().Run(base::TimeTicks::Now());
643 active_frame_callbacks_.pop_front(); 551 active_frame_callbacks_.pop_front();
644 } 552 }
645 } 553 }
646 554
647 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { 555 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() {
(...skipping 24 matching lines...) Expand all
672 return false; 580 return false;
673 } 581 }
674 582
675 void Surface::SetSurfaceHierarchyNeedsCommitToNewSurfaces() { 583 void Surface::SetSurfaceHierarchyNeedsCommitToNewSurfaces() {
676 needs_commit_to_new_surface_ = true; 584 needs_commit_to_new_surface_ = true;
677 for (auto& sub_surface_entry : pending_sub_surfaces_) { 585 for (auto& sub_surface_entry : pending_sub_surfaces_) {
678 sub_surface_entry.first->SetSurfaceHierarchyNeedsCommitToNewSurfaces(); 586 sub_surface_entry.first->SetSurfaceHierarchyNeedsCommitToNewSurfaces();
679 } 587 }
680 } 588 }
681 589
682 void Surface::CommitTextureContents() {
683 // We update contents if Attach() has been called since last commit.
684 if (has_pending_contents_) {
685 has_pending_contents_ = false;
686
687 current_buffer_ = pending_buffer_;
688 pending_buffer_.reset();
689
690 cc::TextureMailbox texture_mailbox;
691 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback;
692 if (current_buffer_) {
693 texture_mailbox_release_callback = current_buffer_->ProduceTextureMailbox(
694 &texture_mailbox, state_.only_visible_on_secure_output,
695 true /* client_usage */);
696 }
697
698 // Update layer with the new contents.
699 if (texture_mailbox_release_callback) {
700 texture_size_in_dip_ = gfx::ScaleToFlooredSize(
701 texture_mailbox.size_in_pixels(), 1.0f / state_.buffer_scale);
702 window_->layer()->SetTextureMailbox(
703 texture_mailbox, std::move(texture_mailbox_release_callback),
704 texture_size_in_dip_);
705 window_->layer()->SetTextureFlipped(false);
706 } else {
707 // Show solid color content if no buffer is attached or we failed
708 // to produce a texture mailbox for the currently attached buffer.
709 window_->layer()->SetShowSolidColorContent();
710 window_->layer()->SetColor(SK_ColorBLACK);
711 }
712
713 // Schedule redraw of the damage region.
714 for (SkRegion::Iterator it(pending_damage_); !it.done(); it.next())
715 window_->layer()->SchedulePaint(gfx::SkIRectToRect(it.rect()));
716
717 // Reset damage.
718 pending_damage_.setEmpty();
719 }
720
721 if (window_->layer()->has_external_content()) {
722 // Determine the new surface size.
723 // - Texture size in DIP defines the size if nothing else is set.
724 // - If a viewport is set then that defines the size, otherwise
725 // the crop rectangle defines the size if set.
726 gfx::Size contents_size = texture_size_in_dip_;
727 if (!state_.viewport.IsEmpty()) {
728 contents_size = state_.viewport;
729 } else if (!state_.crop.IsEmpty()) {
730 DLOG_IF(WARNING, !gfx::IsExpressibleAsInt(state_.crop.width()) ||
731 !gfx::IsExpressibleAsInt(state_.crop.height()))
732 << "Crop rectangle size (" << state_.crop.size().ToString()
733 << ") most be expressible using integers when viewport is not set";
734 contents_size = gfx::ToCeiledSize(state_.crop.size());
735 }
736 window_->layer()->SetTextureCrop(state_.crop);
737 window_->layer()->SetTextureScale(
738 static_cast<float>(texture_size_in_dip_.width()) /
739 contents_size.width(),
740 static_cast<float>(texture_size_in_dip_.height()) /
741 contents_size.height());
742 window_->layer()->SetTextureAlpha(state_.alpha);
743 window_->layer()->SetBounds(
744 gfx::Rect(window_->layer()->bounds().origin(), contents_size));
745 }
746
747 // Move pending frame callbacks to the end of |frame_callbacks_|.
748 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
749
750 // Update alpha compositing properties.
751 // TODO(reveman): Use a more reliable way to force blending off than setting
752 // fills-bounds-opaquely.
753 window_->layer()->SetFillsBoundsOpaquely(
754 state_.blend_mode == SkXfermode::kSrc_Mode ||
755 state_.opaque_region.contains(
756 gfx::RectToSkIRect(gfx::Rect(window_->layer()->size()))));
757 }
758
759 void Surface::CommitSurfaceContents() { 590 void Surface::CommitSurfaceContents() {
760 // We update contents if Attach() has been called since last commit. 591 // We update contents if Attach() has been called since last commit.
761 if (has_pending_contents_) { 592 if (has_pending_contents_) {
762 has_pending_contents_ = false; 593 has_pending_contents_ = false;
763 current_buffer_ = pending_buffer_; 594 current_buffer_ = pending_buffer_;
764 pending_buffer_.reset(); 595 pending_buffer_.reset();
765 596
766 if (current_buffer_) { 597 if (current_buffer_) {
767 std::unique_ptr<cc::SingleReleaseCallback> 598 std::unique_ptr<cc::SingleReleaseCallback>
768 texture_mailbox_release_callback; 599 texture_mailbox_release_callback;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 pending_damage_.setEmpty(); 736 pending_damage_.setEmpty();
906 737
907 DCHECK(!current_resource_.id || 738 DCHECK(!current_resource_.id ||
908 factory_owner_->release_callbacks_.count(current_resource_.id)); 739 factory_owner_->release_callbacks_.count(current_resource_.id));
909 740
910 // Move pending frame callbacks to the end of active_frame_callbacks_ 741 // Move pending frame callbacks to the end of active_frame_callbacks_
911 active_frame_callbacks_.splice(active_frame_callbacks_.end(), 742 active_frame_callbacks_.splice(active_frame_callbacks_.end(),
912 pending_frame_callbacks_); 743 pending_frame_callbacks_);
913 } 744 }
914 745
915 void Surface::SetTextureLayerContents(ui::Layer* layer) {
916 DCHECK(current_buffer_);
917
918 cc::TextureMailbox texture_mailbox;
919 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback =
920 current_buffer_->ProduceTextureMailbox(
921 &texture_mailbox, state_.only_visible_on_secure_output,
922 false /* client_usage */);
923 if (!texture_mailbox_release_callback)
924 return;
925
926 layer->SetTextureMailbox(texture_mailbox,
927 std::move(texture_mailbox_release_callback),
928 texture_size_in_dip_);
929 layer->SetTextureFlipped(false);
930 layer->SetTextureCrop(state_.crop);
931 layer->SetTextureScale(static_cast<float>(texture_size_in_dip_.width()) /
932 layer->bounds().width(),
933 static_cast<float>(texture_size_in_dip_.height()) /
934 layer->bounds().height());
935 layer->SetTextureAlpha(state_.alpha);
936 }
937
938 void Surface::SetSurfaceLayerContents(ui::Layer* layer) { 746 void Surface::SetSurfaceLayerContents(ui::Layer* layer) {
939 if (surface_id_.is_null()) 747 if (surface_id_.is_null())
940 return; 748 return;
941 749
942 gfx::Size layer_size = layer->bounds().size(); 750 gfx::Size layer_size = layer->bounds().size();
943 float contents_surface_to_layer_scale = 1.0f; 751 float contents_surface_to_layer_scale = 1.0f;
944 752
945 layer->SetShowSurface( 753 layer->SetShowSurface(
946 surface_id_, 754 surface_id_,
947 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), 755 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)),
948 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), 756 base::Bind(&RequireCallback, base::Unretained(surface_manager_)),
949 layer_size, contents_surface_to_layer_scale, layer_size); 757 layer_size, contents_surface_to_layer_scale, layer_size);
950 } 758 }
951 759
952 bool Surface::use_surface_layer_ = false;
953
954 } // namespace exo 760 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698