| 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/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 8 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 9 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 9 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 10 #include "content/common/gpu/client/context_provider_command_buffer.h" | 10 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 using content::WebGraphicsContext3DCommandBufferImpl; | 24 using content::WebGraphicsContext3DCommandBufferImpl; |
| 25 | 25 |
| 26 const content::CauseForGpuLaunch kInitCause = | 26 const content::CauseForGpuLaunch kInitCause = |
| 27 content:: | 27 content:: |
| 28 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 28 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
| 29 | 29 |
| 30 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContext( | 30 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContext( |
| 31 content::GpuChannelHost* gpu_channel_host) { | 31 gpu::GpuChannelHost* gpu_channel_host) { |
| 32 // This is for an offscreen context, so the default framebuffer doesn't need | 32 // This is for an offscreen context, so the default framebuffer doesn't need |
| 33 // any alpha, depth, stencil, antialiasing. | 33 // any alpha, depth, stencil, antialiasing. |
| 34 gpu::gles2::ContextCreationAttribHelper attributes; | 34 gpu::gles2::ContextCreationAttribHelper attributes; |
| 35 attributes.alpha_size = -1; | 35 attributes.alpha_size = -1; |
| 36 attributes.depth_size = 0; | 36 attributes.depth_size = 0; |
| 37 attributes.stencil_size = 0; | 37 attributes.stencil_size = 0; |
| 38 attributes.samples = 0; | 38 attributes.samples = 0; |
| 39 attributes.sample_buffers = 0; | 39 attributes.sample_buffers = 0; |
| 40 attributes.bind_generates_resource = false; | 40 attributes.bind_generates_resource = false; |
| 41 bool share_resources = false; | 41 bool share_resources = false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 58 | 58 |
| 59 if (!content::BrowserGpuChannelHostFactory::instance()) | 59 if (!content::BrowserGpuChannelHostFactory::instance()) |
| 60 content::BrowserGpuChannelHostFactory::Initialize(true); | 60 content::BrowserGpuChannelHostFactory::Initialize(true); |
| 61 | 61 |
| 62 content::BrowserGpuChannelHostFactory* factory = | 62 content::BrowserGpuChannelHostFactory* factory = |
| 63 content::BrowserGpuChannelHostFactory::instance(); | 63 content::BrowserGpuChannelHostFactory::instance(); |
| 64 CHECK(factory); | 64 CHECK(factory); |
| 65 base::RunLoop run_loop; | 65 base::RunLoop run_loop; |
| 66 factory->EstablishGpuChannel(kInitCause, run_loop.QuitClosure()); | 66 factory->EstablishGpuChannel(kInitCause, run_loop.QuitClosure()); |
| 67 run_loop.Run(); | 67 run_loop.Run(); |
| 68 scoped_refptr<content::GpuChannelHost> | 68 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( |
| 69 gpu_channel_host(factory->GetGpuChannel()); | 69 factory->GetGpuChannel()); |
| 70 CHECK(gpu_channel_host); | 70 CHECK(gpu_channel_host); |
| 71 | 71 |
| 72 provider_ = content::ContextProviderCommandBuffer::Create( | 72 provider_ = content::ContextProviderCommandBuffer::Create( |
| 73 CreateContext(gpu_channel_host.get()), | 73 CreateContext(gpu_channel_host.get()), |
| 74 content::OFFSCREEN_CONTEXT_FOR_TESTING); | 74 content::OFFSCREEN_CONTEXT_FOR_TESTING); |
| 75 bool bound = provider_->BindToCurrentThread(); | 75 bool bound = provider_->BindToCurrentThread(); |
| 76 CHECK(bound); | 76 CHECK(bound); |
| 77 gl_ = provider_->ContextGL(); | 77 gl_ = provider_->ContextGL(); |
| 78 context_support_ = provider_->ContextSupport(); | 78 context_support_ = provider_->ContextSupport(); |
| 79 | 79 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 bool IsChannelEstablished() { | 137 bool IsChannelEstablished() { |
| 138 return GetFactory()->GetGpuChannel() != NULL; | 138 return GetFactory()->GetGpuChannel() != NULL; |
| 139 } | 139 } |
| 140 | 140 |
| 141 void EstablishAndWait() { | 141 void EstablishAndWait() { |
| 142 base::RunLoop run_loop; | 142 base::RunLoop run_loop; |
| 143 GetFactory()->EstablishGpuChannel(kInitCause, run_loop.QuitClosure()); | 143 GetFactory()->EstablishGpuChannel(kInitCause, run_loop.QuitClosure()); |
| 144 run_loop.Run(); | 144 run_loop.Run(); |
| 145 } | 145 } |
| 146 | 146 |
| 147 GpuChannelHost* GetGpuChannel() { | 147 gpu::GpuChannelHost* GetGpuChannel() { return GetFactory()->GetGpuChannel(); } |
| 148 return GetFactory()->GetGpuChannel(); | |
| 149 } | |
| 150 | 148 |
| 151 static void Signal(bool *event) { | 149 static void Signal(bool *event) { |
| 152 CHECK_EQ(*event, false); | 150 CHECK_EQ(*event, false); |
| 153 *event = true; | 151 *event = true; |
| 154 } | 152 } |
| 155 }; | 153 }; |
| 156 | 154 |
| 157 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor | 155 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor |
| 158 // establishes a GPU channel. | 156 // establishes a GPU channel. |
| 159 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 157 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 189 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor | 187 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor |
| 190 // establishes a GPU channel. | 188 // establishes a GPU channel. |
| 191 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 189 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 192 #define MAYBE_AlreadyEstablished AlreadyEstablished | 190 #define MAYBE_AlreadyEstablished AlreadyEstablished |
| 193 #else | 191 #else |
| 194 #define MAYBE_AlreadyEstablished DISABLED_AlreadyEstablished | 192 #define MAYBE_AlreadyEstablished DISABLED_AlreadyEstablished |
| 195 #endif | 193 #endif |
| 196 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, | 194 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, |
| 197 MAYBE_AlreadyEstablished) { | 195 MAYBE_AlreadyEstablished) { |
| 198 DCHECK(!IsChannelEstablished()); | 196 DCHECK(!IsChannelEstablished()); |
| 199 scoped_refptr<GpuChannelHost> gpu_channel = | 197 scoped_refptr<gpu::GpuChannelHost> gpu_channel = |
| 200 GetFactory()->EstablishGpuChannelSync(kInitCause); | 198 GetFactory()->EstablishGpuChannelSync(kInitCause); |
| 201 | 199 |
| 202 // Expect established callback immediately. | 200 // Expect established callback immediately. |
| 203 bool event = false; | 201 bool event = false; |
| 204 GetFactory()->EstablishGpuChannel( | 202 GetFactory()->EstablishGpuChannel( |
| 205 kInitCause, | 203 kInitCause, |
| 206 base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event)); | 204 base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event)); |
| 207 EXPECT_TRUE(event); | 205 EXPECT_TRUE(event); |
| 208 EXPECT_EQ(gpu_channel.get(), GetGpuChannel()); | 206 EXPECT_EQ(gpu_channel.get(), GetGpuChannel()); |
| 209 } | 207 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 // establishes a GPU channel. | 255 // establishes a GPU channel. |
| 258 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 256 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 259 #define MAYBE_CrashAndRecover | 257 #define MAYBE_CrashAndRecover |
| 260 #else | 258 #else |
| 261 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover | 259 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover |
| 262 #endif | 260 #endif |
| 263 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, | 261 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, |
| 264 MAYBE_CrashAndRecover) { | 262 MAYBE_CrashAndRecover) { |
| 265 DCHECK(!IsChannelEstablished()); | 263 DCHECK(!IsChannelEstablished()); |
| 266 EstablishAndWait(); | 264 EstablishAndWait(); |
| 267 scoped_refptr<GpuChannelHost> host = GetGpuChannel(); | 265 scoped_refptr<gpu::GpuChannelHost> host = GetGpuChannel(); |
| 268 | 266 |
| 269 scoped_refptr<ContextProviderCommandBuffer> provider = | 267 scoped_refptr<ContextProviderCommandBuffer> provider = |
| 270 ContextProviderCommandBuffer::Create(CreateContext(GetGpuChannel()), | 268 ContextProviderCommandBuffer::Create(CreateContext(GetGpuChannel()), |
| 271 OFFSCREEN_CONTEXT_FOR_TESTING); | 269 OFFSCREEN_CONTEXT_FOR_TESTING); |
| 272 base::RunLoop run_loop; | 270 base::RunLoop run_loop; |
| 273 int counter = 0; | 271 int counter = 0; |
| 274 provider->SetLostContextCallback( | 272 provider->SetLostContextCallback( |
| 275 base::Bind(&BrowserGpuChannelHostFactoryTest::OnContextLost, | 273 base::Bind(&BrowserGpuChannelHostFactoryTest::OnContextLost, |
| 276 base::Unretained(this), run_loop.QuitClosure(), &counter)); | 274 base::Unretained(this), run_loop.QuitClosure(), &counter)); |
| 277 EXPECT_TRUE(provider->BindToCurrentThread()); | 275 EXPECT_TRUE(provider->BindToCurrentThread()); |
| 278 GpuProcessHostUIShim* shim = | 276 GpuProcessHostUIShim* shim = |
| 279 GpuProcessHostUIShim::FromID(GetFactory()->GpuProcessHostId()); | 277 GpuProcessHostUIShim::FromID(GetFactory()->GpuProcessHostId()); |
| 280 EXPECT_TRUE(shim != NULL); | 278 EXPECT_TRUE(shim != NULL); |
| 281 shim->SimulateCrash(); | 279 shim->SimulateCrash(); |
| 282 run_loop.Run(); | 280 run_loop.Run(); |
| 283 | 281 |
| 284 EXPECT_EQ(1, counter); | 282 EXPECT_EQ(1, counter); |
| 285 EXPECT_FALSE(IsChannelEstablished()); | 283 EXPECT_FALSE(IsChannelEstablished()); |
| 286 EstablishAndWait(); | 284 EstablishAndWait(); |
| 287 EXPECT_TRUE(IsChannelEstablished()); | 285 EXPECT_TRUE(IsChannelEstablished()); |
| 288 } | 286 } |
| 289 | 287 |
| 290 } // namespace content | 288 } // namespace content |
| OLD | NEW |