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

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 "ppapi/c/dev/ppb_graphics_3d_dev.h" 7 #include <GLES2/gl2.h>
8
8 #include "ppapi/c/dev/ppb_opengles_dev.h" 9 #include "ppapi/c/dev/ppb_opengles_dev.h"
10 #include "ppapi/c/dev/ppb_testing_dev.h"
11 #include "ppapi/cpp/dev/graphics_3d_dev.h"
9 #include "ppapi/cpp/module.h" 12 #include "ppapi/cpp/module.h"
13 #include "ppapi/tests/test_utils.h"
14 #include "ppapi/tests/testing_instance.h"
10 15
11 REGISTER_TEST_CASE(Graphics3D); 16 REGISTER_TEST_CASE(Graphics3D);
12 17
13 bool TestGraphics3D::Init() { 18 bool TestGraphics3D::Init() {
14 graphics_3d_ = reinterpret_cast<const PPB_Graphics3D_Dev*>(
15 pp::Module::Get()->GetBrowserInterface(PPB_GRAPHICS_3D_DEV_INTERFACE));
16 opengl_es2_ = reinterpret_cast<const PPB_OpenGLES2_Dev*>( 19 opengl_es2_ = reinterpret_cast<const PPB_OpenGLES2_Dev*>(
17 pp::Module::Get()->GetBrowserInterface(PPB_OPENGLES2_DEV_INTERFACE)); 20 pp::Module::Get()->GetBrowserInterface(PPB_OPENGLES2_DEV_INTERFACE));
18 return graphics_3d_ && opengl_es2_ && InitTestingInterface(); 21 return opengl_es2_ && InitTestingInterface();
19 } 22 }
20 23
21 void TestGraphics3D::RunTest() { 24 void TestGraphics3D::RunTest() {
25 RUN_TEST(Frame);
22 } 26 }
23 27
28 std::string TestGraphics3D::TestFrame() {
29 const int width = 16;
30 const int height = 16;
31 const int32_t attribs[] = {
32 PP_GRAPHICS3DATTRIB_WIDTH, width,
33 PP_GRAPHICS3DATTRIB_HEIGHT, height,
34 PP_GRAPHICS3DATTRIB_NONE
35 };
36 pp::Graphics3D_Dev context(*instance_, pp::Graphics3D_Dev(), attribs);
37 ASSERT_FALSE(context.is_null());
38
39 // Clear color buffer to opaque red.
40 opengl_es2_->ClearColor(context.pp_resource(), 1.0f, 0.0f, 0.0f, 1.0f);
41 opengl_es2_->Clear(context.pp_resource(), GL_COLOR_BUFFER_BIT);
42 // Check if the color buffer has opaque red.
43 const uint8_t red_color[4] = {255, 0, 0, 255};
44 std::string error = TestPixel(&context, width/2, height/2, red_color);
45 if (!error.empty())
46 return error;
47
48 int32_t rv = SwapBuffersSync(&context);
49 ASSERT_EQ(rv, PP_OK);
50 PASS();
51 }
52
53 int32_t TestGraphics3D::SwapBuffersSync(pp::Graphics3D_Dev* context) {
54 TestCompletionCallback callback(instance_->pp_instance(), true);
55 int32_t rv = context->SwapBuffers(callback);
56 if (rv != PP_OK_COMPLETIONPENDING)
57 return rv;
58
59 return callback.WaitForResult();
60 }
61
62 std::string TestGraphics3D::TestPixel(
63 pp::Graphics3D_Dev* context,
64 int x, int y, const uint8_t expected_color[4]) {
65 GLubyte pixel_color[4];
66 opengl_es2_->ReadPixels(context->pp_resource(),
67 x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel_color);
68
69 ASSERT_EQ(pixel_color[0], expected_color[0]);
70 ASSERT_EQ(pixel_color[1], expected_color[1]);
71 ASSERT_EQ(pixel_color[2], expected_color[2]);
72 ASSERT_EQ(pixel_color[3], expected_color[3]);
73 PASS();
74 }
75
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