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

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

Issue 16998003: Update CrOS to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased 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
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 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 PerCompositorData* data = per_compositor_data_[compositor]; 635 PerCompositorData* data = per_compositor_data_[compositor];
636 if (!data) 636 if (!data)
637 data = CreatePerCompositorData(compositor); 637 data = CreatePerCompositorData(compositor);
638 WebGraphicsContext3DCommandBufferImpl* context = 638 WebGraphicsContext3DCommandBufferImpl* context =
639 CreateContextCommon(data->swap_client->AsWeakPtr(), 639 CreateContextCommon(data->swap_client->AsWeakPtr(),
640 data->surface_id); 640 data->surface_id);
641 BrowserCompositorOutputSurface* surface = 641 BrowserCompositorOutputSurface* surface =
642 new BrowserCompositorOutputSurface( 642 new BrowserCompositorOutputSurface(
643 context, 643 context,
644 per_compositor_data_[compositor]->surface_id, 644 per_compositor_data_[compositor]->surface_id,
645 output_surface_proxy_, 645 output_surface_proxy_.get(),
646 base::MessageLoopProxy::current(), 646 base::MessageLoopProxy::current(),
647 compositor->AsWeakPtr()); 647 compositor->AsWeakPtr());
648 if (data->reflector.get()) { 648 if (data->reflector.get()) {
649 data->reflector->CreateSharedTexture(); 649 data->reflector->CreateSharedTexture();
650 data->reflector->AttachToOutputSurface(surface); 650 data->reflector->AttachToOutputSurface(surface);
651 } 651 }
652 return surface; 652 return surface;
653 } 653 }
654 654
655 virtual scoped_refptr<ui::Reflector> CreateReflector( 655 virtual scoped_refptr<ui::Reflector> CreateReflector(
656 ui::Compositor* source, 656 ui::Compositor* source,
657 ui::Layer* target) OVERRIDE { 657 ui::Layer* target) OVERRIDE {
658 PerCompositorData* data = per_compositor_data_[source]; 658 PerCompositorData* data = per_compositor_data_[source];
659 DCHECK(data); 659 DCHECK(data);
660 660
661 if (data->reflector.get()) 661 if (data->reflector.get())
662 RemoveObserver(data->reflector.get()); 662 RemoveObserver(data->reflector.get());
663 663
664 data->reflector = new ReflectorImpl( 664 data->reflector = new ReflectorImpl(
665 source, target, output_surface_proxy_, 665 source, target, output_surface_proxy_.get(), data->surface_id);
666 data->surface_id);
667 AddObserver(data->reflector.get()); 666 AddObserver(data->reflector.get());
668 return data->reflector; 667 return data->reflector;
669 } 668 }
670 669
671 virtual void RemoveReflector( 670 virtual void RemoveReflector(
672 scoped_refptr<ui::Reflector> reflector) OVERRIDE { 671 scoped_refptr<ui::Reflector> reflector) OVERRIDE {
673 ReflectorImpl* reflector_impl = 672 ReflectorImpl* reflector_impl =
674 static_cast<ReflectorImpl*>(reflector.get()); 673 static_cast<ReflectorImpl*>(reflector.get());
675 PerCompositorData* data = 674 PerCompositorData* data =
676 per_compositor_data_[reflector_impl->mirrored_compositor()]; 675 per_compositor_data_[reflector_impl->mirrored_compositor()];
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 shared_contexts_main_thread_->Context3d()->GetChannelID(); 708 shared_contexts_main_thread_->Context3d()->GetChannelID();
710 return handle; 709 return handle;
711 } 710 }
712 711
713 virtual void DestroySharedSurfaceHandle( 712 virtual void DestroySharedSurfaceHandle(
714 gfx::GLSurfaceHandle surface) OVERRIDE { 713 gfx::GLSurfaceHandle surface) OVERRIDE {
715 } 714 }
716 715
717 virtual scoped_refptr<ui::Texture> CreateTransportClient( 716 virtual scoped_refptr<ui::Texture> CreateTransportClient(
718 float device_scale_factor) OVERRIDE { 717 float device_scale_factor) OVERRIDE {
719 if (!shared_contexts_main_thread_) 718 if (!shared_contexts_main_thread_.get())
720 return NULL; 719 return NULL;
721 scoped_refptr<ImageTransportClientTexture> image( 720 scoped_refptr<ImageTransportClientTexture> image(
722 new ImageTransportClientTexture( 721 new ImageTransportClientTexture(
723 shared_contexts_main_thread_->Context3d(), 722 shared_contexts_main_thread_->Context3d(),
724 device_scale_factor)); 723 device_scale_factor));
725 return image; 724 return image;
726 } 725 }
727 726
728 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( 727 virtual scoped_refptr<ui::Texture> CreateOwnedTexture(
729 const gfx::Size& size, 728 const gfx::Size& size,
730 float device_scale_factor, 729 float device_scale_factor,
731 unsigned int texture_id) OVERRIDE { 730 unsigned int texture_id) OVERRIDE {
732 if (!shared_contexts_main_thread_) 731 if (!shared_contexts_main_thread_.get())
733 return NULL; 732 return NULL;
734 scoped_refptr<OwnedTexture> image(new OwnedTexture( 733 scoped_refptr<OwnedTexture> image(new OwnedTexture(
735 shared_contexts_main_thread_->Context3d(), 734 shared_contexts_main_thread_->Context3d(),
736 size, 735 size,
737 device_scale_factor, 736 device_scale_factor,
738 texture_id)); 737 texture_id));
739 return image; 738 return image;
740 } 739 }
741 740
742 virtual GLHelper* GetGLHelper() OVERRIDE { 741 virtual GLHelper* GetGLHelper() OVERRIDE {
743 if (!gl_helper_) { 742 if (!gl_helper_) {
744 CreateSharedContextLazy(); 743 CreateSharedContextLazy();
745 WebGraphicsContext3DCommandBufferImpl* context_for_main_thread = 744 WebGraphicsContext3DCommandBufferImpl* context_for_main_thread =
746 shared_contexts_main_thread_->Context3d(); 745 shared_contexts_main_thread_->Context3d();
747 gl_helper_.reset(new GLHelper(context_for_main_thread)); 746 gl_helper_.reset(new GLHelper(context_for_main_thread));
748 } 747 }
749 return gl_helper_.get(); 748 return gl_helper_.get();
750 } 749 }
751 750
752 virtual uint32 InsertSyncPoint() OVERRIDE { 751 virtual uint32 InsertSyncPoint() OVERRIDE {
753 if (!shared_contexts_main_thread_) 752 if (!shared_contexts_main_thread_.get())
754 return 0; 753 return 0;
755 return shared_contexts_main_thread_->Context3d()->insertSyncPoint(); 754 return shared_contexts_main_thread_->Context3d()->insertSyncPoint();
756 } 755 }
757 756
758 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE { 757 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE {
759 if (!shared_contexts_main_thread_) 758 if (!shared_contexts_main_thread_.get())
760 return; 759 return;
761 shared_contexts_main_thread_->Context3d()->waitSyncPoint(sync_point); 760 shared_contexts_main_thread_->Context3d()->waitSyncPoint(sync_point);
762 } 761 }
763 762
764 virtual void AddObserver(ImageTransportFactoryObserver* observer) OVERRIDE { 763 virtual void AddObserver(ImageTransportFactoryObserver* observer) OVERRIDE {
765 observer_list_.AddObserver(observer); 764 observer_list_.AddObserver(observer);
766 } 765 }
767 766
768 virtual void RemoveObserver( 767 virtual void RemoveObserver(
769 ImageTransportFactoryObserver* observer) OVERRIDE { 768 ImageTransportFactoryObserver* observer) OVERRIDE {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext, 878 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext,
880 factory_->callback_factory_.GetWeakPtr())); 879 factory_->callback_factory_.GetWeakPtr()));
881 } 880 }
882 881
883 private: 882 private:
884 GpuProcessTransportFactory* factory_; 883 GpuProcessTransportFactory* factory_;
885 }; 884 };
886 885
887 virtual scoped_refptr<cc::ContextProvider> 886 virtual scoped_refptr<cc::ContextProvider>
888 OffscreenContextProviderForMainThread() OVERRIDE { 887 OffscreenContextProviderForMainThread() OVERRIDE {
889 if (!shared_contexts_main_thread_ || 888 if (!shared_contexts_main_thread_.get() ||
890 shared_contexts_main_thread_->DestroyedOnMainThread()) { 889 shared_contexts_main_thread_->DestroyedOnMainThread()) {
891 shared_contexts_main_thread_ = MainThreadContextProvider::Create(this); 890 shared_contexts_main_thread_ = MainThreadContextProvider::Create(this);
892 if (shared_contexts_main_thread_ && 891 if (shared_contexts_main_thread_.get() &&
893 !shared_contexts_main_thread_->BindToCurrentThread()) 892 !shared_contexts_main_thread_->BindToCurrentThread())
894 shared_contexts_main_thread_ = NULL; 893 shared_contexts_main_thread_ = NULL;
895 } 894 }
896 return shared_contexts_main_thread_; 895 return shared_contexts_main_thread_;
897 } 896 }
898 897
899 class CompositorThreadContextProvider : public ContextProviderCommandBuffer { 898 class CompositorThreadContextProvider : public ContextProviderCommandBuffer {
900 public: 899 public:
901 static scoped_refptr<CompositorThreadContextProvider> Create( 900 static scoped_refptr<CompositorThreadContextProvider> Create(
902 GpuProcessTransportFactory* factory) { 901 GpuProcessTransportFactory* factory) {
(...skipping 13 matching lines...) Expand all
916 CreateOffscreenContext3d() OVERRIDE { 915 CreateOffscreenContext3d() OVERRIDE {
917 return make_scoped_ptr(factory_->CreateOffscreenContext()); 916 return make_scoped_ptr(factory_->CreateOffscreenContext());
918 } 917 }
919 918
920 private: 919 private:
921 GpuProcessTransportFactory* factory_; 920 GpuProcessTransportFactory* factory_;
922 }; 921 };
923 922
924 virtual scoped_refptr<cc::ContextProvider> 923 virtual scoped_refptr<cc::ContextProvider>
925 OffscreenContextProviderForCompositorThread() OVERRIDE { 924 OffscreenContextProviderForCompositorThread() OVERRIDE {
926 if (!shared_contexts_compositor_thread_ || 925 if (!shared_contexts_compositor_thread_.get() ||
927 shared_contexts_compositor_thread_->DestroyedOnMainThread()) { 926 shared_contexts_compositor_thread_->DestroyedOnMainThread()) {
928 shared_contexts_compositor_thread_ = 927 shared_contexts_compositor_thread_ =
929 CompositorThreadContextProvider::Create(this); 928 CompositorThreadContextProvider::Create(this);
930 } 929 }
931 return shared_contexts_compositor_thread_; 930 return shared_contexts_compositor_thread_;
932 } 931 }
933 932
934 void CreateSharedContextLazy() { 933 void CreateSharedContextLazy() {
935 scoped_refptr<cc::ContextProvider> provider = 934 scoped_refptr<cc::ContextProvider> provider =
936 OffscreenContextProviderForMainThread(); 935 OffscreenContextProviderForMainThread();
937 if (!provider) { 936 if (!provider.get()) {
938 // If we can't recreate contexts, we won't be able to show the UI. 937 // If we can't recreate contexts, we won't be able to show the UI.
939 // Better crash at this point. 938 // Better crash at this point.
940 FatalGPUError("Failed to initialize UI shared context."); 939 FatalGPUError("Failed to initialize UI shared context.");
941 } 940 }
942 } 941 }
943 942
944 void OnLostMainThreadSharedContext() { 943 void OnLostMainThreadSharedContext() {
945 LOG(ERROR) << "Lost UI shared context."; 944 LOG(ERROR) << "Lost UI shared context.";
946 // Keep old resources around while we call the observers, but ensure that 945 // Keep old resources around while we call the observers, but ensure that
947 // new resources are created if needed. 946 // new resources are created if needed.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 delete g_factory; 1047 delete g_factory;
1049 g_factory = NULL; 1048 g_factory = NULL;
1050 } 1049 }
1051 1050
1052 // static 1051 // static
1053 ImageTransportFactory* ImageTransportFactory::GetInstance() { 1052 ImageTransportFactory* ImageTransportFactory::GetInstance() {
1054 return g_factory; 1053 return g_factory;
1055 } 1054 }
1056 1055
1057 } // namespace content 1056 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_context.cc ('k') | content/browser/renderer_host/render_widget_host_view_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698