Commit 569a70b0 authored by alexst's avatar alexst Committed by Commit bot

Fix latency calculation when multiple rendered buffers are in flight.

This is particularly important on ChromeOS with freon stack.
SwapBuffers ack is sent when the buffers actually swapped, not when the
call to swap them was made. This changed the scheduler behavior and delayed
beginning of the next frame, so to regain it we allowed multiple in flight
frames. The effect this has on latency info is that two frames arriving in
rapid succession would override incorrect latency info making it look like
things ultimately happened earlier than they did.

This patch associates latency info with a particular frame's callback
thus avoiding it being overridden.

BUG=485302

Review URL: https://codereview.chromium.org/1128323006

Cr-Commit-Position: refs/heads/master@{#329936}
parent 325c9f6c
......@@ -202,9 +202,12 @@ bool PassThroughImageTransportSurface::SwapBuffers() {
// of this class. Callback will not be called once the instance of this class
// is destroyed. However, this also means that the callback can be run on
// the calling thread only.
return gfx::GLSurfaceAdapter::SwapBuffersAsync(
base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack,
weak_ptr_factory_.GetWeakPtr()));
std::vector<ui::LatencyInfo>* latency_info_ptr =
new std::vector<ui::LatencyInfo>();
latency_info_ptr->swap(latency_info_);
return gfx::GLSurfaceAdapter::SwapBuffersAsync(base::Bind(
&PassThroughImageTransportSurface::SwapBuffersCallBack,
weak_ptr_factory_.GetWeakPtr(), base::Owned(latency_info_ptr)));
}
bool PassThroughImageTransportSurface::PostSubBuffer(
......@@ -221,21 +224,26 @@ bool PassThroughImageTransportSurface::PostSubBuffer(
// of this class. Callback will not be called once the instance of this class
// is destroyed. However, this also means that the callback can be run on
// the calling thread only.
return gfx::GLSurfaceAdapter::PostSubBufferAsync(x, y, width, height,
std::vector<ui::LatencyInfo>* latency_info_ptr =
new std::vector<ui::LatencyInfo>();
latency_info_ptr->swap(latency_info_);
return gfx::GLSurfaceAdapter::PostSubBufferAsync(
x, y, width, height,
base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack,
weak_ptr_factory_.GetWeakPtr()));
weak_ptr_factory_.GetWeakPtr(),
base::Owned(latency_info_ptr)));
}
void PassThroughImageTransportSurface::SwapBuffersCallBack() {
void PassThroughImageTransportSurface::SwapBuffersCallBack(
std::vector<ui::LatencyInfo>* latency_info_ptr) {
base::TimeTicks swap_ack_time = base::TimeTicks::Now();
for (auto& latency : latency_info_) {
for (auto& latency : *latency_info_ptr) {
latency.AddLatencyNumberWithTimestamp(
ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0,
swap_ack_time, 1);
}
helper_->stub()->SendSwapBuffersCompleted(latency_info_);
latency_info_.clear();
helper_->stub()->SendSwapBuffersCompleted(*latency_info_ptr);
}
bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) {
......
......@@ -196,7 +196,7 @@ class PassThroughImageTransportSurface
// If updated vsync parameters can be determined, send this information to
// the browser.
virtual void SendVSyncUpdateIfAvailable();
void SwapBuffersCallBack();
void SwapBuffersCallBack(std::vector<ui::LatencyInfo>* latency_info_ptr);
ImageTransportHelper* GetHelper() { return helper_.get(); }
......
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