Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / content / browser / compositor / browser_compositor_output_surface.cc
blobbdf3a1b2de663e92df420fc974df80aec34cbde5
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<cc::ContextProvider>& worker_context_provider,
21 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager,
22 scoped_ptr<BrowserCompositorOverlayCandidateValidator>
23 overlay_candidate_validator)
24 : OutputSurface(context_provider, worker_context_provider),
25 vsync_manager_(vsync_manager),
26 reflector_(nullptr),
27 use_begin_frame_scheduling_(
28 base::CommandLine::ForCurrentProcess()
29 ->HasSwitch(cc::switches::kEnableBeginFrameScheduling)) {
30 overlay_candidate_validator_ = overlay_candidate_validator.Pass();
31 Initialize();
34 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
35 scoped_ptr<cc::SoftwareOutputDevice> software_device,
36 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager)
37 : OutputSurface(software_device.Pass()),
38 vsync_manager_(vsync_manager),
39 reflector_(nullptr),
40 use_begin_frame_scheduling_(base::CommandLine::ForCurrentProcess()->
41 HasSwitch(cc::switches::kEnableBeginFrameScheduling)) {
42 Initialize();
45 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() {
46 if (reflector_)
47 reflector_->DetachFromOutputSurface();
48 DCHECK(!reflector_);
49 if (!HasClient())
50 return;
52 // When BeginFrame scheduling is enabled, vsync info is not routed to renderer
53 // by using |vsync_manager_|. Instead, BeginFrame message is used.
54 if (!use_begin_frame_scheduling_)
55 vsync_manager_->RemoveObserver(this);
58 void BrowserCompositorOutputSurface::Initialize() {
59 capabilities_.max_frames_pending = 1;
60 capabilities_.adjust_deadline_for_parent = false;
63 bool BrowserCompositorOutputSurface::BindToClient(
64 cc::OutputSurfaceClient* client) {
65 if (!OutputSurface::BindToClient(client))
66 return false;
68 // Don't want vsync notifications until there is a client.
69 if (!use_begin_frame_scheduling_)
70 vsync_manager_->AddObserver(this);
71 return true;
74 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters(
75 base::TimeTicks timebase,
76 base::TimeDelta interval) {
77 DCHECK(HasClient());
78 DCHECK(!use_begin_frame_scheduling_);
79 CommitVSyncParameters(timebase, interval);
82 void BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu(
83 base::TimeTicks timebase,
84 base::TimeDelta interval) {
85 DCHECK(HasClient());
86 if (use_begin_frame_scheduling_) {
87 CommitVSyncParameters(timebase, interval);
88 return;
91 vsync_manager_->UpdateVSyncParameters(timebase, interval);
94 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) {
95 // Software mirroring is done by doing a GL copy out of the framebuffer - if
96 // we have overlays then that data will be missing.
97 if (overlay_candidate_validator_) {
98 overlay_candidate_validator_->SetSoftwareMirrorMode(reflector != nullptr);
100 reflector_ = reflector;
102 OnReflectorChanged();
105 void BrowserCompositorOutputSurface::OnReflectorChanged() {
108 base::Closure
109 BrowserCompositorOutputSurface::CreateCompositionStartedCallback() {
110 return base::Closure();
113 cc::OverlayCandidateValidator*
114 BrowserCompositorOutputSurface::GetOverlayCandidateValidator() const {
115 return overlay_candidate_validator_.get();
118 } // namespace content