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" |
16 #include "ui/gl/gl_switches.h" | 19 #include "ui/gl/gl_switches.h" |
17 | 20 |
18 namespace { | 21 namespace { |
19 | 22 |
20 using content::WebGraphicsContext3DCommandBufferImpl; | 23 using content::WebGraphicsContext3DCommandBufferImpl; |
21 | 24 |
22 const content::CauseForGpuLaunch kInitCause = | 25 const content::CauseForGpuLaunch kInitCause = |
23 content:: | 26 content:: |
24 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 27 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
25 | 28 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 // Expect established callback immediately. | 190 // Expect established callback immediately. |
188 bool event = false; | 191 bool event = false; |
189 GetFactory()->EstablishGpuChannel( | 192 GetFactory()->EstablishGpuChannel( |
190 kInitCause, | 193 kInitCause, |
191 base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event)); | 194 base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event)); |
192 EXPECT_TRUE(event); | 195 EXPECT_TRUE(event); |
193 EXPECT_EQ(gpu_channel.get(), GetGpuChannel()); | 196 EXPECT_EQ(gpu_channel.get(), GetGpuChannel()); |
194 } | 197 } |
195 #endif | 198 #endif |
196 | 199 |
| 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 |
197 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor | 244 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor |
198 // establishes a GPU channel. | 245 // establishes a GPU channel. |
199 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 246 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
200 #define MAYBE_CrashAndRecover | 247 #define MAYBE_CrashAndRecover |
201 #else | 248 #else |
202 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover | 249 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover |
203 #endif | 250 #endif |
204 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, | 251 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, |
205 MAYBE_CrashAndRecover) { | 252 MAYBE_CrashAndRecover) { |
206 DCHECK(!IsChannelEstablished()); | 253 DCHECK(!IsChannelEstablished()); |
(...skipping 15 matching lines...) Expand all Loading... |
222 shim->SimulateCrash(); | 269 shim->SimulateCrash(); |
223 run_loop.Run(); | 270 run_loop.Run(); |
224 | 271 |
225 EXPECT_EQ(1, counter); | 272 EXPECT_EQ(1, counter); |
226 EXPECT_FALSE(IsChannelEstablished()); | 273 EXPECT_FALSE(IsChannelEstablished()); |
227 EstablishAndWait(); | 274 EstablishAndWait(); |
228 EXPECT_TRUE(IsChannelEstablished()); | 275 EXPECT_TRUE(IsChannelEstablished()); |
229 } | 276 } |
230 | 277 |
231 } // namespace content | 278 } // namespace content |
OLD | NEW |