From 14ec50ada2b42e4ce9dbda53356f801140cb2bd7 Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Sat, 5 Feb 2022 21:52:17 -0800 Subject: [PATCH] Adds a GN flag for playgrounds (#7) --- impeller/aiks/aiks_playground.cc | 4 ++++ impeller/entity/entity_playground.cc | 4 ++++ impeller/playground/BUILD.gn | 8 ++++++++ impeller/playground/playground.h | 8 ++++++++ impeller/playground/playground.mm | 4 ++++ impeller/tools/impeller.gni | 5 +++++ 6 files changed, 33 insertions(+) diff --git a/impeller/aiks/aiks_playground.cc b/impeller/aiks/aiks_playground.cc index ff2513b31d584..572b761f83ab5 100644 --- a/impeller/aiks/aiks_playground.cc +++ b/impeller/aiks/aiks_playground.cc @@ -13,6 +13,10 @@ AiksPlayground::AiksPlayground() = default; AiksPlayground::~AiksPlayground() = default; bool AiksPlayground::OpenPlaygroundHere(const Picture& picture) { + if (!Playground::is_enabled()) { + return true; + } + AiksContext renderer(GetContext()); if (!renderer.IsValid()) { diff --git a/impeller/entity/entity_playground.cc b/impeller/entity/entity_playground.cc index 69e93b74751a4..4c76be6088bd4 100644 --- a/impeller/entity/entity_playground.cc +++ b/impeller/entity/entity_playground.cc @@ -13,6 +13,10 @@ EntityPlayground::EntityPlayground() = default; EntityPlayground::~EntityPlayground() = default; bool EntityPlayground::OpenPlaygroundHere(Entity entity) { + if (!Playground::is_enabled()) { + return true; + } + ContentContext context_context(GetContext()); if (!context_context.IsValid()) { return false; diff --git a/impeller/playground/BUILD.gn b/impeller/playground/BUILD.gn index c69165ec428ba..e1b38dfde4caa 100644 --- a/impeller/playground/BUILD.gn +++ b/impeller/playground/BUILD.gn @@ -21,6 +21,8 @@ impeller_component("playground") { "//third_party/glfw", ] + public_configs = [ ":playground_config" ] + if (is_mac) { frameworks = [ "AppKit.framework", @@ -28,3 +30,9 @@ impeller_component("playground") { ] } } + +config("playground_config") { + if (impeller_enable_playground) { + defines = [ "IMPELLER_ENABLE_PLAYGROUND" ] + } +} diff --git a/impeller/playground/playground.h b/impeller/playground/playground.h index fe83512e85464..b1779a624d956 100644 --- a/impeller/playground/playground.h +++ b/impeller/playground/playground.h @@ -19,6 +19,8 @@ class Playground : public ::testing::Test { ~Playground(); + static constexpr bool is_enabled() { return is_enabled_; } + Point GetCursorPosition() const; ISize GetWindowSize() const; @@ -31,6 +33,12 @@ class Playground : public ::testing::Test { const char* fixture_name) const; private: +#if IMPELLER_ENABLE_PLAYGROUND + static const bool is_enabled_ = true; +#else + static const bool is_enabled_ = false; +#endif // IMPELLER_ENABLE_PLAYGROUND + Renderer renderer_; Point cursor_position_; ISize window_size_ = ISize{1024, 768}; diff --git a/impeller/playground/playground.mm b/impeller/playground/playground.mm index 9918e9fe3faff..df4867ecaa423 100644 --- a/impeller/playground/playground.mm +++ b/impeller/playground/playground.mm @@ -81,6 +81,10 @@ static void PlaygroundKeyCallback(GLFWwindow* window, } bool Playground::OpenPlaygroundHere(Renderer::RenderCallback render_callback) { + if (!is_enabled()) { + return true; + } + if (!render_callback) { return true; } diff --git a/impeller/tools/impeller.gni b/impeller/tools/impeller.gni index 74a6e10af2826..2af17e3490405 100644 --- a/impeller/tools/impeller.gni +++ b/impeller/tools/impeller.gni @@ -5,6 +5,11 @@ import("//build/compiled_action.gni") import("//flutter/common/config.gni") +declare_args() { + # Whether playgrounds are enabled for unit tests. + impeller_enable_playground = false +} + template("impeller_component") { source_set(target_name) { forward_variables_from(invoker, "*")