summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-21 01:26:20 +0000
committerbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-21 01:26:20 +0000
commit3b6085517f7d4f277005f9262ab18c16af0228da (patch)
treeead374a0eec34f53ca63a8312a49728de14dba39
parent39f0d78efeadbfc81432a33a9ac2a1bea3abac1f (diff)
downloadchromium_src-3b6085517f7d4f277005f9262ab18c16af0228da.zip
chromium_src-3b6085517f7d4f277005f9262ab18c16af0228da.tar.gz
chromium_src-3b6085517f7d4f277005f9262ab18c16af0228da.tar.bz2
CrOS: Schedule renderer drawing to hardware vsync.
Before this patch, the renderer scheduled drawing assuming a 60Hz refresh rate at an arbitrary timebase. With this patch, we send a hardware vsync signal to the renderer. The timbase is offset slightly so that the browser UI and renderer do not draw at the same time. BUG=157223 Review URL: https://chromiumcodereview.appspot.com/12218055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183696 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/wm/window_animations.cc7
-rw-r--r--content/browser/renderer_host/image_transport_factory.cc22
-rw-r--r--content/browser/renderer_host/render_widget_host_view_aura.cc11
-rw-r--r--content/browser/renderer_host/render_widget_host_view_aura.h8
-rw-r--r--ui/aura/bench/bench_main.cc8
-rw-r--r--ui/aura/root_window.cc8
-rw-r--r--ui/aura/root_window.h6
-rw-r--r--ui/compositor/compositor.cc10
-rw-r--r--ui/compositor/compositor.h7
-rw-r--r--ui/compositor/compositor_observer.h9
-rw-r--r--ui/compositor/layer_unittest.cc8
11 files changed, 89 insertions, 15 deletions
diff --git a/ash/wm/window_animations.cc b/ash/wm/window_animations.cc
index 2cc12ff..061ce82 100644
--- a/ash/wm/window_animations.cc
+++ b/ash/wm/window_animations.cc
@@ -288,7 +288,8 @@ class CrossFadeObserver : public ui::CompositorObserver,
// ui::CompositorObserver overrides:
virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE {
}
- virtual void OnCompositingStarted(ui::Compositor* compositor) OVERRIDE {
+ virtual void OnCompositingStarted(ui::Compositor* compositor,
+ base::TimeTicks start_time) OVERRIDE {
}
virtual void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE {
}
@@ -299,6 +300,10 @@ class CrossFadeObserver : public ui::CompositorObserver,
virtual void OnCompositingLockStateChanged(
ui::Compositor* compositor) OVERRIDE {
}
+ virtual void OnUpdateVSyncParameters(ui::Compositor* compositor,
+ base::TimeTicks timebase,
+ base::TimeDelta interval) OVERRIDE {
+ }
// aura::WindowObserver overrides:
virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
diff --git a/content/browser/renderer_host/image_transport_factory.cc b/content/browser/renderer_host/image_transport_factory.cc
index f0db826..5b81dbf 100644
--- a/content/browser/renderer_host/image_transport_factory.cc
+++ b/content/browser/renderer_host/image_transport_factory.cc
@@ -284,7 +284,6 @@ class BrowserCompositorOutputSurfaceProxy
DISALLOW_COPY_AND_ASSIGN(BrowserCompositorOutputSurfaceProxy);
};
-
// Adapts a WebGraphicsContext3DCommandBufferImpl into a
// cc::OutputSurface that also handles vsync parameter updates
// arriving from the GPU process.
@@ -292,13 +291,17 @@ class BrowserCompositorOutputSurface
: public cc::OutputSurface,
public base::NonThreadSafe {
public:
- explicit BrowserCompositorOutputSurface(
+ BrowserCompositorOutputSurface(
WebGraphicsContext3DCommandBufferImpl* context,
int surface_id,
- BrowserCompositorOutputSurfaceProxy* output_surface_proxy)
+ BrowserCompositorOutputSurfaceProxy* output_surface_proxy,
+ base::MessageLoopProxy* compositor_message_loop,
+ base::WeakPtr<ui::Compositor> compositor)
: OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(context)),
surface_id_(surface_id),
- output_surface_proxy_(output_surface_proxy) {
+ output_surface_proxy_(output_surface_proxy),
+ compositor_message_loop_(compositor_message_loop),
+ compositor_(compositor) {
DetachFromThread();
}
@@ -325,11 +328,18 @@ class BrowserCompositorOutputSurface
DCHECK(CalledOnValidThread());
DCHECK(client_);
client_->OnVSyncParametersChanged(timebase, interval);
+ compositor_message_loop_->PostTask(
+ FROM_HERE,
+ base::Bind(&ui::Compositor::OnUpdateVSyncParameters,
+ compositor_, timebase, interval));
}
private:
int surface_id_;
scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_;
+
+ scoped_refptr<base::MessageLoopProxy> compositor_message_loop_;
+ base::WeakPtr<ui::Compositor> compositor_;
};
void BrowserCompositorOutputSurfaceProxy::OnUpdateVSyncParameters(
@@ -370,7 +380,9 @@ class GpuProcessTransportFactory
return new BrowserCompositorOutputSurface(
context,
per_compositor_data_[compositor]->surface_id,
- output_surface_proxy_);
+ output_surface_proxy_,
+ base::MessageLoopProxy::current(),
+ compositor->AsWeakPtr());
}
virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE {
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc
index b5b95e8..4477c56 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura.cc
+++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
@@ -2096,7 +2096,8 @@ void RenderWidgetHostViewAura::OnCompositingDidCommit(
}
void RenderWidgetHostViewAura::OnCompositingStarted(
- ui::Compositor* compositor) {
+ ui::Compositor* compositor, base::TimeTicks start_time) {
+ last_draw_ended_ = start_time;
}
void RenderWidgetHostViewAura::OnCompositingEnded(
@@ -2118,6 +2119,14 @@ void RenderWidgetHostViewAura::OnCompositingLockStateChanged(
}
}
+void RenderWidgetHostViewAura::OnUpdateVSyncParameters(
+ ui::Compositor* compositor,
+ base::TimeTicks timebase,
+ base::TimeDelta interval) {
+ if (IsShowing() && !last_draw_ended_.is_null())
+ host_->UpdateVSyncParameters(last_draw_ended_, interval);
+}
+
////////////////////////////////////////////////////////////////////////////////
// RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation:
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.h b/content/browser/renderer_host/render_widget_host_view_aura.h
index 0eae36d..2bca838 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura.h
+++ b/content/browser/renderer_host/render_widget_host_view_aura.h
@@ -275,11 +275,15 @@ class RenderWidgetHostViewAura
// Overridden from ui::CompositorObserver:
virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE;
- virtual void OnCompositingStarted(ui::Compositor* compositor) OVERRIDE;
+ virtual void OnCompositingStarted(ui::Compositor* compositor,
+ base::TimeTicks start_time) OVERRIDE;
virtual void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE;
virtual void OnCompositingAborted(ui::Compositor* compositor) OVERRIDE;
virtual void OnCompositingLockStateChanged(
ui::Compositor* compositor) OVERRIDE;
+ virtual void OnUpdateVSyncParameters(ui::Compositor* compositor,
+ base::TimeTicks timebase,
+ base::TimeDelta interval) OVERRIDE;
// Overridden from ImageTransportFactoryObserver:
virtual void OnLostResources() OVERRIDE;
@@ -522,6 +526,8 @@ class RenderWidgetHostViewAura
PluginWindowMoves plugin_window_moves_;
#endif
+ base::TimeTicks last_draw_ended_;
+
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAura);
};
diff --git a/ui/aura/bench/bench_main.cc b/ui/aura/bench/bench_main.cc
index a0c3d1c..3daedeb 100644
--- a/ui/aura/bench/bench_main.cc
+++ b/ui/aura/bench/bench_main.cc
@@ -95,7 +95,8 @@ class BenchCompositorObserver : public ui::CompositorObserver {
virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE {}
- virtual void OnCompositingStarted(Compositor* compositor) OVERRIDE {}
+ virtual void OnCompositingStarted(Compositor* compositor,
+ base::TimeTicks start_time) OVERRIDE {}
virtual void OnCompositingEnded(Compositor* compositor) OVERRIDE {
if (start_time_.is_null()) {
@@ -121,6 +122,11 @@ class BenchCompositorObserver : public ui::CompositorObserver {
virtual void OnCompositingLockStateChanged(
Compositor* compositor) OVERRIDE {}
+ virtual void OnUpdateVSyncParameters(ui::Compositor* compositor,
+ base::TimeTicks timebase,
+ base::TimeDelta interval) OVERRIDE {
+ }
+
virtual void Draw() {}
int frames() const { return frames_; }
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 4013173..7305ca7 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -476,7 +476,8 @@ void RootWindow::ScheduleDraw() {
void RootWindow::OnCompositingDidCommit(ui::Compositor*) {
}
-void RootWindow::OnCompositingStarted(ui::Compositor*) {
+void RootWindow::OnCompositingStarted(ui::Compositor*,
+ base::TimeTicks start_time) {
}
void RootWindow::OnCompositingEnded(ui::Compositor*) {
@@ -499,6 +500,11 @@ void RootWindow::OnCompositingAborted(ui::Compositor*) {
void RootWindow::OnCompositingLockStateChanged(ui::Compositor*) {
}
+void RootWindow::OnUpdateVSyncParameters(ui::Compositor* compositor,
+ base::TimeTicks timebase,
+ base::TimeDelta interval) {
+}
+
////////////////////////////////////////////////////////////////////////////////
// RootWindow, ui::LayerDelegate implementation:
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index 0a54f1a..6102302 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -244,10 +244,14 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
// Overridden from ui::CompositorObserver:
virtual void OnCompositingDidCommit(ui::Compositor*) OVERRIDE;
- virtual void OnCompositingStarted(ui::Compositor*) OVERRIDE;
+ virtual void OnCompositingStarted(ui::Compositor*,
+ base::TimeTicks start_time) OVERRIDE;
virtual void OnCompositingEnded(ui::Compositor*) OVERRIDE;
virtual void OnCompositingAborted(ui::Compositor*) OVERRIDE;
virtual void OnCompositingLockStateChanged(ui::Compositor*) OVERRIDE;
+ virtual void OnUpdateVSyncParameters(ui::Compositor* compositor,
+ base::TimeTicks timebase,
+ base::TimeDelta interval) OVERRIDE;
// Overridden from ui::LayerDelegate:
virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc
index 923d10d..372a039 100644
--- a/ui/compositor/compositor.cc
+++ b/ui/compositor/compositor.cc
@@ -442,6 +442,13 @@ void Compositor::OnSwapBuffersAborted() {
OnCompositingAborted(this));
}
+void Compositor::OnUpdateVSyncParameters(base::TimeTicks timebase,
+ base::TimeDelta interval) {
+ FOR_EACH_OBSERVER(CompositorObserver,
+ observer_list_,
+ OnUpdateVSyncParameters(this, timebase, interval));
+}
+
void Compositor::willBeginFrame() {
}
@@ -495,9 +502,10 @@ void Compositor::didCommit() {
}
void Compositor::didCommitAndDrawFrame() {
+ base::TimeTicks start_time = base::TimeTicks::Now();
FOR_EACH_OBSERVER(CompositorObserver,
observer_list_,
- OnCompositingStarted(this));
+ OnCompositingStarted(this, start_time));
}
void Compositor::didCompleteSwapBuffers() {
diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h
index 2352be2..5cc806d 100644
--- a/ui/compositor/compositor.h
+++ b/ui/compositor/compositor.h
@@ -9,6 +9,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
+#include "base/time.h"
#include "cc/layer_tree_host_client.h"
#include "ui/compositor/compositor_export.h"
#include "ui/gfx/native_widget_types.h"
@@ -174,7 +175,8 @@ class COMPOSITOR_EXPORT CompositorLock
// appropriately transformed texture for each transformed view in the widget's
// view hierarchy.
class COMPOSITOR_EXPORT Compositor
- : NON_EXPORTED_BASE(public cc::LayerTreeHostClient) {
+ : NON_EXPORTED_BASE(public cc::LayerTreeHostClient),
+ public base::SupportsWeakPtr<Compositor> {
public:
Compositor(CompositorDelegate* delegate,
gfx::AcceleratedWidget widget);
@@ -250,6 +252,9 @@ class COMPOSITOR_EXPORT Compositor
// Signals swap has aborted (e.g. lost context).
void OnSwapBuffersAborted();
+ void OnUpdateVSyncParameters(base::TimeTicks timebase,
+ base::TimeDelta interval);
+
// LayerTreeHostClient implementation.
virtual void willBeginFrame() OVERRIDE;
virtual void didBeginFrame() OVERRIDE;
diff --git a/ui/compositor/compositor_observer.h b/ui/compositor/compositor_observer.h
index 4157453..ec93988 100644
--- a/ui/compositor/compositor_observer.h
+++ b/ui/compositor/compositor_observer.h
@@ -5,6 +5,7 @@
#ifndef UI_COMPOSITOR_COMPOSITOR_OBSERVER_H_
#define UI_COMPOSITOR_COMPOSITOR_OBSERVER_H_
+#include "base/time.h"
#include "ui/compositor/compositor_export.h"
namespace ui {
@@ -25,7 +26,8 @@ class COMPOSITOR_EXPORT CompositorObserver {
// Called when compositing started: it has taken all the layer changes into
// account and has issued the graphics commands.
- virtual void OnCompositingStarted(Compositor* compositor) = 0;
+ virtual void OnCompositingStarted(Compositor* compositor,
+ base::TimeTicks start_time) = 0;
// Called when compositing completes: the present to screen has completed.
virtual void OnCompositingEnded(Compositor* compositor) = 0;
@@ -36,6 +38,11 @@ class COMPOSITOR_EXPORT CompositorObserver {
// Called when the compositor lock state changes.
virtual void OnCompositingLockStateChanged(Compositor* compositor) = 0;
+ // Called when the compositor has received updated VSync parameters.
+ virtual void OnUpdateVSyncParameters(Compositor* compositor,
+ base::TimeTicks timebase,
+ base::TimeDelta interval) = 0;
+
protected:
virtual ~CompositorObserver() {}
};
diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc
index c641e8f..1e75c71 100644
--- a/ui/compositor/layer_unittest.cc
+++ b/ui/compositor/layer_unittest.cc
@@ -277,7 +277,8 @@ class TestCompositorObserver : public CompositorObserver {
virtual void OnCompositingDidCommit(Compositor* compositor) OVERRIDE {
}
- virtual void OnCompositingStarted(Compositor* compositor) OVERRIDE {
+ virtual void OnCompositingStarted(Compositor* compositor,
+ base::TimeTicks start_time) OVERRIDE {
started_ = true;
}
@@ -292,6 +293,11 @@ class TestCompositorObserver : public CompositorObserver {
virtual void OnCompositingLockStateChanged(Compositor* compositor) OVERRIDE {
}
+ virtual void OnUpdateVSyncParameters(Compositor* compositor,
+ base::TimeTicks timebase,
+ base::TimeDelta interval) OVERRIDE {
+ }
+
bool started_;
bool ended_;
bool aborted_;