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 #ifndef GPU_IPC_SERVICE_GPU_VSYNC_PROVIDER_H_ | |
6 #define GPU_IPC_SERVICE_GPU_VSYNC_PROVIDER_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/threading/thread.h" | |
11 #include "base/time/time.h" | |
12 #include "gpu/gpu_export.h" | |
13 #include "gpu/ipc/common/surface_handle.h" | |
14 | |
15 namespace gpu { | |
16 | |
17 // Implements waiting for VSync signal on background thread. | |
18 class GPU_EXPORT GpuVSyncProvider : public base::Thread { | |
stanisc
2016/12/22 21:35:08
Not sure about the class name because it is simila
brucedawson
2016/12/22 21:49:16
Well I like the name...
| |
19 public: | |
20 ~GpuVSyncProvider() override; | |
21 | |
22 using VSyncCallback = base::Callback<void(base::TimeTicks timestamp)>; | |
23 | |
24 // Create an instance of GpuVSyncProvider and start background thread | |
25 // Note that callback will be invoked on the worker thread. | |
26 static std::unique_ptr<GpuVSyncProvider> Create(const VSyncCallback& callback, | |
27 SurfaceHandle surface_handle); | |
28 | |
29 // Enable or disable VSync production. | |
30 void EnableVSync(bool enabled); | |
31 | |
32 private: | |
33 #if defined(OS_WIN) | |
34 GpuVSyncProvider(const VSyncCallback& callback, SurfaceHandle surface_handle); | |
35 | |
36 void StartRunningVSyncOnThread(); | |
37 void WaitForVSyncOnThread(); | |
38 | |
39 void SendVSyncUpdate(base::TimeTicks now); | |
40 | |
41 // Specifies whether VSync generation is enabled. | |
42 // This can be set of main thread only and accessed from both threads. | |
stanisc
2016/12/22 21:35:08
Need to replace of -> on.
stanisc
2017/01/04 22:33:04
Done.
| |
43 volatile bool enabled_ = false; | |
brucedawson
2016/12/22 21:49:16
Shouldn't need volatile. volatile does tend to 'he
stanisc
2016/12/22 22:59:31
I had a lock initially but was concerned it could
brucedawson
2016/12/23 00:37:30
A few possibilities...
1) Use a lock, see if it w
stanisc
2017/01/04 22:33:04
Done.
| |
44 // Specifies whether background task is running. | |
45 // This can be set on background thread only. | |
brucedawson
2016/12/22 21:49:16
Can it be read on other threads? If so then it nee
stanisc
2016/12/22 22:59:31
No, this is accessed on background thread only. I'
stanisc
2017/01/04 22:33:04
Done.
| |
46 bool running_ = false; | |
47 | |
48 const VSyncCallback callback_; | |
49 const SurfaceHandle surface_handle_; | |
50 #endif // defined(OS_WIN) | |
51 | |
52 DISALLOW_COPY_AND_ASSIGN(GpuVSyncProvider); | |
53 }; | |
54 | |
55 } // namespace gpu | |
56 | |
57 #endif // GPU_IPC_SERVICE_GPU_VSYNC_PROVIDER_H_ | |
OLD | NEW |