19 EGLContext share = EGL_NO_CONTEXT) {
20 EGLint attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
22 EGLContext context = eglCreateContext(display, config, share, attributes);
24 return {context != EGL_NO_CONTEXT, context};
28 EGLint attributes[] = {
30 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
31 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
42 EGLint config_count = 0;
43 EGLConfig egl_config =
nullptr;
45 if (eglChooseConfig(display, attributes, &egl_config, 1, &config_count) !=
47 return {
false,
nullptr};
50 bool success = config_count > 0 && egl_config !=
nullptr;
52 return {success, success ? egl_config :
nullptr};
67 environment_(
std::move(environment)),
69 if (!environment_->IsValid()) {
70 FML_LOG(ERROR) <<
"Could not create an Android GL environment.";
79 FML_LOG(ERROR) <<
"Could not choose an EGL configuration.";
85 std::tie(success, context_) =
86 CreateContext(environment_->Display(), config_, EGL_NO_CONTEXT);
88 FML_LOG(ERROR) <<
"Could not create an EGL context";
93 std::tie(success, resource_context_) =
96 FML_LOG(ERROR) <<
"Could not create an EGL resource context";
114 std::unique_ptr<AndroidEGLSurface> pbuffer_surface =
115 CreatePbufferSurface();
116 auto status = pbuffer_surface->MakeCurrent();
117 if (status != AndroidEGLSurfaceMakeCurrentStatus::kFailure) {
118 main_context->releaseResourcesAndAbandonContext();
119 main_context.reset();
129 <<
"Could not tear down the EGL context. Possible resource leak.";
134 FML_LOG(ERROR) <<
"Could not tear down the EGL resource context. Possible "
157AndroidContextGLSkia::CreateOffscreenSurface()
const {
160 EGLDisplay display = environment_->Display();
162 const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
164 EGLSurface
surface = eglCreatePbufferSurface(display, config_, attribs);
165 return std::make_unique<AndroidEGLSurface>(
surface, display,
169std::unique_ptr<AndroidEGLSurface> AndroidContextGLSkia::CreatePbufferSurface()
171 EGLDisplay display = environment_->Display();
173 const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
175 EGLSurface
surface = eglCreatePbufferSurface(display, config_, attribs);
176 return std::make_unique<AndroidEGLSurface>(
surface, display, context_);
187bool AndroidContextGLSkia::ClearCurrent()
const {
188 if (eglGetCurrentContext() != context_) {
191 if (eglMakeCurrent(environment_->Display(), EGL_NO_SURFACE, EGL_NO_SURFACE,
192 EGL_NO_CONTEXT) != EGL_TRUE) {
193 FML_LOG(ERROR) <<
"Could not clear the current context";
208EGLContext AndroidContextGLSkia::CreateNewContext()
const {
211 std::tie(success, context) =
212 CreateContext(environment_->Display(), config_, EGL_NO_CONTEXT);
213 return success ? context : EGL_NO_CONTEXT;
AndroidContextGLSkia(fml::RefPtr< AndroidEnvironmentGL > environment, const TaskRunners &taskRunners)
Holds state that is shared across Android surfaces.
void SetMainSkiaContext(const sk_sp< GrDirectContext > &main_context)
Setter for the Skia context to be used by subsequent AndroidSurfaces.
sk_sp< GrDirectContext > GetMainSkiaContext() const
Accessor for the Skia context associated with AndroidSurfaces and the raster thread.