Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / tests / angle_tests / ANGLETest.cpp
1 #include "ANGLETest.h"
2 #include "EGLWindow.h"
3 #include "OSWindow.h"
4
5 ANGLETest::ANGLETest(EGLint glesMajorVersion, EGLint requestedRenderer)
6     : mEGLWindow(NULL),
7       mOSWindow(NULL)
8 {
9     mEGLWindow = new EGLWindow(1280, 720, glesMajorVersion, requestedRenderer);
10 }
11
12 void ANGLETest::SetUp()
13 {
14     if (!initTestWindow())
15     {
16         FAIL() << "Failed to create ANGLE test window.";
17     }
18
19     if (!resizeWindow(mEGLWindow->getWidth(), mEGLWindow->getHeight()))
20     {
21         FAIL() << "Failed to resize ANGLE test window.";
22     }
23
24     if (!createEGLContext())
25     {
26         FAIL() << "egl context creation failed.";
27     }
28 }
29
30 void ANGLETest::TearDown()
31 {
32     swapBuffers();
33     mOSWindow->messageLoop();
34
35     if (!destroyEGLContext())
36     {
37         FAIL() << "egl context destruction failed.";
38     }
39
40     // Check for quit message
41     Event myEvent;
42     while (mOSWindow->popEvent(&myEvent))
43     {
44         if (myEvent.Type == Event::EVENT_CLOSED)
45         {
46             exit(0);
47         }
48     }
49
50     if (!destroyTestWindow())
51     {
52         FAIL() << "ANGLE test window destruction failed.";
53     }
54 }
55
56 void ANGLETest::swapBuffers()
57 {
58     mEGLWindow->swap();
59 }
60
61 void ANGLETest::drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth)
62 {
63     GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
64
65     glUseProgram(program);
66
67     const GLfloat vertices[] =
68     {
69         -1.0f,  1.0f, quadDepth,
70         -1.0f, -1.0f, quadDepth,
71          1.0f, -1.0f, quadDepth,
72
73         -1.0f,  1.0f, quadDepth,
74          1.0f, -1.0f, quadDepth,
75          1.0f,  1.0f, quadDepth,
76     };
77
78     glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices);
79     glEnableVertexAttribArray(positionLocation);
80
81     glDrawArrays(GL_TRIANGLES, 0, 6);
82
83     glDisableVertexAttribArray(positionLocation);
84     glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
85
86     glUseProgram(0);
87 }
88
89 GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
90 {
91     GLuint shader = glCreateShader(type);
92
93     const char *sourceArray[1] = { source.c_str() };
94     glShaderSource(shader, 1, sourceArray, NULL);
95     glCompileShader(shader);
96
97     GLint compileResult;
98     glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
99
100     if (compileResult == 0)
101     {
102         GLint infoLogLength;
103         glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
104
105         std::vector<GLchar> infoLog(infoLogLength);
106         glGetShaderInfoLog(shader, infoLog.size(), NULL, &infoLog[0]);
107
108         std::cerr << "shader compilation failed: " << &infoLog[0];
109
110         glDeleteShader(shader);
111         shader = 0;
112     }
113
114     return shader;
115 }
116
117 bool ANGLETest::extensionEnabled(const std::string &extName)
118 {
119     const char* extString = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
120     return strstr(extString, extName.c_str()) != NULL;
121 }
122
123 void ANGLETest::setWindowWidth(int width)
124 {
125     mEGLWindow->setWidth(width);
126 }
127
128 void ANGLETest::setWindowHeight(int height)
129 {
130     mEGLWindow->setHeight(height);
131 }
132
133 void ANGLETest::setConfigRedBits(int bits)
134 {
135     mEGLWindow->setConfigRedBits(bits);
136 }
137
138 void ANGLETest::setConfigGreenBits(int bits)
139 {
140     mEGLWindow->setConfigGreenBits(bits);
141 }
142
143 void ANGLETest::setConfigBlueBits(int bits)
144 {
145     mEGLWindow->setConfigBlueBits(bits);
146 }
147
148 void ANGLETest::setConfigAlphaBits(int bits)
149 {
150     mEGLWindow->setConfigAlphaBits(bits);
151 }
152
153 void ANGLETest::setConfigDepthBits(int bits)
154 {
155     mEGLWindow->setConfigDepthBits(bits);
156 }
157
158 void ANGLETest::setConfigStencilBits(int bits)
159 {
160     mEGLWindow->setConfigStencilBits(bits);
161 }
162
163 void ANGLETest::setMultisampleEnabled(bool enabled)
164 {
165     mEGLWindow->setMultisample(enabled);
166 }
167
168 int ANGLETest::getClientVersion() const
169 {
170     return mEGLWindow->getClientVersion();
171 }
172
173 int ANGLETest::getWindowWidth() const
174 {
175     return mEGLWindow->getWidth();
176 }
177
178 int ANGLETest::getWindowHeight() const
179 {
180     return mEGLWindow->getHeight();
181 }
182
183 bool ANGLETest::isMultisampleEnabled() const
184 {
185     return mEGLWindow->isMultisample();
186 }
187
188 bool ANGLETest::createEGLContext()
189 {
190     return mEGLWindow->initializeGL(mOSWindow);
191 }
192
193 bool ANGLETest::destroyEGLContext()
194 {
195     mEGLWindow->destroyGL();
196     return true;
197 }
198
199 bool ANGLETest::initTestWindow()
200 {
201     mOSWindow = CreateOSWindow();
202     if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
203     {
204         return false;
205     }
206
207     mOSWindow->setVisible(false);
208
209     return true;
210 }
211
212 bool ANGLETest::destroyTestWindow()
213 {
214     if (mOSWindow)
215     {
216         mOSWindow->destroy();
217         delete mOSWindow;
218         mOSWindow = NULL;
219     }
220
221     return true;
222 }
223
224 bool ANGLETest::resizeWindow(int width, int height)
225 {
226     return mOSWindow->resize(width, height);
227 }
228
229 void ANGLETest::setWindowVisible(bool isVisible)
230 {
231     mOSWindow->setVisible(isVisible);
232 }