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