1 // Copyright (c) 2012 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.
6 #include <GLES2/gl2ext.h>
7 #include <GLES2/gl2extchromium.h>
10 #include "gpu/command_buffer/tests/gl_manager.h"
11 #include "gpu/command_buffer/tests/gl_test_utils.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
17 class CHROMIUMPathRenderingTest
: public testing::Test
{
19 static const GLsizei kResolution
= 100;
22 void SetUp() override
{
23 GLManager::Options options
;
24 options
.size
= gfx::Size(kResolution
, kResolution
);
25 gl_
.Initialize(options
);
28 void TearDown() override
{ gl_
.Destroy(); }
30 void ExpectEqualMatrix(const GLfloat
* expected
, const GLfloat
* actual
) {
31 for (size_t i
= 0; i
< 16; ++i
) {
32 EXPECT_EQ(expected
[i
], actual
[i
]);
35 void ExpectEqualMatrix(const GLfloat
* expected
, const GLint
* actual
) {
36 for (size_t i
= 0; i
< 16; ++i
) {
37 EXPECT_EQ(static_cast<GLint
>(round(expected
[i
])), actual
[i
]);
43 TEST_F(CHROMIUMPathRenderingTest
, TestMatrix
) {
44 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
47 static const GLfloat kIdentityMatrix
[16] = {
48 1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
,
49 0.0f
, 0.0f
, 1.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1.0f
};
50 static const GLfloat kSeqMatrix
[16] = {
51 0.5f
, -0.5f
, -0.1f
, -0.8f
, 4.4f
, 5.5f
, 6.6f
, 7.7f
,
52 8.8f
, 9.9f
, 10.11f
, 11.22f
, 12.33f
, 13.44f
, 14.55f
, 15.66f
};
53 static const GLenum kMatrixModes
[] = {GL_PATH_MODELVIEW_CHROMIUM
,
54 GL_PATH_PROJECTION_CHROMIUM
};
55 static const GLenum kGetMatrixModes
[] = {GL_PATH_MODELVIEW_MATRIX_CHROMIUM
,
56 GL_PATH_PROJECTION_MATRIX_CHROMIUM
};
58 for (size_t i
= 0; i
< arraysize(kMatrixModes
); ++i
) {
61 memset(mf
, 0, sizeof(mf
));
62 memset(mi
, 0, sizeof(mi
));
63 glGetFloatv(kGetMatrixModes
[i
], mf
);
64 glGetIntegerv(kGetMatrixModes
[i
], mi
);
65 ExpectEqualMatrix(kIdentityMatrix
, mf
);
66 ExpectEqualMatrix(kIdentityMatrix
, mi
);
68 glMatrixLoadfCHROMIUM(kMatrixModes
[i
], kSeqMatrix
);
69 memset(mf
, 0, sizeof(mf
));
70 memset(mi
, 0, sizeof(mi
));
71 glGetFloatv(kGetMatrixModes
[i
], mf
);
72 glGetIntegerv(kGetMatrixModes
[i
], mi
);
73 ExpectEqualMatrix(kSeqMatrix
, mf
);
74 ExpectEqualMatrix(kSeqMatrix
, mi
);
76 glMatrixLoadIdentityCHROMIUM(kMatrixModes
[i
]);
77 memset(mf
, 0, sizeof(mf
));
78 memset(mi
, 0, sizeof(mi
));
79 glGetFloatv(kGetMatrixModes
[i
], mf
);
80 glGetIntegerv(kGetMatrixModes
[i
], mi
);
81 ExpectEqualMatrix(kIdentityMatrix
, mf
);
82 ExpectEqualMatrix(kIdentityMatrix
, mi
);
84 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
88 TEST_F(CHROMIUMPathRenderingTest
, TestMatrixErrors
) {
89 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
93 memset(mf
, 0, sizeof(mf
));
96 glMatrixLoadfCHROMIUM(GL_PATH_MODELVIEW_CHROMIUM
- 1, mf
);
97 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_ENUM
), glGetError());
99 glMatrixLoadfCHROMIUM(GL_PATH_MODELVIEW_CHROMIUM
, mf
);
100 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
103 glMatrixLoadIdentityCHROMIUM(GL_PATH_PROJECTION_CHROMIUM
+ 1);
104 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_ENUM
), glGetError());
106 glMatrixLoadIdentityCHROMIUM(GL_PATH_PROJECTION_CHROMIUM
);
107 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());