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

Commit 9cc667b4 authored by Dominik Laskowski's avatar Dominik Laskowski Committed by Android (Google) Code Review
Browse files

Merge changes I8e0076d3,Id39dab35 into main

* changes:
  SF: Add property to skip boot animation
  SF: Remove StartPropertySetThread
parents e4f2eb28 b0fdfe70
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -210,7 +210,6 @@ filegroup {
        "Scheduler/VsyncModulator.cpp",
        "Scheduler/VsyncSchedule.cpp",
        "ScreenCaptureOutput.cpp",
        "StartPropertySetThread.cpp",
        "SurfaceFlinger.cpp",
        "SurfaceFlingerDefaultFactory.cpp",
        "Tracing/LayerDataSource.cpp",
+0 −41
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 <cutils/properties.h>
#include "StartPropertySetThread.h"

namespace android {

StartPropertySetThread::StartPropertySetThread(bool timestampPropertyValue):
        Thread(false), mTimestampPropertyValue(timestampPropertyValue) {}

status_t StartPropertySetThread::Start() {
    return run("SurfaceFlinger::StartPropertySetThread", PRIORITY_NORMAL);
}

bool StartPropertySetThread::threadLoop() {
    // Set property service.sf.present_timestamp, consumer need check its readiness
    property_set(kTimestampProperty, mTimestampPropertyValue ? "1" : "0");
    // Clear BootAnimation exit flag
    property_set("service.bootanim.exit", "0");
    property_set("service.bootanim.progress", "0");
    // Start BootAnimation if not started
    property_set("ctl.start", "bootanim");
    // Exit immediately
    return false;
}

} // namespace android
+0 −46
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

#ifndef ANDROID_STARTBOOTANIMTHREAD_H
#define ANDROID_STARTBOOTANIMTHREAD_H

#include <stddef.h>

#include <utils/Mutex.h>
#include <utils/Thread.h>

namespace android {

class StartPropertySetThread : public Thread {
// Boot animation is triggered via calls to "property_set()" which can block
// if init's executing slow operation such as 'mount_all --late' (currently
// happening 1/10th with fsck)  concurrently. Running in a separate thread
// allows to pursue the SurfaceFlinger's init process without blocking.
// see b/34499826.
// Any property_set() will block during init stage so need to be offloaded
// to this thread. see b/63844978.
public:
    explicit StartPropertySetThread(bool timestampPropertyValue);
    status_t Start();
private:
    virtual bool threadLoop();
    static constexpr const char* kTimestampProperty = "service.sf.present_timestamp";
    const bool mTimestampPropertyValue;
};

}

#endif // ANDROID_STARTBOOTANIMTHREAD_H
+32 −26
Original line number Diff line number Diff line
@@ -153,7 +153,6 @@
#include "Scheduler/VsyncConfiguration.h"
#include "Scheduler/VsyncModulator.h"
#include "ScreenCaptureOutput.h"
#include "StartPropertySetThread.h"
#include "SurfaceFlingerProperties.h"
#include "TimeStats/TimeStats.h"
#include "TunnelModeEnabledReporter.h"
@@ -566,7 +565,14 @@ void SurfaceFlinger::binderDied(const wp<IBinder>&) {
        initializeDisplays();
    }));

    startBootAnim();
    std::lock_guard lock(mInitBootPropsFutureMutex);
    if (!mInitBootPropsFuture.valid()) {
        mInitBootPropsFuture =
                std::async(std::launch::async, &SurfaceFlinger::initBootProperties, this);
    }

    mInitBootPropsFuture.wait();
    mInitBootPropsFuture = {};
}

void SurfaceFlinger::run() {
@@ -722,13 +728,15 @@ void SurfaceFlinger::bootFinished() {
    }
    mBootFinished = true;
    FlagManager::getMutableInstance().markBootCompleted();
    if (mStartPropertySetThread->join() != NO_ERROR) {
        ALOGE("Join StartPropertySetThread failed!");
    }

    if (std::lock_guard lock(mInitBootPropsFutureMutex); mInitBootPropsFuture.valid()) {
        mInitBootPropsFuture.wait();
        mInitBootPropsFuture = {};
    }
    if (mRenderEnginePrimeCacheFuture.valid()) {
        mRenderEnginePrimeCacheFuture.get();
        mRenderEnginePrimeCacheFuture.wait();
    }

    const nsecs_t now = systemTime();
    const nsecs_t duration = now - mBootTime;
    ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) );
@@ -816,8 +824,6 @@ void chooseRenderEngineType(renderengine::RenderEngineCreationArgs::Builder& bui
    }
}

// Do not call property_set on main thread which will be blocked by init
// Use StartPropertySetThread instead.
void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) {
    ATRACE_CALL();
    ALOGI(  "SurfaceFlinger's main thread ready to run. "
@@ -928,18 +934,30 @@ void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) {
        }
    }

    // Inform native graphics APIs whether the present timestamp is supported:

    mStartPropertySetThread = getFactory().createStartPropertySetThread(mHasReliablePresentFences);

    if (mStartPropertySetThread->Start() != NO_ERROR) {
        ALOGE("Run StartPropertySetThread failed!");
    // Avoid blocking the main thread on `init` to set properties.
    if (std::lock_guard lock(mInitBootPropsFutureMutex); !mInitBootPropsFuture.valid()) {
        mInitBootPropsFuture =
                std::async(std::launch::async, &SurfaceFlinger::initBootProperties, this);
    }

    initTransactionTraceWriter();
    ALOGV("Done initializing");
}

// During boot, offload `initBootProperties` to another thread. `property_set` depends on
// `property_service`, which may be delayed by slow operations like `mount_all --late` in
// the `init` process. See b/34499826 and b/63844978.
void SurfaceFlinger::initBootProperties() {
    property_set("service.sf.present_timestamp", mHasReliablePresentFences ? "1" : "0");

    if (base::GetBoolProperty("debug.sf.boot_animation"s, true)) {
        // Reset and (if needed) start BootAnimation.
        property_set("service.bootanim.exit", "0");
        property_set("service.bootanim.progress", "0");
        property_set("ctl.start", "bootanim");
    }
}

void SurfaceFlinger::initTransactionTraceWriter() {
    if (!mTransactionTracing) {
        return;
@@ -979,18 +997,6 @@ void SurfaceFlinger::readPersistentProperties() {
            static_cast<ui::ColorMode>(base::GetIntProperty("persist.sys.sf.color_mode"s, 0));
}

void SurfaceFlinger::startBootAnim() {
    // Start boot animation service by setting a property mailbox
    // if property setting thread is already running, Start() will be just a NOP
    mStartPropertySetThread->Start();
    // Wait until property was set
    if (mStartPropertySetThread->join() != NO_ERROR) {
        ALOGE("Join StartPropertySetThread failed!");
    }
}

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

status_t SurfaceFlinger::getSupportedFrameTimestamps(
        std::vector<FrameEvent>* outSupported) const {
    *outSupported = {
+9 −5
Original line number Diff line number Diff line
@@ -550,7 +550,7 @@ private:
            bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks,
            uint64_t transactionId, const std::vector<uint64_t>& mergedTransactionIds) override;
    void bootFinished();
    virtual status_t getSupportedFrameTimestamps(std::vector<FrameEvent>* outSupported) const;
    status_t getSupportedFrameTimestamps(std::vector<FrameEvent>* outSupported) const;
    sp<IDisplayEventConnection> createDisplayEventConnection(
            gui::ISurfaceComposer::VsyncSource vsyncSource =
                    gui::ISurfaceComposer::VsyncSource::eVsyncSourceApp,
@@ -871,9 +871,6 @@ private:
    // Traverse through all the layers and compute and cache its bounds.
    void computeLayerBounds();

    // Boot animation, on/off animations and screen capture
    void startBootAnim();

    bool layersHasProtectedLayer(const std::vector<std::pair<Layer*, sp<LayerFE>>>& layers) const;

    void captureScreenCommon(RenderAreaFuture, GetLayerSnapshotsFunction, ui::Size bufferSize,
@@ -1184,10 +1181,17 @@ private:
    ui::Rotation getPhysicalDisplayOrientation(DisplayId, bool isPrimary) const
            REQUIRES(mStateLock);
    void traverseLegacyLayers(const LayerVector::Visitor& visitor) const;

    void initBootProperties();
    void initTransactionTraceWriter();
    sp<StartPropertySetThread> mStartPropertySetThread;

    surfaceflinger::Factory& mFactory;
    pid_t mPid;

    // TODO: b/328459745 - Encapsulate in a SystemProperties object.
    std::mutex mInitBootPropsFutureMutex;
    std::future<void> mInitBootPropsFuture GUARDED_BY(mInitBootPropsFutureMutex);

    std::future<void> mRenderEnginePrimeCacheFuture;

    // mStateLock has conventions related to the current thread, because only
Loading