Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include <GLES2/gl2.h> | |
| 6 #include <GLES2/gl2ext.h> | |
| 7 #include <GLES2/gl2extchromium.h> | |
| 8 | |
| 9 #include "gpu/command_buffer/tests/gl_manager.h" | |
| 10 #include "gpu/command_buffer/tests/gl_test_utils.h" | |
| 11 #include "testing/gmock/include/gmock/gmock.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace gpu { | |
| 15 | |
| 16 class CHROMIUMPathRenderingTest : public testing::Test { | |
| 17 public: | |
| 18 static const GLsizei kResolution = 100; | |
| 19 | |
| 20 protected: | |
| 21 virtual void SetUp() { | |
| 22 GLManager::Options options; | |
| 23 options.size = gfx::Size(kResolution, kResolution); | |
| 24 gl_.Initialize(options); | |
| 25 } | |
| 26 | |
| 27 virtual void TearDown() { | |
| 28 gl_.Destroy(); | |
| 29 } | |
| 30 | |
| 31 template<typename T> | |
| 32 void AssertEqualMatrix(const GLfloat* expected, const T* actual) { | |
| 33 for (size_t i = 0; i < 16; ++i) { | |
| 34 ASSERT_EQ(static_cast<T>(expected[i]), actual[i]); | |
|
vmiura
2014/04/15 18:02:43
nit: EXPECT_EQ instead of ASSERT_EQ?
Kimmo Kinnunen
2014/04/23 12:26:55
Done.
| |
| 35 } | |
| 36 } | |
| 37 GLManager gl_; | |
| 38 }; | |
| 39 | |
| 40 TEST_F(CHROMIUMPathRenderingTest, TestMatrix) { | |
| 41 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { | |
| 42 return; | |
| 43 } | |
| 44 GLfloat identity_matrix[16] = { | |
| 45 1.0f, 0.0f, 0.0f, 0.0f, | |
| 46 0.0f, 1.0f, 0.0f, 0.0f, | |
| 47 0.0f, 0.0f, 1.0f, 0.0f, | |
| 48 0.0f, 0.0f, 0.0f, 1.0f | |
| 49 }; | |
| 50 GLfloat seq_matrix[16] = { | |
| 51 0.0f, 1.0f, 2.0f, 3.0f, | |
| 52 4.0f, 5.0f, 6.0f, 7.0f, | |
| 53 8.0f, 9.0f, 10.0f, 11.0f, | |
| 54 12.0f, 13.0f, 14.0f, 15.0f | |
| 55 }; | |
| 56 GLenum matrix_modes[] = { | |
| 57 GL_MODELVIEW_CHROMIUM, GL_PROJECTION_CHROMIUM | |
| 58 }; | |
| 59 GLenum get_matrix_modes[] = { | |
| 60 GL_MODELVIEW_MATRIX_CHROMIUM, GL_PROJECTION_MATRIX_CHROMIUM | |
| 61 }; | |
| 62 | |
| 63 for (size_t i = 0; i < arraysize(matrix_modes); ++i) { | |
| 64 GLfloat mf[16]; | |
| 65 GLint mi[16]; | |
| 66 memset(mf, 0, sizeof(mf)); | |
| 67 memset(mi, 0, sizeof(mi)); | |
| 68 glGetFloatv(get_matrix_modes[i], mf); | |
| 69 glMatrixLoadIdentityCHROMIUM(matrix_modes[i]); | |
| 70 glGetFloatv(get_matrix_modes[i], mf); | |
| 71 glGetIntegerv(get_matrix_modes[i], mi); | |
| 72 AssertEqualMatrix(identity_matrix, mf); | |
| 73 AssertEqualMatrix(identity_matrix, mi); | |
| 74 | |
| 75 memset(mf, 0, sizeof(mf)); | |
| 76 memset(mi, 0, sizeof(mi)); | |
| 77 glMatrixLoadfCHROMIUM(matrix_modes[i], seq_matrix); | |
| 78 glGetFloatv(get_matrix_modes[i], mf); | |
| 79 glGetIntegerv(get_matrix_modes[i], mi); | |
| 80 AssertEqualMatrix(seq_matrix, mf); | |
| 81 AssertEqualMatrix(seq_matrix, mi); | |
| 82 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 TEST_F(CHROMIUMPathRenderingTest, TestMatrixErrors) { | |
| 87 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { | |
| 88 return; | |
| 89 } | |
| 90 GLfloat mf[16]; | |
| 91 memset(mf, 0, sizeof(mf)); | |
| 92 | |
| 93 // This should fail. | |
| 94 glMatrixLoadfCHROMIUM(GL_MODELVIEW_CHROMIUM - 1, mf); | |
| 95 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); | |
| 96 | |
| 97 glMatrixLoadfCHROMIUM(GL_MODELVIEW_CHROMIUM, mf); | |
| 98 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 99 | |
| 100 // This should fail. | |
| 101 glMatrixLoadIdentityCHROMIUM(GL_PROJECTION_CHROMIUM + 1); | |
| 102 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); | |
| 103 | |
| 104 glMatrixLoadIdentityCHROMIUM(GL_PROJECTION_CHROMIUM); | |
| 105 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 106 } | |
| 107 | |
| 108 } // namespace gpu | |
| OLD | NEW |