Skip to content

Commit

Permalink
Allow resizing the playground.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored and dnfield committed Apr 27, 2022
1 parent 7566d67 commit 0016e48
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions impeller/playground/playground.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
25 changes: 20 additions & 5 deletions impeller/playground/playground.mm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static void PlaygroundKeyCallback(GLFWwindow* window,
}

ISize Playground::GetWindowSize() const {
return {1024, 768};
return window_size_;
}

void Playground::SetCursorPosition(Point pos) {
Expand All @@ -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 =
Expand All @@ -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<Playground*>(::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) {
Expand All @@ -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);
Expand Down Expand Up @@ -193,4 +204,8 @@ CompressedImage compressed_image(
return texture;
}

void Playground::SetWindowSize(ISize size) {
window_size_ = size;
}

} // namespace impeller

0 comments on commit 0016e48

Please sign in to comment.