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_android.h" | 5 #include "content/browser/renderer_host/image_transport_factory_android.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "cc/output/context_provider.h" | |
| 9 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 10 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 10 #include "content/common/gpu/client/gl_helper.h" | 11 #include "content/common/gpu/client/gl_helper.h" |
| 11 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 12 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 12 #include "content/common/gpu/gpu_process_launch_causes.h" | 13 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 13 #include "gpu/command_buffer/client/gles2_implementation.h" | 14 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 14 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 15 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
| 15 #include "third_party/khronos/GLES2/gl2.h" | 16 #include "third_party/khronos/GLES2/gl2.h" |
| 17 #include "ui/compositor/compositor.h" | |
| 16 #include "ui/gfx/android/device_display_info.h" | 18 #include "ui/gfx/android/device_display_info.h" |
| 17 | 19 |
| 18 namespace content { | 20 namespace content { |
| 19 | 21 |
| 20 base::LazyInstance<ObserverList<ImageTransportFactoryAndroidObserver> >::Leaky | 22 base::LazyInstance<ObserverList<ImageTransportFactoryAndroidObserver> >::Leaky |
| 21 g_factory_observers = LAZY_INSTANCE_INITIALIZER; | 23 g_factory_observers = LAZY_INSTANCE_INITIALIZER; |
| 22 | 24 |
| 23 class GLContextLostListener | 25 class GLContextLostListener |
| 24 : public blink::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 26 : public blink::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
| 25 public: | 27 public: |
| 26 // WebGraphicsContextLostCallback implementation. | 28 // WebGraphicsContextLostCallback implementation. |
| 27 virtual void onContextLost() OVERRIDE; | 29 virtual void onContextLost() OVERRIDE; |
| 28 private: | 30 private: |
| 29 static void DidLoseContext(); | 31 static void DidLoseContext(); |
| 30 }; | 32 }; |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 36 bool g_initialized_for_unit_tests = false; | |
| 34 static ImageTransportFactoryAndroid* g_factory = NULL; | 37 static ImageTransportFactoryAndroid* g_factory = NULL; |
| 35 | 38 |
| 36 class CmdBufferImageTransportFactory : public ImageTransportFactoryAndroid { | 39 class CmdBufferImageTransportFactory : public ImageTransportFactoryAndroid { |
| 37 public: | 40 public: |
| 38 CmdBufferImageTransportFactory(); | 41 CmdBufferImageTransportFactory(); |
| 39 virtual ~CmdBufferImageTransportFactory(); | 42 virtual ~CmdBufferImageTransportFactory(); |
| 40 | 43 |
| 41 virtual GLHelper* GetGLHelper() OVERRIDE; | 44 virtual GLHelper* GetGLHelper() OVERRIDE; |
| 42 virtual uint32 GetChannelID() OVERRIDE { | 45 virtual uint32 GetChannelID() OVERRIDE { |
| 43 return BrowserGpuChannelHostFactory::instance()->GetGpuChannelId(); | 46 return BrowserGpuChannelHostFactory::instance()->GetGpuChannelId(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 } | 97 } |
| 95 | 98 |
| 96 GLHelper* CmdBufferImageTransportFactory::GetGLHelper() { | 99 GLHelper* CmdBufferImageTransportFactory::GetGLHelper() { |
| 97 if (!gl_helper_) | 100 if (!gl_helper_) |
| 98 gl_helper_.reset(new GLHelper(context_->GetImplementation(), | 101 gl_helper_.reset(new GLHelper(context_->GetImplementation(), |
| 99 context_->GetContextSupport())); | 102 context_->GetContextSupport())); |
| 100 | 103 |
| 101 return gl_helper_.get(); | 104 return gl_helper_.get(); |
| 102 } | 105 } |
| 103 | 106 |
| 107 class NoImageTransportFactory : public ImageTransportFactoryAndroid { | |
|
dshwang
2014/06/24 14:04:21
This class is very similar to NoTransportImageTran
danakj
2014/07/02 21:43:03
one class per file, can you move this out?
| |
| 108 public: | |
| 109 explicit NoImageTransportFactory( | |
| 110 scoped_ptr<ui::ContextFactory> context_factory) | |
| 111 : context_factory_(context_factory.Pass()) {} | |
| 112 virtual ~NoImageTransportFactory() {} | |
| 113 | |
| 114 virtual GLHelper* GetGLHelper() OVERRIDE { | |
| 115 if (!gl_helper_) { | |
| 116 context_provider_ = context_factory_->SharedMainThreadContextProvider(); | |
| 117 gl_helper_.reset(new GLHelper(context_provider_->ContextGL(), | |
| 118 context_provider_->ContextSupport())); | |
| 119 } | |
| 120 return gl_helper_.get(); | |
| 121 } | |
| 122 virtual uint32 GetChannelID() OVERRIDE { | |
| 123 NOTREACHED(); | |
| 124 return 0; | |
| 125 } | |
| 126 | |
| 127 private: | |
| 128 scoped_ptr<ui::ContextFactory> context_factory_; | |
| 129 scoped_refptr<cc::ContextProvider> context_provider_; | |
| 130 scoped_ptr<GLHelper> gl_helper_; | |
| 131 | |
| 132 DISALLOW_IMPLICIT_CONSTRUCTORS(NoImageTransportFactory); | |
| 133 }; | |
| 134 | |
| 104 } // anonymous namespace | 135 } // anonymous namespace |
| 105 | 136 |
| 106 // static | 137 // static |
| 138 void ImageTransportFactoryAndroid::InitializeForUnitTests( | |
|
dshwang
2014/06/24 14:04:21
Implement it like ImageTransportFactory::Initializ
| |
| 139 scoped_ptr<ui::ContextFactory> test_factory) { | |
| 140 DCHECK(!g_factory); | |
| 141 g_initialized_for_unit_tests = true; | |
| 142 g_factory = new NoImageTransportFactory(test_factory.Pass()); | |
| 143 } | |
| 144 | |
| 145 // static | |
| 107 ImageTransportFactoryAndroid* ImageTransportFactoryAndroid::GetInstance() { | 146 ImageTransportFactoryAndroid* ImageTransportFactoryAndroid::GetInstance() { |
| 108 if (!g_factory) | 147 if (!g_factory) { |
| 148 DCHECK(!g_initialized_for_unit_tests); | |
|
danakj
2014/07/02 21:43:03
i don't think this DCHECK buys much, since there's
| |
| 109 g_factory = new CmdBufferImageTransportFactory(); | 149 g_factory = new CmdBufferImageTransportFactory(); |
| 110 | 150 } |
| 111 return g_factory; | 151 return g_factory; |
| 112 } | 152 } |
| 113 | 153 |
| 114 ImageTransportFactoryAndroid::ImageTransportFactoryAndroid() | 154 ImageTransportFactoryAndroid::ImageTransportFactoryAndroid() |
| 115 : context_lost_listener_(new GLContextLostListener()) {} | 155 : context_lost_listener_(new GLContextLostListener()) {} |
| 116 | 156 |
| 117 ImageTransportFactoryAndroid::~ImageTransportFactoryAndroid() {} | 157 ImageTransportFactoryAndroid::~ImageTransportFactoryAndroid() {} |
| 118 | 158 |
| 119 void ImageTransportFactoryAndroid::AddObserver( | 159 void ImageTransportFactoryAndroid::AddObserver( |
| 120 ImageTransportFactoryAndroidObserver* observer) { | 160 ImageTransportFactoryAndroidObserver* observer) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 137 | 177 |
| 138 void GLContextLostListener::DidLoseContext() { | 178 void GLContextLostListener::DidLoseContext() { |
| 139 delete g_factory; | 179 delete g_factory; |
| 140 g_factory = NULL; | 180 g_factory = NULL; |
| 141 FOR_EACH_OBSERVER(ImageTransportFactoryAndroidObserver, | 181 FOR_EACH_OBSERVER(ImageTransportFactoryAndroidObserver, |
| 142 g_factory_observers.Get(), | 182 g_factory_observers.Get(), |
| 143 OnLostResources()); | 183 OnLostResources()); |
| 144 } | 184 } |
| 145 | 185 |
| 146 } // namespace content | 186 } // namespace content |
| OLD | NEW |