| 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_command_buffer.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" |
| 35 #include "third_party/skia/include/gpu/GrContext.h" |
| 36 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| 34 #include "ui/compositor/compositor.h" | 37 #include "ui/compositor/compositor.h" |
| 35 #include "ui/compositor/compositor_setup.h" | 38 #include "ui/compositor/compositor_setup.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 |
| (...skipping 173 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 369 class GpuProcessTransportFactory | 373 class GpuProcessTransportFactory |
| 370 : public ui::ContextFactory, | 374 : public ui::ContextFactory, |
| 371 public ImageTransportFactory, | 375 public OffscreenContextCommandBufferClient, |
| 372 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 376 public ImageTransportFactory { |
| 373 public: | 377 public: |
| 374 GpuProcessTransportFactory() | 378 GpuProcessTransportFactory() |
| 375 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { | 379 : shared_context_main_thread_(this), |
| 380 shared_context_compositor_thread_(this), |
| 381 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { |
| 376 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy(); | 382 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy(); |
| 377 } | 383 } |
| 378 | 384 |
| 379 virtual ~GpuProcessTransportFactory() { | 385 virtual ~GpuProcessTransportFactory() { |
| 380 DCHECK(per_compositor_data_.empty()); | 386 DCHECK(per_compositor_data_.empty()); |
| 381 } | 387 } |
| 382 | 388 |
| 383 virtual WebGraphicsContext3DCommandBufferImpl* CreateOffscreenContext() | 389 virtual WebGraphicsContext3DCommandBufferImpl* CreateOffscreenContext() |
| 384 OVERRIDE { | 390 OVERRIDE { |
| 385 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client; | 391 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client; |
| 386 return CreateContextCommon(swap_client, 0); | 392 return CreateContextCommon(swap_client, 0); |
| 387 } | 393 } |
| 388 | 394 |
| 389 virtual cc::OutputSurface* CreateOutputSurface( | 395 virtual cc::OutputSurface* CreateOutputSurface( |
| 390 ui::Compositor* compositor) OVERRIDE { | 396 ui::Compositor* compositor) OVERRIDE { |
| 391 PerCompositorData* data = per_compositor_data_[compositor]; | 397 PerCompositorData* data = per_compositor_data_[compositor]; |
| 392 if (!data) | 398 if (!data) |
| 393 data = CreatePerCompositorData(compositor); | 399 data = CreatePerCompositorData(compositor); |
| 394 WebGraphicsContext3DCommandBufferImpl* context = | 400 WebGraphicsContext3DCommandBufferImpl* context = |
| 395 CreateContextCommon(data->swap_client->AsWeakPtr(), | 401 CreateContextCommon(data->swap_client->AsWeakPtr(), |
| 396 data->surface_id); | 402 data->surface_id); |
| 397 return new BrowserCompositorOutputSurface( | 403 return new BrowserCompositorOutputSurface( |
| 398 context, | 404 context, |
| 399 per_compositor_data_[compositor]->surface_id, | 405 per_compositor_data_[compositor]->surface_id, |
| 400 output_surface_proxy_); | 406 output_surface_proxy_); |
| 401 } | 407 } |
| 402 | 408 |
| 409 virtual WebKit::WebGraphicsContext3D* OffscreenContextForMainThread() |
| 410 OVERRIDE { |
| 411 return shared_context_main_thread_.Context3d(); |
| 412 } |
| 413 |
| 414 virtual WebKit::WebGraphicsContext3D* |
| 415 OffscreenContextForCompositorThread() OVERRIDE { |
| 416 return shared_context_compositor_thread_.Context3d(); |
| 417 } |
| 418 |
| 419 virtual GrContext* OffscreenGrContextForMainThread() OVERRIDE { |
| 420 return shared_context_main_thread_.GrContext(); |
| 421 } |
| 422 |
| 423 virtual GrContext* OffscreenGrContextForCompositorThread() OVERRIDE { |
| 424 return shared_context_compositor_thread_.GrContext(); |
| 425 } |
| 426 |
| 403 virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE { | 427 virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE { |
| 404 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 428 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 405 if (it == per_compositor_data_.end()) | 429 if (it == per_compositor_data_.end()) |
| 406 return; | 430 return; |
| 407 PerCompositorData* data = it->second; | 431 PerCompositorData* data = it->second; |
| 408 DCHECK(data); | 432 DCHECK(data); |
| 409 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); | 433 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); |
| 410 delete data; | 434 delete data; |
| 411 per_compositor_data_.erase(it); | 435 per_compositor_data_.erase(it); |
| 412 if (per_compositor_data_.empty()) { | 436 if (per_compositor_data_.empty()) { |
| 413 gl_helper_.reset(); | 437 gl_helper_.reset(); |
| 414 callback_factory_.InvalidateWeakPtrs(); | 438 callback_factory_.InvalidateWeakPtrs(); |
| 415 } | 439 } |
| 416 } | 440 } |
| 417 | 441 |
| 418 virtual ui::ContextFactory* AsContextFactory() OVERRIDE { | 442 virtual ui::ContextFactory* AsContextFactory() OVERRIDE { |
| 419 return this; | 443 return this; |
| 420 } | 444 } |
| 421 | 445 |
| 422 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { | 446 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE { |
| 423 CreateSharedContextLazy(); | |
| 424 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( | 447 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( |
| 425 gfx::kNullPluginWindow, true); | 448 gfx::kNullPluginWindow, true); |
| 426 handle.parent_gpu_process_id = shared_context_->GetGPUProcessID(); | 449 handle.parent_gpu_process_id = |
| 427 handle.parent_client_id = shared_context_->GetChannelID(); | 450 shared_context_main_thread_.Context3d()->GetGPUProcessID(); |
| 428 | 451 handle.parent_client_id = |
| 452 shared_context_main_thread_.Context3d()->GetChannelID(); |
| 429 return handle; | 453 return handle; |
| 430 } | 454 } |
| 431 | 455 |
| 432 virtual void DestroySharedSurfaceHandle( | 456 virtual void DestroySharedSurfaceHandle( |
| 433 gfx::GLSurfaceHandle surface) OVERRIDE { | 457 gfx::GLSurfaceHandle surface) OVERRIDE { |
| 434 } | 458 } |
| 435 | 459 |
| 436 virtual scoped_refptr<ui::Texture> CreateTransportClient( | 460 virtual scoped_refptr<ui::Texture> CreateTransportClient( |
| 437 float device_scale_factor) { | 461 float device_scale_factor) { |
| 438 if (!shared_context_.get()) | 462 if (!shared_context_main_thread_.Context3d()) |
| 439 return NULL; | 463 return NULL; |
| 440 scoped_refptr<ImageTransportClientTexture> image( | 464 scoped_refptr<ImageTransportClientTexture> image( |
| 441 new ImageTransportClientTexture(shared_context_.get(), | 465 new ImageTransportClientTexture( |
| 442 device_scale_factor)); | 466 shared_context_main_thread_.Context3d(), |
| 467 device_scale_factor)); |
| 443 return image; | 468 return image; |
| 444 } | 469 } |
| 445 | 470 |
| 446 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( | 471 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( |
| 447 const gfx::Size& size, | 472 const gfx::Size& size, |
| 448 float device_scale_factor, | 473 float device_scale_factor, |
| 449 unsigned int texture_id) OVERRIDE { | 474 unsigned int texture_id) OVERRIDE { |
| 450 if (!shared_context_.get()) | 475 if (!shared_context_main_thread_.Context3d()) |
| 451 return NULL; | 476 return NULL; |
| 452 scoped_refptr<OwnedTexture> image( | 477 scoped_refptr<OwnedTexture> image(new OwnedTexture( |
| 453 new OwnedTexture(shared_context_.get(), size, device_scale_factor, | 478 shared_context_main_thread_.Context3d(), |
| 454 texture_id)); | 479 size, |
| 480 device_scale_factor, |
| 481 texture_id)); |
| 455 return image; | 482 return image; |
| 456 } | 483 } |
| 457 | 484 |
| 458 virtual GLHelper* GetGLHelper() { | 485 virtual GLHelper* GetGLHelper() { |
| 459 if (!gl_helper_.get()) { | 486 if (!gl_helper_.get()) { |
| 460 CreateSharedContextLazy(); | 487 WebGraphicsContext3DCommandBufferImpl* main_thread_context = |
| 461 WebKit::WebGraphicsContext3D* context_for_thread = | 488 shared_context_main_thread_.Context3d(); |
| 489 if (!main_thread_context) |
| 490 return NULL; |
| 491 WebGraphicsContext3DCommandBufferImpl* helper_thread_context = |
| 462 CreateOffscreenContext(); | 492 CreateOffscreenContext(); |
| 463 if (!context_for_thread) | 493 if (!helper_thread_context) |
| 464 return NULL; | 494 return NULL; |
| 465 gl_helper_.reset(new GLHelper(shared_context_.get(), | 495 gl_helper_.reset(new GLHelper(main_thread_context, |
| 466 context_for_thread)); | 496 helper_thread_context)); |
| 467 } | 497 } |
| 468 return gl_helper_.get(); | 498 return gl_helper_.get(); |
| 469 } | 499 } |
| 470 | 500 |
| 471 virtual uint32 InsertSyncPoint() OVERRIDE { | 501 virtual uint32 InsertSyncPoint() OVERRIDE { |
| 472 if (!shared_context_.get()) | 502 if (!shared_context_main_thread_.Context3d()) |
| 473 return 0; | 503 return 0; |
| 474 return shared_context_->insertSyncPoint(); | 504 return shared_context_main_thread_.Context3d()-> |
| 505 insertSyncPoint(); |
| 475 } | 506 } |
| 476 | 507 |
| 477 virtual void AddObserver(ImageTransportFactoryObserver* observer) { | 508 virtual void AddObserver(ImageTransportFactoryObserver* observer) { |
| 478 observer_list_.AddObserver(observer); | 509 observer_list_.AddObserver(observer); |
| 479 } | 510 } |
| 480 | 511 |
| 481 virtual void RemoveObserver(ImageTransportFactoryObserver* observer) { | 512 virtual void RemoveObserver(ImageTransportFactoryObserver* observer) { |
| 482 observer_list_.RemoveObserver(observer); | 513 observer_list_.RemoveObserver(observer); |
| 483 } | 514 } |
| 484 | 515 |
| 485 // WebGraphicsContextLostCallback implementation, called for the shared | 516 // OffscreenContextCommandBufferClient implementation. |
| 486 // context. | 517 virtual void DidCreateContext( |
| 487 virtual void onContextLost() { | 518 OffscreenContextCommandBuffer* offscreen_context, |
| 488 MessageLoop::current()->PostTask( | 519 bool success) OVERRIDE { |
| 489 FROM_HERE, | 520 if (success) |
| 490 base::Bind(&GpuProcessTransportFactory::OnLostSharedContext, | 521 return; |
| 491 callback_factory_.GetWeakPtr())); | 522 if (offscreen_context == &shared_context_main_thread_) { |
| 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 // OffscreenContextCommandBufferClient implementation. |
| 530 virtual void DidLoseContext(OffscreenContextCommandBuffer* 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 base::Unretained(offscreen_context))); |
| 538 } |
| 539 } |
| 540 |
| 541 void OnLostSwapContext(ui::Compositor* compositor) { |
| 495 LOG(ERROR) << "Lost UI compositor context."; | 542 LOG(ERROR) << "Lost UI compositor context."; |
| 496 PerCompositorData* data = per_compositor_data_[compositor]; | 543 PerCompositorData* data = per_compositor_data_[compositor]; |
| 497 DCHECK(data); | 544 DCHECK(data); |
| 498 | 545 |
| 499 // Prevent callbacks from other contexts in the same share group from | 546 // Prevent callbacks from other contexts in the same share group from |
| 500 // calling us again. | 547 // calling us again. |
| 501 data->swap_client.reset(new CompositorSwapClient(compositor, this)); | 548 data->swap_client.reset(new CompositorSwapClient(compositor, this)); |
| 502 compositor->OnSwapBuffersAborted(); | 549 compositor->OnSwapBuffersAborted(); |
| 503 } | 550 } |
| 504 | 551 |
| 505 private: | 552 private: |
| 506 struct PerCompositorData { | 553 struct PerCompositorData { |
| 507 int surface_id; | 554 int surface_id; |
| 508 scoped_ptr<CompositorSwapClient> swap_client; | 555 scoped_ptr<CompositorSwapClient> swap_client; |
| 509 #if defined(OS_WIN) | 556 #if defined(OS_WIN) |
| 510 scoped_ptr<AcceleratedSurface> accelerated_surface; | 557 scoped_ptr<AcceleratedSurface> accelerated_surface; |
| 511 #endif | 558 #endif |
| 512 }; | 559 }; |
| 513 | 560 |
| 514 PerCompositorData* CreatePerCompositorData(ui::Compositor* compositor) { | 561 PerCompositorData* CreatePerCompositorData(ui::Compositor* compositor) { |
| 515 DCHECK(!per_compositor_data_[compositor]); | 562 DCHECK(!per_compositor_data_[compositor]); |
| 516 | 563 |
| 517 CreateSharedContextLazy(); | |
| 518 | |
| 519 gfx::AcceleratedWidget widget = compositor->widget(); | 564 gfx::AcceleratedWidget widget = compositor->widget(); |
| 520 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); | 565 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); |
| 521 | 566 |
| 522 PerCompositorData* data = new PerCompositorData; | 567 PerCompositorData* data = new PerCompositorData; |
| 523 data->surface_id = tracker->AddSurfaceForNativeWidget(widget); | 568 data->surface_id = tracker->AddSurfaceForNativeWidget(widget); |
| 524 data->swap_client.reset(new CompositorSwapClient(compositor, this)); | 569 data->swap_client.reset(new CompositorSwapClient(compositor, this)); |
| 525 #if defined(OS_WIN) | 570 #if defined(OS_WIN) |
| 526 if (GpuDataManagerImpl::GetInstance()->IsUsingAcceleratedSurface()) | 571 if (GpuDataManagerImpl::GetInstance()->IsUsingAcceleratedSurface()) |
| 527 data->accelerated_surface.reset(new AcceleratedSurface(widget)); | 572 data->accelerated_surface.reset(new AcceleratedSurface(widget)); |
| 528 #endif | 573 #endif |
| (...skipping 24 matching lines...) Expand all Loading... |
| 553 factory, | 598 factory, |
| 554 swap_client)); | 599 swap_client)); |
| 555 if (!context->Initialize( | 600 if (!context->Initialize( |
| 556 attrs, | 601 attrs, |
| 557 false, | 602 false, |
| 558 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) | 603 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) |
| 559 return NULL; | 604 return NULL; |
| 560 return context.release(); | 605 return context.release(); |
| 561 } | 606 } |
| 562 | 607 |
| 563 void CreateSharedContextLazy() { | 608 void OnLostMainThreadSharedContext( |
| 564 if (shared_context_.get()) | 609 OffscreenContextCommandBuffer* offscreen_contxt) { |
| 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, | 610 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
| 589 observer_list_, | 611 observer_list_, |
| 590 OnLostResources()); | 612 OnLostResources()); |
| 591 } | 613 } |
| 592 | 614 |
| 593 typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap; | 615 typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap; |
| 594 PerCompositorDataMap per_compositor_data_; | 616 PerCompositorDataMap per_compositor_data_; |
| 595 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> shared_context_; | 617 OffscreenContextCommandBuffer shared_context_main_thread_; |
| 618 OffscreenContextCommandBuffer shared_context_compositor_thread_; |
| 596 scoped_ptr<GLHelper> gl_helper_; | 619 scoped_ptr<GLHelper> gl_helper_; |
| 597 ObserverList<ImageTransportFactoryObserver> observer_list_; | 620 ObserverList<ImageTransportFactoryObserver> observer_list_; |
| 598 base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_; | 621 base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_; |
| 599 scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_; | 622 scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_; |
| 600 | 623 |
| 601 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory); | 624 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory); |
| 602 }; | 625 }; |
| 603 | 626 |
| 604 void CompositorSwapClient::OnLostContext() { | 627 void CompositorSwapClient::OnLostSwapContext() { |
| 605 factory_->OnLostContext(compositor_); | 628 factory_->OnLostSwapContext(compositor_); |
| 606 // Note: previous line destroyed this. Don't access members from now on. | 629 // Note: previous line destroyed this. Don't access members from now on. |
| 607 } | 630 } |
| 608 | 631 |
| 609 WebKit::WebGraphicsContext3D* CreateTestContext() { | 632 WebKit::WebGraphicsContext3D* CreateTestContext() { |
| 610 ui::TestWebGraphicsContext3D* test_context = | 633 ui::TestWebGraphicsContext3D* test_context = |
| 611 new ui::TestWebGraphicsContext3D(); | 634 new ui::TestWebGraphicsContext3D(); |
| 612 test_context->Initialize(); | 635 test_context->Initialize(); |
| 613 return test_context; | 636 return test_context; |
| 614 } | 637 } |
| 615 | 638 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 637 delete g_factory; | 660 delete g_factory; |
| 638 g_factory = NULL; | 661 g_factory = NULL; |
| 639 } | 662 } |
| 640 | 663 |
| 641 // static | 664 // static |
| 642 ImageTransportFactory* ImageTransportFactory::GetInstance() { | 665 ImageTransportFactory* ImageTransportFactory::GetInstance() { |
| 643 return g_factory; | 666 return g_factory; |
| 644 } | 667 } |
| 645 | 668 |
| 646 } // namespace content | 669 } // namespace content |
| OLD | NEW |