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" |
36 #include "ui/compositor/test_web_graphics_context_3d.h" | 38 #include "ui/compositor/test_web_graphics_context_3d.h" |
37 #include "ui/gfx/native_widget_types.h" | 39 #include "ui/gfx/native_widget_types.h" |
38 #include "ui/gfx/size.h" | 40 #include "ui/gfx/size.h" |
39 | 41 |
40 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
41 #include "ui/surface/accelerated_surface_win.h" | 43 #include "ui/surface/accelerated_surface_win.h" |
42 #endif | 44 #endif |
43 | 45 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_; | 361 scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_; |
360 }; | 362 }; |
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 |
371 // TODO(danakj): Go directly to GPU process instead of through WGC3D. | |
372 class GrContextMemoryManager | |
373 : public WebKit::WebGraphicsContext3D:: | |
374 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM { | |
375 public: | |
376 GrContextMemoryManager( | |
377 WebKit::WebGraphicsContext3D* context3d, GrContext* gr_context) | |
378 : context3d_(context3d), | |
379 gr_context_(gr_context) { | |
380 | |
381 gr_context_->setTextureCacheLimits( | |
382 kMaxGaneshTextureCacheCount, kMaxGaneshTextureCacheBytes); | |
383 context3d_->setMemoryAllocationChangedCallbackCHROMIUM(this); | |
384 } | |
385 ~GrContextMemoryManager() { | |
386 context3d_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); | |
387 } | |
388 | |
389 virtual void onMemoryAllocationChanged( | |
390 WebKit::WebGraphicsMemoryAllocation allocation) OVERRIDE { | |
391 if (!gr_context_) | |
392 return; | |
393 | |
394 if (!allocation.gpuResourceSizeInBytes) { | |
395 gr_context_->freeGpuResources(); | |
396 gr_context_->setTextureCacheLimits(0, 0); | |
397 } else { | |
398 gr_context_->setTextureCacheLimits( | |
399 kMaxGaneshTextureCacheCount, kMaxGaneshTextureCacheBytes); | |
400 } | |
401 } | |
402 | |
403 private: | |
404 // The limit of the number of textures we hold in the GrContext's | |
405 // bitmap->texture cache. | |
406 static const int kMaxGaneshTextureCacheCount = 2048; | |
407 // The limit of the bytes allocated toward textures in the GrContext's | |
408 // bitmap->texture cache. | |
409 static const size_t kMaxGaneshTextureCacheBytes = 96 * 1024 * 1024; | |
410 | |
411 WebKit::WebGraphicsContext3D* context3d_; | |
412 GrContext* gr_context_; | |
413 }; | |
414 | |
369 class GpuProcessTransportFactory | 415 class GpuProcessTransportFactory |
370 : public ui::ContextFactory, | 416 : public ui::ContextFactory, |
371 public ImageTransportFactory, | 417 public ImageTransportFactory, |
372 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 418 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
373 public: | 419 public: |
374 GpuProcessTransportFactory() | 420 GpuProcessTransportFactory() |
375 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { | 421 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { |
376 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy(); | 422 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy(); |
377 } | 423 } |
378 | 424 |
(...skipping 14 matching lines...) Expand all Loading... | |
393 data = CreatePerCompositorData(compositor); | 439 data = CreatePerCompositorData(compositor); |
394 WebGraphicsContext3DCommandBufferImpl* context = | 440 WebGraphicsContext3DCommandBufferImpl* context = |
395 CreateContextCommon(data->swap_client->AsWeakPtr(), | 441 CreateContextCommon(data->swap_client->AsWeakPtr(), |
396 data->surface_id); | 442 data->surface_id); |
397 return new BrowserCompositorOutputSurface( | 443 return new BrowserCompositorOutputSurface( |
398 context, | 444 context, |
399 per_compositor_data_[compositor]->surface_id, | 445 per_compositor_data_[compositor]->surface_id, |
400 output_surface_proxy_); | 446 output_surface_proxy_); |
401 } | 447 } |
402 | 448 |
449 WebKit::WebGraphicsContext3D* CreateOrGetOffscreenSkiaContextForMainThread() { | |
450 CreateOrGetOffscreenContextCommon( | |
451 &offscreen_skia_context_main_thread, | |
452 &offscreen_skia_gr_context_main_thread, | |
453 &offscreen_skia_gr_context_memory_manager_main_thread); | |
454 return offscreen_skia_context_main_thread.get(); | |
455 } | |
456 | |
457 WebKit::WebGraphicsContext3D* | |
458 CreateOrGetOffscreenSkiaContextForCompositorThread() { | |
459 CreateOrGetOffscreenContextCommon( | |
460 &offscreen_skia_context_compositor_thread, | |
461 &offscreen_skia_gr_context_compositor_thread, | |
462 &offscreen_skia_gr_context_memory_manager_compositor_thread); | |
463 return offscreen_skia_context_compositor_thread.get(); | |
464 } | |
465 | |
466 GrContext* CreateOrGetOffscreenSkiaGrContextForMainThread() { | |
467 CreateOrGetOffscreenSkiaContextForMainThread(); | |
468 CreateOrGetGrContextCommon( | |
469 offscreen_skia_context_main_thread.get(), | |
470 &offscreen_skia_gr_context_main_thread, | |
471 &offscreen_skia_gr_context_memory_manager_main_thread); | |
472 return offscreen_skia_gr_context_main_thread.get(); | |
473 } | |
474 | |
475 GrContext* CreateOrGetOffscreenSkiaGrContextForCompositorThread() { | |
476 CreateOrGetOffscreenSkiaContextForCompositorThread(); | |
477 CreateOrGetGrContextCommon( | |
478 offscreen_skia_context_compositor_thread.get(), | |
479 &offscreen_skia_gr_context_compositor_thread, | |
480 &offscreen_skia_gr_context_memory_manager_compositor_thread); | |
481 return offscreen_skia_gr_context_compositor_thread.get(); | |
482 } | |
483 | |
403 virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE { | 484 virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE { |
404 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 485 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
405 if (it == per_compositor_data_.end()) | 486 if (it == per_compositor_data_.end()) |
406 return; | 487 return; |
407 PerCompositorData* data = it->second; | 488 PerCompositorData* data = it->second; |
408 DCHECK(data); | 489 DCHECK(data); |
409 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); | 490 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); |
410 delete data; | 491 delete data; |
411 per_compositor_data_.erase(it); | 492 per_compositor_data_.erase(it); |
412 if (per_compositor_data_.empty()) { | 493 if (per_compositor_data_.empty()) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 factory, | 634 factory, |
554 swap_client)); | 635 swap_client)); |
555 if (!context->Initialize( | 636 if (!context->Initialize( |
556 attrs, | 637 attrs, |
557 false, | 638 false, |
558 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) | 639 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) |
559 return NULL; | 640 return NULL; |
560 return context.release(); | 641 return context.release(); |
561 } | 642 } |
562 | 643 |
644 void CreateOrGetOffscreenContextCommon( | |
645 scoped_ptr<WebKit::WebGraphicsContext3D>* context3d, | |
646 skia::RefPtr<GrContext>* gr_context, | |
647 scoped_ptr<GrContextMemoryManager>* gr_context_memory_manager) { | |
648 if ((*context3d)) { | |
649 if (!(*context3d)->makeContextCurrent() || | |
650 (*context3d)->getGraphicsResetStatusARB()) { | |
651 gr_context_memory_manager->reset(); | |
652 if ((*gr_context)) | |
653 (*gr_context)->contextDestroyed(); | |
654 gr_context->clear(); | |
655 context3d->reset(); | |
656 } | |
657 } | |
658 | |
659 if (!(*context3d)) | |
660 (*context3d) = make_scoped_ptr(CreateOffscreenContext()); | |
piman
2013/02/05 22:42:48
nit: context3d->reset(CreateOffscreenContext()) is
danakj
2013/02/05 22:56:00
Done.
| |
661 } | |
662 | |
663 void CreateOrGetGrContextCommon( | |
664 WebKit::WebGraphicsContext3D* context3d, | |
665 skia::RefPtr<GrContext>* gr_context, | |
666 scoped_ptr<GrContextMemoryManager>* gr_context_memory_manager) { | |
667 if (!context3d) | |
668 return; | |
669 if (*gr_context) | |
670 return; | |
671 | |
672 skia::RefPtr<GrGLInterface> interface = skia::AdoptRef( | |
673 context3d->createGrGLInterface()); | |
674 *gr_context = skia::AdoptRef(GrContext::Create( | |
675 kOpenGL_Shaders_GrEngine, | |
676 reinterpret_cast<GrPlatform3DContext>(interface.get()))); | |
piman
2013/02/05 22:42:48
/cry on the reinterpret_cast
danakj
2013/02/05 22:56:00
Ya... more incoming as well :X
| |
677 | |
678 if (*gr_context) { | |
679 *gr_context_memory_manager = make_scoped_ptr(new GrContextMemoryManager( | |
piman
2013/02/05 22:42:48
nit: can also use reset(...) here
danakj
2013/02/05 22:56:00
Done.
| |
680 context3d, gr_context->get())); | |
681 } | |
682 } | |
683 | |
563 void CreateSharedContextLazy() { | 684 void CreateSharedContextLazy() { |
564 if (shared_context_.get()) | 685 if (shared_context_.get()) |
565 return; | 686 return; |
566 | 687 |
567 shared_context_.reset(CreateOffscreenContext()); | 688 shared_context_.reset(CreateOffscreenContext()); |
568 if (!shared_context_.get()) { | 689 if (!shared_context_.get()) { |
569 // If we can't recreate contexts, we won't be able to show the UI. Better | 690 // If we can't recreate contexts, we won't be able to show the UI. Better |
570 // crash at this point. | 691 // crash at this point. |
571 LOG(FATAL) << "Failed to initialize UI shared context."; | 692 LOG(FATAL) << "Failed to initialize UI shared context."; |
572 } | 693 } |
(...skipping 18 matching lines...) Expand all Loading... | |
591 } | 712 } |
592 | 713 |
593 typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap; | 714 typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap; |
594 PerCompositorDataMap per_compositor_data_; | 715 PerCompositorDataMap per_compositor_data_; |
595 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> shared_context_; | 716 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> shared_context_; |
596 scoped_ptr<GLHelper> gl_helper_; | 717 scoped_ptr<GLHelper> gl_helper_; |
597 ObserverList<ImageTransportFactoryObserver> observer_list_; | 718 ObserverList<ImageTransportFactoryObserver> observer_list_; |
598 base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_; | 719 base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_; |
599 scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_; | 720 scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_; |
600 | 721 |
722 // Per-process data. | |
723 scoped_ptr<WebKit::WebGraphicsContext3D> offscreen_skia_context_main_thread; | |
piman
2013/02/05 22:42:48
Could we reuse the shared_context_ for the main th
danakj
2013/02/05 22:56:00
I don't know, it looks like something that is crea
| |
724 scoped_ptr<WebKit::WebGraphicsContext3D> | |
725 offscreen_skia_context_compositor_thread; | |
726 skia::RefPtr<GrContext> offscreen_skia_gr_context_main_thread; | |
727 skia::RefPtr<GrContext> offscreen_skia_gr_context_compositor_thread; | |
728 scoped_ptr<GrContextMemoryManager> | |
729 offscreen_skia_gr_context_memory_manager_main_thread; | |
730 scoped_ptr<GrContextMemoryManager> | |
731 offscreen_skia_gr_context_memory_manager_compositor_thread; | |
732 | |
601 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory); | 733 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory); |
602 }; | 734 }; |
603 | 735 |
604 void CompositorSwapClient::OnLostContext() { | 736 void CompositorSwapClient::OnLostContext() { |
605 factory_->OnLostContext(compositor_); | 737 factory_->OnLostContext(compositor_); |
606 // Note: previous line destroyed this. Don't access members from now on. | 738 // Note: previous line destroyed this. Don't access members from now on. |
607 } | 739 } |
608 | 740 |
609 WebKit::WebGraphicsContext3D* CreateTestContext() { | 741 WebKit::WebGraphicsContext3D* CreateTestContext() { |
610 ui::TestWebGraphicsContext3D* test_context = | 742 ui::TestWebGraphicsContext3D* test_context = |
(...skipping 26 matching lines...) Expand all Loading... | |
637 delete g_factory; | 769 delete g_factory; |
638 g_factory = NULL; | 770 g_factory = NULL; |
639 } | 771 } |
640 | 772 |
641 // static | 773 // static |
642 ImageTransportFactory* ImageTransportFactory::GetInstance() { | 774 ImageTransportFactory* ImageTransportFactory::GetInstance() { |
643 return g_factory; | 775 return g_factory; |
644 } | 776 } |
645 | 777 |
646 } // namespace content | 778 } // namespace content |
OLD | NEW |