diff options
author | sievers@chromium.org <sievers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-15 21:59:24 +0000 |
---|---|---|
committer | sievers@chromium.org <sievers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-15 21:59:24 +0000 |
commit | 9cf895b669bc8f28b173816f3b3332f33c64d771 (patch) | |
tree | 72cf41418451a56da58d253fa6fb4ad7f863ce9e /content/browser/gpu/gpu_ipc_browsertests.cc | |
parent | c8fafab0cc74036e8c8b7c59615a4d3ab0bd1018 (diff) | |
download | chromium_src-9cf895b669bc8f28b173816f3b3332f33c64d771.zip chromium_src-9cf895b669bc8f28b173816f3b3332f33c64d771.tar.gz chromium_src-9cf895b669bc8f28b173816f3b3332f33c64d771.tar.bz2 |
Allow asynchronous GPU context creation for browser clients
This moves the call to establish a GPU channel out of WGC3D.
It adds an asynchronous method to BrowserGpuChannelHostFactory
that registers callbacks that are run on the main thread once
the channel is established.
This is prerequisite work for asynchronous OutputSurface creation.
BUG=270179,125248,235300
R=piman@chromium.org
Review URL: https://codereview.chromium.org/26959002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@228777 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/gpu/gpu_ipc_browsertests.cc')
-rw-r--r-- | content/browser/gpu/gpu_ipc_browsertests.cc | 147 |
1 files changed, 144 insertions, 3 deletions
diff --git a/content/browser/gpu/gpu_ipc_browsertests.cc b/content/browser/gpu/gpu_ipc_browsertests.cc index 0ee93db..3fda855 100644 --- a/content/browser/gpu/gpu_ipc_browsertests.cc +++ b/content/browser/gpu/gpu_ipc_browsertests.cc @@ -3,8 +3,13 @@ // found in the LICENSE file. #include "base/command_line.h" +#include "base/run_loop.h" #include "content/browser/gpu/browser_gpu_channel_host_factory.h" +#include "content/browser/gpu/gpu_process_host_ui_shim.h" +#include "content/common/gpu/client/context_provider_command_buffer.h" #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" +#include "content/common/gpu/gpu_process_launch_causes.h" +#include "content/public/browser/browser_thread.h" #include "content/public/common/content_switches.h" #include "content/test/content_browser_test.h" #include "ui/gl/gl_switches.h" @@ -15,10 +20,19 @@ namespace { class ContextTestBase : public content::ContentBrowserTest { public: virtual void SetUpOnMainThread() OVERRIDE { - CHECK(content::BrowserGpuChannelHostFactory::instance()); + if (!content::BrowserGpuChannelHostFactory::instance()) + content::BrowserGpuChannelHostFactory::Initialize(true); + + content::BrowserGpuChannelHostFactory* factory = + content::BrowserGpuChannelHostFactory::instance(); + CHECK(factory); + scoped_refptr<content::GpuChannelHost> gpu_channel_host( + factory->EstablishGpuChannelSync( + content:: + CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)); context_.reset( content::WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( - content::BrowserGpuChannelHostFactory::instance(), + gpu_channel_host.get(), WebKit::WebGraphicsContext3D::Attributes(), GURL())); CHECK(context_.get()); @@ -38,6 +52,133 @@ class ContextTestBase : public content::ContentBrowserTest { } // namespace -// Include the actual tests. +// Include the shared tests. #define CONTEXT_TEST_F IN_PROC_BROWSER_TEST_F #include "content/common/gpu/client/gpu_context_tests.h" + +namespace content { + +class BrowserGpuChannelHostFactoryTest : public ContextTestBase { + public: + virtual void SetUpOnMainThread() OVERRIDE { + // Start all tests without a gpu channel so that the tests exercise a + // consistent codepath. + if (!content::BrowserGpuChannelHostFactory::instance()) + content::BrowserGpuChannelHostFactory::Initialize(false); + + CHECK(GetFactory()); + + ContentBrowserTest::SetUpOnMainThread(); + } + + virtual void TearDownOnMainThread() OVERRIDE { + ContextTestBase::TearDownOnMainThread(); + } + + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + // Start all tests without a gpu channel so that the tests exercise a + // consistent codepath. + command_line->AppendSwitch(switches::kDisableGpuProcessPrelaunch); + } + + void OnContextLost(const base::Closure callback, int* counter) { + (*counter)++; + callback.Run(); + } + + protected: + BrowserGpuChannelHostFactory* GetFactory() { + return BrowserGpuChannelHostFactory::instance(); + } + + bool IsChannelEstablished() { + return GetFactory()->GetGpuChannel() != NULL; + } + + void EstablishAndWait() { + base::RunLoop run_loop; + GetFactory()->EstablishGpuChannel( + CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE, + run_loop.QuitClosure()); + run_loop.Run(); + } + + GpuChannelHost* GetGpuChannel() { + return GetFactory()->GetGpuChannel(); + } + + static void Signal(bool *event) { + CHECK_EQ(*event, false); + *event = true; + } + + scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContext() { + return make_scoped_ptr( + WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( + GetGpuChannel(), + WebKit::WebGraphicsContext3D::Attributes(), + GURL())); + } +}; + +IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, Basic) { + DCHECK(!IsChannelEstablished()); + EstablishAndWait(); + EXPECT_TRUE(GetGpuChannel() != NULL); +} + +IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, + EstablishAndTerminate) { + DCHECK(!IsChannelEstablished()); + base::RunLoop run_loop; + GetFactory()->EstablishGpuChannel( + CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE, + run_loop.QuitClosure()); + GetFactory()->Terminate(); + + // The callback should still trigger. + run_loop.Run(); +} + +IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, AlreadyEstablished) { + DCHECK(!IsChannelEstablished()); + scoped_refptr<GpuChannelHost> gpu_channel = + GetFactory()->EstablishGpuChannelSync( + CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE); + + // Expect established callback immediately. + bool event = false; + GetFactory()->EstablishGpuChannel( + CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE, + base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event)); + EXPECT_TRUE(event); + EXPECT_EQ(gpu_channel, GetGpuChannel()); +} + +IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, CrashAndRecover) { + DCHECK(!IsChannelEstablished()); + EstablishAndWait(); + scoped_refptr<GpuChannelHost> host = GetGpuChannel(); + + scoped_refptr<ContextProviderCommandBuffer> provider = + ContextProviderCommandBuffer::Create(CreateContext(), + "BrowserGpuChannelHostFactoryTest"); + base::RunLoop run_loop; + int counter = 0; + provider->SetLostContextCallback( + base::Bind(&BrowserGpuChannelHostFactoryTest::OnContextLost, + base::Unretained(this), run_loop.QuitClosure(), &counter)); + EXPECT_TRUE(provider->BindToCurrentThread()); + GpuProcessHostUIShim* shim = + GpuProcessHostUIShim::FromID(GetFactory()->GpuProcessHostId()); + EXPECT_TRUE(shim != NULL); + shim->SimulateCrash(); + run_loop.Run(); + + EXPECT_EQ(1, counter); + EXPECT_FALSE(IsChannelEstablished()); + EstablishAndWait(); + EXPECT_TRUE(IsChannelEstablished()); +} + +} // namespace content |