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

Side by Side Diff: content/browser/compositor/gpu_process_transport_factory.cc

Issue 277713002: ui/compositor: move the browser compositor thread to the ContextFactory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 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
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();
83
84 if (compositor_thread_.get()) {
85 compositor_thread_->Stop();
danakj 2014/05/08 22:37:30 Why do we need to do Stop() and reset()? The destr
piman 2014/05/08 22:48:34 Done. I was just copy&pasting from existing code t
86 compositor_thread_.reset();
87 }
72 } 88 }
73 89
74 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> 90 scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
75 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext() { 91 GpuProcessTransportFactory::CreateOffscreenCommandBufferContext() {
76 return CreateContextCommon(0); 92 return CreateContextCommon(0);
77 } 93 }
78 94
79 scoped_ptr<cc::SoftwareOutputDevice> CreateSoftwareOutputDevice( 95 scoped_ptr<cc::SoftwareOutputDevice> CreateSoftwareOutputDevice(
80 ui::Compositor* compositor) { 96 ui::Compositor* compositor) {
81 #if defined(OS_WIN) 97 #if defined(OS_WIN)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 scoped_refptr<ContextProviderCommandBuffer> context_provider; 143 scoped_refptr<ContextProviderCommandBuffer> context_provider;
128 if (!create_software_renderer) { 144 if (!create_software_renderer) {
129 context_provider = ContextProviderCommandBuffer::Create( 145 context_provider = ContextProviderCommandBuffer::Create(
130 GpuProcessTransportFactory::CreateContextCommon(data->surface_id), 146 GpuProcessTransportFactory::CreateContextCommon(data->surface_id),
131 "Compositor"); 147 "Compositor");
132 } 148 }
133 149
134 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", !!context_provider); 150 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", !!context_provider);
135 151
136 if (!context_provider.get()) { 152 if (!context_provider.get()) {
137 if (ui::Compositor::WasInitializedWithThread()) { 153 if (compositor_thread_.get()) {
138 LOG(FATAL) << "Failed to create UI context, but can't use software" 154 LOG(FATAL) << "Failed to create UI context, but can't use software"
139 " compositing with browser threaded compositing. Aborting."; 155 " compositing with browser threaded compositing. Aborting.";
140 } 156 }
141 157
142 scoped_ptr<SoftwareBrowserCompositorOutputSurface> surface( 158 scoped_ptr<SoftwareBrowserCompositorOutputSurface> surface(
143 new SoftwareBrowserCompositorOutputSurface( 159 new SoftwareBrowserCompositorOutputSurface(
144 output_surface_proxy_, 160 output_surface_proxy_,
145 CreateSoftwareOutputDevice(compositor), 161 CreateSoftwareOutputDevice(compositor),
146 per_compositor_data_[compositor]->surface_id, 162 per_compositor_data_[compositor]->surface_id,
147 &output_surface_map_, 163 &output_surface_map_,
148 compositor->vsync_manager())); 164 compositor->vsync_manager()));
149 return surface.PassAs<cc::OutputSurface>(); 165 return surface.PassAs<cc::OutputSurface>();
150 } 166 }
151 167
152 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner = 168 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner =
153 ui::Compositor::GetCompositorMessageLoop(); 169 GetCompositorMessageLoop();
154 if (!compositor_thread_task_runner.get()) 170 if (!compositor_thread_task_runner.get())
155 compositor_thread_task_runner = base::MessageLoopProxy::current(); 171 compositor_thread_task_runner = base::MessageLoopProxy::current();
156 172
157 // Here we know the GpuProcessHost has been set up, because we created a 173 // Here we know the GpuProcessHost has been set up, because we created a
158 // context. 174 // context.
159 output_surface_proxy_->ConnectToGpuProcessHost( 175 output_surface_proxy_->ConnectToGpuProcessHost(
160 compositor_thread_task_runner.get()); 176 compositor_thread_task_runner.get());
161 177
162 scoped_ptr<BrowserCompositorOutputSurface> surface( 178 scoped_ptr<BrowserCompositorOutputSurface> surface(
163 new GpuBrowserCompositorOutputSurface( 179 new GpuBrowserCompositorOutputSurface(
164 context_provider, 180 context_provider,
165 per_compositor_data_[compositor]->surface_id, 181 per_compositor_data_[compositor]->surface_id,
166 &output_surface_map_, 182 &output_surface_map_,
167 compositor->vsync_manager(), 183 compositor->vsync_manager(),
168 CreateOverlayCandidateValidator(compositor->widget()))); 184 CreateOverlayCandidateValidator(compositor->widget())));
169 if (data->reflector.get()) 185 if (data->reflector.get())
170 data->reflector->ReattachToOutputSurfaceFromMainThread(surface.get()); 186 data->reflector->ReattachToOutputSurfaceFromMainThread(surface.get());
171 187
172 return surface.PassAs<cc::OutputSurface>(); 188 return surface.PassAs<cc::OutputSurface>();
173 } 189 }
174 190
175 scoped_refptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( 191 scoped_refptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector(
176 ui::Compositor* source, 192 ui::Compositor* source,
177 ui::Layer* target) { 193 ui::Layer* target) {
178 PerCompositorData* data = per_compositor_data_[source]; 194 PerCompositorData* data = per_compositor_data_[source];
179 DCHECK(data); 195 DCHECK(data);
180 196
181 data->reflector = new ReflectorImpl( 197 data->reflector = new ReflectorImpl(source,
182 source, target, &output_surface_map_, data->surface_id); 198 target,
199 &output_surface_map_,
200 GetCompositorMessageLoop(),
201 data->surface_id);
183 return data->reflector; 202 return data->reflector;
184 } 203 }
185 204
186 void GpuProcessTransportFactory::RemoveReflector( 205 void GpuProcessTransportFactory::RemoveReflector(
187 scoped_refptr<ui::Reflector> reflector) { 206 scoped_refptr<ui::Reflector> reflector) {
188 ReflectorImpl* reflector_impl = 207 ReflectorImpl* reflector_impl =
189 static_cast<ReflectorImpl*>(reflector.get()); 208 static_cast<ReflectorImpl*>(reflector.get());
190 PerCompositorData* data = 209 PerCompositorData* data =
191 per_compositor_data_[reflector_impl->mirrored_compositor()]; 210 per_compositor_data_[reflector_impl->mirrored_compositor()];
192 DCHECK(data); 211 DCHECK(data);
(...skipping 22 matching lines...) Expand all
215 "GLHelper to be created."; 234 "GLHelper to be created.";
216 } 235 }
217 } 236 }
218 237
219 bool GpuProcessTransportFactory::DoesCreateTestContexts() { return false; } 238 bool GpuProcessTransportFactory::DoesCreateTestContexts() { return false; }
220 239
221 cc::SharedBitmapManager* GpuProcessTransportFactory::GetSharedBitmapManager() { 240 cc::SharedBitmapManager* GpuProcessTransportFactory::GetSharedBitmapManager() {
222 return HostSharedBitmapManager::current(); 241 return HostSharedBitmapManager::current();
223 } 242 }
224 243
244 base::MessageLoopProxy* GpuProcessTransportFactory::GetCompositorMessageLoop() {
245 if (!compositor_thread_)
246 return NULL;
247 return compositor_thread_->message_loop_proxy();
248 }
249
225 gfx::GLSurfaceHandle GpuProcessTransportFactory::GetSharedSurfaceHandle() { 250 gfx::GLSurfaceHandle GpuProcessTransportFactory::GetSharedSurfaceHandle() {
226 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle( 251 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle(
227 gfx::kNullPluginWindow, gfx::TEXTURE_TRANSPORT); 252 gfx::kNullPluginWindow, gfx::TEXTURE_TRANSPORT);
228 handle.parent_client_id = 253 handle.parent_client_id =
229 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId(); 254 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId();
230 return handle; 255 return handle;
231 } 256 }
232 257
233 GLHelper* GpuProcessTransportFactory::GetGLHelper() { 258 GLHelper* GpuProcessTransportFactory::GetGLHelper() {
234 if (!gl_helper_ && !per_compositor_data_.empty()) { 259 if (!gl_helper_ && !per_compositor_data_.empty()) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, 374 FOR_EACH_OBSERVER(ImageTransportFactoryObserver,
350 observer_list_, 375 observer_list_,
351 OnLostResources()); 376 OnLostResources());
352 377
353 // Kill things that use the shared context before killing the shared context. 378 // Kill things that use the shared context before killing the shared context.
354 lost_gl_helper.reset(); 379 lost_gl_helper.reset();
355 lost_shared_main_thread_contexts = NULL; 380 lost_shared_main_thread_contexts = NULL;
356 } 381 }
357 382
358 } // namespace content 383 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698