Mir
client_helpers.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2015 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17  */
18 
19 #ifndef MIR_EXAMLPES_CLIENT_HELPERS_H_
20 #define MIR_EXAMLPES_CLIENT_HELPERS_H_
21 
23 #include <EGL/egl.h>
24 #include <GLES2/gl2.h>
25 #include <memory>
26 
27 namespace mir
28 {
29 namespace examples
30 {
32 {
33 public:
34  Connection(char const* socket_file);
35  ~Connection();
36  operator MirConnection*();
37  Connection(Connection const&) = delete;
38  Connection& operator=(Connection const&) = delete;
39 private:
40  MirConnection* connection;
41 };
42 
44 {
45 public:
46  NormalSurface(Connection& connection, unsigned int width, unsigned int height, bool prefers_alpha = false);
47 
48  operator MirSurface*() const;
49 private:
50  MirSurface* create_surface(MirConnection* connection, unsigned int width, unsigned int height, bool prefers_alpha);
51  std::function<void(MirSurface*)> const surface_deleter{
52  [](MirSurface* surface) { mir_surface_release_sync(surface); }
53  };
54  std::unique_ptr<MirSurface, decltype(surface_deleter)> surface;
55  NormalSurface(NormalSurface const&) = delete;
56  NormalSurface& operator=(NormalSurface const&) = delete;
57 };
58 
59 class Context
60 {
61 public:
62  Context(Connection& connection, MirSurface* surface, int swap_interval);
63  void make_current();
64  void release_current();
65  void swapbuffers();
66  Context(Context const&) = delete;
67  Context& operator=(Context const&) = delete;
68 private:
69  EGLConfig chooseconfig(EGLDisplay disp);
70  EGLNativeDisplayType native_display;
71  EGLNativeWindowType native_window;
72  struct Display
73  {
74  Display(EGLNativeDisplayType native);
75  ~Display();
76  EGLDisplay disp;
77  } display;
78  EGLConfig config;
79  struct Surface
80  {
81  Surface(EGLDisplay display, EGLConfig config, EGLNativeWindowType native_window);
82  ~Surface();
83  EGLDisplay disp;
84  EGLSurface surface;
85  } surface;
86  struct EglContext
87  {
88  EglContext(EGLDisplay disp, EGLConfig config);
89  ~EglContext();
90  EGLint context_attribs[3] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
91  EGLDisplay disp;
92  EGLContext context;
93  } context;
94 };
95 
96 struct Shader
97 {
98  Shader(GLchar const* const* src, GLuint type);
99  ~Shader();
100  GLuint shader;
101 };
102 
103 struct Program
104 {
105  Program(Shader& vertex, Shader& fragment);
106  ~Program();
107  GLuint program;
108 };
109 }
110 }
111 #endif /* MIR_EXAMLPES_CLIENT_HELPERS_H_ */
All things Mir.
Definition: atomic_callback.h:25
Definition: mir_surface.h:136
~Program()
Definition: client_helpers.cpp:204
Definition: client_helpers.h:103
NormalSurface(Connection &connection, unsigned int width, unsigned int height, bool prefers_alpha=false)
Definition: client_helpers.cpp:48
Context & operator=(Context const &)=delete
~Connection()
Definition: client_helpers.cpp:38
Context(Connection &connection, MirSurface *surface, int swap_interval)
Definition: client_helpers.cpp:93
Shader(GLchar const *const *src, GLuint type)
Definition: client_helpers.cpp:184
Definition: client_helpers.h:43
void mir_surface_release_sync(MirSurface *surface)
Release the specified surface like in mir_surface_release(), but also wait for the operation to compl...
Definition: mir_surface_api.cpp:271
void make_current()
Definition: client_helpers.cpp:107
GLuint shader
Definition: client_helpers.h:100
Connection & operator=(Connection const &)=delete
Connection(char const *socket_file)
Definition: client_helpers.cpp:30
unsigned int width
Definition: black_arrow.c:4
Definition: client_helpers.h:96
unsigned int height
Definition: black_arrow.c:5
void release_current()
Definition: client_helpers.cpp:113
GLuint program
Definition: client_helpers.h:107
Program(Shader &vertex, Shader &fragment)
Definition: client_helpers.cpp:196
Definition: mir_connection.h:88
Definition: client_helpers.h:59
~Shader()
Definition: client_helpers.cpp:191
Definition: client_helpers.h:31
void swapbuffers()
Definition: client_helpers.cpp:118

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Oct 8 16:20:16 UTC 2015