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 #include <cmath> |
| 9 |
| 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" |
| 14 |
| 15 namespace gpu { |
| 16 |
| 17 class CHROMIUMPathRenderingTest : public testing::Test { |
| 18 public: |
| 19 static const GLsizei kResolution = 100; |
| 20 |
| 21 protected: |
| 22 virtual void SetUp() { |
| 23 GLManager::Options options; |
| 24 options.size = gfx::Size(kResolution, kResolution); |
| 25 gl_.Initialize(options); |
| 26 } |
| 27 |
| 28 virtual void TearDown() { gl_.Destroy(); } |
| 29 |
| 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]); |
| 33 } |
| 34 } |
| 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]); |
| 38 } |
| 39 } |
| 40 GLManager gl_; |
| 41 }; |
| 42 |
| 43 TEST_F(CHROMIUMPathRenderingTest, TestMatrix) { |
| 44 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { |
| 45 return; |
| 46 } |
| 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}; |
| 57 |
| 58 for (size_t i = 0; i < arraysize(kMatrixModes); ++i) { |
| 59 GLfloat mf[16]; |
| 60 GLint mi[16]; |
| 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); |
| 67 |
| 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); |
| 75 |
| 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); |
| 83 |
| 84 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 85 } |
| 86 } |
| 87 |
| 88 TEST_F(CHROMIUMPathRenderingTest, TestMatrixErrors) { |
| 89 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { |
| 90 return; |
| 91 } |
| 92 GLfloat mf[16]; |
| 93 memset(mf, 0, sizeof(mf)); |
| 94 |
| 95 // This should fail. |
| 96 glMatrixLoadfCHROMIUM(GL_PATH_MODELVIEW_CHROMIUM - 1, mf); |
| 97 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); |
| 98 |
| 99 glMatrixLoadfCHROMIUM(GL_PATH_MODELVIEW_CHROMIUM, mf); |
| 100 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 101 |
| 102 // This should fail. |
| 103 glMatrixLoadIdentityCHROMIUM(GL_PATH_PROJECTION_CHROMIUM + 1); |
| 104 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); |
| 105 |
| 106 glMatrixLoadIdentityCHROMIUM(GL_PATH_PROJECTION_CHROMIUM); |
| 107 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 108 } |
| 109 |
| 110 } // namespace gpu |
OLD | NEW |