| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
| 6 #include <GLES2/gl2ext.h> | 6 #include <GLES2/gl2ext.h> |
| 7 #include <GLES2/gl2extchromium.h> | 7 #include <GLES2/gl2extchromium.h> |
| 8 #include <stdint.h> |
| 8 | 9 |
| 9 #include "gpu/command_buffer/tests/gl_manager.h" | 10 #include "gpu/command_buffer/tests/gl_manager.h" |
| 10 #include "gpu/command_buffer/tests/gl_test_utils.h" | 11 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 #define SHADER(Src) #Src | 15 #define SHADER(Src) #Src |
| 15 | 16 |
| 16 namespace gpu { | 17 namespace gpu { |
| 17 | 18 |
| 18 class GLVirtualContextsTest : public testing::Test { | 19 class GLVirtualContextsTest : public testing::Test { |
| 19 protected: | 20 protected: |
| 20 static const int kSize0 = 4; | 21 static const int kSize0 = 4; |
| 21 static const int kSize1 = 8; | 22 static const int kSize1 = 8; |
| 22 static const int kSize2 = 16; | 23 static const int kSize2 = 16; |
| 23 | 24 |
| 24 static const GLfloat kFloatRed[4]; | 25 static const GLfloat kFloatRed[4]; |
| 25 static const GLfloat kFloatGreen[4]; | 26 static const GLfloat kFloatGreen[4]; |
| 26 static const uint8 kExpectedRed[4]; | 27 static const uint8_t kExpectedRed[4]; |
| 27 static const uint8 kExpectedGreen[4]; | 28 static const uint8_t kExpectedGreen[4]; |
| 28 | 29 |
| 29 void SetUp() override { | 30 void SetUp() override { |
| 30 GLManager::Options options; | 31 GLManager::Options options; |
| 31 options.size = gfx::Size(kSize0, kSize0); | 32 options.size = gfx::Size(kSize0, kSize0); |
| 32 gl_real_.Initialize(options); | 33 gl_real_.Initialize(options); |
| 33 gl_real_shared_.Initialize(options); | 34 gl_real_shared_.Initialize(options); |
| 34 options.virtual_manager = &gl_real_shared_; | 35 options.virtual_manager = &gl_real_shared_; |
| 35 options.size = gfx::Size(kSize1, kSize1); | 36 options.size = gfx::Size(kSize1, kSize1); |
| 36 gl1_.Initialize(options); | 37 gl1_.Initialize(options); |
| 37 options.size = gfx::Size(kSize2, kSize2); | 38 options.size = gfx::Size(kSize2, kSize2); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 GLManager gl1_; | 85 GLManager gl1_; |
| 85 GLManager gl2_; | 86 GLManager gl2_; |
| 86 }; | 87 }; |
| 87 | 88 |
| 88 const GLfloat GLVirtualContextsTest::kFloatRed[4] = { | 89 const GLfloat GLVirtualContextsTest::kFloatRed[4] = { |
| 89 1.0f, 0.0f, 0.0f, 1.0f, | 90 1.0f, 0.0f, 0.0f, 1.0f, |
| 90 }; | 91 }; |
| 91 const GLfloat GLVirtualContextsTest::kFloatGreen[4] = { | 92 const GLfloat GLVirtualContextsTest::kFloatGreen[4] = { |
| 92 0.0f, 1.0f, 0.0f, 1.0f, | 93 0.0f, 1.0f, 0.0f, 1.0f, |
| 93 }; | 94 }; |
| 94 const uint8 GLVirtualContextsTest::kExpectedRed[4] = { | 95 const uint8_t GLVirtualContextsTest::kExpectedRed[4] = { |
| 95 255, 0, 0, 255, | 96 255, 0, 0, 255, |
| 96 }; | 97 }; |
| 97 const uint8 GLVirtualContextsTest::kExpectedGreen[4] = { | 98 const uint8_t GLVirtualContextsTest::kExpectedGreen[4] = { |
| 98 0, 255, 0, 255, | 99 0, 255, 0, 255, |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 namespace { | 102 namespace { |
| 102 | 103 |
| 103 void SetupSimpleShader(const uint8* color) { | 104 void SetupSimpleShader(const uint8_t* color) { |
| 104 static const char* v_shader_str = SHADER( | 105 static const char* v_shader_str = SHADER( |
| 105 attribute vec4 a_Position; | 106 attribute vec4 a_Position; |
| 106 void main() | 107 void main() |
| 107 { | 108 { |
| 108 gl_Position = a_Position; | 109 gl_Position = a_Position; |
| 109 } | 110 } |
| 110 ); | 111 ); |
| 111 | 112 |
| 112 static const char* f_shader_str = SHADER( | 113 static const char* f_shader_str = SHADER( |
| 113 precision mediump float; | 114 precision mediump float; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 128 GLuint color_loc = glGetUniformLocation(program, "u_color"); | 129 GLuint color_loc = glGetUniformLocation(program, "u_color"); |
| 129 glUniform4f( | 130 glUniform4f( |
| 130 color_loc, | 131 color_loc, |
| 131 color[0] / 255.0f, | 132 color[0] / 255.0f, |
| 132 color[1] / 255.0f, | 133 color[1] / 255.0f, |
| 133 color[2] / 255.0f, | 134 color[2] / 255.0f, |
| 134 color[3] / 255.0f); | 135 color[3] / 255.0f); |
| 135 } | 136 } |
| 136 | 137 |
| 137 void TestDraw(int size) { | 138 void TestDraw(int size) { |
| 138 uint8 expected_clear[] = { 127, 0, 255, 0, }; | 139 uint8_t expected_clear[] = { |
| 140 127, 0, 255, 0, |
| 141 }; |
| 139 glClearColor(0.5f, 0.0f, 1.0f, 0.0f); | 142 glClearColor(0.5f, 0.0f, 1.0f, 0.0f); |
| 140 glClear(GL_COLOR_BUFFER_BIT); | 143 glClear(GL_COLOR_BUFFER_BIT); |
| 141 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, size, size, 1, expected_clear)); | 144 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, size, size, 1, expected_clear)); |
| 142 glDrawArrays(GL_TRIANGLES, 0, 6); | 145 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 143 } | 146 } |
| 144 | 147 |
| 145 } // anonymous namespace | 148 } // anonymous namespace |
| 146 | 149 |
| 147 // http://crbug.com/281565 | 150 // http://crbug.com/281565 |
| 148 TEST_F(GLVirtualContextsTest, Basic) { | 151 TEST_F(GLVirtualContextsTest, Basic) { |
| 149 struct TestInfo { | 152 struct TestInfo { |
| 150 int size; | 153 int size; |
| 151 uint8 color[4]; | 154 uint8_t color[4]; |
| 152 GLManager* manager; | 155 GLManager* manager; |
| 153 }; | 156 }; |
| 154 const int kNumTests = 3; | 157 const int kNumTests = 3; |
| 155 TestInfo tests[] = { | 158 TestInfo tests[] = { |
| 156 { kSize0, { 255, 0, 0, 0, }, &gl_real_, }, | 159 { kSize0, { 255, 0, 0, 0, }, &gl_real_, }, |
| 157 { kSize1, { 0, 255, 0, 0, }, &gl1_, }, | 160 { kSize1, { 0, 255, 0, 0, }, &gl1_, }, |
| 158 { kSize2, { 0, 0, 255, 0, }, &gl2_, }, | 161 { kSize2, { 0, 0, 255, 0, }, &gl2_, }, |
| 159 }; | 162 }; |
| 160 | 163 |
| 161 for (int ii = 0; ii < kNumTests; ++ii) { | 164 for (int ii = 0; ii < kNumTests; ++ii) { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 &query2_available); | 356 &query2_available); |
| 354 EXPECT_TRUE(query2_available); | 357 EXPECT_TRUE(query2_available); |
| 355 | 358 |
| 356 glDeleteQueriesEXT(1, &query2); | 359 glDeleteQueriesEXT(1, &query2); |
| 357 GLTestHelper::CheckGLError("no errors", __LINE__); | 360 GLTestHelper::CheckGLError("no errors", __LINE__); |
| 358 } | 361 } |
| 359 } | 362 } |
| 360 | 363 |
| 361 } // namespace gpu | 364 } // namespace gpu |
| 362 | 365 |
| OLD | NEW |