Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / content / browser / compositor / browser_compositor_output_surface.cc
blobb1cdd90e54e068b94c6e7ffe509192199beb3863
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 "content/browser/compositor/reflector_impl.h"
12 #include "content/common/gpu/client/context_provider_command_buffer.h"
13 #include "ui/compositor/compositor_switches.h"
15 namespace content {
17 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
18 const scoped_refptr<ContextProviderCommandBuffer>& context_provider,
19 int surface_id,
20 IDMap<BrowserCompositorOutputSurface>* output_surface_map,
21 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager)
22 : OutputSurface(context_provider),
23 surface_id_(surface_id),
24 output_surface_map_(output_surface_map),
25 vsync_manager_(vsync_manager) {
26 Initialize();
29 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
30 scoped_ptr<cc::SoftwareOutputDevice> software_device,
31 int surface_id,
32 IDMap<BrowserCompositorOutputSurface>* output_surface_map,
33 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager)
34 : OutputSurface(software_device.Pass()),
35 surface_id_(surface_id),
36 output_surface_map_(output_surface_map),
37 vsync_manager_(vsync_manager) {
38 Initialize();
41 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() {
42 DCHECK(CalledOnValidThread());
43 if (reflector_)
44 reflector_->DetachFromOutputSurface();
45 DCHECK(!reflector_);
46 if (!HasClient())
47 return;
48 output_surface_map_->Remove(surface_id_);
49 vsync_manager_->RemoveObserver(this);
52 void BrowserCompositorOutputSurface::Initialize() {
53 capabilities_.max_frames_pending = 1;
54 capabilities_.adjust_deadline_for_parent = false;
56 DetachFromThread();
59 bool BrowserCompositorOutputSurface::BindToClient(
60 cc::OutputSurfaceClient* client) {
61 DCHECK(CalledOnValidThread());
63 if (!OutputSurface::BindToClient(client))
64 return false;
66 output_surface_map_->AddWithID(this, surface_id_);
67 if (reflector_)
68 reflector_->OnSourceSurfaceReady(this);
69 vsync_manager_->AddObserver(this);
70 return true;
73 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters(
74 base::TimeTicks timebase,
75 base::TimeDelta interval) {
76 DCHECK(CalledOnValidThread());
77 DCHECK(HasClient());
78 CommitVSyncParameters(timebase, interval);
81 void BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu(
82 base::TimeTicks timebase,
83 base::TimeDelta interval) {
84 DCHECK(CalledOnValidThread());
85 DCHECK(HasClient());
86 vsync_manager_->UpdateVSyncParameters(timebase, interval);
89 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) {
90 reflector_ = reflector;
93 } // namespace content