| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 <GLES3/gl3.h> |
| 9 |
| 10 #include "base/command_line.h" |
| 11 #include "base/strings/string_split.h" |
| 12 #include "base/strings/string_util.h" |
| 13 #include "gpu/command_buffer/tests/gl_manager.h" |
| 14 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/gl/gl_switches.h" |
| 18 |
| 19 namespace gpu { |
| 20 |
| 21 class RequestExtensionCHROMIUMTest |
| 22 : public testing::TestWithParam<gles2::ContextType> { |
| 23 protected: |
| 24 void SetUp() override { |
| 25 base::CommandLine command_line(*base::CommandLine::ForCurrentProcess()); |
| 26 command_line.AppendSwitch(switches::kEnableUnsafeES3APIs); |
| 27 GLManager::Options options; |
| 28 options.context_type = GetParam(); |
| 29 gl_.InitializeWithCommandLine(options, &command_line); |
| 30 } |
| 31 void TearDown() override { gl_.Destroy(); } |
| 32 bool IsApplicable() const { return gl_.IsInitialized(); } |
| 33 GLManager gl_; |
| 34 }; |
| 35 |
| 36 TEST_P(RequestExtensionCHROMIUMTest, Basic) { |
| 37 if (!IsApplicable()) { |
| 38 return; |
| 39 } |
| 40 // Test to test that requesting an extension does not delete any extensions. |
| 41 // Also tests that WebGL2 and GLES3 contexts keep glGetString(GL_EXTENSIONS) |
| 42 // and glGetStringi(GL_EXTENSIONS, index) in sync. |
| 43 |
| 44 std::string requestable_extensions_string = |
| 45 reinterpret_cast<const char*>(glGetRequestableExtensionsCHROMIUM()); |
| 46 std::vector<std::string> requestable = |
| 47 base::SplitString(requestable_extensions_string, base::kWhitespaceASCII, |
| 48 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 49 for (const auto& to_request : requestable) { |
| 50 std::string extension_string = |
| 51 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); |
| 52 extension_string += " "; |
| 53 size_t extensions_size_before_request = |
| 54 base::SplitString(extension_string, base::kWhitespaceASCII, |
| 55 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY) |
| 56 .size(); |
| 57 |
| 58 if (extension_string.find(to_request + " ") != std::string::npos) { |
| 59 // Somewhat counterintuitively, requestable extensions contain every |
| 60 // extension available. |
| 61 continue; |
| 62 } |
| 63 |
| 64 glRequestExtensionCHROMIUM(to_request.c_str()); |
| 65 |
| 66 extension_string = |
| 67 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); |
| 68 std::vector<std::string> extensions = |
| 69 base::SplitString(extension_string, base::kWhitespaceASCII, |
| 70 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 71 std::set<std::string> extensions_from_string(extensions.begin(), |
| 72 extensions.end()); |
| 73 |
| 74 if (GetParam() == gles2::CONTEXT_TYPE_WEBGL2 || |
| 75 GetParam() == gles2::CONTEXT_TYPE_OPENGLES3) { |
| 76 // Test that GetString(GL_EXTENSIONS) is consistent with |
| 77 // GetStringi(GL_EXTENSIONS, index) |
| 78 GLint num_extensions = 0; |
| 79 glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions); |
| 80 EXPECT_EQ(static_cast<size_t>(num_extensions), extensions.size()); |
| 81 std::set<std::string> extensions_from_stringi; |
| 82 for (int i = 0; i < num_extensions; ++i) { |
| 83 extensions_from_stringi.insert( |
| 84 reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, i))); |
| 85 } |
| 86 EXPECT_EQ(extensions_from_string, extensions_from_stringi); |
| 87 } |
| 88 |
| 89 // Somewhat counterintuitively, requesting an extension that is offered |
| 90 // does not necessarily make it appear in the extensions list. |
| 91 // This is due to the fact that offered extensions list contains every |
| 92 // available extension, while WebGL2 filters extension list |
| 93 // based on what's in core WebGL2. |
| 94 |
| 95 // Test that RequestExtension does not erase any extensions. |
| 96 EXPECT_GE(extensions.size(), extensions_size_before_request); |
| 97 } |
| 98 } |
| 99 INSTANTIATE_TEST_CASE_P(WithContextTypes, |
| 100 RequestExtensionCHROMIUMTest, |
| 101 ::testing::Values(gles2::CONTEXT_TYPE_WEBGL1, |
| 102 gles2::CONTEXT_TYPE_WEBGL2, |
| 103 gles2::CONTEXT_TYPE_OPENGLES2, |
| 104 gles2::CONTEXT_TYPE_OPENGLES3)); |
| 105 } |
| OLD | NEW |