~mir-team/mir/in-process-egl+input-conglomeration

« back to all changes in this revision

Viewing changes to examples/demo-inprocess-egl/example_egl_helper.cpp

Merged trunk and fixed issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2013 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: Robert Carr <robert.carr@canonical.com>
 
17
 */
 
18
 
 
19
#include "example_egl_helper.h"
 
20
 
 
21
#include <assert.h>
 
22
 
 
23
namespace me = mir::examples;
 
24
 
 
25
me::EGLHelper::EGLHelper(EGLNativeDisplayType native_display, EGLNativeWindowType native_window)
 
26
{
 
27
    display = eglGetDisplay(native_display);
 
28
    assert(display != EGL_NO_DISPLAY);
 
29
 
 
30
    int major, minor, rc;
 
31
    rc = eglInitialize(display, &major, &minor);
 
32
    assert(rc == EGL_TRUE);
 
33
    assert(major == 1);
 
34
    assert(minor == 4);
 
35
 
 
36
    EGLint attribs[] = {
 
37
        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
 
38
        EGL_RED_SIZE, 8,
 
39
        EGL_GREEN_SIZE, 8,
 
40
        EGL_BLUE_SIZE, 8,
 
41
        EGL_ALPHA_SIZE, 8,
 
42
        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
 
43
        EGL_NONE };
 
44
    EGLConfig egl_config;
 
45
    int n;
 
46
    rc = eglChooseConfig(display, attribs, &egl_config, 1, &n);
 
47
    assert(rc == EGL_TRUE);
 
48
    assert(n == 1);
 
49
 
 
50
    surface = eglCreateWindowSurface(display, egl_config, native_window, nullptr);
 
51
    assert(surface != EGL_NO_SURFACE);
 
52
 
 
53
    EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
 
54
    context = eglCreateContext(display, egl_config, EGL_NO_CONTEXT, context_attribs);
 
55
    assert(surface != EGL_NO_CONTEXT);
 
56
}
 
57
 
 
58
me::EGLHelper::~EGLHelper()
 
59
{
 
60
    eglDestroySurface(display, surface);
 
61
    eglDestroyContext(display, context);
 
62
    eglTerminate(display);
 
63
}
 
64
 
 
65
EGLDisplay me::EGLHelper::the_display() const
 
66
{
 
67
    return display;
 
68
}
 
69
 
 
70
EGLContext me::EGLHelper::the_context() const
 
71
{
 
72
    return context;
 
73
}
 
74
 
 
75
EGLSurface me::EGLHelper::the_surface() const
 
76
{
 
77
    return surface;
 
78
}