| 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" | 
|  | 23 |  | 
|  | 24 | namespace android { | 
|  | 25 |  | 
|  | 26 | class DispSyncSource final : public VSyncSource, private DispSync::Callback { | 
|  | 27 | public: | 
|  | 28 | DispSyncSource(DispSync* dispSync, nsecs_t phaseOffset, bool traceVsync, const char* name); | 
|  | 29 |  | 
|  | 30 | ~DispSyncSource() override = default; | 
|  | 31 |  | 
|  | 32 | // The following methods are implementation of VSyncSource. | 
|  | 33 | void setVSyncEnabled(bool enable) override; | 
|  | 34 | void setCallback(VSyncSource::Callback* callback) override; | 
|  | 35 | void setPhaseOffset(nsecs_t phaseOffset) override; | 
| Ady Abraham | b838aed | 2019-02-12 15:30:16 -0800 | [diff] [blame] | 36 | void pauseVsyncCallback(bool pause) override; | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 37 |  | 
|  | 38 | private: | 
|  | 39 | // The following method is the implementation of the DispSync::Callback. | 
|  | 40 | virtual void onDispSyncEvent(nsecs_t when); | 
|  | 41 |  | 
|  | 42 | const char* const mName; | 
| Ana Krulec | 072233f | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 43 | int mValue = 0; | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 44 |  | 
|  | 45 | const bool mTraceVsync; | 
| Ana Krulec | 072233f | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 46 | const std::string mVsyncOnLabel; | 
|  | 47 | const std::string mVsyncEventLabel; | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 48 |  | 
|  | 49 | DispSync* mDispSync; | 
|  | 50 |  | 
| Ana Krulec | 072233f | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 51 | std::mutex mCallbackMutex; | 
|  | 52 | VSyncSource::Callback* mCallback GUARDED_BY(mCallbackMutex) = nullptr; | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 53 |  | 
| Ana Krulec | 072233f | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 54 | std::mutex mVsyncMutex; | 
|  | 55 | nsecs_t mPhaseOffset GUARDED_BY(mVsyncMutex); | 
|  | 56 | bool mEnabled GUARDED_BY(mVsyncMutex) = false; | 
| Ady Abraham | b838aed | 2019-02-12 15:30:16 -0800 | [diff] [blame] | 57 | bool mCallbackPaused GUARDED_BY(mVsyncMutex) = false; | 
| Ana Krulec | 241cf83 | 2018-08-10 15:03:23 -0700 | [diff] [blame] | 58 | }; | 
|  | 59 |  | 
|  | 60 | } // namespace android |