~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to playground/demo-inprocess-surface-client/example_egl_helper.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-10-10 14:01:26 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20141010140126-n1czko8na1kuz4ll
Tags: upstream-0.8.0+14.10.20141010
Import upstream version 0.8.0+14.10.20141010

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
    (void)rc;
 
50
 
 
51
    surface = eglCreateWindowSurface(display, egl_config, native_window, nullptr);
 
52
    assert(surface != EGL_NO_SURFACE);
 
53
 
 
54
    EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
 
55
    context = eglCreateContext(display, egl_config, EGL_NO_CONTEXT, context_attribs);
 
56
    assert(surface != EGL_NO_CONTEXT);
 
57
}
 
58
 
 
59
me::EGLHelper::~EGLHelper()
 
60
{
 
61
    eglDestroySurface(display, surface);
 
62
    eglDestroyContext(display, context);
 
63
    eglTerminate(display);
 
64
}
 
65
 
 
66
EGLDisplay me::EGLHelper::the_display() const
 
67
{
 
68
    return display;
 
69
}
 
70
 
 
71
EGLContext me::EGLHelper::the_context() const
 
72
{
 
73
    return context;
 
74
}
 
75
 
 
76
EGLSurface me::EGLHelper::the_surface() const
 
77
{
 
78
    return surface;
 
79
}