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 <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 amount of frame timelines is arbitrarily set to be reasonable. 28 static constexpr int64_t kFrameTimelinesLength = 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 struct alignas(8) FrameTimeline { 37 // The Vsync Id corresponsing to this vsync event. This will be used to 38 // populate ISurfaceComposer::setFrameTimelineVsync and 39 // SurfaceComposerClient::setFrameTimelineVsync 40 int64_t vsyncId; 41 42 // The deadline in CLOCK_MONOTONIC in nanos that the app needs to complete its 43 // frame by (both on the CPU and the GPU). 44 int64_t deadlineTimestamp; 45 46 // The anticipated Vsync presentation time in nanos. 47 int64_t expectedPresentationTime; 48 } frameTimelines[kFrameTimelinesLength]; // Sorted possible frame timelines. 49 50 // Gets the preferred frame timeline's vsync ID. 51 int64_t preferredVsyncId() const; 52 53 // Gets the preferred frame timeline's deadline timestamp. 54 int64_t preferredDeadlineTimestamp() const; 55 56 // Gets the preferred frame timeline's expected vsync timestamp. 57 int64_t preferredExpectedPresentationTime() const; 58 }; 59 60 struct ParcelableVsyncEventData : public Parcelable { 61 VsyncEventData vsync; 62 63 status_t readFromParcel(const Parcel*) override; 64 status_t writeToParcel(Parcel*) const override; 65 }; 66 } // namespace android::gui 67