| 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 #pragma once
6
7 #include <functional>
8
9 #include "flutter/fml/macros.h"
10 #include "impeller/base/comparable.h"
11 #include "impeller/base/thread.h"
12 #include "impeller/toolkit/egl/egl.h"
13
14 namespace impeller {
15 namespace egl {
16
17 class Surface;
18
19 class Context {
20 public:
21 Context(EGLDisplay display, EGLContext context);
22
23 ~Context();
24
25 bool IsValid() const;
26
27 const EGLContext& GetHandle() const;
28
29 bool MakeCurrent(const Surface& surface) const;
30
31 bool ClearCurrent() const;
32
33 enum class LifecycleEvent {
34 kDidMakeCurrent,
35 kWillClearCurrent,
36 };
37 using LifecycleListener = std::function<void(LifecycleEvent)>;
38 std::optional<UniqueID> AddLifecycleListener(
39 const LifecycleListener& listener);
40
41 bool RemoveLifecycleListener(UniqueID id);
42
43 private:
44 EGLDisplay display_ = EGL_NO_DISPLAY;
45 EGLContext context_ = EGL_NO_CONTEXT;
46 mutable RWMutex listeners_mutex_;
47 std::map<UniqueID, LifecycleListener> listeners_
48 IPLR_GUARDED_BY(listeners_mutex_);
49
50 void DispatchLifecyleEvent(LifecycleEvent event) const;
51
52 FML_DISALLOW_COPY_AND_ASSIGN(Context);
53 };
54
55 } // namespace egl
56 } // namespace impeller
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:13
impeller::egl::Context
Definition: context.h:19
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:37
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:33
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:19
thread.h
impeller
Definition: aiks_context.cc:10