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

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
« no previous file with comments | « components/exo/surface.h ('k') | ui/aura/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 compositor_frame_sink_holder_ = base::MakeUnique<CompositorFrameSinkHolder>(
179 this, window_->CreateCompositorFrameSink());
191 } 180 }
192 181
193 Surface::~Surface() { 182 Surface::~Surface() {
194 aura::Env::GetInstance()->context_factory()->RemoveObserver(this); 183 aura::Env::GetInstance()->context_factory()->RemoveObserver(this);
195 for (SurfaceObserver& observer : observers_) 184 for (SurfaceObserver& observer : observers_)
196 observer.OnSurfaceDestroying(this); 185 observer.OnSurfaceDestroying(this);
197 186
198 window_->RemoveObserver(this); 187 window_->RemoveObserver(this);
199 if (window_->layer()->GetCompositor()) 188 if (window_->layer()->GetCompositor())
200 window_->layer()->GetCompositor()->vsync_manager()->RemoveObserver(this); 189 window_->layer()->GetCompositor()->vsync_manager()->RemoveObserver(this);
(...skipping 10 matching lines...) Expand all
211 presentation_callbacks_.splice(presentation_callbacks_.end(), 200 presentation_callbacks_.splice(presentation_callbacks_.end(),
212 pending_presentation_callbacks_); 201 pending_presentation_callbacks_);
213 swapping_presentation_callbacks_.splice( 202 swapping_presentation_callbacks_.splice(
214 swapping_presentation_callbacks_.end(), presentation_callbacks_); 203 swapping_presentation_callbacks_.end(), presentation_callbacks_);
215 swapped_presentation_callbacks_.splice(swapped_presentation_callbacks_.end(), 204 swapped_presentation_callbacks_.splice(swapped_presentation_callbacks_.end(),
216 swapping_presentation_callbacks_); 205 swapping_presentation_callbacks_);
217 // Call all presentation callbacks with a null presentation time to indicate 206 // Call all presentation callbacks with a null presentation time to indicate
218 // that they have been cancelled. 207 // that they have been cancelled.
219 for (const auto& presentation_callback : swapped_presentation_callbacks_) 208 for (const auto& presentation_callback : swapped_presentation_callbacks_)
220 presentation_callback.Run(base::TimeTicks(), base::TimeDelta()); 209 presentation_callback.Run(base::TimeTicks(), base::TimeDelta());
221
222 compositor_frame_sink_holder_->GetCompositorFrameSink()->EvictFrame();
223 } 210 }
224 211
225 // static 212 // static
226 Surface* Surface::AsSurface(const aura::Window* window) { 213 Surface* Surface::AsSurface(const aura::Window* window) {
227 return window->GetProperty(kSurfaceKey); 214 return window->GetProperty(kSurfaceKey);
228 } 215 }
229 216
230 cc::SurfaceId Surface::GetSurfaceId() const { 217 cc::SurfaceId Surface::GetSurfaceId() const {
231 return cc::SurfaceId(frame_sink_id_, local_surface_id_); 218 return window_->GetSurfaceId();
232 } 219 }
233 220
234 void Surface::Attach(Buffer* buffer) { 221 void Surface::Attach(Buffer* buffer) {
235 TRACE_EVENT1("exo", "Surface::Attach", "buffer", 222 TRACE_EVENT1("exo", "Surface::Attach", "buffer",
236 buffer ? buffer->GetSize().ToString() : "null"); 223 buffer ? buffer->GetSize().ToString() : "null");
237 224
238 has_pending_contents_ = true; 225 has_pending_contents_ = true;
239 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>()); 226 pending_buffer_.Reset(buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>());
240 } 227 }
241 228
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 444
458 // We update contents if Attach() has been called since last commit. 445 // We update contents if Attach() has been called since last commit.
459 if (has_pending_contents_) { 446 if (has_pending_contents_) {
460 has_pending_contents_ = false; 447 has_pending_contents_ = false;
461 448
462 current_buffer_ = std::move(pending_buffer_); 449 current_buffer_ = std::move(pending_buffer_);
463 450
464 UpdateResource(true); 451 UpdateResource(true);
465 } 452 }
466 453
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_. 454 // Move pending frame callbacks to the end of frame_callbacks_.
474 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); 455 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
475 456
476 // Move pending presentation callbacks to the end of presentation_callbacks_. 457 // Move pending presentation callbacks to the end of presentation_callbacks_.
477 presentation_callbacks_.splice(presentation_callbacks_.end(), 458 presentation_callbacks_.splice(presentation_callbacks_.end(),
478 pending_presentation_callbacks_); 459 pending_presentation_callbacks_);
479 460
480 UpdateSurface(false); 461 UpdateSurface(false);
481 462
482 if (old_local_surface_id != local_surface_id_) { 463 if (needs_commit_to_new_surface_) {
483 float contents_surface_to_layer_scale = 1.0; 464 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( 465 window_->layer()->SetFillsBoundsOpaquely(
495 !current_resource_has_alpha_ || 466 !current_resource_has_alpha_ ||
496 state_.blend_mode == SkBlendMode::kSrc || 467 state_.blend_mode == SkBlendMode::kSrc ||
497 state_.opaque_region.contains( 468 state_.opaque_region.contains(
498 gfx::RectToSkIRect(gfx::Rect(content_size_)))); 469 gfx::RectToSkIRect(gfx::Rect(content_size_))));
499 } 470 }
500 471
501 // Reset damage. 472 // Reset damage.
502 pending_damage_.setEmpty(); 473 pending_damage_.setEmpty();
503
504 DCHECK(!current_resource_.id || 474 DCHECK(!current_resource_.id ||
505 compositor_frame_sink_holder_->HasReleaseCallbackForResource( 475 compositor_frame_sink_holder_->HasReleaseCallbackForResource(
506 current_resource_.id)); 476 current_resource_.id));
507 477
508 // Synchronize window hierarchy. This will position and update the stacking 478 // Synchronize window hierarchy. This will position and update the stacking
509 // order of all sub-surfaces after committing all pending state of sub-surface 479 // order of all sub-surfaces after committing all pending state of sub-surface
510 // descendants. 480 // descendants.
511 aura::Window* stacking_target = nullptr; 481 aura::Window* stacking_target = nullptr;
512 for (auto& sub_surface_entry : pending_sub_surfaces_) { 482 for (auto& sub_surface_entry : pending_sub_surfaces_) {
513 Surface* sub_surface = sub_surface_entry.first; 483 Surface* sub_surface = sub_surface_entry.first;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 626
657 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { 627 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() {
658 if (HasLayerHierarchyChanged()) 628 if (HasLayerHierarchyChanged())
659 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); 629 SetSurfaceHierarchyNeedsCommitToNewSurfaces();
660 } 630 }
661 631
662 //////////////////////////////////////////////////////////////////////////////// 632 ////////////////////////////////////////////////////////////////////////////////
663 // ui::ContextFactoryObserver overrides: 633 // ui::ContextFactoryObserver overrides:
664 634
665 void Surface::OnLostResources() { 635 void Surface::OnLostResources() {
666 if (!local_surface_id_.is_valid()) 636 if (!window_->GetSurfaceId().is_valid())
667 return; 637 return;
668
669 UpdateResource(false); 638 UpdateResource(false);
670 UpdateSurface(true); 639 UpdateSurface(true);
671 } 640 }
672 641
673 //////////////////////////////////////////////////////////////////////////////// 642 ////////////////////////////////////////////////////////////////////////////////
674 // aura::WindowObserver overrides: 643 // aura::WindowObserver overrides:
675 644
676 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { 645 void Surface::OnWindowAddedToRootWindow(aura::Window* window) {
677 window->layer()->GetCompositor()->AddFrameSink(frame_sink_id_);
678 window->layer()->GetCompositor()->vsync_manager()->AddObserver(this); 646 window->layer()->GetCompositor()->vsync_manager()->AddObserver(this);
679 } 647 }
680 648
681 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, 649 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window,
682 aura::Window* new_root) { 650 aura::Window* new_root) {
683 window->layer()->GetCompositor()->RemoveFrameSink(frame_sink_id_);
684 window->layer()->GetCompositor()->vsync_manager()->RemoveObserver(this); 651 window->layer()->GetCompositor()->vsync_manager()->RemoveObserver(this);
685 } 652 }
686 653
687 //////////////////////////////////////////////////////////////////////////////// 654 ////////////////////////////////////////////////////////////////////////////////
688 // ui::CompositorVSyncManager::Observer overrides: 655 // ui::CompositorVSyncManager::Observer overrides:
689 656
690 void Surface::OnUpdateVSyncParameters(base::TimeTicks timebase, 657 void Surface::OnUpdateVSyncParameters(base::TimeTicks timebase,
691 base::TimeDelta interval) { 658 base::TimeDelta interval) {
692 // Use current time if platform doesn't provide an accurate timebase. 659 // Use current time if platform doesn't provide an accurate timebase.
693 if (timebase.is_null()) 660 if (timebase.is_null())
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 frame.resource_list.push_back(current_resource_); 846 frame.resource_list.push_back(current_resource_);
880 } 847 }
881 } else { 848 } else {
882 cc::SolidColorDrawQuad* solid_quad = 849 cc::SolidColorDrawQuad* solid_quad =
883 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); 850 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>();
884 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false); 851 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, false);
885 } 852 }
886 853
887 frame.render_pass_list.push_back(std::move(render_pass)); 854 frame.render_pass_list.push_back(std::move(render_pass));
888 compositor_frame_sink_holder_->GetCompositorFrameSink() 855 compositor_frame_sink_holder_->GetCompositorFrameSink()
889 ->SubmitCompositorFrame(local_surface_id_, std::move(frame)); 856 ->SubmitCompositorFrame(std::move(frame));
890 } 857 }
891 858
892 } // namespace exo 859 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/surface.h ('k') | ui/aura/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698