Flutter Engine
The Flutter Engine
ANGLEWindowContext.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
12
14
16
18 PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT =
19 (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
20
21 // We expect ANGLE to support this extension
22 if (!eglGetPlatformDisplayEXT) {
23 return nullptr;
24 }
25
26 fDisplay = this->onGetEGLDisplay(eglGetPlatformDisplayEXT);
27 if (EGL_NO_DISPLAY == fDisplay) {
28 return nullptr;
29 }
30
31 EGLint majorVersion;
32 EGLint minorVersion;
33 if (!eglInitialize(fDisplay, &majorVersion, &minorVersion)) {
34 SkDebugf("Could not initialize display!\n");
35 return nullptr;
36 }
37 EGLint numConfigs;
39 const int sampleBuffers = fSampleCount > 1 ? 1 : 0;
40 const int eglSampleCnt = fSampleCount > 1 ? fSampleCount : 0;
41 const EGLint configAttribs[] = {EGL_RENDERABLE_TYPE,
42 // We currently only support ES3.
43 EGL_OPENGL_ES3_BIT,
44 EGL_RED_SIZE,
45 8,
46 EGL_GREEN_SIZE,
47 8,
48 EGL_BLUE_SIZE,
49 8,
50 EGL_ALPHA_SIZE,
51 8,
52 EGL_SAMPLE_BUFFERS,
53 sampleBuffers,
54 EGL_SAMPLES,
55 eglSampleCnt,
56 EGL_NONE};
57
58 EGLConfig surfaceConfig;
59 if (!eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs)) {
60 SkDebugf("Could not create choose config!\n");
61 return nullptr;
62 }
63 // We currently only support ES3.
64 const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE};
65 fEGLContext = eglCreateContext(fDisplay, surfaceConfig, nullptr, contextAttribs);
66 if (EGL_NO_CONTEXT == fEGLContext) {
67 SkDebugf("Could not create context!\n");
68 return nullptr;
69 }
70 fEGLSurface =
71 eglCreateWindowSurface(fDisplay, surfaceConfig, this->onGetNativeWindow(), nullptr);
72 if (EGL_NO_SURFACE == fEGLSurface) {
73 SkDebugf("Could not create surface!\n");
74 return nullptr;
75 }
76 if (!eglMakeCurrent(fDisplay, fEGLSurface, fEGLSurface, fEGLContext)) {
77 SkDebugf("Could not make context current!\n");
78 return nullptr;
79 }
80
82 nullptr,
83 [](void* ctx, const char name[]) -> GrGLFuncPtr { return eglGetProcAddress(name); }));
84 if (interface) {
85 interface->fFunctions.fClearStencil(0);
86 interface->fFunctions.fClearColor(0, 0, 0, 0);
87 interface->fFunctions.fStencilMask(0xffffffff);
89
91
92 SkISize size = this->onGetSize();
93 fWidth = size.width();
94 fHeight = size.height();
95 interface->fFunctions.fViewport(0, 0, fWidth, fHeight);
96 }
97 return interface;
98}
99
101 eglMakeCurrent(fDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
102 if (EGL_NO_CONTEXT != fEGLContext) {
103 eglDestroyContext(fDisplay, fEGLContext);
104 }
105 if (EGL_NO_SURFACE != fEGLSurface) {
106 eglDestroySurface(fDisplay, fEGLSurface);
107 }
108 if (EGL_NO_DISPLAY != fDisplay) {
109 eglTerminate(fDisplay);
110 }
111}
112
114 if (!eglSwapBuffers(fDisplay, fEGLSurface)) {
115 SkDebugf("Could not complete eglSwapBuffers.\n");
116 }
117}
118
119} // namespace skwindow::internal
SK_API sk_sp< const GrGLInterface > GrGLMakeAssembledInterface(void *ctx, GrGLGetProc get)
#define GR_GL_STENCIL_BUFFER_BIT
Definition: GrGLDefines.h:22
#define GR_GL_COLOR_BUFFER_BIT
Definition: GrGLDefines.h:23
void(* GrGLFuncPtr)()
Definition: GrGLInterface.h:17
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
const DisplayParams & getDisplayParams()
Definition: WindowContext.h:42
virtual SkISize onGetSize() const =0
virtual int onGetStencilBits() const =0
virtual EGLDisplay onGetEGLDisplay(PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT) const =0
virtual NativeWindowType onGetNativeWindow() const =0
sk_sp< const GrGLInterface > onInitializeContext() override
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
GrGLFunction< GrGLViewportFn > fViewport
GrGLFunction< GrGLClearStencilFn > fClearStencil
GrGLFunction< GrGLClearColorFn > fClearColor
GrGLFunction< GrGLStencilMaskFn > fStencilMask
GrGLFunction< GrGLClearFn > fClear
struct GrGLInterface::Functions fFunctions
Definition: SkSize.h:16
constexpr int32_t width() const
Definition: SkSize.h:36