From e4dd57b6328521b64cc8c3b056d0de00eb3c0e93 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Tue, 21 Dec 2021 12:29:09 -0800 Subject: [PATCH] Make sure the GLFW example compiles. (#30442) --- BUILD.gn | 5 +++++ DEPS | 2 +- examples/glfw/BUILD.gn | 14 ++++++++++++++ examples/glfw/FlutterEmbedderGLFW.cc | 27 +++++++++++++++++++-------- shell/platform/embedder/BUILD.gn | 5 +++++ 5 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 examples/glfw/BUILD.gn diff --git a/BUILD.gn b/BUILD.gn index 87b102774b68d..1c01315f9cb46 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -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" ] diff --git a/DEPS b/DEPS index cf2f63c4915c5..30333442be08e 100644 --- a/DEPS +++ b/DEPS @@ -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 # diff --git a/examples/glfw/BUILD.gn b/examples/glfw/BUILD.gn new file mode 100644 index 0000000000000..9c59b84e691ff --- /dev/null +++ b/examples/glfw/BUILD.gn @@ -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", + ] +} diff --git a/examples/glfw/FlutterEmbedderGLFW.cc b/examples/glfw/FlutterEmbedderGLFW.cc index 419630a733cd0..4c239bfbef557 100644 --- a/examples/glfw/FlutterEmbedderGLFW.cc +++ b/examples/glfw/FlutterEmbedderGLFW.cc @@ -89,7 +89,7 @@ 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(userdata)); return true; }; config.open_gl.clear_current = [](void*) -> bool { @@ -97,7 +97,7 @@ bool RunFlutter(GLFWwindow* window, return true; }; config.open_gl.present = [](void* userdata) -> bool { - glfwSwapBuffers((GLFWwindow*)userdata); + glfwSwapBuffers(static_cast(userdata)); return true; }; config.open_gl.fbo_callback = [](void*) -> uint32_t { @@ -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); @@ -125,7 +128,7 @@ bool RunFlutter(GLFWwindow* window, } void printUsage() { - std::cout << "usage: flutter_glfw " + std::cout << "usage: embedder_example " << std::endl; } @@ -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(); } diff --git a/shell/platform/embedder/BUILD.gn b/shell/platform/embedder/BUILD.gn index 529f48a7ebd41..b8bffc3a8d068 100644 --- a/shell/platform/embedder/BUILD.gn +++ b/shell/platform/embedder/BUILD.gn @@ -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") { @@ -108,6 +112,7 @@ template("embedder_source_set") { public_configs += [ ":embedder_gpu_configuration_config", + ":embedder_header_config", "//flutter:config", ] }