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