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/compositor/browser_compositor_output_surface.h"
8 #include "base/command_line.h"
9 #include "base/location.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "cc/base/switches.h"
12 #include "content/browser/compositor/browser_compositor_overlay_candidate_validator.h"
13 #include "content/browser/compositor/reflector_impl.h"
14 #include "content/common/gpu/client/context_provider_command_buffer.h"
18 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
19 const scoped_refptr
<cc::ContextProvider
>& context_provider
,
20 const scoped_refptr
<ui::CompositorVSyncManager
>& vsync_manager
,
21 scoped_ptr
<BrowserCompositorOverlayCandidateValidator
>
22 overlay_candidate_validator
)
23 : OutputSurface(context_provider
),
24 vsync_manager_(vsync_manager
),
26 use_begin_frame_scheduling_(base::CommandLine::ForCurrentProcess()->
27 HasSwitch(cc::switches::kEnableBeginFrameScheduling
)) {
28 overlay_candidate_validator_
= overlay_candidate_validator
.Pass();
32 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
33 scoped_ptr
<cc::SoftwareOutputDevice
> software_device
,
34 const scoped_refptr
<ui::CompositorVSyncManager
>& vsync_manager
)
35 : OutputSurface(software_device
.Pass()),
36 vsync_manager_(vsync_manager
),
38 use_begin_frame_scheduling_(base::CommandLine::ForCurrentProcess()->
39 HasSwitch(cc::switches::kEnableBeginFrameScheduling
)) {
43 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() {
45 reflector_
->DetachFromOutputSurface();
50 // When BeginFrame scheduling is enabled, vsync info is not routed to renderer
51 // by using |vsync_manager_|. Instead, BeginFrame message is used.
52 if (!use_begin_frame_scheduling_
)
53 vsync_manager_
->RemoveObserver(this);
56 void BrowserCompositorOutputSurface::Initialize() {
57 capabilities_
.max_frames_pending
= 1;
58 capabilities_
.adjust_deadline_for_parent
= false;
61 bool BrowserCompositorOutputSurface::BindToClient(
62 cc::OutputSurfaceClient
* client
) {
63 if (!OutputSurface::BindToClient(client
))
66 // Don't want vsync notifications until there is a client.
67 if (!use_begin_frame_scheduling_
)
68 vsync_manager_
->AddObserver(this);
72 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters(
73 base::TimeTicks timebase
,
74 base::TimeDelta interval
) {
76 DCHECK(!use_begin_frame_scheduling_
);
77 CommitVSyncParameters(timebase
, interval
);
80 void BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu(
81 base::TimeTicks timebase
,
82 base::TimeDelta interval
) {
84 if (use_begin_frame_scheduling_
) {
85 CommitVSyncParameters(timebase
, interval
);
89 vsync_manager_
->UpdateVSyncParameters(timebase
, interval
);
92 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl
* reflector
) {
93 // Software mirroring is done by doing a GL copy out of the framebuffer - if
94 // we have overlays then that data will be missing.
95 if (overlay_candidate_validator_
) {
96 overlay_candidate_validator_
->SetSoftwareMirrorMode(reflector
!= nullptr);
98 reflector_
= reflector
;
100 OnReflectorChanged();
103 void BrowserCompositorOutputSurface::OnReflectorChanged() {
107 BrowserCompositorOutputSurface::CreateCompositionStartedCallback() {
108 return base::Closure();
111 cc::OverlayCandidateValidator
*
112 BrowserCompositorOutputSurface::GetOverlayCandidateValidator() const {
113 return overlay_candidate_validator_
.get();
116 } // namespace content