| 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 // Test cases for PPB_Graphics3D functions. | 5 // Test cases for PPB_Graphics3D functions. |
| 6 // TODO(nfullagar): More comprehensive testing of the PPAPI interface. | 6 // TODO(nfullagar): More comprehensive testing of the PPAPI interface. |
| 7 | 7 |
| 8 #include <GLES2/gl2.h> | 8 #include <GLES2/gl2.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <sys/time.h> | 10 #include <sys/time.h> |
| 11 | 11 |
| 12 #include "native_client/src/include/nacl_macros.h" | 12 #include "native_client/src/include/nacl_macros.h" |
| 13 #include "native_client/src/shared/platform/nacl_check.h" | 13 #include "native_client/src/shared/platform/nacl_check.h" |
| 14 #include "native_client/tests/ppapi_test_lib/get_browser_interface.h" | 14 #include "native_client/tests/ppapi_test_lib/get_browser_interface.h" |
| 15 #include "native_client/tests/ppapi_test_lib/internal_utils.h" | 15 #include "native_client/tests/ppapi_test_lib/internal_utils.h" |
| 16 #include "native_client/tests/ppapi_test_lib/test_interface.h" | 16 #include "native_client/tests/ppapi_test_lib/test_interface.h" |
| 17 #include "ppapi/c/dev/pp_graphics_3d_dev.h" |
| 18 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" |
| 19 #include "ppapi/c/dev/ppb_opengles_dev.h" |
| 17 #include "ppapi/c/dev/ppb_testing_dev.h" | 20 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 18 #include "ppapi/c/pp_bool.h" | 21 #include "ppapi/c/pp_bool.h" |
| 19 #include "ppapi/c/pp_completion_callback.h" | 22 #include "ppapi/c/pp_completion_callback.h" |
| 20 #include "ppapi/c/pp_errors.h" | 23 #include "ppapi/c/pp_errors.h" |
| 21 #include "ppapi/c/pp_graphics_3d.h" | |
| 22 #include "ppapi/c/pp_point.h" | 24 #include "ppapi/c/pp_point.h" |
| 23 #include "ppapi/c/pp_rect.h" | 25 #include "ppapi/c/pp_rect.h" |
| 24 #include "ppapi/c/pp_size.h" | 26 #include "ppapi/c/pp_size.h" |
| 25 #include "ppapi/c/ppb_core.h" | 27 #include "ppapi/c/ppb_core.h" |
| 26 #include "ppapi/c/ppb_graphics_3d.h" | |
| 27 #include "ppapi/c/ppb_image_data.h" | 28 #include "ppapi/c/ppb_image_data.h" |
| 28 #include "ppapi/c/ppb_instance.h" | 29 #include "ppapi/c/ppb_instance.h" |
| 29 #include "ppapi/c/ppb_opengles.h" | |
| 30 #include "ppapi/c/ppb_url_loader.h" | 30 #include "ppapi/c/ppb_url_loader.h" |
| 31 #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h" | 31 #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h" |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 const int kWidth = 320; | 35 const int kWidth = 320; |
| 36 const int kHeight = 200; | 36 const int kHeight = 200; |
| 37 //////////////////////////////////////////////////////////////////////////////// | 37 //////////////////////////////////////////////////////////////////////////////// |
| 38 // Test Cases | 38 // Test Cases |
| 39 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
| 40 | 40 |
| 41 // Tests the Graphics3D interface is available. | 41 // Tests the Graphics3D interface is available. |
| 42 void TestGraphics3DInterface() { | 42 void TestGraphics3DInterface() { |
| 43 EXPECT(PPBGraphics3D() != NULL); | 43 EXPECT(PPBGraphics3DDev() != NULL); |
| 44 TEST_PASSED; | 44 TEST_PASSED; |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Tests the OpenGLES interface is available. | 47 // Tests the OpenGLES interface is available. |
| 48 void TestOpenGLES2Interface() { | 48 void TestOpenGLES2Interface() { |
| 49 EXPECT(PPBOpenGLES2() != NULL); | 49 EXPECT(PPBOpenGLES2Dev() != NULL); |
| 50 TEST_PASSED; | 50 TEST_PASSED; |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Tests PPB_Graphics3D::Create(). | 53 // Tests PPB_Graphics3D::Create(). |
| 54 void TestCreate() { | 54 void TestCreate() { |
| 55 int32_t attribs[] = { | 55 int32_t attribs[] = { |
| 56 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, | 56 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, |
| 57 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, | 57 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, |
| 58 PP_GRAPHICS3DATTRIB_NONE}; | 58 PP_GRAPHICS3DATTRIB_NONE}; |
| 59 PP_Resource graphics3d_id = PPBGraphics3D()-> | 59 PP_Resource graphics3d_id = PPBGraphics3DDev()-> |
| 60 Create(pp_instance(), kInvalidResource, attribs); | 60 Create(pp_instance(), kInvalidResource, attribs); |
| 61 EXPECT(graphics3d_id != kInvalidResource); | 61 EXPECT(graphics3d_id != kInvalidResource); |
| 62 PPBCore()->ReleaseResource(graphics3d_id); | 62 PPBCore()->ReleaseResource(graphics3d_id); |
| 63 PP_Resource invalid_graphics3d_id = PPBGraphics3D()-> | 63 PP_Resource invalid_graphics3d_id = PPBGraphics3DDev()-> |
| 64 Create(0, kInvalidResource, attribs); | 64 Create(0, kInvalidResource, attribs); |
| 65 EXPECT(invalid_graphics3d_id == kInvalidResource); | 65 EXPECT(invalid_graphics3d_id == kInvalidResource); |
| 66 int32_t empty_attribs[] = { | 66 int32_t empty_attribs[] = { |
| 67 PP_GRAPHICS3DATTRIB_NONE}; | 67 PP_GRAPHICS3DATTRIB_NONE}; |
| 68 PP_Resource graphics3d_empty_attrib_id = PPBGraphics3D()-> | 68 PP_Resource graphics3d_empty_attrib_id = PPBGraphics3DDev()-> |
| 69 Create(pp_instance(), kInvalidResource, empty_attribs); | 69 Create(pp_instance(), kInvalidResource, empty_attribs); |
| 70 EXPECT(graphics3d_empty_attrib_id != kInvalidResource); | 70 EXPECT(graphics3d_empty_attrib_id != kInvalidResource); |
| 71 PPBCore()->ReleaseResource(graphics3d_empty_attrib_id); | 71 PPBCore()->ReleaseResource(graphics3d_empty_attrib_id); |
| 72 PP_Resource graphics3d_null_attrib_id = PPBGraphics3D()-> | 72 PP_Resource graphics3d_null_attrib_id = PPBGraphics3DDev()-> |
| 73 Create(pp_instance(), kInvalidResource, NULL); | 73 Create(pp_instance(), kInvalidResource, NULL); |
| 74 EXPECT(graphics3d_null_attrib_id != kInvalidResource); | 74 EXPECT(graphics3d_null_attrib_id != kInvalidResource); |
| 75 PPBCore()->ReleaseResource(graphics3d_null_attrib_id); | 75 PPBCore()->ReleaseResource(graphics3d_null_attrib_id); |
| 76 TEST_PASSED; | 76 TEST_PASSED; |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Tests PPB_Graphics3D::IsGraphics3D(). | 79 // Tests PPB_Graphics3D::IsGraphics3D(). |
| 80 void TestIsGraphics3D() { | 80 void TestIsGraphics3D() { |
| 81 int32_t attribs[] = { | 81 int32_t attribs[] = { |
| 82 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, | 82 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, |
| 83 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, | 83 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, |
| 84 PP_GRAPHICS3DATTRIB_NONE}; | 84 PP_GRAPHICS3DATTRIB_NONE}; |
| 85 PP_Resource graphics3d_id = PPBGraphics3D()-> | 85 PP_Resource graphics3d_id = PPBGraphics3DDev()-> |
| 86 Create(pp_instance(), kInvalidResource, attribs); | 86 Create(pp_instance(), kInvalidResource, attribs); |
| 87 EXPECT(graphics3d_id != kInvalidResource); | 87 EXPECT(graphics3d_id != kInvalidResource); |
| 88 EXPECT(PPBGraphics3D()->IsGraphics3D(graphics3d_id) == PP_TRUE); | 88 EXPECT(PPBGraphics3DDev()->IsGraphics3D(graphics3d_id) == PP_TRUE); |
| 89 PPBCore()->ReleaseResource(graphics3d_id); | 89 PPBCore()->ReleaseResource(graphics3d_id); |
| 90 TEST_PASSED; | 90 TEST_PASSED; |
| 91 } | 91 } |
| 92 | 92 |
| 93 // Tests glInitializePPAPI. | 93 // Tests glInitializePPAPI. |
| 94 void Test_glInitializePPAPI() { | 94 void Test_glInitializePPAPI() { |
| 95 GLboolean init_ppapi = glInitializePPAPI(ppb_get_interface()); | 95 GLboolean init_ppapi = glInitializePPAPI(ppb_get_interface()); |
| 96 EXPECT(init_ppapi == true); | 96 EXPECT(init_ppapi == true); |
| 97 TEST_PASSED; | 97 TEST_PASSED; |
| 98 } | 98 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 111 // instead of going through the PPAPI PPBOpenGLES2 interface. | 111 // instead of going through the PPAPI PPBOpenGLES2 interface. |
| 112 glSetCurrentContextPPAPI(info->graphics3d_id); | 112 glSetCurrentContextPPAPI(info->graphics3d_id); |
| 113 glViewport(0, 0, kWidth, kHeight); | 113 glViewport(0, 0, kWidth, kHeight); |
| 114 float blue = float(info->frame_counter) / float(info->frame_end); | 114 float blue = float(info->frame_counter) / float(info->frame_end); |
| 115 glClearColor(0.0f, 0.0f, blue, 1.0f); | 115 glClearColor(0.0f, 0.0f, blue, 1.0f); |
| 116 glClear(GL_COLOR_BUFFER_BIT); | 116 glClear(GL_COLOR_BUFFER_BIT); |
| 117 info->frame_counter += info->frame_increment; | 117 info->frame_counter += info->frame_increment; |
| 118 if (info->frame_counter < info->frame_end) { | 118 if (info->frame_counter < info->frame_end) { |
| 119 PP_CompletionCallback cc = | 119 PP_CompletionCallback cc = |
| 120 PP_MakeCompletionCallback(TestSwapCallback, info); | 120 PP_MakeCompletionCallback(TestSwapCallback, info); |
| 121 int32_t result = PPBGraphics3D()->SwapBuffers(info->graphics3d_id, cc); | 121 int32_t result = PPBGraphics3DDev()->SwapBuffers(info->graphics3d_id, cc); |
| 122 CHECK(PP_OK_COMPLETIONPENDING == result); | 122 CHECK(PP_OK_COMPLETIONPENDING == result); |
| 123 } else { | 123 } else { |
| 124 PPBCore()->ReleaseResource(info->graphics3d_id); | 124 PPBCore()->ReleaseResource(info->graphics3d_id); |
| 125 delete info; | 125 delete info; |
| 126 TEST_PASSED; | 126 TEST_PASSED; |
| 127 } | 127 } |
| 128 glSetCurrentContextPPAPI(0); | 128 glSetCurrentContextPPAPI(0); |
| 129 } | 129 } |
| 130 | 130 |
| 131 // Tests PPB_Graphics3D::SwapBuffers(). This test will render a visible | 131 // Tests PPB_Graphics3D::SwapBuffers(). This test will render a visible |
| 132 // result to the screen -- fading in a solid blue rectangle. | 132 // result to the screen -- fading in a solid blue rectangle. |
| 133 void TestSwapBuffers() { | 133 void TestSwapBuffers() { |
| 134 int32_t attribs[] = { | 134 int32_t attribs[] = { |
| 135 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, | 135 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, |
| 136 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, | 136 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, |
| 137 PP_GRAPHICS3DATTRIB_NONE}; | 137 PP_GRAPHICS3DATTRIB_NONE}; |
| 138 PP_Resource graphics3d_id = PPBGraphics3D()-> | 138 PP_Resource graphics3d_id = PPBGraphics3DDev()-> |
| 139 Create(pp_instance(), kInvalidResource, attribs); | 139 Create(pp_instance(), kInvalidResource, attribs); |
| 140 EXPECT(graphics3d_id != kInvalidResource); | 140 EXPECT(graphics3d_id != kInvalidResource); |
| 141 int32_t success = PPBInstance()->BindGraphics(pp_instance(), graphics3d_id); | 141 int32_t success = PPBInstance()->BindGraphics(pp_instance(), graphics3d_id); |
| 142 EXPECT(success == PP_TRUE); | 142 EXPECT(success == PP_TRUE); |
| 143 RenderInfo* render_info = new RenderInfo; | 143 RenderInfo* render_info = new RenderInfo; |
| 144 render_info->graphics3d_id = graphics3d_id; | 144 render_info->graphics3d_id = graphics3d_id; |
| 145 render_info->frame_counter = 0; | 145 render_info->frame_counter = 0; |
| 146 render_info->frame_end = 256; | 146 render_info->frame_end = 256; |
| 147 render_info->frame_increment = 2; | 147 render_info->frame_increment = 2; |
| 148 PP_CompletionCallback cc = PP_MakeCompletionCallback( | 148 PP_CompletionCallback cc = PP_MakeCompletionCallback( |
| 149 TestSwapCallback, render_info); | 149 TestSwapCallback, render_info); |
| 150 PPBCore()->CallOnMainThread(0, cc, PP_OK); | 150 PPBCore()->CallOnMainThread(0, cc, PP_OK); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void TestResizeAndSwapCallback(void* user_data, int32_t result) { | |
| 154 EXPECT(result == PP_OK); | |
| 155 RenderInfo* info = static_cast<RenderInfo *>(user_data); | |
| 156 int32_t new_width = kWidth - info->frame_counter * 2; | |
| 157 int32_t new_height = kHeight - info->frame_counter * 2; | |
| 158 if (new_width < 0) new_width = 0; | |
| 159 if (new_height < 0) new_height = 0; | |
| 160 int32_t resize_result = PPBGraphics3D()->ResizeBuffers(info->graphics3d_id, | |
| 161 new_width, new_height); | |
| 162 EXPECT(resize_result == PP_OK); | |
| 163 // Set graphics3d_id to the main context, so we can use normal gl style calls | |
| 164 // instead of going through the PPAPI PPBOpenGLES2 interface. | |
| 165 glSetCurrentContextPPAPI(info->graphics3d_id); | |
| 166 // Note: still use original width & height in glViewport; visual inspection | |
| 167 // should show a clipped window that shrinks to new_width, new_height size. | |
| 168 glViewport(0, 0, new_width, new_height); | |
| 169 float green = float(info->frame_counter) / float(info->frame_end); | |
| 170 glClearColor(0.0f, green, 0.0f, 1.0f); | |
| 171 glClear(GL_COLOR_BUFFER_BIT); | |
| 172 info->frame_counter += info->frame_increment; | |
| 173 if (info->frame_counter < info->frame_end) { | |
| 174 PP_CompletionCallback cc = | |
| 175 PP_MakeCompletionCallback(TestResizeAndSwapCallback, info); | |
| 176 int32_t result = PPBGraphics3D()->SwapBuffers(info->graphics3d_id, cc); | |
| 177 CHECK(PP_OK_COMPLETIONPENDING == result); | |
| 178 } else { | |
| 179 PPBCore()->ReleaseResource(info->graphics3d_id); | |
| 180 delete info; | |
| 181 TEST_PASSED; | |
| 182 } | |
| 183 glSetCurrentContextPPAPI(0); | |
| 184 } | |
| 185 | |
| 186 // Tests PPB_Graphics3D::ResizeBuffers(). | |
| 187 void TestResizeBuffers(int32_t* attribs) { | |
| 188 PP_Resource graphics3d_id = PPBGraphics3D()-> | |
| 189 Create(pp_instance(), kInvalidResource, attribs); | |
| 190 EXPECT(graphics3d_id != kInvalidResource); | |
| 191 int32_t success = PPBInstance()->BindGraphics(pp_instance(), graphics3d_id); | |
| 192 EXPECT(success == PP_TRUE); | |
| 193 int32_t result; | |
| 194 // Attempt negative width & heights | |
| 195 result = PPBGraphics3D()->ResizeBuffers(graphics3d_id, -1000, 0); | |
| 196 EXPECT(result == PP_ERROR_BADARGUMENT); | |
| 197 result = PPBGraphics3D()->ResizeBuffers(graphics3d_id, 100, -1); | |
| 198 EXPECT(result == PP_ERROR_BADARGUMENT); | |
| 199 result = PPBGraphics3D()->ResizeBuffers(graphics3d_id, -1, -1); | |
| 200 EXPECT(result == PP_ERROR_BADARGUMENT); | |
| 201 RenderInfo* render_info = new RenderInfo; | |
| 202 render_info->graphics3d_id = graphics3d_id; | |
| 203 render_info->frame_counter = 0; | |
| 204 render_info->frame_end = 256; | |
| 205 render_info->frame_increment = 8; | |
| 206 PP_CompletionCallback cc = PP_MakeCompletionCallback( | |
| 207 TestResizeAndSwapCallback, render_info); | |
| 208 PPBCore()->CallOnMainThread(0, cc, PP_OK); | |
| 209 } | |
| 210 | |
| 211 | |
| 212 // Tests PPB_Graphics3D::ResizeBuffers() w/o depth buffer attached. | |
| 213 void TestResizeBuffersWithoutDepthBuffer() { | |
| 214 int32_t attribs[] = { | |
| 215 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, | |
| 216 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, | |
| 217 PP_GRAPHICS3DATTRIB_NONE}; | |
| 218 TestResizeBuffers(attribs); | |
| 219 } | |
| 220 | |
| 221 | |
| 222 // Tests PPB_Graphics3D::ResizeBuffers() w/ depth buffer attached. | |
| 223 void TestResizeBuffersWithDepthBuffer() { | |
| 224 int32_t attribs[] = { | |
| 225 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, | |
| 226 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, | |
| 227 PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 32, | |
| 228 PP_GRAPHICS3DATTRIB_NONE}; | |
| 229 TestResizeBuffers(attribs); | |
| 230 } | |
| 231 | |
| 232 | |
| 233 // Tests glTerminatePPAPI. | 153 // Tests glTerminatePPAPI. |
| 234 void Test_glTerminatePPAPI() { | 154 void Test_glTerminatePPAPI() { |
| 235 GLboolean terminate = glTerminatePPAPI(); | 155 GLboolean terminate = glTerminatePPAPI(); |
| 236 EXPECT(terminate == true); | 156 EXPECT(terminate == true); |
| 237 TEST_PASSED; | 157 TEST_PASSED; |
| 238 } | 158 } |
| 239 | 159 |
| 240 } // namespace | 160 } // namespace |
| 241 | 161 |
| 242 void SetupTests() { | 162 void SetupTests() { |
| 243 RegisterTest("TestGraphics3DInterface", TestGraphics3DInterface); | 163 RegisterTest("TestGraphics3DInterface", TestGraphics3DInterface); |
| 244 RegisterTest("TestOpenGLES2Interface", TestOpenGLES2Interface); | 164 RegisterTest("TestOpenGLES2Interface", TestOpenGLES2Interface); |
| 245 RegisterTest("TestCreate", TestCreate); | 165 RegisterTest("TestCreate", TestCreate); |
| 246 RegisterTest("TestIsGraphics3D", TestIsGraphics3D); | 166 RegisterTest("TestIsGraphics3D", TestIsGraphics3D); |
| 247 RegisterTest("Test_glInitializePPAPI", Test_glInitializePPAPI); | 167 RegisterTest("Test_glInitializePPAPI", Test_glInitializePPAPI); |
| 248 RegisterTest("TestSwapBuffers", TestSwapBuffers); | 168 RegisterTest("TestSwapBuffers", TestSwapBuffers); |
| 249 RegisterTest("TestResizeBuffersWithoutDepthBuffer", | |
| 250 TestResizeBuffersWithoutDepthBuffer); | |
| 251 RegisterTest("TestResizeBuffersWithDepthBuffer", | |
| 252 TestResizeBuffersWithDepthBuffer); | |
| 253 RegisterTest("Test_glTerminatePPAPI", Test_glTerminatePPAPI); | 169 RegisterTest("Test_glTerminatePPAPI", Test_glTerminatePPAPI); |
| 254 } | 170 } |
| 255 | 171 |
| 256 void SetupPluginInterfaces() { | 172 void SetupPluginInterfaces() { |
| 257 // none | 173 // none |
| 258 } | 174 } |
| OLD | NEW |