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

Commit 576e77f9 authored by Nolan Scobie's avatar Nolan Scobie
Browse files

Add support for enabling GraphiteVkRenderEngine in SurfaceFlinger

Predicated on just the graphite_renderengine flag (overridable with
the debug.renderengine.graphite sysprops), which inherently implies
GraphicsApi::VK.

As currently implemented, setting the old debug.renderengine.backend
sysprop (e.g. "skiavkthreaded") will fully override this logic,
preventing Graphite from being enabled. This approach is simpler, but
also maintains backwards compatibility, and distances the new approach
from that restrictive terminology.

Note that the approach for actually instantiating a RenderEngine
instance extends the existing RenderEngine::create(args) model, forcing
the caller to know exactly which concrete subclass they wish to
instantiate. This could be reworked in the future.

Test: local validation (sysprops + logs)
Bug: b/293371537
Change-Id: Iff0a8894725fc45e679074ddc2e4af56cca318c6
parent 4b292195
Loading
Loading
Loading
Loading
+28 −23
Original line number Diff line number Diff line
@@ -16,40 +16,45 @@

#include <renderengine/RenderEngine.h>

#include <cutils/properties.h>
#include <log/log.h>
#include "renderengine/ExternalTexture.h"
#include "skia/GaneshVkRenderEngine.h"
#include "skia/GraphiteVkRenderEngine.h"
#include "skia/SkiaGLRenderEngine.h"
#include "threaded/RenderEngineThreaded.h"

#include "skia/SkiaGLRenderEngine.h"
#include "skia/SkiaVkRenderEngine.h"
#include <cutils/properties.h>
#include <log/log.h>

namespace android {
namespace renderengine {

std::unique_ptr<RenderEngine> RenderEngine::create(const RenderEngineCreationArgs& args) {
    if (args.threaded == Threaded::YES) {
        switch (args.graphicsApi) {
            case GraphicsApi::GL:
                ALOGD("Threaded RenderEngine with SkiaGL Backend");
                return renderengine::threaded::RenderEngineThreaded::create([args]() {
    threaded::CreateInstanceFactory createInstanceFactory;

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

    if (args.skiaBackend == SkiaBackend::GRAPHITE) {
        createInstanceFactory = [args]() {
            return android::renderengine::skia::GraphiteVkRenderEngine::create(args);
        };
    } else { // GANESH
        if (args.graphicsApi == GraphicsApi::VK) {
            createInstanceFactory = [args]() {
                return android::renderengine::skia::GaneshVkRenderEngine::create(args);
            };
        } else { // GL
            createInstanceFactory = [args]() {
                return android::renderengine::skia::SkiaGLRenderEngine::create(args);
                });
            case GraphicsApi::VK:
                ALOGD("Threaded RenderEngine with SkiaVK Backend");
                return renderengine::threaded::RenderEngineThreaded::create([args]() {
                    return android::renderengine::skia::SkiaVkRenderEngine::create(args);
                });
            };
        }
    }

    switch (args.graphicsApi) {
        case GraphicsApi::GL:
            ALOGD("RenderEngine with SkiaGL Backend");
            return renderengine::skia::SkiaGLRenderEngine::create(args);
        case GraphicsApi::VK:
            ALOGD("RenderEngine with SkiaVK Backend");
            return renderengine::skia::SkiaVkRenderEngine::create(args);
    if (args.threaded == Threaded::YES) {
        return renderengine::threaded::RenderEngineThreaded::create(createInstanceFactory);
    } else {
        return createInstanceFactory();
    }
}

+16 −3
Original line number Diff line number Diff line
@@ -102,6 +102,11 @@ public:
        VK,
    };

    enum class SkiaBackend {
        GANESH,
        GRAPHITE,
    };

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

    static bool canSupport(GraphicsApi);
@@ -257,6 +262,7 @@ struct RenderEngineCreationArgs {
    RenderEngine::ContextPriority contextPriority;
    RenderEngine::Threaded threaded;
    RenderEngine::GraphicsApi graphicsApi;
    RenderEngine::SkiaBackend skiaBackend;

    struct Builder;

@@ -267,7 +273,8 @@ private:
                             bool _supportsBackgroundBlur,
                             RenderEngine::ContextPriority _contextPriority,
                             RenderEngine::Threaded _threaded,
                             RenderEngine::GraphicsApi _graphicsApi)
                             RenderEngine::GraphicsApi _graphicsApi,
                             RenderEngine::SkiaBackend _skiaBackend)
          : pixelFormat(_pixelFormat),
            imageCacheSize(_imageCacheSize),
            enableProtectedContext(_enableProtectedContext),
@@ -275,7 +282,8 @@ private:
            supportsBackgroundBlur(_supportsBackgroundBlur),
            contextPriority(_contextPriority),
            threaded(_threaded),
            graphicsApi(_graphicsApi) {}
            graphicsApi(_graphicsApi),
            skiaBackend(_skiaBackend) {}
    RenderEngineCreationArgs() = delete;
};

@@ -314,10 +322,14 @@ struct RenderEngineCreationArgs::Builder {
        this->graphicsApi = graphicsApi;
        return *this;
    }
    Builder& setSkiaBackend(RenderEngine::SkiaBackend skiaBackend) {
        this->skiaBackend = skiaBackend;
        return *this;
    }
    RenderEngineCreationArgs build() const {
        return RenderEngineCreationArgs(pixelFormat, imageCacheSize, enableProtectedContext,
                                        precacheToneMapperShaderOnly, supportsBackgroundBlur,
                                        contextPriority, threaded, graphicsApi);
                                        contextPriority, threaded, graphicsApi, skiaBackend);
    }

private:
@@ -330,6 +342,7 @@ private:
    RenderEngine::ContextPriority contextPriority = RenderEngine::ContextPriority::MEDIUM;
    RenderEngine::Threaded threaded = RenderEngine::Threaded::YES;
    RenderEngine::GraphicsApi graphicsApi = RenderEngine::GraphicsApi::GL;
    RenderEngine::SkiaBackend skiaBackend = RenderEngine::SkiaBackend::GANESH;
};

} // namespace renderengine
+16 −0
Original line number Diff line number Diff line
@@ -27,6 +27,22 @@

namespace android::renderengine::skia {

std::unique_ptr<GaneshVkRenderEngine> GaneshVkRenderEngine::create(
        const RenderEngineCreationArgs& args) {
    std::unique_ptr<GaneshVkRenderEngine> engine(new GaneshVkRenderEngine(args));
    engine->ensureContextsCreated();

    if (getVulkanInterface(false).isInitialized()) {
        ALOGD("GaneshVkRenderEngine::%s: successfully initialized GaneshVkRenderEngine", __func__);
        return engine;
    } else {
        ALOGE("GaneshVkRenderEngine::%s: could not create GaneshVkRenderEngine. "
              "Likely insufficient Vulkan support",
              __func__);
        return {};
    }
}

// Ganesh-specific function signature for fFinishedProc callback.
static void unref_semaphore(void* semaphore) {
    SkiaVkRenderEngine::DestroySemaphoreInfo* info =
+5 −4
Original line number Diff line number Diff line
@@ -21,15 +21,16 @@
namespace android::renderengine::skia {

class GaneshVkRenderEngine : public SkiaVkRenderEngine {
    friend std::unique_ptr<SkiaVkRenderEngine> SkiaVkRenderEngine::create(
            const RenderEngineCreationArgs& args);
public:
    static std::unique_ptr<GaneshVkRenderEngine> create(const RenderEngineCreationArgs& args);

protected:
    GaneshVkRenderEngine(const RenderEngineCreationArgs& args) : SkiaVkRenderEngine(args) {}

    std::unique_ptr<SkiaGpuContext> createContext(VulkanInterface& vulkanInterface) override;
    void waitFence(SkiaGpuContext* context, base::borrowed_fd fenceFd) override;
    base::unique_fd flushAndSubmit(SkiaGpuContext* context, sk_sp<SkSurface> dstSurface) override;

private:
    GaneshVkRenderEngine(const RenderEngineCreationArgs& args) : SkiaVkRenderEngine(args) {}
};

} // namespace android::renderengine::skia
+17 −0
Original line number Diff line number Diff line
@@ -32,6 +32,23 @@

namespace android::renderengine::skia {

std::unique_ptr<GraphiteVkRenderEngine> GraphiteVkRenderEngine::create(
        const RenderEngineCreationArgs& args) {
    std::unique_ptr<GraphiteVkRenderEngine> engine(new GraphiteVkRenderEngine(args));
    engine->ensureContextsCreated();

    if (getVulkanInterface(false).isInitialized()) {
        ALOGD("GraphiteVkRenderEngine::%s: successfully initialized GraphiteVkRenderEngine",
              __func__);
        return engine;
    } else {
        ALOGE("GraphiteVkRenderEngine::%s: could not create GraphiteVkRenderEngine. "
              "Likely insufficient Vulkan support",
              __func__);
        return {};
    }
}

// Graphite-specific function signature for fFinishedProc callback.
static void unref_semaphore(void* semaphore, skgpu::CallbackResult result) {
    if (result != skgpu::CallbackResult::kSuccess) {
Loading