Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure the GLFW example compiles. #30442

Merged
merged 2 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ group("flutter") {
"//flutter/sky",
]

# Ensure the example for a sample embedder compiles.
if (is_mac || is_linux) {
public_deps += [ "//flutter/examples/glfw" ]
}

# If enbaled, compile the SDK / snapshot.
if (!is_fuchsia) {
public_deps += [ "//flutter/lib/snapshot:generate_snapshot_bins" ]
Expand Down
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ allowed_hosts = [
]

deps = {
'src': 'https://github.com/flutter/buildroot.git' + '@' + '88c2c61d323e3141849611b2d7fd4ac14103c61f',
'src': 'https://github.com/flutter/buildroot.git' + '@' + '4660f4a166979c64ff56f6b856b44ccc1dba5c63',

# Fuchsia compatibility
#
Expand Down
14 changes: 14 additions & 0 deletions examples/glfw/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

executable("glfw") {
output_name = "embedder_example"

sources = [ "FlutterEmbedderGLFW.cc" ]

deps = [
"//flutter/shell/platform/embedder:embedder",
"//third_party/glfw",
]
}
27 changes: 19 additions & 8 deletions examples/glfw/FlutterEmbedderGLFW.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ bool RunFlutter(GLFWwindow* window,
config.type = kOpenGL;
config.open_gl.struct_size = sizeof(config.open_gl);
config.open_gl.make_current = [](void* userdata) -> bool {
glfwMakeContextCurrent((GLFWwindow*)userdata);
glfwMakeContextCurrent(static_cast<GLFWwindow*>(userdata));
return true;
};
config.open_gl.clear_current = [](void*) -> bool {
glfwMakeContextCurrent(nullptr); // is this even a thing?
return true;
};
config.open_gl.present = [](void* userdata) -> bool {
glfwSwapBuffers((GLFWwindow*)userdata);
glfwSwapBuffers(static_cast<GLFWwindow*>(userdata));
return true;
};
config.open_gl.fbo_callback = [](void*) -> uint32_t {
Expand All @@ -116,7 +116,10 @@ bool RunFlutter(GLFWwindow* window,
FlutterEngineResult result =
FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, // renderer
&args, window, &engine);
assert(result == kSuccess && engine != nullptr);
if (result != kSuccess || engine == nullptr) {
std::cout << "Could not run the Flutter Engine." << std::endl;
return false;
}

glfwSetWindowUserPointer(window, engine);
GLFWwindowSizeCallback(window, kInitialWindowWidth, kInitialWindowHeight);
Expand All @@ -125,7 +128,7 @@ bool RunFlutter(GLFWwindow* window,
}

void printUsage() {
std::cout << "usage: flutter_glfw <path to project> <path to icudtl.dat>"
std::cout << "usage: embedder_example <path to project> <path to icudtl.dat>"
<< std::endl;
}

Expand All @@ -145,25 +148,33 @@ int main(int argc, const char* argv[]) {
glfwSetErrorCallback(GLFW_ErrorCallback);

int result = glfwInit();
assert(result == GLFW_TRUE);
if (result != GLFW_TRUE) {
std::cout << "Could not initialize GLFW." << std::endl;
return EXIT_FAILURE;
}

GLFWwindow* window = glfwCreateWindow(
kInitialWindowWidth, kInitialWindowHeight, "Flutter", NULL, NULL);
assert(window != nullptr);
if (window == nullptr) {
std::cout << "Could not create GLFW window." << std::endl;
return EXIT_FAILURE;
}

int framebuffer_width, framebuffer_height;
glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height);
g_pixelRatio = framebuffer_width / kInitialWindowWidth;

bool runResult = RunFlutter(window, project_path, icudtl_path);
assert(runResult);
if (!runResult) {
std::cout << "Could not run the Flutter engine." << std::endl;
return EXIT_FAILURE;
}

glfwSetKeyCallback(window, GLFWKeyCallback);
glfwSetWindowSizeCallback(window, GLFWwindowSizeCallback);
glfwSetMouseButtonCallback(window, GLFWmouseButtonCallback);

while (!glfwWindowShouldClose(window)) {
std::cout << "Looping..." << std::endl;
glfwWaitEvents();
}

Expand Down
5 changes: 5 additions & 0 deletions shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ shell_gpu_configuration("embedder_gpu_configuration") {

_framework_binary_subpath = "Versions/A/FlutterEmbedder"

config("embedder_header_config") {
include_dirs = [ "." ]
}

# Template for the embedder build. Used to allow building it multiple times with
# different flags.
template("embedder_source_set") {
Expand Down Expand Up @@ -108,6 +112,7 @@ template("embedder_source_set") {

public_configs += [
":embedder_gpu_configuration_config",
":embedder_header_config",
"//flutter:config",
]
}
Expand Down