| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright 2018 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 | #pragma once | 
 | 17 |  | 
| Ana Krulec | 072233f | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 18 | #include <mutex> | 
 | 19 | #include <string> | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 20 |  | 
 | 21 | #include "DispSync.h" | 
 | 22 | #include "EventThread.h" | 
| Ady Abraham | 50204dd | 2019-07-19 15:47:11 -0700 | [diff] [blame] | 23 | #include "TracedOrdinal.h" | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 24 |  | 
 | 25 | namespace android { | 
 | 26 |  | 
 | 27 | class DispSyncSource final : public VSyncSource, private DispSync::Callback { | 
 | 28 | public: | 
| Ady Abraham | 9e16a48 | 2019-12-03 17:19:41 -0800 | [diff] [blame] | 29 |     DispSyncSource(DispSync* dispSync, nsecs_t phaseOffset, bool traceVsync, const char* name); | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 30 |  | 
 | 31 |     ~DispSyncSource() override = default; | 
 | 32 |  | 
 | 33 |     // The following methods are implementation of VSyncSource. | 
| Dominik Laskowski | 6505f79 | 2019-09-18 11:10:05 -0700 | [diff] [blame] | 34 |     const char* getName() const override { return mName; } | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 35 |     void setVSyncEnabled(bool enable) override; | 
 | 36 |     void setCallback(VSyncSource::Callback* callback) override; | 
 | 37 |     void setPhaseOffset(nsecs_t phaseOffset) override; | 
 | 38 |  | 
| Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 39 |     void dump(std::string&) const override; | 
 | 40 |  | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 41 | private: | 
 | 42 |     // The following method is the implementation of the DispSync::Callback. | 
 | 43 |     virtual void onDispSyncEvent(nsecs_t when); | 
 | 44 |  | 
 | 45 |     const char* const mName; | 
| Ady Abraham | 50204dd | 2019-07-19 15:47:11 -0700 | [diff] [blame] | 46 |     TracedOrdinal<int> mValue; | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 47 |  | 
 | 48 |     const bool mTraceVsync; | 
| Ana Krulec | 072233f | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 49 |     const std::string mVsyncOnLabel; | 
| Alec Mouri | 7355eb2 | 2019-03-05 14:19:10 -0800 | [diff] [blame] | 50 |     nsecs_t mLastCallbackTime GUARDED_BY(mVsyncMutex) = 0; | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 51 |  | 
 | 52 |     DispSync* mDispSync; | 
 | 53 |  | 
| Ana Krulec | 072233f | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 54 |     std::mutex mCallbackMutex; | 
 | 55 |     VSyncSource::Callback* mCallback GUARDED_BY(mCallbackMutex) = nullptr; | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 56 |  | 
| Ady Abraham | 5e7371c | 2020-03-24 14:47:24 -0700 | [diff] [blame] | 57 |     mutable std::mutex mVsyncMutex; | 
| Ady Abraham | 50204dd | 2019-07-19 15:47:11 -0700 | [diff] [blame] | 58 |     TracedOrdinal<nsecs_t> mPhaseOffset GUARDED_BY(mVsyncMutex); | 
| Ana Krulec | 072233f | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 59 |     bool mEnabled GUARDED_BY(mVsyncMutex) = false; | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 60 | }; | 
 | 61 |  | 
| Alec Mouri | d7599d8 | 2019-05-22 19:58:00 -0700 | [diff] [blame] | 62 | } // namespace android |