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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/gl/gl_context.h" | |
8 #include "ui/gl/gl_gl_api_implementation.h" | 9 #include "ui/gl/gl_gl_api_implementation.h" |
9 #include "ui/gl/gl_implementation.h" | 10 #include "ui/gl/gl_implementation.h" |
10 #include "ui/gl/gl_switches.h" | 11 #include "ui/gl/gl_switches.h" |
12 #include "ui/gl/gpu_timing.h" | |
11 | 13 |
12 namespace gfx { | 14 namespace gfx { |
13 | 15 |
16 class GLContextFake : public GLContext { | |
17 public: | |
18 bool Initialize(GLSurface* compatible_surface, | |
19 GpuPreference gpu_preference) override { | |
20 return true; | |
21 } | |
22 void Destroy() override {} | |
23 bool MakeCurrent(GLSurface* surface) override { return true; } | |
24 void ReleaseCurrent(GLSurface* surface) override {} | |
25 bool IsCurrent(GLSurface* surface) override { return true; } | |
26 void* GetHandle() override { return NULL; } | |
27 scoped_refptr<gfx::GPUTimingClient> CreateGPUTimingClient() override { | |
28 return NULL; | |
29 } | |
30 void OnSetSwapInterval(int interval) override {} | |
31 GLContextFake() : GLContext(NULL) {} | |
32 protected: | |
33 ~GLContextFake() override {} | |
34 }; | |
35 | |
14 class GLApiTest : public testing::Test { | 36 class GLApiTest : public testing::Test { |
15 public: | 37 public: |
16 void SetUp() override { | 38 void SetUp() override { |
17 fake_extension_string_ = ""; | 39 fake_extension_string_ = ""; |
18 num_fake_extension_strings_ = 0; | 40 num_fake_extension_strings_ = 0; |
19 fake_extension_strings_ = nullptr; | 41 fake_extension_strings_ = nullptr; |
20 | 42 |
21 driver_.reset(new DriverGL()); | 43 g_current_gl_context_tls = new base::ThreadLocalPointer<GLApi>; |
22 api_.reset(new RealGLApi()); | 44 api_.reset(new RealGLApi()); |
23 | 45 |
24 driver_->fn.glGetStringFn = &FakeGetString; | 46 g_driver_gl.ClearBindings(); |
25 driver_->fn.glGetStringiFn = &FakeGetStringi; | 47 g_driver_gl.fn.glGetStringFn = &FakeGetString; |
26 driver_->fn.glGetIntegervFn = &FakeGetIntegervFn; | 48 g_driver_gl.fn.glGetStringiFn = &FakeGetStringi; |
49 g_driver_gl.fn.glGetIntegervFn = &FakeGetIntegervFn; | |
50 | |
51 SetGLGetProcAddressProc( | |
52 static_cast<GLGetProcAddressProc>(&FakeGLGetProcAddress)); | |
53 } | |
54 | |
55 static void* GL_BINDING_CALL FakeGLGetProcAddress(const char *proc) { | |
56 return reinterpret_cast<void*>(0x1); | |
27 } | 57 } |
28 | 58 |
29 void TearDown() override { | 59 void TearDown() override { |
30 api_.reset(nullptr); | 60 api_.reset(nullptr); |
31 driver_.reset(nullptr); | 61 delete g_current_gl_context_tls; |
32 | 62 |
33 SetGLImplementation(kGLImplementationNone); | 63 SetGLImplementation(kGLImplementationNone); |
34 fake_extension_string_ = ""; | 64 fake_extension_string_ = ""; |
35 num_fake_extension_strings_ = 0; | 65 num_fake_extension_strings_ = 0; |
36 fake_extension_strings_ = nullptr; | 66 fake_extension_strings_ = nullptr; |
37 } | 67 } |
38 | 68 |
39 void InitializeAPI(base::CommandLine* command_line) { | 69 void InitializeAPI(base::CommandLine* command_line) { |
40 api_.reset(new RealGLApi()); | 70 api_.reset(new RealGLApi()); |
71 g_current_gl_context_tls->Set(api_.get()); | |
72 | |
73 fake_context_ = new GLContextFake(); | |
41 if (command_line) | 74 if (command_line) |
42 api_->InitializeWithCommandLine(driver_.get(), command_line); | 75 api_->InitializeWithCommandLine(&g_driver_gl, command_line); |
43 else | 76 else |
44 api_->Initialize(driver_.get()); | 77 api_->Initialize(&g_driver_gl); |
78 api_->InitializeFilteredExtensions(); | |
no sievers
2015/07/23 23:45:57
Doesn't InitializeWithContext() call this?
Tobias Sargeant
2015/07/24 09:29:14
Not any more. It's safe to remove InitializeWithCo
| |
79 g_driver_gl.InitializeCustomDynamicBindings(fake_context_.get()); | |
45 api_->InitializeWithContext(); | 80 api_->InitializeWithContext(); |
46 } | 81 } |
47 | 82 |
48 void SetFakeExtensionString(const char* fake_string) { | 83 void SetFakeExtensionString(const char* fake_string) { |
49 SetGLImplementation(kGLImplementationDesktopGL); | 84 SetGLImplementation(kGLImplementationDesktopGL); |
50 fake_extension_string_ = fake_string; | 85 fake_extension_string_ = fake_string; |
51 } | 86 } |
52 | 87 |
53 void SetFakeExtensionStrings(const char** fake_strings, uint32_t count) { | 88 void SetFakeExtensionStrings(const char** fake_strings, uint32_t count) { |
54 SetGLImplementation(kGLImplementationDesktopGLCoreProfile); | 89 SetGLImplementation(kGLImplementationDesktopGLCoreProfile); |
(...skipping 30 matching lines...) Expand all Loading... | |
85 return reinterpret_cast<const char*>(api_->glGetStringiFn(GL_EXTENSIONS, | 120 return reinterpret_cast<const char*>(api_->glGetStringiFn(GL_EXTENSIONS, |
86 index)); | 121 index)); |
87 } | 122 } |
88 | 123 |
89 protected: | 124 protected: |
90 static const char* fake_extension_string_; | 125 static const char* fake_extension_string_; |
91 | 126 |
92 static uint32_t num_fake_extension_strings_; | 127 static uint32_t num_fake_extension_strings_; |
93 static const char** fake_extension_strings_; | 128 static const char** fake_extension_strings_; |
94 | 129 |
130 scoped_refptr<GLContext> fake_context_; | |
95 scoped_ptr<DriverGL> driver_; | 131 scoped_ptr<DriverGL> driver_; |
96 scoped_ptr<RealGLApi> api_; | 132 scoped_ptr<RealGLApi> api_; |
97 }; | 133 }; |
98 | 134 |
99 const char* GLApiTest::fake_extension_string_ = ""; | 135 const char* GLApiTest::fake_extension_string_ = ""; |
100 | 136 |
101 uint32_t GLApiTest::num_fake_extension_strings_ = 0; | 137 uint32_t GLApiTest::num_fake_extension_strings_ = 0; |
102 const char** GLApiTest::fake_extension_strings_ = nullptr; | 138 const char** GLApiTest::fake_extension_strings_ = nullptr; |
103 | 139 |
104 TEST_F(GLApiTest, DisabledExtensionStringTest) { | 140 TEST_F(GLApiTest, DisabledExtensionStringTest) { |
105 static const char* kFakeExtensions = "GL_EXT_1 GL_EXT_2 GL_EXT_3 GL_EXT_4"; | 141 static const char* kFakeExtensions = "GL_EXT_1 GL_EXT_2 GL_EXT_3 GL_EXT_4"; |
106 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE"; | 142 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE"; |
107 static const char* kFilteredExtensions = "GL_EXT_3 GL_EXT_4"; | 143 static const char* kFilteredExtensions = "GL_EXT_3 GL_EXT_4"; |
108 | 144 |
109 SetFakeExtensionString(kFakeExtensions); | 145 SetFakeExtensionString(kFakeExtensions); |
110 InitializeAPI(nullptr); | 146 InitializeAPI(nullptr); |
111 | 147 |
112 EXPECT_STREQ(kFakeExtensions, GetExtensions()); | 148 EXPECT_STREQ(kFakeExtensions, GetExtensions()); |
113 | 149 |
114 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 150 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
115 command_line.AppendSwitchASCII(switches::kDisableGLExtensions, | 151 command_line.AppendSwitchASCII(switches::kDisableGLExtensions, |
116 kFakeDisabledExtensions); | 152 kFakeDisabledExtensions); |
117 InitializeAPI(&command_line); | 153 InitializeAPI(&command_line); |
118 | 154 |
119 EXPECT_STREQ(kFilteredExtensions, GetExtensions()); | 155 EXPECT_STREQ(kFilteredExtensions, GetExtensions()); |
120 } | 156 } |
121 | 157 |
158 TEST_F(GLApiTest, DisabledExtensionBitTest) { | |
159 static const char* kFakeExtensions[] = { | |
160 "GL_ARB_timer_query" | |
161 }; | |
162 static const char* kFakeDisabledExtensions = "GL_ARB_timer_query"; | |
163 | |
164 SetFakeExtensionStrings(kFakeExtensions, arraysize(kFakeExtensions)); | |
165 InitializeAPI(nullptr); | |
166 | |
167 EXPECT_TRUE(g_driver_gl.ext.b_GL_ARB_timer_query); | |
168 | |
169 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
170 command_line.AppendSwitchASCII(switches::kDisableGLExtensions, | |
171 kFakeDisabledExtensions); | |
172 InitializeAPI(&command_line); | |
173 | |
174 EXPECT_FALSE(g_driver_gl.ext.b_GL_ARB_timer_query); | |
175 } | |
176 | |
122 TEST_F(GLApiTest, DisabledExtensionStringIndexTest) { | 177 TEST_F(GLApiTest, DisabledExtensionStringIndexTest) { |
123 static const char* kFakeExtensions[] = { | 178 static const char* kFakeExtensions[] = { |
124 "GL_EXT_1", | 179 "GL_EXT_1", |
125 "GL_EXT_2", | 180 "GL_EXT_2", |
126 "GL_EXT_3", | 181 "GL_EXT_3", |
127 "GL_EXT_4" | 182 "GL_EXT_4" |
128 }; | 183 }; |
129 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE"; | 184 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE"; |
130 static const char* kFilteredExtensions[] = { | 185 static const char* kFilteredExtensions[] = { |
131 "GL_EXT_3", | 186 "GL_EXT_3", |
(...skipping 13 matching lines...) Expand all Loading... | |
145 kFakeDisabledExtensions); | 200 kFakeDisabledExtensions); |
146 InitializeAPI(&command_line); | 201 InitializeAPI(&command_line); |
147 | 202 |
148 EXPECT_EQ(arraysize(kFilteredExtensions), GetNumExtensions()); | 203 EXPECT_EQ(arraysize(kFilteredExtensions), GetNumExtensions()); |
149 for (uint32_t i = 0; i < arraysize(kFilteredExtensions); ++i) { | 204 for (uint32_t i = 0; i < arraysize(kFilteredExtensions); ++i) { |
150 EXPECT_STREQ(kFilteredExtensions[i], GetExtensioni(i)); | 205 EXPECT_STREQ(kFilteredExtensions[i], GetExtensioni(i)); |
151 } | 206 } |
152 } | 207 } |
153 | 208 |
154 } // namespace gfx | 209 } // namespace gfx |
OLD | NEW |