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
3 // found in the LICENSE file.
5 #include "content/renderer/gpu/compositor_external_begin_frame_source.h"
7 #include "content/common/view_messages.h"
8 #include "ipc/ipc_sync_channel.h"
9 #include "ipc/ipc_sync_message_filter.h"
13 CompositorExternalBeginFrameSource::CompositorExternalBeginFrameSource(
14 CompositorForwardingMessageFilter
* filter
,
15 IPC::SyncMessageFilter
* sync_message_filter
,
17 : begin_frame_source_filter_(filter
),
18 message_sender_(sync_message_filter
),
19 routing_id_(routing_id
) {
20 DCHECK(begin_frame_source_filter_
.get());
21 DCHECK(message_sender_
.get());
25 CompositorExternalBeginFrameSource::~CompositorExternalBeginFrameSource() {
26 DCHECK(CalledOnValidThread());
27 if (begin_frame_source_proxy_
.get()) {
28 begin_frame_source_proxy_
->ClearBeginFrameSource();
29 begin_frame_source_filter_
->RemoveHandlerOnCompositorThread(
31 begin_frame_source_filter_handler_
);
35 void CompositorExternalBeginFrameSource::OnNeedsBeginFramesChange(
36 bool needs_begin_frames
) {
37 DCHECK(CalledOnValidThread());
38 Send(new ViewHostMsg_SetNeedsBeginFrames(routing_id_
, needs_begin_frames
));
41 void CompositorExternalBeginFrameSource::SetClientReady() {
42 DCHECK(CalledOnValidThread());
43 DCHECK(!begin_frame_source_proxy_
.get());
44 begin_frame_source_proxy_
=
45 new CompositorExternalBeginFrameSourceProxy(this);
46 begin_frame_source_filter_handler_
= base::Bind(
47 &CompositorExternalBeginFrameSourceProxy::OnMessageReceived
,
48 begin_frame_source_proxy_
);
49 begin_frame_source_filter_
->AddHandlerOnCompositorThread(
51 begin_frame_source_filter_handler_
);
54 void CompositorExternalBeginFrameSource::OnMessageReceived(
55 const IPC::Message
& message
) {
56 DCHECK(CalledOnValidThread());
57 DCHECK(begin_frame_source_proxy_
.get());
58 IPC_BEGIN_MESSAGE_MAP(CompositorExternalBeginFrameSource
, message
)
59 IPC_MESSAGE_HANDLER(ViewMsg_BeginFrame
, OnBeginFrame
)
60 IPC_END_MESSAGE_MAP();
63 void CompositorExternalBeginFrameSource::OnBeginFrame(
64 const cc::BeginFrameArgs
& args
) {
65 DCHECK(CalledOnValidThread());
66 CallOnBeginFrame(args
);
69 bool CompositorExternalBeginFrameSource::Send(IPC::Message
* message
) {
70 return message_sender_
->Send(message
);
73 } // namespace content