Index: include/private/SkGpuTimer.h |
diff --git a/include/private/SkGpuTimer.h b/include/private/SkGpuTimer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4037bbb7d6c1d20bb3102ff887a3dd52230095c2 |
--- /dev/null |
+++ b/include/private/SkGpuTimer.h |
@@ -0,0 +1,73 @@ |
+/* |
+ * Copyright 2016 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#ifndef SkGpuTimer_DEFINED |
+#define SkGpuTimer_DEFINED |
+ |
+#include "SkTypes.h" |
+#include "SkExchange.h" |
+#include <chrono> |
+ |
+using SkPlatformGpuTimerQuery = intptr_t; |
bsalomon
2016/09/30 18:37:16
What do you think about putting this in sk_gpu_tes
csmartdalton
2016/10/03 16:52:24
Done.
|
+constexpr static SkPlatformGpuTimerQuery SK_InvalidGpuTimerQuery = 0; |
+ |
+/** |
+ * Platform-independent interface for timing operations on the GPU. |
+ */ |
+class SkGpuTimer { |
+public: |
+ SkGpuTimer(bool disjointSupport) |
+ : fDisjointSupport(disjointSupport) |
+ , fActiveTimer(SK_InvalidGpuTimerQuery) { |
+ } |
+ virtual ~SkGpuTimer() { SkASSERT(!fActiveTimer); } |
+ |
+ /** |
+ * Returns whether this timer can detect disjoint GPU operations while timing. If false, a query |
+ * has less confidence when it completes with QueryStatus::kAccurate. |
+ */ |
+ bool disjointSupport() const { return fDisjointSupport; } |
+ |
+ /** |
+ * Inserts a "start timing" command in the GPU command stream. |
+ */ |
+ void queueStart() { |
+ SkASSERT(!fActiveTimer); |
+ fActiveTimer = this->onQueueTimerStart(); |
+ } |
+ |
+ /** |
+ * Inserts a "stop timing" command in the GPU command stream. |
+ * |
+ * @return a query object that can retrieve the time elapsed once the timer has completed. |
+ */ |
+ SkPlatformGpuTimerQuery SK_WARN_UNUSED_RESULT queueStop() { |
+ SkASSERT(fActiveTimer); |
+ this->onQueueTimerStop(fActiveTimer); |
+ return skstd::exchange(fActiveTimer, SK_InvalidGpuTimerQuery); |
+ } |
+ |
+ enum class QueryStatus { |
+ kInvalid, //<! the timer query is invalid. |
+ kPending, //<! the timer is still running on the GPU. |
+ kDisjoint, //<! the query is complete, but dubious due to disjoint GPU operations. |
+ kAccurate //<! the query is complete and reliable. |
+ }; |
+ |
+ virtual QueryStatus checkQueryStatus(SkPlatformGpuTimerQuery) = 0; |
+ virtual std::chrono::nanoseconds getTimeElapsed(SkPlatformGpuTimerQuery) = 0; |
+ virtual void deleteQuery(SkPlatformGpuTimerQuery) = 0; |
+ |
+private: |
+ virtual SkPlatformGpuTimerQuery onQueueTimerStart() const = 0; |
+ virtual void onQueueTimerStop(SkPlatformGpuTimerQuery) const = 0; |
+ |
+ bool const fDisjointSupport; |
+ SkPlatformGpuTimerQuery fActiveTimer; |
+}; |
+ |
+#endif |