9#define GLFW_EXPOSE_NATIVE_EGL
10#define GLFW_INCLUDE_GLEXT
13#include <EGL/eglext.h>
17#include <unordered_map>
18#include "GLFW/glfw3.h"
19#include "GLFW/glfw3native.h"
42 "This Flutter Embedder was authored against the stable Flutter "
43 "API at version 1. There has been a serious breakage in the "
44 "API. Please read the ChangeLog and take appropriate action "
45 "before updating this assertion");
57 std::chrono::duration_cast<std::chrono::microseconds>(
58 std::chrono::high_resolution_clock::now().time_since_epoch())
76 if (
key == GLFW_MOUSE_BUTTON_1 &&
action == GLFW_PRESS) {
83 if (
key == GLFW_MOUSE_BUTTON_1 &&
action == GLFW_RELEASE) {
87 glfwSetCursorPosCallback(
window,
nullptr);
96 if (
key == GLFW_KEY_ESCAPE &&
action == GLFW_PRESS) {
121 std::array<EGLint, 4> res{
122 static_cast<int>(
rect.left),
height -
static_cast<int>(
rect.bottom),
123 static_cast<int>(
rect.right) -
static_cast<int>(
rect.left),
124 static_cast<int>(
rect.bottom) -
static_cast<int>(
rect.top)};
143 return r !=
nullptr && (r[
len] ==
' ' || r[
len] == 0);
147 const std::string& project_path,
148 const std::string& icudtl_path) {
153 glfwMakeContextCurrent(
static_cast<GLFWwindow*
>(userdata));
157 glfwMakeContextCurrent(
nullptr);
172 PFNEGLSETDAMAGEREGIONKHRPROC set_damage_region_ =
nullptr;
174 set_damage_region_ =
reinterpret_cast<PFNEGLSETDAMAGEREGIONKHRPROC
>(
175 eglGetProcAddress(
"eglSetDamageRegionKHR"));
179 PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC swap_buffers_with_damage_ =
nullptr;
181 swap_buffers_with_damage_ =
182 reinterpret_cast<PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC
>(
183 eglGetProcAddress(
"eglSwapBuffersWithDamageEXT"));
185 swap_buffers_with_damage_ =
186 reinterpret_cast<PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC
>(
187 eglGetProcAddress(
"eglSwapBuffersWithDamageKHR"));
190 if (set_damage_region_) {
202 if (swap_buffers_with_damage_) {
217 [](
void* userdata, intptr_t fbo_id,
222 if (glfwExtensionSupported(
"GL_EXT_buffer_age") ==
GLFW_TRUE) {
228 existing_damage->num_rects = 1;
244 existing_damage->damage[0] = {
i->left,
i->top,
i->right,
i->bottom};
253 return reinterpret_cast<void*
>(glfwGetProcAddress(
name));
258 std::string assets_path = project_path +
"/build/flutter_assets";
261 .assets_path = assets_path.c_str(),
270 std::cout <<
"Could not run the Flutter Engine." << std::endl;
282 <<
"usage: embedder_example_drm <path to project> <path to icudtl.dat>"
287 std::cout <<
"GLFW Error: (" <<
error <<
") " << description << std::endl;
296 std::string project_path =
argv[1];
297 std::string icudtl_path =
argv[2];
303 std::cout <<
"Could not initialize GLFW." << std::endl;
307#if defined(__linux__)
308 glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
311 GLFWwindow*
window = glfwCreateWindow(
314 std::cout <<
"Could not create GLFW window." << std::endl;
318 int framebuffer_width, framebuffer_height;
319 glfwGetFramebufferSize(
window, &framebuffer_width, &framebuffer_height);
328 std::cout <<
"Could not run the Flutter engine." << std::endl;
336 while (!glfwWindowShouldClose(
window)) {
340 glfwDestroyWindow(
window);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
FlutterEngineResult FlutterEngineRun(size_t version, const FlutterRendererConfig *config, const FlutterProjectArgs *args, void *user_data, FLUTTER_API_SYMBOL(FlutterEngine) *engine_out)
Initialize and run a Flutter engine instance and return a handle to it. This is a convenience method ...
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *flutter_metrics)
FlutterEngineResult FlutterEngineSendPointerEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPointerEvent *pointers, size_t events_count)
FlutterPointerPhase
The phase of the pointer event.
#define FLUTTER_ENGINE_VERSION
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint8_t uint32_t uint32_t GError ** error
bool RunFlutter(GLFWwindow *window, const std::string &project_path, const std::string &icudtl_path)
void GLFWcursorPositionCallbackAtPhase(GLFWwindow *window, FlutterPointerPhase phase, double x, double y)
int main(int argc, const char *argv[])
void GLFWwindowSizeCallback(GLFWwindow *window, int width, int height)
void GLFWcursorPositionCallback(GLFWwindow *window, double x, double y)
void GLFWmouseButtonCallback(GLFWwindow *window, int key, int action, int mods)
void GLFW_ErrorCallback(int error, const char *description)
static std::array< EGLint, 4 > RectToInts(const FlutterRect rect)
static const int kMaxHistorySize
std::unordered_map< intptr_t, FlutterRect * > existing_damage_map_
static void GLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
static void JoinFlutterRect(FlutterRect *rect, FlutterRect additional_rect)
static double g_pixelRatio
static constexpr FlutterViewId kImplicitViewId
std::list< FlutterRect > damage_history_
static bool HasExtension(const char *extensions, const char *name)
static const size_t kInitialWindowHeight
static const size_t kInitialWindowWidth
static float max(float r, float g, float b)
static float min(float r, float g, float b)
sk_sp< SkBlender > blender SkRect rect
void * malloc(size_t size)
DEF_SWITCHES_START aot vmservice shared library name
A structure to represent a damage region.
ProcResolver gl_proc_resolver
BoolCallback make_current
BoolPresentInfoCallback present_with_info
UIntCallback fbo_callback
size_t struct_size
The size of this struct. Must be sizeof(FlutterOpenGLRendererConfig).
bool fbo_reset_after_present
FlutterFrameBufferWithDamageCallback populate_existing_damage
BoolCallback clear_current
size_t struct_size
The size of this struct. Must be sizeof(FlutterPointerEvent).
A structure to represent a rectangle.
FlutterOpenGLRendererConfig open_gl
size_t struct_size
The size of this struct. Must be sizeof(FlutterWindowMetricsEvent).