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/waitable_event.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "ui/base/win/hidden_window.h" | |
13 | |
14 #include <windows.h> | |
15 | |
16 namespace gpu { | |
17 | |
18 class GpuVSyncProviderTest : public testing::Test { | |
19 public: | |
20 GpuVSyncProviderTest() | |
21 : vsync_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
22 base::WaitableEvent::InitialState::NOT_SIGNALED) {} | |
23 ~GpuVSyncProviderTest() override {} | |
24 | |
25 void SetUp() override {} | |
26 | |
27 void TearDown() override {} | |
28 | |
29 void OnVSync(base::TimeTicks timestamp) { | |
30 // This is called on VSync worker thread. | |
31 if (InterlockedIncrement(&vsync_count_) == 3) | |
32 vsync_event_.Signal(); | |
33 } | |
34 | |
35 base::WaitableEvent vsync_event_; | |
36 volatile LONG vsync_count_ = 0; | |
brucedawson
2016/12/22 21:49:16
Volatile isn't needed here. What makes this safe t
stanisc
2017/01/04 22:33:04
Done.
| |
37 }; | |
38 | |
39 TEST_F(GpuVSyncProviderTest, VSyncSignalTest) { | |
40 SurfaceHandle window = ui::GetHiddenWindow(); | |
41 | |
42 std::unique_ptr<GpuVSyncProvider> provider = GpuVSyncProvider::Create( | |
43 base::Bind(&GpuVSyncProviderTest::OnVSync, base::Unretained(this)), | |
44 window); | |
45 | |
46 constexpr base::TimeDelta wait_timeout = | |
47 base::TimeDelta::FromMilliseconds(300); | |
48 | |
49 // Verify that there are no VSync signals before provider is enabled | |
50 bool wait_result = vsync_event_.TimedWait(wait_timeout); | |
51 EXPECT_FALSE(wait_result); | |
52 EXPECT_EQ(0, vsync_count_); | |
53 | |
54 provider->EnableVSync(true); | |
55 | |
56 vsync_event_.Wait(); | |
57 | |
58 provider->EnableVSync(false); | |
59 | |
60 // Verify that VSync callbacks stop coming after disabling. | |
61 // Please note that it might still be possible for one | |
62 // callback to be in flight on VSync worker thread, so |vsync_count_| | |
63 // could still be incremented once, but not enough times to trigger | |
64 // |vsync_event_|. | |
65 InterlockedExchange(&vsync_count_, 0); | |
66 wait_result = vsync_event_.TimedWait(wait_timeout); | |
67 EXPECT_FALSE(wait_result); | |
68 } | |
69 | |
70 } // namespace gpu | |
OLD | NEW |