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

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

Issue 2868473002: Implement aura::Window::CreateCompositorFrameSink() (Closed)
Patch Set: Address review issues Created 3 years, 7 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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
14 #include "base/trace_event/trace_event_argument.h" 14 #include "base/trace_event/trace_event_argument.h"
15 #include "cc/output/compositor_frame_sink.h"
15 #include "cc/quads/render_pass.h" 16 #include "cc/quads/render_pass.h"
16 #include "cc/quads/shared_quad_state.h" 17 #include "cc/quads/shared_quad_state.h"
17 #include "cc/quads/solid_color_draw_quad.h" 18 #include "cc/quads/solid_color_draw_quad.h"
18 #include "cc/quads/texture_draw_quad.h" 19 #include "cc/quads/texture_draw_quad.h"
19 #include "cc/resources/single_release_callback.h" 20 #include "cc/resources/single_release_callback.h"
20 #include "cc/surfaces/local_surface_id_allocator.h"
21 #include "cc/surfaces/sequence_surface_reference_factory.h" 21 #include "cc/surfaces/sequence_surface_reference_factory.h"
22 #include "cc/surfaces/surface.h" 22 #include "cc/surfaces/surface.h"
23 #include "cc/surfaces/surface_manager.h" 23 #include "cc/surfaces/surface_manager.h"
24 #include "components/exo/buffer.h" 24 #include "components/exo/buffer.h"
25 #include "components/exo/pointer.h" 25 #include "components/exo/pointer.h"
26 #include "components/exo/surface_delegate.h" 26 #include "components/exo/surface_delegate.h"
27 #include "components/exo/surface_observer.h" 27 #include "components/exo/surface_observer.h"
28 #include "third_party/khronos/GLES2/gl2.h" 28 #include "third_party/khronos/GLES2/gl2.h"
29 #include "ui/aura/env.h" 29 #include "ui/aura/env.h"
30 #include "ui/aura/window_delegate.h" 30 #include "ui/aura/window_delegate.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 159
160 } // namespace 160 } // namespace
161 161
162 //////////////////////////////////////////////////////////////////////////////// 162 ////////////////////////////////////////////////////////////////////////////////
163 // Surface, public: 163 // Surface, public:
164 164
165 // TODO(fsamuel): exo should not use context_factory_private. Instead, we should 165 // TODO(fsamuel): exo should not use context_factory_private. Instead, we should
166 // request a CompositorFrameSink from the aura::Window. Setting up the 166 // request a CompositorFrameSink from the aura::Window. Setting up the
167 // BeginFrame hierarchy should be an internal implementation detail of aura or 167 // BeginFrame hierarchy should be an internal implementation detail of aura or
168 // mus in aura-mus. 168 // mus in aura-mus.
169 Surface::Surface() 169 Surface::Surface() : window_(new aura::Window(new CustomWindowDelegate(this))) {
170 : window_(new aura::Window(new CustomWindowDelegate(this))),
171 frame_sink_id_(aura::Env::GetInstance()
172 ->context_factory_private()
173 ->AllocateFrameSinkId()) {
174 compositor_frame_sink_holder_ = new CompositorFrameSinkHolder(
175 this, frame_sink_id_,
176 aura::Env::GetInstance()->context_factory_private()->GetSurfaceManager());
177 // TODO(samans): exo::Surface should not be using
178 // DirectSurfaceReferenceFactory (crbug.com/688573).
179 surface_reference_factory_ = aura::Env::GetInstance()
180 ->context_factory_private()
181 ->GetSurfaceManager()
182 ->reference_factory();
183 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); 170 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
184 window_->SetName("ExoSurface"); 171 window_->SetName("ExoSurface");
185 window_->SetProperty(kSurfaceKey, this); 172 window_->SetProperty(kSurfaceKey, this);
186 window_->Init(ui::LAYER_SOLID_COLOR); 173 window_->Init(ui::LAYER_SOLID_COLOR);
187 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); 174 window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter));
188 window_->set_owned_by_parent(false); 175 window_->set_owned_by_parent(false);
189 window_->AddObserver(this); 176 window_->AddObserver(this);
190 aura::Env::GetInstance()->context_factory()->AddObserver(this); 177 aura::Env::GetInstance()->context_factory()->AddObserver(this);
178
179 std::unique_ptr<cc::CompositorFrameSink> compositor_frame_sink =
reveman 2017/05/08 19:25:16 nit: feel free to remove this temporary variable i
Peng 2017/05/08 20:14:01 Done.
180 window_->CreateCompositorFrameSink();
181 compositor_frame_sink_holder_ =
182 new CompositorFrameSinkHolder(this, std::move(compositor_frame_sink));
191 } 183 }
192 184
193 Surface::~Surface() { 185 Surface::~Surface() {
194 aura::Env::GetInstance()->context_factory()->RemoveObserver(this); 186 aura::Env::GetInstance()->context_factory()->RemoveObserver(this);
195 for (SurfaceObserver& observer : observers_) 187 for (SurfaceObserver& observer : observers_)
196 observer.OnSurfaceDestroying(this); 188 observer.OnSurfaceDestroying(this);
197 189
198 window_->RemoveObserver(this); 190 window_->RemoveObserver(this);
199 if (window_->layer()->GetCompositor()) 191 if (window_->layer()->GetCompositor())
200 window_->layer()->GetCompositor()->vsync_manager()->RemoveObserver(this); 192 window_->layer()->GetCompositor()->vsync_manager()->RemoveObserver(this);
(...skipping 20 matching lines...) Expand all
221 213
222 compositor_frame_sink_holder_->GetCompositorFrameSink()->EvictFrame(); 214 compositor_frame_sink_holder_->GetCompositorFrameSink()->EvictFrame();
223 } 215 }
224 216
225 // static 217 // static
226 Surface* Surface::AsSurface(const aura::Window* window) { 218 Surface* Surface::AsSurface(const aura::Window* window) {
227 return window->GetProperty(kSurfaceKey); 219 return window->GetProperty(kSurfaceKey);
228 } 220 }
229 221
230 cc::SurfaceId Surface::GetSurfaceId() const { 222 cc::SurfaceId Surface::GetSurfaceId() const {
231 return cc::SurfaceId(frame_sink_id_, local_surface_id_); 223 return window_->GetSurfaceId();
232 } 224 }
233 225
234 void Surface::Attach(Buffer* buffer) { 226 void Surface::Attach(Buffer* buffer) {
235 TRACE_EVENT1("exo", "Surface::Attach", "buffer", 227 TRACE_EVENT1("exo", "Surface::Attach", "buffer",
236 buffer ? buffer->GetSize().ToString() : "null"); 228 buffer ? buffer->GetSize().ToString() : "null");
237 229
238 has_pending_contents_ = true; 230 has_pending_contents_ = true;
239 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>()); 231 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>());
240 } 232 }
241 233
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 449
458 // We update contents if Attach() has been called since last commit. 450 // We update contents if Attach() has been called since last commit.
459 if (has_pending_contents_) { 451 if (has_pending_contents_) {
460 has_pending_contents_ = false; 452 has_pending_contents_ = false;
461 453
462 current_buffer_ = std::move(pending_buffer_); 454 current_buffer_ = std::move(pending_buffer_);
463 455
464 UpdateResource(true); 456 UpdateResource(true);
465 } 457 }
466 458
467 cc::LocalSurfaceId old_local_surface_id = local_surface_id_;
468 if (needs_commit_to_new_surface_ || !local_surface_id_.is_valid()) {
469 needs_commit_to_new_surface_ = false;
470 local_surface_id_ = id_allocator_.GenerateId();
471 }
472
473 // Move pending frame callbacks to the end of frame_callbacks_. 459 // Move pending frame callbacks to the end of frame_callbacks_.
474 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); 460 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
475 461
476 // Move pending presentation callbacks to the end of presentation_callbacks_. 462 // Move pending presentation callbacks to the end of presentation_callbacks_.
477 presentation_callbacks_.splice(presentation_callbacks_.end(), 463 presentation_callbacks_.splice(presentation_callbacks_.end(),
478 pending_presentation_callbacks_); 464 pending_presentation_callbacks_);
479 465
480 UpdateSurface(false); 466 UpdateSurface(false);
481 467
482 if (old_local_surface_id != local_surface_id_) { 468 if (needs_commit_to_new_surface_) {
483 float contents_surface_to_layer_scale = 1.0; 469 needs_commit_to_new_surface_ = false;
484 // The bounds must be updated before switching to the new surface, because
485 // the layer may be mirrored, in which case a surface change causes the
486 // mirror layer to update its surface using the latest bounds.
487 window_->layer()->SetBounds(
488 gfx::Rect(window_->layer()->bounds().origin(), content_size_));
489 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_);
490 window_->layer()->SetShowPrimarySurface(
491 cc::SurfaceInfo(surface_id, contents_surface_to_layer_scale,
492 content_size_),
493 surface_reference_factory_);
494 window_->layer()->SetFillsBoundsOpaquely( 470 window_->layer()->SetFillsBoundsOpaquely(
495 !current_resource_has_alpha_ || 471 !current_resource_has_alpha_ ||
496 state_.blend_mode == SkBlendMode::kSrc || 472 state_.blend_mode == SkBlendMode::kSrc ||
497 state_.opaque_region.contains( 473 state_.opaque_region.contains(
498 gfx::RectToSkIRect(gfx::Rect(content_size_)))); 474 gfx::RectToSkIRect(gfx::Rect(content_size_))));
499 } 475 }
500 476
501 // Reset damage. 477 // Reset damage.
502 pending_damage_.setEmpty(); 478 pending_damage_.setEmpty();
503
504 DCHECK(!current_resource_.id || 479 DCHECK(!current_resource_.id ||
505 compositor_frame_sink_holder_->HasReleaseCallbackForResource( 480 compositor_frame_sink_holder_->HasReleaseCallbackForResource(
506 current_resource_.id)); 481 current_resource_.id));
507 482
508 // Synchronize window hierarchy. This will position and update the stacking 483 // Synchronize window hierarchy. This will position and update the stacking
509 // order of all sub-surfaces after committing all pending state of sub-surface 484 // order of all sub-surfaces after committing all pending state of sub-surface
510 // descendants. 485 // descendants.
511 aura::Window* stacking_target = nullptr; 486 aura::Window* stacking_target = nullptr;
512 for (auto& sub_surface_entry : pending_sub_surfaces_) { 487 for (auto& sub_surface_entry : pending_sub_surfaces_) {
513 Surface* sub_surface = sub_surface_entry.first; 488 Surface* sub_surface = sub_surface_entry.first;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 631
657 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { 632 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() {
658 if (HasLayerHierarchyChanged()) 633 if (HasLayerHierarchyChanged())
659 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); 634 SetSurfaceHierarchyNeedsCommitToNewSurfaces();
660 } 635 }
661 636
662 //////////////////////////////////////////////////////////////////////////////// 637 ////////////////////////////////////////////////////////////////////////////////
663 // ui::ContextFactoryObserver overrides: 638 // ui::ContextFactoryObserver overrides:
664 639
665 void Surface::OnLostResources() { 640 void Surface::OnLostResources() {
666 if (!local_surface_id_.is_valid())
667 return;
668
669 UpdateResource(false); 641 UpdateResource(false);
670 UpdateSurface(true); 642 UpdateSurface(true);
671 } 643 }
672 644
673 //////////////////////////////////////////////////////////////////////////////// 645 ////////////////////////////////////////////////////////////////////////////////
674 // aura::WindowObserver overrides: 646 // aura::WindowObserver overrides:
675 647
676 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { 648 void Surface::OnWindowAddedToRootWindow(aura::Window* window) {
677 window->layer()->GetCompositor()->AddFrameSink(frame_sink_id_);
678 window->layer()->GetCompositor()->vsync_manager()->AddObserver(this); 649 window->layer()->GetCompositor()->vsync_manager()->AddObserver(this);
679 } 650 }
680 651
681 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, 652 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window,
682 aura::Window* new_root) { 653 aura::Window* new_root) {
683 window->layer()->GetCompositor()->RemoveFrameSink(frame_sink_id_);
684 window->layer()->GetCompositor()->vsync_manager()->RemoveObserver(this); 654 window->layer()->GetCompositor()->vsync_manager()->RemoveObserver(this);
685 } 655 }
686 656
687 //////////////////////////////////////////////////////////////////////////////// 657 ////////////////////////////////////////////////////////////////////////////////
688 // ui::CompositorVSyncManager::Observer overrides: 658 // ui::CompositorVSyncManager::Observer overrides:
689 659
690 void Surface::OnUpdateVSyncParameters(base::TimeTicks timebase, 660 void Surface::OnUpdateVSyncParameters(base::TimeTicks timebase,
691 base::TimeDelta interval) { 661 base::TimeDelta interval) {
692 // Use current time if platform doesn't provide an accurate timebase. 662 // Use current time if platform doesn't provide an accurate timebase.
693 if (timebase.is_null()) 663 if (timebase.is_null())
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 frame.resource_list.push_back(current_resource_); 849 frame.resource_list.push_back(current_resource_);
880 } 850 }
881 } else { 851 } else {
882 cc::SolidColorDrawQuad* solid_quad = 852 cc::SolidColorDrawQuad* solid_quad =
883 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); 853 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>();
884 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false); 854 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false);
885 } 855 }
886 856
887 frame.render_pass_list.push_back(std::move(render_pass)); 857 frame.render_pass_list.push_back(std::move(render_pass));
888 compositor_frame_sink_holder_->GetCompositorFrameSink() 858 compositor_frame_sink_holder_->GetCompositorFrameSink()
889 ->SubmitCompositorFrame(local_surface_id_, std::move(frame)); 859 ->SubmitCompositorFrame(std::move(frame));
890 } 860 }
891 861
892 } // namespace exo 862 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698