blob: 328b8c176f1e239e22b5a6c44b2d300562849f03 [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
21#include "DispSync.h"
22#include "EventThread.h"
Ady Abraham50204dd2019-07-19 15:47:11 -070023#include "TracedOrdinal.h"
Ana Krulec241cf832018-08-10 15:03:23 -070024
25namespace android {
26
27class DispSyncSource final : public VSyncSource, private DispSync::Callback {
28public:
Ady Abraham9e16a482019-12-03 17:19:41 -080029 DispSyncSource(DispSync* dispSync, nsecs_t phaseOffset, bool traceVsync, const char* name);
Ana Krulec241cf832018-08-10 15:03:23 -070030
31 ~DispSyncSource() override = default;
32
33 // The following methods are implementation of VSyncSource.
Dominik Laskowski6505f792019-09-18 11:10:05 -070034 const char* getName() const override { return mName; }
Ana Krulec241cf832018-08-10 15:03:23 -070035 void setVSyncEnabled(bool enable) override;
36 void setCallback(VSyncSource::Callback* callback) override;
37 void setPhaseOffset(nsecs_t phaseOffset) override;
38
39private:
40 // The following method is the implementation of the DispSync::Callback.
41 virtual void onDispSyncEvent(nsecs_t when);
42
43 const char* const mName;
Ady Abraham50204dd2019-07-19 15:47:11 -070044 TracedOrdinal<int> mValue;
Ana Krulec241cf832018-08-10 15:03:23 -070045
46 const bool mTraceVsync;
Ana Krulec072233f2018-08-10 15:03:23 -070047 const std::string mVsyncOnLabel;
Alec Mouri7355eb22019-03-05 14:19:10 -080048 nsecs_t mLastCallbackTime GUARDED_BY(mVsyncMutex) = 0;
Ana Krulec241cf832018-08-10 15:03:23 -070049
50 DispSync* mDispSync;
51
Ana Krulec072233f2018-08-10 15:03:23 -070052 std::mutex mCallbackMutex;
53 VSyncSource::Callback* mCallback GUARDED_BY(mCallbackMutex) = nullptr;
Ana Krulec241cf832018-08-10 15:03:23 -070054
Ana Krulec072233f2018-08-10 15:03:23 -070055 std::mutex mVsyncMutex;
Ady Abraham50204dd2019-07-19 15:47:11 -070056 TracedOrdinal<nsecs_t> mPhaseOffset GUARDED_BY(mVsyncMutex);
Ana Krulec072233f2018-08-10 15:03:23 -070057 bool mEnabled GUARDED_BY(mVsyncMutex) = false;
Ana Krulec241cf832018-08-10 15:03:23 -070058};
59
Alec Mourid7599d82019-05-22 19:58:00 -070060} // namespace android