blob: 74ff487fbc45f03d584209d521fc7c42e9f8c2ee [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#include <stdint.h>
24
Roman Stratiienkod21071f2021-03-09 21:56:50 +020025#include <atomic>
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 Stratiienko863a3c22021-09-29 13:00:29 +030039 auto Init(DrmDevice *drm, int display,
40 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
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010051 DrmDevice *drm_;
Sean Paula5df1de2016-02-10 10:00:08 -080052
Roman Stratiienko863a3c22021-09-29 13:00:29 +030053 std::function<void(uint64_t /*timestamp*/)> callback_;
Sean Paul4057be32015-05-13 06:23:09 -070054
55 int display_;
Roman Kovalivskyi521a4c82020-01-03 20:26:45 +020056 std::atomic_bool enabled_;
Sean Paul4057be32015-05-13 06:23:09 -070057 int64_t last_timestamp_;
58};
Sean Paulf72cccd2018-08-27 13:59:08 -040059} // namespace android
Sean Paul4057be32015-05-13 06:23:09 -070060
61#endif