OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "gpu/ipc/service/gpu_vsync_provider.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/synchronization/lock.h" |
| 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/base/win/hidden_window.h" |
| 14 |
| 15 namespace gpu { |
| 16 |
| 17 class GpuVSyncProviderTest : public testing::Test { |
| 18 public: |
| 19 GpuVSyncProviderTest() |
| 20 : vsync_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 21 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
| 22 ~GpuVSyncProviderTest() override {} |
| 23 |
| 24 void SetUp() override {} |
| 25 |
| 26 void TearDown() override {} |
| 27 |
| 28 void OnVSync(base::TimeTicks timestamp) { |
| 29 // This is called on VSync worker thread. |
| 30 base::AutoLock lock(lock_); |
| 31 if (++vsync_count_ == 3) |
| 32 vsync_event_.Signal(); |
| 33 } |
| 34 |
| 35 int vsync_count() { |
| 36 base::AutoLock lock(lock_); |
| 37 return vsync_count_; |
| 38 } |
| 39 |
| 40 void reset_vsync_count() { |
| 41 base::AutoLock lock(lock_); |
| 42 vsync_count_ = 0; |
| 43 } |
| 44 |
| 45 protected: |
| 46 base::WaitableEvent vsync_event_; |
| 47 |
| 48 private: |
| 49 base::Lock lock_; |
| 50 int vsync_count_ = 0; |
| 51 }; |
| 52 |
| 53 TEST_F(GpuVSyncProviderTest, VSyncSignalTest) { |
| 54 SurfaceHandle window = ui::GetHiddenWindow(); |
| 55 |
| 56 std::unique_ptr<GpuVSyncProvider> provider = GpuVSyncProvider::Create( |
| 57 base::Bind(&GpuVSyncProviderTest::OnVSync, base::Unretained(this)), |
| 58 window); |
| 59 |
| 60 constexpr base::TimeDelta wait_timeout = |
| 61 base::TimeDelta::FromMilliseconds(300); |
| 62 |
| 63 // Verify that there are no VSync signals before provider is enabled |
| 64 bool wait_result = vsync_event_.TimedWait(wait_timeout); |
| 65 EXPECT_FALSE(wait_result); |
| 66 EXPECT_EQ(0, vsync_count()); |
| 67 |
| 68 provider->EnableVSync(true); |
| 69 |
| 70 vsync_event_.Wait(); |
| 71 |
| 72 provider->EnableVSync(false); |
| 73 |
| 74 // Verify that VSync callbacks stop coming after disabling. |
| 75 // Please note that it might still be possible for one |
| 76 // callback to be in flight on VSync worker thread, so |vsync_count_| |
| 77 // could still be incremented once, but not enough times to trigger |
| 78 // |vsync_event_|. |
| 79 reset_vsync_count(); |
| 80 wait_result = vsync_event_.TimedWait(wait_timeout); |
| 81 EXPECT_FALSE(wait_result); |
| 82 } |
| 83 |
| 84 } // namespace gpu |
OLD | NEW |