OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/ipc/service/gpu_vsync_provider.h" | 5 #include "gpu/ipc/service/gpu_vsync_provider_win.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/base/win/hidden_window.h" | 13 #include "ui/base/win/hidden_window.h" |
14 | 14 |
15 namespace gpu { | 15 namespace gpu { |
(...skipping 30 matching lines...) Expand all Loading... |
46 base::WaitableEvent vsync_event_; | 46 base::WaitableEvent vsync_event_; |
47 | 47 |
48 private: | 48 private: |
49 base::Lock lock_; | 49 base::Lock lock_; |
50 int vsync_count_ = 0; | 50 int vsync_count_ = 0; |
51 }; | 51 }; |
52 | 52 |
53 TEST_F(GpuVSyncProviderTest, VSyncSignalTest) { | 53 TEST_F(GpuVSyncProviderTest, VSyncSignalTest) { |
54 SurfaceHandle window = ui::GetHiddenWindow(); | 54 SurfaceHandle window = ui::GetHiddenWindow(); |
55 | 55 |
56 std::unique_ptr<GpuVSyncProvider> provider = GpuVSyncProvider::Create( | 56 GpuVSyncProviderForTest provider( |
57 base::Bind(&GpuVSyncProviderTest::OnVSync, base::Unretained(this)), | 57 base::Bind(&GpuVSyncProviderTest::OnVSync, base::Unretained(this)), |
58 window); | 58 window); |
59 | 59 |
60 constexpr base::TimeDelta wait_timeout = | 60 constexpr base::TimeDelta wait_timeout = |
61 base::TimeDelta::FromMilliseconds(300); | 61 base::TimeDelta::FromMilliseconds(300); |
62 | 62 |
63 // Verify that there are no VSync signals before provider is enabled | 63 // Verify that there are no VSync signals before provider is enabled |
64 bool wait_result = vsync_event_.TimedWait(wait_timeout); | 64 bool wait_result = vsync_event_.TimedWait(wait_timeout); |
65 EXPECT_FALSE(wait_result); | 65 EXPECT_FALSE(wait_result); |
66 EXPECT_EQ(0, vsync_count()); | 66 EXPECT_EQ(0, vsync_count()); |
67 | 67 |
68 provider->EnableVSync(true); | 68 provider.SetNeedsVSync(true); |
69 | 69 |
70 vsync_event_.Wait(); | 70 vsync_event_.Wait(); |
71 | 71 |
72 provider->EnableVSync(false); | 72 provider.SetNeedsVSync(false); |
73 | 73 |
74 // Verify that VSync callbacks stop coming after disabling. | 74 // Verify that VSync callbacks stop coming after disabling. |
75 // Please note that it might still be possible for one | 75 // Please note that it might still be possible for one |
76 // callback to be in flight on VSync worker thread, so |vsync_count_| | 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 | 77 // could still be incremented once, but not enough times to trigger |
78 // |vsync_event_|. | 78 // |vsync_event_|. |
79 reset_vsync_count(); | 79 reset_vsync_count(); |
80 wait_result = vsync_event_.TimedWait(wait_timeout); | 80 wait_result = vsync_event_.TimedWait(wait_timeout); |
81 EXPECT_FALSE(wait_result); | 81 EXPECT_FALSE(wait_result); |
82 } | 82 } |
83 | 83 |
84 } // namespace gpu | 84 } // namespace gpu |
OLD | NEW |