Make sure the GLFW example compiles. (flutter/engine#30442)
This commit is contained in:
2
DEPS
2
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
|
||||
#
|
||||
|
||||
@@ -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" ]
|
||||
|
||||
14
engine/src/flutter/examples/glfw/BUILD.gn
Normal file
14
engine/src/flutter/examples/glfw/BUILD.gn
Normal file
@@ -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",
|
||||
]
|
||||
}
|
||||
@@ -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<GLFWwindow*>(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<GLFWwindow*>(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 <path to project> <path to icudtl.dat>"
|
||||
std::cout << "usage: embedder_example <path to project> <path to icudtl.dat>"
|
||||
<< 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user