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