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); |
45 api_->InitializeWithContext(); | 78 api_->InitializeFilteredExtensions(); |
| 79 g_driver_gl.InitializeCustomDynamicBindings(fake_context_.get()); |
46 } | 80 } |
47 | 81 |
48 void SetFakeExtensionString(const char* fake_string) { | 82 void SetFakeExtensionString(const char* fake_string) { |
49 SetGLImplementation(kGLImplementationDesktopGL); | 83 SetGLImplementation(kGLImplementationDesktopGL); |
50 fake_extension_string_ = fake_string; | 84 fake_extension_string_ = fake_string; |
51 } | 85 } |
52 | 86 |
53 void SetFakeExtensionStrings(const char** fake_strings, uint32_t count) { | 87 void SetFakeExtensionStrings(const char** fake_strings, uint32_t count) { |
54 SetGLImplementation(kGLImplementationDesktopGLCoreProfile); | 88 SetGLImplementation(kGLImplementationDesktopGLCoreProfile); |
55 num_fake_extension_strings_ = count; | 89 num_fake_extension_strings_ = count; |
(...skipping 29 matching lines...) Expand all Loading... |
85 return reinterpret_cast<const char*>(api_->glGetStringiFn(GL_EXTENSIONS, | 119 return reinterpret_cast<const char*>(api_->glGetStringiFn(GL_EXTENSIONS, |
86 index)); | 120 index)); |
87 } | 121 } |
88 | 122 |
89 protected: | 123 protected: |
90 static const char* fake_extension_string_; | 124 static const char* fake_extension_string_; |
91 | 125 |
92 static uint32_t num_fake_extension_strings_; | 126 static uint32_t num_fake_extension_strings_; |
93 static const char** fake_extension_strings_; | 127 static const char** fake_extension_strings_; |
94 | 128 |
| 129 scoped_refptr<GLContext> fake_context_; |
95 scoped_ptr<DriverGL> driver_; | 130 scoped_ptr<DriverGL> driver_; |
96 scoped_ptr<RealGLApi> api_; | 131 scoped_ptr<RealGLApi> api_; |
97 }; | 132 }; |
98 | 133 |
99 const char* GLApiTest::fake_extension_string_ = ""; | 134 const char* GLApiTest::fake_extension_string_ = ""; |
100 | 135 |
101 uint32_t GLApiTest::num_fake_extension_strings_ = 0; | 136 uint32_t GLApiTest::num_fake_extension_strings_ = 0; |
102 const char** GLApiTest::fake_extension_strings_ = nullptr; | 137 const char** GLApiTest::fake_extension_strings_ = nullptr; |
103 | 138 |
104 TEST_F(GLApiTest, DisabledExtensionStringTest) { | 139 TEST_F(GLApiTest, DisabledExtensionStringTest) { |
105 static const char* kFakeExtensions = "GL_EXT_1 GL_EXT_2 GL_EXT_3 GL_EXT_4"; | 140 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"; | 141 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE"; |
107 static const char* kFilteredExtensions = "GL_EXT_3 GL_EXT_4"; | 142 static const char* kFilteredExtensions = "GL_EXT_3 GL_EXT_4"; |
108 | 143 |
109 SetFakeExtensionString(kFakeExtensions); | 144 SetFakeExtensionString(kFakeExtensions); |
110 InitializeAPI(nullptr); | 145 InitializeAPI(nullptr); |
111 | 146 |
112 EXPECT_STREQ(kFakeExtensions, GetExtensions()); | 147 EXPECT_STREQ(kFakeExtensions, GetExtensions()); |
113 | 148 |
114 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 149 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
115 command_line.AppendSwitchASCII(switches::kDisableGLExtensions, | 150 command_line.AppendSwitchASCII(switches::kDisableGLExtensions, |
116 kFakeDisabledExtensions); | 151 kFakeDisabledExtensions); |
117 InitializeAPI(&command_line); | 152 InitializeAPI(&command_line); |
118 | 153 |
119 EXPECT_STREQ(kFilteredExtensions, GetExtensions()); | 154 EXPECT_STREQ(kFilteredExtensions, GetExtensions()); |
120 } | 155 } |
121 | 156 |
| 157 TEST_F(GLApiTest, DisabledExtensionBitTest) { |
| 158 static const char* kFakeExtensions[] = { |
| 159 "GL_ARB_timer_query" |
| 160 }; |
| 161 static const char* kFakeDisabledExtensions = "GL_ARB_timer_query"; |
| 162 |
| 163 SetFakeExtensionStrings(kFakeExtensions, arraysize(kFakeExtensions)); |
| 164 InitializeAPI(nullptr); |
| 165 |
| 166 EXPECT_TRUE(g_driver_gl.ext.b_GL_ARB_timer_query); |
| 167 |
| 168 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 169 command_line.AppendSwitchASCII(switches::kDisableGLExtensions, |
| 170 kFakeDisabledExtensions); |
| 171 InitializeAPI(&command_line); |
| 172 |
| 173 EXPECT_FALSE(g_driver_gl.ext.b_GL_ARB_timer_query); |
| 174 } |
| 175 |
122 TEST_F(GLApiTest, DisabledExtensionStringIndexTest) { | 176 TEST_F(GLApiTest, DisabledExtensionStringIndexTest) { |
123 static const char* kFakeExtensions[] = { | 177 static const char* kFakeExtensions[] = { |
124 "GL_EXT_1", | 178 "GL_EXT_1", |
125 "GL_EXT_2", | 179 "GL_EXT_2", |
126 "GL_EXT_3", | 180 "GL_EXT_3", |
127 "GL_EXT_4" | 181 "GL_EXT_4" |
128 }; | 182 }; |
129 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE"; | 183 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE"; |
130 static const char* kFilteredExtensions[] = { | 184 static const char* kFilteredExtensions[] = { |
131 "GL_EXT_3", | 185 "GL_EXT_3", |
(...skipping 13 matching lines...) Expand all Loading... |
145 kFakeDisabledExtensions); | 199 kFakeDisabledExtensions); |
146 InitializeAPI(&command_line); | 200 InitializeAPI(&command_line); |
147 | 201 |
148 EXPECT_EQ(arraysize(kFilteredExtensions), GetNumExtensions()); | 202 EXPECT_EQ(arraysize(kFilteredExtensions), GetNumExtensions()); |
149 for (uint32_t i = 0; i < arraysize(kFilteredExtensions); ++i) { | 203 for (uint32_t i = 0; i < arraysize(kFilteredExtensions); ++i) { |
150 EXPECT_STREQ(kFilteredExtensions[i], GetExtensioni(i)); | 204 EXPECT_STREQ(kFilteredExtensions[i], GetExtensioni(i)); |
151 } | 205 } |
152 } | 206 } |
153 | 207 |
154 } // namespace gfx | 208 } // namespace gfx |
OLD | NEW |