Commit 85c2ff9b authored by jbates@chromium.org's avatar jbates@chromium.org

Plumb vsync info from AcceleratedPresenter to RenderWidgetHostImpl

BUG=137792


Review URL: https://chromiumcodereview.appspot.com/10820041

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151514 0039d316-1c4b-4281-b951-d872f2087c98
parent 9af3b284
...@@ -127,13 +127,16 @@ void AcceleratedSurfaceBuffersSwappedCompletedForGPU(int host_id, ...@@ -127,13 +127,16 @@ void AcceleratedSurfaceBuffersSwappedCompletedForGPU(int host_id,
// This sends a ViewMsg_SwapBuffers_ACK directly to the renderer process // This sends a ViewMsg_SwapBuffers_ACK directly to the renderer process
// (RenderWidget). This path is currently not used with the threaded compositor. // (RenderWidget). This path is currently not used with the threaded compositor.
void AcceleratedSurfaceBuffersSwappedCompletedForRenderer(int surface_id) { void AcceleratedSurfaceBuffersSwappedCompletedForRenderer(
int surface_id,
base::TimeTicks timebase,
base::TimeDelta interval) {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, BrowserThread::UI,
FROM_HERE, FROM_HERE,
base::Bind(&AcceleratedSurfaceBuffersSwappedCompletedForRenderer, base::Bind(&AcceleratedSurfaceBuffersSwappedCompletedForRenderer,
surface_id)); surface_id, timebase, interval));
return; return;
} }
...@@ -150,14 +153,19 @@ void AcceleratedSurfaceBuffersSwappedCompletedForRenderer(int surface_id) { ...@@ -150,14 +153,19 @@ void AcceleratedSurfaceBuffersSwappedCompletedForRenderer(int surface_id) {
if (!rwh) if (!rwh)
return; return;
RenderWidgetHostImpl::From(rwh)->AcknowledgeSwapBuffersToRenderer(); RenderWidgetHostImpl::From(rwh)->AcknowledgeSwapBuffersToRenderer();
if (interval != base::TimeDelta())
RenderWidgetHostImpl::From(rwh)->UpdateVSyncParameters(timebase, interval);
} }
void AcceleratedSurfaceBuffersSwappedCompleted(int host_id, void AcceleratedSurfaceBuffersSwappedCompleted(int host_id,
int route_id, int route_id,
int surface_id, int surface_id,
bool alive) { bool alive,
base::TimeTicks timebase,
base::TimeDelta interval) {
AcceleratedSurfaceBuffersSwappedCompletedForGPU(host_id, route_id, alive); AcceleratedSurfaceBuffersSwappedCompletedForGPU(host_id, route_id, alive);
AcceleratedSurfaceBuffersSwappedCompletedForRenderer(surface_id); AcceleratedSurfaceBuffersSwappedCompletedForRenderer(surface_id, timebase,
interval);
} }
} // anonymous namespace } // anonymous namespace
...@@ -648,10 +656,8 @@ void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( ...@@ -648,10 +656,8 @@ void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped(
base::ScopedClosureRunner scoped_completion_runner( base::ScopedClosureRunner scoped_completion_runner(
base::Bind(&AcceleratedSurfaceBuffersSwappedCompleted, base::Bind(&AcceleratedSurfaceBuffersSwappedCompleted,
host_id_, host_id_, params.route_id, params.surface_id,
params.route_id, true, base::TimeTicks(), base::TimeDelta()));
params.surface_id,
true));
gfx::PluginWindowHandle handle = gfx::PluginWindowHandle handle =
GpuSurfaceTracker::Get()->GetSurfaceWindowHandle(params.surface_id); GpuSurfaceTracker::Get()->GetSurfaceWindowHandle(params.surface_id);
......
...@@ -432,11 +432,11 @@ scoped_refptr<AcceleratedPresenter> AcceleratedPresenter::GetForWindow( ...@@ -432,11 +432,11 @@ scoped_refptr<AcceleratedPresenter> AcceleratedPresenter::GetForWindow(
void AcceleratedPresenter::AsyncPresentAndAcknowledge( void AcceleratedPresenter::AsyncPresentAndAcknowledge(
const gfx::Size& size, const gfx::Size& size,
int64 surface_handle, int64 surface_handle,
const base::Callback<void(bool)>& completion_task) { const CompletionTask& completion_task) {
if (!surface_handle) { if (!surface_handle) {
TRACE_EVENT1("gpu", "EarlyOut_ZeroSurfaceHandle", TRACE_EVENT1("gpu", "EarlyOut_ZeroSurfaceHandle",
"surface_handle", surface_handle); "surface_handle", surface_handle);
completion_task.Run(true); completion_task.Run(true, base::TimeTicks(), base::TimeDelta());
return; return;
} }
...@@ -675,7 +675,7 @@ static base::TimeDelta GetSwapDelay() { ...@@ -675,7 +675,7 @@ static base::TimeDelta GetSwapDelay() {
void AcceleratedPresenter::DoPresentAndAcknowledge( void AcceleratedPresenter::DoPresentAndAcknowledge(
const gfx::Size& size, const gfx::Size& size,
int64 surface_handle, int64 surface_handle,
const base::Callback<void(bool)>& completion_task) { const CompletionTask& completion_task) {
TRACE_EVENT1( TRACE_EVENT1(
"gpu", "DoPresentAndAcknowledge", "surface_handle", surface_handle); "gpu", "DoPresentAndAcknowledge", "surface_handle", surface_handle);
...@@ -688,13 +688,13 @@ void AcceleratedPresenter::DoPresentAndAcknowledge( ...@@ -688,13 +688,13 @@ void AcceleratedPresenter::DoPresentAndAcknowledge(
if (!present_thread_->device()) { if (!present_thread_->device()) {
if (!completion_task.is_null()) if (!completion_task.is_null())
completion_task.Run(false); completion_task.Run(false, base::TimeTicks(), base::TimeDelta());
return; return;
} }
// Ensure the task is always run and while the lock is taken. // Ensure the task is always run and while the lock is taken.
base::ScopedClosureRunner scoped_completion_runner(base::Bind(completion_task, base::ScopedClosureRunner scoped_completion_runner(
true)); base::Bind(completion_task, true, base::TimeTicks(), base::TimeDelta()));
// If invalidated, do nothing, the window is gone. // If invalidated, do nothing, the window is gone.
if (!window_) if (!window_)
...@@ -849,6 +849,24 @@ void AcceleratedPresenter::DoPresentAndAcknowledge( ...@@ -849,6 +849,24 @@ void AcceleratedPresenter::DoPresentAndAcknowledge(
} }
} }
{
TRACE_EVENT0("gpu", "GetPresentationStats");
base::TimeTicks timebase;
base::TimeDelta interval;
uint32 numerator = 0, denominator = 0;
if (GetPresentationStats(&timebase, &numerator, &denominator) &&
numerator > 0 && denominator > 0) {
int64 interval_micros =
static_cast<int64>(1000000 * numerator) / denominator;
interval = base::TimeDelta::FromMicroseconds(interval_micros);
}
scoped_completion_runner.Release();
completion_task.Run(true, timebase, interval);
TRACE_EVENT2("gpu", "GetPresentationStats",
"timebase", timebase.ToInternalValue(),
"interval", interval.ToInternalValue());
}
hidden_ = false; hidden_ = false;
} }
...@@ -862,7 +880,7 @@ void AcceleratedPresenter::DoReleaseSurface() { ...@@ -862,7 +880,7 @@ void AcceleratedPresenter::DoReleaseSurface() {
source_texture_.Release(); source_texture_.Release();
} }
void AcceleratedPresenter::GetPresentationStats(base::TimeTicks* timebase, bool AcceleratedPresenter::GetPresentationStats(base::TimeTicks* timebase,
uint32* interval_numerator, uint32* interval_numerator,
uint32* interval_denominator) { uint32* interval_denominator) {
lock_.AssertAcquired(); lock_.AssertAcquired();
...@@ -871,13 +889,18 @@ void AcceleratedPresenter::GetPresentationStats(base::TimeTicks* timebase, ...@@ -871,13 +889,18 @@ void AcceleratedPresenter::GetPresentationStats(base::TimeTicks* timebase,
timing_info.cbSize = sizeof(timing_info); timing_info.cbSize = sizeof(timing_info);
HRESULT result = DwmGetCompositionTimingInfo(window_, &timing_info); HRESULT result = DwmGetCompositionTimingInfo(window_, &timing_info);
if (result != S_OK) if (result != S_OK)
return; return false;
*timebase = base::TimeTicks::FromQPCValue( *timebase = base::TimeTicks::FromQPCValue(
static_cast<LONGLONG>(timing_info.qpcVBlank)); static_cast<LONGLONG>(timing_info.qpcVBlank));
// Offset from QPC-space to TimeTicks::Now-space.
*timebase += (base::TimeTicks::Now() - base::TimeTicks::HighResNow());
// Swap the numerator/denominator to convert frequency to period. // Swap the numerator/denominator to convert frequency to period.
*interval_numerator = timing_info.rateRefresh.uiDenominator; *interval_numerator = timing_info.rateRefresh.uiDenominator;
*interval_denominator = timing_info.rateRefresh.uiNumerator; *interval_denominator = timing_info.rateRefresh.uiNumerator;
return true;
} }
AcceleratedSurface::AcceleratedSurface(gfx::NativeWindow window) AcceleratedSurface::AcceleratedSurface(gfx::NativeWindow window)
......
...@@ -25,7 +25,9 @@ class Rect; ...@@ -25,7 +25,9 @@ class Rect;
class SURFACE_EXPORT AcceleratedPresenter class SURFACE_EXPORT AcceleratedPresenter
: public base::RefCountedThreadSafe<AcceleratedPresenter> { : public base::RefCountedThreadSafe<AcceleratedPresenter> {
public: public:
typedef base::Callback<void(bool)> CompletionTaskl; typedef base::Callback<void(bool,
base::TimeTicks,
base::TimeDelta)> CompletionTask;
explicit AcceleratedPresenter(gfx::NativeWindow window); explicit AcceleratedPresenter(gfx::NativeWindow window);
...@@ -42,7 +44,7 @@ class SURFACE_EXPORT AcceleratedPresenter ...@@ -42,7 +44,7 @@ class SURFACE_EXPORT AcceleratedPresenter
void AsyncPresentAndAcknowledge( void AsyncPresentAndAcknowledge(
const gfx::Size& size, const gfx::Size& size,
int64 surface_handle, int64 surface_handle,
const base::Callback<void(bool)>& completion_task); const CompletionTask& completion_task);
// Schedule the presenter to free all its resources. This can be called on any // Schedule the presenter to free all its resources. This can be called on any
// thread. // thread.
...@@ -71,7 +73,7 @@ class SURFACE_EXPORT AcceleratedPresenter ...@@ -71,7 +73,7 @@ class SURFACE_EXPORT AcceleratedPresenter
void DoPresentAndAcknowledge( void DoPresentAndAcknowledge(
const gfx::Size& size, const gfx::Size& size,
int64 surface_handle, int64 surface_handle,
const base::Callback<void(bool)>& completion_task); const CompletionTask& completion_task);
void DoSuspend(); void DoSuspend();
void DoPresent(HDC dc, bool* presented); void DoPresent(HDC dc, bool* presented);
bool DoRealPresent(HDC dc); bool DoRealPresent(HDC dc);
...@@ -85,7 +87,8 @@ class SURFACE_EXPORT AcceleratedPresenter ...@@ -85,7 +87,8 @@ class SURFACE_EXPORT AcceleratedPresenter
// and an interval_denominator of 60000, resulting in an interval of // and an interval_denominator of 60000, resulting in an interval of
// 1001/60000 ~= .016683 seconds // 1001/60000 ~= .016683 seconds
// Note: This function assumes lock_ is acquired. // Note: This function assumes lock_ is acquired.
void GetPresentationStats(base::TimeTicks* timebase, // Returns true on success.
bool GetPresentationStats(base::TimeTicks* timebase,
uint32* interval_numerator, uint32* interval_numerator,
uint32* interval_denominator); uint32* interval_denominator);
......
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