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/browser/android/in_process/synchronous_compositor_external_begin_frame_source.h"
7 #include "cc/output/begin_frame_args.h"
8 #include "content/browser/android/in_process/synchronous_compositor_impl.h"
9 #include "content/browser/android/in_process/synchronous_compositor_registry.h"
10 #include "content/public/browser/browser_thread.h"
14 SynchronousCompositorExternalBeginFrameSource::
15 SynchronousCompositorExternalBeginFrameSource(int routing_id
)
16 : routing_id_(routing_id
),
18 compositor_(nullptr) {
21 SynchronousCompositorExternalBeginFrameSource::
22 ~SynchronousCompositorExternalBeginFrameSource() {
23 DCHECK(CalledOnValidThread());
26 SynchronousCompositorRegistry::GetInstance()->UnregisterBeginFrameSource(
32 void SynchronousCompositorExternalBeginFrameSource::BeginFrame(
33 const cc::BeginFrameArgs
& args
) {
34 DCHECK(CalledOnValidThread());
35 CallOnBeginFrame(args
);
38 void SynchronousCompositorExternalBeginFrameSource::SetCompositor(
39 SynchronousCompositorImpl
* compositor
) {
40 DCHECK(CalledOnValidThread());
41 if (compositor_
== compositor
) return;
44 compositor_
->OnNeedsBeginFramesChange(false);
46 compositor_
= compositor
;
49 compositor_
->OnNeedsBeginFramesChange(needs_begin_frames_
);
52 void SynchronousCompositorExternalBeginFrameSource::OnNeedsBeginFramesChange(
53 bool needs_begin_frames
) {
54 DCHECK(CalledOnValidThread());
56 compositor_
->OnNeedsBeginFramesChange(needs_begin_frames
);
59 void SynchronousCompositorExternalBeginFrameSource::SetClientReady() {
60 DCHECK(CalledOnValidThread());
61 SynchronousCompositorRegistry::GetInstance()->RegisterBeginFrameSource(
66 // Not using base::NonThreadSafe as we want to enforce a more exacting threading
67 // requirement: SynchronousCompositorExternalBeginFrameSource() must only be
68 // used on the UI thread.
70 SynchronousCompositorExternalBeginFrameSource::CalledOnValidThread() const {
71 return BrowserThread::CurrentlyOn(BrowserThread::UI
);
74 } // namespace content