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

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

Issue 2388753003: Introduce cc::LocalFrameId and use in SurfaceFactory (Closed)
Patch Set: Fix exo_unittests Created 4 years, 2 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 const cc::ReturnedResourceArray& resources) { 173 const cc::ReturnedResourceArray& resources) {
174 scoped_refptr<SurfaceFactoryOwner> holder(this); 174 scoped_refptr<SurfaceFactoryOwner> holder(this);
175 for (auto& resource : resources) { 175 for (auto& resource : resources) {
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::SurfaceId& 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(id);
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 191
192 //////////////////////////////////////////////////////////////////////////////// 192 ////////////////////////////////////////////////////////////////////////////////
193 // SurfaceFactoryOwner, private: 193 // SurfaceFactoryOwner, private:
(...skipping 15 matching lines...) Expand all
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); 213 window_->set_layer_owner_delegate(this);
214 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); 214 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter));
215 window_->set_owned_by_parent(false); 215 window_->set_owned_by_parent(false);
216 factory_owner_->surface_ = this; 216 factory_owner_->surface_ = this;
217 factory_owner_->frame_sink_id_ = 217 factory_owner_->frame_sink_id_ =
218 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId(); 218 aura::Env::GetInstance()->context_factory()->AllocateFrameSinkId();
219 factory_owner_->id_allocator_.reset( 219 factory_owner_->id_allocator_.reset(new cc::SurfaceIdAllocator());
220 new cc::SurfaceIdAllocator(factory_owner_->frame_sink_id_));
221 surface_manager_->RegisterFrameSinkId(factory_owner_->frame_sink_id_); 220 surface_manager_->RegisterFrameSinkId(factory_owner_->frame_sink_id_);
222 factory_owner_->surface_factory_.reset(new cc::SurfaceFactory( 221 factory_owner_->surface_factory_.reset(new cc::SurfaceFactory(
223 factory_owner_->frame_sink_id_, surface_manager_, factory_owner_.get())); 222 factory_owner_->frame_sink_id_, surface_manager_, factory_owner_.get()));
224 aura::Env::GetInstance()->context_factory()->AddObserver(this); 223 aura::Env::GetInstance()->context_factory()->AddObserver(this);
225 } 224 }
226 225
227 Surface::~Surface() { 226 Surface::~Surface() {
228 aura::Env::GetInstance()->context_factory()->RemoveObserver(this); 227 aura::Env::GetInstance()->context_factory()->RemoveObserver(this);
229 FOR_EACH_OBSERVER(SurfaceObserver, observers_, OnSurfaceDestroying(this)); 228 FOR_EACH_OBSERVER(SurfaceObserver, observers_, OnSurfaceDestroying(this));
230 229
231 window_->layer()->SetShowSolidColorContent(); 230 window_->layer()->SetShowSolidColorContent();
232 231
233 factory_owner_->surface_ = nullptr; 232 factory_owner_->surface_ = nullptr;
234 233
235 // Call pending frame callbacks with a null frame time to indicate that they 234 // Call pending frame callbacks with a null frame time to indicate that they
236 // have been cancelled. 235 // have been cancelled.
237 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); 236 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
238 active_frame_callbacks_.splice(active_frame_callbacks_.end(), 237 active_frame_callbacks_.splice(active_frame_callbacks_.end(),
239 frame_callbacks_); 238 frame_callbacks_);
240 for (const auto& frame_callback : active_frame_callbacks_) 239 for (const auto& frame_callback : active_frame_callbacks_)
241 frame_callback.Run(base::TimeTicks()); 240 frame_callback.Run(base::TimeTicks());
242 241
243 if (!surface_id_.is_null()) 242 if (!local_frame_id_.is_null())
244 factory_owner_->surface_factory_->Destroy(surface_id_); 243 factory_owner_->surface_factory_->Destroy(local_frame_id_);
245 } 244 }
246 245
247 // static 246 // static
248 Surface* Surface::AsSurface(const aura::Window* window) { 247 Surface* Surface::AsSurface(const aura::Window* window) {
249 return window->GetProperty(kSurfaceKey); 248 return window->GetProperty(kSurfaceKey);
250 } 249 }
251 250
251 cc::SurfaceId Surface::GetSurfaceId() const {
252 return cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_);
253 }
254
252 void Surface::Attach(Buffer* buffer) { 255 void Surface::Attach(Buffer* buffer) {
253 TRACE_EVENT1("exo", "Surface::Attach", "buffer", 256 TRACE_EVENT1("exo", "Surface::Attach", "buffer",
254 buffer ? buffer->GetSize().ToString() : "null"); 257 buffer ? buffer->GetSize().ToString() : "null");
255 258
256 has_pending_contents_ = true; 259 has_pending_contents_ = true;
257 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>()); 260 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>());
258 } 261 }
259 262
260 void Surface::Damage(const gfx::Rect& damage) { 263 void Surface::Damage(const gfx::Rect& damage) {
261 TRACE_EVENT1("exo", "Surface::Damage", "damage", damage.ToString()); 264 TRACE_EVENT1("exo", "Surface::Damage", "damage", damage.ToString());
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 439
437 if (delegate_) { 440 if (delegate_) {
438 delegate_->OnSurfaceCommit(); 441 delegate_->OnSurfaceCommit();
439 } else { 442 } else {
440 CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); 443 CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces();
441 CommitSurfaceHierarchy(); 444 CommitSurfaceHierarchy();
442 } 445 }
443 } 446 }
444 447
445 void Surface::OnLostResources() { 448 void Surface::OnLostResources() {
446 if (surface_id_.is_null()) 449 if (local_frame_id_.is_null())
447 return; 450 return;
448 451
449 UpdateResource(false); 452 UpdateResource(false);
450 UpdateSurface(false); 453 UpdateSurface(false);
451 } 454 }
452 455
453 void Surface::CommitSurfaceHierarchy() { 456 void Surface::CommitSurfaceHierarchy() {
454 DCHECK(needs_commit_surface_hierarchy_); 457 DCHECK(needs_commit_surface_hierarchy_);
455 needs_commit_surface_hierarchy_ = false; 458 needs_commit_surface_hierarchy_ = false;
456 has_pending_layer_changes_ = false; 459 has_pending_layer_changes_ = false;
457 460
458 state_ = pending_state_; 461 state_ = pending_state_;
459 pending_state_.only_visible_on_secure_output = false; 462 pending_state_.only_visible_on_secure_output = false;
460 463
461 // We update contents if Attach() has been called since last commit. 464 // We update contents if Attach() has been called since last commit.
462 if (has_pending_contents_) { 465 if (has_pending_contents_) {
463 has_pending_contents_ = false; 466 has_pending_contents_ = false;
464 467
465 current_buffer_ = std::move(pending_buffer_); 468 current_buffer_ = std::move(pending_buffer_);
466 469
467 UpdateResource(true); 470 UpdateResource(true);
468 } 471 }
469 472
470 cc::SurfaceId old_surface_id = surface_id_; 473 cc::LocalFrameId old_local_frame_id = local_frame_id_;
471 if (needs_commit_to_new_surface_ || surface_id_.is_null()) { 474 if (needs_commit_to_new_surface_ || local_frame_id_.is_null()) {
472 needs_commit_to_new_surface_ = false; 475 needs_commit_to_new_surface_ = false;
473 surface_id_ = factory_owner_->id_allocator_->GenerateId(); 476 local_frame_id_ = factory_owner_->id_allocator_->GenerateId();
474 factory_owner_->surface_factory_->Create(surface_id_); 477 factory_owner_->surface_factory_->Create(local_frame_id_);
475 } 478 }
476 479
477 UpdateSurface(true); 480 UpdateSurface(true);
478 481
479 if (!old_surface_id.is_null() && old_surface_id != surface_id_) { 482 if (!old_local_frame_id.is_null() && old_local_frame_id != local_frame_id_) {
480 factory_owner_->surface_factory_->SetPreviousFrameSurface(surface_id_, 483 factory_owner_->surface_factory_->SetPreviousFrameSurface(
481 old_surface_id); 484 local_frame_id_, old_local_frame_id);
482 factory_owner_->surface_factory_->Destroy(old_surface_id); 485 factory_owner_->surface_factory_->Destroy(old_local_frame_id);
483 } 486 }
484 487
485 if (old_surface_id != surface_id_) { 488 if (old_local_frame_id != local_frame_id_) {
486 float contents_surface_to_layer_scale = 1.0; 489 float contents_surface_to_layer_scale = 1.0;
487 window_->layer()->SetShowSurface( 490 window_->layer()->SetShowSurface(
488 surface_id_, 491 cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_),
489 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), 492 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)),
490 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), 493 base::Bind(&RequireCallback, base::Unretained(surface_manager_)),
491 content_size_, contents_surface_to_layer_scale, content_size_); 494 content_size_, contents_surface_to_layer_scale, content_size_);
492 window_->layer()->SetBounds( 495 window_->layer()->SetBounds(
493 gfx::Rect(window_->layer()->bounds().origin(), content_size_)); 496 gfx::Rect(window_->layer()->bounds().origin(), content_size_));
494 window_->layer()->SetFillsBoundsOpaquely( 497 window_->layer()->SetFillsBoundsOpaquely(
495 state_.blend_mode == SkXfermode::kSrc_Mode || 498 state_.blend_mode == SkXfermode::kSrc_Mode ||
496 state_.opaque_region.contains( 499 state_.opaque_region.contains(
497 gfx::RectToSkIRect(gfx::Rect(content_size_)))); 500 gfx::RectToSkIRect(gfx::Rect(content_size_))));
498 } 501 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 // ui::LayerOwnerDelegate overrides: 613 // ui::LayerOwnerDelegate overrides:
611 614
612 void Surface::OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) { 615 void Surface::OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) {
613 if (!current_buffer_.buffer()) 616 if (!current_buffer_.buffer())
614 return; 617 return;
615 618
616 // TODO(reveman): Give the client a chance to provide new contents. 619 // TODO(reveman): Give the client a chance to provide new contents.
617 SetSurfaceLayerContents(new_layer); 620 SetSurfaceLayerContents(new_layer);
618 } 621 }
619 622
620 void Surface::WillDraw(const cc::SurfaceId& id) { 623 void Surface::WillDraw(const cc::LocalFrameId& id) {
621 while (!active_frame_callbacks_.empty()) { 624 while (!active_frame_callbacks_.empty()) {
622 active_frame_callbacks_.front().Run(base::TimeTicks::Now()); 625 active_frame_callbacks_.front().Run(base::TimeTicks::Now());
623 active_frame_callbacks_.pop_front(); 626 active_frame_callbacks_.pop_front();
624 } 627 }
625 } 628 }
626 629
627 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { 630 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() {
628 if (HasLayerHierarchyChanged()) 631 if (HasLayerHierarchyChanged())
629 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); 632 SetSurfaceHierarchyNeedsCommitToNewSurfaces();
630 } 633 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 } 688 }
686 689
687 void Surface::SetSurfaceHierarchyNeedsCommitToNewSurfaces() { 690 void Surface::SetSurfaceHierarchyNeedsCommitToNewSurfaces() {
688 needs_commit_to_new_surface_ = true; 691 needs_commit_to_new_surface_ = true;
689 for (auto& sub_surface_entry : pending_sub_surfaces_) { 692 for (auto& sub_surface_entry : pending_sub_surfaces_) {
690 sub_surface_entry.first->SetSurfaceHierarchyNeedsCommitToNewSurfaces(); 693 sub_surface_entry.first->SetSurfaceHierarchyNeedsCommitToNewSurfaces();
691 } 694 }
692 } 695 }
693 696
694 void Surface::SetSurfaceLayerContents(ui::Layer* layer) { 697 void Surface::SetSurfaceLayerContents(ui::Layer* layer) {
695 if (surface_id_.is_null()) 698 if (local_frame_id_.is_null())
696 return; 699 return;
697 700
698 gfx::Size layer_size = layer->bounds().size(); 701 gfx::Size layer_size = layer->bounds().size();
699 float contents_surface_to_layer_scale = 1.0f; 702 float contents_surface_to_layer_scale = 1.0f;
700 703
701 layer->SetShowSurface( 704 layer->SetShowSurface(
702 surface_id_, 705 cc::SurfaceId(factory_owner_->frame_sink_id_, local_frame_id_),
703 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), 706 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)),
704 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), 707 base::Bind(&RequireCallback, base::Unretained(surface_manager_)),
705 layer_size, contents_surface_to_layer_scale, layer_size); 708 layer_size, contents_surface_to_layer_scale, layer_size);
706 } 709 }
707 710
708 void Surface::UpdateResource(bool client_usage) { 711 void Surface::UpdateResource(bool client_usage) {
709 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; 712 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback;
710 713
711 cc::TextureMailbox texture_mailbox; 714 cc::TextureMailbox texture_mailbox;
712 if (current_buffer_.buffer()) { 715 if (current_buffer_.buffer()) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 cc::SolidColorDrawQuad* solid_quad = 819 cc::SolidColorDrawQuad* solid_quad =
817 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); 820 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>();
818 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false); 821 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false);
819 } 822 }
820 823
821 delegated_frame->render_pass_list.push_back(std::move(render_pass)); 824 delegated_frame->render_pass_list.push_back(std::move(render_pass));
822 cc::CompositorFrame frame; 825 cc::CompositorFrame frame;
823 frame.delegated_frame_data = std::move(delegated_frame); 826 frame.delegated_frame_data = std::move(delegated_frame);
824 827
825 factory_owner_->surface_factory_->SubmitCompositorFrame( 828 factory_owner_->surface_factory_->SubmitCompositorFrame(
826 surface_id_, std::move(frame), cc::SurfaceFactory::DrawCallback()); 829 local_frame_id_, std::move(frame), cc::SurfaceFactory::DrawCallback());
827 } 830 }
828 831
829 int64_t Surface::SetPropertyInternal(const void* key, 832 int64_t Surface::SetPropertyInternal(const void* key,
830 const char* name, 833 const char* name,
831 PropertyDeallocator deallocator, 834 PropertyDeallocator deallocator,
832 int64_t value, 835 int64_t value,
833 int64_t default_value) { 836 int64_t default_value) {
834 int64_t old = GetPropertyInternal(key, default_value); 837 int64_t old = GetPropertyInternal(key, default_value);
835 if (value == default_value) { 838 if (value == default_value) {
836 prop_map_.erase(key); 839 prop_map_.erase(key);
837 } else { 840 } else {
838 Value prop_value; 841 Value prop_value;
839 prop_value.name = name; 842 prop_value.name = name;
840 prop_value.value = value; 843 prop_value.value = value;
841 prop_value.deallocator = deallocator; 844 prop_value.deallocator = deallocator;
842 prop_map_[key] = prop_value; 845 prop_map_[key] = prop_value;
843 } 846 }
844 return old; 847 return old;
845 } 848 }
846 849
847 int64_t Surface::GetPropertyInternal(const void* key, 850 int64_t Surface::GetPropertyInternal(const void* key,
848 int64_t default_value) const { 851 int64_t default_value) const {
849 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); 852 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key);
850 if (iter == prop_map_.end()) 853 if (iter == prop_map_.end())
851 return default_value; 854 return default_value;
852 return iter->second.value; 855 return iter->second.value;
853 } 856 }
854 857
855 } // namespace exo 858 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698