@@ -16,38 +16,101 @@ namespace impeller {
1616namespace egl {
1717
1818class Surface ;
19-
19+ class Display ;
20+
21+ // ------------------------------------------------------------------------------
22+ // / @brief An instance of an EGL context.
23+ // /
24+ // / An EGL context can only be used on a single thread at a given
25+ // / time. A thread can only have a single context current at any
26+ // / given time.
27+ // /
28+ // / Context cannot be created directly. Only a valid instance of an
29+ // / egl::Display can create a context.
30+ // /
2031class Context {
2132 public:
22- Context (EGLDisplay display, EGLContext context);
23-
2433 ~Context ();
2534
35+ // ----------------------------------------------------------------------------
36+ // / @brief Determines if a valid context could be created. The context
37+ // / still needs to be made current on the thread for it to be
38+ // / useful.
39+ // /
40+ // / @return True if valid, False otherwise.
41+ // /
2642 bool IsValid () const ;
2743
44+ // ----------------------------------------------------------------------------
45+ // / @brief Get the underlying handle to the EGL context.
46+ // /
47+ // / @return The handle.
48+ // /
2849 const EGLContext& GetHandle () const ;
2950
51+ // ----------------------------------------------------------------------------
52+ // / @brief Make the context current on the calling thread. It is the
53+ // / caller responsibility to ensure that any context previously
54+ // / current on the thread must be cleared via `ClearCurrent`.
55+ // /
56+ // / @important The config used to create the surface must match the config
57+ // / used to create this context instance.
58+ // /
59+ // / @param[in] surface The surface to use to make the context current.
60+ // /
61+ // / @return If the context could be made current on the callers thread.
62+ // /
3063 bool MakeCurrent (const Surface& surface) const ;
3164
65+ // ----------------------------------------------------------------------------
66+ // / @brief Clear the thread association of this context.
67+ // /
68+ // / @return If the thread association could be cleared.
69+ // /
3270 bool ClearCurrent () const ;
3371
3472 enum class LifecycleEvent {
3573 kDidMakeCurrent ,
3674 kWillClearCurrent ,
3775 };
3876 using LifecycleListener = std::function<void (LifecycleEvent)>;
77+ // ----------------------------------------------------------------------------
78+ // / @brief Add a listener that gets invoked when the context is made and
79+ // / cleared current from the thread. Applications typically use
80+ // / this to manage workers that schedule OpenGL API calls that
81+ // / need to be careful about the context being current when
82+ // / called.
83+ // /
84+ // / @param[in] listener The listener
85+ // /
86+ // / @return A unique ID for the listener that can used used in
87+ // / `RemoveLifecycleListener` to remove a previously added
88+ // / listener.
89+ // /
3990 std::optional<UniqueID> AddLifecycleListener (
4091 const LifecycleListener& listener);
4192
93+ // ----------------------------------------------------------------------------
94+ // / @brief Remove a previously added context listener.
95+ // /
96+ // / @param[in] id The identifier obtained via a previous call to
97+ // / `AddLifecycleListener`.
98+ // /
99+ // / @return True if the listener could be removed.
100+ // /
42101 bool RemoveLifecycleListener (UniqueID id);
43102
44103 private:
104+ friend class Display ;
105+
45106 EGLDisplay display_ = EGL_NO_DISPLAY;
46107 EGLContext context_ = EGL_NO_CONTEXT;
47108 mutable RWMutex listeners_mutex_;
48109 std::map<UniqueID, LifecycleListener> listeners_ IPLR_GUARDED_BY (
49110 listeners_mutex_);
50111
112+ Context (EGLDisplay display, EGLContext context);
113+
51114 void DispatchLifecyleEvent (LifecycleEvent event) const ;
52115
53116 Context (const Context&) = delete ;
0 commit comments