1 /* 2 * Copyright (C) 2022 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 17 #pragma once 18 19 #include <android/gui/FrameTimelineInfo.h> 20 21 #include <array> 22 23 namespace android::gui { 24 // Plain Old Data (POD) vsync data structure. For example, it can be easily used in the 25 // DisplayEventReceiver::Event union. 26 struct VsyncEventData { 27 // Max capacity of frame timelines is arbitrarily set to be reasonable. 28 static constexpr int64_t kFrameTimelinesCapacity = 7; 29 30 // The current frame interval in ns when this frame was scheduled. 31 int64_t frameInterval; 32 33 // Index into the frameTimelines that represents the platform's preferred frame timeline. 34 uint32_t preferredFrameTimelineIndex; 35 36 // Size of frame timelines provided by the platform; max is kFrameTimelinesCapacity. 37 uint32_t frameTimelinesLength; 38 39 struct alignas(8) FrameTimeline { 40 // The Vsync Id corresponsing to this vsync event. This will be used to 41 // populate ISurfaceComposer::setFrameTimelineVsync and 42 // SurfaceComposerClient::setFrameTimelineVsync 43 int64_t vsyncId; 44 45 // The deadline in CLOCK_MONOTONIC in nanos that the app needs to complete its 46 // frame by (both on the CPU and the GPU). 47 int64_t deadlineTimestamp; 48 49 // The anticipated Vsync presentation time in nanos. 50 int64_t expectedPresentationTime; 51 } frameTimelines[kFrameTimelinesCapacity]; // Sorted possible frame timelines. 52 53 // Gets the preferred frame timeline's vsync ID. 54 int64_t preferredVsyncId() const; 55 56 // Gets the preferred frame timeline's deadline timestamp. 57 int64_t preferredDeadlineTimestamp() const; 58 59 // Gets the preferred frame timeline's expected vsync timestamp. 60 int64_t preferredExpectedPresentationTime() const; 61 }; 62 63 struct ParcelableVsyncEventData : public Parcelable { 64 VsyncEventData vsync; 65 66 status_t readFromParcel(const Parcel*) override; 67 status_t writeToParcel(Parcel*) const override; 68 }; 69 } // namespace android::gui 70