xref: /aosp_15_r20/frameworks/native/include/gui/VsyncEventData.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2022 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #pragma once
18*38e8c45fSAndroid Build Coastguard Worker 
19*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/FrameTimelineInfo.h>
20*38e8c45fSAndroid Build Coastguard Worker 
21*38e8c45fSAndroid Build Coastguard Worker #include <array>
22*38e8c45fSAndroid Build Coastguard Worker 
23*38e8c45fSAndroid Build Coastguard Worker namespace android::gui {
24*38e8c45fSAndroid Build Coastguard Worker // Plain Old Data (POD) vsync data structure. For example, it can be easily used in the
25*38e8c45fSAndroid Build Coastguard Worker // DisplayEventReceiver::Event union.
26*38e8c45fSAndroid Build Coastguard Worker struct VsyncEventData {
27*38e8c45fSAndroid Build Coastguard Worker     // Max capacity of frame timelines is arbitrarily set to be reasonable.
28*38e8c45fSAndroid Build Coastguard Worker     static constexpr int64_t kFrameTimelinesCapacity = 7;
29*38e8c45fSAndroid Build Coastguard Worker 
30*38e8c45fSAndroid Build Coastguard Worker     // The current frame interval in ns when this frame was scheduled.
31*38e8c45fSAndroid Build Coastguard Worker     int64_t frameInterval;
32*38e8c45fSAndroid Build Coastguard Worker 
33*38e8c45fSAndroid Build Coastguard Worker     // Index into the frameTimelines that represents the platform's preferred frame timeline.
34*38e8c45fSAndroid Build Coastguard Worker     uint32_t preferredFrameTimelineIndex;
35*38e8c45fSAndroid Build Coastguard Worker 
36*38e8c45fSAndroid Build Coastguard Worker     // Size of frame timelines provided by the platform; max is kFrameTimelinesCapacity.
37*38e8c45fSAndroid Build Coastguard Worker     uint32_t frameTimelinesLength;
38*38e8c45fSAndroid Build Coastguard Worker 
39*38e8c45fSAndroid Build Coastguard Worker     // Number of queued buffers to indicate if buffer stuffing mode is detected.
40*38e8c45fSAndroid Build Coastguard Worker     uint32_t numberQueuedBuffers;
41*38e8c45fSAndroid Build Coastguard Worker 
42*38e8c45fSAndroid Build Coastguard Worker     struct alignas(8) FrameTimeline {
43*38e8c45fSAndroid Build Coastguard Worker         // The Vsync Id corresponsing to this vsync event. This will be used to
44*38e8c45fSAndroid Build Coastguard Worker         // populate ISurfaceComposer::setFrameTimelineVsync and
45*38e8c45fSAndroid Build Coastguard Worker         // SurfaceComposerClient::setFrameTimelineVsync
46*38e8c45fSAndroid Build Coastguard Worker         int64_t vsyncId;
47*38e8c45fSAndroid Build Coastguard Worker 
48*38e8c45fSAndroid Build Coastguard Worker         // The deadline in CLOCK_MONOTONIC in nanos that the app needs to complete its
49*38e8c45fSAndroid Build Coastguard Worker         // frame by (both on the CPU and the GPU).
50*38e8c45fSAndroid Build Coastguard Worker         int64_t deadlineTimestamp;
51*38e8c45fSAndroid Build Coastguard Worker 
52*38e8c45fSAndroid Build Coastguard Worker         // The anticipated Vsync presentation time in nanos.
53*38e8c45fSAndroid Build Coastguard Worker         int64_t expectedPresentationTime;
54*38e8c45fSAndroid Build Coastguard Worker     } frameTimelines[kFrameTimelinesCapacity]; // Sorted possible frame timelines.
55*38e8c45fSAndroid Build Coastguard Worker 
56*38e8c45fSAndroid Build Coastguard Worker     // Gets the preferred frame timeline's vsync ID.
57*38e8c45fSAndroid Build Coastguard Worker     int64_t preferredVsyncId() const;
58*38e8c45fSAndroid Build Coastguard Worker 
59*38e8c45fSAndroid Build Coastguard Worker     // Gets the preferred frame timeline's deadline timestamp.
60*38e8c45fSAndroid Build Coastguard Worker     int64_t preferredDeadlineTimestamp() const;
61*38e8c45fSAndroid Build Coastguard Worker 
62*38e8c45fSAndroid Build Coastguard Worker     // Gets the preferred frame timeline's expected vsync timestamp.
63*38e8c45fSAndroid Build Coastguard Worker     int64_t preferredExpectedPresentationTime() const;
64*38e8c45fSAndroid Build Coastguard Worker };
65*38e8c45fSAndroid Build Coastguard Worker 
66*38e8c45fSAndroid Build Coastguard Worker struct ParcelableVsyncEventData : public Parcelable {
67*38e8c45fSAndroid Build Coastguard Worker     VsyncEventData vsync;
68*38e8c45fSAndroid Build Coastguard Worker 
69*38e8c45fSAndroid Build Coastguard Worker     status_t readFromParcel(const Parcel*) override;
70*38e8c45fSAndroid Build Coastguard Worker     status_t writeToParcel(Parcel*) const override;
71*38e8c45fSAndroid Build Coastguard Worker };
72*38e8c45fSAndroid Build Coastguard Worker } // namespace android::gui
73