Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 976cf406 authored by Rachel Lee's avatar Rachel Lee Committed by Android (Google) Code Review
Browse files

Merge changes I64f0ea61,I51b18ed3,I6f5f2357

* changes:
  Create data class VSyncSource::VSyncData.
  Split VsyncEventData from DisplayEventDispatcher.
  Remove vsync ID generation before multi timelines.
parents 806283df f16da3cb
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -198,6 +198,7 @@ cc_library_shared {
        "SurfaceComposerClient.cpp",
        "SurfaceComposerClient.cpp",
        "SyncFeatures.cpp",
        "SyncFeatures.cpp",
        "TransactionTracing.cpp",
        "TransactionTracing.cpp",
        "VsyncEventData.cpp",
        "view/Surface.cpp",
        "view/Surface.cpp",
        "WindowInfosListenerReporter.cpp",
        "WindowInfosListenerReporter.cpp",
        "bufferqueue/1.0/B2HProducerListener.cpp",
        "bufferqueue/1.0/B2HProducerListener.cpp",
+5 −6
Original line number Original line Diff line number Diff line
@@ -148,14 +148,13 @@ int DisplayEventDispatcher::handleEvent(int, int events, void*) {


void DisplayEventDispatcher::populateFrameTimelines(const DisplayEventReceiver::Event& event,
void DisplayEventDispatcher::populateFrameTimelines(const DisplayEventReceiver::Event& event,
                                                    VsyncEventData* outVsyncEventData) const {
                                                    VsyncEventData* outVsyncEventData) const {
    for (size_t i = 0; i < DisplayEventReceiver::kFrameTimelinesLength; i++) {
    for (size_t i = 0; i < VsyncEventData::kFrameTimelinesLength; i++) {
        DisplayEventReceiver::Event::VSync::FrameTimeline receiverTimeline =
        DisplayEventReceiver::Event::VSync::FrameTimeline receiverTimeline =
                event.vsync.frameTimelines[i];
                event.vsync.frameTimelines[i];
        outVsyncEventData->frameTimelines[i] = {.id = receiverTimeline.vsyncId,
        outVsyncEventData->frameTimelines[i] =
                                                .deadlineTimestamp =
                VsyncEventData::FrameTimeline(receiverTimeline.vsyncId,
                                              receiverTimeline.deadlineTimestamp,
                                              receiverTimeline.deadlineTimestamp,
                                                .expectedPresentTime =
                                              receiverTimeline.expectedVSyncTimestamp);
                                                        receiverTimeline.expectedVSyncTimestamp};
    }
    }
}
}


+76 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "gui/VsyncEventData.h"
#include <gui/DisplayEventReceiver.h>
#include <private/gui/ParcelUtils.h>
#include <utils/Log.h>
#include <utils/Looper.h>
#include <cstdint>

namespace android::gui {

status_t VsyncEventData::readFromParcel(const Parcel* parcel) {
    if (parcel == nullptr) {
        ALOGE("%s: Null parcel", __func__);
        return BAD_VALUE;
    }

    SAFE_PARCEL(parcel->readInt64, &id)
    SAFE_PARCEL(parcel->readInt64, &deadlineTimestamp);
    SAFE_PARCEL(parcel->readInt64, &frameInterval);

    uint64_t uintPreferredFrameTimelineIndex;
    SAFE_PARCEL(parcel->readUint64, &uintPreferredFrameTimelineIndex);
    preferredFrameTimelineIndex = static_cast<size_t>(uintPreferredFrameTimelineIndex);

    std::vector<FrameTimeline> timelines;
    SAFE_PARCEL(parcel->readParcelableVector, &timelines);
    std::copy_n(timelines.begin(), timelines.size(), frameTimelines.begin());

    return OK;
}
status_t VsyncEventData::writeToParcel(Parcel* parcel) const {
    SAFE_PARCEL(parcel->writeInt64, id)
    SAFE_PARCEL(parcel->writeInt64, deadlineTimestamp);
    SAFE_PARCEL(parcel->writeInt64, frameInterval);
    SAFE_PARCEL(parcel->writeUint64, preferredFrameTimelineIndex);
    SAFE_PARCEL(parcel->writeParcelableVector,
                std::vector(frameTimelines.begin(), frameTimelines.end()));

    return OK;
}
status_t VsyncEventData::FrameTimeline::readFromParcel(const Parcel* parcel) {
    if (parcel == nullptr) {
        ALOGE("%s: Null parcel", __func__);
        return BAD_VALUE;
    }

    SAFE_PARCEL(parcel->readInt64, &id)
    SAFE_PARCEL(parcel->readInt64, &deadlineTimestamp);
    SAFE_PARCEL(parcel->readInt64, &expectedPresentTime);

    return OK;
}
status_t VsyncEventData::FrameTimeline::writeToParcel(Parcel* parcel) const {
    SAFE_PARCEL(parcel->writeInt64, id);
    SAFE_PARCEL(parcel->writeInt64, deadlineTimestamp);
    SAFE_PARCEL(parcel->writeInt64, expectedPresentTime);

    return OK;
}

}; // namespace android::gui
+0 −35
Original line number Original line Diff line number Diff line
@@ -17,45 +17,10 @@
#include <gui/DisplayEventReceiver.h>
#include <gui/DisplayEventReceiver.h>
#include <utils/Log.h>
#include <utils/Log.h>
#include <utils/Looper.h>
#include <utils/Looper.h>
#include <array>


namespace android {
namespace android {
using FrameRateOverride = DisplayEventReceiver::Event::FrameRateOverride;
using FrameRateOverride = DisplayEventReceiver::Event::FrameRateOverride;


struct VsyncEventData {
    // The Vsync Id corresponsing to this vsync event. This will be used to
    // populate ISurfaceComposer::setFrameTimelineVsync and
    // SurfaceComposerClient::setFrameTimelineVsync
    int64_t id = FrameTimelineInfo::INVALID_VSYNC_ID;

    // The deadline in CLOCK_MONOTONIC that the app needs to complete its
    // frame by (both on the CPU and the GPU)
    int64_t deadlineTimestamp = std::numeric_limits<int64_t>::max();

    // The current frame interval in ns when this frame was scheduled.
    int64_t frameInterval = 0;

    struct FrameTimeline {
        // The Vsync Id corresponsing to this vsync event. This will be used to
        // populate ISurfaceComposer::setFrameTimelineVsync and
        // SurfaceComposerClient::setFrameTimelineVsync
        int64_t id = FrameTimelineInfo::INVALID_VSYNC_ID;

        // The deadline in CLOCK_MONOTONIC that the app needs to complete its
        // frame by (both on the CPU and the GPU)
        int64_t deadlineTimestamp = std::numeric_limits<int64_t>::max();

        // The anticipated Vsync present time.
        int64_t expectedPresentTime = 0;
    };

    // Sorted possible frame timelines.
    std::array<FrameTimeline, DisplayEventReceiver::kFrameTimelinesLength> frameTimelines;

    // Index into the frameTimelines that represents the platform's preferred frame timeline.
    size_t preferredFrameTimelineIndex = std::numeric_limits<size_t>::max();
};

class DisplayEventDispatcher : public LooperCallback {
class DisplayEventDispatcher : public LooperCallback {
public:
public:
    explicit DisplayEventDispatcher(
    explicit DisplayEventDispatcher(
+3 −3
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@


#include <binder/IInterface.h>
#include <binder/IInterface.h>
#include <gui/ISurfaceComposer.h>
#include <gui/ISurfaceComposer.h>
#include <gui/VsyncEventData.h>


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


@@ -34,6 +35,7 @@ namespace android {
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


using gui::IDisplayEventConnection;
using gui::IDisplayEventConnection;
using gui::VsyncEventData;


namespace gui {
namespace gui {
class BitTube;
class BitTube;
@@ -49,8 +51,6 @@ static inline constexpr uint32_t fourcc(char c1, char c2, char c3, char c4) {
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
class DisplayEventReceiver {
class DisplayEventReceiver {
public:
public:
    // Max amount of frame timelines is arbitrarily set to be reasonable.
    static constexpr int64_t kFrameTimelinesLength = 7;


    enum {
    enum {
        DISPLAY_EVENT_VSYNC = fourcc('v', 's', 'y', 'n'),
        DISPLAY_EVENT_VSYNC = fourcc('v', 's', 'y', 'n'),
@@ -85,7 +85,7 @@ public:
                nsecs_t expectedVSyncTimestamp __attribute__((aligned(8)));
                nsecs_t expectedVSyncTimestamp __attribute__((aligned(8)));
                nsecs_t deadlineTimestamp __attribute__((aligned(8)));
                nsecs_t deadlineTimestamp __attribute__((aligned(8)));
                int64_t vsyncId;
                int64_t vsyncId;
            } frameTimelines[kFrameTimelinesLength];
            } frameTimelines[VsyncEventData::kFrameTimelinesLength];
        };
        };


        struct Hotplug {
        struct Hotplug {
Loading