Skip to content

Commit

Permalink
Adds a GN flag for playgrounds (flutter#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanderso authored and dnfield committed Apr 27, 2022
1 parent e982526 commit 14ec50a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions impeller/aiks/aiks_playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
4 changes: 4 additions & 0 deletions impeller/entity/entity_playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions impeller/playground/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ impeller_component("playground") {
"//third_party/glfw",
]

public_configs = [ ":playground_config" ]

if (is_mac) {
frameworks = [
"AppKit.framework",
"QuartzCore.framework",
]
}
}

config("playground_config") {
if (impeller_enable_playground) {
defines = [ "IMPELLER_ENABLE_PLAYGROUND" ]
}
}
8 changes: 8 additions & 0 deletions impeller/playground/playground.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Playground : public ::testing::Test {

~Playground();

static constexpr bool is_enabled() { return is_enabled_; }

Point GetCursorPosition() const;

ISize GetWindowSize() const;
Expand All @@ -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};
Expand Down
4 changes: 4 additions & 0 deletions impeller/playground/playground.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions impeller/tools/impeller.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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, "*")
Expand Down

0 comments on commit 14ec50a

Please sign in to comment.