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 uint8_t msaa_samples) {
29 EGLint sample_buffers = msaa_samples > 1 ? 1 : 0;
30 EGLint attributes[] = {
32 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
33 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
40 EGL_SAMPLES,
static_cast<EGLint
>(msaa_samples),
41 EGL_SAMPLE_BUFFERS, sample_buffers,
46 EGLint config_count = 0;
47 EGLConfig egl_config =
nullptr;
49 if (eglChooseConfig(display, attributes, &egl_config, 1, &config_count) !=
51 return {
false,
nullptr};
54 bool success = config_count > 0 && egl_config !=
nullptr;
56 return {success, success ? egl_config :
nullptr};
72 environment_(
std::move(environment)),
74 if (!environment_->IsValid()) {
75 FML_LOG(
ERROR) <<
"Could not create an Android GL environment.";
82 std::tie(success, config_) =
85 FML_LOG(
ERROR) <<
"Could not choose an EGL configuration.";
91 std::tie(success, context_) =
92 CreateContext(environment_->Display(), config_, EGL_NO_CONTEXT);
99 std::tie(success, resource_context_) =
102 FML_LOG(
ERROR) <<
"Could not create an EGL resource context";
163AndroidContextGLSkia::CreateOffscreenSurface()
const {
166 EGLDisplay display = environment_->Display();
168 const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
170 EGLSurface
surface = eglCreatePbufferSurface(display, config_, attribs);
171 return std::make_unique<AndroidEGLSurface>(
surface, display,
175std::unique_ptr<AndroidEGLSurface> AndroidContextGLSkia::CreatePbufferSurface()
177 EGLDisplay display = environment_->Display();
179 const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
181 EGLSurface
surface = eglCreatePbufferSurface(display, config_, attribs);
182 return std::make_unique<AndroidEGLSurface>(
surface, display, context_);
193bool AndroidContextGLSkia::ClearCurrent()
const {
194 if (eglGetCurrentContext() != context_) {
197 if (eglMakeCurrent(environment_->Display(), EGL_NO_SURFACE, EGL_NO_SURFACE,
198 EGL_NO_CONTEXT) != EGL_TRUE) {
199 FML_LOG(
ERROR) <<
"Could not clear the current context";
214EGLContext AndroidContextGLSkia::CreateNewContext()
const {
217 std::tie(success, context) =
218 CreateContext(environment_->Display(), config_, EGL_NO_CONTEXT);
219 return success ? context : EGL_NO_CONTEXT;
AndroidContextGLSkia(fml::RefPtr< AndroidEnvironmentGL > environment, const TaskRunners &taskRunners, uint8_t msaa_samples)
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.