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

Commit d450a7f2 authored by Noelle Scobie's avatar Noelle Scobie
Browse files

Add ftl support to RenderEngine enums

Omitting the `k` enum prefix technically goes against Android's general
C++ guidelines, but allows ftl enum calls to be chained together while
remaining legible, e.g. "GraphiteVk" instead of "kGraphitekVk".
There appears to already be precedent where ftl enums are used.

An alternative to ftl (and the associated renaming of enum values) could
be to manually create helper toString functions, but that seems
unnecessary.

Bug: N/A
Test: compiles
Flag: EXEMPT refactor
Change-Id: I9c1e57882587eba3f88eab0f91248c2d79b2d145
parent 79ad3676
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@

#include <com_android_graphics_surfaceflinger_flags.h>
#include <cutils/properties.h>
#include <ftl/enum.h>
#include <log/log.h>

// TODO: b/341728634 - Clean up conditional compilation.
@@ -45,28 +46,28 @@ std::unique_ptr<RenderEngine> RenderEngine::create(const RenderEngineCreationArg
#if COMPILE_GRAPHITE_RENDERENGINE
    const RenderEngine::SkiaBackend actualSkiaBackend = args.skiaBackend;
#else
    if (args.skiaBackend == RenderEngine::SkiaBackend::GRAPHITE) {
    if (args.skiaBackend == RenderEngine::SkiaBackend::Graphite) {
        ALOGE("RenderEngine with Graphite Skia backend was requested, but Graphite was not "
              "included in the build. Falling back to Ganesh (%s)",
              args.graphicsApi == RenderEngine::GraphicsApi::GL ? "GL" : "Vulkan");
              ftl::enum_string(args.graphicsApi).c_str());
    }
    const RenderEngine::SkiaBackend actualSkiaBackend = RenderEngine::SkiaBackend::GANESH;
    const RenderEngine::SkiaBackend actualSkiaBackend = RenderEngine::SkiaBackend::Ganesh;
#endif

    ALOGD("%sRenderEngine with %s Backend (%s)", args.threaded == Threaded::YES ? "Threaded " : "",
          args.graphicsApi == GraphicsApi::GL ? "SkiaGL" : "SkiaVK",
          actualSkiaBackend == SkiaBackend::GANESH ? "Ganesh" : "Graphite");
    ALOGD("%sRenderEngine with Skia%s Backend (%s)",
          args.threaded == Threaded::Yes ? "Threaded " : "",
          ftl::enum_string(args.graphicsApi).c_str(), ftl::enum_string(actualSkiaBackend).c_str());

// TODO: b/341728634 - Clean up conditional compilation.
#if COMPILE_GRAPHITE_RENDERENGINE
    if (actualSkiaBackend == SkiaBackend::GRAPHITE) {
    if (actualSkiaBackend == SkiaBackend::Graphite) {
        createInstanceFactory = [args]() {
            return android::renderengine::skia::GraphiteVkRenderEngine::create(args);
        };
    } else
#endif
    { // GANESH
        if (args.graphicsApi == GraphicsApi::VK) {
        if (args.graphicsApi == GraphicsApi::Vk) {
            createInstanceFactory = [args]() {
                return android::renderengine::skia::GaneshVkRenderEngine::create(args);
            };
@@ -77,7 +78,7 @@ std::unique_ptr<RenderEngine> RenderEngine::create(const RenderEngineCreationArg
        }
    }

    if (args.threaded == Threaded::YES) {
    if (args.threaded == Threaded::Yes) {
        return renderengine::threaded::RenderEngineThreaded::create(createInstanceFactory);
    } else {
        return createInstanceFactory();
+9 −9
Original line number Diff line number Diff line
@@ -77,14 +77,14 @@ std::pair<uint32_t, uint32_t> getDisplaySize() {

static std::unique_ptr<RenderEngine> createRenderEngine(
        RenderEngine::Threaded threaded, RenderEngine::GraphicsApi graphicsApi,
        RenderEngine::BlurAlgorithm blurAlgorithm = RenderEngine::BlurAlgorithm::KAWASE) {
        RenderEngine::BlurAlgorithm blurAlgorithm = RenderEngine::BlurAlgorithm::Kawase) {
    auto args = RenderEngineCreationArgs::Builder()
                        .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888))
                        .setImageCacheSize(1)
                        .setEnableProtectedContext(true)
                        .setPrecacheToneMapperShaderOnly(false)
                        .setBlurAlgorithm(blurAlgorithm)
                        .setContextPriority(RenderEngine::ContextPriority::REALTIME)
                        .setContextPriority(RenderEngine::ContextPriority::Realtime)
                        .setThreaded(threaded)
                        .setGraphicsApi(graphicsApi)
                        .build();
@@ -310,16 +310,16 @@ void BM_homescreen_edgeExtension(benchmark::State& benchState, Args&&... args) {
    benchDrawLayers(*re, layers, benchState, "homescreen_edge_extension");
}

BENCHMARK_CAPTURE(BM_homescreen_blur, gaussian, RenderEngine::Threaded::YES,
                  RenderEngine::GraphicsApi::GL, RenderEngine::BlurAlgorithm::GAUSSIAN);
BENCHMARK_CAPTURE(BM_homescreen_blur, gaussian, RenderEngine::Threaded::Yes,
                  RenderEngine::GraphicsApi::GL, RenderEngine::BlurAlgorithm::Gaussian);

BENCHMARK_CAPTURE(BM_homescreen_blur, kawase, RenderEngine::Threaded::YES,
                  RenderEngine::GraphicsApi::GL, RenderEngine::BlurAlgorithm::KAWASE);
BENCHMARK_CAPTURE(BM_homescreen_blur, kawase, RenderEngine::Threaded::Yes,
                  RenderEngine::GraphicsApi::GL, RenderEngine::BlurAlgorithm::Kawase);

BENCHMARK_CAPTURE(BM_homescreen_blur, kawase_dual_filter, RenderEngine::Threaded::YES,
                  RenderEngine::GraphicsApi::GL, RenderEngine::BlurAlgorithm::KAWASE_DUAL_FILTER);
BENCHMARK_CAPTURE(BM_homescreen_blur, kawase_dual_filter, RenderEngine::Threaded::Yes,
                  RenderEngine::GraphicsApi::GL, RenderEngine::BlurAlgorithm::KawaseDualFilter);

BENCHMARK_CAPTURE(BM_homescreen, SkiaGLThreaded, RenderEngine::Threaded::YES,
BENCHMARK_CAPTURE(BM_homescreen, SkiaGLThreaded, RenderEngine::Threaded::Yes,
                  RenderEngine::GraphicsApi::GL);

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_EDGE_EXTENSION_SHADER
+34 −21
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#define SF_RENDERENGINE_H_

#include <android-base/unique_fd.h>
#include <ftl/enum.h>
#include <ftl/future.h>
#include <math/mat4.h>
#include <renderengine/DisplaySettings.h>
@@ -92,8 +93,10 @@ class ExternalTexture;
}

enum class Protection {
    UNPROTECTED = 1,
    PROTECTED = 2,
    Unprotected,
    Protected,

    ftl_last = Protected
};

// Toggles for skipping or enabling priming of particular shaders.
@@ -115,32 +118,42 @@ struct PrimeCacheConfig {
class RenderEngine {
public:
    enum class ContextPriority {
        LOW = 1,
        MEDIUM = 2,
        HIGH = 3,
        REALTIME = 4,
        Low,
        Medium,
        High,
        Realtime,

        ftl_last = Realtime
    };

    enum class Threaded {
        NO,
        YES,
        No,
        Yes,

        ftl_last = Yes
    };

    enum class GraphicsApi {
        GL,
        VK,
        Vk,

        ftl_last = Vk
    };

    enum class SkiaBackend {
        GANESH,
        GRAPHITE,
        Ganesh,
        Graphite,

        ftl_last = Graphite
    };

    enum class BlurAlgorithm {
        NONE,
        GAUSSIAN,
        KAWASE,
        KAWASE_DUAL_FILTER,
        None,
        Gaussian,
        Kawase,
        KawaseDualFilter,

        ftl_last = KawaseDualFilter
    };

    static std::unique_ptr<RenderEngine> create(const RenderEngineCreationArgs& args);
@@ -253,7 +266,7 @@ public:

    // TODO(b/180767535): This is only implemented to allow for backend-specific behavior, which
    // we should not allow in general, so remove this.
    bool isThreaded() const { return mThreaded == Threaded::YES; }
    bool isThreaded() const { return mThreaded == Threaded::Yes; }

    static void validateInputBufferUsage(const sp<GraphicBuffer>&);
    static void validateOutputBufferUsage(const sp<GraphicBuffer>&);
@@ -265,7 +278,7 @@ public:
    virtual void setEnableTracing(bool /*tracingEnabled*/) {}

protected:
    RenderEngine() : RenderEngine(Threaded::NO) {}
    RenderEngine() : RenderEngine(Threaded::No) {}

    RenderEngine(Threaded threaded) : mThreaded(threaded) {}

@@ -408,11 +421,11 @@ private:
    uint32_t imageCacheSize = 0;
    bool enableProtectedContext = false;
    bool precacheToneMapperShaderOnly = false;
    RenderEngine::BlurAlgorithm blurAlgorithm = RenderEngine::BlurAlgorithm::NONE;
    RenderEngine::ContextPriority contextPriority = RenderEngine::ContextPriority::MEDIUM;
    RenderEngine::Threaded threaded = RenderEngine::Threaded::YES;
    RenderEngine::BlurAlgorithm blurAlgorithm = RenderEngine::BlurAlgorithm::None;
    RenderEngine::ContextPriority contextPriority = RenderEngine::ContextPriority::Medium;
    RenderEngine::Threaded threaded = RenderEngine::Threaded::Yes;
    RenderEngine::GraphicsApi graphicsApi = RenderEngine::GraphicsApi::GL;
    RenderEngine::SkiaBackend skiaBackend = RenderEngine::SkiaBackend::GANESH;
    RenderEngine::SkiaBackend skiaBackend = RenderEngine::SkiaBackend::Ganesh;
};

} // namespace renderengine
+16 −16
Original line number Diff line number Diff line
@@ -174,12 +174,12 @@ std::unique_ptr<SkiaGLRenderEngine> SkiaGLRenderEngine::create(
    const std::optional<RenderEngine::ContextPriority> priority = createContextPriority(args);
    if (args.enableProtectedContext && extensions.hasProtectedContent()) {
        protectedContext =
                createEglContext(display, config, nullptr, priority, Protection::PROTECTED);
                createEglContext(display, config, nullptr, priority, Protection::Protected);
        ALOGE_IF(protectedContext == EGL_NO_CONTEXT, "Can't create protected context");
    }

    EGLContext ctxt =
            createEglContext(display, config, protectedContext, priority, Protection::UNPROTECTED);
            createEglContext(display, config, protectedContext, priority, Protection::Unprotected);

    // if can't create a GL context, we can only abort.
    LOG_ALWAYS_FATAL_IF(ctxt == EGL_NO_CONTEXT, "EGLContext creation failed");
@@ -187,7 +187,7 @@ std::unique_ptr<SkiaGLRenderEngine> SkiaGLRenderEngine::create(
    EGLSurface placeholder = EGL_NO_SURFACE;
    if (!extensions.hasSurfacelessContext()) {
        placeholder = createPlaceholderEglPbufferSurface(display, config, args.pixelFormat,
                                                         Protection::UNPROTECTED);
                                                         Protection::Unprotected);
        LOG_ALWAYS_FATAL_IF(placeholder == EGL_NO_SURFACE, "can't create placeholder pbuffer");
    }
    EGLBoolean success = eglMakeCurrent(display, placeholder, placeholder, ctxt);
@@ -198,7 +198,7 @@ std::unique_ptr<SkiaGLRenderEngine> SkiaGLRenderEngine::create(
    EGLSurface protectedPlaceholder = EGL_NO_SURFACE;
    if (protectedContext != EGL_NO_CONTEXT && !extensions.hasSurfacelessContext()) {
        protectedPlaceholder = createPlaceholderEglPbufferSurface(display, config, args.pixelFormat,
                                                                  Protection::PROTECTED);
                                                                  Protection::Protected);
        ALOGE_IF(protectedPlaceholder == EGL_NO_SURFACE,
                 "can't create protected placeholder pbuffer");
    }
@@ -461,22 +461,22 @@ EGLContext SkiaGLRenderEngine::createEglContext(EGLDisplay display, EGLConfig co
    if (contextPriority) {
        contextAttributes.push_back(EGL_CONTEXT_PRIORITY_LEVEL_IMG);
        switch (*contextPriority) {
            case ContextPriority::REALTIME:
            case ContextPriority::Realtime:
                contextAttributes.push_back(EGL_CONTEXT_PRIORITY_REALTIME_NV);
                break;
            case ContextPriority::MEDIUM:
            case ContextPriority::Medium:
                contextAttributes.push_back(EGL_CONTEXT_PRIORITY_MEDIUM_IMG);
                break;
            case ContextPriority::LOW:
            case ContextPriority::Low:
                contextAttributes.push_back(EGL_CONTEXT_PRIORITY_LOW_IMG);
                break;
            case ContextPriority::HIGH:
            case ContextPriority::High:
            default:
                contextAttributes.push_back(EGL_CONTEXT_PRIORITY_HIGH_IMG);
                break;
        }
    }
    if (protection == Protection::PROTECTED) {
    if (protection == Protection::Protected) {
        contextAttributes.push_back(EGL_PROTECTED_CONTENT_EXT);
        contextAttributes.push_back(EGL_TRUE);
    }
@@ -506,16 +506,16 @@ std::optional<RenderEngine::ContextPriority> SkiaGLRenderEngine::createContextPr
    }

    switch (args.contextPriority) {
        case RenderEngine::ContextPriority::REALTIME:
        case RenderEngine::ContextPriority::Realtime:
            if (GLExtensions::getInstance().hasRealtimePriority()) {
                return RenderEngine::ContextPriority::REALTIME;
                return RenderEngine::ContextPriority::Realtime;
            } else {
                ALOGI("Realtime priority unsupported, degrading gracefully to high priority");
                return RenderEngine::ContextPriority::HIGH;
                return RenderEngine::ContextPriority::High;
            }
        case RenderEngine::ContextPriority::HIGH:
        case RenderEngine::ContextPriority::MEDIUM:
        case RenderEngine::ContextPriority::LOW:
        case RenderEngine::ContextPriority::High:
        case RenderEngine::ContextPriority::Medium:
        case RenderEngine::ContextPriority::Low:
            return args.contextPriority;
        default:
            return std::nullopt;
@@ -535,7 +535,7 @@ EGLSurface SkiaGLRenderEngine::createPlaceholderEglPbufferSurface(EGLDisplay dis
    attributes.push_back(1);
    attributes.push_back(EGL_HEIGHT);
    attributes.push_back(1);
    if (protection == Protection::PROTECTED) {
    if (protection == Protection::Protected) {
        attributes.push_back(EGL_PROTECTED_CONTENT_EXT);
        attributes.push_back(EGL_TRUE);
    }
+3 −3
Original line number Diff line number Diff line
@@ -317,17 +317,17 @@ SkiaRenderEngine::SkiaRenderEngine(Threaded threaded, PixelFormat pixelFormat,
                                   BlurAlgorithm blurAlgorithm)
      : RenderEngine(threaded), mDefaultPixelFormat(pixelFormat) {
    switch (blurAlgorithm) {
        case BlurAlgorithm::GAUSSIAN: {
        case BlurAlgorithm::Gaussian: {
            ALOGD("Background Blurs Enabled (Gaussian algorithm)");
            mBlurFilter = new GaussianBlurFilter(mRuntimeEffectManager);
            break;
        }
        case BlurAlgorithm::KAWASE: {
        case BlurAlgorithm::Kawase: {
            ALOGD("Background Blurs Enabled (Kawase algorithm)");
            mBlurFilter = new KawaseBlurFilter(mRuntimeEffectManager);
            break;
        }
        case BlurAlgorithm::KAWASE_DUAL_FILTER: {
        case BlurAlgorithm::KawaseDualFilter: {
            ALOGD("Background Blurs Enabled (Kawase dual-filtering algorithm)");
            if (FlagManager::getInstance().window_blur_kawase2_fix_aliasing()) {
                mBlurFilter = new KawaseBlurDualFilterV2(mRuntimeEffectManager);
Loading