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
3 // found in the LICENSE file.
5 #include "ppapi/tests/test_graphics_3d.h"
9 #include "ppapi/c/dev/ppb_testing_dev.h"
10 #include "ppapi/c/ppb_opengles2.h"
11 #include "ppapi/cpp/graphics_3d.h"
12 #include "ppapi/cpp/module.h"
13 #include "ppapi/tests/test_utils.h"
14 #include "ppapi/tests/testing_instance.h"
16 REGISTER_TEST_CASE(Graphics3D
);
18 bool TestGraphics3D::Init() {
19 opengl_es2_
= reinterpret_cast<const PPB_OpenGLES2
*>(
20 pp::Module::Get()->GetBrowserInterface(PPB_OPENGLES2_INTERFACE
));
21 return opengl_es2_
&& InitTestingInterface();
24 void TestGraphics3D::RunTest() {
28 std::string
TestGraphics3D::TestFrame() {
30 const int height
= 16;
31 const int32_t attribs
[] = {
32 PP_GRAPHICS3DATTRIB_WIDTH
, width
,
33 PP_GRAPHICS3DATTRIB_HEIGHT
, height
,
34 PP_GRAPHICS3DATTRIB_NONE
36 pp::Graphics3D
context(instance_
, attribs
);
37 ASSERT_FALSE(context
.is_null());
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
);
48 int32_t rv
= SwapBuffersSync(&context
);
53 int32_t TestGraphics3D::SwapBuffersSync(pp::Graphics3D
* context
) {
54 TestCompletionCallback
callback(instance_
->pp_instance(), true);
55 int32_t rv
= context
->SwapBuffers(callback
);
56 if (rv
!= PP_OK_COMPLETIONPENDING
)
59 return callback
.WaitForResult();
62 std::string
TestGraphics3D::TestPixel(
63 pp::Graphics3D
* 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
);
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]);