| 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" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 201 |
| 202 Surface::~Surface() { | 202 Surface::~Surface() { |
| 203 aura::Env::GetInstance()->context_factory()->RemoveObserver(this); | 203 aura::Env::GetInstance()->context_factory()->RemoveObserver(this); |
| 204 for (SurfaceObserver& observer : observers_) | 204 for (SurfaceObserver& observer : observers_) |
| 205 observer.OnSurfaceDestroying(this); | 205 observer.OnSurfaceDestroying(this); |
| 206 | 206 |
| 207 window_->RemoveObserver(this); | 207 window_->RemoveObserver(this); |
| 208 window_->layer()->SetShowSolidColorContent(); | 208 window_->layer()->SetShowSolidColorContent(); |
| 209 | 209 |
| 210 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); | 210 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); |
| 211 compositor_frame_sink_holder_->ActivateFrameCallbacks(&frame_callbacks_); | 211 active_frame_callbacks_.splice(active_frame_callbacks_.end(), |
| 212 compositor_frame_sink_holder_->CancelFrameCallbacks(); | 212 frame_callbacks_); |
| 213 // Call all frame callbacks with a null frame time to indicate that they |
| 214 // have been cancelled. |
| 215 for (const auto& frame_callback : active_frame_callbacks_) |
| 216 frame_callback.Run(base::TimeTicks()); |
| 217 |
| 218 presentation_callbacks_.splice(presentation_callbacks_.end(), |
| 219 pending_presentation_callbacks_); |
| 220 swapping_presentation_callbacks_.splice( |
| 221 swapping_presentation_callbacks_.end(), presentation_callbacks_); |
| 222 swapped_presentation_callbacks_.splice(swapped_presentation_callbacks_.end(), |
| 223 swapping_presentation_callbacks_); |
| 224 // Call all presentation callbacks with a null presentation time to indicate |
| 225 // that they have been cancelled. |
| 226 for (const auto& presentation_callback : swapped_presentation_callbacks_) |
| 227 presentation_callback.Run(base::TimeTicks(), base::TimeDelta()); |
| 213 | 228 |
| 214 compositor_frame_sink_holder_->GetCompositorFrameSink()->EvictFrame(); | 229 compositor_frame_sink_holder_->GetCompositorFrameSink()->EvictFrame(); |
| 215 } | 230 } |
| 216 | 231 |
| 217 // static | 232 // static |
| 218 Surface* Surface::AsSurface(const aura::Window* window) { | 233 Surface* Surface::AsSurface(const aura::Window* window) { |
| 219 return window->GetProperty(kSurfaceKey); | 234 return window->GetProperty(kSurfaceKey); |
| 220 } | 235 } |
| 221 | 236 |
| 222 cc::SurfaceId Surface::GetSurfaceId() const { | 237 cc::SurfaceId Surface::GetSurfaceId() const { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 236 | 251 |
| 237 pending_damage_.op(gfx::RectToSkIRect(damage), SkRegion::kUnion_Op); | 252 pending_damage_.op(gfx::RectToSkIRect(damage), SkRegion::kUnion_Op); |
| 238 } | 253 } |
| 239 | 254 |
| 240 void Surface::RequestFrameCallback(const FrameCallback& callback) { | 255 void Surface::RequestFrameCallback(const FrameCallback& callback) { |
| 241 TRACE_EVENT0("exo", "Surface::RequestFrameCallback"); | 256 TRACE_EVENT0("exo", "Surface::RequestFrameCallback"); |
| 242 | 257 |
| 243 pending_frame_callbacks_.push_back(callback); | 258 pending_frame_callbacks_.push_back(callback); |
| 244 } | 259 } |
| 245 | 260 |
| 261 void Surface::RequestPresentationCallback( |
| 262 const PresentationCallback& callback) { |
| 263 TRACE_EVENT0("exo", "Surface::RequestPresentationCallback"); |
| 264 |
| 265 pending_presentation_callbacks_.push_back(callback); |
| 266 } |
| 267 |
| 246 void Surface::SetOpaqueRegion(const SkRegion& region) { | 268 void Surface::SetOpaqueRegion(const SkRegion& region) { |
| 247 TRACE_EVENT1("exo", "Surface::SetOpaqueRegion", "region", | 269 TRACE_EVENT1("exo", "Surface::SetOpaqueRegion", "region", |
| 248 gfx::SkIRectToRect(region.getBounds()).ToString()); | 270 gfx::SkIRectToRect(region.getBounds()).ToString()); |
| 249 | 271 |
| 250 pending_state_.opaque_region = region; | 272 pending_state_.opaque_region = region; |
| 251 } | 273 } |
| 252 | 274 |
| 253 void Surface::SetInputRegion(const SkRegion& region) { | 275 void Surface::SetInputRegion(const SkRegion& region) { |
| 254 TRACE_EVENT1("exo", "Surface::SetInputRegion", "region", | 276 TRACE_EVENT1("exo", "Surface::SetInputRegion", "region", |
| 255 gfx::SkIRectToRect(region.getBounds()).ToString()); | 277 gfx::SkIRectToRect(region.getBounds()).ToString()); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 // Reset damage. | 485 // Reset damage. |
| 464 pending_damage_.setEmpty(); | 486 pending_damage_.setEmpty(); |
| 465 | 487 |
| 466 DCHECK(!current_resource_.id || | 488 DCHECK(!current_resource_.id || |
| 467 compositor_frame_sink_holder_->HasReleaseCallbackForResource( | 489 compositor_frame_sink_holder_->HasReleaseCallbackForResource( |
| 468 current_resource_.id)); | 490 current_resource_.id)); |
| 469 | 491 |
| 470 // Move pending frame callbacks to the end of frame_callbacks_. | 492 // Move pending frame callbacks to the end of frame_callbacks_. |
| 471 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); | 493 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); |
| 472 | 494 |
| 495 // Move pending presentation callbacks to the end of presentation_callbacks_. |
| 496 presentation_callbacks_.splice(presentation_callbacks_.end(), |
| 497 pending_presentation_callbacks_); |
| 498 |
| 473 // Synchronize window hierarchy. This will position and update the stacking | 499 // Synchronize window hierarchy. This will position and update the stacking |
| 474 // order of all sub-surfaces after committing all pending state of sub-surface | 500 // order of all sub-surfaces after committing all pending state of sub-surface |
| 475 // descendants. | 501 // descendants. |
| 476 aura::Window* stacking_target = nullptr; | 502 aura::Window* stacking_target = nullptr; |
| 477 for (auto& sub_surface_entry : pending_sub_surfaces_) { | 503 for (auto& sub_surface_entry : pending_sub_surfaces_) { |
| 478 Surface* sub_surface = sub_surface_entry.first; | 504 Surface* sub_surface = sub_surface_entry.first; |
| 479 | 505 |
| 480 // Synchronsouly commit all pending state of the sub-surface and its | 506 // Synchronsouly commit all pending state of the sub-surface and its |
| 481 // decendents. | 507 // decendents. |
| 482 if (sub_surface->needs_commit_surface_hierarchy()) | 508 if (sub_surface->needs_commit_surface_hierarchy()) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 } | 589 } |
| 564 | 590 |
| 565 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const { | 591 std::unique_ptr<base::trace_event::TracedValue> Surface::AsTracedValue() const { |
| 566 std::unique_ptr<base::trace_event::TracedValue> value( | 592 std::unique_ptr<base::trace_event::TracedValue> value( |
| 567 new base::trace_event::TracedValue()); | 593 new base::trace_event::TracedValue()); |
| 568 value->SetString("name", window_->layer()->name()); | 594 value->SetString("name", window_->layer()->name()); |
| 569 return value; | 595 return value; |
| 570 } | 596 } |
| 571 | 597 |
| 572 void Surface::WillDraw() { | 598 void Surface::WillDraw() { |
| 573 compositor_frame_sink_holder_->ActivateFrameCallbacks(&frame_callbacks_); | 599 active_frame_callbacks_.splice(active_frame_callbacks_.end(), |
| 600 frame_callbacks_); |
| 601 swapping_presentation_callbacks_.splice( |
| 602 swapping_presentation_callbacks_.end(), presentation_callbacks_); |
| 603 } |
| 604 |
| 605 bool Surface::NeedsBeginFrame() const { |
| 606 return !active_frame_callbacks_.empty(); |
| 607 } |
| 608 |
| 609 void Surface::BeginFrame(base::TimeTicks frame_time) { |
| 610 while (!active_frame_callbacks_.empty()) { |
| 611 active_frame_callbacks_.front().Run(frame_time); |
| 612 active_frame_callbacks_.pop_front(); |
| 613 } |
| 574 } | 614 } |
| 575 | 615 |
| 576 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { | 616 void Surface::CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces() { |
| 577 if (HasLayerHierarchyChanged()) | 617 if (HasLayerHierarchyChanged()) |
| 578 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); | 618 SetSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 579 } | 619 } |
| 580 | 620 |
| 621 //////////////////////////////////////////////////////////////////////////////// |
| 622 // ui::ContextFactoryObserver overrides: |
| 623 |
| 581 void Surface::OnLostResources() { | 624 void Surface::OnLostResources() { |
| 582 if (!local_frame_id_.is_valid()) | 625 if (!local_frame_id_.is_valid()) |
| 583 return; | 626 return; |
| 584 | 627 |
| 585 UpdateResource(false); | 628 UpdateResource(false); |
| 586 UpdateSurface(true); | 629 UpdateSurface(true); |
| 587 } | 630 } |
| 588 | 631 |
| 632 //////////////////////////////////////////////////////////////////////////////// |
| 633 // aura::WindowObserver overrides: |
| 634 |
| 589 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { | 635 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { |
| 590 window->layer()->GetCompositor()->AddFrameSink(frame_sink_id_); | 636 window->layer()->GetCompositor()->AddFrameSink(frame_sink_id_); |
| 637 window->layer()->GetCompositor()->vsync_manager()->AddObserver(this); |
| 591 } | 638 } |
| 592 | 639 |
| 593 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, | 640 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, |
| 594 aura::Window* new_root) { | 641 aura::Window* new_root) { |
| 595 window->layer()->GetCompositor()->RemoveFrameSink(frame_sink_id_); | 642 window->layer()->GetCompositor()->RemoveFrameSink(frame_sink_id_); |
| 643 window->layer()->GetCompositor()->vsync_manager()->RemoveObserver(this); |
| 596 } | 644 } |
| 597 | 645 |
| 646 //////////////////////////////////////////////////////////////////////////////// |
| 647 // ui::CompositorVSyncManager::Observer overrides: |
| 648 |
| 649 void Surface::OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 650 base::TimeDelta interval) { |
| 651 // Use current time if platform doesn't provide an accurate timebase. |
| 652 if (timebase.is_null()) |
| 653 timebase = base::TimeTicks::Now(); |
| 654 |
| 655 while (!swapped_presentation_callbacks_.empty()) { |
| 656 swapped_presentation_callbacks_.front().Run(timebase, interval); |
| 657 swapped_presentation_callbacks_.pop_front(); |
| 658 } |
| 659 |
| 660 // VSync parameters updates are generated at the start of a new swap. Move |
| 661 // the swapping presentation callbacks to swapped callbacks so they fire |
| 662 // at the next VSync parameters update as that will contain the presentation |
| 663 // time for the previous frame. |
| 664 swapped_presentation_callbacks_.splice(swapped_presentation_callbacks_.end(), |
| 665 swapping_presentation_callbacks_); |
| 666 } |
| 667 |
| 668 //////////////////////////////////////////////////////////////////////////////// |
| 669 // Buffer, private: |
| 670 |
| 598 Surface::State::State() : input_region(SkIRect::MakeLargest()) {} | 671 Surface::State::State() : input_region(SkIRect::MakeLargest()) {} |
| 599 | 672 |
| 600 Surface::State::~State() = default; | 673 Surface::State::~State() = default; |
| 601 | 674 |
| 602 bool Surface::State::operator==(const State& other) { | 675 bool Surface::State::operator==(const State& other) { |
| 603 return (other.crop == crop && alpha == other.alpha && | 676 return (other.crop == crop && alpha == other.alpha && |
| 604 other.blend_mode == blend_mode && other.viewport == viewport && | 677 other.blend_mode == blend_mode && other.viewport == viewport && |
| 605 other.opaque_region == opaque_region && | 678 other.opaque_region == opaque_region && |
| 606 other.buffer_scale == buffer_scale && | 679 other.buffer_scale == buffer_scale && |
| 607 other.input_region == input_region); | 680 other.input_region == input_region); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 | 868 |
| 796 int64_t Surface::GetPropertyInternal(const void* key, | 869 int64_t Surface::GetPropertyInternal(const void* key, |
| 797 int64_t default_value) const { | 870 int64_t default_value) const { |
| 798 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); | 871 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); |
| 799 if (iter == prop_map_.end()) | 872 if (iter == prop_map_.end()) |
| 800 return default_value; | 873 return default_value; |
| 801 return iter->second.value; | 874 return iter->second.value; |
| 802 } | 875 } |
| 803 | 876 |
| 804 } // namespace exo | 877 } // namespace exo |
| OLD | NEW |