Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
impeller::egl::Context Class Reference

#include <context.h>

Public Types

enum class  LifecycleEvent { kDidMakeCurrent , kWillClearCurrent }
 
using LifecycleListener = std::function< void(LifecycleEvent)>
 

Public Member Functions

 Context (EGLDisplay display, EGLContext context)
 
 ~Context ()
 
bool IsValid () const
 
const EGLContext & GetHandle () const
 
bool MakeCurrent (const Surface &surface) const
 
bool ClearCurrent () const
 
std::optional< UniqueIDAddLifecycleListener (const LifecycleListener &listener)
 
bool RemoveLifecycleListener (UniqueID id)
 

Detailed Description

Definition at line 20 of file context.h.

Member Typedef Documentation

◆ LifecycleListener

Definition at line 38 of file context.h.

Member Enumeration Documentation

◆ LifecycleEvent

Enumerator
kDidMakeCurrent 
kWillClearCurrent 

Definition at line 34 of file context.h.

Constructor & Destructor Documentation

◆ Context()

Context::Context ( EGLDisplay  display,
EGLContext  context 
)

Definition at line 12 of file context.cc.

13 : display_(display), context_(context) {}

◆ ~Context()

Context::~Context ( )

Definition at line 15 of file context.cc.

15 {
16 if (context_ != EGL_NO_CONTEXT) {
17 if (::eglDestroyContext(display_, context_) != EGL_TRUE) {
19 }
20 }
21}
#define IMPELLER_LOG_EGL_ERROR
Definition egl.h:19

Member Function Documentation

◆ AddLifecycleListener()

std::optional< UniqueID > Context::AddLifecycleListener ( const LifecycleListener listener)

Definition at line 74 of file context.cc.

75 {
76 if (!listener) {
77 return std::nullopt;
78 }
79 WriterLock lock(listeners_mutex_);
80 UniqueID id;
81 listeners_[id] = listener;
82 return id;
83}
const uintptr_t id

◆ ClearCurrent()

bool Context::ClearCurrent ( ) const

Definition at line 61 of file context.cc.

61 {
62 DispatchLifecyleEvent(LifecycleEvent::kWillClearCurrent);
63 const auto result = EGLMakeCurrentIfNecessary(display_, //
64 EGL_NO_SURFACE, //
65 EGL_NO_SURFACE, //
66 EGL_NO_CONTEXT //
67 ) == EGL_TRUE;
68 if (!result) {
70 }
71 return result;
72}
GAsyncResult * result
static EGLBoolean EGLMakeCurrentIfNecessary(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context)
Definition context.cc:31

◆ GetHandle()

const EGLContext & Context::GetHandle ( ) const

Definition at line 27 of file context.cc.

27 {
28 return context_;
29}

◆ IsValid()

bool Context::IsValid ( ) const

Definition at line 23 of file context.cc.

23 {
24 return context_ != EGL_NO_CONTEXT;
25}

◆ MakeCurrent()

bool Context::MakeCurrent ( const Surface surface) const

Definition at line 45 of file context.cc.

45 {
46 if (context_ == EGL_NO_CONTEXT) {
47 return false;
48 }
49 const auto result = EGLMakeCurrentIfNecessary(display_, //
50 surface.GetHandle(), //
51 surface.GetHandle(), //
52 context_ //
53 ) == EGL_TRUE;
54 if (!result) {
56 }
57 DispatchLifecyleEvent(LifecycleEvent::kDidMakeCurrent);
58 return result;
59}
VkSurfaceKHR surface
Definition main.cc:49

◆ RemoveLifecycleListener()

bool Context::RemoveLifecycleListener ( UniqueID  id)

Definition at line 85 of file context.cc.

85 {
86 WriterLock lock(listeners_mutex_);
87 auto found = listeners_.find(id);
88 if (found == listeners_.end()) {
89 return false;
90 }
91 listeners_.erase(found);
92 return true;
93}

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