Mir

Merge lp:~afrantzis/mir/report-egl-errors-in-exceptions into lp:mir

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 2497
Proposed branch: lp:~afrantzis/mir/report-egl-errors-in-exceptions
Merge into: lp:mir
Diff against target: 625 lines (+267/-32)
15 files modified
src/include/platform/mir/graphics/egl_error.h (+40/-0)
src/platform/graphics/CMakeLists.txt (+1/-0)
src/platform/graphics/egl_error.cpp (+72/-0)
src/platform/graphics/egl_resources.cpp (+3/-2)
src/platform/symbols.map (+1/-0)
src/platforms/android/server/buffer.cpp (+3/-2)
src/platforms/android/server/gl_context.cpp (+6/-10)
src/platforms/mesa/server/buffer_allocator.cpp (+2/-1)
src/platforms/mesa/server/display_helpers.cpp (+9/-7)
src/server/graphics/nested/display.cpp (+6/-5)
src/server/graphics/nested/display_buffer.cpp (+2/-1)
src/server/graphics/offscreen/display.cpp (+3/-2)
src/server/graphics/surfaceless_egl_context.cpp (+3/-2)
tests/unit-tests/graphics/CMakeLists.txt (+1/-0)
tests/unit-tests/graphics/test_egl_error.cpp (+115/-0)
To merge this branch: bzr merge lp:~afrantzis/mir/report-egl-errors-in-exceptions
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Kevin DuBois (community) Approve
Alan Griffiths Approve
Robert Carr (community) Approve
Review via email: mp+256534@code.launchpad.net

Commit message

server,platform: Report the EGL error code when throwing exceptions for EGL errors

Description of the change

server,platform: Report the EGL error code when throwing exceptions for EGL errors

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Robert Carr (robertcarr) wrote :

LGTM! A few preexisting \n in exception strings that I guess shouldn't be there?

Revision history for this message
Robert Carr (robertcarr) :
review: Approve
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

> A few preexisting \n in exception strings that I guess shouldn't be there?

Fixed!

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

38+ egl_error(std::string const& msg)
39+ : std::system_error(eglGetError(), egl_category(), msg)
40+ {
41+ }

I'm not sure why this code is inline (which requires egl_category() to be published)

review: Approve
Revision history for this message
Kevin DuBois (kdub) wrote :

could the code in src/platforms/android/server/gl_context.cpp use this too?

review: Approve
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

I think it would be better to expose egl_error and its typeinfo since it gets thrown around? But I might be wrong, and boost::exception already deals with that.

Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

I was thinking about cases in which somebody wants to catch egl_error outside of libmirserver.so

Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

@Kevin
> could the code in src/platforms/android/server/gl_context.cpp use this too?

12 +++ src/platforms/android/server/gl_context.cpp 2015-04-17 07:34:44 +0000

:)

@Andreas
> I think it would be better to expose egl_error and its typeinfo since it gets thrown around?

mg::egl_error is a convenience class. For all intents the purpose, the exception we are throwing is a std::system_error with an egl_category.

@Alan
> I'm not sure why this code is inline (which requires egl_category() to be published)

See above, and also, in some cases this convenience class may not be usable, since it calls eglGetError() itself.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> mg::egl_error is a convenience class. For all intents the purpose, the
> exception we are throwing is a std::system_error with an egl_category.

a convenience class that could be replaced by a convenience function?

inline auto egl_error(std::string const& msg) -> std::system_error
{
    return std::system_error(eglGetError(), egl_category(), msg);
}

Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

> a convenience class that could be replaced by a convenience function?

Better, thanks.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'src/include/platform/mir/graphics/egl_error.h'
--- src/include/platform/mir/graphics/egl_error.h 1970-01-01 00:00:00 +0000
+++ src/include/platform/mir/graphics/egl_error.h 2015-04-17 15:49:38 +0000
@@ -0,0 +1,40 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17 */
18
19#ifndef MIR_GRAPHICS_EGL_ERROR_H_
20#define MIR_GRAPHICS_EGL_ERROR_H_
21
22#include <system_error>
23#include <EGL/egl.h>
24
25namespace mir
26{
27namespace graphics
28{
29
30std::error_category const& egl_category();
31
32inline auto egl_error(std::string const& msg) -> std::system_error
33{
34 return std::system_error{eglGetError(), egl_category(), msg};
35}
36
37}
38}
39
40#endif
041
=== modified file 'src/platform/graphics/CMakeLists.txt'
--- src/platform/graphics/CMakeLists.txt 2015-03-31 02:35:42 +0000
+++ src/platform/graphics/CMakeLists.txt 2015-04-17 15:49:38 +0000
@@ -5,6 +5,7 @@
55
6 egl_extensions.cpp6 egl_extensions.cpp
7 egl_resources.cpp7 egl_resources.cpp
8 egl_error.cpp
8 display_configuration.cpp9 display_configuration.cpp
9 buffer_basic.cpp10 buffer_basic.cpp
10 pixel_format_utils.cpp11 pixel_format_utils.cpp
1112
=== added file 'src/platform/graphics/egl_error.cpp'
--- src/platform/graphics/egl_error.cpp 1970-01-01 00:00:00 +0000
+++ src/platform/graphics/egl_error.cpp 2015-04-17 15:49:38 +0000
@@ -0,0 +1,72 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17 */
18
19#include "mir/graphics/egl_error.h"
20#include <sstream>
21
22namespace
23{
24
25std::string to_hex_string(int n)
26{
27 std::stringstream ss;
28 ss << std::showbase << std::hex << n;
29 return ss.str();
30}
31
32struct egl_category : std::error_category
33{
34 const char* name() const noexcept override { return "egl"; }
35
36 std::string message(int ev) const override
37 {
38 #define CASE_FOR_ERROR(error) \
39 case error: return #error " (" + to_hex_string(error) + ")";
40 switch (ev)
41 {
42 CASE_FOR_ERROR(EGL_SUCCESS)
43 CASE_FOR_ERROR(EGL_NOT_INITIALIZED)
44 CASE_FOR_ERROR(EGL_BAD_ACCESS)
45 CASE_FOR_ERROR(EGL_BAD_ALLOC)
46 CASE_FOR_ERROR(EGL_BAD_ATTRIBUTE)
47 CASE_FOR_ERROR(EGL_BAD_CONFIG)
48 CASE_FOR_ERROR(EGL_BAD_CONTEXT)
49 CASE_FOR_ERROR(EGL_BAD_CURRENT_SURFACE)
50 CASE_FOR_ERROR(EGL_BAD_DISPLAY)
51 CASE_FOR_ERROR(EGL_BAD_MATCH)
52 CASE_FOR_ERROR(EGL_BAD_NATIVE_PIXMAP)
53 CASE_FOR_ERROR(EGL_BAD_NATIVE_WINDOW)
54 CASE_FOR_ERROR(EGL_BAD_PARAMETER)
55 CASE_FOR_ERROR(EGL_BAD_SURFACE)
56 CASE_FOR_ERROR(EGL_CONTEXT_LOST)
57
58 default:
59 return "Unknown error (" + to_hex_string(ev) + ")";
60 }
61 #undef CASE_ERROR
62 }
63};
64
65}
66
67std::error_category const& mir::graphics::egl_category()
68{
69 static class egl_category const egl_category_instance{};
70
71 return egl_category_instance;
72}
073
=== modified file 'src/platform/graphics/egl_resources.cpp'
--- src/platform/graphics/egl_resources.cpp 2014-03-12 02:46:58 +0000
+++ src/platform/graphics/egl_resources.cpp 2015-04-17 15:49:38 +0000
@@ -17,6 +17,7 @@
17 */17 */
1818
19#include "mir/graphics/egl_resources.h"19#include "mir/graphics/egl_resources.h"
20#include "mir/graphics/egl_error.h"
2021
21#include <boost/throw_exception.hpp>22#include <boost/throw_exception.hpp>
22#include <stdexcept>23#include <stdexcept>
@@ -31,7 +32,7 @@
31 : egl_display_{egl_display}, egl_context_{egl_context}32 : egl_display_{egl_display}, egl_context_{egl_context}
32{33{
33 if (egl_context_ == EGL_NO_CONTEXT)34 if (egl_context_ == EGL_NO_CONTEXT)
34 BOOST_THROW_EXCEPTION(std::runtime_error("Could not create egl context\n"));35 BOOST_THROW_EXCEPTION(mg::egl_error("Could not create egl context"));
35}36}
3637
37mg::EGLContextStore::~EGLContextStore() noexcept38mg::EGLContextStore::~EGLContextStore() noexcept
@@ -62,7 +63,7 @@
62 : egl_display_{egl_display}, egl_surface_{egl_surface}63 : egl_display_{egl_display}, egl_surface_{egl_surface}
63{64{
64 if (egl_surface_ == EGL_NO_SURFACE && !allow_no_surface)65 if (egl_surface_ == EGL_NO_SURFACE && !allow_no_surface)
65 BOOST_THROW_EXCEPTION(std::runtime_error("Could not create egl surface\n"));66 BOOST_THROW_EXCEPTION(mg::egl_error("Could not create egl surface"));
66}67}
6768
68mg::EGLSurfaceStore::EGLSurfaceStore(EGLDisplay egl_display, EGLSurface egl_surface)69mg::EGLSurfaceStore::EGLSurfaceStore(EGLDisplay egl_display, EGLSurface egl_surface)
6970
=== modified file 'src/platform/symbols.map'
--- src/platform/symbols.map 2015-04-09 06:20:31 +0000
+++ src/platform/symbols.map 2015-04-17 15:49:38 +0000
@@ -246,6 +246,7 @@
246 mir::graphics::EGLSurfaceStore::EGLSurfaceStore*;246 mir::graphics::EGLSurfaceStore::EGLSurfaceStore*;
247 mir::graphics::EGLSurfaceStore::EGLSurfaceStore*;247 mir::graphics::EGLSurfaceStore::EGLSurfaceStore*;
248 mir::graphics::EGLSurfaceStore::operator*;248 mir::graphics::EGLSurfaceStore::operator*;
249 mir::graphics::egl_category*;
249 mir::graphics::GLTexture::bind*;250 mir::graphics::GLTexture::bind*;
250 mir::graphics::GLTexture::?GLTexture*;251 mir::graphics::GLTexture::?GLTexture*;
251 mir::graphics::GLTexture::GLTexture*;252 mir::graphics::GLTexture::GLTexture*;
252253
=== modified file 'src/platforms/android/server/buffer.cpp'
--- src/platforms/android/server/buffer.cpp 2015-04-09 17:37:55 +0000
+++ src/platforms/android/server/buffer.cpp 2015-04-17 15:49:38 +0000
@@ -18,6 +18,7 @@
18 */18 */
1919
20#include "mir/graphics/egl_extensions.h"20#include "mir/graphics/egl_extensions.h"
21#include "mir/graphics/egl_error.h"
21#include "mir/graphics/android/native_buffer.h"22#include "mir/graphics/android/native_buffer.h"
22#include "mir/graphics/android/sync_fence.h"23#include "mir/graphics/android/sync_fence.h"
23#include "android_format_conversion-inl.h"24#include "android_format_conversion-inl.h"
@@ -83,7 +84,7 @@
8384
84 if (current.first == EGL_NO_DISPLAY)85 if (current.first == EGL_NO_DISPLAY)
85 {86 {
86 BOOST_THROW_EXCEPTION(std::runtime_error("cannot bind buffer to texture without EGL context\n"));87 BOOST_THROW_EXCEPTION(std::runtime_error("cannot bind buffer to texture without EGL context"));
87 }88 }
8889
89 static const EGLint image_attrs[] =90 static const EGLint image_attrs[] =
@@ -102,7 +103,7 @@
102103
103 if (image == EGL_NO_IMAGE_KHR)104 if (image == EGL_NO_IMAGE_KHR)
104 {105 {
105 BOOST_THROW_EXCEPTION(std::runtime_error("error binding buffer to texture\n"));106 BOOST_THROW_EXCEPTION(mg::egl_error("error binding buffer to texture"));
106 }107 }
107 egl_image_map[current] = image;108 egl_image_map[current] = image;
108 }109 }
109110
=== modified file 'src/platforms/android/server/gl_context.cpp'
--- src/platforms/android/server/gl_context.cpp 2015-01-22 09:00:14 +0000
+++ src/platforms/android/server/gl_context.cpp 2015-04-17 15:49:38 +0000
@@ -21,6 +21,7 @@
21#include "android_format_conversion-inl.h"21#include "android_format_conversion-inl.h"
22#include "mir/graphics/display_report.h"22#include "mir/graphics/display_report.h"
23#include "mir/graphics/gl_config.h"23#include "mir/graphics/gl_config.h"
24#include "mir/graphics/egl_error.h"
2425
25#include <algorithm>26#include <algorithm>
26#include <boost/throw_exception.hpp>27#include <boost/throw_exception.hpp>
@@ -52,13 +53,13 @@
5253
53 auto egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);54 auto egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
54 if (egl_display == EGL_NO_DISPLAY)55 if (egl_display == EGL_NO_DISPLAY)
55 BOOST_THROW_EXCEPTION(std::runtime_error("eglGetDisplay failed\n"));56 BOOST_THROW_EXCEPTION(mg::egl_error("eglGetDisplay failed"));
5657
57 if (eglInitialize(egl_display, &major, &minor) == EGL_FALSE)58 if (eglInitialize(egl_display, &major, &minor) == EGL_FALSE)
58 BOOST_THROW_EXCEPTION(std::runtime_error("eglInitialize failure\n"));59 BOOST_THROW_EXCEPTION(mg::egl_error("eglInitialize failure"));
5960
60 if ((major != 1) || (minor != 4))61 if ((major != 1) || (minor != 4))
61 BOOST_THROW_EXCEPTION(std::runtime_error("must have EGL 1.4\n"));62 BOOST_THROW_EXCEPTION(std::runtime_error("must have EGL 1.4"));
62 return egl_display;63 return egl_display;
63}64}
6465
@@ -108,7 +109,7 @@
108 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) == EGL_FALSE)109 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) == EGL_FALSE)
109 {110 {
110 BOOST_THROW_EXCEPTION(111 BOOST_THROW_EXCEPTION(
111 std::runtime_error("could not activate surface with eglMakeCurrent\n"));112 mg::egl_error("could not activate surface with eglMakeCurrent"));
112 }113 }
113}114}
114115
@@ -186,13 +187,8 @@
186187
187void mga::FramebufferGLContext::swap_buffers() const188void mga::FramebufferGLContext::swap_buffers() const
188{189{
189 eglGetError();
190 if (eglSwapBuffers(egl_display, egl_surface) == EGL_FALSE)190 if (eglSwapBuffers(egl_display, egl_surface) == EGL_FALSE)
191 {191 BOOST_THROW_EXCEPTION(mg::egl_error("eglSwapBuffers failure"));
192 std::stringstream sstream;
193 sstream << "eglSwapBuffers failure: EGL error code " << std::hex << eglGetError();
194 BOOST_THROW_EXCEPTION(std::runtime_error(sstream.str()));
195 }
196}192}
197193
198std::shared_ptr<mg::Buffer> mga::FramebufferGLContext::last_rendered_buffer() const194std::shared_ptr<mg::Buffer> mga::FramebufferGLContext::last_rendered_buffer() const
199195
=== modified file 'src/platforms/mesa/server/buffer_allocator.cpp'
--- src/platforms/mesa/server/buffer_allocator.cpp 2015-04-14 12:22:18 +0000
+++ src/platforms/mesa/server/buffer_allocator.cpp 2015-04-17 15:49:38 +0000
@@ -23,6 +23,7 @@
23#include "anonymous_shm_file.h"23#include "anonymous_shm_file.h"
24#include "shm_buffer.h"24#include "shm_buffer.h"
25#include "mir/graphics/egl_extensions.h"25#include "mir/graphics/egl_extensions.h"
26#include "mir/graphics/egl_error.h"
26#include "mir/graphics/buffer_properties.h"27#include "mir/graphics/buffer_properties.h"
27#include <boost/throw_exception.hpp>28#include <boost/throw_exception.hpp>
2829
@@ -86,7 +87,7 @@
86 reinterpret_cast<void*>(bo_raw),87 reinterpret_cast<void*>(bo_raw),
87 image_attrs);88 image_attrs);
88 if (egl_image == EGL_NO_IMAGE_KHR)89 if (egl_image == EGL_NO_IMAGE_KHR)
89 BOOST_THROW_EXCEPTION(std::runtime_error("Failed to create EGLImage from GBM bo"));90 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to create EGLImage from GBM bo"));
90 }91 }
91 }92 }
9293
9394
=== modified file 'src/platforms/mesa/server/display_helpers.cpp'
--- src/platforms/mesa/server/display_helpers.cpp 2015-01-22 09:00:14 +0000
+++ src/platforms/mesa/server/display_helpers.cpp 2015-04-17 15:49:38 +0000
@@ -20,6 +20,7 @@
20#include "drm_close_threadsafe.h"20#include "drm_close_threadsafe.h"
2121
22#include "mir/graphics/gl_config.h"22#include "mir/graphics/gl_config.h"
23#include "mir/graphics/egl_error.h"
23#include "mir/udev/wrapper.h"24#include "mir/udev/wrapper.h"
2425
25#include <boost/exception/errinfo_errno.hpp>26#include <boost/exception/errinfo_errno.hpp>
@@ -31,6 +32,7 @@
31#include <xf86drm.h>32#include <xf86drm.h>
32#include <fcntl.h>33#include <fcntl.h>
3334
35namespace mg = mir::graphics;
34namespace mgm = mir::graphics::mesa;36namespace mgm = mir::graphics::mesa;
35namespace mgmh = mir::graphics::mesa::helpers;37namespace mgmh = mir::graphics::mesa::helpers;
3638
@@ -317,7 +319,7 @@
317319
318 egl_context = eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, context_attr);320 egl_context = eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, context_attr);
319 if (egl_context == EGL_NO_CONTEXT)321 if (egl_context == EGL_NO_CONTEXT)
320 BOOST_THROW_EXCEPTION(std::runtime_error("Failed to create EGL context"));322 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to create EGL context"));
321}323}
322324
323void mgmh::EGLHelper::setup(GBMHelper const& gbm, EGLContext shared_context)325void mgmh::EGLHelper::setup(GBMHelper const& gbm, EGLContext shared_context)
@@ -331,7 +333,7 @@
331333
332 egl_context = eglCreateContext(egl_display, egl_config, shared_context, context_attr);334 egl_context = eglCreateContext(egl_display, egl_config, shared_context, context_attr);
333 if (egl_context == EGL_NO_CONTEXT)335 if (egl_context == EGL_NO_CONTEXT)
334 BOOST_THROW_EXCEPTION(std::runtime_error("Failed to create EGL context"));336 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to create EGL context"));
335}337}
336338
337void mgmh::EGLHelper::setup(GBMHelper const& gbm, gbm_surface* surface_gbm,339void mgmh::EGLHelper::setup(GBMHelper const& gbm, gbm_surface* surface_gbm,
@@ -346,11 +348,11 @@
346348
347 egl_surface = eglCreateWindowSurface(egl_display, egl_config, surface_gbm, nullptr);349 egl_surface = eglCreateWindowSurface(egl_display, egl_config, surface_gbm, nullptr);
348 if(egl_surface == EGL_NO_SURFACE)350 if(egl_surface == EGL_NO_SURFACE)
349 BOOST_THROW_EXCEPTION(std::runtime_error("Failed to create EGL window surface"));351 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to create EGL window surface"));
350352
351 egl_context = eglCreateContext(egl_display, egl_config, shared_context, context_attr);353 egl_context = eglCreateContext(egl_display, egl_config, shared_context, context_attr);
352 if (egl_context == EGL_NO_CONTEXT)354 if (egl_context == EGL_NO_CONTEXT)
353 BOOST_THROW_EXCEPTION(std::runtime_error("Failed to create EGL context"));355 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to create EGL context"));
354}356}
355357
356mgmh::EGLHelper::~EGLHelper() noexcept358mgmh::EGLHelper::~EGLHelper() noexcept
@@ -408,14 +410,14 @@
408410
409 egl_display = eglGetDisplay(static_cast<EGLNativeDisplayType>(gbm.device));411 egl_display = eglGetDisplay(static_cast<EGLNativeDisplayType>(gbm.device));
410 if (egl_display == EGL_NO_DISPLAY)412 if (egl_display == EGL_NO_DISPLAY)
411 BOOST_THROW_EXCEPTION(std::runtime_error("Failed to get EGL display"));413 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to get EGL display"));
412414
413 if (initialize)415 if (initialize)
414 {416 {
415 EGLint major, minor;417 EGLint major, minor;
416418
417 if (eglInitialize(egl_display, &major, &minor) == EGL_FALSE)419 if (eglInitialize(egl_display, &major, &minor) == EGL_FALSE)
418 BOOST_THROW_EXCEPTION(std::runtime_error("Failed to initialize EGL display"));420 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to initialize EGL display"));
419421
420 if ((major != required_egl_version_major) || (minor != required_egl_version_minor))422 if ((major != required_egl_version_major) || (minor != required_egl_version_minor))
421 {423 {
@@ -432,7 +434,7 @@
432 if (eglChooseConfig(egl_display, config_attr, &egl_config, 1, &num_egl_configs) == EGL_FALSE ||434 if (eglChooseConfig(egl_display, config_attr, &egl_config, 1, &num_egl_configs) == EGL_FALSE ||
433 num_egl_configs != 1)435 num_egl_configs != 1)
434 {436 {
435 BOOST_THROW_EXCEPTION(std::runtime_error("Failed to choose ARGB EGL config"));437 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to choose ARGB EGL config"));
436 }438 }
437}439}
438440
439441
=== modified file 'src/server/graphics/nested/display.cpp'
--- src/server/graphics/nested/display.cpp 2015-04-08 03:02:37 +0000
+++ src/server/graphics/nested/display.cpp 2015-04-17 15:49:38 +0000
@@ -28,6 +28,7 @@
28#include "mir/graphics/display_configuration_policy.h"28#include "mir/graphics/display_configuration_policy.h"
29#include "mir/graphics/overlapping_output_grouping.h"29#include "mir/graphics/overlapping_output_grouping.h"
30#include "mir/graphics/gl_config.h"30#include "mir/graphics/gl_config.h"
31#include "mir/graphics/egl_error.h"
3132
32#include <boost/throw_exception.hpp>33#include <boost/throw_exception.hpp>
33#include <stdexcept>34#include <stdexcept>
@@ -48,7 +49,7 @@
48{49{
49 if (egl_surface == EGL_NO_SURFACE)50 if (egl_surface == EGL_NO_SURFACE)
50 {51 {
51 BOOST_THROW_EXCEPTION(std::runtime_error("Nested Mir Display Error: Failed to create EGL surface."));52 BOOST_THROW_EXCEPTION(mg::egl_error("Nested Mir Display Error: Failed to create EGL surface."));
52 }53 }
53}54}
5455
@@ -66,7 +67,7 @@
66{67{
67 egl_display = eglGetDisplay(native_display);68 egl_display = eglGetDisplay(native_display);
68 if (egl_display == EGL_NO_DISPLAY)69 if (egl_display == EGL_NO_DISPLAY)
69 BOOST_THROW_EXCEPTION(std::runtime_error("Nested Mir Display Error: Failed to fetch EGL display."));70 BOOST_THROW_EXCEPTION(mg::egl_error("Nested Mir Display Error: Failed to fetch EGL display."));
70}71}
7172
72void mgn::detail::EGLDisplayHandle::initialize(MirPixelFormat format)73void mgn::detail::EGLDisplayHandle::initialize(MirPixelFormat format)
@@ -76,13 +77,13 @@
7677
77 if (eglInitialize(egl_display, &major, &minor) != EGL_TRUE)78 if (eglInitialize(egl_display, &major, &minor) != EGL_TRUE)
78 {79 {
79 BOOST_THROW_EXCEPTION(std::runtime_error("Nested Mir Display Error: Failed to initialize EGL."));80 BOOST_THROW_EXCEPTION(mg::egl_error("Nested Mir Display Error: Failed to initialize EGL."));
80 }81 }
8182
82 egl_context_ = eglCreateContext(egl_display, choose_windowed_es_config(format), EGL_NO_CONTEXT, detail::nested_egl_context_attribs);83 egl_context_ = eglCreateContext(egl_display, choose_windowed_es_config(format), EGL_NO_CONTEXT, detail::nested_egl_context_attribs);
8384
84 if (egl_context_ == EGL_NO_CONTEXT)85 if (egl_context_ == EGL_NO_CONTEXT)
85 BOOST_THROW_EXCEPTION(std::runtime_error("Failed to create shared EGL context"));86 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to create shared EGL context"));
86}87}
8788
88EGLConfig mgn::detail::EGLDisplayHandle::choose_windowed_es_config(MirPixelFormat format) const89EGLConfig mgn::detail::EGLDisplayHandle::choose_windowed_es_config(MirPixelFormat format) const
@@ -104,7 +105,7 @@
104105
105 int res = eglChooseConfig(egl_display, nested_egl_config_attribs, &result, 1, &n);106 int res = eglChooseConfig(egl_display, nested_egl_config_attribs, &result, 1, &n);
106 if ((res != EGL_TRUE) || (n != 1))107 if ((res != EGL_TRUE) || (n != 1))
107 BOOST_THROW_EXCEPTION(std::runtime_error("Nested Mir Display Error: Failed to choose EGL configuration."));108 BOOST_THROW_EXCEPTION(mg::egl_error("Nested Mir Display Error: Failed to choose EGL configuration."));
108109
109 return result;110 return result;
110}111}
111112
=== modified file 'src/server/graphics/nested/display_buffer.cpp'
--- src/server/graphics/nested/display_buffer.cpp 2015-04-10 01:59:08 +0000
+++ src/server/graphics/nested/display_buffer.cpp 2015-04-17 15:49:38 +0000
@@ -21,6 +21,7 @@
21#include "host_connection.h"21#include "host_connection.h"
22#include "mir/input/input_dispatcher.h"22#include "mir/input/input_dispatcher.h"
23#include "mir/graphics/pixel_format_utils.h"23#include "mir/graphics/pixel_format_utils.h"
24#include "mir/graphics/egl_error.h"
24#include "mir/events/event_private.h"25#include "mir/events/event_private.h"
2526
26#include <boost/throw_exception.hpp>27#include <boost/throw_exception.hpp>
@@ -56,7 +57,7 @@
56void mgn::detail::DisplayBuffer::make_current()57void mgn::detail::DisplayBuffer::make_current()
57{58{
58 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) != EGL_TRUE)59 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) != EGL_TRUE)
59 BOOST_THROW_EXCEPTION(std::runtime_error("Nested Mir Display Error: Failed to update EGL surface.\n"));60 BOOST_THROW_EXCEPTION(mg::egl_error("Nested Mir Display Error: Failed to update EGL surface"));
60}61}
6162
62void mgn::detail::DisplayBuffer::release_current()63void mgn::detail::DisplayBuffer::release_current()
6364
=== modified file 'src/server/graphics/offscreen/display.cpp'
--- src/server/graphics/offscreen/display.cpp 2015-03-31 02:35:42 +0000
+++ src/server/graphics/offscreen/display.cpp 2015-04-17 15:49:38 +0000
@@ -19,6 +19,7 @@
19#include "display.h"19#include "display.h"
20#include "display_buffer.h"20#include "display_buffer.h"
21#include "mir/graphics/display_configuration_policy.h"21#include "mir/graphics/display_configuration_policy.h"
22#include "mir/graphics/egl_error.h"
22#include "mir/geometry/size.h"23#include "mir/geometry/size.h"
2324
24#include <boost/throw_exception.hpp>25#include <boost/throw_exception.hpp>
@@ -45,7 +46,7 @@
45 : egl_display{eglGetDisplay(native_display)}46 : egl_display{eglGetDisplay(native_display)}
46{47{
47 if (egl_display == EGL_NO_DISPLAY)48 if (egl_display == EGL_NO_DISPLAY)
48 BOOST_THROW_EXCEPTION(std::runtime_error("Failed to get EGL display"));49 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to get EGL display"));
49}50}
5051
51mgo::detail::EGLDisplayHandle::EGLDisplayHandle(EGLDisplayHandle&& other)52mgo::detail::EGLDisplayHandle::EGLDisplayHandle(EGLDisplayHandle&& other)
@@ -59,7 +60,7 @@
59 int major, minor;60 int major, minor;
6061
61 if (eglInitialize(egl_display, &major, &minor) == EGL_FALSE)62 if (eglInitialize(egl_display, &major, &minor) == EGL_FALSE)
62 BOOST_THROW_EXCEPTION(std::runtime_error("Failed to initialize EGL"));63 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to initialize EGL"));
6364
64 if ((major != 1) || (minor != 4))65 if ((major != 1) || (minor != 4))
65 BOOST_THROW_EXCEPTION(std::runtime_error("EGL version 1.4 needed"));66 BOOST_THROW_EXCEPTION(std::runtime_error("EGL version 1.4 needed"));
6667
=== modified file 'src/server/graphics/surfaceless_egl_context.cpp'
--- src/server/graphics/surfaceless_egl_context.cpp 2015-04-13 14:26:52 +0000
+++ src/server/graphics/surfaceless_egl_context.cpp 2015-04-17 15:49:38 +0000
@@ -18,6 +18,7 @@
1818
19#include "mir/graphics/surfaceless_egl_context.h"19#include "mir/graphics/surfaceless_egl_context.h"
20#include "mir/graphics/gl_extensions_base.h"20#include "mir/graphics/gl_extensions_base.h"
21#include "mir/graphics/egl_error.h"
2122
22#include <boost/throw_exception.hpp>23#include <boost/throw_exception.hpp>
23#include <stdexcept>24#include <stdexcept>
@@ -99,7 +100,7 @@
99 if (eglChooseConfig(egl_display, attribs, &egl_config, 1, &num_egl_configs) == EGL_FALSE ||100 if (eglChooseConfig(egl_display, attribs, &egl_config, 1, &num_egl_configs) == EGL_FALSE ||
100 num_egl_configs != 1)101 num_egl_configs != 1)
101 {102 {
102 BOOST_THROW_EXCEPTION(std::runtime_error("Failed to choose EGL config"));103 BOOST_THROW_EXCEPTION(mg::egl_error("Failed to choose EGL config"));
103 }104 }
104105
105 return egl_config;106 return egl_config;
@@ -186,7 +187,7 @@
186 egl_context) == EGL_FALSE)187 egl_context) == EGL_FALSE)
187 {188 {
188 BOOST_THROW_EXCEPTION(189 BOOST_THROW_EXCEPTION(
189 std::runtime_error("could not make context current\n"));190 mg::egl_error("could not make context current"));
190 }191 }
191}192}
192193
193194
=== modified file 'tests/unit-tests/graphics/CMakeLists.txt'
--- tests/unit-tests/graphics/CMakeLists.txt 2015-04-09 06:20:31 +0000
+++ tests/unit-tests/graphics/CMakeLists.txt 2015-04-17 15:49:38 +0000
@@ -2,6 +2,7 @@
2 ${CMAKE_CURRENT_SOURCE_DIR}/test_graphics_platform.cpp2 ${CMAKE_CURRENT_SOURCE_DIR}/test_graphics_platform.cpp
3 ${CMAKE_CURRENT_SOURCE_DIR}/test_display_configuration.cpp3 ${CMAKE_CURRENT_SOURCE_DIR}/test_display_configuration.cpp
4 ${CMAKE_CURRENT_SOURCE_DIR}/test_egl_extensions.cpp4 ${CMAKE_CURRENT_SOURCE_DIR}/test_egl_extensions.cpp
5 ${CMAKE_CURRENT_SOURCE_DIR}/test_egl_error.cpp
5 ${CMAKE_CURRENT_SOURCE_DIR}/test_display.cpp6 ${CMAKE_CURRENT_SOURCE_DIR}/test_display.cpp
6 ${CMAKE_CURRENT_SOURCE_DIR}/test_default_display_configuration_policy.cpp7 ${CMAKE_CURRENT_SOURCE_DIR}/test_default_display_configuration_policy.cpp
7 ${CMAKE_CURRENT_SOURCE_DIR}/test_buffer_id.cpp8 ${CMAKE_CURRENT_SOURCE_DIR}/test_buffer_id.cpp
89
=== added file 'tests/unit-tests/graphics/test_egl_error.cpp'
--- tests/unit-tests/graphics/test_egl_error.cpp 1970-01-01 00:00:00 +0000
+++ tests/unit-tests/graphics/test_egl_error.cpp 2015-04-17 15:49:38 +0000
@@ -0,0 +1,115 @@
1/*
2 * Copyright © 2015 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 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: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17 */
18
19#include "mir/graphics/egl_error.h"
20#include "mir_test_doubles/mock_egl.h"
21
22#include <gtest/gtest.h>
23#include <gmock/gmock.h>
24
25namespace mg = mir::graphics;
26namespace mtd = mir::test::doubles;
27
28namespace
29{
30
31std::string to_hex_string(int n)
32{
33 std::stringstream ss;
34 ss << std::showbase << std::hex << n;
35 return ss.str();
36}
37
38struct EGLErrorTest : ::testing::Test
39{
40 testing::NiceMock<mtd::MockEGL> mock_egl;
41
42 std::string const user_message{"Something failed"};
43 std::string const egl_error_code_str{"EGL_BAD_MATCH"};
44 int const egl_error_code{EGL_BAD_MATCH};
45};
46
47}
48
49TEST_F(EGLErrorTest, produces_correct_error_code)
50{
51 using namespace testing;
52
53 EXPECT_CALL(mock_egl, eglGetError())
54 .WillOnce(Return(egl_error_code));
55
56 std::error_code ec;
57
58 try
59 {
60 throw mg::egl_error("");
61 }
62 catch (std::system_error const& error)
63 {
64 ec = error.code();
65 }
66
67 EXPECT_THAT(ec.value(), Eq(egl_error_code));
68}
69
70TEST_F(EGLErrorTest, produces_message_with_user_string_and_error_code_for_known_error)
71{
72 using namespace testing;
73
74 EXPECT_CALL(mock_egl, eglGetError())
75 .WillOnce(Return(egl_error_code));
76
77 std::string error_message;
78
79 try
80 {
81 throw mg::egl_error(user_message);
82 }
83 catch (std::system_error const& error)
84 {
85 error_message = error.what();
86 }
87
88 EXPECT_THAT(error_message, HasSubstr(user_message));
89 EXPECT_THAT(error_message, HasSubstr(egl_error_code_str));
90 EXPECT_THAT(error_message, HasSubstr(to_hex_string(egl_error_code)));
91}
92
93TEST_F(EGLErrorTest, produces_message_with_user_string_and_error_code_for_unknown_error)
94{
95 using namespace testing;
96
97 int const unknown_egl_error_code{0x131313};
98
99 EXPECT_CALL(mock_egl, eglGetError())
100 .WillOnce(Return(unknown_egl_error_code));
101
102 std::string error_message;
103
104 try
105 {
106 throw mg::egl_error(user_message);
107 }
108 catch (std::system_error const& error)
109 {
110 error_message = error.what();
111 }
112
113 EXPECT_THAT(error_message, HasSubstr(user_message));
114 EXPECT_THAT(error_message, HasSubstr(to_hex_string(unknown_egl_error_code)));
115}

Subscribers

People subscribed via source and target branches