75 handle_(nullptr, &DestroyWindowHandle),
76 worker_(std::shared_ptr<ReactorWorker>(new ReactorWorker())),
77 use_angle_(switches.use_angle) {
78 if (use_angle_) {
79#if IMPELLER_PLAYGROUND_SUPPORTS_ANGLE
80 angle_glesv2_ = dlopen("libGLESv2.dylib", RTLD_LAZY);
81#endif
83 }
84
85 ::glfwDefaultWindowHints();
86
87#if FML_OS_MACOSX
88 FML_CHECK(use_angle_) <<
"Must use Angle on macOS for OpenGL ES.";
89 ::glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
90#endif
91#if FML_OS_LINUX
92
93
94 ::glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
95#endif
96 ::glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
97 ::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
98 ::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
99 ::glfwWindowHint(GLFW_RED_BITS, 8);
100 ::glfwWindowHint(GLFW_GREEN_BITS, 8);
101 ::glfwWindowHint(GLFW_BLUE_BITS, 8);
102 ::glfwWindowHint(GLFW_ALPHA_BITS, 8);
103 ::glfwWindowHint(GLFW_DEPTH_BITS, 32);
104 ::glfwWindowHint(GLFW_STENCIL_BITS, 8);
105 ::glfwWindowHint(GLFW_SAMPLES, 4);
106
108#ifndef NDEBUG
109 ::glfwWindowHint(GLFW_CONTEXT_DEBUG,
GLFW_TRUE);
110#endif
111
112 auto window = ::glfwCreateWindow(1, 1,
"Test",
nullptr,
nullptr);
113
114 ::glfwMakeContextCurrent(
window);
115 worker_->SetReactionsAllowedOnCurrentThread(true);
116
118
119 auto gl = std::make_unique<ProcTableGLES>(CreateGLProcAddressResolver());
120 if (!gl->IsValid()) {
121 FML_LOG(ERROR) <<
"Proc table when creating a playground was invalid.";
122 return;
123 }
124
125 if (gl->GetDescription()->HasDebugExtension()) {
126 gl->DebugMessageCallbackKHR(
127 +[](GLenum , GLenum message_type, GLuint ,
128 GLenum , GLsizei ,
const GLchar*
message,
129 const void* ) {
130 switch (message_type) {
131 case GL_DEBUG_TYPE_ERROR_KHR:
133 return;
134 default:
135 return;
136 }
137 },
138 nullptr);
139
140#ifndef NDEBUG
141 gl->Enable(GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR);
142#endif
143 }
144 bool is_gles3 = gl->GetDescription()->GetGlVersion().IsAtLeast(Version(3));
145 auto context_gles =
148 if (!context_gles) {
149 FML_LOG(ERROR) <<
"Could not create context.";
150 return;
151 }
152
153 auto worker_id = context_gles->AddReactorWorker(worker_);
154 if (!worker_id.has_value()) {
155 FML_LOG(ERROR) <<
"Could not add reactor worker.";
156 return;
157 }
158 context_ = std::move(context_gles);
159}
static std::shared_ptr< ContextGLES > Create(const Flags &flags, std::unique_ptr< ProcTableGLES > gl, const std::vector< std::shared_ptr< fml::Mapping > > &shader_libraries, bool enable_gpu_tracing)
PlaygroundImpl(PlaygroundSwitches switches)
const PlaygroundSwitches switches_
#define FML_LOG(severity)
#define FML_CHECK(condition)
static std::vector< std::shared_ptr< fml::Mapping > > ShaderLibraryMappingsForPlayground()