OLD | NEW |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | 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 | 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 <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <GLES2/gl2.h> | 10 #include <GLES2/gl2.h> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 // Tests PPB_Graphics3D::Create(). | 54 // Tests PPB_Graphics3D::Create(). |
55 void TestCreate() { | 55 void TestCreate() { |
56 int32_t attribs[] = { | 56 int32_t attribs[] = { |
57 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, | 57 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, |
58 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, | 58 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, |
59 PP_GRAPHICS3DATTRIB_NONE}; | 59 PP_GRAPHICS3DATTRIB_NONE}; |
60 PP_Resource graphics3d_id = PPBGraphics3DDev()-> | 60 PP_Resource graphics3d_id = PPBGraphics3DDev()-> |
61 Create(pp_instance(), kInvalidResource, attribs); | 61 Create(pp_instance(), kInvalidResource, attribs); |
62 EXPECT(graphics3d_id != kInvalidResource); | 62 EXPECT(graphics3d_id != kInvalidResource); |
| 63 PPBCore()->ReleaseResource(graphics3d_id); |
63 PP_Resource invalid_graphics3d_id = PPBGraphics3DDev()-> | 64 PP_Resource invalid_graphics3d_id = PPBGraphics3DDev()-> |
64 Create(0, kInvalidResource, attribs); | 65 Create(0, kInvalidResource, attribs); |
65 EXPECT(invalid_graphics3d_id == kInvalidResource); | 66 EXPECT(invalid_graphics3d_id == kInvalidResource); |
66 int32_t empty_attribs[] = { | 67 int32_t empty_attribs[] = { |
67 PP_GRAPHICS3DATTRIB_NONE}; | 68 PP_GRAPHICS3DATTRIB_NONE}; |
68 PP_Resource graphics3d_empty_attrib_id = PPBGraphics3DDev()-> | 69 PP_Resource graphics3d_empty_attrib_id = PPBGraphics3DDev()-> |
69 Create(pp_instance(), kInvalidResource, empty_attribs); | 70 Create(pp_instance(), kInvalidResource, empty_attribs); |
70 EXPECT(graphics3d_empty_attrib_id != kInvalidResource); | 71 EXPECT(graphics3d_empty_attrib_id != kInvalidResource); |
| 72 PPBCore()->ReleaseResource(graphics3d_empty_attrib_id); |
71 PP_Resource graphics3d_null_attrib_id = PPBGraphics3DDev()-> | 73 PP_Resource graphics3d_null_attrib_id = PPBGraphics3DDev()-> |
72 Create(pp_instance(), kInvalidResource, NULL); | 74 Create(pp_instance(), kInvalidResource, NULL); |
73 EXPECT(graphics3d_null_attrib_id != kInvalidResource); | 75 EXPECT(graphics3d_null_attrib_id != kInvalidResource); |
| 76 PPBCore()->ReleaseResource(graphics3d_null_attrib_id); |
74 TEST_PASSED; | 77 TEST_PASSED; |
75 } | 78 } |
76 | 79 |
77 // Tests PPB_Graphics3D::IsGraphics3D(). | 80 // Tests PPB_Graphics3D::IsGraphics3D(). |
78 void TestIsGraphics3D() { | 81 void TestIsGraphics3D() { |
79 int32_t attribs[] = { | 82 int32_t attribs[] = { |
80 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, | 83 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, |
81 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, | 84 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight, |
82 PP_GRAPHICS3DATTRIB_NONE}; | 85 PP_GRAPHICS3DATTRIB_NONE}; |
83 PP_Resource graphics3d_id = PPBGraphics3DDev()-> | 86 PP_Resource graphics3d_id = PPBGraphics3DDev()-> |
84 Create(pp_instance(), kInvalidResource, attribs); | 87 Create(pp_instance(), kInvalidResource, attribs); |
85 EXPECT(graphics3d_id != kInvalidResource); | 88 EXPECT(graphics3d_id != kInvalidResource); |
86 EXPECT(PPBGraphics3DDev()->IsGraphics3D(graphics3d_id) == PP_TRUE); | 89 EXPECT(PPBGraphics3DDev()->IsGraphics3D(graphics3d_id) == PP_TRUE); |
| 90 PPBCore()->ReleaseResource(graphics3d_id); |
87 TEST_PASSED; | 91 TEST_PASSED; |
88 } | 92 } |
89 | 93 |
90 struct RenderInfo { | 94 struct RenderInfo { |
91 PP_Resource graphics3d_id; | 95 PP_Resource graphics3d_id; |
92 int32_t frame_counter; | 96 int32_t frame_counter; |
93 int32_t frame_end; | 97 int32_t frame_end; |
94 }; | 98 }; |
95 | 99 |
96 void SwapCallback(void* user_data, int32_t result) { | 100 void SwapCallback(void* user_data, int32_t result) { |
97 EXPECT(result == PP_OK); | 101 EXPECT(result == PP_OK); |
98 RenderInfo* info = static_cast<RenderInfo *>(user_data); | 102 RenderInfo* info = static_cast<RenderInfo *>(user_data); |
99 // Set graphics3d_id to the main context, so we can use normal gl style calls | 103 // Set graphics3d_id to the main context, so we can use normal gl style calls |
100 // instead of going through the PPAPI PPBOpenGLES2 interface. | 104 // instead of going through the PPAPI PPBOpenGLES2 interface. |
101 glSetCurrentContextPPAPI(info->graphics3d_id); | 105 glSetCurrentContextPPAPI(info->graphics3d_id); |
102 glViewport(0, 0, kWidth, kHeight); | 106 glViewport(0, 0, kWidth, kHeight); |
103 float blue = float(info->frame_counter) / float(info->frame_end); | 107 float blue = float(info->frame_counter) / float(info->frame_end); |
104 glClearColor(0.0f, 0.0f, blue, 1.0f); | 108 glClearColor(0.0f, 0.0f, blue, 1.0f); |
105 glClear(GL_COLOR_BUFFER_BIT); | 109 glClear(GL_COLOR_BUFFER_BIT); |
106 ++info->frame_counter; | 110 ++info->frame_counter; |
107 if (info->frame_counter < info->frame_end) { | 111 if (info->frame_counter < info->frame_end) { |
108 PP_CompletionCallback cc = PP_MakeCompletionCallback(SwapCallback, info); | 112 PP_CompletionCallback cc = PP_MakeCompletionCallback(SwapCallback, info); |
109 int32_t result = PPBGraphics3DDev()->SwapBuffers(info->graphics3d_id, cc); | 113 int32_t result = PPBGraphics3DDev()->SwapBuffers(info->graphics3d_id, cc); |
110 CHECK(PP_OK_COMPLETIONPENDING == result); | 114 CHECK(PP_OK_COMPLETIONPENDING == result); |
111 } else { | 115 } else { |
| 116 PPBCore()->ReleaseResource(info->graphics3d_id); |
112 delete info; | 117 delete info; |
113 } | 118 } |
114 glSetCurrentContextPPAPI(0); | 119 glSetCurrentContextPPAPI(0); |
115 } | 120 } |
116 | 121 |
117 // Tests PPB_Graphics3D::SwapBuffers(). This test will render a visible | 122 // Tests PPB_Graphics3D::SwapBuffers(). This test will render a visible |
118 // result to the screen -- fading in a solid blue rectangle. | 123 // result to the screen -- fading in a solid blue rectangle. |
119 void TestSwapBuffers() { | 124 void TestSwapBuffers() { |
120 int32_t attribs[] = { | 125 int32_t attribs[] = { |
121 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, | 126 PP_GRAPHICS3DATTRIB_WIDTH, kWidth, |
(...skipping 21 matching lines...) Expand all Loading... |
143 RegisterTest("TestGraphics3DInterface", TestGraphics3DInterface); | 148 RegisterTest("TestGraphics3DInterface", TestGraphics3DInterface); |
144 RegisterTest("TestOpenGLES2Interface", TestOpenGLES2Interface); | 149 RegisterTest("TestOpenGLES2Interface", TestOpenGLES2Interface); |
145 RegisterTest("TestCreate", TestCreate); | 150 RegisterTest("TestCreate", TestCreate); |
146 RegisterTest("TestIsGraphics3D", TestIsGraphics3D); | 151 RegisterTest("TestIsGraphics3D", TestIsGraphics3D); |
147 RegisterTest("TestSwapBuffers", TestSwapBuffers); | 152 RegisterTest("TestSwapBuffers", TestSwapBuffers); |
148 } | 153 } |
149 | 154 |
150 void SetupPluginInterfaces() { | 155 void SetupPluginInterfaces() { |
151 // none | 156 // none |
152 } | 157 } |
OLD | NEW |