Chromium Code Reviews| Index: ppapi/tests/test_graphics_3d.cc |
| =================================================================== |
| --- ppapi/tests/test_graphics_3d.cc (revision 99012) |
| +++ ppapi/tests/test_graphics_3d.cc (working copy) |
| @@ -4,12 +4,32 @@ |
| #include "ppapi/tests/test_graphics_3d.h" |
| +#include <GLES2/gl2.h> |
| + |
| #include "ppapi/c/dev/ppb_graphics_3d_dev.h" |
| #include "ppapi/c/dev/ppb_opengles_dev.h" |
| +#include "ppapi/c/dev/ppb_testing_dev.h" |
| #include "ppapi/cpp/module.h" |
| +#include "ppapi/tests/testing_instance.h" |
| REGISTER_TEST_CASE(Graphics3D); |
| +namespace { |
| + |
| +struct SwapBuffers { |
| + int32_t result; |
| + PP_Instance instance; |
| + const PPB_Testing_Dev* testing; |
| +}; |
| + |
| +void SwapBuffersCallback(void* data, int32_t result) { |
| + SwapBuffers* swap_buffers = reinterpret_cast<SwapBuffers*>(data); |
| + swap_buffers->result = result; |
| + swap_buffers->testing->QuitMessageLoop(swap_buffers->instance); |
| +} |
| + |
| +} // namespace |
| + |
| bool TestGraphics3D::Init() { |
| graphics_3d_ = reinterpret_cast<const PPB_Graphics3D_Dev*>( |
| pp::Module::Get()->GetBrowserInterface(PPB_GRAPHICS_3D_DEV_INTERFACE)); |
| @@ -19,5 +39,62 @@ |
| } |
| void TestGraphics3D::RunTest() { |
| + RUN_TEST(Frame); |
| } |
| +std::string TestGraphics3D::TestFrame() { |
| + const int width = 16; |
| + const int height = 16; |
| + const int32_t attribs[] = { |
| + PP_GRAPHICS3DATTRIB_WIDTH, width, |
| + PP_GRAPHICS3DATTRIB_HEIGHT, height, |
| + PP_GRAPHICS3DATTRIB_NONE |
| + }; |
| + PP_Resource context = |
| + graphics_3d_->Create(instance_->pp_instance(), 0, attribs); |
|
piman
2011/08/31 20:18:54
use pp::Graphics3D to avoid manual refcounting? Sa
alokp
2011/08/31 20:48:28
Done.
|
| + ASSERT_NE(context, NULL); |
|
piman
2011/08/31 20:18:54
nit: s/NULL/0/ (PP_Resource is not a pointer).
alokp
2011/08/31 20:48:28
Done.
|
| + |
| + // Clear color buffer to opaque red. |
| + opengl_es2_->ClearColor(context, 1.0f, 0.0f, 0.0f, 1.0f); |
| + opengl_es2_->Clear(context, GL_COLOR_BUFFER_BIT); |
| + int32_t rv = SwapBuffersSync(context); |
| + ASSERT_EQ(rv, PP_OK); |
| + |
| + // Check if the color buffer has opaque red. |
| + const uint8_t red_color[4] = {255, 0, 0, 255}; |
| + std::string error = TestPixel(context, width/2, height/2, red_color); |
|
piman
2011/08/31 20:18:54
Here you rely on the swap buffers being non-destru
alokp
2011/08/31 20:48:28
Done.
|
| + |
| + pp::Module::Get()->core()->ReleaseResource(context); |
| + return error; |
| +} |
| + |
| +int32_t TestGraphics3D::SwapBuffersSync(PP_Resource context) { |
| + SwapBuffers swap_buffers; |
| + swap_buffers.result = PP_OK; |
| + swap_buffers.instance = instance_->pp_instance(); |
| + swap_buffers.testing = testing_interface_; |
| + |
| + int32_t rv = graphics_3d_->SwapBuffers( |
| + context, |
| + PP_MakeCompletionCallback(SwapBuffersCallback, &swap_buffers)); |
|
piman
2011/08/31 20:18:54
You should be able to use the TestCompletionCallba
alokp
2011/08/31 20:48:28
Nice utility. Thanks for pointing it out. Done.
|
| + if (rv != PP_OK_COMPLETIONPENDING) |
| + return rv; |
| + |
| + testing_interface_->RunMessageLoop(instance_->pp_instance()); |
| + return swap_buffers.result; |
| +} |
| + |
| +std::string TestGraphics3D::TestPixel( |
| + PP_Resource context, |
| + int x, int y, const uint8_t expected_color[4]) { |
| + GLubyte pixel_color[4]; |
| + opengl_es2_->ReadPixels(context, |
| + x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel_color); |
| + |
| + ASSERT_EQ(pixel_color[0], expected_color[0]); |
| + ASSERT_EQ(pixel_color[1], expected_color[1]); |
| + ASSERT_EQ(pixel_color[2], expected_color[2]); |
| + ASSERT_EQ(pixel_color[3], expected_color[3]); |
| + PASS(); |
| +} |
| + |