Commit ef1cb089 authored by David Reveman's avatar David Reveman Committed by Commit Bot

exo: Cleanup callback handling.

This makes us acquire callbacks before frame submission instead
of at commit time.

This makes us handle callbacks a bit better when a surface is
committed without having a STH.

Bug: 
Test: exo_unittests
Change-Id: I06aa0914d42c4a9dbfab8e291acd7d051b744de0
Reviewed-on: https://chromium-review.googlesource.com/761558Reviewed-by: default avatarPeng Huang <penghuang@chromium.org>
Commit-Queue: David Reveman <reveman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515289}
parent 8a28390a
...@@ -208,12 +208,15 @@ Surface::~Surface() { ...@@ -208,12 +208,15 @@ Surface::~Surface() {
// Call all frame callbacks with a null frame time to indicate that they // Call all frame callbacks with a null frame time to indicate that they
// have been cancelled. // have been cancelled.
for (const auto& frame_callback : pending_frame_callbacks_) frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
for (const auto& frame_callback : frame_callbacks_)
frame_callback.Run(base::TimeTicks()); frame_callback.Run(base::TimeTicks());
// Call all presentation callbacks with a null presentation time to indicate // Call all presentation callbacks with a null presentation time to indicate
// that they have been cancelled. // that they have been cancelled.
for (const auto& presentation_callback : pending_presentation_callbacks_) presentation_callbacks_.splice(presentation_callbacks_.end(),
pending_presentation_callbacks_);
for (const auto& presentation_callback : presentation_callbacks_)
presentation_callback.Run(base::TimeTicks(), base::TimeDelta(), 0); presentation_callback.Run(base::TimeTicks(), base::TimeDelta(), 0);
WMHelper::GetInstance()->ResetDragDropDelegate(window_.get()); WMHelper::GetInstance()->ResetDragDropDelegate(window_.get());
...@@ -435,13 +438,10 @@ void Surface::Commit() { ...@@ -435,13 +438,10 @@ void Surface::Commit() {
if (delegate_) if (delegate_)
delegate_->OnSurfaceCommit(); delegate_->OnSurfaceCommit();
else else
CommitSurfaceHierarchy(nullptr, nullptr, false); CommitSurfaceHierarchy(false);
} }
void Surface::CommitSurfaceHierarchy( void Surface::CommitSurfaceHierarchy(bool synchronized) {
std::list<FrameCallback>* frame_callbacks,
std::list<PresentationCallback>* presentation_callbacks,
bool synchronized) {
if (needs_commit_surface_ && (synchronized || !IsSynchronized())) { if (needs_commit_surface_ && (synchronized || !IsSynchronized())) {
needs_commit_surface_ = false; needs_commit_surface_ = false;
synchronized = true; synchronized = true;
...@@ -489,14 +489,13 @@ void Surface::CommitSurfaceHierarchy( ...@@ -489,14 +489,13 @@ void Surface::CommitSurfaceHierarchy(
if (needs_update_buffer_transform) if (needs_update_buffer_transform)
UpdateBufferTransform(); UpdateBufferTransform();
// Move pending frame callbacks to the end of frame_callbacks. // Move pending frame callbacks to the end of |frame_callbacks_|.
if (frame_callbacks) frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
frame_callbacks->splice(frame_callbacks->end(), pending_frame_callbacks_);
// Move pending presentation callbacks to the end of presentation_callbacks. // Move pending presentation callbacks to the end of
if (presentation_callbacks) // |presentation_callbacks_|.
presentation_callbacks->splice(presentation_callbacks->end(), presentation_callbacks_.splice(presentation_callbacks_.end(),
pending_presentation_callbacks_); pending_presentation_callbacks_);
UpdateContentSize(); UpdateContentSize();
...@@ -537,21 +536,34 @@ void Surface::CommitSurfaceHierarchy( ...@@ -537,21 +536,34 @@ void Surface::CommitSurfaceHierarchy(
surface_hierarchy_content_bounds_ = gfx::Rect(content_size_); surface_hierarchy_content_bounds_ = gfx::Rect(content_size_);
// The top most sub-surface is at the front of the RenderPass's quad_list,
// so we need composite sub-surface in reversed order.
for (const auto& sub_surface_entry : base::Reversed(sub_surfaces_)) { for (const auto& sub_surface_entry : base::Reversed(sub_surfaces_)) {
auto* sub_surface = sub_surface_entry.first; auto* sub_surface = sub_surface_entry.first;
gfx::Point origin = sub_surface_entry.second; gfx::Point origin = sub_surface_entry.second;
// Synchronously commit all pending state of the sub-surface and its // Synchronously commit all pending state of the sub-surface and its
// descendants. // descendants.
sub_surface->CommitSurfaceHierarchy(frame_callbacks, presentation_callbacks, sub_surface->CommitSurfaceHierarchy(synchronized);
synchronized);
surface_hierarchy_content_bounds_.Union( surface_hierarchy_content_bounds_.Union(
sub_surface->surface_hierarchy_content_bounds() + sub_surface->surface_hierarchy_content_bounds() +
origin.OffsetFromOrigin()); origin.OffsetFromOrigin());
} }
} }
void Surface::AppendSurfaceHierarchyCallbacks(
std::list<FrameCallback>* frame_callbacks,
std::list<PresentationCallback>* presentation_callbacks) {
// Move frame callbacks to the end of |frame_callbacks|.
frame_callbacks->splice(frame_callbacks->end(), frame_callbacks_);
// Move presentation callbacks to the end of |presentation_callbacks|.
presentation_callbacks->splice(presentation_callbacks->end(),
presentation_callbacks_);
for (const auto& sub_surface_entry : base::Reversed(sub_surfaces_)) {
auto* sub_surface = sub_surface_entry.first;
sub_surface->AppendSurfaceHierarchyCallbacks(frame_callbacks,
presentation_callbacks);
}
}
void Surface::AppendSurfaceHierarchyContentsToFrame( void Surface::AppendSurfaceHierarchyContentsToFrame(
const gfx::Point& origin, const gfx::Point& origin,
float device_scale_factor, float device_scale_factor,
......
...@@ -149,11 +149,15 @@ class Surface final : public ui::PropertyHandler { ...@@ -149,11 +149,15 @@ class Surface final : public ui::PropertyHandler {
// recursively calling CommitSurfaceHierarchy() for each sub-surface. // recursively calling CommitSurfaceHierarchy() for each sub-surface.
// If |synchronized| is set to false, then synchronized surfaces should not // If |synchronized| is set to false, then synchronized surfaces should not
// commit pending state. // commit pending state.
void CommitSurfaceHierarchy( void CommitSurfaceHierarchy(bool synchronized);
// This will append current callbacks for surface and its descendants to
// |frame_callbacks| and |presentation_callbacks|.
void AppendSurfaceHierarchyCallbacks(
std::list<FrameCallback>* frame_callbacks, std::list<FrameCallback>* frame_callbacks,
std::list<PresentationCallback>* presentation_callbacks, std::list<PresentationCallback>* presentation_callbacks);
bool synchronized);
// This will append contents for surface and its descendants to frame.
void AppendSurfaceHierarchyContentsToFrame( void AppendSurfaceHierarchyContentsToFrame(
const gfx::Point& origin, const gfx::Point& origin,
float device_scale_factor, float device_scale_factor,
...@@ -326,6 +330,7 @@ class Surface final : public ui::PropertyHandler { ...@@ -326,6 +330,7 @@ class Surface final : public ui::PropertyHandler {
// |active_frame_callbacks_| when the effect of the Commit() is scheduled to // |active_frame_callbacks_| when the effect of the Commit() is scheduled to
// be drawn. They fire at the first begin frame notification after this. // be drawn. They fire at the first begin frame notification after this.
std::list<FrameCallback> pending_frame_callbacks_; std::list<FrameCallback> pending_frame_callbacks_;
std::list<FrameCallback> frame_callbacks_;
// These lists contains the callbacks to notify the client when surface // These lists contains the callbacks to notify the client when surface
// contents have been presented. These callbacks move to // contents have been presented. These callbacks move to
...@@ -335,6 +340,7 @@ class Surface final : public ui::PropertyHandler { ...@@ -335,6 +340,7 @@ class Surface final : public ui::PropertyHandler {
// after receiving VSync parameters update for the previous frame. They fire // after receiving VSync parameters update for the previous frame. They fire
// at the next VSync parameters update after that. // at the next VSync parameters update after that.
std::list<PresentationCallback> pending_presentation_callbacks_; std::list<PresentationCallback> pending_presentation_callbacks_;
std::list<PresentationCallback> presentation_callbacks_;
// This is the state that has yet to be committed. // This is the state that has yet to be committed.
State pending_state_; State pending_state_;
......
...@@ -211,8 +211,7 @@ void SurfaceTreeHost::UpdateNeedsBeginFrame() { ...@@ -211,8 +211,7 @@ void SurfaceTreeHost::UpdateNeedsBeginFrame() {
void SurfaceTreeHost::OnSurfaceCommit() { void SurfaceTreeHost::OnSurfaceCommit() {
DCHECK(presentation_callbacks_.empty()); DCHECK(presentation_callbacks_.empty());
root_surface_->CommitSurfaceHierarchy(&frame_callbacks_, root_surface_->CommitSurfaceHierarchy(false);
&presentation_callbacks_, false);
UpdateHostWindowBounds(); UpdateHostWindowBounds();
} }
...@@ -272,6 +271,8 @@ void SurfaceTreeHost::SubmitCompositorFrame() { ...@@ -272,6 +271,8 @@ void SurfaceTreeHost::SubmitCompositorFrame() {
current_begin_frame_ack_.has_damage = true; current_begin_frame_ack_.has_damage = true;
} }
frame.metadata.begin_frame_ack = current_begin_frame_ack_; frame.metadata.begin_frame_ack = current_begin_frame_ack_;
root_surface_->AppendSurfaceHierarchyCallbacks(&frame_callbacks_,
&presentation_callbacks_);
if (!presentation_callbacks_.empty()) { if (!presentation_callbacks_.empty()) {
// If overflow happens, we increase it again. // If overflow happens, we increase it again.
if (!++presentation_token_) if (!++presentation_token_)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment