blob: 867179b6497fa9df057b8b0bbf8ae7ec83168caf [file] [log] [blame]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/gpu/compositor_external_begin_frame_source.h"
#include "content/common/view_messages.h"
#include "ipc/ipc_sync_channel.h"
#include "ipc/ipc_sync_message_filter.h"
namespace content {
CompositorExternalBeginFrameSource::CompositorExternalBeginFrameSource(
CompositorForwardingMessageFilter* filter,
IPC::SyncMessageFilter* sync_message_filter,
int routing_id)
: BeginFrameSource(kNotRestartableId),
external_begin_frame_source_(this),
begin_frame_source_filter_(filter),
message_sender_(sync_message_filter),
routing_id_(routing_id) {
DCHECK(begin_frame_source_filter_);
DCHECK(message_sender_);
DETACH_FROM_THREAD(thread_checker_);
}
CompositorExternalBeginFrameSource::~CompositorExternalBeginFrameSource() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (begin_frame_source_proxy_) {
begin_frame_source_proxy_->ClearBeginFrameSource();
begin_frame_source_filter_->RemoveHandlerOnCompositorThread(
routing_id_,
begin_frame_source_filter_handler_);
}
}
void CompositorExternalBeginFrameSource::AddObserver(
viz::BeginFrameObserver* obs) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (!begin_frame_source_proxy_) {
begin_frame_source_proxy_ =
new CompositorExternalBeginFrameSourceProxy(this);
begin_frame_source_filter_handler_ =
base::Bind(&CompositorExternalBeginFrameSourceProxy::OnMessageReceived,
begin_frame_source_proxy_);
begin_frame_source_filter_->AddHandlerOnCompositorThread(
routing_id_, begin_frame_source_filter_handler_);
}
external_begin_frame_source_.AddObserver(obs);
}
void CompositorExternalBeginFrameSource::RemoveObserver(
viz::BeginFrameObserver* obs) {
external_begin_frame_source_.RemoveObserver(obs);
}
void CompositorExternalBeginFrameSource::DidFinishFrame(
viz::BeginFrameObserver* obs) {
external_begin_frame_source_.DidFinishFrame(obs);
}
bool CompositorExternalBeginFrameSource::IsThrottled() const {
return true;
}
void CompositorExternalBeginFrameSource::OnNeedsBeginFrames(
bool needs_begin_frames) {
Send(new ViewHostMsg_SetNeedsBeginFrames(routing_id_, needs_begin_frames));
}
void CompositorExternalBeginFrameSource::OnMessageReceived(
const IPC::Message& message) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(begin_frame_source_proxy_);
IPC_BEGIN_MESSAGE_MAP(CompositorExternalBeginFrameSource, message)
IPC_MESSAGE_HANDLER(ViewMsg_SetBeginFramePaused,
OnSetBeginFrameSourcePaused)
IPC_MESSAGE_HANDLER(ViewMsg_BeginFrame, OnBeginFrame)
IPC_END_MESSAGE_MAP()
}
void CompositorExternalBeginFrameSource::OnSetBeginFrameSourcePaused(
bool paused) {
external_begin_frame_source_.OnSetBeginFrameSourcePaused(paused);
}
void CompositorExternalBeginFrameSource::OnBeginFrame(
const viz::BeginFrameArgs& args) {
external_begin_frame_source_.OnBeginFrame(args);
}
bool CompositorExternalBeginFrameSource::Send(IPC::Message* message) {
return message_sender_->Send(message);
}
} // namespace content