| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // Test cases for PPB_Graphics3D functions. |
| 6 // TODO(nfullagar): More comprehensive testing of the PPAPI interface. |
| 7 |
| 8 #include <string.h> |
| 9 |
| 10 #include <GLES2/gl2.h> |
| 11 |
| 12 #include "native_client/src/include/nacl_macros.h" |
| 13 #include "native_client/src/shared/platform/nacl_check.h" |
| 14 #include "native_client/tests/ppapi_test_lib/get_browser_interface.h" |
| 15 #include "native_client/tests/ppapi_test_lib/test_interface.h" |
| 16 #include "native_client/src/third_party/ppapi/c/dev/pp_graphics_3d_dev.h" |
| 17 #include "native_client/src/third_party/ppapi/c/dev/ppb_graphics_3d_dev.h" |
| 18 #include "native_client/src/third_party/ppapi/c/dev/ppb_opengles_dev.h" |
| 19 #include "native_client/src/third_party/ppapi/c/dev/ppb_testing_dev.h" |
| 20 #include "native_client/src/third_party/ppapi/c/pp_bool.h" |
| 21 #include "native_client/src/third_party/ppapi/c/pp_completion_callback.h" |
| 22 #include "native_client/src/third_party/ppapi/c/pp_errors.h" |
| 23 #include "native_client/src/third_party/ppapi/c/pp_point.h" |
| 24 #include "native_client/src/third_party/ppapi/c/pp_rect.h" |
| 25 #include "native_client/src/third_party/ppapi/c/pp_size.h" |
| 26 #include "native_client/src/third_party/ppapi/c/ppb_core.h" |
| 27 #include "native_client/src/third_party/ppapi/c/ppb_image_data.h" |
| 28 #include "native_client/src/third_party/ppapi/c/ppb_instance.h" |
| 29 #include "native_client/src/third_party/ppapi/c/ppb_url_loader.h" |
| 30 |
| 31 namespace { |
| 32 |
| 33 const int kWidth = 320; |
| 34 const int kHeight = 200; |
| 35 |
| 36 //////////////////////////////////////////////////////////////////////////////// |
| 37 // Test Cases |
| 38 //////////////////////////////////////////////////////////////////////////////// |
| 39 |
| 40 // Tests the Graphics3D interface is available. |
| 41 void TestGraphics3DInterface() { |
| 42 EXPECT(PPBGraphics3DDev() != NULL); |
| 43 TEST_PASSED; |
| 44 } |
| 45 |
| 46 // Tests the OpenGLES interface is available. |
| 47 void TestOpenGLES2Interface() { |
| 48 EXPECT(PPBOpenGLES2Dev() != NULL); |
| 49 TEST_PASSED; |
| 50 } |
| 51 |
| 52 // Tests PPB_Graphics3D::Create(). |
| 53 void TestCreate() { |
| 54 int32_t attribs[] = { |
| 55 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, |
| 56 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, |
| 57 PP_GRAPHICS3DATTRIB_NONE}; |
| 58 PP_Resource graphics3d_id = PPBGraphics3DDev()-> |
| 59 Create(pp_instance(), kInvalidResource, attribs); |
| 60 EXPECT(graphics3d_id != kInvalidResource); |
| 61 PP_Resource invalid_graphics3d_id = PPBGraphics3DDev()-> |
| 62 Create(0, kInvalidResource, attribs); |
| 63 EXPECT(invalid_graphics3d_id == kInvalidResource); |
| 64 TEST_PASSED; |
| 65 } |
| 66 |
| 67 // Tests PPB_Graphics3D::IsGraphics3D(). |
| 68 void TestIsGraphics3D() { |
| 69 int32_t attribs[] = { |
| 70 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, |
| 71 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, |
| 72 PP_GRAPHICS3DATTRIB_NONE}; |
| 73 PP_Resource graphics3d_id = PPBGraphics3DDev()-> |
| 74 Create(pp_instance(), kInvalidResource, attribs); |
| 75 EXPECT(graphics3d_id != kInvalidResource); |
| 76 EXPECT(PPBGraphics3DDev()->IsGraphics3D(graphics3d_id) == PP_TRUE); |
| 77 TEST_PASSED; |
| 78 } |
| 79 |
| 80 struct RenderInfo { |
| 81 PP_Resource graphics3d_id; |
| 82 int32_t frame_counter; |
| 83 int32_t frame_end; |
| 84 }; |
| 85 |
| 86 void SwapCallback(void* user_data, int32_t result) { |
| 87 EXPECT(result == PP_OK); |
| 88 RenderInfo* info = static_cast<RenderInfo *>(user_data); |
| 89 const PPB_OpenGLES2_Dev* gl = PPBOpenGLES2Dev(); |
| 90 EXPECT(gl != NULL); |
| 91 gl->Viewport(info->graphics3d_id, 0, 0, kWidth, kHeight); |
| 92 float blue = float(info->frame_counter) / float(info->frame_end); |
| 93 gl->ClearColor(info->graphics3d_id, 0.0f, 0.0f, blue, 1.0f); |
| 94 gl->Clear(info->graphics3d_id, GL_COLOR_BUFFER_BIT); |
| 95 ++info->frame_counter; |
| 96 if (info->frame_counter < info->frame_end) { |
| 97 PP_CompletionCallback cc = PP_MakeCompletionCallback(SwapCallback, info); |
| 98 int32_t result = PPBGraphics3DDev()->SwapBuffers(info->graphics3d_id, cc); |
| 99 CHECK(PP_OK_COMPLETIONPENDING == result); |
| 100 } else { |
| 101 delete info; |
| 102 } |
| 103 } |
| 104 |
| 105 // Tests PPB_Graphics3D::SwapBuffers(). This test will render a visible |
| 106 // result to the screen -- fading in a solid blue rectangle. |
| 107 void TestSwapBuffers() { |
| 108 int32_t attribs[] = { |
| 109 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, |
| 110 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, |
| 111 PP_GRAPHICS3DATTRIB_NONE}; |
| 112 PP_Resource graphics3d_id = PPBGraphics3DDev()-> |
| 113 Create(pp_instance(), kInvalidResource, attribs); |
| 114 EXPECT(graphics3d_id != kInvalidResource); |
| 115 int32_t success = PPBInstance()->BindGraphics(pp_instance(), graphics3d_id); |
| 116 EXPECT(success == PP_TRUE); |
| 117 RenderInfo* render_info = new RenderInfo; |
| 118 render_info->graphics3d_id = graphics3d_id; |
| 119 render_info->frame_counter = 0; |
| 120 render_info->frame_end = 256; |
| 121 PP_CompletionCallback cc = MakeTestableCompletionCallback( |
| 122 "SwapBufferCallback", SwapCallback, render_info); |
| 123 PPBCore()->CallOnMainThread(0, cc, PP_OK); |
| 124 TEST_PASSED; |
| 125 } |
| 126 |
| 127 } // namespace |
| 128 |
| 129 void SetupTests() { |
| 130 RegisterTest("TestGraphics3DInterface", TestGraphics3DInterface); |
| 131 RegisterTest("TestOpenGLES2Interface", TestOpenGLES2Interface); |
| 132 RegisterTest("TestCreate", TestCreate); |
| 133 RegisterTest("TestIsGraphics3D", TestIsGraphics3D); |
| 134 RegisterTest("TestSwapBuffers", TestSwapBuffers); |
| 135 } |
| 136 |
| 137 void SetupPluginInterfaces() { |
| 138 // none |
| 139 } |
| OLD | NEW |