PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/gpu/command_buffer/tests/es3_misc_functions_unittest.cc

https://gitlab.com/0072016/Facebook-SDK-
C++ | 113 lines | 93 code | 13 blank | 7 comment | 3 complexity | 34181e1925aa56df14e7cfa0ded7b363 MD5 | raw file
  1. // Copyright 2015 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. #include <GLES2/gl2.h>
  5. #include <GLES2/gl2ext.h>
  6. #include <GLES2/gl2extchromium.h>
  7. #include <GLES3/gl3.h>
  8. #include "base/command_line.h"
  9. #include "base/strings/string_split.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"
  14. #include "ui/gl/gl_switches.h"
  15. #define SHADER_VERSION_300(Src) "#version 300 es\n" #Src
  16. namespace gpu {
  17. class OpenGLES3FunctionTest : public testing::Test {
  18. protected:
  19. void SetUp() override {
  20. base::CommandLine command_line(*base::CommandLine::ForCurrentProcess());
  21. command_line.AppendSwitch(switches::kEnableUnsafeES3APIs);
  22. GLManager::Options options;
  23. options.context_type = gles2::CONTEXT_TYPE_OPENGLES3;
  24. gl_.InitializeWithCommandLine(options, &command_line);
  25. }
  26. void TearDown() override { gl_.Destroy(); }
  27. bool IsApplicable() const { return gl_.IsInitialized(); }
  28. GLManager gl_;
  29. };
  30. #if defined(OS_ANDROID)
  31. // Test is failing for Lollipop 64 bit Tester.
  32. // See crbug/550292.
  33. #define MAYBE_GetFragDataLocationInvalid DISABLED_GetFragDataLocationInvalid
  34. #else
  35. #define MAYBE_GetFragDataLocationInvalid GetFragDataLocationInvalid
  36. #endif
  37. TEST_F(OpenGLES3FunctionTest, MAYBE_GetFragDataLocationInvalid) {
  38. if (!IsApplicable()) {
  39. return;
  40. }
  41. // clang-format off
  42. static const char* kVertexShader =
  43. SHADER_VERSION_300(
  44. in vec4 position;
  45. void main() {
  46. gl_Position = position;
  47. });
  48. static const char* kFragColorShader =
  49. SHADER_VERSION_300(
  50. precision mediump float;
  51. uniform vec4 src;
  52. out vec4 FragColor;
  53. void main() {
  54. FragColor = src;
  55. });
  56. // clang-format on
  57. GLuint vsid = GLTestHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader);
  58. GLuint fsid = GLTestHelper::LoadShader(GL_FRAGMENT_SHADER, kFragColorShader);
  59. GLuint program = glCreateProgram();
  60. glAttachShader(program, vsid);
  61. glAttachShader(program, fsid);
  62. glDeleteShader(vsid);
  63. glDeleteShader(fsid);
  64. GLint location = glGetFragDataLocation(program, "FragColor");
  65. EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
  66. EXPECT_EQ(-1, location);
  67. location = glGetFragDataLocation(program, "Unknown");
  68. EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
  69. EXPECT_EQ(-1, location);
  70. glLinkProgram(program);
  71. location = glGetFragDataLocation(program, "FragColor");
  72. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  73. EXPECT_EQ(0, location);
  74. location = glGetFragDataLocation(program, "Unknown");
  75. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  76. EXPECT_EQ(-1, location);
  77. glDeleteProgram(program);
  78. }
  79. TEST_F(OpenGLES3FunctionTest, GetStringiTest) {
  80. if (!IsApplicable()) {
  81. return;
  82. }
  83. std::string extensionString =
  84. reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
  85. std::vector<std::string> extensions =
  86. base::SplitString(extensionString, base::kWhitespaceASCII,
  87. base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
  88. int num_extensions = 0;
  89. glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
  90. EXPECT_EQ(extensions.size(), static_cast<size_t>(num_extensions));
  91. std::set<std::string> extensions_from_string(extensions.begin(),
  92. extensions.end());
  93. std::set<std::string> extensions_from_stringi;
  94. for (int i = 0; i < num_extensions; ++i) {
  95. extensions_from_stringi.insert(
  96. reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, i)));
  97. }
  98. EXPECT_EQ(extensions_from_string, extensions_from_stringi);
  99. }
  100. } // namespace gpu