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

Commit 8ddb04ea authored by Chong Zhang's avatar Chong Zhang
Browse files

Add a flag to create renderengine for video use

Media uses renderengine to do HDR to SDR tone mapping
for thumbnail extraction. It only needs a few shaders.
Currently primeCache primes many shaders but none of
the ones media uses.

Add a flag to only prime the HDR->SDR shaders with
the settings that matches media usage.

bug: 135717526
bug: 140894732

Change-Id: I89b488d7c53351b13414adf71af28efd3232ecc6
parent 72f94e1d
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -457,8 +457,10 @@ Framebuffer* GLESRenderEngine::getFramebufferForDrawing() {
}

void GLESRenderEngine::primeCache() const {
    ProgramCache::getInstance().primeCache(mInProtectedContext ? mProtectedEGLContext : mEGLContext,
                                           mFeatureFlags & USE_COLOR_MANAGEMENT);
    ProgramCache::getInstance().primeCache(
            mInProtectedContext ? mProtectedEGLContext : mEGLContext,
                    mFeatureFlags & USE_COLOR_MANAGEMENT,
                    mFeatureFlags & PRECACHE_TONE_MAPPER_SHADER_ONLY);
}

base::unique_fd GLESRenderEngine::flush() {
+30 −1
Original line number Diff line number Diff line
@@ -77,9 +77,38 @@ Formatter& dedent(Formatter& f) {
    return f;
}

void ProgramCache::primeCache(EGLContext context, bool useColorManagement) {
void ProgramCache::primeCache(
        EGLContext context, bool useColorManagement, bool toneMapperShaderOnly) {
    auto& cache = mCaches[context];
    uint32_t shaderCount = 0;

    if (toneMapperShaderOnly) {
        Key shaderKey;
        // base settings used by HDR->SDR tonemap only
        shaderKey.set(Key::BLEND_MASK | Key::INPUT_TRANSFORM_MATRIX_MASK |
                      Key::OUTPUT_TRANSFORM_MATRIX_MASK | Key::OUTPUT_TF_MASK |
                      Key::OPACITY_MASK | Key::ALPHA_MASK |
                      Key::ROUNDED_CORNERS_MASK | Key::TEXTURE_MASK,
                      Key::BLEND_NORMAL | Key::INPUT_TRANSFORM_MATRIX_ON |
                      Key::OUTPUT_TRANSFORM_MATRIX_ON | Key::OUTPUT_TF_SRGB |
                      Key::OPACITY_OPAQUE | Key::ALPHA_EQ_ONE |
                      Key::ROUNDED_CORNERS_OFF | Key::TEXTURE_EXT);
        for (int i = 0; i < 4; i++) {
            // Cache input transfer for HLG & ST2084
            shaderKey.set(Key::INPUT_TF_MASK, (i & 1) ?
                    Key::INPUT_TF_HLG : Key::INPUT_TF_ST2084);

            // Cache Y410 input on or off
            shaderKey.set(Key::Y410_BT2020_MASK, (i & 2) ?
                    Key::Y410_BT2020_ON : Key::Y410_BT2020_OFF);
            if (cache.count(shaderKey) == 0) {
                cache.emplace(shaderKey, generateProgram(shaderKey));
                shaderCount++;
            }
        }
        return;
    }

    uint32_t keyMask = Key::BLEND_MASK | Key::OPACITY_MASK | Key::ALPHA_MASK | Key::TEXTURE_MASK
        | Key::ROUNDED_CORNERS_MASK;
    // Prime the cache for all combinations of the above masks,
+1 −1
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ public:
    ~ProgramCache() = default;

    // Generate shaders to populate the cache
    void primeCache(const EGLContext context, bool useColorManagement);
    void primeCache(const EGLContext context, bool useColorManagement, bool toneMapperShaderOnly);

    size_t getSize(const EGLContext context) { return mCaches[context].size(); }

+3 −0
Original line number Diff line number Diff line
@@ -66,6 +66,9 @@ public:

        // Create a protected context when if possible
        ENABLE_PROTECTED_CONTEXT = 1 << 2,

        // Only precache HDR to SDR tone-mapping shaders
        PRECACHE_TONE_MAPPER_SHADER_ONLY = 1 << 3,
    };

    static std::unique_ptr<impl::RenderEngine> create(int hwcFormat, uint32_t featureFlags,