| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/tests/test_graphics_3d.h" | 5 #include "ppapi/tests/test_graphics_3d.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
| 8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <stdlib.h> | 10 #include <stdlib.h> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 opengl_es2_ = static_cast<const PPB_OpenGLES2*>( | 27 opengl_es2_ = static_cast<const PPB_OpenGLES2*>( |
| 28 pp::Module::Get()->GetBrowserInterface(PPB_OPENGLES2_INTERFACE)); | 28 pp::Module::Get()->GetBrowserInterface(PPB_OPENGLES2_INTERFACE)); |
| 29 glInitializePPAPI(pp::Module::Get()->get_browser_interface()); | 29 glInitializePPAPI(pp::Module::Get()->get_browser_interface()); |
| 30 return opengl_es2_ && CheckTestingInterface(); | 30 return opengl_es2_ && CheckTestingInterface(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void TestGraphics3D::RunTests(const std::string& filter) { | 33 void TestGraphics3D::RunTests(const std::string& filter) { |
| 34 RUN_CALLBACK_TEST(TestGraphics3D, FramePPAPI, filter); | 34 RUN_CALLBACK_TEST(TestGraphics3D, FramePPAPI, filter); |
| 35 RUN_CALLBACK_TEST(TestGraphics3D, FrameGL, filter); | 35 RUN_CALLBACK_TEST(TestGraphics3D, FrameGL, filter); |
| 36 RUN_CALLBACK_TEST(TestGraphics3D, ExtensionsGL, filter); | 36 RUN_CALLBACK_TEST(TestGraphics3D, ExtensionsGL, filter); |
| 37 RUN_CALLBACK_TEST(TestGraphics3D, BadResource, filter); |
| 37 } | 38 } |
| 38 | 39 |
| 39 std::string TestGraphics3D::TestFramePPAPI() { | 40 std::string TestGraphics3D::TestFramePPAPI() { |
| 40 const int width = 16; | 41 const int width = 16; |
| 41 const int height = 16; | 42 const int height = 16; |
| 42 const int32_t attribs[] = { | 43 const int32_t attribs[] = { |
| 43 PP_GRAPHICS3DATTRIB_WIDTH, width, | 44 PP_GRAPHICS3DATTRIB_WIDTH, width, |
| 44 PP_GRAPHICS3DATTRIB_HEIGHT, height, | 45 PP_GRAPHICS3DATTRIB_HEIGHT, height, |
| 45 PP_GRAPHICS3DATTRIB_NONE | 46 PP_GRAPHICS3DATTRIB_NONE |
| 46 }; | 47 }; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 GLubyte pixel_color[4]; | 161 GLubyte pixel_color[4]; |
| 161 glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel_color); | 162 glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel_color); |
| 162 | 163 |
| 163 ASSERT_EQ(pixel_color[0], expected_color[0]); | 164 ASSERT_EQ(pixel_color[0], expected_color[0]); |
| 164 ASSERT_EQ(pixel_color[1], expected_color[1]); | 165 ASSERT_EQ(pixel_color[1], expected_color[1]); |
| 165 ASSERT_EQ(pixel_color[2], expected_color[2]); | 166 ASSERT_EQ(pixel_color[2], expected_color[2]); |
| 166 ASSERT_EQ(pixel_color[3], expected_color[3]); | 167 ASSERT_EQ(pixel_color[3], expected_color[3]); |
| 167 PASS(); | 168 PASS(); |
| 168 } | 169 } |
| 169 | 170 |
| 171 std::string TestGraphics3D::TestBadResource() { |
| 172 // The point of this test is mostly just to make sure that we don't crash and |
| 173 // provide reasonable (error) results when the resource is bad. |
| 174 const PP_Resource kBadResource = 123; |
| 175 |
| 176 // Access OpenGLES API through the PPAPI interface. |
| 177 opengl_es2_->ClearColor(kBadResource, 0.0f, 0.0f, 0.0f, 0.0f); |
| 178 opengl_es2_->Clear(kBadResource, GL_COLOR_BUFFER_BIT); |
| 179 ASSERT_EQ(GL_INVALID_OPERATION, opengl_es2_->GetError(kBadResource)); |
| 180 ASSERT_EQ(NULL, opengl_es2_->GetString(kBadResource, GL_VERSION)); |
| 181 ASSERT_EQ(0, opengl_es2_->GetUniformLocation(kBadResource, 0, NULL)); |
| 182 ASSERT_EQ(GL_FALSE, opengl_es2_->IsBuffer(kBadResource, 0)); |
| 183 ASSERT_EQ(GL_INVALID_ENUM, |
| 184 opengl_es2_->CheckFramebufferStatus(kBadResource, |
| 185 GL_DRAW_FRAMEBUFFER)); |
| 186 |
| 187 glSetCurrentContextPPAPI(kBadResource); |
| 188 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 189 glClear(GL_COLOR_BUFFER_BIT); |
| 190 ASSERT_EQ(GL_INVALID_OPERATION, glGetError()); |
| 191 ASSERT_EQ(NULL, glGetString(GL_VERSION)); |
| 192 ASSERT_EQ(0, glGetUniformLocation(0, NULL)); |
| 193 ASSERT_EQ(GL_FALSE, glIsBuffer(0)); |
| 194 ASSERT_EQ(GL_INVALID_ENUM, glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER)); |
| 195 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
| 196 glClear(GL_COLOR_BUFFER_BIT); |
| 197 |
| 198 PASS(); |
| 199 } |
| 200 |
| OLD | NEW |