Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Unified Diff: gpu/ipc/service/gpu_vsync_provider.h

Issue 2596123002: GpuVSyncProvider with unit test (Closed)
Patch Set: Fixed build failure on posix. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/ipc/service/gpu_vsync_provider.h
diff --git a/gpu/ipc/service/gpu_vsync_provider.h b/gpu/ipc/service/gpu_vsync_provider.h
new file mode 100644
index 0000000000000000000000000000000000000000..023628f75abe4d82a63f87a7f9fd2ed8d3cad822
--- /dev/null
+++ b/gpu/ipc/service/gpu_vsync_provider.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef GPU_IPC_SERVICE_GPU_VSYNC_PROVIDER_H_
+#define GPU_IPC_SERVICE_GPU_VSYNC_PROVIDER_H_
+
+#include <memory>
+
+#include "base/threading/thread.h"
+#include "base/time/time.h"
+#include "gpu/gpu_export.h"
+#include "gpu/ipc/common/surface_handle.h"
+
+namespace gpu {
+
+// Implements waiting for VSync signal on background thread.
+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...
+ public:
+ ~GpuVSyncProvider() override;
+
+ using VSyncCallback = base::Callback<void(base::TimeTicks timestamp)>;
+
+ // Create an instance of GpuVSyncProvider and start background thread
+ // Note that callback will be invoked on the worker thread.
+ static std::unique_ptr<GpuVSyncProvider> Create(const VSyncCallback& callback,
+ SurfaceHandle surface_handle);
+
+ // Enable or disable VSync production.
+ void EnableVSync(bool enabled);
+
+ private:
+#if defined(OS_WIN)
+ GpuVSyncProvider(const VSyncCallback& callback, SurfaceHandle surface_handle);
+
+ void StartRunningVSyncOnThread();
+ void WaitForVSyncOnThread();
+
+ void SendVSyncUpdate(base::TimeTicks now);
+
+ // Specifies whether VSync generation is enabled.
+ // 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.
+ 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.
+ // Specifies whether background task is running.
+ // 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.
+ bool running_ = false;
+
+ const VSyncCallback callback_;
+ const SurfaceHandle surface_handle_;
+#endif // defined(OS_WIN)
+
+ DISALLOW_COPY_AND_ASSIGN(GpuVSyncProvider);
+};
+
+} // namespace gpu
+
+#endif // GPU_IPC_SERVICE_GPU_VSYNC_PROVIDER_H_

Powered by Google App Engine
This is Rietveld 408576698