blob: 1774cc6323e31f55d91db34943995f243a15bb38 [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
Roman Stratiienkobde95662022-12-10 20:27:58 +020017#pragma once
Sean Paul4057be32015-05-13 06:23:09 -070018
Sean Paul4057be32015-05-13 06:23:09 -070019#include <hardware/hardware.h>
20#include <hardware/hwcomposer.h>
Roman Stratiienko23701092020-09-26 02:08:41 +030021#include <hardware/hwcomposer2.h>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030022
Roman Stratiienkod21071f2021-03-09 21:56:50 +020023#include <atomic>
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020024#include <cstdint>
Roman Stratiienko863a3c22021-09-29 13:00:29 +030025#include <functional>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030026#include <map>
27
Roman Stratiienko13cc3662020-08-29 21:35:39 +030028#include "DrmDevice.h"
29#include "utils/Worker.h"
Sean Paul4057be32015-05-13 06:23:09 -070030
31namespace android {
32
33class VSyncWorker : public Worker {
34 public:
35 VSyncWorker();
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020036 ~VSyncWorker() override = default;
Sean Paul4057be32015-05-13 06:23:09 -070037
Roman Stratiienko19c162f2022-02-01 09:35:08 +020038 auto Init(DrmDisplayPipeline *pipe,
Roman Stratiienko863a3c22021-09-29 13:00:29 +030039 std::function<void(uint64_t /*timestamp*/)> callback) -> int;
Sean Paul4057be32015-05-13 06:23:09 -070040
Adrian Salidofa37f672017-02-16 10:29:46 -080041 void VSyncControl(bool enabled);
Sean Paul4057be32015-05-13 06:23:09 -070042
43 protected:
Haixia Shi479412c2015-10-27 10:40:48 -070044 void Routine() override;
Sean Paul4057be32015-05-13 06:23:09 -070045
46 private:
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020047 int64_t GetPhasedVSync(int64_t frame_ns, int64_t current) const;
Sean Paul4057be32015-05-13 06:23:09 -070048 int SyntheticWaitVBlank(int64_t *timestamp);
49
Roman Stratiienko863a3c22021-09-29 13:00:29 +030050 std::function<void(uint64_t /*timestamp*/)> callback_;
Sean Paul4057be32015-05-13 06:23:09 -070051
Roman Stratiienko19c162f2022-02-01 09:35:08 +020052 DrmDisplayPipeline *pipe_ = nullptr;
53 std::atomic_bool enabled_ = false;
54 int64_t last_timestamp_ = -1;
Sean Paul4057be32015-05-13 06:23:09 -070055};
Sean Paulf72cccd2018-08-27 13:59:08 -040056} // namespace android