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

Commit 86b78a72 authored by Ana Krulec's avatar Ana Krulec Committed by Android (Google) Code Review
Browse files

Merge "SF: Moving InjectVSyncSource into it's own class"

parents d1b89db9 47454457
Loading
Loading
Loading
Loading
+53 −0
Original line number Original line 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
+1 −25
Original line number Original line Diff line number Diff line
@@ -88,6 +88,7 @@
#include "Scheduler/DispSyncSource.h"
#include "Scheduler/DispSyncSource.h"
#include "Scheduler/EventControlThread.h"
#include "Scheduler/EventControlThread.h"
#include "Scheduler/EventThread.h"
#include "Scheduler/EventThread.h"
#include "Scheduler/InjectVSyncSource.h"


#include <cutils/compiler.h>
#include <cutils/compiler.h>


@@ -566,31 +567,6 @@ void SurfaceFlinger::deleteTextureAsync(uint32_t texture) {
    postMessageAsync(new LambdaMessage([=] { getRenderEngine().deleteTextures(1, &texture); }));
    postMessageAsync(new LambdaMessage([=] { getRenderEngine().deleteTextures(1, &texture); }));
}
}


class InjectVSyncSource final : public VSyncSource {
public:
    InjectVSyncSource() = default;
    ~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; // Protects the following
    VSyncSource::Callback* mCallback = nullptr;
};

// Do not call property_set on main thread which will be blocked by init
// Do not call property_set on main thread which will be blocked by init
// Use StartPropertySetThread instead.
// Use StartPropertySetThread instead.
void SurfaceFlinger::init() {
void SurfaceFlinger::init() {