| Flutter Impeller |

context.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_TOOLKIT_EGL_CONTEXT_H_
6 #define FLUTTER_IMPELLER_TOOLKIT_EGL_CONTEXT_H_
7
8 #include <functional>
9
10 #include "flutter/fml/macros.h"
11 #include "impeller/base/comparable.h"
12 #include "impeller/base/thread.h"
13 #include "impeller/toolkit/egl/egl.h"
14
15 namespace impeller {
16 namespace egl {
17
18 class Surface;
19
20 class Context {
21 public:
22 Context(EGLDisplay display, EGLContext context);
23
24 ~Context();
25
26 bool IsValid() const;
27
28 const EGLContext& GetHandle() const;
29
30 bool MakeCurrent(const Surface& surface) const;
31
32 bool ClearCurrent() const;
33
34 enum class LifecycleEvent {
35 kDidMakeCurrent,
36 kWillClearCurrent,
37 };
38 using LifecycleListener = std::function<void(LifecycleEvent)>;
39 std::optional<UniqueID> AddLifecycleListener(
40 const LifecycleListener& listener);
41
42 bool RemoveLifecycleListener(UniqueID id);
43
44 private:
45 EGLDisplay display_ = EGL_NO_DISPLAY;
46 EGLContext context_ = EGL_NO_CONTEXT;
47 mutable RWMutex listeners_mutex_;
48 std::map<UniqueID, LifecycleListener> listeners_
49 IPLR_GUARDED_BY(listeners_mutex_);
50
51 void DispatchLifecyleEvent(LifecycleEvent event) const;
52
53 Context(const Context&) = delete;
54
55 Context& operator=(const Context&) = delete;
56 };
57
58 } // namespace egl
59 } // namespace impeller
60
61 #endif // FLUTTER_IMPELLER_TOOLKIT_EGL_CONTEXT_H_
impeller::egl::Context::GetHandle
const EGLContext & GetHandle() const
Definition: context.cc:27
impeller::egl::Context::LifecycleEvent::kDidMakeCurrent
@ kDidMakeCurrent
egl.h
impeller::egl::Context::LifecycleEvent::kWillClearCurrent
@ kWillClearCurrent
impeller::egl::Surface
Definition: surface.h:14
impeller::egl::Context
Definition: context.h:20
impeller::egl::Context::AddLifecycleListener
std::optional< UniqueID > AddLifecycleListener(const LifecycleListener &listener)
Definition: context.cc:74
impeller::egl::Context::RemoveLifecycleListener
bool RemoveLifecycleListener(UniqueID id)
Definition: context.cc:85
impeller::egl::Context::LifecycleListener
std::function< void(LifecycleEvent)> LifecycleListener
Definition: context.h:38
impeller::egl::Context::MakeCurrent
bool MakeCurrent(const Surface &surface) const
Definition: context.cc:45
impeller::egl::Context::ClearCurrent
bool ClearCurrent() const
Definition: context.cc:61
comparable.h
impeller::egl::Context::LifecycleEvent
LifecycleEvent
Definition: context.h:34
impeller::egl::Context::IsValid
bool IsValid() const
Definition: context.cc:23
impeller::egl::Context::~Context
~Context()
Definition: context.cc:15
impeller::egl::Context::Context
Context(EGLDisplay display, EGLContext context)
Definition: context.cc:12
impeller::UniqueID
Definition: comparable.h:16
thread.h
impeller
Definition: aiks_context.cc:10