| Flutter Windows Embedder |

surface.cc
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 #include "flutter/shell/platform/windows/egl/surface.h"
6
7 #include "flutter/shell/platform/windows/egl/egl.h"
8
9 namespace flutter {
10 namespace egl {
11
12 Surface::Surface(EGLDisplay display, EGLContext context, EGLSurface surface)
13 : display_(display), context_(context), surface_(surface) {}
14
15 Surface::~Surface() {
16 Destroy();
17 }
18
19 bool Surface::IsValid() const {
20 return is_valid_;
21 }
22
23 bool Surface::Destroy() {
24 if (surface_ != EGL_NO_SURFACE) {
25 // Ensure the surface is not current before destroying it.
26 if (::eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
27 EGL_NO_CONTEXT) != EGL_TRUE) {
28 WINDOWS_LOG_EGL_ERROR;
29 return false;
30 }
31
32 if (::eglDestroySurface(display_, surface_) != EGL_TRUE) {
33 WINDOWS_LOG_EGL_ERROR;
34 return false;
35 }
36 }
37
38 is_valid_ = false;
39 surface_ = EGL_NO_SURFACE;
40 return true;
41 }
42
43 bool Surface::IsCurrent() const {
44 return display_ == ::eglGetCurrentDisplay() &&
45 surface_ == ::eglGetCurrentSurface(EGL_DRAW) &&
46 surface_ == ::eglGetCurrentSurface(EGL_READ) &&
47 context_ == ::eglGetCurrentContext();
48 }
49
50 bool Surface::MakeCurrent() const {
51 if (::eglMakeCurrent(display_, surface_, surface_, context_) != EGL_TRUE) {
52 WINDOWS_LOG_EGL_ERROR;
53 return false;
54 }
55
56 return true;
57 }
58
59 bool Surface::SwapBuffers() const {
60 if (::eglSwapBuffers(display_, surface_) != EGL_TRUE) {
61 WINDOWS_LOG_EGL_ERROR;
62 return false;
63 }
64
65 return true;
66 }
67
68 const EGLSurface& Surface::GetHandle() const {
69 return surface_;
70 }
71
72 } // namespace egl
73 } // namespace flutter
flutter::egl::Surface::is_valid_
bool is_valid_
Definition: surface.h:48
flutter::egl::Surface::Surface
Surface(EGLDisplay display, EGLContext context, EGLSurface surface)
Definition: surface.cc:12
flutter::egl::Surface::~Surface
virtual ~Surface()
Definition: surface.cc:15
surface.h
WINDOWS_LOG_EGL_ERROR
#define WINDOWS_LOG_EGL_ERROR
Definition: egl.h:19
flutter::egl::Surface::Destroy
virtual bool Destroy()
Definition: surface.cc:23
flutter::egl::Surface::display_
EGLDisplay display_
Definition: surface.h:50
flutter::egl::Surface::GetHandle
virtual const EGLSurface & GetHandle() const
Definition: surface.cc:68
egl.h
flutter::egl::Surface::IsValid
virtual bool IsValid() const
Definition: surface.cc:19
flutter::egl::Surface::surface_
EGLSurface surface_
Definition: surface.h:52
flutter::egl::Surface::MakeCurrent
virtual bool MakeCurrent() const
Definition: surface.cc:50
flutter::egl::Surface::SwapBuffers
virtual bool SwapBuffers() const
Definition: surface.cc:59
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::egl::Surface::IsCurrent
virtual bool IsCurrent() const
Definition: surface.cc:43
flutter::egl::Surface::context_
EGLContext context_
Definition: surface.h:51