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

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

Issue 11195011: Send vsync timebase updates to the browser compositor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use the existing output surface mechanism to feed vsync info into the compositor Created 8 years, 2 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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "base/threading/non_thread_safe.h"
14 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 15 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
15 #include "content/browser/gpu/gpu_data_manager_impl.h" 16 #include "content/browser/gpu/gpu_data_manager_impl.h"
17 #include "content/browser/gpu/gpu_process_host.h"
16 #include "content/browser/gpu/gpu_surface_tracker.h" 18 #include "content/browser/gpu/gpu_surface_tracker.h"
17 #include "content/common/gpu/client/gl_helper.h" 19 #include "content/common/gpu/client/gl_helper.h"
18 #include "content/common/gpu/client/gpu_channel_host.h" 20 #include "content/common/gpu/client/gpu_channel_host.h"
19 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 21 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
22 #include "content/common/gpu/gpu_messages.h"
20 #include "content/common/gpu/gpu_process_launch_causes.h" 23 #include "content/common/gpu/gpu_process_launch_causes.h"
21 #include "content/common/webkitplatformsupport_impl.h" 24 #include "content/common/webkitplatformsupport_impl.h"
25 #include "content/public/browser/browser_thread.h"
22 #include "content/public/common/content_switches.h" 26 #include "content/public/common/content_switches.h"
23 #include "gpu/ipc/command_buffer_proxy.h" 27 #include "gpu/ipc/command_buffer_proxy.h"
28 #include "ipc/ipc_forwarding_message_filter.h"
29 #include "ipc/ipc_message_macros.h"
30 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput Surface.h"
31 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput SurfaceClient.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC ontext3D.h" 32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC ontext3D.h"
25 #include "ui/compositor/compositor.h" 33 #include "ui/compositor/compositor.h"
26 #include "ui/compositor/compositor_setup.h" 34 #include "ui/compositor/compositor_setup.h"
27 #include "ui/compositor/test_web_graphics_context_3d.h" 35 #include "ui/compositor/test_web_graphics_context_3d.h"
28 #include "ui/gfx/native_widget_types.h" 36 #include "ui/gfx/native_widget_types.h"
29 #include "ui/gfx/size.h" 37 #include "ui/gfx/size.h"
30 38
31 #if defined(OS_WIN) 39 #if defined(OS_WIN)
32 #include "ui/surface/accelerated_surface_win.h" 40 #include "ui/surface/accelerated_surface_win.h"
33 #endif 41 #endif
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 221 }
214 222
215 private: 223 private:
216 void OnLostContext(); 224 void OnLostContext();
217 ui::Compositor* compositor_; 225 ui::Compositor* compositor_;
218 GpuProcessTransportFactory* factory_; 226 GpuProcessTransportFactory* factory_;
219 227
220 DISALLOW_COPY_AND_ASSIGN(CompositorSwapClient); 228 DISALLOW_COPY_AND_ASSIGN(CompositorSwapClient);
221 }; 229 };
222 230
231 void AddFilterOnIOThreadTask(
piman 2012/10/24 16:56:54 Up to now, this file didn't have to know about the
ajuma 2012/10/26 20:12:39 Done.
232 int host_id,
233 scoped_refptr<IPC::ChannelProxy::MessageFilter> filter) {
234 GpuProcessHost* host = GpuProcessHost::FromID(host_id);
235 if (host)
236 host->AddFilter(filter);
237 }
238
239 // Adapts a WebGraphicsContext3DCommandBufferImpl into a
240 // WebCompositorOutputSurface that also handles vsync parameter updates
241 // arriving from the GPU process.
242 class BrowserCompositorOutputSurface :
243 public WebKit::WebCompositorOutputSurface,
244 public base::NonThreadSafe {
245 public:
246 explicit BrowserCompositorOutputSurface(
247 WebGraphicsContext3DCommandBufferImpl* context)
248 : context3D_(context)
249 , client_(NULL) {
250 DetachFromThread();
251 }
252
253 virtual ~BrowserCompositorOutputSurface() {
254 DCHECK(CalledOnValidThread());
255 if (!client_)
256 return;
257 output_surface_proxy_->ClearOutputSurface();
258 output_surface_filter_->RemoveRoute(MSG_ROUTING_CONTROL);
259 }
260
261 virtual bool bindToClient(
262 WebKit::WebCompositorOutputSurfaceClient* client) OVERRIDE {
263 DCHECK(CalledOnValidThread());
264 DCHECK(client);
265 DCHECK(!client_);
266 if (context3D_.get()) {
267 if (!context3D_->makeContextCurrent())
268 return false;
269 }
270
271 client_ = client;
272
273 uint32 messages_to_filter[] = {GpuHostMsg_UpdateVSyncParameters::ID};
274 output_surface_filter_ = new IPC::ForwardingMessageFilter(
275 messages_to_filter, arraysize(messages_to_filter),
276 MessageLoop::current()->message_loop_proxy());
277 content::BrowserThread::PostTask(content::BrowserThread::IO,
278 FROM_HERE,
279 base::Bind(&AddFilterOnIOThreadTask,
280 context3D_->GetGPUProcessID(),
281 output_surface_filter_));
282
283 output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy(this);
284 output_surface_filter_->AddRoute(
285 MSG_ROUTING_CONTROL,
286 base::Bind(&BrowserCompositorOutputSurfaceProxy::OnMessageReceived,
287 output_surface_proxy_));
288
289 return true;
290 }
291
292 virtual const Capabilities& capabilities() const OVERRIDE {
293 DCHECK(CalledOnValidThread());
294 return capabilities_;
295 }
296
297 virtual WebKit::WebGraphicsContext3D* context3D() const OVERRIDE {
298 DCHECK(CalledOnValidThread());
299 return context3D_.get();
300 }
301
302 virtual void sendFrameToParentCompositor(
303 const WebKit::WebCompositorFrame&) OVERRIDE {
304 }
305
306 private:
307 class BrowserCompositorOutputSurfaceProxy :
308 public base::RefCountedThreadSafe<BrowserCompositorOutputSurfaceProxy> {
309 public:
310 explicit BrowserCompositorOutputSurfaceProxy(
311 BrowserCompositorOutputSurface* output_surface)
312 : output_surface_(output_surface) {}
313 void ClearOutputSurface() { output_surface_ = NULL; }
314 void OnMessageReceived(const IPC::Message& message) {
315 if (output_surface_)
316 output_surface_->OnMessageReceived(message);
piman 2012/10/24 16:56:54 As mentioned on the message, we need to deal with
ajuma 2012/10/26 20:12:39 Done.
317 }
318
319 private:
320 friend class
321 base::RefCountedThreadSafe<BrowserCompositorOutputSurfaceProxy>;
322 ~BrowserCompositorOutputSurfaceProxy() {}
323 BrowserCompositorOutputSurface* output_surface_;
324
325 DISALLOW_COPY_AND_ASSIGN(BrowserCompositorOutputSurfaceProxy);
326 };
327
328 void OnMessageReceived(const IPC::Message& message) {
329 DCHECK(CalledOnValidThread());
330 if (!client_)
331 return;
332 IPC_BEGIN_MESSAGE_MAP(BrowserCompositorOutputSurface, message)
333 IPC_MESSAGE_HANDLER(GpuHostMsg_UpdateVSyncParameters,
334 OnUpdateVSyncParameters);
335 IPC_END_MESSAGE_MAP()
336 }
337
338 void OnUpdateVSyncParameters(
339 base::TimeTicks timebase, base::TimeDelta interval) {
340 DCHECK(CalledOnValidThread());
341 DCHECK(client_);
342 double monotonicTimebase = timebase.ToInternalValue() /
343 static_cast<double>(base::Time::kMicrosecondsPerSecond);
344 double intervalInSeconds = interval.ToInternalValue() /
345 static_cast<double>(base::Time::kMicrosecondsPerSecond);
346 client_->onVSyncParametersChanged(monotonicTimebase, intervalInSeconds);
347 }
348
349 scoped_refptr<IPC::ForwardingMessageFilter> output_surface_filter_;
350 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3D_;
351 Capabilities capabilities_;
352 WebKit::WebCompositorOutputSurfaceClient* client_;
353 scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_;
354 };
355
223 class GpuProcessTransportFactory : 356 class GpuProcessTransportFactory :
224 public ui::ContextFactory, 357 public ui::ContextFactory,
225 public ImageTransportFactory, 358 public ImageTransportFactory,
226 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { 359 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
227 public: 360 public:
228 GpuProcessTransportFactory() 361 GpuProcessTransportFactory()
229 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { 362 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
230 } 363 }
231 364
232 virtual ~GpuProcessTransportFactory() { 365 virtual ~GpuProcessTransportFactory() {
233 DCHECK(per_compositor_data_.empty()); 366 DCHECK(per_compositor_data_.empty());
234 } 367 }
235 368
236 virtual WebKit::WebGraphicsContext3D* CreateContext( 369 virtual WebGraphicsContext3DCommandBufferImpl* CreateContext(
237 ui::Compositor* compositor) OVERRIDE { 370 ui::Compositor* compositor) OVERRIDE {
238 PerCompositorData* data = per_compositor_data_[compositor]; 371 PerCompositorData* data = per_compositor_data_[compositor];
239 if (!data) 372 if (!data)
240 data = CreatePerCompositorData(compositor); 373 data = CreatePerCompositorData(compositor);
241 return CreateContextCommon(data->swap_client->AsWeakPtr(), 374 return CreateContextCommon(data->swap_client->AsWeakPtr(),
242 data->surface_id); 375 data->surface_id);
243 } 376 }
244 377
245 virtual WebGraphicsContext3DCommandBufferImpl* CreateOffscreenContext() 378 virtual WebGraphicsContext3DCommandBufferImpl* CreateOffscreenContext()
246 OVERRIDE { 379 OVERRIDE {
247 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client; 380 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client;
248 return CreateContextCommon(swap_client, 0); 381 return CreateContextCommon(swap_client, 0);
249 } 382 }
250 383
384 virtual WebKit::WebCompositorOutputSurface* CreateOutputSurface(
385 ui::Compositor* compositor) OVERRIDE {
386 WebGraphicsContext3DCommandBufferImpl* context = CreateContext(compositor);
387 return new BrowserCompositorOutputSurface(context);
388 }
389
251 virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE { 390 virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE {
252 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); 391 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor);
253 if (it == per_compositor_data_.end()) 392 if (it == per_compositor_data_.end())
254 return; 393 return;
255 PerCompositorData* data = it->second; 394 PerCompositorData* data = it->second;
256 DCHECK(data); 395 DCHECK(data);
257 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); 396 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id);
258 delete data; 397 delete data;
259 per_compositor_data_.erase(it); 398 per_compositor_data_.erase(it);
260 if (per_compositor_data_.empty()) { 399 if (per_compositor_data_.empty()) {
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 void ImageTransportFactory::Terminate() { 645 void ImageTransportFactory::Terminate() {
507 ui::ContextFactory::SetInstance(NULL); 646 ui::ContextFactory::SetInstance(NULL);
508 delete g_factory; 647 delete g_factory;
509 g_factory = NULL; 648 g_factory = NULL;
510 } 649 }
511 650
512 // static 651 // static
513 ImageTransportFactory* ImageTransportFactory::GetInstance() { 652 ImageTransportFactory* ImageTransportFactory::GetInstance() {
514 return g_factory; 653 return g_factory;
515 } 654 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698