From 488101bf891623780e2f4d0eaacadc6d02e268f9 Mon Sep 17 00:00:00 2001 From: Nolan Scobie Date: Mon, 20 May 2024 13:32:13 -0400 Subject: [RenderEngine] Only compile Graphite if either Graphite flag is enabled RE-Graphite will be *compiled* if either the graphite_renderengine or force_compile_graphite_renderengine ready-only flag is enabled at compile time (inclusive OR). RE-Graphite can be compiled and *enabled* by: 1. setting just graphite_renderengine=true, or 2. setting both force_compile_graphite_renderengine=true and the debug.renderengine.graphite system property to true. Why RenderEngine needs a dep on libsurfaceflingerflags now: libsurfaceflinger_common pulls in SF's FlagManager, which is layered on top of the API that's autogenerated for SF's aconfig module, libsurfaceflingerflags. The COM_ANDROID_GRAPHICS_SURFACEFLINGER_FLAGS(...) macro is defined by com_android_graphics_surfaceflinger_flags.h in that latter aconfig module, and that header is not exported by the higher-level FlagManager code. Bug: b/293371537 Bug: b/331678326 Bug: b/341728634 Test: boot and bloaty (see b/331678326) Flag: com.android.graphics.surfaceflinger.flags.graphite_renderengine Change-Id: I9d0b15bda08430552716a9a1f7cd59d91ee7b9a6 --- libs/renderengine/Android.bp | 1 + libs/renderengine/RenderEngine.cpp | 31 +++++++++++++++++++++++++--- libs/renderengine/tests/Android.bp | 1 + libs/renderengine/tests/RenderEngineTest.cpp | 21 +++++++++++++++++-- 4 files changed, 49 insertions(+), 5 deletions(-) (limited to 'libs') diff --git a/libs/renderengine/Android.bp b/libs/renderengine/Android.bp index 757d935647..4a04467308 100644 --- a/libs/renderengine/Android.bp +++ b/libs/renderengine/Android.bp @@ -50,6 +50,7 @@ cc_defaults { "libshaders", "libtonemap", "libsurfaceflinger_common", + "libsurfaceflingerflags", ], local_include_dirs: ["include"], export_include_dirs: ["include"], diff --git a/libs/renderengine/RenderEngine.cpp b/libs/renderengine/RenderEngine.cpp index 1c60563b25..bc3976d9f1 100644 --- a/libs/renderengine/RenderEngine.cpp +++ b/libs/renderengine/RenderEngine.cpp @@ -22,24 +22,49 @@ #include "skia/SkiaGLRenderEngine.h" #include "threaded/RenderEngineThreaded.h" +#include #include #include +// TODO: b/341728634 - Clean up conditional compilation. +#if COM_ANDROID_GRAPHICS_SURFACEFLINGER_FLAGS(GRAPHITE_RENDERENGINE) || \ + COM_ANDROID_GRAPHICS_SURFACEFLINGER_FLAGS(FORCE_COMPILE_GRAPHITE_RENDERENGINE) +#define COMPILE_GRAPHITE_RENDERENGINE 1 +#else +#define COMPILE_GRAPHITE_RENDERENGINE 0 +#endif + namespace android { namespace renderengine { std::unique_ptr RenderEngine::create(const RenderEngineCreationArgs& args) { threaded::CreateInstanceFactory createInstanceFactory; +// TODO: b/341728634 - Clean up conditional compilation. +#if COMPILE_GRAPHITE_RENDERENGINE + const RenderEngine::SkiaBackend actualSkiaBackend = args.skiaBackend; +#else + 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"); + } + 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", - args.skiaBackend == SkiaBackend::GANESH ? "Ganesh" : "Graphite"); + actualSkiaBackend == SkiaBackend::GANESH ? "Ganesh" : "Graphite"); - if (args.skiaBackend == SkiaBackend::GRAPHITE) { +// TODO: b/341728634 - Clean up conditional compilation. +#if COMPILE_GRAPHITE_RENDERENGINE + if (actualSkiaBackend == SkiaBackend::GRAPHITE) { createInstanceFactory = [args]() { return android::renderengine::skia::GraphiteVkRenderEngine::create(args); }; - } else { // GANESH + } else +#endif + { // GANESH if (args.graphicsApi == GraphicsApi::VK) { createInstanceFactory = [args]() { return android::renderengine::skia::GaneshVkRenderEngine::create(args); diff --git a/libs/renderengine/tests/Android.bp b/libs/renderengine/tests/Android.bp index 0eea187407..06d543961b 100644 --- a/libs/renderengine/tests/Android.bp +++ b/libs/renderengine/tests/Android.bp @@ -46,6 +46,7 @@ cc_test { "libshaders", "libtonemap", "libsurfaceflinger_common", + "libsurfaceflingerflags", ], header_libs: [ "libtonemap_headers", diff --git a/libs/renderengine/tests/RenderEngineTest.cpp b/libs/renderengine/tests/RenderEngineTest.cpp index 4dcaff9ec8..a8a98236e2 100644 --- a/libs/renderengine/tests/RenderEngineTest.cpp +++ b/libs/renderengine/tests/RenderEngineTest.cpp @@ -22,6 +22,7 @@ #pragma clang diagnostic ignored "-Wconversion" #pragma clang diagnostic ignored "-Wextra" +#include #include #include #include @@ -41,6 +42,14 @@ #include "../skia/SkiaVkRenderEngine.h" #include "../threaded/RenderEngineThreaded.h" +// TODO: b/341728634 - Clean up conditional compilation. +#if COM_ANDROID_GRAPHICS_SURFACEFLINGER_FLAGS(GRAPHITE_RENDERENGINE) || \ + COM_ANDROID_GRAPHICS_SURFACEFLINGER_FLAGS(FORCE_COMPILE_GRAPHITE_RENDERENGINE) +#define COMPILE_GRAPHITE_RENDERENGINE 1 +#else +#define COMPILE_GRAPHITE_RENDERENGINE 0 +#endif + constexpr int DEFAULT_DISPLAY_WIDTH = 128; constexpr int DEFAULT_DISPLAY_HEIGHT = 256; constexpr int DEFAULT_DISPLAY_OFFSET = 64; @@ -152,6 +161,8 @@ public: } }; +// TODO: b/341728634 - Clean up conditional compilation. +#if COMPILE_GRAPHITE_RENDERENGINE class GraphiteVkRenderEngineFactory : public RenderEngineFactory { public: std::string name() override { return "GraphiteVkRenderEngineFactory"; } @@ -164,6 +175,7 @@ public: return renderengine::RenderEngine::SkiaBackend::GRAPHITE; } }; +#endif class RenderEngineTest : public ::testing::TestWithParam> { public: @@ -1497,10 +1509,15 @@ void RenderEngineTest::tonemap(ui::Dataspace sourceDataspace, std::function(), - std::make_shared(), - std::make_shared())); + std::make_shared() +#if COMPILE_GRAPHITE_RENDERENGINE + , + std::make_shared() +#endif + )); TEST_P(RenderEngineTest, drawLayers_noLayersToDraw) { if (!GetParam()->apiSupported()) { -- cgit v1.2.3-59-g8ed1b