Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: content/browser/gpu/gpu_ipc_browsertests.cc

Issue 1414683003: Fix gpu command buffer use after free by GrContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix android webview build + browser test Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
197 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor 200 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor
198 // establishes a GPU channel. 201 // establishes a GPU channel.
199 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 202 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
203 #define MAYBE_GrContextKeepsGpuChannelAlive GrContextKeepsGpuChannelAlive
204 #else
205 #define MAYBE_GrContextKeepsGpuChannelAlive \
206 DISABLED_GrContextKeepsGpuChannelAlive
207 #endif
208 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest,
209 MAYBE_GrContextKeepsGpuChannelAlive) {
Ken Russell (switch to Gerrit) 2015/11/11 19:16:51 It looks like this new test's failing on some of t
210 // Test for crbug.com/551143
211 // This test verifies that holding a reference to the GrContext created by
212 // a ContextProviderCommandBuffer will keep the gpu channel alive after the
213 // provider has been destroyed. Without this behavior, user code would have
214 // to be careful to destroy objects in the right order to avoid using freed
215 // memory as a function pointer in the GrContext's GrGLInterface instance.
216 DCHECK(!IsChannelEstablished());
217 EstablishAndWait();
218
219 // Step 2: verify that holding onto the provider's GrContext will
220 // retain the host after provider is destroyed.
221 scoped_refptr<ContextProviderCommandBuffer> provider =
222 ContextProviderCommandBuffer::Create(CreateContext(),
223 OFFSCREEN_CONTEXT_FOR_TESTING);
224 EXPECT_TRUE(provider->BindToCurrentThread());
225
226 skia::RefPtr<GrContext> gr_context = skia::SharePtr(provider->GrContext());
227 provider = nullptr;
228
229 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
230 skia::RefPtr<SkSurface> surface = skia::AdoptRef(SkSurface::NewRenderTarget(
231 gr_context.get(), SkSurface::kNo_Budgeted, info));
232 gr_context = nullptr;
233
234 // use the canvas after the provider and grcontext have been locally
235 // unref'ed. This should work just fine thanks to SkSurface_Gpu ref'ing
236 // the GrContext, which is ref'ing the GrGLInterfaceForWebGraphicsContext3D,
237 // which owns the commandbuffer instance.
238 surface->getCanvas()->clear(SK_ColorGREEN);
239 SkColor readback;
240 surface->getCanvas()->readPixels(info, &readback, sizeof(SkColor), 0, 0);
241 EXPECT_EQ(SK_ColorGREEN, readback);
242 }
243
244 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor
245 // establishes a GPU channel.
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());
207 EstablishAndWait(); 254 EstablishAndWait();
208 scoped_refptr<GpuChannelHost> host = GetGpuChannel(); 255 scoped_refptr<GpuChannelHost> host = GetGpuChannel();
209 256
(...skipping 12 matching lines...) Expand all
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698