Flutter Engine
flutter::AngleSurfaceManager Class Reference

#include <angle_surface_manager.h>

Public Member Functions

 ~AngleSurfaceManager ()
 
 AngleSurfaceManager (const AngleSurfaceManager &)=delete
 
AngleSurfaceManageroperator= (const AngleSurfaceManager &)=delete
 
bool CreateSurface (WindowsRenderTarget *render_target, EGLint width, EGLint height)
 
void ResizeSurface (WindowsRenderTarget *render_target, EGLint width, EGLint height)
 
void GetSurfaceDimensions (EGLint *width, EGLint *height)
 
void DestroySurface ()
 
bool MakeCurrent ()
 
bool ClearContext ()
 
bool MakeResourceCurrent ()
 
EGLBoolean SwapBuffers ()
 

Static Public Member Functions

static std::unique_ptr< AngleSurfaceManagerCreate ()
 

Detailed Description

Definition at line 25 of file angle_surface_manager.h.

Constructor & Destructor Documentation

◆ ~AngleSurfaceManager()

flutter::AngleSurfaceManager::~AngleSurfaceManager ( )

Definition at line 48 of file angle_surface_manager.cc.

References LogEglError(), and result.

48  {
49  CleanUp();
50  --instance_count_;
51 }

◆ AngleSurfaceManager()

flutter::AngleSurfaceManager::AngleSurfaceManager ( const AngleSurfaceManager )
delete

Member Function Documentation

◆ ClearContext()

bool flutter::AngleSurfaceManager::ClearContext ( )

Definition at line 315 of file angle_surface_manager.cc.

Referenced by ResizeSurface().

315  {
316  return (eglMakeCurrent(egl_display_, nullptr, nullptr, egl_context_) ==
317  EGL_TRUE);
318 }

◆ Create()

std::unique_ptr< AngleSurfaceManager > flutter::AngleSurfaceManager::Create ( )
static

Definition at line 31 of file angle_surface_manager.cc.

Referenced by flutter::FlutterWindowsEngine::FlutterWindowsEngine().

31  {
32  std::unique_ptr<AngleSurfaceManager> manager;
33  manager.reset(new AngleSurfaceManager());
34  if (!manager->initialize_succeeded_) {
35  return nullptr;
36  }
37  return std::move(manager);
38 }
AngleSurfaceManager(const AngleSurfaceManager &)=delete

◆ CreateSurface()

bool flutter::AngleSurfaceManager::CreateSurface ( WindowsRenderTarget render_target,
EGLint  width,
EGLint  height 
)

Definition at line 216 of file angle_surface_manager.cc.

References height, LogEglError(), target, and width.

Referenced by ResizeSurface().

218  {
219  if (!render_target || !initialize_succeeded_) {
220  return false;
221  }
222 
223  EGLSurface surface = EGL_NO_SURFACE;
224 
225 #ifdef WINUWP
226  const EGLint surfaceAttributes[] = {EGL_NONE};
227 #else
228  const EGLint surfaceAttributes[] = {
229  EGL_FIXED_SIZE_ANGLE, EGL_TRUE, EGL_WIDTH, width,
230  EGL_HEIGHT, height, EGL_NONE};
231 #endif
232 
233 #ifdef WINUWP
234 #ifdef USECOREWINDOW
235  auto target = std::get<winrt::Windows::UI::Core::CoreWindow>(*render_target);
236 #else
237  auto target =
238  std::get<winrt::Windows::UI::Composition::SpriteVisual>(*render_target);
239 #endif
240  surface = eglCreateWindowSurface(
241  egl_display_, egl_config_,
242  static_cast<EGLNativeWindowType>(winrt::get_abi(target)),
243  surfaceAttributes);
244 #else
245  surface = eglCreateWindowSurface(
246  egl_display_, egl_config_,
247  static_cast<EGLNativeWindowType>(std::get<HWND>(*render_target)),
248  surfaceAttributes);
249 #endif
250  if (surface == EGL_NO_SURFACE) {
251  LogEglError("Surface creation failed.");
252  }
253 
254  surface_width_ = width;
255  surface_height_ = height;
256  render_surface_ = surface;
257  return true;
258 }
uint32_t * target
int32_t width
int32_t height
static void LogEglError(std::string message)

◆ DestroySurface()

void flutter::AngleSurfaceManager::DestroySurface ( )

Definition at line 303 of file angle_surface_manager.cc.

Referenced by ResizeSurface().

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

◆ GetSurfaceDimensions()

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

Definition at line 289 of file angle_surface_manager.cc.

Referenced by ResizeSurface().

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

◆ MakeCurrent()

bool flutter::AngleSurfaceManager::MakeCurrent ( )

Definition at line 310 of file angle_surface_manager.cc.

310  {
311  return (eglMakeCurrent(egl_display_, render_surface_, render_surface_,
312  egl_context_) == EGL_TRUE);
313 }

◆ MakeResourceCurrent()

bool flutter::AngleSurfaceManager::MakeResourceCurrent ( )

Definition at line 320 of file angle_surface_manager.cc.

320  {
321  return (eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
322  egl_resource_context_) == EGL_TRUE);
323 }

◆ operator=()

AngleSurfaceManager& flutter::AngleSurfaceManager::operator= ( const AngleSurfaceManager )
delete

◆ ResizeSurface()

void flutter::AngleSurfaceManager::ResizeSurface ( WindowsRenderTarget render_target,
EGLint  width,
EGLint  height 
)

Definition at line 260 of file angle_surface_manager.cc.

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

262  {
263  EGLint existing_width, existing_height;
264  GetSurfaceDimensions(&existing_width, &existing_height);
265  if (width != existing_width || height != existing_height) {
266  surface_width_ = width;
267  surface_height_ = height;
268 
269  // TODO(clarkezone) convert ifdef to use use final implementation of angle
270  // resize API prototyped here
271  // https://github.com/clarkezone/angle/tree/resizeswapchaintest to eliminate
272  // unnecessary surface creation / desctruction by use ResizeSwapchain
273  // https://github.com/flutter/flutter/issues/79427
274 #ifdef WINUWP
275  // Resize render_surface_. Internaly this calls mSwapChain->ResizeBuffers
276  // avoiding the need to destory and recreate the underlying SwapChain.
277  eglPostSubBufferNV(egl_display_, render_surface_, 1, 1, width, height);
278 #else
279  ClearContext();
280  DestroySurface();
281  if (!CreateSurface(render_target, width, height)) {
282  std::cerr << "AngleSurfaceManager::ResizeSurface failed to create surface"
283  << std::endl;
284  }
285 #endif
286  }
287 }
void GetSurfaceDimensions(EGLint *width, EGLint *height)
int32_t width
int32_t height
bool CreateSurface(WindowsRenderTarget *render_target, EGLint width, EGLint height)

◆ SwapBuffers()

EGLBoolean flutter::AngleSurfaceManager::SwapBuffers ( )

Definition at line 325 of file angle_surface_manager.cc.

325  {
326  return (eglSwapBuffers(egl_display_, render_surface_));
327 }

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