blob: 786ee98ccafa898f5ba944f0af4cc6ecb3b093d9 [file] [log] [blame]
Kevin DuBoisb2501ba2019-11-12 14:20:29 -08001/*
2 * Copyright 2019 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#pragma once
18
19#include <android-base/thread_annotations.h>
20#include <ui/FenceTime.h>
21#include <memory>
22#include <mutex>
23#include <vector>
24
25namespace android::scheduler {
26
Kevin DuBois2fd3cea2019-11-14 08:52:45 -080027class Clock;
Kevin DuBoisb2501ba2019-11-12 14:20:29 -080028class VSyncDispatch;
29class VSyncTracker;
30
31// TODO (b/145217110): consider renaming.
32class VSyncReactor /* TODO (b/140201379): : public android::DispSync */ {
33public:
Kevin DuBois2fd3cea2019-11-14 08:52:45 -080034 VSyncReactor(std::unique_ptr<Clock> clock, std::unique_ptr<VSyncDispatch> dispatch,
35 std::unique_ptr<VSyncTracker> tracker, size_t pendingFenceLimit);
Kevin DuBoisb2501ba2019-11-12 14:20:29 -080036
37 bool addPresentFence(const std::shared_ptr<FenceTime>& fence);
38 void setIgnorePresentFences(bool ignoration);
39
Kevin DuBois2fd3cea2019-11-14 08:52:45 -080040 nsecs_t computeNextRefresh(int periodOffset) const;
41 nsecs_t expectedPresentTime();
42
Kevin DuBoisee2ad9f2019-11-21 11:10:57 -080043 void setPeriod(nsecs_t period);
44 nsecs_t getPeriod();
45
Kevin DuBoisa9fdab72019-11-14 09:44:14 -080046 // TODO: (b/145626181) remove begin,endResync functions from DispSync i/f when possible.
47 void beginResync();
48 bool addResyncSample(nsecs_t timestamp, bool* periodFlushed);
49 void endResync();
50
Kevin DuBoisb2501ba2019-11-12 14:20:29 -080051private:
Kevin DuBois2fd3cea2019-11-14 08:52:45 -080052 std::unique_ptr<Clock> const mClock;
Kevin DuBoisb2501ba2019-11-12 14:20:29 -080053 std::unique_ptr<VSyncDispatch> const mDispatch;
54 std::unique_ptr<VSyncTracker> const mTracker;
55 size_t const mPendingLimit;
56
57 std::mutex mMutex;
58 bool mIgnorePresentFences GUARDED_BY(mMutex) = false;
59 std::vector<std::shared_ptr<FenceTime>> mUnfiredFences GUARDED_BY(mMutex);
Kevin DuBoisa9fdab72019-11-14 09:44:14 -080060 bool mPeriodChangeInProgress GUARDED_BY(mMutex) = false;
Kevin DuBoisb2501ba2019-11-12 14:20:29 -080061};
62
63} // namespace android::scheduler