diff options
author | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-06 19:43:07 +0000 |
---|---|---|
committer | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-06 19:43:07 +0000 |
commit | ccc1722eae2c4f93e519007dbfd5c78ce73c6d71 (patch) | |
tree | dc67e891c4e99873da2045f83e09e0e6dc6a1566 /cc/scheduler | |
parent | 394ea33667e9528276ccfc685547f2cafeaee086 (diff) | |
download | chromium_src-ccc1722eae2c4f93e519007dbfd5c78ce73c6d71.zip chromium_src-ccc1722eae2c4f93e519007dbfd5c78ce73c6d71.tar.gz chromium_src-ccc1722eae2c4f93e519007dbfd5c78ce73c6d71.tar.bz2 |
Add cc option to non-lazily disable vsync notification
The option will be used by Android WebView using synchronous compositor
which requires this behavior that conflicts with other platforms.
BUG=
Review URL: https://chromiumcodereview.appspot.com/14898002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198510 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/scheduler')
-rw-r--r-- | cc/scheduler/vsync_time_source.cc | 23 | ||||
-rw-r--r-- | cc/scheduler/vsync_time_source.h | 15 | ||||
-rw-r--r-- | cc/scheduler/vsync_time_source_unittest.cc | 28 |
3 files changed, 55 insertions, 11 deletions
diff --git a/cc/scheduler/vsync_time_source.cc b/cc/scheduler/vsync_time_source.cc index 75314fb..206e2376 100644 --- a/cc/scheduler/vsync_time_source.cc +++ b/cc/scheduler/vsync_time_source.cc @@ -4,18 +4,22 @@ #include "cc/scheduler/vsync_time_source.h" +#include "base/logging.h" + namespace cc { scoped_refptr<VSyncTimeSource> VSyncTimeSource::Create( - VSyncProvider* vsync_provider) { - return make_scoped_refptr(new VSyncTimeSource(vsync_provider)); + VSyncProvider* vsync_provider, NotificationDisableOption option) { + return make_scoped_refptr(new VSyncTimeSource(vsync_provider, option)); } -VSyncTimeSource::VSyncTimeSource(VSyncProvider* vsync_provider) +VSyncTimeSource::VSyncTimeSource( + VSyncProvider* vsync_provider, NotificationDisableOption option) : active_(false), notification_requested_(false), vsync_provider_(vsync_provider), - client_(NULL) {} + client_(NULL), + disable_option_(option) {} VSyncTimeSource::~VSyncTimeSource() {} @@ -27,13 +31,14 @@ void VSyncTimeSource::SetActive(bool active) { if (active_ == active) return; active_ = active; - // The notification will be lazily disabled in the callback to ensure - // we get notified of the frame immediately following a quick on-off-on - // transition. if (active_ && !notification_requested_) { notification_requested_ = true; vsync_provider_->RequestVSyncNotification(this); } + if (!active_ && disable_option_ == DISABLE_SYNCHRONOUSLY) { + notification_requested_ = false; + vsync_provider_->RequestVSyncNotification(NULL); + } } bool VSyncTimeSource::Active() const { @@ -55,7 +60,9 @@ void VSyncTimeSource::SetTimebaseAndInterval(base::TimeTicks, void VSyncTimeSource::DidVSync(base::TimeTicks frame_time) { last_tick_time_ = frame_time; - if (!active_) { + if (disable_option_ == DISABLE_SYNCHRONOUSLY) { + DCHECK(active_); + } else if (!active_) { if (notification_requested_) { notification_requested_ = false; vsync_provider_->RequestVSyncNotification(NULL); diff --git a/cc/scheduler/vsync_time_source.h b/cc/scheduler/vsync_time_source.h index 910168f..4cd0441 100644 --- a/cc/scheduler/vsync_time_source.h +++ b/cc/scheduler/vsync_time_source.h @@ -33,7 +33,16 @@ class VSyncProvider { // external vsync signal. class CC_EXPORT VSyncTimeSource : public TimeSource, public VSyncClient { public: - static scoped_refptr<VSyncTimeSource> Create(VSyncProvider* vsync_provider); + enum NotificationDisableOption { + // The notification will be lazily disabled in the callback to ensure + // we get notified of the frame immediately following a quick on-off-on + // transition. + DISABLE_ON_NEXT_TICK, + DISABLE_SYNCHRONOUSLY + }; + + static scoped_refptr<VSyncTimeSource> Create( + VSyncProvider* vsync_provider, NotificationDisableOption option); // TimeSource implementation virtual void SetClient(TimeSourceClient* client) OVERRIDE; @@ -48,7 +57,8 @@ class CC_EXPORT VSyncTimeSource : public TimeSource, public VSyncClient { virtual void DidVSync(base::TimeTicks frame_time) OVERRIDE; protected: - explicit VSyncTimeSource(VSyncProvider* vsync_provider); + explicit VSyncTimeSource(VSyncProvider* vsync_provider, + NotificationDisableOption option); virtual ~VSyncTimeSource(); base::TimeTicks last_tick_time_; @@ -58,6 +68,7 @@ class CC_EXPORT VSyncTimeSource : public TimeSource, public VSyncClient { VSyncProvider* vsync_provider_; TimeSourceClient* client_; + NotificationDisableOption disable_option_; DISALLOW_COPY_AND_ASSIGN(VSyncTimeSource); }; diff --git a/cc/scheduler/vsync_time_source_unittest.cc b/cc/scheduler/vsync_time_source_unittest.cc index d652017..4834630 100644 --- a/cc/scheduler/vsync_time_source_unittest.cc +++ b/cc/scheduler/vsync_time_source_unittest.cc @@ -32,7 +32,9 @@ class FakeVSyncProvider : public VSyncProvider { class VSyncTimeSourceTest : public testing::Test { public: - VSyncTimeSourceTest() : timer_(VSyncTimeSource::Create(&provider_)) { + VSyncTimeSourceTest() + : timer_(VSyncTimeSource::Create( + &provider_, VSyncTimeSource::DISABLE_ON_NEXT_TICK)) { timer_->SetClient(&client_); } @@ -80,6 +82,30 @@ TEST_F(VSyncTimeSourceTest, NotificationDisabledLazily) { EXPECT_FALSE(client_.TickCalled()); } +TEST_F(VSyncTimeSourceTest, NotificationDisabledImmediatelyForSetting) { + timer_ = VSyncTimeSource::Create(&provider_, + VSyncTimeSource::DISABLE_SYNCHRONOUSLY); + timer_->SetClient(&client_); + base::TimeTicks frame_time = base::TimeTicks::Now(); + + // Enable timer and trigger sync once. + timer_->SetActive(true); + EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); + provider_.Trigger(frame_time); + EXPECT_TRUE(client_.TickCalled()); + + // Disable timer should disable vsync notification immediately. + timer_->SetActive(false); + EXPECT_FALSE(provider_.IsVSyncNotificationEnabled()); + + // Enable again and timer can be ticked again. + client_.Reset(); + timer_->SetActive(true); + EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); + provider_.Trigger(frame_time); + EXPECT_TRUE(client_.TickCalled()); +} + TEST_F(VSyncTimeSourceTest, ValidNextTickTime) { base::TimeTicks frame_time = base::TimeTicks::Now(); base::TimeDelta interval = base::TimeDelta::FromSeconds(1); |