Move Tuple to base namespace.
[chromium-blink-merge.git] / content / browser / compositor / browser_compositor_output_surface.cc
blob0e014c94a68524df657cf89dab59780b31d6d608
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"
7 #include "base/bind.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"
16 namespace content {
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),
25 reflector_(nullptr),
26 use_begin_frame_scheduling_(base::CommandLine::ForCurrentProcess()->
27 HasSwitch(cc::switches::kEnableBeginFrameScheduling)) {
28 overlay_candidate_validator_ = overlay_candidate_validator.Pass();
29 Initialize();
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),
37 reflector_(nullptr),
38 use_begin_frame_scheduling_(base::CommandLine::ForCurrentProcess()->
39 HasSwitch(cc::switches::kEnableBeginFrameScheduling)) {
40 Initialize();
43 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() {
44 if (reflector_)
45 reflector_->DetachFromOutputSurface();
46 DCHECK(!reflector_);
47 if (!HasClient())
48 return;
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))
64 return false;
66 // Don't want vsync notifications until there is a client.
67 if (!use_begin_frame_scheduling_)
68 vsync_manager_->AddObserver(this);
69 return true;
72 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters(
73 base::TimeTicks timebase,
74 base::TimeDelta interval) {
75 DCHECK(HasClient());
76 DCHECK(!use_begin_frame_scheduling_);
77 CommitVSyncParameters(timebase, interval);
80 void BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu(
81 base::TimeTicks timebase,
82 base::TimeDelta interval) {
83 DCHECK(HasClient());
84 if (use_begin_frame_scheduling_) {
85 CommitVSyncParameters(timebase, interval);
86 return;
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() {
106 base::Closure
107 BrowserCompositorOutputSurface::CreateCompositionStartedCallback() {
108 return base::Closure();
111 cc::OverlayCandidateValidator*
112 BrowserCompositorOutputSurface::GetOverlayCandidateValidator() const {
113 return overlay_candidate_validator_.get();
116 } // namespace content