diff options
Diffstat (limited to 'drm/VSyncWorker.h')
-rw-r--r-- | drm/VSyncWorker.h | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/drm/VSyncWorker.h b/drm/VSyncWorker.h index 1e6d39f..031a561 100644 --- a/drm/VSyncWorker.h +++ b/drm/VSyncWorker.h @@ -14,46 +14,53 @@ * limitations under the License. */ -#ifndef ANDROID_EVENT_WORKER_H_ -#define ANDROID_EVENT_WORKER_H_ +#pragma once -#include <hardware/hardware.h> -#include <hardware/hwcomposer.h> -#include <hardware/hwcomposer2.h> - -#include <atomic> -#include <cstdint> +#include <condition_variable> #include <functional> #include <map> +#include <mutex> +#include <thread> #include "DrmDevice.h" -#include "utils/Worker.h" namespace android { -class VSyncWorker : public Worker { +struct VSyncWorkerCallbacks { + std::function<void(uint64_t /*timestamp*/)> out_event; + std::function<uint32_t()> get_vperiod_ns; +}; + +class VSyncWorker { public: - VSyncWorker(); - ~VSyncWorker() override = default; + ~VSyncWorker() = default; - auto Init(DrmDisplayPipeline *pipe, - std::function<void(uint64_t /*timestamp*/)> callback) -> int; + auto static CreateInstance(DrmDisplayPipeline *pipe, + VSyncWorkerCallbacks &callbacks) + -> std::shared_ptr<VSyncWorker>; void VSyncControl(bool enabled); - - protected: - void Routine() override; + void StopThread(); private: + VSyncWorker() = default; + + void ThreadFn(const std::shared_ptr<VSyncWorker> &vsw); + int64_t GetPhasedVSync(int64_t frame_ns, int64_t current) const; int SyntheticWaitVBlank(int64_t *timestamp); - std::function<void(uint64_t /*timestamp*/)> callback_; + VSyncWorkerCallbacks callbacks_; + + SharedFd drm_fd_; + uint32_t high_crtc_ = 0; - DrmDisplayPipeline *pipe_ = nullptr; - std::atomic_bool enabled_ = false; + bool enabled_ = false; + bool thread_exit_ = false; int64_t last_timestamp_ = -1; + + std::condition_variable cv_; + std::thread vswt_; + std::mutex mutex_; }; } // namespace android - -#endif |