blob: 50560a5a2b49d9d358c948fd5f859ff836bc6482 [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"
23
24namespace android {
25
26class DispSyncSource final : public VSyncSource, private DispSync::Callback {
27public:
Ady Abraham45e4e362019-06-07 18:20:51 -070028 DispSyncSource(DispSync* dispSync, nsecs_t phaseOffset, nsecs_t offsetThresholdForNextVsync,
29 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.
34 void setVSyncEnabled(bool enable) override;
35 void setCallback(VSyncSource::Callback* callback) override;
36 void setPhaseOffset(nsecs_t phaseOffset) override;
37
38private:
39 // The following method is the implementation of the DispSync::Callback.
40 virtual void onDispSyncEvent(nsecs_t when);
41
Alec Mourid7599d82019-05-22 19:58:00 -070042 void tracePhaseOffset() REQUIRES(mVsyncMutex);
43
Ana Krulec241cf832018-08-10 15:03:23 -070044 const char* const mName;
Ana Krulec072233f2018-08-10 15:03:23 -070045 int mValue = 0;
Ana Krulec241cf832018-08-10 15:03:23 -070046
47 const bool mTraceVsync;
Ana Krulec072233f2018-08-10 15:03:23 -070048 const std::string mVsyncOnLabel;
49 const std::string mVsyncEventLabel;
Alec Mourid7599d82019-05-22 19:58:00 -070050 const std::string mVsyncOffsetLabel;
51 const std::string mVsyncNegativeOffsetLabel;
Alec Mouri7355eb22019-03-05 14:19:10 -080052 nsecs_t mLastCallbackTime GUARDED_BY(mVsyncMutex) = 0;
Ana Krulec241cf832018-08-10 15:03:23 -070053
54 DispSync* mDispSync;
55
Ana Krulec072233f2018-08-10 15:03:23 -070056 std::mutex mCallbackMutex;
57 VSyncSource::Callback* mCallback GUARDED_BY(mCallbackMutex) = nullptr;
Ana Krulec241cf832018-08-10 15:03:23 -070058
Ana Krulec072233f2018-08-10 15:03:23 -070059 std::mutex mVsyncMutex;
60 nsecs_t mPhaseOffset GUARDED_BY(mVsyncMutex);
Ady Abraham45e4e362019-06-07 18:20:51 -070061 const nsecs_t mOffsetThresholdForNextVsync;
Ana Krulec072233f2018-08-10 15:03:23 -070062 bool mEnabled GUARDED_BY(mVsyncMutex) = false;
Ana Krulec241cf832018-08-10 15:03:23 -070063};
64
Alec Mourid7599d82019-05-22 19:58:00 -070065} // namespace android