| 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 "content/browser/gpu/browser_gpu_channel_host_factory.h" | 7 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 
| 8 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 8 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 
| 9 #include "content/common/gpu/client/context_provider_command_buffer.h" | 9 #include "content/common/gpu/client/context_provider_command_buffer.h" | 
| 10 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 10 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 
| 11 #include "content/common/gpu/gpu_process_launch_causes.h" | 11 #include "content/common/gpu/gpu_process_launch_causes.h" | 
| 12 #include "content/public/browser/gpu_data_manager.h" | 12 #include "content/public/browser/gpu_data_manager.h" | 
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" | 
| 14 #include "content/public/test/content_browser_test.h" | 14 #include "content/public/test/content_browser_test.h" | 
| 15 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" | 15 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" | 
| 16 #include "third_party/skia/include/core/SkCanvas.h" |  | 
| 17 #include "third_party/skia/include/core/SkSurface.h" |  | 
| 18 #include "third_party/skia/include/gpu/GrContext.h" |  | 
| 19 #include "ui/gl/gl_switches.h" | 16 #include "ui/gl/gl_switches.h" | 
| 20 | 17 | 
| 21 namespace { | 18 namespace { | 
| 22 | 19 | 
| 23 using content::WebGraphicsContext3DCommandBufferImpl; | 20 using content::WebGraphicsContext3DCommandBufferImpl; | 
| 24 | 21 | 
| 25 const content::CauseForGpuLaunch kInitCause = | 22 const content::CauseForGpuLaunch kInitCause = | 
| 26     content:: | 23     content:: | 
| 27         CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 24         CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 
| 28 | 25 | 
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 190   // Expect established callback immediately. | 187   // Expect established callback immediately. | 
| 191   bool event = false; | 188   bool event = false; | 
| 192   GetFactory()->EstablishGpuChannel( | 189   GetFactory()->EstablishGpuChannel( | 
| 193       kInitCause, | 190       kInitCause, | 
| 194       base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event)); | 191       base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event)); | 
| 195   EXPECT_TRUE(event); | 192   EXPECT_TRUE(event); | 
| 196   EXPECT_EQ(gpu_channel.get(), GetGpuChannel()); | 193   EXPECT_EQ(gpu_channel.get(), GetGpuChannel()); | 
| 197 } | 194 } | 
| 198 #endif | 195 #endif | 
| 199 | 196 | 
| 200 // Test fails on Windows because GPU Channel set-up does not work. |  | 
| 201 #if !defined(OS_WIN) |  | 
| 202 #define MAYBE_GrContextKeepsGpuChannelAlive GrContextKeepsGpuChannelAlive |  | 
| 203 #else |  | 
| 204 #define MAYBE_GrContextKeepsGpuChannelAlive \ |  | 
| 205     DISABLED_GrContextKeepsGpuChannelAlive |  | 
| 206 #endif |  | 
| 207 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, |  | 
| 208                        MAYBE_GrContextKeepsGpuChannelAlive) { |  | 
| 209   // Test for crbug.com/551143 |  | 
| 210   // This test verifies that holding a reference to the GrContext created by |  | 
| 211   // a ContextProviderCommandBuffer will keep the gpu channel alive after the |  | 
| 212   // provider has been destroyed. Without this behavior, user code would have |  | 
| 213   // to be careful to destroy objects in the right order to avoid using freed |  | 
| 214   // memory as a function pointer in the GrContext's GrGLInterface instance. |  | 
| 215   DCHECK(!IsChannelEstablished()); |  | 
| 216   EstablishAndWait(); |  | 
| 217 |  | 
| 218   // Step 2: verify that holding onto the provider's GrContext will |  | 
| 219   // retain the host after provider is destroyed. |  | 
| 220   scoped_refptr<ContextProviderCommandBuffer> provider = |  | 
| 221       ContextProviderCommandBuffer::Create(CreateContext(), |  | 
| 222                                            OFFSCREEN_CONTEXT_FOR_TESTING); |  | 
| 223   EXPECT_TRUE(provider->BindToCurrentThread()); |  | 
| 224 |  | 
| 225   skia::RefPtr<GrContext> gr_context = skia::SharePtr(provider->GrContext()); |  | 
| 226   provider = nullptr; |  | 
| 227 |  | 
| 228   SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |  | 
| 229   skia::RefPtr<SkSurface> surface = skia::AdoptRef(SkSurface::NewRenderTarget( |  | 
| 230       gr_context.get(), SkSurface::kNo_Budgeted, info)); |  | 
| 231   gr_context = nullptr; |  | 
| 232 |  | 
| 233   // use the canvas after the provider and grcontext have been locally |  | 
| 234   // unref'ed. This should work just fine thanks to SkSurface_Gpu ref'ing |  | 
| 235   // the GrContext, which is ref'ing the GrGLInterfaceForWebGraphicsContext3D, |  | 
| 236   // which owns the commandbuffer instance. |  | 
| 237   SkPaint greenFillPaint; |  | 
| 238   greenFillPaint.setColor(SK_ColorGREEN); |  | 
| 239   greenFillPaint.setStyle(SkPaint::kFill_Style); |  | 
| 240   // Passes by not crashing |  | 
| 241   surface->getCanvas()->drawRect(SkRect::MakeWH(100, 100), greenFillPaint); |  | 
| 242 } |  | 
| 243 |  | 
| 244 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor | 197 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor | 
| 245 // establishes a GPU channel. | 198 // establishes a GPU channel. | 
| 246 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 199 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 
| 247 #define MAYBE_CrashAndRecover | 200 #define MAYBE_CrashAndRecover | 
| 248 #else | 201 #else | 
| 249 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover | 202 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover | 
| 250 #endif | 203 #endif | 
| 251 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, | 204 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, | 
| 252                        MAYBE_CrashAndRecover) { | 205                        MAYBE_CrashAndRecover) { | 
| 253   DCHECK(!IsChannelEstablished()); | 206   DCHECK(!IsChannelEstablished()); | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 269   shim->SimulateCrash(); | 222   shim->SimulateCrash(); | 
| 270   run_loop.Run(); | 223   run_loop.Run(); | 
| 271 | 224 | 
| 272   EXPECT_EQ(1, counter); | 225   EXPECT_EQ(1, counter); | 
| 273   EXPECT_FALSE(IsChannelEstablished()); | 226   EXPECT_FALSE(IsChannelEstablished()); | 
| 274   EstablishAndWait(); | 227   EstablishAndWait(); | 
| 275   EXPECT_TRUE(IsChannelEstablished()); | 228   EXPECT_TRUE(IsChannelEstablished()); | 
| 276 } | 229 } | 
| 277 | 230 | 
| 278 }  // namespace content | 231 }  // namespace content | 
| OLD | NEW | 
|---|