| Flutter Impeller |

Public Types | Public Member Functions | List of all members
impeller::egl::Context Class Reference

`#include <context.h>`

## Public Types
enum | LifecycleEvent { LifecycleEvent::kDidMakeCurrent, LifecycleEvent::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< UniqueID > | AddLifecycleListener (const LifecycleListener &listener)
bool | RemoveLifecycleListener (UniqueID id)

## Detailed Description

Definition at line 19 of file context.h.

## Member Typedef Documentation

## ◆ LifecycleListener

using impeller::egl::Context::LifecycleListener = std::function<void(LifecycleEvent)>

Definition at line 37 of file context.h.

## Member Enumeration Documentation

## ◆ LifecycleEvent

enum impeller::egl::Context::LifecycleEvent
| strong

Enumerator
kDidMakeCurrent |
kWillClearCurrent |

Definition at line 33 of file context.h.

33 {
34 kDidMakeCurrent,
35 kWillClearCurrent,
36 };

## Constructor & Destructor Documentation

## ◆ Context()

impeller::egl::Context::Context | ( | EGLDisplay | display,
|  | EGLContext | context
| ) |  |

Definition at line 12 of file context.cc.

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

## ◆ ~Context()

impeller::egl::Context::~Context | ( |  | ) |

Definition at line 15 of file context.cc.

15 {
16 if (context_ != EGL_NO_CONTEXT) {
17 if (::eglDestroyContext(display_, context_) != EGL_TRUE) {
18 IMPELLER_LOG_EGL_ERROR;
19 }
20 }
21 }

References IMPELLER_LOG_EGL_ERROR.

## Member Function Documentation

## ◆ AddLifecycleListener()

std::optional< UniqueID > impeller::egl::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 }

## ◆ ClearCurrent()

bool impeller::egl::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) {
69 IMPELLER_LOG_EGL_ERROR;
70 }
71 return result;
72 }

References impeller::egl::EGLMakeCurrentIfNecessary(), IMPELLER_LOG_EGL_ERROR, and kWillClearCurrent.

## ◆ GetHandle()

const EGLContext & impeller::egl::Context::GetHandle | ( |  | ) | const

Definition at line 27 of file context.cc.

27 {
28 return context_;
29 }

Referenced by impeller::egl::Display::CreateContext().

## ◆ IsValid()

bool impeller::egl::Context::IsValid | ( |  | ) | const

Definition at line 23 of file context.cc.

23 {
24 return context_ != EGL_NO_CONTEXT;
25 }

## ◆ MakeCurrent()

bool impeller::egl::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) {
55 IMPELLER_LOG_EGL_ERROR;
56 }
57 DispatchLifecyleEvent(LifecycleEvent::kDidMakeCurrent);
58 return result;
59 }

References impeller::egl::EGLMakeCurrentIfNecessary(), impeller::egl::Surface::GetHandle(), IMPELLER_LOG_EGL_ERROR, and kDidMakeCurrent.

## ◆ RemoveLifecycleListener()

bool impeller::egl::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:

- impeller/toolkit/egl/context.h
- impeller/toolkit/egl/context.cc

impeller::egl::Context::LifecycleEvent::kDidMakeCurrent
@ kDidMakeCurrent
impeller::egl::Context::LifecycleEvent::kWillClearCurrent
@ kWillClearCurrent
impeller::egl::EGLMakeCurrentIfNecessary
static EGLBoolean EGLMakeCurrentIfNecessary(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context)
Definition: context.cc:31
IMPELLER_LOG_EGL_ERROR
#define IMPELLER_LOG_EGL_ERROR
Definition: egl.h:18