12 Context::Context(EGLDisplay display, EGLContext context)
13 : display_(display), context_(context) {}
16 if (context_ != EGL_NO_CONTEXT) {
17 if (::eglDestroyContext(display_, context_) != EGL_TRUE) {
23 bool Context::IsValid()
const {
24 return context_ != EGL_NO_CONTEXT;
27 const EGLContext& Context::GetHandle()
const {
35 if (display != ::eglGetCurrentDisplay() ||
36 draw != ::eglGetCurrentSurface(EGL_DRAW) ||
37 read != ::eglGetCurrentSurface(EGL_READ) ||
38 context != ::eglGetCurrentContext()) {
39 return ::eglMakeCurrent(display, draw, read, context);
45 bool Context::MakeCurrent(
const Surface& surface)
const {
46 if (context_ == EGL_NO_CONTEXT) {
57 DispatchLifecyleEvent(LifecycleEvent::kDidMakeCurrent);
61 bool Context::ClearCurrent()
const {
62 DispatchLifecyleEvent(LifecycleEvent::kWillClearCurrent);
74 std::optional<UniqueID> Context::AddLifecycleListener(
81 listeners_[id] = listener;
85 bool Context::RemoveLifecycleListener(
UniqueID id) {
87 auto found = listeners_.find(
id);
88 if (found == listeners_.end()) {
91 listeners_.erase(found);
95 void Context::DispatchLifecyleEvent(LifecycleEvent event)
const {
97 for (
const auto& listener : listeners_) {
98 listener.second(event);
102 bool Context::IsCurrent()
const {
103 return ::eglGetCurrentContext() == context_;
std::function< void(LifecycleEvent)> LifecycleListener
An instance of an EGL surface. There is no ability to create surfaces directly. Instead,...
const EGLSurface & GetHandle() const
#define IMPELLER_LOG_EGL_ERROR
static EGLBoolean EGLMakeCurrentIfNecessary(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context)