Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | namespace android::scheduler { |
| 26 | |
Kevin DuBois | 2fd3cea | 2019-11-14 08:52:45 -0800 | [diff] [blame] | 27 | class Clock; |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 28 | class VSyncDispatch; |
| 29 | class VSyncTracker; |
| 30 | |
| 31 | // TODO (b/145217110): consider renaming. |
| 32 | class VSyncReactor /* TODO (b/140201379): : public android::DispSync */ { |
| 33 | public: |
Kevin DuBois | 2fd3cea | 2019-11-14 08:52:45 -0800 | [diff] [blame] | 34 | VSyncReactor(std::unique_ptr<Clock> clock, std::unique_ptr<VSyncDispatch> dispatch, |
| 35 | std::unique_ptr<VSyncTracker> tracker, size_t pendingFenceLimit); |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 36 | |
| 37 | bool addPresentFence(const std::shared_ptr<FenceTime>& fence); |
| 38 | void setIgnorePresentFences(bool ignoration); |
| 39 | |
Kevin DuBois | 2fd3cea | 2019-11-14 08:52:45 -0800 | [diff] [blame] | 40 | nsecs_t computeNextRefresh(int periodOffset) const; |
| 41 | nsecs_t expectedPresentTime(); |
| 42 | |
Kevin DuBois | ee2ad9f | 2019-11-21 11:10:57 -0800 | [diff] [blame] | 43 | void setPeriod(nsecs_t period); |
| 44 | nsecs_t getPeriod(); |
| 45 | |
Kevin DuBois | a9fdab7 | 2019-11-14 09:44:14 -0800 | [diff] [blame^] | 46 | // 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 DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 51 | private: |
Kevin DuBois | 2fd3cea | 2019-11-14 08:52:45 -0800 | [diff] [blame] | 52 | std::unique_ptr<Clock> const mClock; |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 53 | 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 DuBois | a9fdab7 | 2019-11-14 09:44:14 -0800 | [diff] [blame^] | 60 | bool mPeriodChangeInProgress GUARDED_BY(mMutex) = false; |
Kevin DuBois | b2501ba | 2019-11-12 14:20:29 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } // namespace android::scheduler |