~ubuntu-branches/ubuntu/vivid/mir/vivid

« back to all changes in this revision

Viewing changes to tests/include/mir_test_doubles/mock_egl.h

  • 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 © 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 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
#define GL_GLEXT_PROTOTYPES
 
25
#define EGL_EGLEXT_PROTOTYPES
 
26
#include <EGL/egl.h>
 
27
#include <EGL/eglext.h>
 
28
//for GL extensions
 
29
#include <GLES2/gl2.h>
 
30
#include <GLES2/gl2ext.h>
 
31
 
 
32
namespace mir
 
33
{
 
34
namespace test
 
35
{
 
36
namespace doubles
 
37
{
 
38
 
 
39
MATCHER_P(AttrMatches, val, std::string("matches"))
 
40
{
 
41
    auto i = 0;
 
42
    while ((val[i] != EGL_NONE) && (arg[i] != EGL_NONE))
 
43
    {
 
44
        if (val[i] != arg[i])
 
45
            return false;
 
46
        i++;
 
47
    }
 
48
 
 
49
    if ((val[i] == EGL_NONE) && (arg[i] == EGL_NONE))
 
50
    {
 
51
        return true;
 
52
    }
 
53
    return false;
 
54
}
 
55
 
 
56
MATCHER_P2(EGLConfigContainsAttrib, attrib, value, "")
 
57
{
 
58
    bool attrib_position = true;
 
59
    bool attrib_found = false;
 
60
 
 
61
    while (!attrib_position || *arg != EGL_NONE)
 
62
    {
 
63
        if (attrib_position && *arg == attrib)
 
64
        {
 
65
            attrib_found = true;
 
66
        }
 
67
        else if (!attrib_position)
 
68
        {
 
69
            if (attrib_found && *arg == value)
 
70
            {
 
71
                return true;
 
72
            }
 
73
 
 
74
            attrib_found = false;
 
75
        }
 
76
        attrib_position = !attrib_position;
 
77
        ++arg;
 
78
    }
 
79
 
 
80
    return false;
 
81
}
 
82
 
 
83
class MockEGL
 
84
{
 
85
public:
 
86
    MockEGL();
 
87
    ~MockEGL();
 
88
 
 
89
    void provide_egl_extensions();
 
90
 
 
91
    typedef void (*generic_function_pointer_t)(void);
 
92
 
 
93
    MOCK_METHOD1(eglGetDisplay, EGLDisplay(NativeDisplayType));
 
94
    MOCK_METHOD3(eglInitialize, EGLBoolean(EGLDisplay,EGLint*,EGLint*));
 
95
    MOCK_METHOD1(eglTerminate, EGLBoolean(EGLDisplay));
 
96
    MOCK_METHOD2(eglQueryString,const char*(EGLDisplay, EGLint));
 
97
    MOCK_METHOD1(eglBindApi, EGLBoolean(EGLenum));
 
98
    MOCK_METHOD1(eglGetProcAddress,generic_function_pointer_t(const char*));
 
99
 
 
100
    // Config management
 
101
    MOCK_METHOD4(eglGetConfigs, EGLBoolean(EGLDisplay,EGLConfig*,EGLint,EGLint*));
 
102
    MOCK_METHOD5(eglChooseConfig, EGLBoolean(EGLDisplay, const EGLint*,EGLConfig*,EGLint,EGLint*));
 
103
    MOCK_METHOD4(eglGetConfigAttrib, EGLBoolean(EGLDisplay,EGLConfig,EGLint,EGLint*));
 
104
 
 
105
    // Surface management
 
106
    MOCK_METHOD4(eglCreateWindowSurface, EGLSurface(EGLDisplay,EGLConfig,NativeWindowType,const EGLint*));
 
107
    MOCK_METHOD4(eglCreatePixmapSurface, EGLSurface(EGLDisplay,EGLConfig,NativePixmapType,const EGLint*));
 
108
    MOCK_METHOD3(eglCreatePbufferSurface, EGLSurface(EGLDisplay,EGLConfig,const EGLint*));
 
109
    MOCK_METHOD2(eglDestroySurface, EGLBoolean(EGLDisplay,EGLSurface));
 
110
    MOCK_METHOD4(eglQuerySurface, EGLBoolean(EGLDisplay,EGLSurface,EGLint,EGLint*));
 
111
 
 
112
    // EGL 1.1 render-to-texture APIs
 
113
    MOCK_METHOD4(eglSurfaceAttrib, EGLBoolean(EGLDisplay,EGLSurface,EGLint,EGLint));
 
114
    MOCK_METHOD3(eglBindTexImage, EGLBoolean(EGLDisplay,EGLSurface,EGLint));
 
115
    MOCK_METHOD3(eglReleaseTexImage, EGLBoolean(EGLDisplay,EGLSurface,EGLint));
 
116
 
 
117
    // EGL 1.1 swap control API
 
118
    MOCK_METHOD2(eglSwapInterval, EGLBoolean(EGLDisplay,EGLint));
 
119
 
 
120
    MOCK_METHOD4(eglCreateContext, EGLContext(EGLDisplay,EGLConfig,EGLContext,const EGLint*));
 
121
    MOCK_METHOD2(eglDestroyContext, EGLBoolean(EGLDisplay,EGLContext));
 
122
    MOCK_METHOD4(eglMakeCurrent, EGLBoolean(EGLDisplay,EGLSurface,EGLSurface,EGLContext));
 
123
    MOCK_METHOD0(eglGetCurrentContext,EGLContext());
 
124
    MOCK_METHOD1(eglGetCurrentSurface,EGLSurface(EGLint));
 
125
    MOCK_METHOD0(eglGetCurrentDisplay, EGLDisplay());
 
126
    MOCK_METHOD4(eglQueryContext, EGLBoolean(EGLDisplay,EGLContext,EGLint,EGLint*));
 
127
 
 
128
    MOCK_METHOD0(eglWaitGL, EGLBoolean());
 
129
    MOCK_METHOD1(eglWaitNative, EGLBoolean(EGLint));
 
130
    MOCK_METHOD2(eglSwapBuffers, EGLBoolean(EGLDisplay,EGLSurface));
 
131
    MOCK_METHOD3(eglCopyBuffers, EGLBoolean(EGLDisplay,EGLSurface,NativePixmapType));
 
132
 
 
133
    MOCK_METHOD0(eglGetError, EGLint (void));
 
134
 
 
135
    MOCK_METHOD5(eglCreateImageKHR, EGLImageKHR(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint*));
 
136
    MOCK_METHOD2(eglDestroyImageKHR,EGLBoolean(EGLDisplay, EGLImageKHR));
 
137
    MOCK_METHOD2(glEGLImageTargetTexture2DOES, void(GLenum, GLeglImageOES));
 
138
 
 
139
    EGLDisplay fake_egl_display;
 
140
    EGLConfig* fake_configs;
 
141
    EGLint fake_configs_num;
 
142
    EGLSurface fake_egl_surface;
 
143
    EGLContext fake_egl_context;
 
144
    EGLImageKHR fake_egl_image;
 
145
    int fake_visual_id;
 
146
};
 
147
 
 
148
}
 
149
}
 
150
}
 
151
 
 
152
#endif /* MIR_TEST_DOUBLES_MOCK_EGL_H_ */