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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/image_transport_factory.cc
diff --git a/content/browser/renderer_host/image_transport_factory.cc b/content/browser/renderer_host/image_transport_factory.cc
index 4de531a912c721ffae42c9e7ea5c926b3d5fc3e7..495e6b4083c2ba9c8432a250bf2f094a3c69b018 100644
--- a/content/browser/renderer_host/image_transport_factory.cc
+++ b/content/browser/renderer_host/image_transport_factory.cc
@@ -11,16 +11,24 @@
#include "base/command_line.h"
#include "base/memory/ref_counted.h"
#include "base/observer_list.h"
+#include "base/threading/non_thread_safe.h"
#include "content/browser/gpu/browser_gpu_channel_host_factory.h"
#include "content/browser/gpu/gpu_data_manager_impl.h"
+#include "content/browser/gpu/gpu_process_host.h"
#include "content/browser/gpu/gpu_surface_tracker.h"
#include "content/common/gpu/client/gl_helper.h"
#include "content/common/gpu/client/gpu_channel_host.h"
#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
+#include "content/common/gpu/gpu_messages.h"
#include "content/common/gpu/gpu_process_launch_causes.h"
#include "content/common/webkitplatformsupport_impl.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_switches.h"
#include "gpu/ipc/command_buffer_proxy.h"
+#include "ipc/ipc_forwarding_message_filter.h"
+#include "ipc/ipc_message_macros.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutputSurface.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutputSurfaceClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/compositor_setup.h"
@@ -220,6 +228,131 @@ class CompositorSwapClient
DISALLOW_COPY_AND_ASSIGN(CompositorSwapClient);
};
+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.
+ int host_id,
+ scoped_refptr<IPC::ChannelProxy::MessageFilter> filter) {
+ GpuProcessHost* host = GpuProcessHost::FromID(host_id);
+ if (host)
+ host->AddFilter(filter);
+}
+
+// Adapts a WebGraphicsContext3DCommandBufferImpl into a
+// WebCompositorOutputSurface that also handles vsync parameter updates
+// arriving from the GPU process.
+class BrowserCompositorOutputSurface :
+ public WebKit::WebCompositorOutputSurface,
+ public base::NonThreadSafe {
+ public:
+ explicit BrowserCompositorOutputSurface(
+ WebGraphicsContext3DCommandBufferImpl* context)
+ : context3D_(context)
+ , client_(NULL) {
+ DetachFromThread();
+ }
+
+ virtual ~BrowserCompositorOutputSurface() {
+ DCHECK(CalledOnValidThread());
+ if (!client_)
+ return;
+ output_surface_proxy_->ClearOutputSurface();
+ output_surface_filter_->RemoveRoute(MSG_ROUTING_CONTROL);
+ }
+
+ virtual bool bindToClient(
+ WebKit::WebCompositorOutputSurfaceClient* client) OVERRIDE {
+ DCHECK(CalledOnValidThread());
+ DCHECK(client);
+ DCHECK(!client_);
+ if (context3D_.get()) {
+ if (!context3D_->makeContextCurrent())
+ return false;
+ }
+
+ client_ = client;
+
+ uint32 messages_to_filter[] = {GpuHostMsg_UpdateVSyncParameters::ID};
+ output_surface_filter_ = new IPC::ForwardingMessageFilter(
+ messages_to_filter, arraysize(messages_to_filter),
+ MessageLoop::current()->message_loop_proxy());
+ content::BrowserThread::PostTask(content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&AddFilterOnIOThreadTask,
+ context3D_->GetGPUProcessID(),
+ output_surface_filter_));
+
+ output_surface_proxy_ = new BrowserCompositorOutputSurfaceProxy(this);
+ output_surface_filter_->AddRoute(
+ MSG_ROUTING_CONTROL,
+ base::Bind(&BrowserCompositorOutputSurfaceProxy::OnMessageReceived,
+ output_surface_proxy_));
+
+ return true;
+ }
+
+ virtual const Capabilities& capabilities() const OVERRIDE {
+ DCHECK(CalledOnValidThread());
+ return capabilities_;
+ }
+
+ virtual WebKit::WebGraphicsContext3D* context3D() const OVERRIDE {
+ DCHECK(CalledOnValidThread());
+ return context3D_.get();
+ }
+
+ virtual void sendFrameToParentCompositor(
+ const WebKit::WebCompositorFrame&) OVERRIDE {
+ }
+
+ private:
+ class BrowserCompositorOutputSurfaceProxy :
+ public base::RefCountedThreadSafe<BrowserCompositorOutputSurfaceProxy> {
+ public:
+ explicit BrowserCompositorOutputSurfaceProxy(
+ BrowserCompositorOutputSurface* output_surface)
+ : output_surface_(output_surface) {}
+ void ClearOutputSurface() { output_surface_ = NULL; }
+ void OnMessageReceived(const IPC::Message& message) {
+ if (output_surface_)
+ 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.
+ }
+
+ private:
+ friend class
+ base::RefCountedThreadSafe<BrowserCompositorOutputSurfaceProxy>;
+ ~BrowserCompositorOutputSurfaceProxy() {}
+ BrowserCompositorOutputSurface* output_surface_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowserCompositorOutputSurfaceProxy);
+ };
+
+ void OnMessageReceived(const IPC::Message& message) {
+ DCHECK(CalledOnValidThread());
+ if (!client_)
+ return;
+ IPC_BEGIN_MESSAGE_MAP(BrowserCompositorOutputSurface, message)
+ IPC_MESSAGE_HANDLER(GpuHostMsg_UpdateVSyncParameters,
+ OnUpdateVSyncParameters);
+ IPC_END_MESSAGE_MAP()
+ }
+
+ void OnUpdateVSyncParameters(
+ base::TimeTicks timebase, base::TimeDelta interval) {
+ DCHECK(CalledOnValidThread());
+ DCHECK(client_);
+ double monotonicTimebase = timebase.ToInternalValue() /
+ static_cast<double>(base::Time::kMicrosecondsPerSecond);
+ double intervalInSeconds = interval.ToInternalValue() /
+ static_cast<double>(base::Time::kMicrosecondsPerSecond);
+ client_->onVSyncParametersChanged(monotonicTimebase, intervalInSeconds);
+ }
+
+ scoped_refptr<IPC::ForwardingMessageFilter> output_surface_filter_;
+ scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3D_;
+ Capabilities capabilities_;
+ WebKit::WebCompositorOutputSurfaceClient* client_;
+ scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_;
+};
+
class GpuProcessTransportFactory :
public ui::ContextFactory,
public ImageTransportFactory,
@@ -233,7 +366,7 @@ class GpuProcessTransportFactory :
DCHECK(per_compositor_data_.empty());
}
- virtual WebKit::WebGraphicsContext3D* CreateContext(
+ virtual WebGraphicsContext3DCommandBufferImpl* CreateContext(
ui::Compositor* compositor) OVERRIDE {
PerCompositorData* data = per_compositor_data_[compositor];
if (!data)
@@ -248,6 +381,12 @@ class GpuProcessTransportFactory :
return CreateContextCommon(swap_client, 0);
}
+ virtual WebKit::WebCompositorOutputSurface* CreateOutputSurface(
+ ui::Compositor* compositor) OVERRIDE {
+ WebGraphicsContext3DCommandBufferImpl* context = CreateContext(compositor);
+ return new BrowserCompositorOutputSurface(context);
+ }
+
virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE {
PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor);
if (it == per_compositor_data_.end())

Powered by Google App Engine
This is Rietveld 408576698