Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Side by Side Diff: ppapi/native_client/tests/ppapi_browser/ppb_graphics3d/ppapi_ppb_graphics3d.cc

Issue 7740013: Cloning a bunch of stuff from the native_client repository at r6528 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/internal_utils.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"
20 #include "ppapi/c/dev/ppb_testing_dev.h"
21 #include "ppapi/c/pp_bool.h"
22 #include "ppapi/c/pp_completion_callback.h"
23 #include "ppapi/c/pp_errors.h"
24 #include "ppapi/c/pp_point.h"
25 #include "ppapi/c/pp_rect.h"
26 #include "ppapi/c/pp_size.h"
27 #include "ppapi/c/ppb_core.h"
28 #include "ppapi/c/ppb_image_data.h"
29 #include "ppapi/c/ppb_instance.h"
30 #include "ppapi/c/ppb_url_loader.h"
31 #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h"
32
33 namespace {
34
35 const int kWidth = 320;
36 const int kHeight = 200;
37
38 ////////////////////////////////////////////////////////////////////////////////
39 // Test Cases
40 ////////////////////////////////////////////////////////////////////////////////
41
42 // Tests the Graphics3D interface is available.
43 void TestGraphics3DInterface() {
44 EXPECT(PPBGraphics3DDev() != NULL);
45 TEST_PASSED;
46 }
47
48 // Tests the OpenGLES interface is available.
49 void TestOpenGLES2Interface() {
50 EXPECT(PPBOpenGLES2Dev() != NULL);
51 TEST_PASSED;
52 }
53
54 // Tests PPB_Graphics3D::Create().
55 void TestCreate() {
56 int32_t attribs[] = {
57 PP_GRAPHICS3DATTRIB_WIDTH, kWidth,
58 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight,
59 PP_GRAPHICS3DATTRIB_NONE};
60 PP_Resource graphics3d_id = PPBGraphics3DDev()->
61 Create(pp_instance(), kInvalidResource, attribs);
62 EXPECT(graphics3d_id != kInvalidResource);
63 PP_Resource invalid_graphics3d_id = PPBGraphics3DDev()->
64 Create(0, kInvalidResource, attribs);
65 EXPECT(invalid_graphics3d_id == kInvalidResource);
66 int32_t empty_attribs[] = {
67 PP_GRAPHICS3DATTRIB_NONE};
68 PP_Resource graphics3d_empty_attrib_id = PPBGraphics3DDev()->
69 Create(pp_instance(), kInvalidResource, empty_attribs);
70 EXPECT(graphics3d_empty_attrib_id != kInvalidResource);
71 PP_Resource graphics3d_null_attrib_id = PPBGraphics3DDev()->
72 Create(pp_instance(), kInvalidResource, NULL);
73 EXPECT(graphics3d_null_attrib_id != kInvalidResource);
74 TEST_PASSED;
75 }
76
77 // Tests PPB_Graphics3D::IsGraphics3D().
78 void TestIsGraphics3D() {
79 int32_t attribs[] = {
80 PP_GRAPHICS3DATTRIB_WIDTH, kWidth,
81 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight,
82 PP_GRAPHICS3DATTRIB_NONE};
83 PP_Resource graphics3d_id = PPBGraphics3DDev()->
84 Create(pp_instance(), kInvalidResource, attribs);
85 EXPECT(graphics3d_id != kInvalidResource);
86 EXPECT(PPBGraphics3DDev()->IsGraphics3D(graphics3d_id) == PP_TRUE);
87 TEST_PASSED;
88 }
89
90 struct RenderInfo {
91 PP_Resource graphics3d_id;
92 int32_t frame_counter;
93 int32_t frame_end;
94 };
95
96 void SwapCallback(void* user_data, int32_t result) {
97 EXPECT(result == PP_OK);
98 RenderInfo* info = static_cast<RenderInfo *>(user_data);
99 // Set graphics3d_id to the main context, so we can use normal gl style calls
100 // instead of going through the PPAPI PPBOpenGLES2 interface.
101 glSetCurrentContextPPAPI(info->graphics3d_id);
102 glViewport(0, 0, kWidth, kHeight);
103 float blue = float(info->frame_counter) / float(info->frame_end);
104 glClearColor(0.0f, 0.0f, blue, 1.0f);
105 glClear(GL_COLOR_BUFFER_BIT);
106 ++info->frame_counter;
107 if (info->frame_counter < info->frame_end) {
108 PP_CompletionCallback cc = PP_MakeCompletionCallback(SwapCallback, info);
109 int32_t result = PPBGraphics3DDev()->SwapBuffers(info->graphics3d_id, cc);
110 CHECK(PP_OK_COMPLETIONPENDING == result);
111 } else {
112 delete info;
113 }
114 glSetCurrentContextPPAPI(0);
115 }
116
117 // Tests PPB_Graphics3D::SwapBuffers(). This test will render a visible
118 // result to the screen -- fading in a solid blue rectangle.
119 void TestSwapBuffers() {
120 int32_t attribs[] = {
121 PP_GRAPHICS3DATTRIB_WIDTH, kWidth,
122 PP_GRAPHICS3DATTRIB_HEIGHT, kHeight,
123 PP_GRAPHICS3DATTRIB_NONE};
124 PP_Resource graphics3d_id = PPBGraphics3DDev()->
125 Create(pp_instance(), kInvalidResource, attribs);
126 EXPECT(graphics3d_id != kInvalidResource);
127 int32_t success = PPBInstance()->BindGraphics(pp_instance(), graphics3d_id);
128 EXPECT(success == PP_TRUE);
129 RenderInfo* render_info = new RenderInfo;
130 render_info->graphics3d_id = graphics3d_id;
131 render_info->frame_counter = 0;
132 render_info->frame_end = 256;
133 glInitializePPAPI(ppb_get_interface());
134 PP_CompletionCallback cc = MakeTestableCompletionCallback(
135 "SwapBufferCallback", SwapCallback, render_info);
136 PPBCore()->CallOnMainThread(0, cc, PP_OK);
137 TEST_PASSED;
138 }
139
140 } // namespace
141
142 void SetupTests() {
143 RegisterTest("TestGraphics3DInterface", TestGraphics3DInterface);
144 RegisterTest("TestOpenGLES2Interface", TestOpenGLES2Interface);
145 RegisterTest("TestCreate", TestCreate);
146 RegisterTest("TestIsGraphics3D", TestIsGraphics3D);
147 RegisterTest("TestSwapBuffers", TestSwapBuffers);
148 }
149
150 void SetupPluginInterfaces() {
151 // none
152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698