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

Commit c16a77dd authored by Alec Mouri's avatar Alec Mouri
Browse files

Support caching of {LinearEffect, SkRuntimeEffect} pairs

RenderEngine cpu-time when doing tone mapping goes down from 40ms to
~13ms now that effect compilation is only done once.

Bug: 164223050
Test: Youtube HDR
Change-Id: I61e8a6795908078152d66333a62e179f8bbe2030
parent c7f6c8b4
Loading
Loading
Loading
Loading
+10 −1
Original line number Original line Diff line number Diff line
@@ -638,7 +638,16 @@ status_t SkiaGLRenderEngine::drawLayers(const DisplaySettings& display,
                                                   .outputDataspace = display.outputDataspace,
                                                   .outputDataspace = display.outputDataspace,
                                                   .undoPremultipliedAlpha = !item.isOpaque &&
                                                   .undoPremultipliedAlpha = !item.isOpaque &&
                                                           item.usePremultipliedAlpha};
                                                           item.usePremultipliedAlpha};
                sk_sp<SkRuntimeEffect> runtimeEffect = buildRuntimeEffect(effect);

                auto effectIter = mRuntimeEffects.find(effect);
                sk_sp<SkRuntimeEffect> runtimeEffect = nullptr;
                if (effectIter == mRuntimeEffects.end()) {
                    runtimeEffect = buildRuntimeEffect(effect);
                    mRuntimeEffects.insert({effect, runtimeEffect});
                } else {
                    runtimeEffect = effectIter->second;
                }

                paint.setShader(createLinearEffectShader(shader, effect, runtimeEffect,
                paint.setShader(createLinearEffectShader(shader, effect, runtimeEffect,
                                                         display.maxLuminance,
                                                         display.maxLuminance,
                                                         layer->source.buffer.maxMasteringLuminance,
                                                         layer->source.buffer.maxMasteringLuminance,
+2 −0
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@
#include "SkiaRenderEngine.h"
#include "SkiaRenderEngine.h"
#include "android-base/macros.h"
#include "android-base/macros.h"
#include "filters/BlurFilter.h"
#include "filters/BlurFilter.h"
#include "skia/filters/LinearEffect.h"


namespace android {
namespace android {
namespace renderengine {
namespace renderengine {
@@ -100,6 +101,7 @@ private:
            GUARDED_BY(mRenderingMutex);
            GUARDED_BY(mRenderingMutex);
    std::unordered_map<uint64_t, std::shared_ptr<AutoBackendTexture::LocalRef>>
    std::unordered_map<uint64_t, std::shared_ptr<AutoBackendTexture::LocalRef>>
            mProtectedTextureCache GUARDED_BY(mRenderingMutex);
            mProtectedTextureCache GUARDED_BY(mRenderingMutex);
    std::unordered_map<LinearEffect, sk_sp<SkRuntimeEffect>, LinearEffectHasher> mRuntimeEffects;
    // Mutex guarding rendering operations, so that:
    // Mutex guarding rendering operations, so that:
    // 1. GL operations aren't interleaved, and
    // 1. GL operations aren't interleaved, and
    // 2. Internal state related to rendering that is potentially modified by
    // 2. Internal state related to rendering that is potentially modified by
+18 −0
Original line number Original line Diff line number Diff line
@@ -63,6 +63,24 @@ struct LinearEffect {
    const bool undoPremultipliedAlpha = false;
    const bool undoPremultipliedAlpha = false;
};
};


static inline bool operator==(const LinearEffect& lhs, const LinearEffect& rhs) {
    return lhs.inputDataspace == rhs.inputDataspace && lhs.outputDataspace == rhs.outputDataspace &&
            lhs.undoPremultipliedAlpha == rhs.undoPremultipliedAlpha;
}

struct LinearEffectHasher {
    // Inspired by art/runtime/class_linker.cc
    // Also this is what boost:hash_combine does
    static size_t HashCombine(size_t seed, size_t val) {
        return seed ^ (val + 0x9e3779b9 + (seed << 6) + (seed >> 2));
    }
    size_t operator()(const LinearEffect& le) const {
        size_t result = std::hash<ui::Dataspace>{}(le.inputDataspace);
        result = HashCombine(result, std::hash<ui::Dataspace>{}(le.outputDataspace));
        return HashCombine(result, std::hash<bool>{}(le.undoPremultipliedAlpha));
    }
};

sk_sp<SkRuntimeEffect> buildRuntimeEffect(const LinearEffect& linearEffect);
sk_sp<SkRuntimeEffect> buildRuntimeEffect(const LinearEffect& linearEffect);


// Generates a shader resulting from applying the a linear effect created from
// Generates a shader resulting from applying the a linear effect created from