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