12Context::Context(EGLDisplay display, EGLContext context)
13 :
display_(display), context_(context) {}
16 if (context_ != EGL_NO_CONTEXT) {
17 if (::eglDestroyContext(
display_, context_) != EGL_TRUE) {
23bool Context::IsValid()
const {
24 return context_ != EGL_NO_CONTEXT;
27const 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);
46 if (context_ == EGL_NO_CONTEXT) {
57 DispatchLifecyleEvent(LifecycleEvent::kDidMakeCurrent);
61bool Context::ClearCurrent()
const {
62 DispatchLifecyleEvent(LifecycleEvent::kWillClearCurrent);
74std::optional<UniqueID> Context::AddLifecycleListener(
81 listeners_[
id] = listener;
85bool Context::RemoveLifecycleListener(
UniqueID id) {
87 auto found = listeners_.find(
id);
88 if (found == listeners_.end()) {
91 listeners_.erase(found);
95void Context::DispatchLifecyleEvent(LifecycleEvent
event)
const {
97 for (
const auto& listener : listeners_) {
98 listener.second(
event);
static bool read(SkStream *stream, void *buffer, size_t amount)
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
std::function< void(LifecycleEvent)> LifecycleListener
An instance of an EGL surface. There is no ability to create surfaces directly. Instead,...
static EGLBoolean EGLMakeCurrentIfNecessary(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context)