blob: 1e6d39f0c3b6bc5d0ee2abb24d619fa03e4dec35 [file] [log] [blame]
Sean Paul4057be32015-05-13 06:23:09 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_EVENT_WORKER_H_
18#define ANDROID_EVENT_WORKER_H_
19
Sean Paul4057be32015-05-13 06:23:09 -070020#include <hardware/hardware.h>
21#include <hardware/hwcomposer.h>
Roman Stratiienko23701092020-09-26 02:08:41 +030022#include <hardware/hwcomposer2.h>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030023
Roman Stratiienkod21071f2021-03-09 21:56:50 +020024#include <atomic>
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020025#include <cstdint>
Roman Stratiienko863a3c22021-09-29 13:00:29 +030026#include <functional>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030027#include <map>
28
Roman Stratiienko13cc3662020-08-29 21:35:39 +030029#include "DrmDevice.h"
30#include "utils/Worker.h"
Sean Paul4057be32015-05-13 06:23:09 -070031
32namespace android {
33
34class VSyncWorker : public Worker {
35 public:
36 VSyncWorker();
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020037 ~VSyncWorker() override = default;
Sean Paul4057be32015-05-13 06:23:09 -070038
Roman Stratiienko19c162f2022-02-01 09:35:08 +020039 auto Init(DrmDisplayPipeline *pipe,
Roman Stratiienko863a3c22021-09-29 13:00:29 +030040 std::function<void(uint64_t /*timestamp*/)> callback) -> int;
Sean Paul4057be32015-05-13 06:23:09 -070041
Adrian Salidofa37f672017-02-16 10:29:46 -080042 void VSyncControl(bool enabled);
Sean Paul4057be32015-05-13 06:23:09 -070043
44 protected:
Haixia Shi479412c2015-10-27 10:40:48 -070045 void Routine() override;
Sean Paul4057be32015-05-13 06:23:09 -070046
47 private:
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020048 int64_t GetPhasedVSync(int64_t frame_ns, int64_t current) const;
Sean Paul4057be32015-05-13 06:23:09 -070049 int SyntheticWaitVBlank(int64_t *timestamp);
50
Roman Stratiienko863a3c22021-09-29 13:00:29 +030051 std::function<void(uint64_t /*timestamp*/)> callback_;
Sean Paul4057be32015-05-13 06:23:09 -070052
Roman Stratiienko19c162f2022-02-01 09:35:08 +020053 DrmDisplayPipeline *pipe_ = nullptr;
54 std::atomic_bool enabled_ = false;
55 int64_t last_timestamp_ = -1;
Sean Paul4057be32015-05-13 06:23:09 -070056};
Sean Paulf72cccd2018-08-27 13:59:08 -040057} // namespace android
Sean Paul4057be32015-05-13 06:23:09 -070058
59#endif