blob: 2fce235546bf6e115a7bb65d0f2748b5506d5b20 [file] [log] [blame]
Ana Krulec241cf832018-08-10 15:03:23 -07001/*
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 Krulec072233f2018-08-10 15:03:23 -070018#include <mutex>
19#include <string>
Ana Krulec241cf832018-08-10 15:03:23 -070020
Ana Krulec241cf832018-08-10 15:03:23 -070021#include "EventThread.h"
Ady Abraham50204dd2019-07-19 15:47:11 -070022#include "TracedOrdinal.h"
Ady Abraham9c53ee72020-07-22 21:16:18 -070023#include "VSyncDispatch.h"
Ana Krulec241cf832018-08-10 15:03:23 -070024
Ady Abraham9c53ee72020-07-22 21:16:18 -070025namespace android::scheduler {
26class CallbackRepeater;
Ana Krulec241cf832018-08-10 15:03:23 -070027
Ady Abraham9c53ee72020-07-22 21:16:18 -070028class DispSyncSource final : public VSyncSource {
Ana Krulec241cf832018-08-10 15:03:23 -070029public:
Ady Abraham9c53ee72020-07-22 21:16:18 -070030 DispSyncSource(VSyncDispatch& vSyncDispatch, std::chrono::nanoseconds workDuration,
31 std::chrono::nanoseconds readyDuration, bool traceVsync, const char* name);
Ana Krulec241cf832018-08-10 15:03:23 -070032
Ady Abraham9c53ee72020-07-22 21:16:18 -070033 ~DispSyncSource() override;
Ana Krulec241cf832018-08-10 15:03:23 -070034
35 // The following methods are implementation of VSyncSource.
Dominik Laskowski6505f792019-09-18 11:10:05 -070036 const char* getName() const override { return mName; }
Ana Krulec241cf832018-08-10 15:03:23 -070037 void setVSyncEnabled(bool enable) override;
38 void setCallback(VSyncSource::Callback* callback) override;
Ady Abraham9c53ee72020-07-22 21:16:18 -070039 void setDuration(std::chrono::nanoseconds workDuration,
40 std::chrono::nanoseconds readyDuration) override;
Ana Krulec241cf832018-08-10 15:03:23 -070041
Ady Abraham5e7371c2020-03-24 14:47:24 -070042 void dump(std::string&) const override;
43
Ana Krulec241cf832018-08-10 15:03:23 -070044private:
Ady Abraham9c53ee72020-07-22 21:16:18 -070045 void onVsyncCallback(nsecs_t vsyncTime, nsecs_t targetWakeupTime, nsecs_t readyTime);
Ana Krulec241cf832018-08-10 15:03:23 -070046
47 const char* const mName;
Ady Abraham50204dd2019-07-19 15:47:11 -070048 TracedOrdinal<int> mValue;
Ana Krulec241cf832018-08-10 15:03:23 -070049
50 const bool mTraceVsync;
Ana Krulec072233f2018-08-10 15:03:23 -070051 const std::string mVsyncOnLabel;
Ana Krulec241cf832018-08-10 15:03:23 -070052
Ady Abraham9c53ee72020-07-22 21:16:18 -070053 std::unique_ptr<CallbackRepeater> mCallbackRepeater;
Ana Krulec241cf832018-08-10 15:03:23 -070054
Ana Krulec072233f2018-08-10 15:03:23 -070055 std::mutex mCallbackMutex;
56 VSyncSource::Callback* mCallback GUARDED_BY(mCallbackMutex) = nullptr;
Ana Krulec241cf832018-08-10 15:03:23 -070057
Ady Abraham5e7371c2020-03-24 14:47:24 -070058 mutable std::mutex mVsyncMutex;
Ady Abraham9c53ee72020-07-22 21:16:18 -070059 TracedOrdinal<std::chrono::nanoseconds> mWorkDuration GUARDED_BY(mVsyncMutex);
60 std::chrono::nanoseconds mReadyDuration GUARDED_BY(mVsyncMutex);
Ana Krulec072233f2018-08-10 15:03:23 -070061 bool mEnabled GUARDED_BY(mVsyncMutex) = false;
Ana Krulec241cf832018-08-10 15:03:23 -070062};
63
Ady Abraham9c53ee72020-07-22 21:16:18 -070064} // namespace android::scheduler