Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
impeller::egl::Display Class Reference

A connection to an EGL display. Only one connection per application instance is sufficient. More...

#include <display.h>

Public Member Functions

 Display ()
 
virtual ~Display ()
 
virtual bool IsValid () const
 
virtual std::unique_ptr< ConfigChooseConfig (ConfigDescriptor config) const
 Choose a config that most closely matches a given descriptor. If there are no matches, this method returns nullptr. More...
 
virtual std::unique_ptr< ContextCreateContext (const Config &config, const Context *share_context)
 Create a context with a supported config. The supported config can be obtained via a successful call to ChooseConfig. More...
 
virtual std::unique_ptr< SurfaceCreateWindowSurface (const Config &config, EGLNativeWindowType window)
 Create a window surface. The window is an opaque pointer whose value value is platform specific. For instance, ANativeWindow on Android. More...
 
virtual std::unique_ptr< SurfaceCreatePixelBufferSurface (const Config &config, size_t width, size_t height)
 Create an offscreen pixelbuffer surface. These are of limited use except in the context where applications need to render to a texture in an offscreen context. In such cases, a 1x1 pixel buffer surface is created to obtain a surface that can be used to make the context current on the background thread. More...
 

Detailed Description

A connection to an EGL display. Only one connection per application instance is sufficient.

The display connection is used to first choose a config from among the available, create a context from that config, and then use that context with a surface on one (and only one) thread at a time.

Definition at line 28 of file display.h.

Constructor & Destructor Documentation

◆ Display()

impeller::egl::Display::Display ( )

Definition at line 15 of file display.cc.

15 {
16 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
17
18 if (::eglInitialize(display, nullptr, nullptr) != EGL_TRUE) {
20 return;
21 }
22 display_ = display;
23}
#define IMPELLER_LOG_EGL_ERROR
Definition: egl.h:25

◆ ~Display()

impeller::egl::Display::~Display ( )
virtual

Definition at line 25 of file display.cc.

25 {
26 if (display_ != EGL_NO_DISPLAY) {
27 if (::eglTerminate(display_) != EGL_TRUE) {
29 }
30 }
31}

Member Function Documentation

◆ ChooseConfig()

std::unique_ptr< Config > impeller::egl::Display::ChooseConfig ( ConfigDescriptor  config) const
virtual

Choose a config that most closely matches a given descriptor. If there are no matches, this method returns nullptr.

Parameters
[in]configThe configuration
Returns
A config that matches a descriptor if one is available. nullptr otherwise.

Definition at line 72 of file display.cc.

72 {
73 if (!display_) {
74 return nullptr;
75 }
76
77 std::vector<EGLint> attributes;
78
79 {
80 attributes.push_back(EGL_RENDERABLE_TYPE);
81 switch (config.api) {
82 case API::kOpenGL:
83 attributes.push_back(EGL_OPENGL_BIT);
84 break;
85 case API::kOpenGLES2:
86 attributes.push_back(EGL_OPENGL_ES2_BIT);
87 break;
88 case API::kOpenGLES3:
89 attributes.push_back(EGL_OPENGL_ES3_BIT);
90 break;
91 }
92 }
93
94 {
95 attributes.push_back(EGL_SURFACE_TYPE);
96 switch (config.surface_type) {
98 attributes.push_back(EGL_WINDOW_BIT);
99 break;
101 attributes.push_back(EGL_PBUFFER_BIT);
102 break;
103 }
104 }
105
106 {
107 switch (config.color_format) {
109 attributes.push_back(EGL_RED_SIZE);
110 attributes.push_back(8);
111 attributes.push_back(EGL_GREEN_SIZE);
112 attributes.push_back(8);
113 attributes.push_back(EGL_BLUE_SIZE);
114 attributes.push_back(8);
115 attributes.push_back(EGL_ALPHA_SIZE);
116 attributes.push_back(8);
117 break;
119 attributes.push_back(EGL_RED_SIZE);
120 attributes.push_back(5);
121 attributes.push_back(EGL_GREEN_SIZE);
122 attributes.push_back(6);
123 attributes.push_back(EGL_BLUE_SIZE);
124 attributes.push_back(5);
125 break;
126 }
127 }
128
129 {
130 attributes.push_back(EGL_DEPTH_SIZE);
131 attributes.push_back(static_cast<EGLint>(config.depth_bits));
132 }
133
134 {
135 attributes.push_back(EGL_STENCIL_SIZE);
136 attributes.push_back(static_cast<EGLint>(config.stencil_bits));
137 }
138
139 {
140 const auto sample_count = static_cast<EGLint>(config.samples);
141 if (sample_count > 1) {
142 attributes.push_back(EGL_SAMPLE_BUFFERS);
143 attributes.push_back(1);
144 attributes.push_back(EGL_SAMPLES);
145 attributes.push_back(sample_count);
146 }
147 }
148
149 // termination sentinel must be present.
150 attributes.push_back(EGL_NONE);
151
152 EGLConfig config_out = nullptr;
153 EGLint config_count_out = 0;
154 if (::eglChooseConfig(display_, // display
155 attributes.data(), // attributes (null terminated)
156 &config_out, // matched configs
157 1, // configs array size
158 &config_count_out // match configs count
159 ) != EGL_TRUE) {
161 return nullptr;
162 }
163
164 if (config_count_out != 1u) {
166 return nullptr;
167 }
168
169 return std::make_unique<Config>(config, config_out);
170}

◆ CreateContext()

std::unique_ptr< Context > impeller::egl::Display::CreateContext ( const Config config,
const Context share_context 
)
virtual

Create a context with a supported config. The supported config can be obtained via a successful call to ChooseConfig.

Parameters
[in]configThe configuration.
[in]share_contextThe share context. Context within the same share-group use the same handle table. The contexts should still only be used exclusively on each thread however.
Returns
A context if one can be created. nullptr otherwise.

Definition at line 37 of file display.cc.

38 {
39 const auto& desc = config.GetDescriptor();
40
41 std::vector<EGLint> attributes;
42 switch (desc.api) {
43 case API::kOpenGL:
44 break;
45 case API::kOpenGLES2:
46 attributes.push_back(EGL_CONTEXT_CLIENT_VERSION);
47 attributes.push_back(2);
48 break;
49 case API::kOpenGLES3:
50 attributes.push_back(EGL_CONTEXT_CLIENT_VERSION);
51 attributes.push_back(3);
52 break;
53 }
54 // Termination sentinel must be present.
55 attributes.push_back(EGL_NONE);
56
57 auto context = ::eglCreateContext(
58 display_, // display
59 config.GetHandle(), // config
60 share_context != nullptr ? share_context->GetHandle() : nullptr, // share
61 attributes.data() // attributes
62 );
63
64 if (context == EGL_NO_CONTEXT) {
66 return nullptr;
67 }
68
69 return std::unique_ptr<Context>(new Context(display_, context));
70}

◆ CreatePixelBufferSurface()

std::unique_ptr< Surface > impeller::egl::Display::CreatePixelBufferSurface ( const Config config,
size_t  width,
size_t  height 
)
virtual

Create an offscreen pixelbuffer surface. These are of limited use except in the context where applications need to render to a texture in an offscreen context. In such cases, a 1x1 pixel buffer surface is created to obtain a surface that can be used to make the context current on the background thread.

Parameters
[in]configThe configuration
[in]widthThe width
[in]heightThe height
Returns
A valid pixel buffer surface if one can be created. nullptr otherwise.

Definition at line 188 of file display.cc.

190 {
191 // clang-format off
192 const EGLint attribs[] = {
193 EGL_WIDTH, static_cast<EGLint>(width),
194 EGL_HEIGHT, static_cast<EGLint>(height),
195 EGL_NONE
196 };
197 // clang-format on
198 auto surface = ::eglCreatePbufferSurface(display_, // display
199 config.GetHandle(), // config
200 attribs // attrib_list
201 );
202 if (surface == EGL_NO_SURFACE) {
204 return nullptr;
205 }
206 return std::unique_ptr<Surface>(new Surface(display_, surface));
207}
VkSurfaceKHR surface
Definition: main.cc:49
int32_t height
int32_t width

◆ CreateWindowSurface()

std::unique_ptr< Surface > impeller::egl::Display::CreateWindowSurface ( const Config config,
EGLNativeWindowType  window 
)
virtual

Create a window surface. The window is an opaque pointer whose value value is platform specific. For instance, ANativeWindow on Android.

Parameters
[in]configA valid configuration. One can be obtained via ChooseConfig.
[in]windowAn opaque pointer to a platform specific window handle.
Returns
A valid window surface if one can be created. nullptr otherwise.

Definition at line 172 of file display.cc.

174 {
175 const EGLint attribs[] = {EGL_NONE};
176 auto surface = ::eglCreateWindowSurface(display_, // display
177 config.GetHandle(), // config
178 window, // window
179 attribs // attrib_list
180 );
181 if (surface == EGL_NO_SURFACE) {
183 return nullptr;
184 }
185 return std::unique_ptr<Surface>(new Surface(display_, surface));
186}
GLFWwindow * window
Definition: main.cc:45

◆ IsValid()

bool impeller::egl::Display::IsValid ( ) const
virtual
Returns
True if the display connection is valid.

Definition at line 33 of file display.cc.

33 {
34 return display_ != EGL_NO_DISPLAY;
35}

The documentation for this class was generated from the following files: