| Flutter Windows Embedder |

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
flutter::AngleSurfaceManager Class Reference

`#include <angle_surface_manager.h>`

## Public Member Functions
virtual | ~AngleSurfaceManager ()
virtual bool | CreateSurface (WindowsRenderTarget *render_target, EGLint width, EGLint height, bool enable_vsync)
virtual void | ResizeSurface (WindowsRenderTarget *render_target, EGLint width, EGLint height, bool enable_vsync)
void | GetSurfaceDimensions (EGLint *width, EGLint *height)
virtual void | DestroySurface ()
bool | HasContextCurrent ()
bool | MakeCurrent ()
bool | ClearCurrent ()
bool | ClearContext ()
bool | MakeResourceCurrent ()
EGLBoolean | SwapBuffers ()
EGLSurface | CreateSurfaceFromHandle (EGLenum handle_type, EGLClientBuffer handle, const EGLint *attributes) const
EGLDisplay | egl_display () const
virtual void | SetVSyncEnabled (bool enabled)
bool | GetDevice (ID3D11Device **device)

## Static Public Member Functions
static std::unique_ptr< AngleSurfaceManager > | Create (bool enable_impeller)

## Protected Member Functions
| AngleSurfaceManager (bool enable_impeller)

## Detailed Description

Definition at line 28 of file angle_surface_manager.h.

## Constructor & Destructor Documentation

## ◆ ~AngleSurfaceManager()

flutter::AngleSurfaceManager::~AngleSurfaceManager | ( |  | ) |
| virtual

Definition at line 41 of file angle_surface_manager.cc.

41 {
42 CleanUp();
43 --instance_count_;
44 }

## ◆ AngleSurfaceManager()

flutter::AngleSurfaceManager::AngleSurfaceManager | ( | bool | enable_impeller | ) |
| explicit protected

Definition at line 33 of file angle_surface_manager.cc.

34 : egl_config_(nullptr),
35 egl_display_(EGL_NO_DISPLAY),
36 egl_context_(EGL_NO_CONTEXT) {
37 initialize_succeeded_ = Initialize(enable_impeller);
38 ++instance_count_;
39 }

Referenced by Create().

## Member Function Documentation

## ◆ ClearContext()

bool flutter::AngleSurfaceManager::ClearContext | ( |  | ) |

Definition at line 322 of file angle_surface_manager.cc.

322 {
323 return (eglMakeCurrent(egl_display_, nullptr, nullptr, egl_context_) ==
324 EGL_TRUE);
325 }

Referenced by ResizeSurface().

## ◆ ClearCurrent()

bool flutter::AngleSurfaceManager::ClearCurrent | ( |  | ) |

Definition at line 317 of file angle_surface_manager.cc.

317 {
318 return (eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
319 EGL_NO_CONTEXT) == EGL_TRUE);
320 }

## ◆ Create()

std::unique_ptr< AngleSurfaceManager > flutter::AngleSurfaceManager::Create | ( | bool | enable_impeller | ) |
| static

Definition at line 23 of file angle_surface_manager.cc.

24 {
25 std::unique_ptr<AngleSurfaceManager> manager;
26 manager.reset(new AngleSurfaceManager(enable_impeller));
27 if (!manager->initialize_succeeded_) {
28 return nullptr;
29 }
30 return std::move(manager);
31 }

References AngleSurfaceManager().

## ◆ CreateSurface()

bool flutter::AngleSurfaceManager::CreateSurface | ( | WindowsRenderTarget * | render_target,
|  | EGLint | width,
|  | EGLint | height,
|  | bool | enable_vsync
| ) |  |
| virtual

Definition at line 232 of file angle_surface_manager.cc.

235 {
236 if (!render_target || !initialize_succeeded_) {
237 return false;
238 }
239
240 EGLSurface surface = EGL_NO_SURFACE;
241
242 const EGLint surfaceAttributes[] = {
243 EGL_FIXED_SIZE_ANGLE, EGL_TRUE, EGL_WIDTH, width,
244 EGL_HEIGHT, height, EGL_NONE};
245
246 surface = eglCreateWindowSurface(
247 egl_display_, egl_config_,
248 static_cast<EGLNativeWindowType>(std::get<HWND>(*render_target)),
249 surfaceAttributes);
250 if (surface == EGL_NO_SURFACE) {
251 LogEglError("Surface creation failed.");
252 return false;
253 }
254
255 surface_width_ = width;
256 surface_height_ = height;
257 render_surface_ = surface;
258
259 if (!MakeCurrent()) {
260 LogEglError("Unable to make surface current to update the swap interval");
261 return false;
262 }
263
264 SetVSyncEnabled(vsync_enabled);
265 return true;
266 }

References LogEglError(), MakeCurrent(), and SetVSyncEnabled().

Referenced by ResizeSurface().

## ◆ CreateSurfaceFromHandle()

EGLSurface flutter::AngleSurfaceManager::CreateSurfaceFromHandle | ( | EGLenum | handle_type,
|  | EGLClientBuffer | handle,
|  | const EGLint * | attributes
| ) |  | const

Definition at line 336 of file angle_surface_manager.cc.

339 {
340 return eglCreatePbufferFromClientBuffer(egl_display_, handle_type, handle,
341 egl_config_, attributes);
342 }

## ◆ DestroySurface()

void flutter::AngleSurfaceManager::DestroySurface | ( |  | ) |
| virtual

Definition at line 301 of file angle_surface_manager.cc.

301 {
302 if (egl_display_ != EGL_NO_DISPLAY && render_surface_ != EGL_NO_SURFACE) {
303 eglDestroySurface(egl_display_, render_surface_);
304 }
305 render_surface_ = EGL_NO_SURFACE;
306 }

Referenced by ResizeSurface().

## ◆ egl_display()

EGLDisplay flutter::AngleSurfaceManager::egl_display | ( |  | ) | const
| inline

Definition at line 90 of file angle_surface_manager.h.

90 { return egl_display_; };

## ◆ GetDevice()

bool flutter::AngleSurfaceManager::GetDevice | ( | ID3D11Device ** | device | ) |

Definition at line 356 of file angle_surface_manager.cc.

356 {
357 if (!resolved_device_) {
358 PFNEGLQUERYDISPLAYATTRIBEXTPROC egl_query_display_attrib_EXT =
359 reinterpret_cast<PFNEGLQUERYDISPLAYATTRIBEXTPROC>(
360 eglGetProcAddress("eglQueryDisplayAttribEXT"));
361
362 PFNEGLQUERYDEVICEATTRIBEXTPROC egl_query_device_attrib_EXT =
363 reinterpret_cast<PFNEGLQUERYDEVICEATTRIBEXTPROC>(
364 eglGetProcAddress("eglQueryDeviceAttribEXT"));
365
366 if (!egl_query_display_attrib_EXT || !egl_query_device_attrib_EXT) {
367 return false;
368 }
369
370 EGLAttrib egl_device = 0;
371 EGLAttrib angle_device = 0;
372 if (egl_query_display_attrib_EXT(egl_display_, EGL_DEVICE_EXT,
373 &egl_device) == EGL_TRUE) {
374 if (egl_query_device_attrib_EXT(
375 reinterpret_cast<EGLDeviceEXT>(egl_device),
376 EGL_D3D11_DEVICE_ANGLE, &angle_device) == EGL_TRUE) {
377 resolved_device_ = reinterpret_cast<ID3D11Device*>(angle_device);
378 }
379 }
380 }
381
382 resolved_device_.CopyTo(device);
383 return (resolved_device_ != nullptr);
384 }

## ◆ GetSurfaceDimensions()

void flutter::AngleSurfaceManager::GetSurfaceDimensions | ( | EGLint * | width,
|  | EGLint * | height
| ) |  |

Definition at line 287 of file angle_surface_manager.cc.

287 {
288 if (render_surface_ == EGL_NO_SURFACE || !initialize_succeeded_) {
289 *width = 0;
290 *height = 0;
291 return;
292 }
293
294 // Can't use eglQuerySurface here; Because we're not using
295 // EGL_FIXED_SIZE_ANGLE flag anymore, Angle may resize the surface before
296 // Flutter asks it to, which breaks resize redraw synchronization
297 *width = surface_width_;
298 *height = surface_height_;
299 }

Referenced by ResizeSurface().

## ◆ HasContextCurrent()

bool flutter::AngleSurfaceManager::HasContextCurrent | ( |  | ) |

Definition at line 308 of file angle_surface_manager.cc.

308 {
309 return eglGetCurrentContext() != EGL_NO_CONTEXT;
310 }

## ◆ MakeCurrent()

bool flutter::AngleSurfaceManager::MakeCurrent | ( |  | ) |

Definition at line 312 of file angle_surface_manager.cc.

312 {
313 return (eglMakeCurrent(egl_display_, render_surface_, render_surface_,
314 egl_context_) == EGL_TRUE);
315 }

Referenced by CreateSurface(), and flutter::FlutterWindowsView::OnDwmCompositionChanged().

## ◆ MakeResourceCurrent()

bool flutter::AngleSurfaceManager::MakeResourceCurrent | ( |  | ) |

Definition at line 327 of file angle_surface_manager.cc.

327 {
328 return (eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
329 egl_resource_context_) == EGL_TRUE);
330 }

## ◆ ResizeSurface()

void flutter::AngleSurfaceManager::ResizeSurface | ( | WindowsRenderTarget * | render_target,
|  | EGLint | width,
|  | EGLint | height,
|  | bool | enable_vsync
| ) |  |
| virtual

Definition at line 268 of file angle_surface_manager.cc.

271 {
272 EGLint existing_width, existing_height;
273 GetSurfaceDimensions(&existing_width, &existing_height);
274 if (width != existing_width || height != existing_height) {
275 surface_width_ = width;
276 surface_height_ = height;
277
278 ClearContext();
279 DestroySurface();
280 if (!CreateSurface(render_target, width, height, vsync_enabled)) {
281 FML_LOG(ERROR)
282 << "AngleSurfaceManager::ResizeSurface failed to create surface";
283 }
284 }
285 }

References ClearContext(), CreateSurface(), DestroySurface(), and GetSurfaceDimensions().

## ◆ SetVSyncEnabled()

void flutter::AngleSurfaceManager::SetVSyncEnabled | ( | bool | enabled | ) |
| virtual

Definition at line 344 of file angle_surface_manager.cc.

344 {
345 // OpenGL swap intervals can be used to prevent screen tearing.
346 // If enabled, the raster thread blocks until the v-blank.
347 // This is unnecessary if DWM composition is enabled.
348 // See: https://www.khronos.org/opengl/wiki/Swap_Interval
349 // See: https://learn.microsoft.com/windows/win32/dwm/composition-ovw
350 if (eglSwapInterval(egl_display_, enabled ? 1 : 0) != EGL_TRUE) {
351 LogEglError("Unable to update the swap interval");
352 return;
353 }
354 }

References LogEglError().

Referenced by CreateSurface(), and flutter::FlutterWindowsView::OnDwmCompositionChanged().

## ◆ SwapBuffers()

EGLBoolean flutter::AngleSurfaceManager::SwapBuffers | ( |  | ) |

Definition at line 332 of file angle_surface_manager.cc.

332 {
333 return (eglSwapBuffers(egl_display_, render_surface_));
334 }

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

- shell/platform/windows/angle_surface_manager.h
- shell/platform/windows/angle_surface_manager.cc

flutter::AngleSurfaceManager::ClearContext
bool ClearContext()
Definition: angle_surface_manager.cc:322
flutter::AngleSurfaceManager::CreateSurface
virtual bool CreateSurface(WindowsRenderTarget *render_target, EGLint width, EGLint height, bool enable_vsync)
Definition: angle_surface_manager.cc:232
LogEglError
static void LogEglError(std::string message)
Definition: angle_surface_manager.cc:13
flutter::AngleSurfaceManager::AngleSurfaceManager
AngleSurfaceManager(bool enable_impeller)
Definition: angle_surface_manager.cc:33
flutter::AngleSurfaceManager::DestroySurface
virtual void DestroySurface()
Definition: angle_surface_manager.cc:301
flutter::AngleSurfaceManager::MakeCurrent
bool MakeCurrent()
Definition: angle_surface_manager.cc:312
flutter::AngleSurfaceManager::SetVSyncEnabled
virtual void SetVSyncEnabled(bool enabled)
Definition: angle_surface_manager.cc:344
flutter::AngleSurfaceManager::GetSurfaceDimensions
void GetSurfaceDimensions(EGLint *width, EGLint *height)
Definition: angle_surface_manager.cc:287