OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/image_transport_factory.h" | 5 #include "content/browser/renderer_host/image_transport_factory.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 24 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
25 #include "content/common/gpu/gpu_messages.h" | 25 #include "content/common/gpu/gpu_messages.h" |
26 #include "content/common/gpu/gpu_process_launch_causes.h" | 26 #include "content/common/gpu/gpu_process_launch_causes.h" |
27 #include "content/common/webkitplatformsupport_impl.h" | 27 #include "content/common/webkitplatformsupport_impl.h" |
28 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
29 #include "gpu/GLES2/gl2extchromium.h" | 29 #include "gpu/GLES2/gl2extchromium.h" |
30 #include "gpu/ipc/command_buffer_proxy.h" | 30 #include "gpu/ipc/command_buffer_proxy.h" |
31 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 31 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
32 #include "third_party/khronos/GLES2/gl2.h" | 32 #include "third_party/khronos/GLES2/gl2.h" |
33 #include "third_party/khronos/GLES2/gl2ext.h" | 33 #include "third_party/khronos/GLES2/gl2ext.h" |
| 34 #include "third_party/skia/include/gpu/GrContext.h" |
| 35 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
34 #include "ui/compositor/compositor.h" | 36 #include "ui/compositor/compositor.h" |
35 #include "ui/compositor/compositor_setup.h" | 37 #include "ui/compositor/compositor_setup.h" |
| 38 #include "ui/compositor/offscreen_context.h" |
36 #include "ui/compositor/test_web_graphics_context_3d.h" | 39 #include "ui/compositor/test_web_graphics_context_3d.h" |
37 #include "ui/gfx/native_widget_types.h" | 40 #include "ui/gfx/native_widget_types.h" |
38 #include "ui/gfx/size.h" | 41 #include "ui/gfx/size.h" |
39 | 42 |
40 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
41 #include "ui/surface/accelerated_surface_win.h" | 44 #include "ui/surface/accelerated_surface_win.h" |
42 #endif | 45 #endif |
43 | 46 |
44 namespace content { | 47 namespace content { |
45 namespace { | 48 namespace { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 220 |
218 virtual void OnViewContextSwapBuffersComplete() OVERRIDE { | 221 virtual void OnViewContextSwapBuffersComplete() OVERRIDE { |
219 compositor_->OnSwapBuffersComplete(); | 222 compositor_->OnSwapBuffersComplete(); |
220 } | 223 } |
221 | 224 |
222 virtual void OnViewContextSwapBuffersAborted() OVERRIDE { | 225 virtual void OnViewContextSwapBuffersAborted() OVERRIDE { |
223 // Recreating contexts directly from here causes issues, so post a task | 226 // Recreating contexts directly from here causes issues, so post a task |
224 // instead. | 227 // instead. |
225 // TODO(piman): Fix the underlying issues. | 228 // TODO(piman): Fix the underlying issues. |
226 MessageLoop::current()->PostTask(FROM_HERE, | 229 MessageLoop::current()->PostTask(FROM_HERE, |
227 base::Bind(&CompositorSwapClient::OnLostContext, this->AsWeakPtr())); | 230 base::Bind(&CompositorSwapClient::OnLostSwapContext, |
| 231 this->AsWeakPtr())); |
228 } | 232 } |
229 | 233 |
230 private: | 234 private: |
231 void OnLostContext(); | 235 void OnLostSwapContext(); |
232 ui::Compositor* compositor_; | 236 ui::Compositor* compositor_; |
233 GpuProcessTransportFactory* factory_; | 237 GpuProcessTransportFactory* factory_; |
234 | 238 |
235 DISALLOW_COPY_AND_ASSIGN(CompositorSwapClient); | 239 DISALLOW_COPY_AND_ASSIGN(CompositorSwapClient); |
236 }; | 240 }; |
237 | 241 |
238 class BrowserCompositorOutputSurface; | 242 class BrowserCompositorOutputSurface; |
239 | 243 |
240 // Directs vsync updates to the appropriate BrowserCompositorOutputSurface. | 244 // Directs vsync updates to the appropriate BrowserCompositorOutputSurface. |
241 class BrowserCompositorOutputSurfaceProxy | 245 class BrowserCompositorOutputSurfaceProxy |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_; | 363 scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_; |
360 }; | 364 }; |
361 | 365 |
362 void BrowserCompositorOutputSurfaceProxy::OnUpdateVSyncParameters( | 366 void BrowserCompositorOutputSurfaceProxy::OnUpdateVSyncParameters( |
363 int surface_id, base::TimeTicks timebase, base::TimeDelta interval) { | 367 int surface_id, base::TimeTicks timebase, base::TimeDelta interval) { |
364 BrowserCompositorOutputSurface* surface = surface_map_.Lookup(surface_id); | 368 BrowserCompositorOutputSurface* surface = surface_map_.Lookup(surface_id); |
365 if (surface) | 369 if (surface) |
366 surface->OnUpdateVSyncParameters(timebase, interval); | 370 surface->OnUpdateVSyncParameters(timebase, interval); |
367 } | 371 } |
368 | 372 |
| 373 // TODO(danakj): Talk to the GPU mem manager directly. |
| 374 class GpuProcessOffscreenContext |
| 375 : public ui::OffscreenContext, |
| 376 public WebKit::WebGraphicsContext3D:: |
| 377 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM { |
| 378 public: |
| 379 GpuProcessOffscreenContext(ui::ContextFactory* context_factory, |
| 380 ui::OffscreenContextClient* client) |
| 381 : ui::OffscreenContext(context_factory, client) { |
| 382 } |
| 383 |
| 384 protected: |
| 385 virtual void DidCreateContext(bool success) OVERRIDE { |
| 386 ui::OffscreenContext::DidCreateContext(success); |
| 387 if (!context3d_if_exists()) |
| 388 return; |
| 389 |
| 390 // TODO(danakj): Talk to the GPU mem manager directly. |
| 391 context3d_if_exists()->setMemoryAllocationChangedCallbackCHROMIUM(this); |
| 392 } |
| 393 |
| 394 private: |
| 395 // WebGraphicsMemoryAllocationChangedCallbackCHROMIUM implementation. |
| 396 virtual void onMemoryAllocationChanged( |
| 397 WebKit::WebGraphicsMemoryAllocation allocation) OVERRIDE { |
| 398 if (!gr_context_if_exists()) |
| 399 return; |
| 400 |
| 401 if (!allocation.gpuResourceSizeInBytes) { |
| 402 gr_context_if_exists()->freeGpuResources(); |
| 403 gr_context_if_exists()->setTextureCacheLimits(0, 0); |
| 404 return; |
| 405 } |
| 406 |
| 407 gr_context_if_exists()->setTextureCacheLimits( |
| 408 kMaxGaneshTextureCacheCount, kMaxGaneshTextureCacheBytes); |
| 409 } |
| 410 }; |
| 411 |
369 class GpuProcessTransportFactory | 412 class GpuProcessTransportFactory |
370 : public ui::ContextFactory, | 413 : public ui::ContextFactory, |
371 public ImageTransportFactory, | 414 public ui::OffscreenContextClient, |
372 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 415 public ImageTransportFactory { |
373 public: | 416 public: |
374 GpuProcessTransportFactory() | 417 GpuProcessTransportFactory() |
375 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { | 418 : shared_context_main_thread_(this, this), |
| 419 shared_context_compositor_thread_(this, this), |
| 420 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { |
376 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy(); | 421 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy(); |
377 } | 422 } |
378 | 423 |
379 virtual ~GpuProcessTransportFactory() { | 424 virtual ~GpuProcessTransportFactory() { |
380 DCHECK(per_compositor_data_.empty()); | 425 DCHECK(per_compositor_data_.empty()); |
381 } | 426 } |
382 | 427 |
383 virtual WebGraphicsContext3DCommandBufferImpl* CreateOffscreenContext() | 428 virtual WebGraphicsContext3DCommandBufferImpl* CreateOffscreenContext() |
384 OVERRIDE { | 429 OVERRIDE { |
385 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client; | 430 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client; |
386 return CreateContextCommon(swap_client, 0); | 431 return CreateContextCommon(swap_client, 0); |
387 } | 432 } |
388 | 433 |
389 virtual cc::OutputSurface* CreateOutputSurface( | 434 virtual cc::OutputSurface* CreateOutputSurface( |
390 ui::Compositor* compositor) OVERRIDE { | 435 ui::Compositor* compositor) OVERRIDE { |
391 PerCompositorData* data = per_compositor_data_[compositor]; | 436 PerCompositorData* data = per_compositor_data_[compositor]; |
392 if (!data) | 437 if (!data) |
393 data = CreatePerCompositorData(compositor); | 438 data = CreatePerCompositorData(compositor); |
394 WebGraphicsContext3DCommandBufferImpl* context = | 439 WebGraphicsContext3DCommandBufferImpl* context = |
395 CreateContextCommon(data->swap_client->AsWeakPtr(), | 440 CreateContextCommon(data->swap_client->AsWeakPtr(), |
396 data->surface_id); | 441 data->surface_id); |
397 return new BrowserCompositorOutputSurface( | 442 return new BrowserCompositorOutputSurface( |
398 context, | 443 context, |
399 per_compositor_data_[compositor]->surface_id, | 444 per_compositor_data_[compositor]->surface_id, |
400 output_surface_proxy_); | 445 output_surface_proxy_); |
401 } | 446 } |
402 | 447 |
| 448 virtual WebKit::WebGraphicsContext3D* OffscreenContextForMainThread() |
| 449 OVERRIDE { |
| 450 return shared_context_main_thread_.Context3d(); |
| 451 } |
| 452 |
| 453 virtual WebKit::WebGraphicsContext3D* |
| 454 OffscreenContextForCompositorThread() OVERRIDE { |
| 455 return shared_context_compositor_thread_.Context3d(); |
| 456 } |
| 457 |
| 458 virtual GrContext* OffscreenGrContextForMainThread() OVERRIDE { |
| 459 return shared_context_main_thread_.GrContext(); |
| 460 } |
| 461 |
| 462 virtual GrContext* OffscreenGrContextForCompositorThread() OVERRIDE { |
| 463 return shared_context_compositor_thread_.GrContext(); |
| 464 } |
| 465 |
403 virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE { | 466 virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE { |
404 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 467 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
405 if (it == per_compositor_data_.end()) | 468 if (it == per_compositor_data_.end()) |
406 return; | 469 return; |
407 PerCompositorData* data = it->second; | 470 PerCompositorData* data = it->second; |
408 DCHECK(data); | 471 DCHECK(data); |
409 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); | 472 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); |
410 delete data; | 473 delete data; |
411 per_compositor_data_.erase(it); | 474 per_compositor_data_.erase(it); |
412 if (per_compositor_data_.empty()) { | 475 if (per_compositor_data_.empty()) { |
413 gl_helper_.reset(); | 476 gl_helper_.reset(); |
414 callback_factory_.InvalidateWeakPtrs(); | 477 callback_factory_.InvalidateWeakPtrs(); |
415 } | 478 } |
416 } | 479 } |
417 | 480 |
418 virtual ui::ContextFactory* AsContextFactory() OVERRIDE { | 481 virtual ui::ContextFactory* AsContextFactory() OVERRIDE { |
419 return this; | 482 return this; |
420 } | 483 } |
421 | 484 |
422 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { | 485 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { |
423 CreateSharedContextLazy(); | 486 WebGraphicsContext3DCommandBufferImpl* context3d = |
| 487 static_cast<WebGraphicsContext3DCommandBufferImpl*>( |
| 488 shared_context_main_thread_.Context3d()); |
| 489 DCHECK(context3d); |
| 490 |
424 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( | 491 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( |
425 gfx::kNullPluginWindow, true); | 492 gfx::kNullPluginWindow, true); |
426 handle.parent_gpu_process_id = shared_context_->GetGPUProcessID(); | 493 handle.parent_gpu_process_id = context3d->GetGPUProcessID(); |
427 handle.parent_client_id = shared_context_->GetChannelID(); | 494 handle.parent_client_id = context3d->GetChannelID(); |
428 | |
429 return handle; | 495 return handle; |
430 } | 496 } |
431 | 497 |
432 virtual void DestroySharedSurfaceHandle( | 498 virtual void DestroySharedSurfaceHandle( |
433 gfx::GLSurfaceHandle surface) OVERRIDE { | 499 gfx::GLSurfaceHandle surface) OVERRIDE { |
434 } | 500 } |
435 | 501 |
436 virtual scoped_refptr<ui::Texture> CreateTransportClient( | 502 virtual scoped_refptr<ui::Texture> CreateTransportClient( |
437 float device_scale_factor) { | 503 float device_scale_factor) { |
438 if (!shared_context_.get()) | 504 if (!shared_context_main_thread_.Context3d()) |
439 return NULL; | 505 return NULL; |
440 scoped_refptr<ImageTransportClientTexture> image( | 506 scoped_refptr<ImageTransportClientTexture> image( |
441 new ImageTransportClientTexture(shared_context_.get(), | 507 new ImageTransportClientTexture( |
442 device_scale_factor)); | 508 shared_context_main_thread_.Context3d(), |
| 509 device_scale_factor)); |
443 return image; | 510 return image; |
444 } | 511 } |
445 | 512 |
446 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( | 513 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( |
447 const gfx::Size& size, | 514 const gfx::Size& size, |
448 float device_scale_factor, | 515 float device_scale_factor, |
449 unsigned int texture_id) OVERRIDE { | 516 unsigned int texture_id) OVERRIDE { |
450 if (!shared_context_.get()) | 517 if (!shared_context_main_thread_.Context3d()) |
451 return NULL; | 518 return NULL; |
452 scoped_refptr<OwnedTexture> image( | 519 scoped_refptr<OwnedTexture> image(new OwnedTexture( |
453 new OwnedTexture(shared_context_.get(), size, device_scale_factor, | 520 shared_context_main_thread_.Context3d(), |
454 texture_id)); | 521 size, |
| 522 device_scale_factor, |
| 523 texture_id)); |
455 return image; | 524 return image; |
456 } | 525 } |
457 | 526 |
458 virtual GLHelper* GetGLHelper() { | 527 virtual GLHelper* GetGLHelper() { |
459 if (!gl_helper_.get()) { | 528 if (!gl_helper_.get()) { |
460 CreateSharedContextLazy(); | 529 WebKit::WebGraphicsContext3D* main_thread_context = |
461 WebKit::WebGraphicsContext3D* context_for_thread = | 530 shared_context_main_thread_.Context3d(); |
| 531 if (!main_thread_context) |
| 532 return NULL; |
| 533 WebKit::WebGraphicsContext3D* helper_thread_context = |
462 CreateOffscreenContext(); | 534 CreateOffscreenContext(); |
463 if (!context_for_thread) | 535 if (!helper_thread_context) |
464 return NULL; | 536 return NULL; |
465 gl_helper_.reset(new GLHelper(shared_context_.get(), | 537 gl_helper_.reset(new GLHelper(main_thread_context, |
466 context_for_thread)); | 538 helper_thread_context)); |
467 } | 539 } |
468 return gl_helper_.get(); | 540 return gl_helper_.get(); |
469 } | 541 } |
470 | 542 |
471 virtual uint32 InsertSyncPoint() OVERRIDE { | 543 virtual uint32 InsertSyncPoint() OVERRIDE { |
472 if (!shared_context_.get()) | 544 if (!shared_context_main_thread_.Context3d()) |
473 return 0; | 545 return 0; |
474 return shared_context_->insertSyncPoint(); | 546 return shared_context_main_thread_.Context3d()-> |
| 547 insertSyncPoint(); |
475 } | 548 } |
476 | 549 |
477 virtual void AddObserver(ImageTransportFactoryObserver* observer) { | 550 virtual void AddObserver(ImageTransportFactoryObserver* observer) { |
478 observer_list_.AddObserver(observer); | 551 observer_list_.AddObserver(observer); |
479 } | 552 } |
480 | 553 |
481 virtual void RemoveObserver(ImageTransportFactoryObserver* observer) { | 554 virtual void RemoveObserver(ImageTransportFactoryObserver* observer) { |
482 observer_list_.RemoveObserver(observer); | 555 observer_list_.RemoveObserver(observer); |
483 } | 556 } |
484 | 557 |
485 // WebGraphicsContextLostCallback implementation, called for the shared | 558 // OffscreenContextClient implementation. |
486 // context. | 559 virtual void DidCreateContext(ui::OffscreenContext* offscreen_context, |
487 virtual void onContextLost() { | 560 bool success) |
488 MessageLoop::current()->PostTask( | 561 OVERRIDE { |
489 FROM_HERE, | 562 if (success) |
490 base::Bind(&GpuProcessTransportFactory::OnLostSharedContext, | 563 return; |
491 callback_factory_.GetWeakPtr())); | 564 if (offscreen_context == &shared_context_main_thread_) { |
| 565 // If we can't recreate contexts, we won't be able to show the UI. Better |
| 566 // crash at this point. |
| 567 LOG(FATAL) << "Failed to initialize UI shared main thread context."; |
| 568 } |
492 } | 569 } |
493 | 570 |
494 void OnLostContext(ui::Compositor* compositor) { | 571 // OffscreenContextClient implementation. |
| 572 virtual void DidLoseContext(ui::OffscreenContext* offscreen_context) |
| 573 OVERRIDE { |
| 574 if (offscreen_context == &shared_context_main_thread_) { |
| 575 MessageLoop::current()->PostTask( |
| 576 FROM_HERE, |
| 577 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext, |
| 578 callback_factory_.GetWeakPtr(), |
| 579 base::Unretained(offscreen_context))); |
| 580 } |
| 581 } |
| 582 |
| 583 void OnLostSwapContext(ui::Compositor* compositor) { |
495 LOG(ERROR) << "Lost UI compositor context."; | 584 LOG(ERROR) << "Lost UI compositor context."; |
496 PerCompositorData* data = per_compositor_data_[compositor]; | 585 PerCompositorData* data = per_compositor_data_[compositor]; |
497 DCHECK(data); | 586 DCHECK(data); |
498 | 587 |
499 // Prevent callbacks from other contexts in the same share group from | 588 // Prevent callbacks from other contexts in the same share group from |
500 // calling us again. | 589 // calling us again. |
501 data->swap_client.reset(new CompositorSwapClient(compositor, this)); | 590 data->swap_client.reset(new CompositorSwapClient(compositor, this)); |
502 compositor->OnSwapBuffersAborted(); | 591 compositor->OnSwapBuffersAborted(); |
503 } | 592 } |
504 | 593 |
505 private: | 594 private: |
506 struct PerCompositorData { | 595 struct PerCompositorData { |
507 int surface_id; | 596 int surface_id; |
508 scoped_ptr<CompositorSwapClient> swap_client; | 597 scoped_ptr<CompositorSwapClient> swap_client; |
509 #if defined(OS_WIN) | 598 #if defined(OS_WIN) |
510 scoped_ptr<AcceleratedSurface> accelerated_surface; | 599 scoped_ptr<AcceleratedSurface> accelerated_surface; |
511 #endif | 600 #endif |
512 }; | 601 }; |
513 | 602 |
514 PerCompositorData* CreatePerCompositorData(ui::Compositor* compositor) { | 603 PerCompositorData* CreatePerCompositorData(ui::Compositor* compositor) { |
515 DCHECK(!per_compositor_data_[compositor]); | 604 DCHECK(!per_compositor_data_[compositor]); |
516 | 605 |
517 CreateSharedContextLazy(); | |
518 | |
519 gfx::AcceleratedWidget widget = compositor->widget(); | 606 gfx::AcceleratedWidget widget = compositor->widget(); |
520 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); | 607 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); |
521 | 608 |
522 PerCompositorData* data = new PerCompositorData; | 609 PerCompositorData* data = new PerCompositorData; |
523 data->surface_id = tracker->AddSurfaceForNativeWidget(widget); | 610 data->surface_id = tracker->AddSurfaceForNativeWidget(widget); |
524 data->swap_client.reset(new CompositorSwapClient(compositor, this)); | 611 data->swap_client.reset(new CompositorSwapClient(compositor, this)); |
525 #if defined(OS_WIN) | 612 #if defined(OS_WIN) |
526 if (GpuDataManagerImpl::GetInstance()->IsUsingAcceleratedSurface()) | 613 if (GpuDataManagerImpl::GetInstance()->IsUsingAcceleratedSurface()) |
527 data->accelerated_surface.reset(new AcceleratedSurface(widget)); | 614 data->accelerated_surface.reset(new AcceleratedSurface(widget)); |
528 #endif | 615 #endif |
(...skipping 24 matching lines...) Expand all Loading... |
553 factory, | 640 factory, |
554 swap_client)); | 641 swap_client)); |
555 if (!context->Initialize( | 642 if (!context->Initialize( |
556 attrs, | 643 attrs, |
557 false, | 644 false, |
558 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) | 645 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) |
559 return NULL; | 646 return NULL; |
560 return context.release(); | 647 return context.release(); |
561 } | 648 } |
562 | 649 |
563 void CreateSharedContextLazy() { | 650 void OnLostMainThreadSharedContext(ui::OffscreenContext* offscreen_contxt) { |
564 if (shared_context_.get()) | |
565 return; | |
566 | |
567 shared_context_.reset(CreateOffscreenContext()); | |
568 if (!shared_context_.get()) { | |
569 // If we can't recreate contexts, we won't be able to show the UI. Better | |
570 // crash at this point. | |
571 LOG(FATAL) << "Failed to initialize UI shared context."; | |
572 } | |
573 if (!shared_context_->makeContextCurrent()) { | |
574 // If we can't recreate contexts, we won't be able to show the UI. Better | |
575 // crash at this point. | |
576 LOG(FATAL) << "Failed to make UI shared context current."; | |
577 } | |
578 shared_context_->setContextLostCallback(this); | |
579 } | |
580 | |
581 void OnLostSharedContext() { | |
582 // Keep old resources around while we call the observers, but ensure that | |
583 // new resources are created if needed. | |
584 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> old_shared_context( | |
585 shared_context_.release()); | |
586 scoped_ptr<GLHelper> old_helper(gl_helper_.release()); | |
587 | |
588 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 651 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
589 observer_list_, | 652 observer_list_, |
590 OnLostResources()); | 653 OnLostResources()); |
591 } | 654 } |
592 | 655 |
593 typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap; | 656 typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap; |
594 PerCompositorDataMap per_compositor_data_; | 657 PerCompositorDataMap per_compositor_data_; |
595 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> shared_context_; | 658 GpuProcessOffscreenContext shared_context_main_thread_; |
| 659 GpuProcessOffscreenContext shared_context_compositor_thread_; |
596 scoped_ptr<GLHelper> gl_helper_; | 660 scoped_ptr<GLHelper> gl_helper_; |
597 ObserverList<ImageTransportFactoryObserver> observer_list_; | 661 ObserverList<ImageTransportFactoryObserver> observer_list_; |
598 base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_; | 662 base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_; |
599 scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_; | 663 scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_; |
600 | 664 |
601 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory); | 665 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory); |
602 }; | 666 }; |
603 | 667 |
604 void CompositorSwapClient::OnLostContext() { | 668 void CompositorSwapClient::OnLostSwapContext() { |
605 factory_->OnLostContext(compositor_); | 669 factory_->OnLostSwapContext(compositor_); |
606 // Note: previous line destroyed this. Don't access members from now on. | 670 // Note: previous line destroyed this. Don't access members from now on. |
607 } | 671 } |
608 | 672 |
609 WebKit::WebGraphicsContext3D* CreateTestContext() { | 673 WebKit::WebGraphicsContext3D* CreateTestContext() { |
610 ui::TestWebGraphicsContext3D* test_context = | 674 ui::TestWebGraphicsContext3D* test_context = |
611 new ui::TestWebGraphicsContext3D(); | 675 new ui::TestWebGraphicsContext3D(); |
612 test_context->Initialize(); | 676 test_context->Initialize(); |
613 return test_context; | 677 return test_context; |
614 } | 678 } |
615 | 679 |
(...skipping 21 matching lines...) Expand all Loading... |
637 delete g_factory; | 701 delete g_factory; |
638 g_factory = NULL; | 702 g_factory = NULL; |
639 } | 703 } |
640 | 704 |
641 // static | 705 // static |
642 ImageTransportFactory* ImageTransportFactory::GetInstance() { | 706 ImageTransportFactory* ImageTransportFactory::GetInstance() { |
643 return g_factory; | 707 return g_factory; |
644 } | 708 } |
645 | 709 |
646 } // namespace content | 710 } // namespace content |
OLD | NEW |