• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include <mutex>
19 #include <string>
20 
21 #include "EventThread.h"
22 #include "TracedOrdinal.h"
23 #include "VSyncDispatch.h"
24 
25 namespace android::scheduler {
26 class CallbackRepeater;
27 
28 class DispSyncSource final : public VSyncSource {
29 public:
30     DispSyncSource(VSyncDispatch& vSyncDispatch, std::chrono::nanoseconds workDuration,
31                    std::chrono::nanoseconds readyDuration, bool traceVsync, const char* name);
32 
33     ~DispSyncSource() override;
34 
35     // The following methods are implementation of VSyncSource.
getName()36     const char* getName() const override { return mName; }
37     void setVSyncEnabled(bool enable) override;
38     void setCallback(VSyncSource::Callback* callback) override;
39     void setDuration(std::chrono::nanoseconds workDuration,
40                      std::chrono::nanoseconds readyDuration) override;
41 
42     void dump(std::string&) const override;
43 
44 private:
45     void onVsyncCallback(nsecs_t vsyncTime, nsecs_t targetWakeupTime, nsecs_t readyTime);
46 
47     const char* const mName;
48     TracedOrdinal<int> mValue;
49 
50     const bool mTraceVsync;
51     const std::string mVsyncOnLabel;
52 
53     std::unique_ptr<CallbackRepeater> mCallbackRepeater;
54 
55     std::mutex mCallbackMutex;
56     VSyncSource::Callback* mCallback GUARDED_BY(mCallbackMutex) = nullptr;
57 
58     mutable std::mutex mVsyncMutex;
59     TracedOrdinal<std::chrono::nanoseconds> mWorkDuration GUARDED_BY(mVsyncMutex);
60     std::chrono::nanoseconds mReadyDuration GUARDED_BY(mVsyncMutex);
61     bool mEnabled GUARDED_BY(mVsyncMutex) = false;
62 };
63 
64 } // namespace android::scheduler
65