| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 <GLES3/gl3.h> | 8 #include <GLES3/gl3.h> |
| 9 #include <stdint.h> |
| 9 | 10 |
| 10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "gpu/command_buffer/service/gpu_switches.h" | 13 #include "gpu/command_buffer/service/gpu_switches.h" |
| 13 #include "gpu/command_buffer/tests/gl_manager.h" | 14 #include "gpu/command_buffer/tests/gl_manager.h" |
| 14 #include "gpu/command_buffer/tests/gl_test_utils.h" | 15 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/gl/gl_switches.h" | 18 #include "ui/gl/gl_switches.h" |
| 18 | 19 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 37 if (factor == GL_ONE_MINUS_SRC1_ALPHA_EXT) | 38 if (factor == GL_ONE_MINUS_SRC1_ALPHA_EXT) |
| 38 return 1.0f - src1[3]; | 39 return 1.0f - src1[3]; |
| 39 return 0.0f; | 40 return 0.0f; |
| 40 } | 41 } |
| 41 | 42 |
| 42 // Implementation of GLES 2 blend equation that is dual-source aware. | 43 // Implementation of GLES 2 blend equation that is dual-source aware. |
| 43 template <int RGBs, int RGBd, int As, int Ad> | 44 template <int RGBs, int RGBd, int As, int Ad> |
| 44 void BlendEquationFuncAdd(float dst[4], | 45 void BlendEquationFuncAdd(float dst[4], |
| 45 float src[4], | 46 float src[4], |
| 46 float src1[4], | 47 float src1[4], |
| 47 uint8 result[4]) { | 48 uint8_t result[4]) { |
| 48 float r[4]; | 49 float r[4]; |
| 49 r[0] = src[0] * Weight<RGBs, 0>(dst, src, src1) + | 50 r[0] = src[0] * Weight<RGBs, 0>(dst, src, src1) + |
| 50 dst[0] * Weight<RGBd, 0>(dst, src, src1); | 51 dst[0] * Weight<RGBd, 0>(dst, src, src1); |
| 51 r[1] = src[1] * Weight<RGBs, 1>(dst, src, src1) + | 52 r[1] = src[1] * Weight<RGBs, 1>(dst, src, src1) + |
| 52 dst[1] * Weight<RGBd, 1>(dst, src, src1); | 53 dst[1] * Weight<RGBd, 1>(dst, src, src1); |
| 53 r[2] = src[2] * Weight<RGBs, 2>(dst, src, src1) + | 54 r[2] = src[2] * Weight<RGBs, 2>(dst, src, src1) + |
| 54 dst[2] * Weight<RGBd, 2>(dst, src, src1); | 55 dst[2] * Weight<RGBd, 2>(dst, src, src1); |
| 55 r[3] = src[3] * Weight<As, 3>(dst, src, src1) + | 56 r[3] = src[3] * Weight<As, 3>(dst, src, src1) + |
| 56 dst[3] * Weight<Ad, 3>(dst, src, src1); | 57 dst[3] * Weight<Ad, 3>(dst, src, src1); |
| 57 for (int i = 0; i < 4; ++i) { | 58 for (int i = 0; i < 4; ++i) { |
| 58 result[i] = static_cast<uint8>( | 59 result[i] = static_cast<uint8_t>( |
| 59 std::floor(std::max(0.0f, std::min(1.0f, r[i])) * 255.0f)); | 60 std::floor(std::max(0.0f, std::min(1.0f, r[i])) * 255.0f)); |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 } // namespace | 64 } // namespace |
| 64 | 65 |
| 65 namespace gpu { | 66 namespace gpu { |
| 66 | 67 |
| 67 class EXTBlendFuncExtendedTest : public testing::Test { | 68 class EXTBlendFuncExtendedTest : public testing::Test { |
| 68 public: | 69 public: |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 GL_ONE_MINUS_SRC1_ALPHA_EXT); | 174 GL_ONE_MINUS_SRC1_ALPHA_EXT); |
| 174 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 175 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 175 | 176 |
| 176 // Draw one triangle (bottom left half). | 177 // Draw one triangle (bottom left half). |
| 177 glViewport(0, 0, kWidth, kHeight); | 178 glViewport(0, 0, kWidth, kHeight); |
| 178 glClearColor(kDst[0], kDst[1], kDst[2], kDst[3]); | 179 glClearColor(kDst[0], kDst[1], kDst[2], kDst[3]); |
| 179 glClear(GL_COLOR_BUFFER_BIT); | 180 glClear(GL_COLOR_BUFFER_BIT); |
| 180 glDrawArrays(GL_TRIANGLES, 0, 6); | 181 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 181 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 182 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 182 // Verify. | 183 // Verify. |
| 183 uint8 color[4]; | 184 uint8_t color[4]; |
| 184 BlendEquationFuncAdd<GL_SRC1_COLOR_EXT, GL_SRC_ALPHA, | 185 BlendEquationFuncAdd<GL_SRC1_COLOR_EXT, GL_SRC_ALPHA, |
| 185 GL_ONE_MINUS_SRC1_COLOR_EXT, | 186 GL_ONE_MINUS_SRC1_COLOR_EXT, |
| 186 GL_ONE_MINUS_SRC1_ALPHA_EXT>(kDst, kSrc, kSrc1, color); | 187 GL_ONE_MINUS_SRC1_ALPHA_EXT>(kDst, kSrc, kSrc1, color); |
| 187 | 188 |
| 188 EXPECT_TRUE(GLTestHelper::CheckPixels(kWidth / 4, (3 * kHeight) / 4, 1, 1, | 189 EXPECT_TRUE(GLTestHelper::CheckPixels(kWidth / 4, (3 * kHeight) / 4, 1, 1, |
| 189 1, color)); | 190 1, color)); |
| 190 EXPECT_TRUE(GLTestHelper::CheckPixels(kWidth - 1, 0, 1, 1, 1, color)); | 191 EXPECT_TRUE(GLTestHelper::CheckPixels(kWidth - 1, 0, 1, 1, 1, color)); |
| 191 } | 192 } |
| 192 | 193 |
| 193 protected: | 194 protected: |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 | 645 |
| 645 INSTANTIATE_TEST_CASE_P(TranslatorVariants, | 646 INSTANTIATE_TEST_CASE_P(TranslatorVariants, |
| 646 EXTBlendFuncExtendedDrawTest, | 647 EXTBlendFuncExtendedDrawTest, |
| 647 ::testing::Bool()); | 648 ::testing::Bool()); |
| 648 | 649 |
| 649 INSTANTIATE_TEST_CASE_P(TranslatorVariants, | 650 INSTANTIATE_TEST_CASE_P(TranslatorVariants, |
| 650 EXTBlendFuncExtendedES3DrawTest, | 651 EXTBlendFuncExtendedES3DrawTest, |
| 651 ::testing::Bool()); | 652 ::testing::Bool()); |
| 652 | 653 |
| 653 } // namespace gpu | 654 } // namespace gpu |
| OLD | NEW |