Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0016e48

Browse files
chinmaygardednfield
authored andcommitted
Allow resizing the playground.
1 parent 7566d67 commit 0016e48

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

impeller/playground/playground.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ class Playground : public ::testing::Test {
3333
private:
3434
Renderer renderer_;
3535
Point cursor_position_;
36+
ISize window_size_ = ISize{1024, 768};
3637

3738
void SetCursorPosition(Point pos);
3839

40+
void SetWindowSize(ISize size);
41+
3942
FML_DISALLOW_COPY_AND_ASSIGN(Playground);
4043
};
4144

impeller/playground/playground.mm

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static void PlaygroundKeyCallback(GLFWwindow* window,
7878
}
7979

8080
ISize Playground::GetWindowSize() const {
81-
return {1024, 768};
81+
return window_size_;
8282
}
8383

8484
void Playground::SetCursorPosition(Point pos) {
@@ -100,10 +100,6 @@ static void PlaygroundKeyCallback(GLFWwindow* window,
100100
fml::ScopedCleanupClosure terminate([]() { ::glfwTerminate(); });
101101

102102
::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
103-
// Recreation of the target render buffer is not setup in the playground yet.
104-
// So prevent users from resizing and getting confused that their math is
105-
// wrong.
106-
::glfwWindowHint(GLFW_RESIZABLE, false);
107103

108104
auto window_title = GetWindowTitle(flutter::testing::GetCurrentTestName());
109105
auto window =
@@ -114,6 +110,16 @@ static void PlaygroundKeyCallback(GLFWwindow* window,
114110
}
115111

116112
::glfwSetWindowUserPointer(window, this);
113+
::glfwSetWindowSizeCallback(
114+
window, [](GLFWwindow* window, int width, int height) -> void {
115+
auto playground =
116+
reinterpret_cast<Playground*>(::glfwGetWindowUserPointer(window));
117+
if (!playground) {
118+
return;
119+
}
120+
playground->SetWindowSize(
121+
ISize{std::max(width, 0), std::max(height, 0)});
122+
});
117123
::glfwSetKeyCallback(window, &PlaygroundKeyCallback);
118124
::glfwSetCursorPosCallback(window, [](GLFWwindow* window, double x,
119125
double y) {
@@ -138,6 +144,11 @@ static void PlaygroundKeyCallback(GLFWwindow* window,
138144
return true;
139145
}
140146

147+
const auto layer_size = layer.bounds.size;
148+
const auto layer_scale = layer.contentsScale;
149+
layer.drawableSize = CGSizeMake(layer_size.width * layer_scale,
150+
layer_size.height * layer_scale);
151+
141152
Renderer::RenderCallback wrapped_callback = [render_callback](auto& pass) {
142153
pass.SetLabel("Playground Main Render Pass");
143154
return render_callback(pass);
@@ -193,4 +204,8 @@ CompressedImage compressed_image(
193204
return texture;
194205
}
195206

207+
void Playground::SetWindowSize(ISize size) {
208+
window_size_ = size;
209+
}
210+
196211
} // namespace impeller

0 commit comments

Comments
 (0)