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

Commit 837fef2b authored by Alec Mouri's avatar Alec Mouri Committed by Automerger Merge Worker
Browse files

Merge "Support skipping CachedSet rendering based on invalidate() proximity"...

Merge "Support skipping CachedSet rendering based on invalidate() proximity" into sc-dev am: 8e80994d am: cd2463b9

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/14886619

Change-Id: Ib584b3ae224278c516033f3ee6524f2491b725db
parents b978893d cd2463b9
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -82,6 +82,9 @@ struct CompositionRefreshArgs {


    // The earliest time to send the present command to the HAL
    // The earliest time to send the present command to the HAL
    std::chrono::steady_clock::time_point earliestPresentTime;
    std::chrono::steady_clock::time_point earliestPresentTime;

    // The predicted next invalidation time
    std::optional<std::chrono::steady_clock::time_point> nextInvalidateTime;
};
};


} // namespace android::compositionengine
} // namespace android::compositionengine
+1 −1
Original line number Original line Diff line number Diff line
@@ -286,7 +286,7 @@ protected:
    virtual std::optional<base::unique_fd> composeSurfaces(
    virtual std::optional<base::unique_fd> composeSurfaces(
            const Region&, const compositionengine::CompositionRefreshArgs& refreshArgs) = 0;
            const Region&, const compositionengine::CompositionRefreshArgs& refreshArgs) = 0;
    virtual void postFramebuffer() = 0;
    virtual void postFramebuffer() = 0;
    virtual void renderCachedSets() = 0;
    virtual void renderCachedSets(const CompositionRefreshArgs&) = 0;
    virtual void chooseCompositionStrategy() = 0;
    virtual void chooseCompositionStrategy() = 0;
    virtual bool getSkipColorTransform() const = 0;
    virtual bool getSkipColorTransform() const = 0;
    virtual FrameFences presentAndGetFrameFences() = 0;
    virtual FrameFences presentAndGetFrameFences() = 0;
+1 −1
Original line number Original line Diff line number Diff line
@@ -93,7 +93,7 @@ public:
    std::optional<base::unique_fd> composeSurfaces(
    std::optional<base::unique_fd> composeSurfaces(
            const Region&, const compositionengine::CompositionRefreshArgs& refreshArgs) override;
            const Region&, const compositionengine::CompositionRefreshArgs& refreshArgs) override;
    void postFramebuffer() override;
    void postFramebuffer() override;
    void renderCachedSets() override;
    void renderCachedSets(const CompositionRefreshArgs&) override;
    void cacheClientCompositionRequests(uint32_t) override;
    void cacheClientCompositionRequests(uint32_t) override;


    // Testing
    // Testing
+4 −0
Original line number Original line Diff line number Diff line
@@ -98,6 +98,7 @@ public:
        mDrawFence = nullptr;
        mDrawFence = nullptr;
        mBlurLayer = nullptr;
        mBlurLayer = nullptr;
        mHolePunchLayer = nullptr;
        mHolePunchLayer = nullptr;
        mSkipCount = 0;


        mLayers.insert(mLayers.end(), other.mLayers.cbegin(), other.mLayers.cend());
        mLayers.insert(mLayers.end(), other.mLayers.cbegin(), other.mLayers.cend());
        Region boundingRegion;
        Region boundingRegion;
@@ -107,6 +108,8 @@ public:
        mVisibleRegion.orSelf(other.mVisibleRegion);
        mVisibleRegion.orSelf(other.mVisibleRegion);
    }
    }
    void incrementAge() { ++mAge; }
    void incrementAge() { ++mAge; }
    void incrementSkipCount() { mSkipCount++; }
    size_t getSkipCount() { return mSkipCount; }


    // Renders the cached set with the supplied output composition state.
    // Renders the cached set with the supplied output composition state.
    void render(renderengine::RenderEngine& re, TexturePool& texturePool,
    void render(renderengine::RenderEngine& re, TexturePool& texturePool,
@@ -155,6 +158,7 @@ private:
    Rect mBounds = Rect::EMPTY_RECT;
    Rect mBounds = Rect::EMPTY_RECT;
    Region mVisibleRegion;
    Region mVisibleRegion;
    size_t mAge = 0;
    size_t mAge = 0;
    size_t mSkipCount = 0;


    // TODO(b/190411067): This is a shared pointer only because CachedSets are copied into different
    // TODO(b/190411067): This is a shared pointer only because CachedSets are copied into different
    // containers in the Flattener. Logically this should have unique ownership otherwise.
    // containers in the Flattener. Logically this should have unique ownership otherwise.
+38 −5
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@
#include <compositionengine/impl/planner/CachedSet.h>
#include <compositionengine/impl/planner/CachedSet.h>
#include <compositionengine/impl/planner/LayerState.h>
#include <compositionengine/impl/planner/LayerState.h>


#include <chrono>
#include <numeric>
#include <numeric>
#include <vector>
#include <vector>


@@ -37,7 +38,35 @@ class Predictor;


class Flattener {
class Flattener {
public:
public:
    Flattener(renderengine::RenderEngine& renderEngine, bool enableHolePunch = false);
    struct CachedSetRenderSchedulingTunables {
        // This default assumes that rendering a cached set takes about 3ms. That time is then cut
        // in half - the next frame using the cached set would have the same workload, meaning that
        // composition cost is the same. This is best illustrated with the following example:
        //
        // Suppose we're at a 120hz cadence so SurfaceFlinger is budgeted 8.3ms per-frame. If
        // renderCachedSets costs 3ms, then two consecutive frames have timings:
        //
        // First frame: Start at 0ms, end at 6.8ms.
        // renderCachedSets: Start at 6.8ms, end at 9.8ms.
        // Second frame: Start at 9.8ms, end at 16.6ms.
        //
        // Now the second frame won't render a cached set afterwards, but the first frame didn't
        // really steal time from the second frame.
        static const constexpr std::chrono::nanoseconds kDefaultCachedSetRenderDuration = 1500us;

        static const constexpr size_t kDefaultMaxDeferRenderAttempts = 240;

        // Duration allocated for rendering a cached set. If we don't have enough time for rendering
        // a cached set, then rendering is deferred to another frame.
        const std::chrono::nanoseconds cachedSetRenderDuration;
        // Maximum of times that we defer rendering a cached set. If we defer rendering a cached set
        // too many times, then render it anyways so that future frames would benefit from the
        // flattened cached set.
        const size_t maxDeferRenderAttempts;
    };
    Flattener(renderengine::RenderEngine& renderEngine, bool enableHolePunch = false,
              std::optional<CachedSetRenderSchedulingTunables> cachedSetRenderSchedulingTunables =
                      std::nullopt);


    void setDisplaySize(ui::Size size) {
    void setDisplaySize(ui::Size size) {
        mDisplaySize = size;
        mDisplaySize = size;
@@ -48,16 +77,14 @@ public:
                                std::chrono::steady_clock::time_point now);
                                std::chrono::steady_clock::time_point now);


    // Renders the newest cached sets with the supplied output composition state
    // Renders the newest cached sets with the supplied output composition state
    void renderCachedSets(const OutputCompositionState& outputState);
    void renderCachedSets(const OutputCompositionState& outputState,
                          std::optional<std::chrono::steady_clock::time_point> renderDeadline);


    void dump(std::string& result) const;
    void dump(std::string& result) const;
    void dumpLayers(std::string& result) const;
    void dumpLayers(std::string& result) const;


    const std::optional<CachedSet>& getNewCachedSetForTesting() const { return mNewCachedSet; }
    const std::optional<CachedSet>& getNewCachedSetForTesting() const { return mNewCachedSet; }


protected:
    std::optional<CachedSet> mNewCachedSet;

private:
private:
    size_t calculateDisplayCost(const std::vector<const LayerState*>& layers) const;
    size_t calculateDisplayCost(const std::vector<const LayerState*>& layers) const;


@@ -149,9 +176,15 @@ private:


    renderengine::RenderEngine& mRenderEngine;
    renderengine::RenderEngine& mRenderEngine;
    const bool mEnableHolePunch;
    const bool mEnableHolePunch;
    const std::optional<CachedSetRenderSchedulingTunables> mCachedSetRenderSchedulingTunables;


    TexturePool mTexturePool;
    TexturePool mTexturePool;


protected:
    // mNewCachedSet must be destroyed before mTexturePool is.
    std::optional<CachedSet> mNewCachedSet;

private:
    ui::Size mDisplaySize;
    ui::Size mDisplaySize;


    NonBufferHash mCurrentGeometry;
    NonBufferHash mCurrentGeometry;
Loading