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