Chromium Code Reviews| 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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
| 16 #include "cc/output_surface.h" | 16 #include "cc/output_surface.h" |
| 17 #include "cc/output_surface_client.h" | 17 #include "cc/output_surface_client.h" |
| 18 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 18 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 19 #include "content/browser/gpu/gpu_data_manager_impl.h" | 19 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 20 #include "content/browser/gpu/gpu_process_host.h" | 20 #include "content/browser/gpu/gpu_process_host.h" |
| 21 #include "content/browser/gpu/gpu_surface_tracker.h" | 21 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 22 #include "content/common/gpu/client/gl_helper.h" | 22 #include "content/common/gpu/client/gl_helper.h" |
| 23 #include "content/common/gpu/client/gpu_channel_host.h" | 23 #include "content/common/gpu/client/gpu_channel_host.h" |
| 24 #include "content/common/gpu/client/offscreen_context.h" | |
| 24 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 25 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 25 #include "content/common/gpu/gpu_messages.h" | 26 #include "content/common/gpu/gpu_messages.h" |
| 26 #include "content/common/gpu/gpu_process_launch_causes.h" | 27 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 27 #include "content/common/webkitplatformsupport_impl.h" | 28 #include "content/common/webkitplatformsupport_impl.h" |
| 28 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
| 29 #include "gpu/GLES2/gl2extchromium.h" | 30 #include "gpu/GLES2/gl2extchromium.h" |
| 30 #include "gpu/ipc/command_buffer_proxy.h" | 31 #include "gpu/ipc/command_buffer_proxy.h" |
| 31 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" | 32 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" |
| 32 #include "third_party/khronos/GLES2/gl2.h" | 33 #include "third_party/khronos/GLES2/gl2.h" |
| 33 #include "third_party/khronos/GLES2/gl2ext.h" | 34 #include "third_party/khronos/GLES2/gl2ext.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 | 218 |
| 218 virtual void OnViewContextSwapBuffersComplete() OVERRIDE { | 219 virtual void OnViewContextSwapBuffersComplete() OVERRIDE { |
| 219 compositor_->OnSwapBuffersComplete(); | 220 compositor_->OnSwapBuffersComplete(); |
| 220 } | 221 } |
| 221 | 222 |
| 222 virtual void OnViewContextSwapBuffersAborted() OVERRIDE { | 223 virtual void OnViewContextSwapBuffersAborted() OVERRIDE { |
| 223 // Recreating contexts directly from here causes issues, so post a task | 224 // Recreating contexts directly from here causes issues, so post a task |
| 224 // instead. | 225 // instead. |
| 225 // TODO(piman): Fix the underlying issues. | 226 // TODO(piman): Fix the underlying issues. |
| 226 MessageLoop::current()->PostTask(FROM_HERE, | 227 MessageLoop::current()->PostTask(FROM_HERE, |
| 227 base::Bind(&CompositorSwapClient::OnLostContext, this->AsWeakPtr())); | 228 base::Bind(&CompositorSwapClient::OnLostSwapContext, |
| 229 this->AsWeakPtr())); | |
| 228 } | 230 } |
| 229 | 231 |
| 230 private: | 232 private: |
| 231 void OnLostContext(); | 233 void OnLostSwapContext(); |
| 232 ui::Compositor* compositor_; | 234 ui::Compositor* compositor_; |
| 233 GpuProcessTransportFactory* factory_; | 235 GpuProcessTransportFactory* factory_; |
| 234 | 236 |
| 235 DISALLOW_COPY_AND_ASSIGN(CompositorSwapClient); | 237 DISALLOW_COPY_AND_ASSIGN(CompositorSwapClient); |
| 236 }; | 238 }; |
| 237 | 239 |
| 238 class BrowserCompositorOutputSurface; | 240 class BrowserCompositorOutputSurface; |
| 239 | 241 |
| 240 // Directs vsync updates to the appropriate BrowserCompositorOutputSurface. | 242 // Directs vsync updates to the appropriate BrowserCompositorOutputSurface. |
| 241 class BrowserCompositorOutputSurfaceProxy | 243 class BrowserCompositorOutputSurfaceProxy |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 | 363 |
| 362 void BrowserCompositorOutputSurfaceProxy::OnUpdateVSyncParameters( | 364 void BrowserCompositorOutputSurfaceProxy::OnUpdateVSyncParameters( |
| 363 int surface_id, base::TimeTicks timebase, base::TimeDelta interval) { | 365 int surface_id, base::TimeTicks timebase, base::TimeDelta interval) { |
| 364 BrowserCompositorOutputSurface* surface = surface_map_.Lookup(surface_id); | 366 BrowserCompositorOutputSurface* surface = surface_map_.Lookup(surface_id); |
| 365 if (surface) | 367 if (surface) |
| 366 surface->OnUpdateVSyncParameters(timebase, interval); | 368 surface->OnUpdateVSyncParameters(timebase, interval); |
| 367 } | 369 } |
| 368 | 370 |
| 369 class GpuProcessTransportFactory | 371 class GpuProcessTransportFactory |
| 370 : public ui::ContextFactory, | 372 : public ui::ContextFactory, |
| 371 public ImageTransportFactory, | 373 public OffscreenContextClient, |
| 372 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 374 public ImageTransportFactory { |
| 373 public: | 375 public: |
| 374 GpuProcessTransportFactory() | 376 GpuProcessTransportFactory() |
| 375 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { | 377 : shared_context_main_thread_(this), |
| 378 shared_context_compositor_thread_(this), | |
| 379 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { | |
| 376 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy(); | 380 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy(); |
| 377 } | 381 } |
| 378 | 382 |
| 379 virtual ~GpuProcessTransportFactory() { | 383 virtual ~GpuProcessTransportFactory() { |
| 380 DCHECK(per_compositor_data_.empty()); | 384 DCHECK(per_compositor_data_.empty()); |
| 381 } | 385 } |
| 382 | 386 |
| 383 virtual WebGraphicsContext3DCommandBufferImpl* CreateOffscreenContext() | 387 virtual WebGraphicsContext3DCommandBufferImpl* CreateOffscreenContext() |
| 384 OVERRIDE { | 388 OVERRIDE { |
| 385 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client; | 389 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client; |
| 386 return CreateContextCommon(swap_client, 0); | 390 return CreateContextCommon(swap_client, 0); |
| 387 } | 391 } |
| 388 | 392 |
| 389 virtual cc::OutputSurface* CreateOutputSurface( | 393 virtual cc::OutputSurface* CreateOutputSurface( |
| 390 ui::Compositor* compositor) OVERRIDE { | 394 ui::Compositor* compositor) OVERRIDE { |
| 391 PerCompositorData* data = per_compositor_data_[compositor]; | 395 PerCompositorData* data = per_compositor_data_[compositor]; |
| 392 if (!data) | 396 if (!data) |
| 393 data = CreatePerCompositorData(compositor); | 397 data = CreatePerCompositorData(compositor); |
| 394 WebGraphicsContext3DCommandBufferImpl* context = | 398 WebGraphicsContext3DCommandBufferImpl* context = |
| 395 CreateContextCommon(data->swap_client->AsWeakPtr(), | 399 CreateContextCommon(data->swap_client->AsWeakPtr(), |
| 396 data->surface_id); | 400 data->surface_id); |
| 397 return new BrowserCompositorOutputSurface( | 401 return new BrowserCompositorOutputSurface( |
| 398 context, | 402 context, |
| 399 per_compositor_data_[compositor]->surface_id, | 403 per_compositor_data_[compositor]->surface_id, |
| 400 output_surface_proxy_); | 404 output_surface_proxy_); |
| 401 } | 405 } |
| 402 | 406 |
| 407 virtual WebKit::WebGraphicsContext3D* OffscreenContextForMainThread() | |
| 408 OVERRIDE { | |
| 409 return shared_context_main_thread_.Context3d(); | |
| 410 } | |
| 411 | |
| 412 virtual WebKit::WebGraphicsContext3D* | |
| 413 OffscreenContextForCompositorThread() OVERRIDE { | |
| 414 return shared_context_compositor_thread_.Context3d(); | |
| 415 } | |
| 416 | |
| 417 virtual GrContext* OffscreenGrContextForMainThread() OVERRIDE { | |
| 418 return shared_context_main_thread_.GrContext(); | |
| 419 } | |
| 420 | |
| 421 virtual GrContext* OffscreenGrContextForCompositorThread() OVERRIDE { | |
| 422 return shared_context_compositor_thread_.GrContext(); | |
| 423 } | |
| 424 | |
| 403 virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE { | 425 virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE { |
| 404 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 426 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 405 if (it == per_compositor_data_.end()) | 427 if (it == per_compositor_data_.end()) |
| 406 return; | 428 return; |
| 407 PerCompositorData* data = it->second; | 429 PerCompositorData* data = it->second; |
| 408 DCHECK(data); | 430 DCHECK(data); |
| 409 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); | 431 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); |
| 410 delete data; | 432 delete data; |
| 411 per_compositor_data_.erase(it); | 433 per_compositor_data_.erase(it); |
| 412 if (per_compositor_data_.empty()) { | 434 if (per_compositor_data_.empty()) { |
| 413 gl_helper_.reset(); | 435 gl_helper_.reset(); |
| 414 callback_factory_.InvalidateWeakPtrs(); | 436 callback_factory_.InvalidateWeakPtrs(); |
| 415 } | 437 } |
| 416 } | 438 } |
| 417 | 439 |
| 418 virtual ui::ContextFactory* AsContextFactory() OVERRIDE { | 440 virtual ui::ContextFactory* AsContextFactory() OVERRIDE { |
| 419 return this; | 441 return this; |
| 420 } | 442 } |
| 421 | 443 |
| 422 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { | 444 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { |
| 423 CreateSharedContextLazy(); | 445 // This class always creates offscreen contests of this type. |
| 446 WebGraphicsContext3DCommandBufferImpl* context3d = | |
| 447 static_cast<WebGraphicsContext3DCommandBufferImpl*>( | |
| 448 shared_context_main_thread_.Context3d()); | |
| 449 | |
| 424 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( | 450 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( |
| 425 gfx::kNullPluginWindow, true); | 451 gfx::kNullPluginWindow, true); |
| 426 handle.parent_gpu_process_id = shared_context_->GetGPUProcessID(); | 452 handle.parent_gpu_process_id = context3d->GetGPUProcessID(); |
| 427 handle.parent_client_id = shared_context_->GetChannelID(); | 453 handle.parent_client_id = context3d->GetChannelID(); |
| 428 | |
| 429 return handle; | 454 return handle; |
| 430 } | 455 } |
| 431 | 456 |
| 432 virtual void DestroySharedSurfaceHandle( | 457 virtual void DestroySharedSurfaceHandle( |
| 433 gfx::GLSurfaceHandle surface) OVERRIDE { | 458 gfx::GLSurfaceHandle surface) OVERRIDE { |
| 434 } | 459 } |
| 435 | 460 |
| 436 virtual scoped_refptr<ui::Texture> CreateTransportClient( | 461 virtual scoped_refptr<ui::Texture> CreateTransportClient( |
| 437 float device_scale_factor) { | 462 float device_scale_factor) { |
| 438 if (!shared_context_.get()) | 463 if (!shared_context_main_thread_.Context3d()) |
| 439 return NULL; | 464 return NULL; |
| 440 scoped_refptr<ImageTransportClientTexture> image( | 465 scoped_refptr<ImageTransportClientTexture> image( |
| 441 new ImageTransportClientTexture(shared_context_.get(), | 466 new ImageTransportClientTexture( |
| 442 device_scale_factor)); | 467 shared_context_main_thread_.Context3d(), |
| 468 device_scale_factor)); | |
| 443 return image; | 469 return image; |
| 444 } | 470 } |
| 445 | 471 |
| 446 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( | 472 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( |
| 447 const gfx::Size& size, | 473 const gfx::Size& size, |
| 448 float device_scale_factor, | 474 float device_scale_factor, |
| 449 unsigned int texture_id) OVERRIDE { | 475 unsigned int texture_id) OVERRIDE { |
| 450 if (!shared_context_.get()) | 476 if (!shared_context_main_thread_.Context3d()) |
| 451 return NULL; | 477 return NULL; |
| 452 scoped_refptr<OwnedTexture> image( | 478 scoped_refptr<OwnedTexture> image(new OwnedTexture( |
| 453 new OwnedTexture(shared_context_.get(), size, device_scale_factor, | 479 shared_context_main_thread_.Context3d(), |
| 454 texture_id)); | 480 size, |
| 481 device_scale_factor, | |
| 482 texture_id)); | |
| 455 return image; | 483 return image; |
| 456 } | 484 } |
| 457 | 485 |
| 458 virtual GLHelper* GetGLHelper() { | 486 virtual GLHelper* GetGLHelper() { |
| 459 if (!gl_helper_.get()) { | 487 if (!gl_helper_.get()) { |
| 460 CreateSharedContextLazy(); | 488 WebKit::WebGraphicsContext3D* main_thread_context = |
| 461 WebKit::WebGraphicsContext3D* context_for_thread = | 489 shared_context_main_thread_.Context3d(); |
| 490 if (!main_thread_context) | |
| 491 return NULL; | |
| 492 WebGraphicsContext3DCommandBufferImpl* helper_thread_context = | |
| 462 CreateOffscreenContext(); | 493 CreateOffscreenContext(); |
| 463 if (!context_for_thread) | 494 if (!helper_thread_context) |
| 464 return NULL; | 495 return NULL; |
| 465 gl_helper_.reset(new GLHelper(shared_context_.get(), | 496 gl_helper_.reset(new GLHelper(main_thread_context, |
| 466 context_for_thread)); | 497 helper_thread_context)); |
| 467 } | 498 } |
| 468 return gl_helper_.get(); | 499 return gl_helper_.get(); |
| 469 } | 500 } |
| 470 | 501 |
| 471 virtual uint32 InsertSyncPoint() OVERRIDE { | 502 virtual uint32 InsertSyncPoint() OVERRIDE { |
| 472 if (!shared_context_.get()) | 503 if (!shared_context_main_thread_.Context3d()) |
| 473 return 0; | 504 return 0; |
| 474 return shared_context_->insertSyncPoint(); | 505 return shared_context_main_thread_.Context3d()-> |
| 506 insertSyncPoint(); | |
| 475 } | 507 } |
| 476 | 508 |
| 477 virtual void AddObserver(ImageTransportFactoryObserver* observer) { | 509 virtual void AddObserver(ImageTransportFactoryObserver* observer) { |
| 478 observer_list_.AddObserver(observer); | 510 observer_list_.AddObserver(observer); |
| 479 } | 511 } |
| 480 | 512 |
| 481 virtual void RemoveObserver(ImageTransportFactoryObserver* observer) { | 513 virtual void RemoveObserver(ImageTransportFactoryObserver* observer) { |
| 482 observer_list_.RemoveObserver(observer); | 514 observer_list_.RemoveObserver(observer); |
| 483 } | 515 } |
| 484 | 516 |
| 485 // WebGraphicsContextLostCallback implementation, called for the shared | 517 // OffscreenContextClient implementation. |
| 486 // context. | 518 virtual void DidCreateContext(OffscreenContext* offscreen_context, |
| 487 virtual void onContextLost() { | 519 bool success) OVERRIDE { |
| 488 MessageLoop::current()->PostTask( | 520 if (success) |
| 489 FROM_HERE, | 521 return; |
| 490 base::Bind(&GpuProcessTransportFactory::OnLostSharedContext, | 522 if (offscreen_context == &shared_context_main_thread_) { |
| 491 callback_factory_.GetWeakPtr())); | 523 // If we can't recreate contexts, we won't be able to show the UI. Better |
| 524 // crash at this point. | |
| 525 LOG(FATAL) << "Failed to initialize UI shared main thread context."; | |
| 526 } | |
| 492 } | 527 } |
| 493 | 528 |
| 494 void OnLostContext(ui::Compositor* compositor) { | 529 // OffscreenContextClient implementation. |
| 530 virtual void DidLoseContext(OffscreenContext* offscreen_context) | |
| 531 OVERRIDE { | |
| 532 if (offscreen_context == &shared_context_main_thread_) { | |
| 533 MessageLoop::current()->PostTask( | |
| 534 FROM_HERE, | |
| 535 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext, | |
| 536 callback_factory_.GetWeakPtr())); | |
| 537 } | |
| 538 } | |
| 539 | |
| 540 void OnLostSwapContext(ui::Compositor* compositor) { | |
| 495 LOG(ERROR) << "Lost UI compositor context."; | 541 LOG(ERROR) << "Lost UI compositor context."; |
| 496 PerCompositorData* data = per_compositor_data_[compositor]; | 542 PerCompositorData* data = per_compositor_data_[compositor]; |
| 497 DCHECK(data); | 543 DCHECK(data); |
| 498 | 544 |
| 499 // Prevent callbacks from other contexts in the same share group from | 545 // Prevent callbacks from other contexts in the same share group from |
| 500 // calling us again. | 546 // calling us again. |
| 501 data->swap_client.reset(new CompositorSwapClient(compositor, this)); | 547 data->swap_client.reset(new CompositorSwapClient(compositor, this)); |
| 502 compositor->OnSwapBuffersAborted(); | 548 compositor->OnSwapBuffersAborted(); |
| 503 } | 549 } |
| 504 | 550 |
| 505 private: | 551 private: |
| 506 struct PerCompositorData { | 552 struct PerCompositorData { |
| 507 int surface_id; | 553 int surface_id; |
| 508 scoped_ptr<CompositorSwapClient> swap_client; | 554 scoped_ptr<CompositorSwapClient> swap_client; |
| 509 #if defined(OS_WIN) | 555 #if defined(OS_WIN) |
| 510 scoped_ptr<AcceleratedSurface> accelerated_surface; | 556 scoped_ptr<AcceleratedSurface> accelerated_surface; |
| 511 #endif | 557 #endif |
| 512 }; | 558 }; |
| 513 | 559 |
| 514 PerCompositorData* CreatePerCompositorData(ui::Compositor* compositor) { | 560 PerCompositorData* CreatePerCompositorData(ui::Compositor* compositor) { |
| 515 DCHECK(!per_compositor_data_[compositor]); | 561 DCHECK(!per_compositor_data_[compositor]); |
| 516 | 562 |
| 517 CreateSharedContextLazy(); | |
| 518 | |
| 519 gfx::AcceleratedWidget widget = compositor->widget(); | 563 gfx::AcceleratedWidget widget = compositor->widget(); |
| 520 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); | 564 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); |
| 521 | 565 |
| 522 PerCompositorData* data = new PerCompositorData; | 566 PerCompositorData* data = new PerCompositorData; |
| 523 data->surface_id = tracker->AddSurfaceForNativeWidget(widget); | 567 data->surface_id = tracker->AddSurfaceForNativeWidget(widget); |
| 524 data->swap_client.reset(new CompositorSwapClient(compositor, this)); | 568 data->swap_client.reset(new CompositorSwapClient(compositor, this)); |
| 525 #if defined(OS_WIN) | 569 #if defined(OS_WIN) |
| 526 if (GpuDataManagerImpl::GetInstance()->IsUsingAcceleratedSurface()) | 570 if (GpuDataManagerImpl::GetInstance()->IsUsingAcceleratedSurface()) |
| 527 data->accelerated_surface.reset(new AcceleratedSurface(widget)); | 571 data->accelerated_surface.reset(new AcceleratedSurface(widget)); |
| 528 #endif | 572 #endif |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 553 factory, | 597 factory, |
| 554 swap_client)); | 598 swap_client)); |
| 555 if (!context->Initialize( | 599 if (!context->Initialize( |
| 556 attrs, | 600 attrs, |
| 557 false, | 601 false, |
| 558 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) | 602 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) |
| 559 return NULL; | 603 return NULL; |
| 560 return context.release(); | 604 return context.release(); |
| 561 } | 605 } |
| 562 | 606 |
| 563 void CreateSharedContextLazy() { | 607 void OnLostMainThreadSharedContext() { |
|
piman
2013/02/11 18:45:33
Mmh, there was code here to keep alive the context
danakj
2013/02/11 18:58:13
Hm, ya I lost the GLHelper thing. I kept the resou
| |
| 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, | 608 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
| 589 observer_list_, | 609 observer_list_, |
| 590 OnLostResources()); | 610 OnLostResources()); |
| 591 } | 611 } |
| 592 | 612 |
| 593 typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap; | 613 typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap; |
| 594 PerCompositorDataMap per_compositor_data_; | 614 PerCompositorDataMap per_compositor_data_; |
| 595 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> shared_context_; | 615 OffscreenContext shared_context_main_thread_; |
| 616 OffscreenContext shared_context_compositor_thread_; | |
| 596 scoped_ptr<GLHelper> gl_helper_; | 617 scoped_ptr<GLHelper> gl_helper_; |
| 597 ObserverList<ImageTransportFactoryObserver> observer_list_; | 618 ObserverList<ImageTransportFactoryObserver> observer_list_; |
| 598 base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_; | 619 base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_; |
| 599 scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_; | 620 scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_; |
| 600 | 621 |
| 601 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory); | 622 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory); |
| 602 }; | 623 }; |
| 603 | 624 |
| 604 void CompositorSwapClient::OnLostContext() { | 625 void CompositorSwapClient::OnLostSwapContext() { |
| 605 factory_->OnLostContext(compositor_); | 626 factory_->OnLostSwapContext(compositor_); |
| 606 // Note: previous line destroyed this. Don't access members from now on. | 627 // Note: previous line destroyed this. Don't access members from now on. |
| 607 } | 628 } |
| 608 | 629 |
| 609 WebKit::WebGraphicsContext3D* CreateTestContext() { | 630 WebKit::WebGraphicsContext3D* CreateTestContext() { |
| 610 ui::TestWebGraphicsContext3D* test_context = | 631 ui::TestWebGraphicsContext3D* test_context = |
| 611 new ui::TestWebGraphicsContext3D(); | 632 new ui::TestWebGraphicsContext3D(); |
| 612 test_context->Initialize(); | 633 test_context->Initialize(); |
| 613 return test_context; | 634 return test_context; |
| 614 } | 635 } |
| 615 | 636 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 637 delete g_factory; | 658 delete g_factory; |
| 638 g_factory = NULL; | 659 g_factory = NULL; |
| 639 } | 660 } |
| 640 | 661 |
| 641 // static | 662 // static |
| 642 ImageTransportFactory* ImageTransportFactory::GetInstance() { | 663 ImageTransportFactory* ImageTransportFactory::GetInstance() { |
| 643 return g_factory; | 664 return g_factory; |
| 644 } | 665 } |
| 645 | 666 |
| 646 } // namespace content | 667 } // namespace content |
| OLD | NEW |