| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/gl/gl_context.h" | 12 #include "ui/gl/gl_context.h" |
| 13 #include "ui/gl/gl_gl_api_implementation.h" | 13 #include "ui/gl/gl_gl_api_implementation.h" |
| 14 #include "ui/gl/gl_implementation.h" | 14 #include "ui/gl/gl_implementation.h" |
| 15 #include "ui/gl/gl_switches.h" | 15 #include "ui/gl/gl_switches.h" |
| 16 #include "ui/gl/gl_version_info.h" |
| 16 #include "ui/gl/gpu_timing.h" | 17 #include "ui/gl/gpu_timing.h" |
| 17 | 18 |
| 18 namespace gl { | 19 namespace gl { |
| 19 | 20 |
| 20 class GLContextFake : public GLContext { | |
| 21 public: | |
| 22 bool Initialize(GLSurface* compatible_surface, | |
| 23 const GLContextAttribs& attribs) override { | |
| 24 return true; | |
| 25 } | |
| 26 bool MakeCurrent(GLSurface* surface) override { return true; } | |
| 27 void ReleaseCurrent(GLSurface* surface) override {} | |
| 28 bool IsCurrent(GLSurface* surface) override { return true; } | |
| 29 void* GetHandle() override { return NULL; } | |
| 30 scoped_refptr<GPUTimingClient> CreateGPUTimingClient() override { | |
| 31 return NULL; | |
| 32 } | |
| 33 void OnSetSwapInterval(int interval) override {} | |
| 34 GLContextFake() : GLContext(NULL) {} | |
| 35 protected: | |
| 36 ~GLContextFake() override {} | |
| 37 }; | |
| 38 | |
| 39 class GLApiTest : public testing::Test { | 21 class GLApiTest : public testing::Test { |
| 40 public: | 22 public: |
| 41 void SetUp() override { | 23 void SetUp() override { |
| 42 fake_extension_string_ = ""; | 24 fake_extension_string_ = ""; |
| 43 fake_version_string_ = ""; | 25 fake_version_string_ = ""; |
| 44 num_fake_extension_strings_ = 0; | 26 num_fake_extension_strings_ = 0; |
| 45 fake_extension_strings_ = nullptr; | 27 fake_extension_strings_ = nullptr; |
| 46 | 28 |
| 47 DCHECK(!g_current_gl_context_tls); | |
| 48 g_current_gl_context_tls = new base::ThreadLocalPointer<GLApi>; | |
| 49 | |
| 50 SetGLGetProcAddressProc( | 29 SetGLGetProcAddressProc( |
| 51 static_cast<GLGetProcAddressProc>(&FakeGLGetProcAddress)); | 30 static_cast<GLGetProcAddressProc>(&FakeGLGetProcAddress)); |
| 52 } | 31 } |
| 53 | 32 |
| 54 static GLFunctionPointerType GL_BINDING_CALL | 33 static GLFunctionPointerType GL_BINDING_CALL |
| 55 FakeGLGetProcAddress(const char* proc) { | 34 FakeGLGetProcAddress(const char* proc) { |
| 56 return reinterpret_cast<GLFunctionPointerType>(0x1); | 35 return reinterpret_cast<GLFunctionPointerType>(0x1); |
| 57 } | 36 } |
| 58 | 37 |
| 59 void TearDown() override { | 38 void TearDown() override { |
| 60 api_.reset(nullptr); | 39 api_.reset(nullptr); |
| 61 delete g_current_gl_context_tls; | 40 driver_.reset(nullptr); |
| 62 g_current_gl_context_tls = nullptr; | |
| 63 | 41 |
| 64 SetGLImplementation(kGLImplementationNone); | 42 SetGLImplementation(kGLImplementationNone); |
| 65 fake_extension_string_ = ""; | 43 fake_extension_string_ = ""; |
| 66 fake_version_string_ = ""; | 44 fake_version_string_ = ""; |
| 67 num_fake_extension_strings_ = 0; | 45 num_fake_extension_strings_ = 0; |
| 68 fake_extension_strings_ = nullptr; | 46 fake_extension_strings_ = nullptr; |
| 69 } | 47 } |
| 70 | 48 |
| 71 void InitializeAPI(base::CommandLine* command_line) { | 49 void InitializeAPI(base::CommandLine* command_line) { |
| 50 driver_.reset(new DriverGL()); |
| 51 driver_->fn.glGetStringFn = &FakeGetString; |
| 52 driver_->fn.glGetStringiFn = &FakeGetStringi; |
| 53 driver_->fn.glGetIntegervFn = &FakeGetIntegervFn; |
| 54 |
| 72 api_.reset(new RealGLApi()); | 55 api_.reset(new RealGLApi()); |
| 73 g_current_gl_context_tls->Set(api_.get()); | 56 if (command_line) |
| 57 api_->InitializeWithCommandLine(driver_.get(), command_line); |
| 58 else |
| 59 api_->Initialize(driver_.get()); |
| 74 | 60 |
| 75 g_driver_gl.ClearBindings(); | |
| 76 g_driver_gl.fn.glGetStringFn = &FakeGetString; | |
| 77 g_driver_gl.fn.glGetStringiFn = &FakeGetStringi; | |
| 78 g_driver_gl.fn.glGetIntegervFn = &FakeGetIntegervFn; | |
| 79 | |
| 80 fake_context_ = new GLContextFake(); | |
| 81 if (command_line) | |
| 82 api_->InitializeWithCommandLine(&g_driver_gl, command_line); | |
| 83 else | |
| 84 api_->Initialize(&g_driver_gl); | |
| 85 api_->InitializeFilteredExtensions(); | 61 api_->InitializeFilteredExtensions(); |
| 86 g_driver_gl.InitializeCustomDynamicBindings(fake_context_.get()); | 62 std::unique_ptr<GLVersionInfo> version = |
| 63 GetVersionInfoFromContext(api_.get()); |
| 64 driver_->InitializeDynamicBindings( |
| 65 version.get(), GetGLExtensionsFromCurrentContext(api_.get())); |
| 66 api_->set_version(std::move(version)); |
| 87 } | 67 } |
| 88 | 68 |
| 89 void SetFakeExtensionString(const char* fake_string) { | 69 void SetFakeExtensionString(const char* fake_string) { |
| 90 SetGLImplementation(kGLImplementationDesktopGL); | 70 SetGLImplementation(kGLImplementationDesktopGL); |
| 91 fake_extension_string_ = fake_string; | 71 fake_extension_string_ = fake_string; |
| 92 fake_version_string_ = "2.1"; | 72 fake_version_string_ = "2.1"; |
| 93 } | 73 } |
| 94 | 74 |
| 95 void SetFakeExtensionStrings(const char** fake_strings, uint32_t count) { | 75 void SetFakeExtensionStrings(const char** fake_strings, uint32_t count) { |
| 96 SetGLImplementation(kGLImplementationDesktopGL); | 76 SetGLImplementation(kGLImplementationDesktopGL); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 index)); | 111 index)); |
| 132 } | 112 } |
| 133 | 113 |
| 134 protected: | 114 protected: |
| 135 static const char* fake_extension_string_; | 115 static const char* fake_extension_string_; |
| 136 static const char* fake_version_string_; | 116 static const char* fake_version_string_; |
| 137 | 117 |
| 138 static uint32_t num_fake_extension_strings_; | 118 static uint32_t num_fake_extension_strings_; |
| 139 static const char** fake_extension_strings_; | 119 static const char** fake_extension_strings_; |
| 140 | 120 |
| 141 scoped_refptr<GLContext> fake_context_; | |
| 142 std::unique_ptr<DriverGL> driver_; | 121 std::unique_ptr<DriverGL> driver_; |
| 143 std::unique_ptr<RealGLApi> api_; | 122 std::unique_ptr<RealGLApi> api_; |
| 144 }; | 123 }; |
| 145 | 124 |
| 146 const char* GLApiTest::fake_extension_string_ = ""; | 125 const char* GLApiTest::fake_extension_string_ = ""; |
| 147 const char* GLApiTest::fake_version_string_ = ""; | 126 const char* GLApiTest::fake_version_string_ = ""; |
| 148 | 127 |
| 149 uint32_t GLApiTest::num_fake_extension_strings_ = 0; | 128 uint32_t GLApiTest::num_fake_extension_strings_ = 0; |
| 150 const char** GLApiTest::fake_extension_strings_ = nullptr; | 129 const char** GLApiTest::fake_extension_strings_ = nullptr; |
| 151 | 130 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 169 | 148 |
| 170 TEST_F(GLApiTest, DisabledExtensionBitTest) { | 149 TEST_F(GLApiTest, DisabledExtensionBitTest) { |
| 171 static const char* kFakeExtensions[] = { | 150 static const char* kFakeExtensions[] = { |
| 172 "GL_ARB_timer_query" | 151 "GL_ARB_timer_query" |
| 173 }; | 152 }; |
| 174 static const char* kFakeDisabledExtensions = "GL_ARB_timer_query"; | 153 static const char* kFakeDisabledExtensions = "GL_ARB_timer_query"; |
| 175 | 154 |
| 176 SetFakeExtensionStrings(kFakeExtensions, arraysize(kFakeExtensions)); | 155 SetFakeExtensionStrings(kFakeExtensions, arraysize(kFakeExtensions)); |
| 177 InitializeAPI(nullptr); | 156 InitializeAPI(nullptr); |
| 178 | 157 |
| 179 EXPECT_TRUE(g_driver_gl.ext.b_GL_ARB_timer_query); | 158 EXPECT_TRUE(driver_->ext.b_GL_ARB_timer_query); |
| 180 | 159 |
| 181 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 160 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 182 command_line.AppendSwitchASCII(switches::kDisableGLExtensions, | 161 command_line.AppendSwitchASCII(switches::kDisableGLExtensions, |
| 183 kFakeDisabledExtensions); | 162 kFakeDisabledExtensions); |
| 184 InitializeAPI(&command_line); | 163 InitializeAPI(&command_line); |
| 185 | 164 |
| 186 EXPECT_FALSE(g_driver_gl.ext.b_GL_ARB_timer_query); | 165 EXPECT_FALSE(driver_->ext.b_GL_ARB_timer_query); |
| 187 } | 166 } |
| 188 | 167 |
| 189 TEST_F(GLApiTest, DisabledExtensionStringIndexTest) { | 168 TEST_F(GLApiTest, DisabledExtensionStringIndexTest) { |
| 190 static const char* kFakeExtensions[] = { | 169 static const char* kFakeExtensions[] = { |
| 191 "GL_EXT_1", | 170 "GL_EXT_1", |
| 192 "GL_EXT_2", | 171 "GL_EXT_2", |
| 193 "GL_EXT_3", | 172 "GL_EXT_3", |
| 194 "GL_EXT_4" | 173 "GL_EXT_4" |
| 195 }; | 174 }; |
| 196 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE"; | 175 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE"; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 212 kFakeDisabledExtensions); | 191 kFakeDisabledExtensions); |
| 213 InitializeAPI(&command_line); | 192 InitializeAPI(&command_line); |
| 214 | 193 |
| 215 EXPECT_EQ(arraysize(kFilteredExtensions), GetNumExtensions()); | 194 EXPECT_EQ(arraysize(kFilteredExtensions), GetNumExtensions()); |
| 216 for (uint32_t i = 0; i < arraysize(kFilteredExtensions); ++i) { | 195 for (uint32_t i = 0; i < arraysize(kFilteredExtensions); ++i) { |
| 217 EXPECT_STREQ(kFilteredExtensions[i], GetExtensioni(i)); | 196 EXPECT_STREQ(kFilteredExtensions[i], GetExtensioni(i)); |
| 218 } | 197 } |
| 219 } | 198 } |
| 220 | 199 |
| 221 } // namespace gl | 200 } // namespace gl |
| OLD | NEW |