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_);
49 void PlaygroundImplGLES::DestroyWindowHandle(WindowHandle handle) {
53 ::glfwDestroyWindow(
reinterpret_cast<GLFWwindow*
>(handle));
58 handle_(nullptr, &DestroyWindowHandle),
60 ::glfwDefaultWindowHints();
64 ::glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
65 #else // FML_OS_MACOSX
66 ::glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
67 ::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
68 ::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
69 #endif // FML_OS_MACOSX
70 ::glfwWindowHint(GLFW_RED_BITS, 8);
71 ::glfwWindowHint(GLFW_GREEN_BITS, 8);
72 ::glfwWindowHint(GLFW_BLUE_BITS, 8);
73 ::glfwWindowHint(GLFW_ALPHA_BITS, 8);
74 ::glfwWindowHint(GLFW_DEPTH_BITS, 32);
75 ::glfwWindowHint(GLFW_STENCIL_BITS, 8);
76 ::glfwWindowHint(GLFW_SAMPLES, 4);
78 ::glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
80 auto window = ::glfwCreateWindow(1, 1,
"Test",
nullptr,
nullptr);
82 ::glfwMakeContextCurrent(window);
83 worker_->SetReactionsAllowedOnCurrentThread(
true);
85 handle_.reset(window);
90 static std::vector<std::shared_ptr<fml::Mapping>>
93 std::make_shared<fml::NonOwnedMapping>(
94 impeller_entity_shaders_gles_data,
95 impeller_entity_shaders_gles_length),
96 std::make_shared<fml::NonOwnedMapping>(
97 impeller_fixtures_shaders_gles_data,
98 impeller_fixtures_shaders_gles_length),
99 std::make_shared<fml::NonOwnedMapping>(
100 impeller_imgui_shaders_gles_data, impeller_imgui_shaders_gles_length),
101 std::make_shared<fml::NonOwnedMapping>(
102 impeller_scene_shaders_gles_data, impeller_scene_shaders_gles_length),
107 std::shared_ptr<Context> PlaygroundImplGLES::GetContext()
const {
108 auto resolver = [](
const char* name) ->
void* {
109 return reinterpret_cast<void*
>(::glfwGetProcAddress(name));
111 auto gl = std::make_unique<ProcTableGLES>(resolver);
112 if (!gl->IsValid()) {
113 FML_LOG(ERROR) <<
"Proc table when creating a playground was invalid.";
120 FML_LOG(ERROR) <<
"Could not create context.";
124 auto worker_id = context->AddReactorWorker(worker_);
125 if (!worker_id.has_value()) {
126 FML_LOG(ERROR) <<
"Could not add reactor worker.";
134 return handle_.get();
138 std::unique_ptr<Surface> PlaygroundImplGLES::AcquireSurfaceFrame(
139 std::shared_ptr<Context> context) {
140 auto window =
reinterpret_cast<GLFWwindow*
>(GetWindowHandle());
143 ::glfwGetFramebufferSize(window, &width, &height);
144 if (width <= 0 || height <= 0) {
148 ::glfwSwapBuffers(window);
160 const std::shared_ptr<Capabilities>& capabilities) {
162 fml::StatusCode::kUnimplemented,
163 "PlaygroundImplGLES doesn't support setting the capabilities.");