Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/aura/software_browser_compositor_output_surface.h" | 5 #include "content/browser/aura/software_browser_compositor_output_surface.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | |
| 7 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 8 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 9 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/output/software_output_device.h" | 11 #include "cc/output/software_output_device.h" |
| 11 #include "content/browser/renderer_host/render_widget_host_impl.h" | 12 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 12 #include "ui/events/latency_info.h" | 13 #include "ui/events/latency_info.h" |
| 14 #include "ui/gl/vsync_provider.h" | |
| 13 | 15 |
| 14 namespace content { | 16 namespace content { |
| 15 | 17 |
| 18 class VSyncListener : public base::RefCountedThreadSafe<VSyncListener> { | |
| 19 public: | |
| 20 VSyncListener(SoftwareBrowserCompositorOutputSurface* surface, | |
| 21 scoped_refptr<base::MessageLoopProxy> compositor_message_loop, | |
| 22 base::WeakPtr<ui::Compositor> compositor); | |
| 23 | |
| 24 // Called by the VSyncProvider when updating the time of the most recent | |
| 25 // screen refresh. | |
| 26 void VSyncCallback(const base::TimeTicks timebase, | |
| 27 const base::TimeDelta interval); | |
| 28 | |
| 29 private: | |
| 30 friend class base::RefCountedThreadSafe<VSyncListener>; | |
| 31 | |
| 32 virtual ~VSyncListener(); | |
| 33 | |
| 34 SoftwareBrowserCompositorOutputSurface* surface_; | |
| 35 scoped_refptr<base::MessageLoopProxy> compositor_message_loop_; | |
| 36 base::WeakPtr<ui::Compositor> compositor_; | |
| 37 | |
| 38 DISALLOW_COPY_AND_ASSIGN(VSyncListener); | |
| 39 }; | |
|
piman
2013/11/05 23:32:27
So this class is really only there to forward the
dnicoara
2013/11/06 18:11:47
Yes, this would be similar to the BrowserComposito
| |
| 40 | |
| 41 VSyncListener::VSyncListener( | |
| 42 SoftwareBrowserCompositorOutputSurface* surface, | |
| 43 scoped_refptr<base::MessageLoopProxy> compositor_message_loop, | |
| 44 base::WeakPtr<ui::Compositor> compositor) | |
| 45 : surface_(surface), | |
| 46 compositor_message_loop_(compositor_message_loop), | |
| 47 compositor_(compositor) { | |
| 48 } | |
| 49 | |
| 50 VSyncListener::~VSyncListener() { | |
| 51 } | |
| 52 | |
| 53 void VSyncListener::VSyncCallback( | |
| 54 const base::TimeTicks timebase, | |
| 55 const base::TimeDelta interval) { | |
|
piman
2013/11/05 23:32:27
So, this should be called on the compositor alread
| |
| 56 // Update the OutputSurface. | |
| 57 surface_->OnVSyncParametersChanged(timebase, interval); | |
|
piman
2013/11/05 23:32:27
What guarantee do we have that surface_ is still v
| |
| 58 // Propagate the update to the compositor. | |
| 59 compositor_message_loop_->PostTask( | |
| 60 FROM_HERE, | |
| 61 base::Bind(&ui::Compositor::OnUpdateVSyncParameters, | |
| 62 compositor_, | |
| 63 timebase, | |
| 64 interval)); | |
| 65 } | |
| 66 | |
| 16 SoftwareBrowserCompositorOutputSurface::SoftwareBrowserCompositorOutputSurface( | 67 SoftwareBrowserCompositorOutputSurface::SoftwareBrowserCompositorOutputSurface( |
| 17 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 68 scoped_ptr<cc::SoftwareOutputDevice> software_device, |
| 18 : cc::OutputSurface(software_device.Pass()) {} | 69 base::MessageLoopProxy* compositor_message_loop, |
| 70 base::WeakPtr<ui::Compositor> compositor) | |
| 71 : cc::OutputSurface(software_device.Pass()), | |
| 72 vsync_listener_(new VSyncListener(this, | |
| 73 compositor_message_loop, | |
| 74 compositor)) { | |
| 75 } | |
| 76 | |
| 77 SoftwareBrowserCompositorOutputSurface:: | |
| 78 ~SoftwareBrowserCompositorOutputSurface() { | |
|
piman
2013/11/05 23:32:27
nit: this looks indented wrong. git cl format?
| |
| 79 } | |
| 19 | 80 |
| 20 void SoftwareBrowserCompositorOutputSurface::SwapBuffers( | 81 void SoftwareBrowserCompositorOutputSurface::SwapBuffers( |
| 21 cc::CompositorFrame* frame) { | 82 cc::CompositorFrame* frame) { |
| 22 ui::LatencyInfo latency_info = frame->metadata.latency_info; | 83 ui::LatencyInfo latency_info = frame->metadata.latency_info; |
| 23 latency_info.AddLatencyNumber( | 84 latency_info.AddLatencyNumber( |
| 24 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); | 85 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0); |
| 25 | 86 |
| 26 base::MessageLoop::current()->PostTask( | 87 base::MessageLoop::current()->PostTask( |
| 27 FROM_HERE, | 88 FROM_HERE, |
| 28 base::Bind( | 89 base::Bind( |
| 29 &RenderWidgetHostImpl::CompositorFrameDrawn, | 90 &RenderWidgetHostImpl::CompositorFrameDrawn, |
| 30 latency_info)); | 91 latency_info)); |
| 92 | |
| 93 gfx::VSyncProvider* vsync_provider = software_device_->GetVSyncProvider(); | |
| 94 if (vsync_provider) { | |
| 95 vsync_provider->GetVSyncParameters(base::Bind( | |
| 96 &VSyncListener::VSyncCallback, | |
| 97 vsync_listener_)); | |
| 98 } | |
| 31 } | 99 } |
| 32 | 100 |
| 33 } // namespace content | 101 } // namespace content |
| OLD | NEW |