Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / compositor / gpu_process_transport_factory.cc
blob151ba009b06a47e5803aad4baa342618a7672dd1
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/offscreen_browser_compositor_output_surface.h"
28 #include "content/browser/compositor/reflector_impl.h"
29 #include "content/browser/compositor/software_browser_compositor_output_surface.h"
30 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
31 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
32 #include "content/browser/gpu/compositor_util.h"
33 #include "content/browser/gpu/gpu_data_manager_impl.h"
34 #include "content/browser/gpu/gpu_surface_tracker.h"
35 #include "content/browser/renderer_host/render_widget_host_impl.h"
36 #include "content/common/gpu/client/context_provider_command_buffer.h"
37 #include "content/common/gpu/client/gl_helper.h"
38 #include "content/common/gpu/client/gpu_channel_host.h"
39 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
40 #include "content/common/gpu/gpu_process_launch_causes.h"
41 #include "content/common/host_shared_bitmap_manager.h"
42 #include "content/public/common/content_switches.h"
43 #include "gpu/GLES2/gl2extchromium.h"
44 #include "gpu/command_buffer/client/gles2_interface.h"
45 #include "gpu/command_buffer/common/mailbox.h"
46 #include "third_party/khronos/GLES2/gl2.h"
47 #include "ui/compositor/compositor.h"
48 #include "ui/compositor/compositor_constants.h"
49 #include "ui/compositor/compositor_switches.h"
50 #include "ui/gfx/geometry/size.h"
51 #include "ui/gfx/native_widget_types.h"
53 #if defined(OS_WIN)
54 #include "content/browser/compositor/software_output_device_win.h"
55 #elif defined(USE_OZONE)
56 #include "content/browser/compositor/browser_compositor_overlay_candidate_validator_ozone.h"
57 #include "content/browser/compositor/software_output_device_ozone.h"
58 #include "ui/ozone/public/ozone_switches.h"
59 #include "ui/ozone/public/surface_factory_ozone.h"
60 #elif defined(USE_X11)
61 #include "content/browser/compositor/software_output_device_x11.h"
62 #elif defined(OS_MACOSX)
63 #include "content/browser/compositor/software_output_device_mac.h"
64 #endif
66 using cc::ContextProvider;
67 using gpu::gles2::GLES2Interface;
69 static const int kNumRetriesBeforeSoftwareFallback = 4;
71 namespace content {
72 namespace {
74 class RasterThread : public base::SimpleThread {
75 public:
76 RasterThread(cc::TaskGraphRunner* task_graph_runner)
77 : base::SimpleThread("CompositorTileWorker1"),
78 task_graph_runner_(task_graph_runner) {}
80 // Overridden from base::SimpleThread:
81 void Run() override { task_graph_runner_->Run(); }
83 private:
84 cc::TaskGraphRunner* task_graph_runner_;
86 DISALLOW_COPY_AND_ASSIGN(RasterThread);
89 } // namespace
91 struct GpuProcessTransportFactory::PerCompositorData {
92 int surface_id;
93 BrowserCompositorOutputSurface* surface;
94 ReflectorImpl* reflector;
95 scoped_ptr<cc::OnscreenDisplayClient> display_client;
97 PerCompositorData() : surface_id(0), surface(nullptr), reflector(nullptr) {}
100 GpuProcessTransportFactory::GpuProcessTransportFactory()
101 : next_surface_id_namespace_(1u),
102 task_graph_runner_(new cc::TaskGraphRunner),
103 callback_factory_(this) {
104 if (UseSurfacesEnabled())
105 surface_manager_ = make_scoped_ptr(new cc::SurfaceManager);
107 if (ui::IsUIImplSidePaintingEnabled()) {
108 raster_thread_.reset(new RasterThread(task_graph_runner_.get()));
109 raster_thread_->Start();
113 GpuProcessTransportFactory::~GpuProcessTransportFactory() {
114 DCHECK(per_compositor_data_.empty());
116 // Make sure the lost context callback doesn't try to run during destruction.
117 callback_factory_.InvalidateWeakPtrs();
119 task_graph_runner_->Shutdown();
120 if (raster_thread_)
121 raster_thread_->Join();
124 scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
125 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext() {
126 CauseForGpuLaunch cause =
127 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
128 scoped_refptr<GpuChannelHost> gpu_channel_host(
129 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause));
130 return CreateContextCommon(gpu_channel_host, 0);
133 scoped_ptr<cc::SoftwareOutputDevice> CreateSoftwareOutputDevice(
134 ui::Compositor* compositor) {
135 #if defined(OS_WIN)
136 return scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareOutputDeviceWin(
137 compositor));
138 #elif defined(USE_OZONE)
139 return scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareOutputDeviceOzone(
140 compositor));
141 #elif defined(USE_X11)
142 return scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareOutputDeviceX11(
143 compositor));
144 #elif defined(OS_MACOSX)
145 return scoped_ptr<cc::SoftwareOutputDevice>(
146 new SoftwareOutputDeviceMac(compositor));
147 #else
148 NOTREACHED();
149 return scoped_ptr<cc::SoftwareOutputDevice>();
150 #endif
153 scoped_ptr<BrowserCompositorOverlayCandidateValidator>
154 CreateOverlayCandidateValidator(gfx::AcceleratedWidget widget) {
155 #if defined(USE_OZONE)
156 ui::OverlayCandidatesOzone* overlay_candidates =
157 ui::SurfaceFactoryOzone::GetInstance()->GetOverlayCandidates(widget);
158 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
159 if (overlay_candidates &&
160 (command_line->HasSwitch(switches::kEnableHardwareOverlays) ||
161 command_line->HasSwitch(switches::kOzoneTestSingleOverlaySupport))) {
162 return scoped_ptr<BrowserCompositorOverlayCandidateValidator>(
163 new BrowserCompositorOverlayCandidateValidatorOzone(
164 widget, overlay_candidates));
166 #endif
167 return scoped_ptr<BrowserCompositorOverlayCandidateValidator>();
170 static bool ShouldCreateGpuOutputSurface(ui::Compositor* compositor) {
171 #if defined(OS_CHROMEOS)
172 // Software fallback does not happen on Chrome OS.
173 return true;
174 #endif
176 #if defined(OS_WIN)
177 if (::GetProp(compositor->widget(), kForceSoftwareCompositor) &&
178 ::RemoveProp(compositor->widget(), kForceSoftwareCompositor))
179 return false;
180 #endif
182 return GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor();
185 void GpuProcessTransportFactory::CreateOutputSurface(
186 base::WeakPtr<ui::Compositor> compositor) {
187 DCHECK(!!compositor);
188 PerCompositorData* data = per_compositor_data_[compositor.get()];
189 if (!data) {
190 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/466870
191 // is fixed.
192 tracked_objects::ScopedTracker tracking_profile1(
193 FROM_HERE_WITH_EXPLICIT_FUNCTION(
194 "466870 GpuProcessTransportFactory::CreateOutputSurface1"));
195 data = CreatePerCompositorData(compositor.get());
196 } else {
197 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an
198 // output_surface_map_ here.
199 output_surface_map_.Remove(data->surface_id);
200 data->surface = nullptr;
203 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/466870
204 // is fixed.
205 tracked_objects::ScopedTracker tracking_profile2(
206 FROM_HERE_WITH_EXPLICIT_FUNCTION(
207 "466870 GpuProcessTransportFactory::CreateOutputSurface2"));
209 bool create_gpu_output_surface =
210 ShouldCreateGpuOutputSurface(compositor.get());
211 if (create_gpu_output_surface) {
212 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/466870
213 // is fixed.
214 tracked_objects::ScopedTracker tracking_profile3(
215 FROM_HERE_WITH_EXPLICIT_FUNCTION(
216 "466870 GpuProcessTransportFactory::CreateOutputSurface3"));
218 CauseForGpuLaunch cause =
219 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
220 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel(
221 cause, base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel,
222 callback_factory_.GetWeakPtr(), compositor,
223 create_gpu_output_surface, 0));
224 } else {
225 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/466870
226 // is fixed.
227 tracked_objects::ScopedTracker tracking_profile4(
228 FROM_HERE_WITH_EXPLICIT_FUNCTION(
229 "466870 GpuProcessTransportFactory::CreateOutputSurface4"));
231 EstablishedGpuChannel(compositor, create_gpu_output_surface, 0);
235 void GpuProcessTransportFactory::EstablishedGpuChannel(
236 base::WeakPtr<ui::Compositor> compositor,
237 bool create_gpu_output_surface,
238 int num_attempts) {
239 if (!compositor)
240 return;
241 PerCompositorData* data = per_compositor_data_[compositor.get()];
242 DCHECK(data);
244 if (num_attempts > kNumRetriesBeforeSoftwareFallback) {
245 #if defined(OS_CHROMEOS)
246 LOG(FATAL) << "Unable to create a UI graphics context, and cannot use "
247 << "software compositing on ChromeOS.";
248 #endif
249 create_gpu_output_surface = false;
252 scoped_refptr<ContextProviderCommandBuffer> context_provider;
253 if (create_gpu_output_surface) {
254 scoped_refptr<GpuChannelHost> gpu_channel_host =
255 BrowserGpuChannelHostFactory::instance()->GetGpuChannel();
256 if (gpu_channel_host.get()) {
257 context_provider = ContextProviderCommandBuffer::Create(
258 GpuProcessTransportFactory::CreateContextCommon(gpu_channel_host,
259 data->surface_id),
260 BROWSER_COMPOSITOR_ONSCREEN_CONTEXT);
261 if (context_provider && !context_provider->BindToCurrentThread())
262 context_provider = nullptr;
265 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor",
266 !!context_provider.get());
268 if (!context_provider) {
269 // Try again.
270 CauseForGpuLaunch cause =
271 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
272 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel(
273 cause, base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel,
274 callback_factory_.GetWeakPtr(), compositor,
275 create_gpu_output_surface, num_attempts + 1));
276 return;
280 scoped_ptr<BrowserCompositorOutputSurface> surface;
281 if (!create_gpu_output_surface) {
282 surface = make_scoped_ptr(new SoftwareBrowserCompositorOutputSurface(
283 CreateSoftwareOutputDevice(compositor.get()),
284 compositor->vsync_manager()));
285 } else {
286 DCHECK(context_provider);
287 if (!data->surface_id) {
288 surface = make_scoped_ptr(new OffscreenBrowserCompositorOutputSurface(
289 context_provider, compositor->vsync_manager(),
290 scoped_ptr<BrowserCompositorOverlayCandidateValidator>()));
291 } else
292 #if defined(USE_OZONE)
293 if (ui::SurfaceFactoryOzone::GetInstance()
294 ->CanShowPrimaryPlaneAsOverlay()) {
295 surface =
296 make_scoped_ptr(new GpuSurfacelessBrowserCompositorOutputSurface(
297 context_provider, data->surface_id, compositor->vsync_manager(),
298 CreateOverlayCandidateValidator(compositor->widget()), GL_RGB,
299 BrowserGpuMemoryBufferManager::current()));
300 } else
301 #endif
303 surface = make_scoped_ptr(new GpuBrowserCompositorOutputSurface(
304 context_provider, compositor->vsync_manager(),
305 CreateOverlayCandidateValidator(compositor->widget())));
309 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an
310 // output_surface_map_ here.
311 output_surface_map_.AddWithID(surface.get(), data->surface_id);
312 data->surface = surface.get();
313 if (data->reflector)
314 data->reflector->OnSourceSurfaceReady(data->surface);
316 if (!UseSurfacesEnabled()) {
317 compositor->SetOutputSurface(surface.Pass());
318 return;
321 // This gets a bit confusing. Here we have a ContextProvider in the |surface|
322 // configured to render directly to this widget. We need to make an
323 // OnscreenDisplayClient associated with that context, then return a
324 // SurfaceDisplayOutputSurface set up to draw to the display's surface.
325 cc::SurfaceManager* manager = surface_manager_.get();
326 scoped_ptr<cc::OnscreenDisplayClient> display_client(
327 new cc::OnscreenDisplayClient(
328 surface.Pass(), manager, HostSharedBitmapManager::current(),
329 BrowserGpuMemoryBufferManager::current(),
330 compositor->GetRendererSettings(), compositor->task_runner()));
332 scoped_ptr<cc::SurfaceDisplayOutputSurface> output_surface(
333 new cc::SurfaceDisplayOutputSurface(
334 manager, compositor->surface_id_allocator(), context_provider));
335 display_client->set_surface_output_surface(output_surface.get());
336 output_surface->set_display_client(display_client.get());
337 display_client->display()->Resize(compositor->size());
338 data->display_client = display_client.Pass();
339 compositor->SetOutputSurface(output_surface.Pass());
342 scoped_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector(
343 ui::Compositor* source_compositor,
344 ui::Layer* target_layer) {
345 PerCompositorData* source_data = per_compositor_data_[source_compositor];
346 DCHECK(source_data);
348 scoped_ptr<ReflectorImpl> reflector(
349 new ReflectorImpl(source_compositor, target_layer));
350 source_data->reflector = reflector.get();
351 if (BrowserCompositorOutputSurface* source_surface = source_data->surface)
352 reflector->OnSourceSurfaceReady(source_surface);
353 return reflector.Pass();
356 void GpuProcessTransportFactory::RemoveReflector(ui::Reflector* reflector) {
357 ReflectorImpl* reflector_impl = static_cast<ReflectorImpl*>(reflector);
358 PerCompositorData* data =
359 per_compositor_data_[reflector_impl->mirrored_compositor()];
360 DCHECK(data);
361 data->reflector->Shutdown();
362 data->reflector = nullptr;
365 void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) {
366 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor);
367 if (it == per_compositor_data_.end())
368 return;
369 PerCompositorData* data = it->second;
370 DCHECK(data);
371 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an
372 // output_surface_map_ here.
373 if (data->surface)
374 output_surface_map_.Remove(data->surface_id);
375 if (data->surface_id)
376 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id);
377 delete data;
378 per_compositor_data_.erase(it);
379 if (per_compositor_data_.empty()) {
380 // Destroying the GLHelper may cause some async actions to be cancelled,
381 // causing things to request a new GLHelper. Due to crbug.com/176091 the
382 // GLHelper created in this case would be lost/leaked if we just reset()
383 // on the |gl_helper_| variable directly. So instead we call reset() on a
384 // local scoped_ptr.
385 scoped_ptr<GLHelper> helper = gl_helper_.Pass();
387 // If there are any observer left at this point, make sure they clean up
388 // before we destroy the GLHelper.
389 FOR_EACH_OBSERVER(
390 ImageTransportFactoryObserver, observer_list_, OnLostResources());
392 helper.reset();
393 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new "
394 "GLHelper to be created.";
398 bool GpuProcessTransportFactory::DoesCreateTestContexts() { return false; }
400 uint32 GpuProcessTransportFactory::GetImageTextureTarget() {
401 return BrowserGpuChannelHostFactory::GetImageTextureTarget();
404 cc::SharedBitmapManager* GpuProcessTransportFactory::GetSharedBitmapManager() {
405 return HostSharedBitmapManager::current();
408 gpu::GpuMemoryBufferManager*
409 GpuProcessTransportFactory::GetGpuMemoryBufferManager() {
410 return BrowserGpuMemoryBufferManager::current();
413 cc::TaskGraphRunner* GpuProcessTransportFactory::GetTaskGraphRunner() {
414 return task_graph_runner_.get();
417 ui::ContextFactory* GpuProcessTransportFactory::GetContextFactory() {
418 return this;
421 gfx::GLSurfaceHandle GpuProcessTransportFactory::GetSharedSurfaceHandle() {
422 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle(
423 gfx::kNullPluginWindow, gfx::NULL_TRANSPORT);
424 handle.parent_client_id =
425 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId();
426 return handle;
429 scoped_ptr<cc::SurfaceIdAllocator>
430 GpuProcessTransportFactory::CreateSurfaceIdAllocator() {
431 return make_scoped_ptr(
432 new cc::SurfaceIdAllocator(next_surface_id_namespace_++));
435 void GpuProcessTransportFactory::ResizeDisplay(ui::Compositor* compositor,
436 const gfx::Size& size) {
437 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor);
438 if (it == per_compositor_data_.end())
439 return;
440 PerCompositorData* data = it->second;
441 DCHECK(data);
442 if (data->display_client)
443 data->display_client->display()->Resize(size);
446 cc::SurfaceManager* GpuProcessTransportFactory::GetSurfaceManager() {
447 return surface_manager_.get();
450 GLHelper* GpuProcessTransportFactory::GetGLHelper() {
451 if (!gl_helper_ && !per_compositor_data_.empty()) {
452 scoped_refptr<cc::ContextProvider> provider =
453 SharedMainThreadContextProvider();
454 if (provider.get())
455 gl_helper_.reset(new GLHelper(provider->ContextGL(),
456 provider->ContextSupport()));
458 return gl_helper_.get();
461 void GpuProcessTransportFactory::AddObserver(
462 ImageTransportFactoryObserver* observer) {
463 observer_list_.AddObserver(observer);
466 void GpuProcessTransportFactory::RemoveObserver(
467 ImageTransportFactoryObserver* observer) {
468 observer_list_.RemoveObserver(observer);
471 #if defined(OS_MACOSX)
472 void GpuProcessTransportFactory::OnSurfaceDisplayed(int surface_id) {
473 BrowserCompositorOutputSurface* surface = output_surface_map_.Lookup(
474 surface_id);
475 if (surface)
476 surface->OnSurfaceDisplayed();
479 void GpuProcessTransportFactory::SetCompositorSuspendedForRecycle(
480 ui::Compositor* compositor,
481 bool suspended) {
482 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor);
483 if (it == per_compositor_data_.end())
484 return;
485 PerCompositorData* data = it->second;
486 DCHECK(data);
487 BrowserCompositorOutputSurface* surface =
488 output_surface_map_.Lookup(data->surface_id);
489 if (surface)
490 surface->SetSurfaceSuspendedForRecycle(suspended);
493 bool GpuProcessTransportFactory::
494 SurfaceShouldNotShowFramesAfterSuspendForRecycle(int surface_id) const {
495 BrowserCompositorOutputSurface* surface =
496 output_surface_map_.Lookup(surface_id);
497 if (surface)
498 return surface->SurfaceShouldNotShowFramesAfterSuspendForRecycle();
499 return false;
501 #endif
503 scoped_refptr<cc::ContextProvider>
504 GpuProcessTransportFactory::SharedMainThreadContextProvider() {
505 if (shared_main_thread_contexts_.get())
506 return shared_main_thread_contexts_;
508 // In threaded compositing mode, we have to create our own context for the
509 // main thread since the compositor's context will be bound to the
510 // compositor thread. When not in threaded mode, we still need a separate
511 // context so that skia and gl_helper don't step on each other.
512 shared_main_thread_contexts_ = ContextProviderCommandBuffer::Create(
513 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext(),
514 BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT);
516 if (shared_main_thread_contexts_.get()) {
517 shared_main_thread_contexts_->SetLostContextCallback(
518 base::Bind(&GpuProcessTransportFactory::
519 OnLostMainThreadSharedContextInsideCallback,
520 callback_factory_.GetWeakPtr()));
521 if (!shared_main_thread_contexts_->BindToCurrentThread())
522 shared_main_thread_contexts_ = NULL;
524 return shared_main_thread_contexts_;
527 GpuProcessTransportFactory::PerCompositorData*
528 GpuProcessTransportFactory::CreatePerCompositorData(
529 ui::Compositor* compositor) {
530 DCHECK(!per_compositor_data_[compositor]);
532 gfx::AcceleratedWidget widget = compositor->widget();
533 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get();
535 PerCompositorData* data = new PerCompositorData;
536 if (compositor->widget() == gfx::kNullAcceleratedWidget) {
537 data->surface_id = 0;
538 } else {
539 data->surface_id = tracker->AddSurfaceForNativeWidget(widget);
540 tracker->SetSurfaceHandle(data->surface_id,
541 gfx::GLSurfaceHandle(widget, gfx::NATIVE_DIRECT));
544 per_compositor_data_[compositor] = data;
546 return data;
549 scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
550 GpuProcessTransportFactory::CreateContextCommon(
551 scoped_refptr<GpuChannelHost> gpu_channel_host,
552 int surface_id) {
553 if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor())
554 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
555 blink::WebGraphicsContext3D::Attributes attrs;
556 attrs.shareResources = true;
557 attrs.depth = false;
558 attrs.stencil = false;
559 attrs.antialias = false;
560 attrs.noAutomaticFlushes = true;
561 bool lose_context_when_out_of_memory = true;
562 if (!gpu_channel_host.get()) {
563 LOG(ERROR) << "Failed to establish GPU channel.";
564 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
566 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon");
567 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
568 new WebGraphicsContext3DCommandBufferImpl(
569 surface_id,
570 url,
571 gpu_channel_host.get(),
572 attrs,
573 lose_context_when_out_of_memory,
574 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits(),
575 NULL));
576 return context.Pass();
579 void GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback() {
580 base::MessageLoop::current()->PostTask(
581 FROM_HERE,
582 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext,
583 callback_factory_.GetWeakPtr()));
586 void GpuProcessTransportFactory::OnLostMainThreadSharedContext() {
587 LOG(ERROR) << "Lost UI shared context.";
589 // Keep old resources around while we call the observers, but ensure that
590 // new resources are created if needed.
591 // Kill shared contexts for both threads in tandem so they are always in
592 // the same share group.
593 scoped_refptr<cc::ContextProvider> lost_shared_main_thread_contexts =
594 shared_main_thread_contexts_;
595 shared_main_thread_contexts_ = NULL;
597 scoped_ptr<GLHelper> lost_gl_helper = gl_helper_.Pass();
599 FOR_EACH_OBSERVER(ImageTransportFactoryObserver,
600 observer_list_,
601 OnLostResources());
603 // Kill things that use the shared context before killing the shared context.
604 lost_gl_helper.reset();
605 lost_shared_main_thread_contexts = NULL;
608 } // namespace content