OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/compositor/gpu_process_transport_factory.h" | 5 #include "content/browser/compositor/gpu_process_transport_factory.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/threading/thread.h" |
14 #include "cc/output/compositor_frame.h" | 15 #include "cc/output/compositor_frame.h" |
15 #include "cc/output/output_surface.h" | 16 #include "cc/output/output_surface.h" |
16 #include "content/browser/compositor/browser_compositor_output_surface.h" | 17 #include "content/browser/compositor/browser_compositor_output_surface.h" |
17 #include "content/browser/compositor/browser_compositor_output_surface_proxy.h" | 18 #include "content/browser/compositor/browser_compositor_output_surface_proxy.h" |
18 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" | 19 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" |
19 #include "content/browser/compositor/reflector_impl.h" | 20 #include "content/browser/compositor/reflector_impl.h" |
20 #include "content/browser/compositor/software_browser_compositor_output_surface.
h" | 21 #include "content/browser/compositor/software_browser_compositor_output_surface.
h" |
21 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 22 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
22 #include "content/browser/gpu/gpu_data_manager_impl.h" | 23 #include "content/browser/gpu/gpu_data_manager_impl.h" |
23 #include "content/browser/gpu/gpu_surface_tracker.h" | 24 #include "content/browser/gpu/gpu_surface_tracker.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 56 |
56 struct GpuProcessTransportFactory::PerCompositorData { | 57 struct GpuProcessTransportFactory::PerCompositorData { |
57 int surface_id; | 58 int surface_id; |
58 scoped_refptr<ReflectorImpl> reflector; | 59 scoped_refptr<ReflectorImpl> reflector; |
59 }; | 60 }; |
60 | 61 |
61 GpuProcessTransportFactory::GpuProcessTransportFactory() | 62 GpuProcessTransportFactory::GpuProcessTransportFactory() |
62 : callback_factory_(this) { | 63 : callback_factory_(this) { |
63 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy( | 64 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy( |
64 &output_surface_map_); | 65 &output_surface_map_); |
| 66 #if defined(OS_CHROMEOS) |
| 67 bool use_thread = !CommandLine::ForCurrentProcess()->HasSwitch( |
| 68 switches::kUIDisableThreadedCompositing); |
| 69 #else |
| 70 bool use_thread = false; |
| 71 #endif |
| 72 if (use_thread) { |
| 73 compositor_thread_.reset(new base::Thread("Browser Compositor")); |
| 74 compositor_thread_->Start(); |
| 75 } |
65 } | 76 } |
66 | 77 |
67 GpuProcessTransportFactory::~GpuProcessTransportFactory() { | 78 GpuProcessTransportFactory::~GpuProcessTransportFactory() { |
68 DCHECK(per_compositor_data_.empty()); | 79 DCHECK(per_compositor_data_.empty()); |
69 | 80 |
70 // Make sure the lost context callback doesn't try to run during destruction. | 81 // Make sure the lost context callback doesn't try to run during destruction. |
71 callback_factory_.InvalidateWeakPtrs(); | 82 callback_factory_.InvalidateWeakPtrs(); |
72 } | 83 } |
73 | 84 |
74 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 85 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 138 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
128 if (!create_software_renderer) { | 139 if (!create_software_renderer) { |
129 context_provider = ContextProviderCommandBuffer::Create( | 140 context_provider = ContextProviderCommandBuffer::Create( |
130 GpuProcessTransportFactory::CreateContextCommon(data->surface_id), | 141 GpuProcessTransportFactory::CreateContextCommon(data->surface_id), |
131 "Compositor"); | 142 "Compositor"); |
132 } | 143 } |
133 | 144 |
134 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", !!context_provider); | 145 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", !!context_provider); |
135 | 146 |
136 if (!context_provider.get()) { | 147 if (!context_provider.get()) { |
137 if (ui::Compositor::WasInitializedWithThread()) { | 148 if (compositor_thread_.get()) { |
138 LOG(FATAL) << "Failed to create UI context, but can't use software" | 149 LOG(FATAL) << "Failed to create UI context, but can't use software" |
139 " compositing with browser threaded compositing. Aborting."; | 150 " compositing with browser threaded compositing. Aborting."; |
140 } | 151 } |
141 | 152 |
142 scoped_ptr<SoftwareBrowserCompositorOutputSurface> surface( | 153 scoped_ptr<SoftwareBrowserCompositorOutputSurface> surface( |
143 new SoftwareBrowserCompositorOutputSurface( | 154 new SoftwareBrowserCompositorOutputSurface( |
144 output_surface_proxy_, | 155 output_surface_proxy_, |
145 CreateSoftwareOutputDevice(compositor), | 156 CreateSoftwareOutputDevice(compositor), |
146 per_compositor_data_[compositor]->surface_id, | 157 per_compositor_data_[compositor]->surface_id, |
147 &output_surface_map_, | 158 &output_surface_map_, |
148 compositor->vsync_manager())); | 159 compositor->vsync_manager())); |
149 return surface.PassAs<cc::OutputSurface>(); | 160 return surface.PassAs<cc::OutputSurface>(); |
150 } | 161 } |
151 | 162 |
152 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner = | 163 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner = |
153 ui::Compositor::GetCompositorMessageLoop(); | 164 GetCompositorMessageLoop(); |
154 if (!compositor_thread_task_runner.get()) | 165 if (!compositor_thread_task_runner.get()) |
155 compositor_thread_task_runner = base::MessageLoopProxy::current(); | 166 compositor_thread_task_runner = base::MessageLoopProxy::current(); |
156 | 167 |
157 // Here we know the GpuProcessHost has been set up, because we created a | 168 // Here we know the GpuProcessHost has been set up, because we created a |
158 // context. | 169 // context. |
159 output_surface_proxy_->ConnectToGpuProcessHost( | 170 output_surface_proxy_->ConnectToGpuProcessHost( |
160 compositor_thread_task_runner.get()); | 171 compositor_thread_task_runner.get()); |
161 | 172 |
162 scoped_ptr<BrowserCompositorOutputSurface> surface( | 173 scoped_ptr<BrowserCompositorOutputSurface> surface( |
163 new GpuBrowserCompositorOutputSurface( | 174 new GpuBrowserCompositorOutputSurface( |
164 context_provider, | 175 context_provider, |
165 per_compositor_data_[compositor]->surface_id, | 176 per_compositor_data_[compositor]->surface_id, |
166 &output_surface_map_, | 177 &output_surface_map_, |
167 compositor->vsync_manager(), | 178 compositor->vsync_manager(), |
168 CreateOverlayCandidateValidator(compositor->widget()))); | 179 CreateOverlayCandidateValidator(compositor->widget()))); |
169 if (data->reflector.get()) | 180 if (data->reflector.get()) |
170 data->reflector->ReattachToOutputSurfaceFromMainThread(surface.get()); | 181 data->reflector->ReattachToOutputSurfaceFromMainThread(surface.get()); |
171 | 182 |
172 return surface.PassAs<cc::OutputSurface>(); | 183 return surface.PassAs<cc::OutputSurface>(); |
173 } | 184 } |
174 | 185 |
175 scoped_refptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( | 186 scoped_refptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( |
176 ui::Compositor* source, | 187 ui::Compositor* source, |
177 ui::Layer* target) { | 188 ui::Layer* target) { |
178 PerCompositorData* data = per_compositor_data_[source]; | 189 PerCompositorData* data = per_compositor_data_[source]; |
179 DCHECK(data); | 190 DCHECK(data); |
180 | 191 |
181 data->reflector = new ReflectorImpl( | 192 data->reflector = new ReflectorImpl(source, |
182 source, target, &output_surface_map_, data->surface_id); | 193 target, |
| 194 &output_surface_map_, |
| 195 GetCompositorMessageLoop(), |
| 196 data->surface_id); |
183 return data->reflector; | 197 return data->reflector; |
184 } | 198 } |
185 | 199 |
186 void GpuProcessTransportFactory::RemoveReflector( | 200 void GpuProcessTransportFactory::RemoveReflector( |
187 scoped_refptr<ui::Reflector> reflector) { | 201 scoped_refptr<ui::Reflector> reflector) { |
188 ReflectorImpl* reflector_impl = | 202 ReflectorImpl* reflector_impl = |
189 static_cast<ReflectorImpl*>(reflector.get()); | 203 static_cast<ReflectorImpl*>(reflector.get()); |
190 PerCompositorData* data = | 204 PerCompositorData* data = |
191 per_compositor_data_[reflector_impl->mirrored_compositor()]; | 205 per_compositor_data_[reflector_impl->mirrored_compositor()]; |
192 DCHECK(data); | 206 DCHECK(data); |
(...skipping 22 matching lines...) Expand all Loading... |
215 "GLHelper to be created."; | 229 "GLHelper to be created."; |
216 } | 230 } |
217 } | 231 } |
218 | 232 |
219 bool GpuProcessTransportFactory::DoesCreateTestContexts() { return false; } | 233 bool GpuProcessTransportFactory::DoesCreateTestContexts() { return false; } |
220 | 234 |
221 cc::SharedBitmapManager* GpuProcessTransportFactory::GetSharedBitmapManager() { | 235 cc::SharedBitmapManager* GpuProcessTransportFactory::GetSharedBitmapManager() { |
222 return HostSharedBitmapManager::current(); | 236 return HostSharedBitmapManager::current(); |
223 } | 237 } |
224 | 238 |
| 239 base::MessageLoopProxy* GpuProcessTransportFactory::GetCompositorMessageLoop() { |
| 240 if (!compositor_thread_) |
| 241 return NULL; |
| 242 return compositor_thread_->message_loop_proxy(); |
| 243 } |
| 244 |
225 gfx::GLSurfaceHandle GpuProcessTransportFactory::GetSharedSurfaceHandle() { | 245 gfx::GLSurfaceHandle GpuProcessTransportFactory::GetSharedSurfaceHandle() { |
226 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( | 246 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( |
227 gfx::kNullPluginWindow, gfx::TEXTURE_TRANSPORT); | 247 gfx::kNullPluginWindow, gfx::TEXTURE_TRANSPORT); |
228 handle.parent_client_id = | 248 handle.parent_client_id = |
229 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId(); | 249 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId(); |
230 return handle; | 250 return handle; |
231 } | 251 } |
232 | 252 |
233 GLHelper* GpuProcessTransportFactory::GetGLHelper() { | 253 GLHelper* GpuProcessTransportFactory::GetGLHelper() { |
234 if (!gl_helper_ && !per_compositor_data_.empty()) { | 254 if (!gl_helper_ && !per_compositor_data_.empty()) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 369 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
350 observer_list_, | 370 observer_list_, |
351 OnLostResources()); | 371 OnLostResources()); |
352 | 372 |
353 // Kill things that use the shared context before killing the shared context. | 373 // Kill things that use the shared context before killing the shared context. |
354 lost_gl_helper.reset(); | 374 lost_gl_helper.reset(); |
355 lost_shared_main_thread_contexts = NULL; | 375 lost_shared_main_thread_contexts = NULL; |
356 } | 376 } |
357 | 377 |
358 } // namespace content | 378 } // namespace content |
OLD | NEW |