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 "content/browser/compositor/reflector_impl.h"
12 #include "content/common/gpu/client/context_provider_command_buffer.h"
13 #include "ui/compositor/compositor_switches.h"
17 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
18 const scoped_refptr
<ContextProviderCommandBuffer
>& context_provider
,
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
) {
29 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
30 scoped_ptr
<cc::SoftwareOutputDevice
> software_device
,
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
) {
41 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() {
42 DCHECK(CalledOnValidThread());
44 reflector_
->DetachFromOutputSurface();
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;
59 bool BrowserCompositorOutputSurface::BindToClient(
60 cc::OutputSurfaceClient
* client
) {
61 DCHECK(CalledOnValidThread());
63 if (!OutputSurface::BindToClient(client
))
66 output_surface_map_
->AddWithID(this, surface_id_
);
68 reflector_
->OnSourceSurfaceReady(this);
69 vsync_manager_
->AddObserver(this);
73 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters(
74 base::TimeTicks timebase
,
75 base::TimeDelta interval
) {
76 DCHECK(CalledOnValidThread());
78 CommitVSyncParameters(timebase
, interval
);
81 void BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu(
82 base::TimeTicks timebase
,
83 base::TimeDelta interval
) {
84 DCHECK(CalledOnValidThread());
86 vsync_manager_
->UpdateVSyncParameters(timebase
, interval
);
89 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl
* reflector
) {
90 reflector_
= reflector
;
93 } // namespace content