From 0016e4808ecfbfa42fd38e8fa3f49c5f4f7f52ff Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Tue, 28 Dec 2021 17:33:08 -0800 Subject: [PATCH] Allow resizing the playground. --- impeller/playground/playground.h | 3 +++ impeller/playground/playground.mm | 25 ++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/impeller/playground/playground.h b/impeller/playground/playground.h index 1d35b1c9b07e8..fe83512e85464 100644 --- a/impeller/playground/playground.h +++ b/impeller/playground/playground.h @@ -33,9 +33,12 @@ class Playground : public ::testing::Test { private: Renderer renderer_; Point cursor_position_; + ISize window_size_ = ISize{1024, 768}; void SetCursorPosition(Point pos); + void SetWindowSize(ISize size); + FML_DISALLOW_COPY_AND_ASSIGN(Playground); }; diff --git a/impeller/playground/playground.mm b/impeller/playground/playground.mm index d79740cb8dbdc..68b67eac350a5 100644 --- a/impeller/playground/playground.mm +++ b/impeller/playground/playground.mm @@ -78,7 +78,7 @@ static void PlaygroundKeyCallback(GLFWwindow* window, } ISize Playground::GetWindowSize() const { - return {1024, 768}; + return window_size_; } void Playground::SetCursorPosition(Point pos) { @@ -100,10 +100,6 @@ static void PlaygroundKeyCallback(GLFWwindow* window, fml::ScopedCleanupClosure terminate([]() { ::glfwTerminate(); }); ::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); - // Recreation of the target render buffer is not setup in the playground yet. - // So prevent users from resizing and getting confused that their math is - // wrong. - ::glfwWindowHint(GLFW_RESIZABLE, false); auto window_title = GetWindowTitle(flutter::testing::GetCurrentTestName()); auto window = @@ -114,6 +110,16 @@ static void PlaygroundKeyCallback(GLFWwindow* window, } ::glfwSetWindowUserPointer(window, this); + ::glfwSetWindowSizeCallback( + window, [](GLFWwindow* window, int width, int height) -> void { + auto playground = + reinterpret_cast(::glfwGetWindowUserPointer(window)); + if (!playground) { + return; + } + playground->SetWindowSize( + ISize{std::max(width, 0), std::max(height, 0)}); + }); ::glfwSetKeyCallback(window, &PlaygroundKeyCallback); ::glfwSetCursorPosCallback(window, [](GLFWwindow* window, double x, double y) { @@ -138,6 +144,11 @@ static void PlaygroundKeyCallback(GLFWwindow* window, return true; } + const auto layer_size = layer.bounds.size; + const auto layer_scale = layer.contentsScale; + layer.drawableSize = CGSizeMake(layer_size.width * layer_scale, + layer_size.height * layer_scale); + Renderer::RenderCallback wrapped_callback = [render_callback](auto& pass) { pass.SetLabel("Playground Main Render Pass"); return render_callback(pass); @@ -193,4 +204,8 @@ CompressedImage compressed_image( return texture; } +void Playground::SetWindowSize(ISize size) { + window_size_ = size; +} + } // namespace impeller