Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: content/browser/gpu/gpu_ipc_browsertests.cc

Issue 2197613003: gpu: Introduce GpuChannelEstablishFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ptr_util.h" 6 #include "base/memory/ptr_util.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 9 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
10 #include "content/browser/gpu/gpu_process_host_ui_shim.h" 10 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
(...skipping 26 matching lines...) Expand all
37 attributes.bind_generates_resource = false; 37 attributes.bind_generates_resource = false;
38 constexpr bool automatic_flushes = false; 38 constexpr bool automatic_flushes = false;
39 constexpr bool support_locking = false; 39 constexpr bool support_locking = false;
40 return make_scoped_refptr(new content::ContextProviderCommandBuffer( 40 return make_scoped_refptr(new content::ContextProviderCommandBuffer(
41 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT, 41 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT,
42 gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle, GURL(), 42 gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle, GURL(),
43 automatic_flushes, support_locking, gpu::SharedMemoryLimits(), attributes, 43 automatic_flushes, support_locking, gpu::SharedMemoryLimits(), attributes,
44 nullptr, content::command_buffer_metrics::OFFSCREEN_CONTEXT_FOR_TESTING)); 44 nullptr, content::command_buffer_metrics::OFFSCREEN_CONTEXT_FOR_TESTING));
45 } 45 }
46 46
47 class ContextTestBase : public content::ContentBrowserTest { 47 void OnEstablishedGpuChannel(
48 const base::Closure& quit_closure,
49 scoped_refptr<gpu::GpuChannelHost>* retvalue,
50 scoped_refptr<gpu::GpuChannelHost> established_host) {
51 if (retvalue)
52 *retvalue = std::move(established_host);
53 quit_closure.Run();
54 }
55
56 class EstablishGpuChannelHelper {
48 public: 57 public:
49 void SetUpOnMainThread() override { 58 EstablishGpuChannelHelper() {}
50 // This may leave the provider_ null in some cases, so tests need to early 59 ~EstablishGpuChannelHelper() {}
51 // out.
52 if (!content::BrowserGpuChannelHostFactory::CanUseForTesting())
53 return;
54 60
61 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSyncRunLoop() {
55 if (!content::BrowserGpuChannelHostFactory::instance()) 62 if (!content::BrowserGpuChannelHostFactory::instance())
56 content::BrowserGpuChannelHostFactory::Initialize(true); 63 content::BrowserGpuChannelHostFactory::Initialize(true);
57 64
58 content::BrowserGpuChannelHostFactory* factory = 65 content::BrowserGpuChannelHostFactory* factory =
59 content::BrowserGpuChannelHostFactory::instance(); 66 content::BrowserGpuChannelHostFactory::instance();
60 CHECK(factory); 67 CHECK(factory);
61 base::RunLoop run_loop; 68 base::RunLoop run_loop;
62 factory->EstablishGpuChannel(kInitCause, run_loop.QuitClosure()); 69 factory->EstablishGpuChannel(
70 kInitCause, base::Bind(&OnEstablishedGpuChannel, run_loop.QuitClosure(),
71 &gpu_channel_host_));
63 run_loop.Run(); 72 run_loop.Run();
64 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( 73 return std::move(gpu_channel_host_);
65 factory->GetGpuChannel()); 74 }
75
76 private:
77 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host_;
78 DISALLOW_COPY_AND_ASSIGN(EstablishGpuChannelHelper);
79 };
80
81 class ContextTestBase : public content::ContentBrowserTest {
82 public:
83 void SetUpOnMainThread() override {
84 // This may leave the provider_ null in some cases, so tests need to early
85 // out.
86 if (!content::BrowserGpuChannelHostFactory::CanUseForTesting())
87 return;
88
89 EstablishGpuChannelHelper helper;
90 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host =
91 helper.EstablishGpuChannelSyncRunLoop();
66 CHECK(gpu_channel_host); 92 CHECK(gpu_channel_host);
67 93
68 provider_ = CreateContext(std::move(gpu_channel_host)); 94 provider_ = CreateContext(std::move(gpu_channel_host));
69 bool bound = provider_->BindToCurrentThread(); 95 bool bound = provider_->BindToCurrentThread();
70 CHECK(bound); 96 CHECK(bound);
71 gl_ = provider_->ContextGL(); 97 gl_ = provider_->ContextGL();
72 context_support_ = provider_->ContextSupport(); 98 context_support_ = provider_->ContextSupport();
73 99
74 ContentBrowserTest::SetUpOnMainThread(); 100 ContentBrowserTest::SetUpOnMainThread();
75 } 101 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // Start all tests without a gpu channel so that the tests exercise a 142 // Start all tests without a gpu channel so that the tests exercise a
117 // consistent codepath. 143 // consistent codepath.
118 command_line->AppendSwitch(switches::kDisableGpuEarlyInit); 144 command_line->AppendSwitch(switches::kDisableGpuEarlyInit);
119 } 145 }
120 146
121 void OnContextLost(const base::Closure callback, int* counter) { 147 void OnContextLost(const base::Closure callback, int* counter) {
122 (*counter)++; 148 (*counter)++;
123 callback.Run(); 149 callback.Run();
124 } 150 }
125 151
152 void Signal(bool* event,
153 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) {
154 CHECK_EQ(*event, false);
155 *event = true;
156 gpu_channel_host_ = std::move(gpu_channel_host);
157 }
158
126 protected: 159 protected:
127 BrowserGpuChannelHostFactory* GetFactory() { 160 BrowserGpuChannelHostFactory* GetFactory() {
128 return BrowserGpuChannelHostFactory::instance(); 161 return BrowserGpuChannelHostFactory::instance();
129 } 162 }
130 163
131 bool IsChannelEstablished() { 164 bool IsChannelEstablished() {
132 return GetFactory()->GetGpuChannel() != NULL; 165 return gpu_channel_host_ && !gpu_channel_host_->IsLost();
133 } 166 }
134 167
135 void EstablishAndWait() { 168 void EstablishAndWait() {
136 base::RunLoop run_loop; 169 EstablishGpuChannelHelper helper;
137 GetFactory()->EstablishGpuChannel(kInitCause, run_loop.QuitClosure()); 170 gpu_channel_host_ = helper.EstablishGpuChannelSyncRunLoop();
138 run_loop.Run();
139 } 171 }
140 172
141 gpu::GpuChannelHost* GetGpuChannel() { return GetFactory()->GetGpuChannel(); } 173 gpu::GpuChannelHost* GetGpuChannel() { return gpu_channel_host_.get(); }
142 174
143 static void Signal(bool *event) { 175 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host_;
144 CHECK_EQ(*event, false);
145 *event = true;
146 }
147 }; 176 };
148 177
149 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor 178 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor
150 // establishes a GPU channel. 179 // establishes a GPU channel.
151 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 180 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
152 #define MAYBE_Basic Basic 181 #define MAYBE_Basic Basic
153 #else 182 #else
154 #define MAYBE_Basic DISABLED_Basic 183 #define MAYBE_Basic DISABLED_Basic
155 #endif 184 #endif
156 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, MAYBE_Basic) { 185 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, MAYBE_Basic) {
157 DCHECK(!IsChannelEstablished()); 186 DCHECK(!IsChannelEstablished());
158 EstablishAndWait(); 187 EstablishAndWait();
159 EXPECT_TRUE(GetGpuChannel() != NULL); 188 EXPECT_TRUE(GetGpuChannel() != NULL);
160 } 189 }
161 190
162 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor 191 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor
163 // establishes a GPU channel. 192 // establishes a GPU channel.
164 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 193 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
165 #define MAYBE_EstablishAndTerminate EstablishAndTerminate 194 #define MAYBE_EstablishAndTerminate EstablishAndTerminate
166 #else 195 #else
167 #define MAYBE_EstablishAndTerminate DISABLED_EstablishAndTerminate 196 #define MAYBE_EstablishAndTerminate DISABLED_EstablishAndTerminate
168 #endif 197 #endif
169 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, 198 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest,
170 MAYBE_EstablishAndTerminate) { 199 MAYBE_EstablishAndTerminate) {
171 DCHECK(!IsChannelEstablished()); 200 DCHECK(!IsChannelEstablished());
172 base::RunLoop run_loop; 201 base::RunLoop run_loop;
173 GetFactory()->EstablishGpuChannel(kInitCause, run_loop.QuitClosure()); 202 GetFactory()->EstablishGpuChannel(
203 kInitCause,
204 base::Bind(&OnEstablishedGpuChannel, run_loop.QuitClosure(), nullptr));
174 GetFactory()->Terminate(); 205 GetFactory()->Terminate();
175 206
176 // The callback should still trigger. 207 // The callback should still trigger.
177 run_loop.Run(); 208 run_loop.Run();
178 } 209 }
179 210
180 #if !defined(OS_ANDROID) 211 #if !defined(OS_ANDROID)
181 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor 212 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor
182 // establishes a GPU channel. 213 // establishes a GPU channel.
183 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 214 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
184 #define MAYBE_AlreadyEstablished AlreadyEstablished 215 #define MAYBE_AlreadyEstablished AlreadyEstablished
185 #else 216 #else
186 #define MAYBE_AlreadyEstablished DISABLED_AlreadyEstablished 217 #define MAYBE_AlreadyEstablished DISABLED_AlreadyEstablished
187 #endif 218 #endif
188 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, 219 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest,
189 MAYBE_AlreadyEstablished) { 220 MAYBE_AlreadyEstablished) {
190 DCHECK(!IsChannelEstablished()); 221 DCHECK(!IsChannelEstablished());
191 scoped_refptr<gpu::GpuChannelHost> gpu_channel = 222 scoped_refptr<gpu::GpuChannelHost> gpu_channel =
192 GetFactory()->EstablishGpuChannelSync(kInitCause); 223 GetFactory()->EstablishGpuChannelSync(kInitCause);
193 224
194 // Expect established callback immediately. 225 // Expect established callback immediately.
195 bool event = false; 226 bool event = false;
196 GetFactory()->EstablishGpuChannel( 227 GetFactory()->EstablishGpuChannel(
197 kInitCause, 228 kInitCause, base::Bind(&BrowserGpuChannelHostFactoryTest::Signal,
198 base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event)); 229 base::Unretained(this), &event));
199 EXPECT_TRUE(event); 230 EXPECT_TRUE(event);
200 EXPECT_EQ(gpu_channel.get(), GetGpuChannel()); 231 EXPECT_EQ(gpu_channel.get(), GetGpuChannel());
201 } 232 }
202 #endif 233 #endif
203 234
204 // Test fails on Windows because GPU Channel set-up fails. 235 // Test fails on Windows because GPU Channel set-up fails.
205 #if !defined(OS_WIN) 236 #if !defined(OS_WIN)
206 #define MAYBE_GrContextKeepsGpuChannelAlive GrContextKeepsGpuChannelAlive 237 #define MAYBE_GrContextKeepsGpuChannelAlive GrContextKeepsGpuChannelAlive
207 #else 238 #else
208 #define MAYBE_GrContextKeepsGpuChannelAlive \ 239 #define MAYBE_GrContextKeepsGpuChannelAlive \
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 SkPaint greenFillPaint; 282 SkPaint greenFillPaint;
252 greenFillPaint.setColor(SK_ColorGREEN); 283 greenFillPaint.setColor(SK_ColorGREEN);
253 greenFillPaint.setStyle(SkPaint::kFill_Style); 284 greenFillPaint.setStyle(SkPaint::kFill_Style);
254 // Passes by not crashing 285 // Passes by not crashing
255 surface->getCanvas()->drawRect(SkRect::MakeWH(100, 100), greenFillPaint); 286 surface->getCanvas()->drawRect(SkRect::MakeWH(100, 100), greenFillPaint);
256 } 287 }
257 288
258 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor 289 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor
259 // establishes a GPU channel. 290 // establishes a GPU channel.
260 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 291 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
261 #define MAYBE_CrashAndRecover 292 #define MAYBE_CrashAndRecover CrashAndRecover
262 #else 293 #else
263 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover 294 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover
264 #endif 295 #endif
265 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, 296 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest,
266 MAYBE_CrashAndRecover) { 297 MAYBE_CrashAndRecover) {
267 DCHECK(!IsChannelEstablished()); 298 DCHECK(!IsChannelEstablished());
268 EstablishAndWait(); 299 EstablishAndWait();
269 scoped_refptr<gpu::GpuChannelHost> host = GetGpuChannel(); 300 scoped_refptr<gpu::GpuChannelHost> host = GetGpuChannel();
270 301
271 scoped_refptr<ContextProviderCommandBuffer> provider = 302 scoped_refptr<ContextProviderCommandBuffer> provider =
(...skipping 10 matching lines...) Expand all
282 shim->SimulateCrash(); 313 shim->SimulateCrash();
283 run_loop.Run(); 314 run_loop.Run();
284 315
285 EXPECT_EQ(1, counter); 316 EXPECT_EQ(1, counter);
286 EXPECT_FALSE(IsChannelEstablished()); 317 EXPECT_FALSE(IsChannelEstablished());
287 EstablishAndWait(); 318 EstablishAndWait();
288 EXPECT_TRUE(IsChannelEstablished()); 319 EXPECT_TRUE(IsChannelEstablished());
289 } 320 }
290 321
291 } // namespace content 322 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698