• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
20 #include <hardware/hardware.h>
21 #include <hardware/hwcomposer.h>
22 #include <hardware/hwcomposer2.h>
23 
24 #include <atomic>
25 #include <cstdint>
26 #include <functional>
27 #include <map>
28 
29 #include "DrmDevice.h"
30 #include "utils/Worker.h"
31 
32 namespace android {
33 
34 class VSyncWorker : public Worker {
35  public:
36   VSyncWorker();
37   ~VSyncWorker() override = default;
38 
39   auto Init(DrmDisplayPipeline *pipe,
40             std::function<void(uint64_t /*timestamp*/)> callback) -> int;
41 
42   void VSyncControl(bool enabled);
43 
44  protected:
45   void Routine() override;
46 
47  private:
48   int64_t GetPhasedVSync(int64_t frame_ns, int64_t current) const;
49   int SyntheticWaitVBlank(int64_t *timestamp);
50 
51   std::function<void(uint64_t /*timestamp*/)> callback_;
52 
53   DrmDisplayPipeline *pipe_ = nullptr;
54   std::atomic_bool enabled_ = false;
55   int64_t last_timestamp_ = -1;
56 };
57 }  // namespace android
58 
59 #endif
60