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
3 // found in the LICENSE file.
5 #include "content/renderer/gpu/compositor_output_surface.h"
7 #include "base/message_loop_proxy.h"
8 #include "content/common/view_messages.h"
9 #include "content/renderer/render_thread_impl.h"
10 #include "ipc/ipc_forwarding_message_filter.h"
11 #include "ipc/ipc_sync_channel.h"
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutputSurfaceClient.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
15 using WebKit::WebGraphicsContext3D
;
17 //------------------------------------------------------------------------------
20 IPC::ForwardingMessageFilter
* CompositorOutputSurface::CreateFilter(
21 base::TaskRunner
* target_task_runner
)
23 uint32 messages_to_filter
[] = {ViewMsg_UpdateVSyncParameters::ID
};
24 return new IPC::ForwardingMessageFilter(
25 messages_to_filter
, arraysize(messages_to_filter
),
29 CompositorOutputSurface::CompositorOutputSurface(
31 WebGraphicsContext3D
* context3D
)
32 : output_surface_filter_(
33 RenderThreadImpl::current()->compositor_output_surface_filter())
35 , routing_id_(routing_id
)
36 , context3D_(context3D
) {
37 DCHECK(output_surface_filter_
);
38 capabilities_
.hasParentCompositor
= false;
42 CompositorOutputSurface::~CompositorOutputSurface() {
43 DCHECK(CalledOnValidThread());
46 output_surface_filter_
->RemoveRoute(routing_id_
);
49 const WebKit::WebCompositorOutputSurface::Capabilities
&
50 CompositorOutputSurface::capabilities() const {
51 DCHECK(CalledOnValidThread());
55 bool CompositorOutputSurface::bindToClient(
56 WebKit::WebCompositorOutputSurfaceClient
* client
) {
57 DCHECK(CalledOnValidThread());
59 if (!context3D_
->makeContextCurrent())
64 output_surface_filter_
->AddRoute(
66 base::Bind(&CompositorOutputSurface::OnMessageReceived
,
67 base::Unretained(this)));
72 WebGraphicsContext3D
* CompositorOutputSurface::context3D() const {
73 DCHECK(CalledOnValidThread());
74 return context3D_
.get();
77 void CompositorOutputSurface::sendFrameToParentCompositor(
78 const WebKit::WebCompositorFrame
&) {
79 DCHECK(CalledOnValidThread());
83 void CompositorOutputSurface::OnMessageReceived(const IPC::Message
& message
) {
84 DCHECK(CalledOnValidThread());
87 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface
, message
)
88 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters
, OnUpdateVSyncParameters
);
92 void CompositorOutputSurface::OnUpdateVSyncParameters(
93 base::TimeTicks timebase
,
94 base::TimeDelta interval
) {
95 DCHECK(CalledOnValidThread());
97 double monotonicTimebase
= timebase
.ToInternalValue() /
98 static_cast<double>(base::Time::kMicrosecondsPerSecond
);
99 double intervalInSeconds
= interval
.ToInternalValue() /
100 static_cast<double>(base::Time::kMicrosecondsPerSecond
);
101 client_
->onVSyncParametersChanged(monotonicTimebase
, intervalInSeconds
);