Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/c/dev/ppb_graphics_3d_dev.h" | 7 #include <GLES2/gl2.h> |
| 8 | |
| 8 #include "ppapi/c/dev/ppb_opengles_dev.h" | 9 #include "ppapi/c/dev/ppb_opengles_dev.h" |
| 10 #include "ppapi/c/dev/ppb_testing_dev.h" | |
| 11 #include "ppapi/cpp/dev/graphics_3d_dev.h" | |
| 9 #include "ppapi/cpp/module.h" | 12 #include "ppapi/cpp/module.h" |
| 13 #include "ppapi/tests/test_utils.h" | |
| 14 #include "ppapi/tests/testing_instance.h" | |
| 10 | 15 |
| 11 REGISTER_TEST_CASE(Graphics3D); | 16 REGISTER_TEST_CASE(Graphics3D); |
| 12 | 17 |
| 13 bool TestGraphics3D::Init() { | 18 bool TestGraphics3D::Init() { |
| 14 graphics_3d_ = reinterpret_cast<const PPB_Graphics3D_Dev*>( | 19 graphics_3d_ = reinterpret_cast<const PPB_Graphics3D_Dev*>( |
| 15 pp::Module::Get()->GetBrowserInterface(PPB_GRAPHICS_3D_DEV_INTERFACE)); | 20 pp::Module::Get()->GetBrowserInterface(PPB_GRAPHICS_3D_DEV_INTERFACE)); |
|
piman
2011/08/31 21:02:38
Don't need this anymore?
alokp
2011/09/01 21:05:17
Done.
| |
| 16 opengl_es2_ = reinterpret_cast<const PPB_OpenGLES2_Dev*>( | 21 opengl_es2_ = reinterpret_cast<const PPB_OpenGLES2_Dev*>( |
| 17 pp::Module::Get()->GetBrowserInterface(PPB_OPENGLES2_DEV_INTERFACE)); | 22 pp::Module::Get()->GetBrowserInterface(PPB_OPENGLES2_DEV_INTERFACE)); |
| 18 return graphics_3d_ && opengl_es2_ && InitTestingInterface(); | 23 return graphics_3d_ && opengl_es2_ && InitTestingInterface(); |
| 19 } | 24 } |
| 20 | 25 |
| 21 void TestGraphics3D::RunTest() { | 26 void TestGraphics3D::RunTest() { |
| 27 RUN_TEST(Frame); | |
| 22 } | 28 } |
| 23 | 29 |
| 30 std::string TestGraphics3D::TestFrame() { | |
| 31 const int width = 16; | |
| 32 const int height = 16; | |
| 33 const int32_t attribs[] = { | |
| 34 PP_GRAPHICS3DATTRIB_WIDTH, width, | |
| 35 PP_GRAPHICS3DATTRIB_HEIGHT, height, | |
| 36 PP_GRAPHICS3DATTRIB_NONE | |
| 37 }; | |
| 38 pp::Graphics3D_Dev context(*instance_, pp::Graphics3D_Dev(), attribs); | |
| 39 ASSERT_FALSE(context.is_null()); | |
| 40 | |
| 41 // Clear color buffer to opaque red. | |
| 42 opengl_es2_->ClearColor(context.pp_resource(), 1.0f, 0.0f, 0.0f, 1.0f); | |
| 43 opengl_es2_->Clear(context.pp_resource(), GL_COLOR_BUFFER_BIT); | |
| 44 // Check if the color buffer has opaque red. | |
| 45 const uint8_t red_color[4] = {255, 0, 0, 255}; | |
| 46 std::string error = TestPixel(&context, width/2, height/2, red_color); | |
| 47 if (!error.empty()) | |
| 48 return error; | |
| 49 | |
| 50 int32_t rv = SwapBuffersSync(&context); | |
| 51 ASSERT_EQ(rv, PP_OK); | |
| 52 PASS(); | |
| 53 } | |
| 54 | |
| 55 int32_t TestGraphics3D::SwapBuffersSync(pp::Graphics3D_Dev* context) { | |
| 56 TestCompletionCallback callback(instance_->pp_instance(), true); | |
| 57 int32_t rv = context->SwapBuffers(callback); | |
| 58 if (rv != PP_OK_COMPLETIONPENDING) | |
| 59 return rv; | |
| 60 | |
| 61 return callback.WaitForResult(); | |
| 62 } | |
| 63 | |
| 64 std::string TestGraphics3D::TestPixel( | |
| 65 pp::Graphics3D_Dev* context, | |
| 66 int x, int y, const uint8_t expected_color[4]) { | |
| 67 GLubyte pixel_color[4]; | |
| 68 opengl_es2_->ReadPixels(context->pp_resource(), | |
| 69 x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel_color); | |
| 70 | |
| 71 ASSERT_EQ(pixel_color[0], expected_color[0]); | |
| 72 ASSERT_EQ(pixel_color[1], expected_color[1]); | |
| 73 ASSERT_EQ(pixel_color[2], expected_color[2]); | |
| 74 ASSERT_EQ(pixel_color[3], expected_color[3]); | |
| 75 PASS(); | |
| 76 } | |
| 77 | |
| OLD | NEW |