7 #define GLFW_INCLUDE_NONE
8 #include "third_party/glfw/include/GLFW/glfw3.h"
10 #include "flutter/fml/build_config.h"
11 #include "impeller/entity/gles/entity_shaders_gles.h"
12 #include "impeller/fixtures/gles/fixtures_shaders_gles.h"
13 #include "impeller/playground/imgui/gles/imgui_shaders_gles.h"
16 #include "impeller/scene/shaders/gles/scene_shaders_gles.h"
28 auto found = reactions_allowed_.find(std::this_thread::get_id());
29 if (found == reactions_allowed_.end()) {
37 reactions_allowed_[std::this_thread::get_id()] = allowed;
41 mutable RWMutex mutex_;
42 std::map<std::thread::id, bool> reactions_allowed_ IPLR_GUARDED_BY(mutex_);
47 void PlaygroundImplGLES::DestroyWindowHandle(WindowHandle handle) {
51 ::glfwDestroyWindow(
reinterpret_cast<GLFWwindow*
>(handle));
56 handle_(nullptr, &DestroyWindowHandle),
58 ::glfwDefaultWindowHints();
62 ::glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
63 #else // FML_OS_MACOSX
64 ::glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
65 ::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
66 ::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
67 #endif // FML_OS_MACOSX
68 ::glfwWindowHint(GLFW_RED_BITS, 8);
69 ::glfwWindowHint(GLFW_GREEN_BITS, 8);
70 ::glfwWindowHint(GLFW_BLUE_BITS, 8);
71 ::glfwWindowHint(GLFW_ALPHA_BITS, 8);
72 ::glfwWindowHint(GLFW_DEPTH_BITS, 32);
73 ::glfwWindowHint(GLFW_STENCIL_BITS, 8);
74 ::glfwWindowHint(GLFW_SAMPLES, 4);
76 ::glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
78 auto window = ::glfwCreateWindow(1, 1,
"Test",
nullptr,
nullptr);
80 ::glfwMakeContextCurrent(window);
81 worker_->SetReactionsAllowedOnCurrentThread(
true);
83 handle_.reset(window);
88 static std::vector<std::shared_ptr<fml::Mapping>>
91 std::make_shared<fml::NonOwnedMapping>(
92 impeller_entity_shaders_gles_data,
93 impeller_entity_shaders_gles_length),
94 std::make_shared<fml::NonOwnedMapping>(
95 impeller_fixtures_shaders_gles_data,
96 impeller_fixtures_shaders_gles_length),
97 std::make_shared<fml::NonOwnedMapping>(
98 impeller_imgui_shaders_gles_data, impeller_imgui_shaders_gles_length),
99 std::make_shared<fml::NonOwnedMapping>(
100 impeller_scene_shaders_gles_data, impeller_scene_shaders_gles_length),
105 std::shared_ptr<Context> PlaygroundImplGLES::GetContext()
const {
106 auto resolver = [](
const char* name) ->
void* {
107 return reinterpret_cast<void*
>(::glfwGetProcAddress(name));
109 auto gl = std::make_unique<ProcTableGLES>(resolver);
110 if (!gl->IsValid()) {
111 FML_LOG(ERROR) <<
"Proc table when creating a playground was invalid.";
118 FML_LOG(ERROR) <<
"Could not create context.";
122 auto worker_id = context->AddReactorWorker(worker_);
123 if (!worker_id.has_value()) {
124 FML_LOG(ERROR) <<
"Could not add reactor worker.";
132 return handle_.get();
136 std::unique_ptr<Surface> PlaygroundImplGLES::AcquireSurfaceFrame(
137 std::shared_ptr<Context> context) {
138 auto window =
reinterpret_cast<GLFWwindow*
>(GetWindowHandle());
141 ::glfwGetFramebufferSize(window, &width, &height);
142 if (width <= 0 || height <= 0) {
146 ::glfwSwapBuffers(window);