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_EXAMPLES_CLIENT_HELPERS_H_
20 #define MIR_EXAMPLES_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(char const* socket_file, const char* name);
36  ~Connection();
37  operator MirConnection*();
38  Connection(Connection const&) = delete;
39  Connection& operator=(Connection const&) = delete;
40 private:
41  MirConnection* connection;
42 };
43 
45 {
46 public:
48  Connection& connection,
49  unsigned int width,
50  unsigned int height,
51  bool prefer_alpha = false,
52  bool hardware = true);
53 
54  operator MirBufferStream*() const;
55 private:
56  MirBufferStream* create_stream(
57  MirConnection* connection,
58  unsigned int width,
59  unsigned int height,
60  bool prefer_alpha,
61  bool hardware);
62 
63  std::unique_ptr<MirBufferStream, decltype(&mir_buffer_stream_release_sync)> const stream;
64 
65  BufferStream(BufferStream const&) = delete;
66  BufferStream& operator=(BufferStream const&) = delete;
67 };
68 
70 {
71 public:
72  NormalWindow(Connection& connection, unsigned int width, unsigned int height, bool prefers_alpha = false, bool hardware = true);
73 
74  operator MirWindow*() const;
75 private:
76  MirWindow* create_window(MirConnection* connection, unsigned int width, unsigned int height, bool prefers_alpha, bool hardware);
77  std::function<void(MirWindow*)> const window_deleter{
78  [](MirWindow* window) { mir_window_release_sync(window); }
79  };
80  std::unique_ptr<MirWindow, decltype(window_deleter)> window;
81  NormalWindow(NormalWindow const&) = delete;
82  NormalWindow& operator=(NormalWindow const&) = delete;
83 };
84 
85 class Context
86 {
87 public:
88  Context(Connection& connection, MirWindow* surface, int swap_interval);
89  void make_current();
90  void release_current();
91  void swapbuffers();
92  Context(Context const&) = delete;
93  Context& operator=(Context const&) = delete;
94 private:
95  EGLConfig chooseconfig(EGLDisplay disp);
96  EGLNativeDisplayType native_display;
97  EGLNativeWindowType native_window;
98  struct Display
99  {
100  Display(EGLNativeDisplayType native);
101  ~Display();
102  EGLDisplay disp;
103  } display;
104  EGLConfig config;
105  struct Surface
106  {
107  Surface(EGLDisplay display, EGLConfig config, EGLNativeWindowType native_window);
108  ~Surface();
109  EGLDisplay disp;
110  EGLSurface surface;
111  } surface;
112  struct EglContext
113  {
114  EglContext(EGLDisplay disp, EGLConfig config);
115  ~EglContext();
116  EGLint context_attribs[3] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
117  EGLDisplay disp;
118  EGLContext context;
119  } context;
120 };
121 
122 struct Shader
123 {
124  Shader(GLchar const* const* src, GLuint type);
125  ~Shader();
126  GLuint shader;
127 };
128 
129 struct Program
130 {
131  Program(Shader& vertex, Shader& fragment);
132  ~Program();
133  GLuint program;
134 };
135 }
136 }
137 #endif /* MIR_EXAMLPES_CLIENT_HELPERS_H_ */
Definition: as_render_target.h:27
bool make_current(mrg::RenderTarget *render_target)
Definition: server_example_adorning_compositor.cpp:39
struct MirSurface MirWindow
Definition: client_types.h:43
struct MirBufferStream MirBufferStream
Definition: client_types.h:49
Definition: client_helpers.h:129
~Connection()
Definition: client_helpers.cpp:44
GLuint shader
Definition: client_helpers.h:126
unsigned int height
Definition: mir_image.h:27
Definition: client_helpers.h:69
Connection & operator=(Connection const &)=delete
Connection(char const *socket_file)
Definition: client_helpers.cpp:39
unsigned int width
Definition: mir_image.h:26
struct MirConnection MirConnection
Definition: client_types.h:41
Definition: client_helpers.h:122
Definition: client_helpers.h:44
void mir_window_release_sync(MirWindow *window)
Release the specified window like in mir_window_release(), but also wait for the operation to complet...
GLuint program
Definition: client_helpers.h:133
char const * name
Definition: client_types.h:170
Definition: client_helpers.h:85
Definition: client_helpers.h:31

Copyright © 2012-2016 Canonical Ltd.
Generated on Mon Jun 5 11:05:03 UTC 2017