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

Side by Side Diff: ppapi/tests/test_graphics_3d.cc

Issue 7818004: Added a simple smoke test for Graphics3D. It attempts to exercise the entire graphics-3d pipeline... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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
« no previous file with comments | « ppapi/tests/test_graphics_3d.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ppapi/tests/test_graphics_3d.h" 5 #include "ppapi/tests/test_graphics_3d.h"
6 6
7 #include <GLES2/gl2.h>
8
7 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" 9 #include "ppapi/c/dev/ppb_graphics_3d_dev.h"
8 #include "ppapi/c/dev/ppb_opengles_dev.h" 10 #include "ppapi/c/dev/ppb_opengles_dev.h"
11 #include "ppapi/c/dev/ppb_testing_dev.h"
9 #include "ppapi/cpp/module.h" 12 #include "ppapi/cpp/module.h"
13 #include "ppapi/tests/testing_instance.h"
10 14
11 REGISTER_TEST_CASE(Graphics3D); 15 REGISTER_TEST_CASE(Graphics3D);
12 16
17 namespace {
18
19 struct SwapBuffers {
20 int32_t result;
21 PP_Instance instance;
22 const PPB_Testing_Dev* testing;
23 };
24
25 void SwapBuffersCallback(void* data, int32_t result) {
26 SwapBuffers* swap_buffers = reinterpret_cast<SwapBuffers*>(data);
27 swap_buffers->result = result;
28 swap_buffers->testing->QuitMessageLoop(swap_buffers->instance);
29 }
30
31 } // namespace
32
13 bool TestGraphics3D::Init() { 33 bool TestGraphics3D::Init() {
14 graphics_3d_ = reinterpret_cast<const PPB_Graphics3D_Dev*>( 34 graphics_3d_ = reinterpret_cast<const PPB_Graphics3D_Dev*>(
15 pp::Module::Get()->GetBrowserInterface(PPB_GRAPHICS_3D_DEV_INTERFACE)); 35 pp::Module::Get()->GetBrowserInterface(PPB_GRAPHICS_3D_DEV_INTERFACE));
16 opengl_es2_ = reinterpret_cast<const PPB_OpenGLES2_Dev*>( 36 opengl_es2_ = reinterpret_cast<const PPB_OpenGLES2_Dev*>(
17 pp::Module::Get()->GetBrowserInterface(PPB_OPENGLES2_DEV_INTERFACE)); 37 pp::Module::Get()->GetBrowserInterface(PPB_OPENGLES2_DEV_INTERFACE));
18 return graphics_3d_ && opengl_es2_ && InitTestingInterface(); 38 return graphics_3d_ && opengl_es2_ && InitTestingInterface();
19 } 39 }
20 40
21 void TestGraphics3D::RunTest() { 41 void TestGraphics3D::RunTest() {
42 RUN_TEST(Frame);
22 } 43 }
23 44
45 std::string TestGraphics3D::TestFrame() {
46 const int width = 16;
47 const int height = 16;
48 const int32_t attribs[] = {
49 PP_GRAPHICS3DATTRIB_WIDTH, width,
50 PP_GRAPHICS3DATTRIB_HEIGHT, height,
51 PP_GRAPHICS3DATTRIB_NONE
52 };
53 PP_Resource context =
54 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.
55 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.
56
57 // Clear color buffer to opaque red.
58 opengl_es2_->ClearColor(context, 1.0f, 0.0f, 0.0f, 1.0f);
59 opengl_es2_->Clear(context, GL_COLOR_BUFFER_BIT);
60 int32_t rv = SwapBuffersSync(context);
61 ASSERT_EQ(rv, PP_OK);
62
63 // Check if the color buffer has opaque red.
64 const uint8_t red_color[4] = {255, 0, 0, 255};
65 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.
66
67 pp::Module::Get()->core()->ReleaseResource(context);
68 return error;
69 }
70
71 int32_t TestGraphics3D::SwapBuffersSync(PP_Resource context) {
72 SwapBuffers swap_buffers;
73 swap_buffers.result = PP_OK;
74 swap_buffers.instance = instance_->pp_instance();
75 swap_buffers.testing = testing_interface_;
76
77 int32_t rv = graphics_3d_->SwapBuffers(
78 context,
79 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.
80 if (rv != PP_OK_COMPLETIONPENDING)
81 return rv;
82
83 testing_interface_->RunMessageLoop(instance_->pp_instance());
84 return swap_buffers.result;
85 }
86
87 std::string TestGraphics3D::TestPixel(
88 PP_Resource context,
89 int x, int y, const uint8_t expected_color[4]) {
90 GLubyte pixel_color[4];
91 opengl_es2_->ReadPixels(context,
92 x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel_color);
93
94 ASSERT_EQ(pixel_color[0], expected_color[0]);
95 ASSERT_EQ(pixel_color[1], expected_color[1]);
96 ASSERT_EQ(pixel_color[2], expected_color[2]);
97 ASSERT_EQ(pixel_color[3], expected_color[3]);
98 PASS();
99 }
100
OLDNEW
« no previous file with comments | « ppapi/tests/test_graphics_3d.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698