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

Commit 9bc9dc69 authored by Ana Krulec's avatar Ana Krulec
Browse files

Creating a threaded version of the Render Engine.

This class contains a thread. Each time a function of this class is called,
we create a lambda function that is put on a queue. The main thread then
executes the functions in order.

In V1, all elements are passed by reference, and the main thread blocks on
the execution of this thread. In the future iterations, the lambda makes
copies of elements that should exist regardless of what happens to the thread
that calls into this thread.

go/speculative-render-engine for more info.

Test: Activate blur. Collect systrace.
Test: Open Chrome. Collect systrace.
Test: atest RenderEngineThreadedTest
Bug: 155929501
Change-Id: I246c6c1abb77a4c96c0867e722757326f8069b16
parent d29f327a
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -64,6 +64,13 @@ filegroup {
    ],
}

filegroup {
    name: "librenderengine_threaded_sources",
    srcs: [
        "threaded/RenderEngineThreaded.cpp",
    ],
}

cc_library_static {
    name: "librenderengine",
    defaults: ["librenderengine_defaults"],
@@ -80,6 +87,7 @@ cc_library_static {
    srcs: [
        ":librenderengine_sources",
        ":librenderengine_gl_sources",
        ":librenderengine_threaded_sources",
    ],
    lto: {
        thin: true,
+19 −5
Original line number Diff line number Diff line
@@ -20,20 +20,34 @@
#include <log/log.h>
#include <private/gui/SyncFeatures.h>
#include "gl/GLESRenderEngine.h"
#include "threaded/RenderEngineThreaded.h"

namespace android {
namespace renderengine {

std::unique_ptr<impl::RenderEngine> RenderEngine::create(const RenderEngineCreationArgs& args) {
    RenderEngineType renderEngineType = args.renderEngineType;

    // Keep the ability to override by PROPERTIES:
    char prop[PROPERTY_VALUE_MAX];
    property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, "gles");
    property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, "");
    if (strcmp(prop, "gles") == 0) {
        ALOGD("RenderEngine GLES Backend");
        return renderengine::gl::GLESRenderEngine::create(args);
        renderEngineType = RenderEngineType::GLES;
    }
    if (strcmp(prop, "threaded") == 0) {
        renderEngineType = RenderEngineType::THREADED;
    }
    ALOGE("UNKNOWN BackendType: %s, create GLES RenderEngine.", prop);

    switch (renderEngineType) {
        case RenderEngineType::THREADED:
            ALOGD("Threaded RenderEngine with GLES Backend");
            return renderengine::threaded::RenderEngineThreaded::create(args);
        case RenderEngineType::GLES:
        default:
            ALOGD("RenderEngine with GLES Backend");
            return renderengine::gl::GLESRenderEngine::create(args);
    }
}

RenderEngine::~RenderEngine() = default;

+30 −16
Original line number Diff line number Diff line
@@ -50,6 +50,10 @@ class Mesh;
class Texture;
struct RenderEngineCreationArgs;

namespace threaded {
class RenderEngineThreaded;
}

namespace impl {
class RenderEngine;
}
@@ -67,6 +71,11 @@ public:
        HIGH = 3,
    };

    enum class RenderEngineType {
        GLES = 1,
        THREADED = 2,
    };

    static std::unique_ptr<impl::RenderEngine> create(const RenderEngineCreationArgs& args);

    virtual ~RenderEngine() = 0;
@@ -174,6 +183,7 @@ protected:
    // live longer than RenderEngine.
    virtual Framebuffer* getFramebufferForDrawing() = 0;
    friend class BindNativeBufferAsFramebuffer;
    friend class threaded::RenderEngineThreaded;
};

struct RenderEngineCreationArgs {
@@ -184,26 +194,25 @@ struct RenderEngineCreationArgs {
    bool precacheToneMapperShaderOnly;
    bool supportsBackgroundBlur;
    RenderEngine::ContextPriority contextPriority;
    RenderEngine::RenderEngineType renderEngineType;

    struct Builder;

private:
    // must be created by Builder via constructor with full argument list
    RenderEngineCreationArgs(
            int _pixelFormat,
            uint32_t _imageCacheSize,
            bool _useColorManagement,
            bool _enableProtectedContext,
            bool _precacheToneMapperShaderOnly,
    RenderEngineCreationArgs(int _pixelFormat, uint32_t _imageCacheSize, bool _useColorManagement,
                             bool _enableProtectedContext, bool _precacheToneMapperShaderOnly,
                             bool _supportsBackgroundBlur,
            RenderEngine::ContextPriority _contextPriority)
        : pixelFormat(_pixelFormat)
        , imageCacheSize(_imageCacheSize)
        , useColorManagement(_useColorManagement)
        , enableProtectedContext(_enableProtectedContext)
        , precacheToneMapperShaderOnly(_precacheToneMapperShaderOnly)
        , supportsBackgroundBlur(_supportsBackgroundBlur)
        , contextPriority(_contextPriority) {}
                             RenderEngine::ContextPriority _contextPriority,
                             RenderEngine::RenderEngineType _renderEngineType)
          : pixelFormat(_pixelFormat),
            imageCacheSize(_imageCacheSize),
            useColorManagement(_useColorManagement),
            enableProtectedContext(_enableProtectedContext),
            precacheToneMapperShaderOnly(_precacheToneMapperShaderOnly),
            supportsBackgroundBlur(_supportsBackgroundBlur),
            contextPriority(_contextPriority),
            renderEngineType(_renderEngineType) {}
    RenderEngineCreationArgs() = delete;
};

@@ -238,10 +247,14 @@ struct RenderEngineCreationArgs::Builder {
        this->contextPriority = contextPriority;
        return *this;
    }
    Builder& setRenderEngineType(RenderEngine::RenderEngineType renderEngineType) {
        this->renderEngineType = renderEngineType;
        return *this;
    }
    RenderEngineCreationArgs build() const {
        return RenderEngineCreationArgs(pixelFormat, imageCacheSize, useColorManagement,
                                        enableProtectedContext, precacheToneMapperShaderOnly,
                                        supportsBackgroundBlur, contextPriority);
                                        supportsBackgroundBlur, contextPriority, renderEngineType);
    }

private:
@@ -253,6 +266,7 @@ private:
    bool precacheToneMapperShaderOnly = false;
    bool supportsBackgroundBlur = false;
    RenderEngine::ContextPriority contextPriority = RenderEngine::ContextPriority::MEDIUM;
    RenderEngine::RenderEngineType renderEngineType = RenderEngine::RenderEngineType::GLES;
};

class BindNativeBufferAsFramebuffer {
+2 −0
Original line number Diff line number Diff line
@@ -18,10 +18,12 @@ cc_test {
    test_suites: ["device-tests"],
    srcs: [
        "RenderEngineTest.cpp",
        "RenderEngineThreadedTest.cpp",
    ],
    static_libs: [
        "libgmock",
        "librenderengine",
        "librenderengine_mocks",
    ],
    shared_libs: [
        "libbase",
+11 −9
Original line number Diff line number Diff line
@@ -22,12 +22,13 @@
#include <condition_variable>
#include <fstream>

#include <gtest/gtest.h>
#include <cutils/properties.h>
#include <gtest/gtest.h>
#include <renderengine/RenderEngine.h>
#include <sync/sync.h>
#include <ui/PixelFormat.h>
#include "../gl/GLESRenderEngine.h"
#include "../threaded/RenderEngineThreaded.h"

constexpr int DEFAULT_DISPLAY_WIDTH = 128;
constexpr int DEFAULT_DISPLAY_HEIGHT = 256;
@@ -47,6 +48,7 @@ struct RenderEngineTest : public ::testing::Test {
                        .setPrecacheToneMapperShaderOnly(false)
                        .setSupportsBackgroundBlur(true)
                        .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM)
                        .setRenderEngineType(renderengine::RenderEngine::RenderEngineType::GLES)
                        .build());
    }

Loading