| 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" |
| 11 #include "content/common/gpu/client/context_provider_command_buffer.h" | 11 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 12 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 12 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 13 #include "content/common/gpu_process_launch_causes.h" | 13 #include "content/common/gpu_process_launch_causes.h" |
| 14 #include "content/public/browser/gpu_data_manager.h" | 14 #include "content/public/browser/gpu_data_manager.h" |
| 15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 16 #include "content/public/test/content_browser_test.h" | 16 #include "content/public/test/content_browser_test.h" |
| 17 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/core/SkCanvas.h" |
| 18 #include "third_party/skia/include/core/SkPaint.h" | 18 #include "third_party/skia/include/core/SkPaint.h" |
| 19 #include "third_party/skia/include/core/SkSurface.h" | 19 #include "third_party/skia/include/core/SkSurface.h" |
| 20 #include "third_party/skia/include/gpu/GrContext.h" | 20 #include "third_party/skia/include/gpu/GrContext.h" |
| 21 #include "ui/gl/gl_switches.h" | 21 #include "ui/gl/gl_switches.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 using content::WebGraphicsContext3DCommandBufferImpl; | |
| 26 | |
| 27 const content::CauseForGpuLaunch kInitCause = | 25 const content::CauseForGpuLaunch kInitCause = |
| 28 content:: | 26 content:: |
| 29 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 27 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
| 30 | 28 |
| 31 std::unique_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContext( | 29 scoped_refptr<content::ContextProviderCommandBuffer> CreateContext( |
| 32 gpu::GpuChannelHost* gpu_channel_host) { | 30 gpu::GpuChannelHost* gpu_channel_host) { |
| 33 // This is for an offscreen context, so the default framebuffer doesn't need | 31 // This is for an offscreen context, so the default framebuffer doesn't need |
| 34 // any alpha, depth, stencil, antialiasing. | 32 // any alpha, depth, stencil, antialiasing. |
| 35 gpu::gles2::ContextCreationAttribHelper attributes; | 33 gpu::gles2::ContextCreationAttribHelper attributes; |
| 36 attributes.alpha_size = -1; | 34 attributes.alpha_size = -1; |
| 37 attributes.depth_size = 0; | 35 attributes.depth_size = 0; |
| 38 attributes.stencil_size = 0; | 36 attributes.stencil_size = 0; |
| 39 attributes.samples = 0; | 37 attributes.samples = 0; |
| 40 attributes.sample_buffers = 0; | 38 attributes.sample_buffers = 0; |
| 41 attributes.bind_generates_resource = false; | 39 attributes.bind_generates_resource = false; |
| 42 bool automatic_flushes = false; | 40 bool automatic_flushes = false; |
| 43 return base::WrapUnique(new WebGraphicsContext3DCommandBufferImpl( | 41 return make_scoped_refptr(new content::ContextProviderCommandBuffer( |
| 44 gpu::kNullSurfaceHandle, GURL(), gpu_channel_host, attributes, | 42 base::WrapUnique(new content::WebGraphicsContext3DCommandBufferImpl( |
| 45 gfx::PreferIntegratedGpu, automatic_flushes)); | 43 gpu::kNullSurfaceHandle, GURL(), gpu_channel_host, |
| 44 gfx::PreferIntegratedGpu, automatic_flushes)), |
| 45 gpu::SharedMemoryLimits(), attributes, nullptr, |
| 46 content::command_buffer_metrics::OFFSCREEN_CONTEXT_FOR_TESTING)); |
| 46 } | 47 } |
| 47 | 48 |
| 48 class ContextTestBase : public content::ContentBrowserTest { | 49 class ContextTestBase : public content::ContentBrowserTest { |
| 49 public: | 50 public: |
| 50 void SetUpOnMainThread() override { | 51 void SetUpOnMainThread() override { |
| 51 // 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 |
| 52 // out. | 53 // out. |
| 53 if (!content::BrowserGpuChannelHostFactory::CanUseForTesting()) | 54 if (!content::BrowserGpuChannelHostFactory::CanUseForTesting()) |
| 54 return; | 55 return; |
| 55 | 56 |
| 56 if (!content::BrowserGpuChannelHostFactory::instance()) | 57 if (!content::BrowserGpuChannelHostFactory::instance()) |
| 57 content::BrowserGpuChannelHostFactory::Initialize(true); | 58 content::BrowserGpuChannelHostFactory::Initialize(true); |
| 58 | 59 |
| 59 content::BrowserGpuChannelHostFactory* factory = | 60 content::BrowserGpuChannelHostFactory* factory = |
| 60 content::BrowserGpuChannelHostFactory::instance(); | 61 content::BrowserGpuChannelHostFactory::instance(); |
| 61 CHECK(factory); | 62 CHECK(factory); |
| 62 base::RunLoop run_loop; | 63 base::RunLoop run_loop; |
| 63 factory->EstablishGpuChannel(kInitCause, run_loop.QuitClosure()); | 64 factory->EstablishGpuChannel(kInitCause, run_loop.QuitClosure()); |
| 64 run_loop.Run(); | 65 run_loop.Run(); |
| 65 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( | 66 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( |
| 66 factory->GetGpuChannel()); | 67 factory->GetGpuChannel()); |
| 67 CHECK(gpu_channel_host); | 68 CHECK(gpu_channel_host); |
| 68 | 69 |
| 69 provider_ = new content::ContextProviderCommandBuffer( | 70 provider_ = CreateContext(gpu_channel_host.get()); |
| 70 CreateContext(gpu_channel_host.get()), gpu::SharedMemoryLimits(), | |
| 71 nullptr, content::OFFSCREEN_CONTEXT_FOR_TESTING); | |
| 72 bool bound = provider_->BindToCurrentThread(); | 71 bool bound = provider_->BindToCurrentThread(); |
| 73 CHECK(bound); | 72 CHECK(bound); |
| 74 gl_ = provider_->ContextGL(); | 73 gl_ = provider_->ContextGL(); |
| 75 context_support_ = provider_->ContextSupport(); | 74 context_support_ = provider_->ContextSupport(); |
| 76 | 75 |
| 77 ContentBrowserTest::SetUpOnMainThread(); | 76 ContentBrowserTest::SetUpOnMainThread(); |
| 78 } | 77 } |
| 79 | 78 |
| 80 void TearDownOnMainThread() override { | 79 void TearDownOnMainThread() override { |
| 81 // Must delete the context first. | 80 // Must delete the context first. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // a ContextProviderCommandBuffer will keep the gpu channel alive after the | 217 // a ContextProviderCommandBuffer will keep the gpu channel alive after the |
| 219 // provider has been destroyed. Without this behavior, user code would have | 218 // provider has been destroyed. Without this behavior, user code would have |
| 220 // to be careful to destroy objects in the right order to avoid using freed | 219 // to be careful to destroy objects in the right order to avoid using freed |
| 221 // memory as a function pointer in the GrContext's GrGLInterface instance. | 220 // memory as a function pointer in the GrContext's GrGLInterface instance. |
| 222 DCHECK(!IsChannelEstablished()); | 221 DCHECK(!IsChannelEstablished()); |
| 223 EstablishAndWait(); | 222 EstablishAndWait(); |
| 224 | 223 |
| 225 // Step 2: verify that holding onto the provider's GrContext will | 224 // Step 2: verify that holding onto the provider's GrContext will |
| 226 // retain the host after provider is destroyed. | 225 // retain the host after provider is destroyed. |
| 227 scoped_refptr<ContextProviderCommandBuffer> provider = | 226 scoped_refptr<ContextProviderCommandBuffer> provider = |
| 228 new ContextProviderCommandBuffer(CreateContext(GetGpuChannel()), | 227 CreateContext(GetGpuChannel()); |
| 229 gpu::SharedMemoryLimits(), nullptr, | |
| 230 OFFSCREEN_CONTEXT_FOR_TESTING); | |
| 231 EXPECT_TRUE(provider->BindToCurrentThread()); | 228 EXPECT_TRUE(provider->BindToCurrentThread()); |
| 232 | 229 |
| 233 sk_sp<GrContext> gr_context = sk_ref_sp(provider->GrContext()); | 230 sk_sp<GrContext> gr_context = sk_ref_sp(provider->GrContext()); |
| 234 | 231 |
| 235 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 232 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
| 236 sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget( | 233 sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget( |
| 237 gr_context.get(), SkBudgeted::kNo, info); | 234 gr_context.get(), SkBudgeted::kNo, info); |
| 238 EXPECT_TRUE(surface); | 235 EXPECT_TRUE(surface); |
| 239 | 236 |
| 240 // Destroy the GL context after we made a surface. | 237 // Destroy the GL context after we made a surface. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 267 #else | 264 #else |
| 268 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover | 265 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover |
| 269 #endif | 266 #endif |
| 270 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, | 267 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, |
| 271 MAYBE_CrashAndRecover) { | 268 MAYBE_CrashAndRecover) { |
| 272 DCHECK(!IsChannelEstablished()); | 269 DCHECK(!IsChannelEstablished()); |
| 273 EstablishAndWait(); | 270 EstablishAndWait(); |
| 274 scoped_refptr<gpu::GpuChannelHost> host = GetGpuChannel(); | 271 scoped_refptr<gpu::GpuChannelHost> host = GetGpuChannel(); |
| 275 | 272 |
| 276 scoped_refptr<ContextProviderCommandBuffer> provider = | 273 scoped_refptr<ContextProviderCommandBuffer> provider = |
| 277 new ContextProviderCommandBuffer(CreateContext(GetGpuChannel()), | 274 CreateContext(GetGpuChannel()); |
| 278 gpu::SharedMemoryLimits(), nullptr, | |
| 279 OFFSCREEN_CONTEXT_FOR_TESTING); | |
| 280 base::RunLoop run_loop; | 275 base::RunLoop run_loop; |
| 281 int counter = 0; | 276 int counter = 0; |
| 282 provider->SetLostContextCallback( | 277 provider->SetLostContextCallback( |
| 283 base::Bind(&BrowserGpuChannelHostFactoryTest::OnContextLost, | 278 base::Bind(&BrowserGpuChannelHostFactoryTest::OnContextLost, |
| 284 base::Unretained(this), run_loop.QuitClosure(), &counter)); | 279 base::Unretained(this), run_loop.QuitClosure(), &counter)); |
| 285 EXPECT_TRUE(provider->BindToCurrentThread()); | 280 EXPECT_TRUE(provider->BindToCurrentThread()); |
| 286 GpuProcessHostUIShim* shim = | 281 GpuProcessHostUIShim* shim = |
| 287 GpuProcessHostUIShim::FromID(GetFactory()->GpuProcessHostId()); | 282 GpuProcessHostUIShim::FromID(GetFactory()->GpuProcessHostId()); |
| 288 EXPECT_TRUE(shim != NULL); | 283 EXPECT_TRUE(shim != NULL); |
| 289 shim->SimulateCrash(); | 284 shim->SimulateCrash(); |
| 290 run_loop.Run(); | 285 run_loop.Run(); |
| 291 | 286 |
| 292 EXPECT_EQ(1, counter); | 287 EXPECT_EQ(1, counter); |
| 293 EXPECT_FALSE(IsChannelEstablished()); | 288 EXPECT_FALSE(IsChannelEstablished()); |
| 294 EstablishAndWait(); | 289 EstablishAndWait(); |
| 295 EXPECT_TRUE(IsChannelEstablished()); | 290 EXPECT_TRUE(IsChannelEstablished()); |
| 296 } | 291 } |
| 297 | 292 |
| 298 } // namespace content | 293 } // namespace content |
| OLD | NEW |