Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: content/browser/renderer_host/image_transport_factory.cc

Issue 17447007: Change WGC3DInProcessCBImpl factories to return a base class pointer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/test/pixel_test.cc ('k') | content/browser/renderer_host/image_transport_factory_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 }; 478 };
479 479
480 // Adapts a WebGraphicsContext3DCommandBufferImpl into a 480 // Adapts a WebGraphicsContext3DCommandBufferImpl into a
481 // cc::OutputSurface that also handles vsync parameter updates 481 // cc::OutputSurface that also handles vsync parameter updates
482 // arriving from the GPU process. 482 // arriving from the GPU process.
483 class BrowserCompositorOutputSurface 483 class BrowserCompositorOutputSurface
484 : public cc::OutputSurface, 484 : public cc::OutputSurface,
485 public base::NonThreadSafe { 485 public base::NonThreadSafe {
486 public: 486 public:
487 BrowserCompositorOutputSurface( 487 BrowserCompositorOutputSurface(
488 WebGraphicsContext3DCommandBufferImpl* context, 488 scoped_ptr<WebKit::WebGraphicsContext3D> context,
489 int surface_id, 489 int surface_id,
490 BrowserCompositorOutputSurfaceProxy* output_surface_proxy, 490 BrowserCompositorOutputSurfaceProxy* output_surface_proxy,
491 base::MessageLoopProxy* compositor_message_loop, 491 base::MessageLoopProxy* compositor_message_loop,
492 base::WeakPtr<ui::Compositor> compositor) 492 base::WeakPtr<ui::Compositor> compositor)
493 : OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(context)), 493 : OutputSurface(context.Pass()),
494 surface_id_(surface_id), 494 surface_id_(surface_id),
495 output_surface_proxy_(output_surface_proxy), 495 output_surface_proxy_(output_surface_proxy),
496 compositor_message_loop_(compositor_message_loop), 496 compositor_message_loop_(compositor_message_loop),
497 compositor_(compositor) { 497 compositor_(compositor) {
498 CommandLine* command_line = CommandLine::ForCurrentProcess(); 498 CommandLine* command_line = CommandLine::ForCurrentProcess();
499 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) { 499 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) {
500 std::string string_value = command_line->GetSwitchValueASCII( 500 std::string string_value = command_line->GetSwitchValueASCII(
501 switches::kUIMaxFramesPending); 501 switches::kUIMaxFramesPending);
502 int int_value; 502 int int_value;
503 if (base::StringToInt(string_value, &int_value)) 503 if (base::StringToInt(string_value, &int_value))
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 public: 621 public:
622 GpuProcessTransportFactory() 622 GpuProcessTransportFactory()
623 : callback_factory_(this) { 623 : callback_factory_(this) {
624 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy(); 624 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy();
625 } 625 }
626 626
627 virtual ~GpuProcessTransportFactory() { 627 virtual ~GpuProcessTransportFactory() {
628 DCHECK(per_compositor_data_.empty()); 628 DCHECK(per_compositor_data_.empty());
629 } 629 }
630 630
631 virtual WebGraphicsContext3DCommandBufferImpl* CreateOffscreenContext() 631 scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
632 OVERRIDE { 632 CreateOffscreenCommandBufferContext() {
633 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client; 633 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client;
634 return CreateContextCommon(swap_client, 0); 634 return CreateContextCommon(swap_client, 0);
635 } 635 }
636 636
637 virtual scoped_ptr<WebKit::WebGraphicsContext3D> CreateOffscreenContext()
638 OVERRIDE {
639 return CreateOffscreenCommandBufferContext()
640 .PassAs<WebKit::WebGraphicsContext3D>();
641 }
642
637 virtual cc::OutputSurface* CreateOutputSurface( 643 virtual cc::OutputSurface* CreateOutputSurface(
638 ui::Compositor* compositor) OVERRIDE { 644 ui::Compositor* compositor) OVERRIDE {
639 PerCompositorData* data = per_compositor_data_[compositor]; 645 PerCompositorData* data = per_compositor_data_[compositor];
640 if (!data) 646 if (!data)
641 data = CreatePerCompositorData(compositor); 647 data = CreatePerCompositorData(compositor);
642 WebGraphicsContext3DCommandBufferImpl* context =
643 CreateContextCommon(data->swap_client->AsWeakPtr(),
644 data->surface_id);
645 BrowserCompositorOutputSurface* surface = 648 BrowserCompositorOutputSurface* surface =
646 new BrowserCompositorOutputSurface( 649 new BrowserCompositorOutputSurface(
647 context, 650 CreateContextCommon(data->swap_client->AsWeakPtr(),
651 data->surface_id)
652 .PassAs<WebKit::WebGraphicsContext3D>(),
648 per_compositor_data_[compositor]->surface_id, 653 per_compositor_data_[compositor]->surface_id,
649 output_surface_proxy_.get(), 654 output_surface_proxy_.get(),
650 base::MessageLoopProxy::current(), 655 base::MessageLoopProxy::current(),
651 compositor->AsWeakPtr()); 656 compositor->AsWeakPtr());
652 if (data->reflector.get()) { 657 if (data->reflector.get()) {
653 data->reflector->CreateSharedTexture(); 658 data->reflector->CreateSharedTexture();
654 data->reflector->AttachToOutputSurface(surface); 659 data->reflector->AttachToOutputSurface(surface);
655 } 660 }
656 return surface; 661 return surface;
657 } 662 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 #endif 816 #endif
812 tracker->SetSurfaceHandle( 817 tracker->SetSurfaceHandle(
813 data->surface_id, 818 data->surface_id,
814 gfx::GLSurfaceHandle(widget, gfx::NATIVE_DIRECT)); 819 gfx::GLSurfaceHandle(widget, gfx::NATIVE_DIRECT));
815 820
816 per_compositor_data_[compositor] = data; 821 per_compositor_data_[compositor] = data;
817 822
818 return data; 823 return data;
819 } 824 }
820 825
821 WebGraphicsContext3DCommandBufferImpl* CreateContextCommon( 826 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContextCommon(
822 const base::WeakPtr<WebGraphicsContext3DSwapBuffersClient>& swap_client, 827 const base::WeakPtr<WebGraphicsContext3DSwapBuffersClient>& swap_client,
823 int surface_id) { 828 int surface_id) {
824 WebKit::WebGraphicsContext3D::Attributes attrs; 829 WebKit::WebGraphicsContext3D::Attributes attrs;
825 attrs.shareResources = true; 830 attrs.shareResources = true;
826 attrs.depth = false; 831 attrs.depth = false;
827 attrs.stencil = false; 832 attrs.stencil = false;
828 attrs.antialias = false; 833 attrs.antialias = false;
829 attrs.noAutomaticFlushes = true; 834 attrs.noAutomaticFlushes = true;
830 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance(); 835 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance();
831 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); 836 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon");
832 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( 837 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
833 new WebGraphicsContext3DCommandBufferImpl( 838 new WebGraphicsContext3DCommandBufferImpl(
834 surface_id, 839 surface_id,
835 url, 840 url,
836 factory, 841 factory,
837 swap_client)); 842 swap_client));
838 if (!context->InitializeWithDefaultBufferSizes( 843 if (!context->InitializeWithDefaultBufferSizes(
839 attrs, 844 attrs,
840 false, 845 false,
841 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) 846 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
842 return NULL; 847 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
843 return context.release(); 848 return context.Pass();
844 } 849 }
845 850
846 // Crash given that we are unable to show any UI whatsoever. On Windows we 851 // Crash given that we are unable to show any UI whatsoever. On Windows we
847 // also trigger code in breakpad causes a system process to show message box. 852 // also trigger code in breakpad causes a system process to show message box.
848 // In all cases a crash dump is generated. 853 // In all cases a crash dump is generated.
849 void FatalGPUError(const char* message) { 854 void FatalGPUError(const char* message) {
850 #if defined(OS_WIN) 855 #if defined(OS_WIN)
851 // 0xC01E0200 corresponds to STATUS_GRAPHICS_GPU_EXCEPTION_ON_DEVICE. 856 // 0xC01E0200 corresponds to STATUS_GRAPHICS_GPU_EXCEPTION_ON_DEVICE.
852 ::RaiseException(0xC01E0200, EXCEPTION_NONCONTINUABLE, 0, NULL); 857 ::RaiseException(0xC01E0200, EXCEPTION_NONCONTINUABLE, 0, NULL);
853 #else 858 #else
(...skipping 12 matching lines...) Expand all
866 return provider; 871 return provider;
867 } 872 }
868 873
869 protected: 874 protected:
870 explicit MainThreadContextProvider(GpuProcessTransportFactory* factory) 875 explicit MainThreadContextProvider(GpuProcessTransportFactory* factory)
871 : factory_(factory) {} 876 : factory_(factory) {}
872 virtual ~MainThreadContextProvider() {} 877 virtual ~MainThreadContextProvider() {}
873 878
874 virtual scoped_ptr<WebGraphicsContext3DCommandBufferImpl> 879 virtual scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
875 CreateOffscreenContext3d() OVERRIDE { 880 CreateOffscreenContext3d() OVERRIDE {
876 return make_scoped_ptr(factory_->CreateOffscreenContext()); 881 return factory_->CreateOffscreenCommandBufferContext();
877 } 882 }
878 883
879 virtual void OnLostContext() OVERRIDE { 884 virtual void OnLostContext() OVERRIDE {
880 base::MessageLoop::current()->PostTask( 885 base::MessageLoop::current()->PostTask(
881 FROM_HERE, 886 FROM_HERE,
882 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext, 887 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext,
883 factory_->callback_factory_.GetWeakPtr())); 888 factory_->callback_factory_.GetWeakPtr()));
884 } 889 }
885 890
886 private: 891 private:
(...skipping 23 matching lines...) Expand all
910 return provider; 915 return provider;
911 } 916 }
912 917
913 protected: 918 protected:
914 explicit CompositorThreadContextProvider( 919 explicit CompositorThreadContextProvider(
915 GpuProcessTransportFactory* factory) : factory_(factory) {} 920 GpuProcessTransportFactory* factory) : factory_(factory) {}
916 virtual ~CompositorThreadContextProvider() {} 921 virtual ~CompositorThreadContextProvider() {}
917 922
918 virtual scoped_ptr<WebGraphicsContext3DCommandBufferImpl> 923 virtual scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
919 CreateOffscreenContext3d() OVERRIDE { 924 CreateOffscreenContext3d() OVERRIDE {
920 return make_scoped_ptr(factory_->CreateOffscreenContext()); 925 return factory_->CreateOffscreenCommandBufferContext();
921 } 926 }
922 927
923 private: 928 private:
924 GpuProcessTransportFactory* factory_; 929 GpuProcessTransportFactory* factory_;
925 }; 930 };
926 931
927 virtual scoped_refptr<cc::ContextProvider> 932 virtual scoped_refptr<cc::ContextProvider>
928 OffscreenContextProviderForCompositorThread() OVERRIDE { 933 OffscreenContextProviderForCompositorThread() OVERRIDE {
929 if (!shared_contexts_compositor_thread_.get() || 934 if (!shared_contexts_compositor_thread_.get() ||
930 shared_contexts_compositor_thread_->DestroyedOnMainThread()) { 935 shared_contexts_compositor_thread_->DestroyedOnMainThread()) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 latency_info.swap_timestamp = base::TimeTicks::HighResNow(); 994 latency_info.swap_timestamp = base::TimeTicks::HighResNow();
990 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); 995 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info);
991 cc::OutputSurface::SwapBuffers(frame); 996 cc::OutputSurface::SwapBuffers(frame);
992 } 997 }
993 }; 998 };
994 999
995 class SoftwareContextFactory : public ui::ContextFactory { 1000 class SoftwareContextFactory : public ui::ContextFactory {
996 public: 1001 public:
997 SoftwareContextFactory() {} 1002 SoftwareContextFactory() {}
998 virtual ~SoftwareContextFactory() {} 1003 virtual ~SoftwareContextFactory() {}
999 virtual WebKit::WebGraphicsContext3D* CreateOffscreenContext() OVERRIDE { 1004 virtual scoped_ptr<WebKit::WebGraphicsContext3D> CreateOffscreenContext()
1000 return NULL; 1005 OVERRIDE {
1006 return scoped_ptr<WebKit::WebGraphicsContext3D>();
1001 } 1007 }
1002 virtual cc::OutputSurface* CreateOutputSurface( 1008 virtual cc::OutputSurface* CreateOutputSurface(
1003 ui::Compositor* compositor) OVERRIDE { 1009 ui::Compositor* compositor) OVERRIDE {
1004 #if defined(OS_WIN) 1010 #if defined(OS_WIN)
1005 scoped_ptr<SoftwareOutputDeviceWin> software_device( 1011 scoped_ptr<SoftwareOutputDeviceWin> software_device(
1006 new SoftwareOutputDeviceWin(compositor)); 1012 new SoftwareOutputDeviceWin(compositor));
1007 return new SoftwareOutputSurface( 1013 return new SoftwareOutputSurface(
1008 software_device.PassAs<cc::SoftwareOutputDevice>()); 1014 software_device.PassAs<cc::SoftwareOutputDevice>());
1009 #elif defined(USE_X11) 1015 #elif defined(USE_X11)
1010 scoped_ptr<SoftwareOutputDeviceX11> software_device( 1016 scoped_ptr<SoftwareOutputDeviceX11> software_device(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 delete g_factory; 1071 delete g_factory;
1066 g_factory = NULL; 1072 g_factory = NULL;
1067 } 1073 }
1068 1074
1069 // static 1075 // static
1070 ImageTransportFactory* ImageTransportFactory::GetInstance() { 1076 ImageTransportFactory* ImageTransportFactory::GetInstance() {
1071 return g_factory; 1077 return g_factory;
1072 } 1078 }
1073 1079
1074 } // namespace content 1080 } // namespace content
OLDNEW
« no previous file with comments | « cc/test/pixel_test.cc ('k') | content/browser/renderer_host/image_transport_factory_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698