OLD | NEW |
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 25 matching lines...) Expand all Loading... |
36 attributes.alpha_size = -1; | 36 attributes.alpha_size = -1; |
37 attributes.depth_size = 0; | 37 attributes.depth_size = 0; |
38 attributes.stencil_size = 0; | 38 attributes.stencil_size = 0; |
39 attributes.samples = 0; | 39 attributes.samples = 0; |
40 attributes.sample_buffers = 0; | 40 attributes.sample_buffers = 0; |
41 attributes.bind_generates_resource = false; | 41 attributes.bind_generates_resource = false; |
42 bool share_resources = false; | 42 bool share_resources = false; |
43 bool automatic_flushes = false; | 43 bool automatic_flushes = false; |
44 return base::WrapUnique(new WebGraphicsContext3DCommandBufferImpl( | 44 return base::WrapUnique(new WebGraphicsContext3DCommandBufferImpl( |
45 gpu::kNullSurfaceHandle, GURL(), gpu_channel_host, attributes, | 45 gpu::kNullSurfaceHandle, GURL(), gpu_channel_host, attributes, |
46 gfx::PreferIntegratedGpu, share_resources, automatic_flushes, | 46 gfx::PreferIntegratedGpu, share_resources, automatic_flushes, nullptr)); |
47 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits(), nullptr)); | |
48 } | 47 } |
49 | 48 |
50 class ContextTestBase : public content::ContentBrowserTest { | 49 class ContextTestBase : public content::ContentBrowserTest { |
51 public: | 50 public: |
52 void SetUpOnMainThread() override { | 51 void SetUpOnMainThread() override { |
53 // This may leave the provider_ null in some cases, so tests need to early | 52 // This may leave the provider_ null in some cases, so tests need to early |
54 // out. | 53 // out. |
55 if (!content::BrowserGpuChannelHostFactory::CanUseForTesting()) | 54 if (!content::BrowserGpuChannelHostFactory::CanUseForTesting()) |
56 return; | 55 return; |
57 | 56 |
58 if (!content::BrowserGpuChannelHostFactory::instance()) | 57 if (!content::BrowserGpuChannelHostFactory::instance()) |
59 content::BrowserGpuChannelHostFactory::Initialize(true); | 58 content::BrowserGpuChannelHostFactory::Initialize(true); |
60 | 59 |
61 content::BrowserGpuChannelHostFactory* factory = | 60 content::BrowserGpuChannelHostFactory* factory = |
62 content::BrowserGpuChannelHostFactory::instance(); | 61 content::BrowserGpuChannelHostFactory::instance(); |
63 CHECK(factory); | 62 CHECK(factory); |
64 base::RunLoop run_loop; | 63 base::RunLoop run_loop; |
65 factory->EstablishGpuChannel(kInitCause, run_loop.QuitClosure()); | 64 factory->EstablishGpuChannel(kInitCause, run_loop.QuitClosure()); |
66 run_loop.Run(); | 65 run_loop.Run(); |
67 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( | 66 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( |
68 factory->GetGpuChannel()); | 67 factory->GetGpuChannel()); |
69 CHECK(gpu_channel_host); | 68 CHECK(gpu_channel_host); |
70 | 69 |
71 provider_ = new content::ContextProviderCommandBuffer( | 70 provider_ = new content::ContextProviderCommandBuffer( |
72 CreateContext(gpu_channel_host.get()), | 71 CreateContext(gpu_channel_host.get()), gpu::SharedMemoryLimits(), |
73 content::OFFSCREEN_CONTEXT_FOR_TESTING); | 72 content::OFFSCREEN_CONTEXT_FOR_TESTING); |
74 bool bound = provider_->BindToCurrentThread(); | 73 bool bound = provider_->BindToCurrentThread(); |
75 CHECK(bound); | 74 CHECK(bound); |
76 gl_ = provider_->ContextGL(); | 75 gl_ = provider_->ContextGL(); |
77 context_support_ = provider_->ContextSupport(); | 76 context_support_ = provider_->ContextSupport(); |
78 | 77 |
79 ContentBrowserTest::SetUpOnMainThread(); | 78 ContentBrowserTest::SetUpOnMainThread(); |
80 } | 79 } |
81 | 80 |
82 void TearDownOnMainThread() override { | 81 void TearDownOnMainThread() override { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // provider has been destroyed. Without this behavior, user code would have | 220 // provider has been destroyed. Without this behavior, user code would have |
222 // to be careful to destroy objects in the right order to avoid using freed | 221 // to be careful to destroy objects in the right order to avoid using freed |
223 // memory as a function pointer in the GrContext's GrGLInterface instance. | 222 // memory as a function pointer in the GrContext's GrGLInterface instance. |
224 DCHECK(!IsChannelEstablished()); | 223 DCHECK(!IsChannelEstablished()); |
225 EstablishAndWait(); | 224 EstablishAndWait(); |
226 | 225 |
227 // Step 2: verify that holding onto the provider's GrContext will | 226 // Step 2: verify that holding onto the provider's GrContext will |
228 // retain the host after provider is destroyed. | 227 // retain the host after provider is destroyed. |
229 scoped_refptr<ContextProviderCommandBuffer> provider = | 228 scoped_refptr<ContextProviderCommandBuffer> provider = |
230 new ContextProviderCommandBuffer(CreateContext(GetGpuChannel()), | 229 new ContextProviderCommandBuffer(CreateContext(GetGpuChannel()), |
| 230 gpu::SharedMemoryLimits(), |
231 OFFSCREEN_CONTEXT_FOR_TESTING); | 231 OFFSCREEN_CONTEXT_FOR_TESTING); |
232 EXPECT_TRUE(provider->BindToCurrentThread()); | 232 EXPECT_TRUE(provider->BindToCurrentThread()); |
233 | 233 |
234 sk_sp<GrContext> gr_context = sk_ref_sp(provider->GrContext()); | 234 sk_sp<GrContext> gr_context = sk_ref_sp(provider->GrContext()); |
235 | 235 |
236 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 236 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
237 sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget( | 237 sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget( |
238 gr_context.get(), SkBudgeted::kNo, info); | 238 gr_context.get(), SkBudgeted::kNo, info); |
239 EXPECT_TRUE(surface); | 239 EXPECT_TRUE(surface); |
240 | 240 |
(...skipping 28 matching lines...) Expand all Loading... |
269 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover | 269 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover |
270 #endif | 270 #endif |
271 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, | 271 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, |
272 MAYBE_CrashAndRecover) { | 272 MAYBE_CrashAndRecover) { |
273 DCHECK(!IsChannelEstablished()); | 273 DCHECK(!IsChannelEstablished()); |
274 EstablishAndWait(); | 274 EstablishAndWait(); |
275 scoped_refptr<gpu::GpuChannelHost> host = GetGpuChannel(); | 275 scoped_refptr<gpu::GpuChannelHost> host = GetGpuChannel(); |
276 | 276 |
277 scoped_refptr<ContextProviderCommandBuffer> provider = | 277 scoped_refptr<ContextProviderCommandBuffer> provider = |
278 new ContextProviderCommandBuffer(CreateContext(GetGpuChannel()), | 278 new ContextProviderCommandBuffer(CreateContext(GetGpuChannel()), |
| 279 gpu::SharedMemoryLimits(), |
279 OFFSCREEN_CONTEXT_FOR_TESTING); | 280 OFFSCREEN_CONTEXT_FOR_TESTING); |
280 base::RunLoop run_loop; | 281 base::RunLoop run_loop; |
281 int counter = 0; | 282 int counter = 0; |
282 provider->SetLostContextCallback( | 283 provider->SetLostContextCallback( |
283 base::Bind(&BrowserGpuChannelHostFactoryTest::OnContextLost, | 284 base::Bind(&BrowserGpuChannelHostFactoryTest::OnContextLost, |
284 base::Unretained(this), run_loop.QuitClosure(), &counter)); | 285 base::Unretained(this), run_loop.QuitClosure(), &counter)); |
285 EXPECT_TRUE(provider->BindToCurrentThread()); | 286 EXPECT_TRUE(provider->BindToCurrentThread()); |
286 GpuProcessHostUIShim* shim = | 287 GpuProcessHostUIShim* shim = |
287 GpuProcessHostUIShim::FromID(GetFactory()->GpuProcessHostId()); | 288 GpuProcessHostUIShim::FromID(GetFactory()->GpuProcessHostId()); |
288 EXPECT_TRUE(shim != NULL); | 289 EXPECT_TRUE(shim != NULL); |
289 shim->SimulateCrash(); | 290 shim->SimulateCrash(); |
290 run_loop.Run(); | 291 run_loop.Run(); |
291 | 292 |
292 EXPECT_EQ(1, counter); | 293 EXPECT_EQ(1, counter); |
293 EXPECT_FALSE(IsChannelEstablished()); | 294 EXPECT_FALSE(IsChannelEstablished()); |
294 EstablishAndWait(); | 295 EstablishAndWait(); |
295 EXPECT_TRUE(IsChannelEstablished()); | 296 EXPECT_TRUE(IsChannelEstablished()); |
296 } | 297 } |
297 | 298 |
298 } // namespace content | 299 } // namespace content |
OLD | NEW |