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

Commit d75948ef authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 4954221 from 86b78a72 to qt-release

Change-Id: Ia1ee9c29486a6f53c0b905378bc0c812d3983b8a
parents cb3e9c3f 86b78a72
Loading
Loading
Loading
Loading
+1 −16
Original line number Diff line number Diff line
@@ -132,22 +132,7 @@ Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& n
    CompositorTiming compositorTiming;
    flinger->getCompositorTiming(&compositorTiming);
    mFrameEventHistory.initializeCompositorTiming(compositorTiming);
}

void Layer::onFirstRef() NO_THREAD_SAFETY_ANALYSIS {
    if (!isCreatedFromMainThread()) {
        // Grab the SF state lock during this since it's the only way to safely access HWC
        mFlinger->mStateLock.lock();
    }

    const auto& hwc = mFlinger->getHwComposer();
    const auto& activeConfig = hwc.getActiveConfig(HWC_DISPLAY_PRIMARY);
    nsecs_t displayPeriod = activeConfig->getVsyncPeriod();
    mFrameTracker.setDisplayRefreshPeriod(displayPeriod);

    if (!isCreatedFromMainThread()) {
        mFlinger->mStateLock.unlock();
    }
    mFrameTracker.setDisplayRefreshPeriod(compositorTiming.interval);
}

Layer::~Layer() {
+0 −2
Original line number Diff line number Diff line
@@ -604,8 +604,6 @@ protected:
              : mFlinger(flinger), mLayer(layer) {}
    };

    virtual void onFirstRef();

    friend class impl::SurfaceInterceptor;

    void commitTransaction(const State& stateToCommit);
+12 −15
Original line number Diff line number Diff line
@@ -16,8 +16,9 @@

#include "DispSyncSource.h"

#include <utils/Mutex.h>
#include <android-base/stringprintf.h>
#include <utils/Trace.h>
#include <mutex>

#include "DispSync.h"
#include "EventThread.h"
@@ -27,42 +28,38 @@ namespace android {
DispSyncSource::DispSyncSource(DispSync* dispSync, nsecs_t phaseOffset, bool traceVsync,
                               const char* name)
      : mName(name),
        mValue(0),
        mTraceVsync(traceVsync),
        mVsyncOnLabel(String8::format("VsyncOn-%s", name)),
        mVsyncEventLabel(String8::format("VSYNC-%s", name)),
        mVsyncOnLabel(base::StringPrintf("VsyncOn-%s", name)),
        mVsyncEventLabel(base::StringPrintf("VSYNC-%s", name)),
        mDispSync(dispSync),
        mCallbackMutex(),
        mVsyncMutex(),
        mPhaseOffset(phaseOffset),
        mEnabled(false) {}
        mPhaseOffset(phaseOffset) {}

void DispSyncSource::setVSyncEnabled(bool enable) {
    Mutex::Autolock lock(mVsyncMutex);
    std::lock_guard lock(mVsyncMutex);
    if (enable) {
        status_t err = mDispSync->addEventListener(mName, mPhaseOffset,
                                                   static_cast<DispSync::Callback*>(this));
        if (err != NO_ERROR) {
            ALOGE("error registering vsync callback: %s (%d)", strerror(-err), err);
        }
        // ATRACE_INT(mVsyncOnLabel.string(), 1);
        // ATRACE_INT(mVsyncOnLabel.c_str(), 1);
    } else {
        status_t err = mDispSync->removeEventListener(static_cast<DispSync::Callback*>(this));
        if (err != NO_ERROR) {
            ALOGE("error unregistering vsync callback: %s (%d)", strerror(-err), err);
        }
        // ATRACE_INT(mVsyncOnLabel.string(), 0);
        // ATRACE_INT(mVsyncOnLabel.c_str(), 0);
    }
    mEnabled = enable;
}

void DispSyncSource::setCallback(VSyncSource::Callback* callback) {
    Mutex::Autolock lock(mCallbackMutex);
    std::lock_guard lock(mCallbackMutex);
    mCallback = callback;
}

void DispSyncSource::setPhaseOffset(nsecs_t phaseOffset) {
    Mutex::Autolock lock(mVsyncMutex);
    std::lock_guard lock(mVsyncMutex);

    // Normalize phaseOffset to [0, period)
    auto period = mDispSync->getPeriod();
@@ -89,12 +86,12 @@ void DispSyncSource::setPhaseOffset(nsecs_t phaseOffset) {
void DispSyncSource::onDispSyncEvent(nsecs_t when) {
    VSyncSource::Callback* callback;
    {
        Mutex::Autolock lock(mCallbackMutex);
        std::lock_guard lock(mCallbackMutex);
        callback = mCallback;

        if (mTraceVsync) {
            mValue = (mValue + 1) % 2;
            ATRACE_INT(mVsyncEventLabel.string(), mValue);
            ATRACE_INT(mVsyncEventLabel.c_str(), mValue);
        }
    }

+10 −11
Original line number Diff line number Diff line
@@ -15,8 +15,8 @@
 */
#pragma once

#include <utils/Mutex.h>
#include <utils/String8.h>
#include <mutex>
#include <string>

#include "DispSync.h"
#include "EventThread.h"
@@ -39,21 +39,20 @@ private:
    virtual void onDispSyncEvent(nsecs_t when);

    const char* const mName;

    int mValue;
    int mValue = 0;

    const bool mTraceVsync;
    const String8 mVsyncOnLabel;
    const String8 mVsyncEventLabel;
    const std::string mVsyncOnLabel;
    const std::string mVsyncEventLabel;

    DispSync* mDispSync;

    Mutex mCallbackMutex; // Protects the following
    VSyncSource::Callback* mCallback = nullptr;
    std::mutex mCallbackMutex;
    VSyncSource::Callback* mCallback GUARDED_BY(mCallbackMutex) = nullptr;

    Mutex mVsyncMutex; // Protects the following
    nsecs_t mPhaseOffset;
    bool mEnabled;
    std::mutex mVsyncMutex;
    nsecs_t mPhaseOffset GUARDED_BY(mVsyncMutex);
    bool mEnabled GUARDED_BY(mVsyncMutex) = false;
};

} // namespace android
 No newline at end of file
+53 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 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.
 */

#pragma once

#include <mutex>

#include "EventThread.h"

namespace android {

/**
 * VSync signals used during SurfaceFlinger trace playback (traces we captured
 * with SurfaceInterceptor).
 */
class InjectVSyncSource final : public VSyncSource {
public:
    ~InjectVSyncSource() override = default;

    void setCallback(VSyncSource::Callback* callback) override {
        std::lock_guard<std::mutex> lock(mCallbackMutex);
        mCallback = callback;
    }

    void onInjectSyncEvent(nsecs_t when) {
        std::lock_guard<std::mutex> lock(mCallbackMutex);
        if (mCallback) {
            mCallback->onVSyncEvent(when);
        }
    }

    void setVSyncEnabled(bool) override {}
    void setPhaseOffset(nsecs_t) override {}

private:
    std::mutex mCallbackMutex;
    VSyncSource::Callback* mCallback GUARDED_BY(mCallbackMutex) = nullptr;
};

} // namespace android
 No newline at end of file
Loading