Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / browser / compositor / gpu_process_transport_factory.cc
blobf2d1b3924d8dda6b3520fb81a3e7996496477671
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/compositor/gpu_process_transport_factory.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "base/command_line.h"
11 #include "base/location.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/metrics/histogram.h"
14 #include "base/profiler/scoped_tracker.h"
15 #include "base/threading/simple_thread.h"
16 #include "base/threading/thread.h"
17 #include "cc/output/compositor_frame.h"
18 #include "cc/output/output_surface.h"
19 #include "cc/resources/task_graph_runner.h"
20 #include "cc/surfaces/onscreen_display_client.h"
21 #include "cc/surfaces/surface_display_output_surface.h"
22 #include "cc/surfaces/surface_manager.h"
23 #include "content/browser/compositor/browser_compositor_output_surface.h"
24 #include "content/browser/compositor/browser_compositor_overlay_candidate_validator.h"
25 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h"
26 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_surface.h"
27 #include "content/browser/compositor/reflector_impl.h"
28 #include "content/browser/compositor/software_browser_compositor_output_surface.h"
29 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
30 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
31 #include "content/browser/gpu/compositor_util.h"
32 #include "content/browser/gpu/gpu_data_manager_impl.h"
33 #include "content/browser/gpu/gpu_surface_tracker.h"
34 #include "content/browser/renderer_host/render_widget_host_impl.h"
35 #include "content/common/gpu/client/context_provider_command_buffer.h"
36 #include "content/common/gpu/client/gl_helper.h"
37 #include "content/common/gpu/client/gpu_channel_host.h"
38 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
39 #include "content/common/gpu/gpu_process_launch_causes.h"
40 #include "content/common/host_shared_bitmap_manager.h"
41 #include "content/public/common/content_switches.h"
42 #include "gpu/GLES2/gl2extchromium.h"
43 #include "gpu/command_buffer/client/gles2_interface.h"
44 #include "gpu/command_buffer/common/mailbox.h"
45 #include "third_party/khronos/GLES2/gl2.h"
46 #include "ui/compositor/compositor.h"
47 #include "ui/compositor/compositor_constants.h"
48 #include "ui/compositor/compositor_switches.h"
49 #include "ui/gfx/geometry/size.h"
50 #include "ui/gfx/native_widget_types.h"
52 #if defined(OS_WIN)
53 #include "content/browser/compositor/software_output_device_win.h"
54 #elif defined(USE_OZONE)
55 #include "content/browser/compositor/browser_compositor_overlay_candidate_validator_ozone.h"
56 #include "content/browser/compositor/software_output_device_ozone.h"
57 #include "ui/ozone/public/ozone_switches.h"
58 #include "ui/ozone/public/surface_factory_ozone.h"
59 #elif defined(USE_X11)
60 #include "content/browser/compositor/software_output_device_x11.h"
61 #elif defined(OS_MACOSX)
62 #include "content/browser/compositor/software_output_device_mac.h"
63 #endif
65 using cc::ContextProvider;
66 using gpu::gles2::GLES2Interface;
68 static const int kNumRetriesBeforeSoftwareFallback = 4;
70 namespace content {
71 namespace {
73 class RasterThread : public base::SimpleThread {
74 public:
75 RasterThread(cc::TaskGraphRunner* task_graph_runner)
76 : base::SimpleThread("CompositorTileWorker1"),
77 task_graph_runner_(task_graph_runner) {}
79 // Overridden from base::SimpleThread:
80 void Run() override { task_graph_runner_->Run(); }
82 private:
83 cc::TaskGraphRunner* task_graph_runner_;
85 DISALLOW_COPY_AND_ASSIGN(RasterThread);
88 } // namespace
90 struct GpuProcessTransportFactory::PerCompositorData {
91 int surface_id;
92 BrowserCompositorOutputSurface* surface;
93 ReflectorImpl* reflector;
94 scoped_ptr<cc::OnscreenDisplayClient> display_client;
96 PerCompositorData() : surface_id(0), surface(nullptr), reflector(nullptr) {}
99 GpuProcessTransportFactory::GpuProcessTransportFactory()
100 : next_surface_id_namespace_(1u),
101 task_graph_runner_(new cc::TaskGraphRunner),
102 callback_factory_(this) {
103 if (UseSurfacesEnabled())
104 surface_manager_ = make_scoped_ptr(new cc::SurfaceManager);
106 if (ui::IsUIImplSidePaintingEnabled()) {
107 raster_thread_.reset(new RasterThread(task_graph_runner_.get()));
108 raster_thread_->Start();
112 GpuProcessTransportFactory::~GpuProcessTransportFactory() {
113 DCHECK(per_compositor_data_.empty());
115 // Make sure the lost context callback doesn't try to run during destruction.
116 callback_factory_.InvalidateWeakPtrs();
118 task_graph_runner_->Shutdown();
119 if (raster_thread_)
120 raster_thread_->Join();
123 scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
124 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext() {
125 CauseForGpuLaunch cause =
126 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
127 scoped_refptr<GpuChannelHost> gpu_channel_host(
128 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause));
129 return CreateContextCommon(gpu_channel_host, 0);
132 scoped_ptr<cc::SoftwareOutputDevice> CreateSoftwareOutputDevice(
133 ui::Compositor* compositor) {
134 #if defined(OS_WIN)
135 return scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareOutputDeviceWin(
136 compositor));
137 #elif defined(USE_OZONE)
138 return scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareOutputDeviceOzone(
139 compositor));
140 #elif defined(USE_X11)
141 return scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareOutputDeviceX11(
142 compositor));
143 #elif defined(OS_MACOSX)
144 return scoped_ptr<cc::SoftwareOutputDevice>(
145 new SoftwareOutputDeviceMac(compositor));
146 #else
147 NOTREACHED();
148 return scoped_ptr<cc::SoftwareOutputDevice>();
149 #endif
152 scoped_ptr<BrowserCompositorOverlayCandidateValidator>
153 CreateOverlayCandidateValidator(gfx::AcceleratedWidget widget) {
154 #if defined(USE_OZONE)
155 ui::OverlayCandidatesOzone* overlay_candidates =
156 ui::SurfaceFactoryOzone::GetInstance()->GetOverlayCandidates(widget);
157 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
158 if (overlay_candidates &&
159 (command_line->HasSwitch(switches::kEnableHardwareOverlays) ||
160 command_line->HasSwitch(switches::kOzoneTestSingleOverlaySupport))) {
161 return scoped_ptr<BrowserCompositorOverlayCandidateValidator>(
162 new BrowserCompositorOverlayCandidateValidatorOzone(
163 widget, overlay_candidates));
165 #endif
166 return scoped_ptr<BrowserCompositorOverlayCandidateValidator>();
169 static bool ShouldCreateGpuOutputSurface(ui::Compositor* compositor) {
170 #if defined(OS_CHROMEOS)
171 // Software fallback does not happen on Chrome OS.
172 return true;
173 #endif
175 #if defined(OS_WIN)
176 if (::GetProp(compositor->widget(), kForceSoftwareCompositor) &&
177 ::RemoveProp(compositor->widget(), kForceSoftwareCompositor))
178 return false;
179 #endif
181 return GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor();
184 void GpuProcessTransportFactory::CreateOutputSurface(
185 base::WeakPtr<ui::Compositor> compositor) {
186 DCHECK(!!compositor);
187 PerCompositorData* data = per_compositor_data_[compositor.get()];
188 if (!data) {
189 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/466870
190 // is fixed.
191 tracked_objects::ScopedTracker tracking_profile1(
192 FROM_HERE_WITH_EXPLICIT_FUNCTION(
193 "466870 GpuProcessTransportFactory::CreateOutputSurface1"));
194 data = CreatePerCompositorData(compositor.get());
195 } else {
196 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an
197 // output_surface_map_ here.
198 output_surface_map_.Remove(data->surface_id);
199 data->surface = nullptr;
202 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/466870
203 // is fixed.
204 tracked_objects::ScopedTracker tracking_profile2(
205 FROM_HERE_WITH_EXPLICIT_FUNCTION(
206 "466870 GpuProcessTransportFactory::CreateOutputSurface2"));
208 bool create_gpu_output_surface =
209 ShouldCreateGpuOutputSurface(compositor.get());
210 if (create_gpu_output_surface) {
211 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/466870
212 // is fixed.
213 tracked_objects::ScopedTracker tracking_profile3(
214 FROM_HERE_WITH_EXPLICIT_FUNCTION(
215 "466870 GpuProcessTransportFactory::CreateOutputSurface3"));
217 CauseForGpuLaunch cause =
218 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
219 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel(
220 cause, base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel,
221 callback_factory_.GetWeakPtr(), compositor,
222 create_gpu_output_surface, 0));
223 } else {
224 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/466870
225 // is fixed.
226 tracked_objects::ScopedTracker tracking_profile4(
227 FROM_HERE_WITH_EXPLICIT_FUNCTION(
228 "466870 GpuProcessTransportFactory::CreateOutputSurface4"));
230 EstablishedGpuChannel(compositor, create_gpu_output_surface, 0);
234 void GpuProcessTransportFactory::EstablishedGpuChannel(
235 base::WeakPtr<ui::Compositor> compositor,
236 bool create_gpu_output_surface,
237 int num_attempts) {
238 if (!compositor)
239 return;
240 PerCompositorData* data = per_compositor_data_[compositor.get()];
241 DCHECK(data);
243 if (num_attempts > kNumRetriesBeforeSoftwareFallback) {
244 #if defined(OS_CHROMEOS)
245 LOG(FATAL) << "Unable to create a UI graphics context, and cannot use "
246 << "software compositing on ChromeOS.";
247 #endif
248 create_gpu_output_surface = false;
251 scoped_refptr<ContextProviderCommandBuffer> context_provider;
252 if (create_gpu_output_surface) {
253 scoped_refptr<GpuChannelHost> gpu_channel_host =
254 BrowserGpuChannelHostFactory::instance()->GetGpuChannel();
255 if (gpu_channel_host.get()) {
256 context_provider = ContextProviderCommandBuffer::Create(
257 GpuProcessTransportFactory::CreateContextCommon(gpu_channel_host,
258 data->surface_id),
259 "Compositor");
260 if (context_provider && !context_provider->BindToCurrentThread())
261 context_provider = nullptr;
264 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor",
265 !!context_provider.get());
267 if (!context_provider) {
268 // Try again.
269 CauseForGpuLaunch cause =
270 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
271 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel(
272 cause, base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel,
273 callback_factory_.GetWeakPtr(), compositor,
274 create_gpu_output_surface, num_attempts + 1));
275 return;
279 scoped_ptr<BrowserCompositorOutputSurface> surface;
280 if (!create_gpu_output_surface) {
281 surface = make_scoped_ptr(new SoftwareBrowserCompositorOutputSurface(
282 CreateSoftwareOutputDevice(compositor.get()),
283 compositor->vsync_manager()));
284 } else {
285 DCHECK(context_provider);
286 #if defined(USE_OZONE)
287 if (ui::SurfaceFactoryOzone::GetInstance()
288 ->CanShowPrimaryPlaneAsOverlay()) {
289 surface =
290 make_scoped_ptr(new GpuSurfacelessBrowserCompositorOutputSurface(
291 context_provider, data->surface_id, compositor->vsync_manager(),
292 CreateOverlayCandidateValidator(compositor->widget()), GL_RGB,
293 BrowserGpuMemoryBufferManager::current()));
294 } else
295 #endif
297 surface = make_scoped_ptr(new GpuBrowserCompositorOutputSurface(
298 context_provider, compositor->vsync_manager(),
299 CreateOverlayCandidateValidator(compositor->widget())));
303 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an
304 // output_surface_map_ here.
305 output_surface_map_.AddWithID(surface.get(), data->surface_id);
306 data->surface = surface.get();
307 if (data->reflector)
308 data->reflector->OnSourceSurfaceReady(data->surface);
310 if (!UseSurfacesEnabled()) {
311 compositor->SetOutputSurface(surface.Pass());
312 return;
315 // This gets a bit confusing. Here we have a ContextProvider in the |surface|
316 // configured to render directly to this widget. We need to make an
317 // OnscreenDisplayClient associated with that context, then return a
318 // SurfaceDisplayOutputSurface set up to draw to the display's surface.
319 cc::SurfaceManager* manager = surface_manager_.get();
320 scoped_ptr<cc::OnscreenDisplayClient> display_client(
321 new cc::OnscreenDisplayClient(
322 surface.Pass(), manager, HostSharedBitmapManager::current(),
323 BrowserGpuMemoryBufferManager::current(),
324 compositor->GetRendererSettings(), compositor->task_runner()));
326 scoped_ptr<cc::SurfaceDisplayOutputSurface> output_surface(
327 new cc::SurfaceDisplayOutputSurface(
328 manager, compositor->surface_id_allocator(), context_provider));
329 display_client->set_surface_output_surface(output_surface.get());
330 output_surface->set_display_client(display_client.get());
331 display_client->display()->Resize(compositor->size());
332 data->display_client = display_client.Pass();
333 compositor->SetOutputSurface(output_surface.Pass());
336 scoped_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector(
337 ui::Compositor* source_compositor,
338 ui::Layer* target_layer) {
339 PerCompositorData* source_data = per_compositor_data_[source_compositor];
340 DCHECK(source_data);
342 scoped_ptr<ReflectorImpl> reflector(
343 new ReflectorImpl(source_compositor, target_layer));
344 source_data->reflector = reflector.get();
345 if (BrowserCompositorOutputSurface* source_surface = source_data->surface)
346 reflector->OnSourceSurfaceReady(source_surface);
347 return reflector.Pass();
350 void GpuProcessTransportFactory::RemoveReflector(ui::Reflector* reflector) {
351 ReflectorImpl* reflector_impl = static_cast<ReflectorImpl*>(reflector);
352 PerCompositorData* data =
353 per_compositor_data_[reflector_impl->mirrored_compositor()];
354 DCHECK(data);
355 data->reflector->Shutdown();
356 data->reflector = nullptr;
359 void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) {
360 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor);
361 if (it == per_compositor_data_.end())
362 return;
363 PerCompositorData* data = it->second;
364 DCHECK(data);
365 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an
366 // output_surface_map_ here.
367 if (data->surface)
368 output_surface_map_.Remove(data->surface_id);
369 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id);
370 delete data;
371 per_compositor_data_.erase(it);
372 if (per_compositor_data_.empty()) {
373 // Destroying the GLHelper may cause some async actions to be cancelled,
374 // causing things to request a new GLHelper. Due to crbug.com/176091 the
375 // GLHelper created in this case would be lost/leaked if we just reset()
376 // on the |gl_helper_| variable directly. So instead we call reset() on a
377 // local scoped_ptr.
378 scoped_ptr<GLHelper> helper = gl_helper_.Pass();
380 // If there are any observer left at this point, make sure they clean up
381 // before we destroy the GLHelper.
382 FOR_EACH_OBSERVER(
383 ImageTransportFactoryObserver, observer_list_, OnLostResources());
385 helper.reset();
386 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new "
387 "GLHelper to be created.";
391 bool GpuProcessTransportFactory::DoesCreateTestContexts() { return false; }
393 uint32 GpuProcessTransportFactory::GetImageTextureTarget() {
394 return BrowserGpuChannelHostFactory::GetImageTextureTarget();
397 cc::SharedBitmapManager* GpuProcessTransportFactory::GetSharedBitmapManager() {
398 return HostSharedBitmapManager::current();
401 gpu::GpuMemoryBufferManager*
402 GpuProcessTransportFactory::GetGpuMemoryBufferManager() {
403 return BrowserGpuMemoryBufferManager::current();
406 cc::TaskGraphRunner* GpuProcessTransportFactory::GetTaskGraphRunner() {
407 return task_graph_runner_.get();
410 ui::ContextFactory* GpuProcessTransportFactory::GetContextFactory() {
411 return this;
414 gfx::GLSurfaceHandle GpuProcessTransportFactory::GetSharedSurfaceHandle() {
415 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle(
416 gfx::kNullPluginWindow, gfx::NULL_TRANSPORT);
417 handle.parent_client_id =
418 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId();
419 return handle;
422 scoped_ptr<cc::SurfaceIdAllocator>
423 GpuProcessTransportFactory::CreateSurfaceIdAllocator() {
424 return make_scoped_ptr(
425 new cc::SurfaceIdAllocator(next_surface_id_namespace_++));
428 void GpuProcessTransportFactory::ResizeDisplay(ui::Compositor* compositor,
429 const gfx::Size& size) {
430 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor);
431 if (it == per_compositor_data_.end())
432 return;
433 PerCompositorData* data = it->second;
434 DCHECK(data);
435 if (data->display_client)
436 data->display_client->display()->Resize(size);
439 cc::SurfaceManager* GpuProcessTransportFactory::GetSurfaceManager() {
440 return surface_manager_.get();
443 GLHelper* GpuProcessTransportFactory::GetGLHelper() {
444 if (!gl_helper_ && !per_compositor_data_.empty()) {
445 scoped_refptr<cc::ContextProvider> provider =
446 SharedMainThreadContextProvider();
447 if (provider.get())
448 gl_helper_.reset(new GLHelper(provider->ContextGL(),
449 provider->ContextSupport()));
451 return gl_helper_.get();
454 void GpuProcessTransportFactory::AddObserver(
455 ImageTransportFactoryObserver* observer) {
456 observer_list_.AddObserver(observer);
459 void GpuProcessTransportFactory::RemoveObserver(
460 ImageTransportFactoryObserver* observer) {
461 observer_list_.RemoveObserver(observer);
464 #if defined(OS_MACOSX)
465 void GpuProcessTransportFactory::OnSurfaceDisplayed(int surface_id) {
466 BrowserCompositorOutputSurface* surface = output_surface_map_.Lookup(
467 surface_id);
468 if (surface)
469 surface->OnSurfaceDisplayed();
472 void GpuProcessTransportFactory::SetCompositorSuspendedForRecycle(
473 ui::Compositor* compositor,
474 bool suspended) {
475 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor);
476 if (it == per_compositor_data_.end())
477 return;
478 PerCompositorData* data = it->second;
479 DCHECK(data);
480 BrowserCompositorOutputSurface* surface =
481 output_surface_map_.Lookup(data->surface_id);
482 if (surface)
483 surface->SetSurfaceSuspendedForRecycle(suspended);
486 bool GpuProcessTransportFactory::
487 SurfaceShouldNotShowFramesAfterSuspendForRecycle(int surface_id) const {
488 BrowserCompositorOutputSurface* surface =
489 output_surface_map_.Lookup(surface_id);
490 if (surface)
491 return surface->SurfaceShouldNotShowFramesAfterSuspendForRecycle();
492 return false;
494 #endif
496 scoped_refptr<cc::ContextProvider>
497 GpuProcessTransportFactory::SharedMainThreadContextProvider() {
498 if (shared_main_thread_contexts_.get())
499 return shared_main_thread_contexts_;
501 // In threaded compositing mode, we have to create our own context for the
502 // main thread since the compositor's context will be bound to the
503 // compositor thread. When not in threaded mode, we still need a separate
504 // context so that skia and gl_helper don't step on each other.
505 shared_main_thread_contexts_ = ContextProviderCommandBuffer::Create(
506 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext(),
507 "Offscreen-MainThread");
509 if (shared_main_thread_contexts_.get()) {
510 shared_main_thread_contexts_->SetLostContextCallback(
511 base::Bind(&GpuProcessTransportFactory::
512 OnLostMainThreadSharedContextInsideCallback,
513 callback_factory_.GetWeakPtr()));
514 if (!shared_main_thread_contexts_->BindToCurrentThread())
515 shared_main_thread_contexts_ = NULL;
517 return shared_main_thread_contexts_;
520 GpuProcessTransportFactory::PerCompositorData*
521 GpuProcessTransportFactory::CreatePerCompositorData(
522 ui::Compositor* compositor) {
523 DCHECK(!per_compositor_data_[compositor]);
525 gfx::AcceleratedWidget widget = compositor->widget();
526 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get();
528 PerCompositorData* data = new PerCompositorData;
529 data->surface_id = tracker->AddSurfaceForNativeWidget(widget);
530 tracker->SetSurfaceHandle(
531 data->surface_id,
532 gfx::GLSurfaceHandle(widget, gfx::NATIVE_DIRECT));
534 per_compositor_data_[compositor] = data;
536 return data;
539 scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
540 GpuProcessTransportFactory::CreateContextCommon(
541 scoped_refptr<GpuChannelHost> gpu_channel_host,
542 int surface_id) {
543 if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor())
544 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
545 blink::WebGraphicsContext3D::Attributes attrs;
546 attrs.shareResources = true;
547 attrs.depth = false;
548 attrs.stencil = false;
549 attrs.antialias = false;
550 attrs.noAutomaticFlushes = true;
551 bool lose_context_when_out_of_memory = true;
552 if (!gpu_channel_host.get()) {
553 LOG(ERROR) << "Failed to establish GPU channel.";
554 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
556 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon");
557 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
558 new WebGraphicsContext3DCommandBufferImpl(
559 surface_id,
560 url,
561 gpu_channel_host.get(),
562 attrs,
563 lose_context_when_out_of_memory,
564 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits(),
565 NULL));
566 return context.Pass();
569 void GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback() {
570 base::MessageLoop::current()->PostTask(
571 FROM_HERE,
572 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext,
573 callback_factory_.GetWeakPtr()));
576 void GpuProcessTransportFactory::OnLostMainThreadSharedContext() {
577 LOG(ERROR) << "Lost UI shared context.";
579 // Keep old resources around while we call the observers, but ensure that
580 // new resources are created if needed.
581 // Kill shared contexts for both threads in tandem so they are always in
582 // the same share group.
583 scoped_refptr<cc::ContextProvider> lost_shared_main_thread_contexts =
584 shared_main_thread_contexts_;
585 shared_main_thread_contexts_ = NULL;
587 scoped_ptr<GLHelper> lost_gl_helper = gl_helper_.Pass();
589 FOR_EACH_OBSERVER(ImageTransportFactoryObserver,
590 observer_list_,
591 OnLostResources());
593 // Kill things that use the shared context before killing the shared context.
594 lost_gl_helper.reset();
595 lost_shared_main_thread_contexts = NULL;
598 } // namespace content