Mir
mock_egl.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 or 3,
6  * as 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: Thomas Voss <thomas.voss@canonical.com>
17  */
18 
19 #ifndef MIR_TEST_DOUBLES_MOCK_EGL_H_
20 #define MIR_TEST_DOUBLES_MOCK_EGL_H_
21 
22 #include <gmock/gmock.h>
23 
24 #include <mutex>
25 #include <thread>
26 #include <unordered_map>
27 
28 #ifndef GL_GLEXT_PROTOTYPES
29 #define GL_GLEXT_PROTOTYPES
30 #endif
31 #define EGL_EGLEXT_PROTOTYPES
32 #include <EGL/egl.h>
33 #include <EGL/eglext.h>
34 //for GL extensions
35 #include <GLES2/gl2.h>
36 #include <GLES2/gl2ext.h>
37 
38 namespace mir
39 {
40 namespace test
41 {
42 namespace doubles
43 {
44 
45 MATCHER_P(AttrMatches, val, std::string("matches"))
46 {
47  auto i = 0;
48  while ((val[i] != EGL_NONE) && (arg[i] != EGL_NONE))
49  {
50  if (val[i] != arg[i])
51  return false;
52  i++;
53  }
54 
55  if ((val[i] == EGL_NONE) && (arg[i] == EGL_NONE))
56  {
57  return true;
58  }
59  return false;
60 }
61 
62 MATCHER_P2(EGLConfigContainsAttrib, attrib, value, "")
63 {
64  bool attrib_position = true;
65  bool attrib_found = false;
66 
67  while (!attrib_position || *arg != EGL_NONE)
68  {
69  if (attrib_position && *arg == attrib)
70  {
71  attrib_found = true;
72  }
73  else if (!attrib_position)
74  {
75  if (attrib_found && *arg == value)
76  {
77  return true;
78  }
79 
80  attrib_found = false;
81  }
82  attrib_position = !attrib_position;
83  ++arg;
84  }
85 
86  return false;
87 }
88 
89 class MockEGL
90 {
91 public:
92  MockEGL();
93  virtual ~MockEGL();
94 
97 
98  // Provide a functional version of eglSwapBuffers on stubbed platforms
99  // When enabled, if an instance of mir::client::EGLNativeSurface is passed to
100  // eglCreateWindowSurface, then the returned EGLSurface can be used with
101  // eglSwapBuffers to invoke EGLNativeSurface::swap_buffers_sync
103 
104  typedef void (*generic_function_pointer_t)(void);
105  typedef void* AnyNativeType;
106 
107  MOCK_METHOD1(eglGetDisplay, EGLDisplay(AnyNativeType));
108  MOCK_METHOD3(eglInitialize, EGLBoolean(EGLDisplay,EGLint*,EGLint*));
109  MOCK_METHOD1(eglTerminate, EGLBoolean(EGLDisplay));
110  MOCK_METHOD2(eglQueryString,const char*(EGLDisplay, EGLint));
111  MOCK_METHOD1(eglBindApi, EGLBoolean(EGLenum));
112  MOCK_METHOD1(eglGetProcAddress,generic_function_pointer_t(const char*));
113 
114  // Config management
115  MOCK_METHOD4(eglGetConfigs, EGLBoolean(EGLDisplay,EGLConfig*,EGLint,EGLint*));
116  MOCK_METHOD5(eglChooseConfig, EGLBoolean(EGLDisplay, const EGLint*,EGLConfig*,EGLint,EGLint*));
117  MOCK_METHOD4(eglGetConfigAttrib, EGLBoolean(EGLDisplay,EGLConfig,EGLint,EGLint*));
118 
119  // Surface management
120  MOCK_METHOD4(eglCreateWindowSurface, EGLSurface(EGLDisplay,EGLConfig,AnyNativeType,const EGLint*));
121  MOCK_METHOD4(eglCreatePixmapSurface, EGLSurface(EGLDisplay,EGLConfig,AnyNativeType,const EGLint*));
122  MOCK_METHOD3(eglCreatePbufferSurface, EGLSurface(EGLDisplay,EGLConfig,const EGLint*));
123  MOCK_METHOD2(eglDestroySurface, EGLBoolean(EGLDisplay,EGLSurface));
124  MOCK_METHOD4(eglQuerySurface, EGLBoolean(EGLDisplay,EGLSurface,EGLint,EGLint*));
125 
126  // EGL 1.1 render-to-texture APIs
127  MOCK_METHOD4(eglSurfaceAttrib, EGLBoolean(EGLDisplay,EGLSurface,EGLint,EGLint));
128  MOCK_METHOD3(eglBindTexImage, EGLBoolean(EGLDisplay,EGLSurface,EGLint));
129  MOCK_METHOD3(eglReleaseTexImage, EGLBoolean(EGLDisplay,EGLSurface,EGLint));
130 
131  // EGL 1.1 swap control API
132  MOCK_METHOD2(eglSwapInterval, EGLBoolean(EGLDisplay,EGLint));
133 
134  MOCK_METHOD4(eglCreateContext, EGLContext(EGLDisplay,EGLConfig,EGLContext,const EGLint*));
135  MOCK_METHOD2(eglDestroyContext, EGLBoolean(EGLDisplay,EGLContext));
136  MOCK_METHOD4(eglMakeCurrent, EGLBoolean(EGLDisplay,EGLSurface,EGLSurface,EGLContext));
137  MOCK_METHOD0(eglGetCurrentContext,EGLContext());
138  MOCK_METHOD1(eglGetCurrentSurface,EGLSurface(EGLint));
139  MOCK_METHOD0(eglGetCurrentDisplay, EGLDisplay());
140  MOCK_METHOD4(eglQueryContext, EGLBoolean(EGLDisplay,EGLContext,EGLint,EGLint*));
141 
142  MOCK_METHOD0(eglWaitGL, EGLBoolean());
143  MOCK_METHOD1(eglWaitNative, EGLBoolean(EGLint));
144  MOCK_METHOD2(eglSwapBuffers, EGLBoolean(EGLDisplay,EGLSurface));
145  MOCK_METHOD3(eglCopyBuffers, EGLBoolean(EGLDisplay,EGLSurface,AnyNativeType));
146 
147  MOCK_METHOD0(eglGetError, EGLint (void));
148 
149  MOCK_METHOD5(eglCreateImageKHR, EGLImageKHR(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint*));
150  MOCK_METHOD2(eglDestroyImageKHR,EGLBoolean(EGLDisplay, EGLImageKHR));
151  MOCK_METHOD2(glEGLImageTargetTexture2DOES, void(GLenum, GLeglImageOES));
152 
153  MOCK_METHOD3(eglCreateSyncKHR, EGLSyncKHR(EGLDisplay, EGLenum, EGLint const*));
154  MOCK_METHOD2(eglDestroySyncKHR, EGLBoolean(EGLDisplay, EGLSyncKHR));
155  MOCK_METHOD4(eglClientWaitSyncKHR, EGLint(EGLDisplay, EGLSyncKHR, EGLint, EGLTimeKHR));
156 
157  MOCK_METHOD5(eglGetSyncValuesCHROMIUM, EGLBoolean(EGLDisplay, EGLSurface,
158  int64_t*, int64_t*,
159  int64_t*));
160 
161  MOCK_METHOD2(eglBindWaylandDisplayWL,
162  EGLBoolean(EGLDisplay, struct wl_display*));
163  MOCK_METHOD2(eglUnbindWaylandDisplayWL,
164  EGLBoolean(EGLDisplay, struct wl_display*));
165  MOCK_METHOD4(eglQueryWaylandBufferWL,
166  EGLBoolean(EGLDisplay, struct wl_resource*, EGLint, EGLint*));
167 
168  EGLDisplay const fake_egl_display;
169  EGLConfig const* const fake_configs;
170  EGLint const fake_configs_num;
171  EGLSurface const fake_egl_surface;
172  EGLContext const fake_egl_context;
173  EGLImageKHR const fake_egl_image;
174  int const fake_visual_id;
175  std::mutex mutable current_contexts_mutex;
176  std::unordered_map<std::thread::id,EGLContext> current_contexts;
177 };
178 
179 }
180 }
181 }
182 
183 #endif /* MIR_TEST_DOUBLES_MOCK_EGL_H_ */
std::mutex current_contexts_mutex
Definition: mock_egl.h:175
AutoUnblockThread is a helper thread class that can gracefully shutdown at destruction time...
Definition: sw_splash.h:26
MOCK_METHOD0(eglGetCurrentContext, EGLContext())
EGLImageKHR const fake_egl_image
Definition: mock_egl.h:173
MATCHER_P(DisplayConfigMatches, config, "")
Definition: display_config_matchers.h:119
int const fake_visual_id
Definition: mock_egl.h:174
EGLConfig const *const fake_configs
Definition: mock_egl.h:169
MOCK_METHOD5(eglChooseConfig, EGLBoolean(EGLDisplay, const EGLint *, EGLConfig *, EGLint, EGLint *))
MOCK_METHOD1(eglGetDisplay, EGLDisplay(AnyNativeType))
MOCK_METHOD4(eglGetConfigs, EGLBoolean(EGLDisplay, EGLConfig *, EGLint, EGLint *))
void(* generic_function_pointer_t)(void)
Definition: mock_egl.h:104
EGLint const fake_configs_num
Definition: mock_egl.h:170
EGLContext const fake_egl_context
Definition: mock_egl.h:172
MOCK_METHOD3(eglInitialize, EGLBoolean(EGLDisplay, EGLint *, EGLint *))
MATCHER_P2(EGLConfigContainsAttrib, attrib, value, "")
Definition: mock_egl.h:62
void * AnyNativeType
Definition: mock_egl.h:105
std::unordered_map< std::thread::id, EGLContext > current_contexts
Definition: mock_egl.h:176
Definition: mock_egl.h:89
MOCK_METHOD2(eglQueryString, const char *(EGLDisplay, EGLint))
EGLDisplay const fake_egl_display
Definition: mock_egl.h:168
void provide_stub_platform_buffer_swapping()
EGLSurface const fake_egl_surface
Definition: mock_egl.h:171

Copyright © 2012-2018 Canonical Ltd.
Generated on Mon Feb 19 14:05:11 UTC 2018