1 // Copyright (c) 2013 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/aura/browser_compositor_output_surface.h"
8 #include "base/command_line.h"
9 #include "base/location.h"
10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "content/browser/aura/reflector_impl.h"
13 #include "content/common/gpu/client/context_provider_command_buffer.h"
14 #include "ui/compositor/compositor.h"
15 #include "ui/compositor/compositor_switches.h"
19 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
20 const scoped_refptr
<ContextProviderCommandBuffer
>& context_provider
,
22 IDMap
<BrowserCompositorOutputSurface
>* output_surface_map
,
23 base::MessageLoopProxy
* compositor_message_loop
,
24 base::WeakPtr
<ui::Compositor
> compositor
)
25 : OutputSurface(context_provider
),
26 surface_id_(surface_id
),
27 output_surface_map_(output_surface_map
),
28 compositor_message_loop_(compositor_message_loop
),
29 compositor_(compositor
) {
33 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
34 scoped_ptr
<cc::SoftwareOutputDevice
> software_device
,
36 IDMap
<BrowserCompositorOutputSurface
>* output_surface_map
,
37 base::MessageLoopProxy
* compositor_message_loop
,
38 base::WeakPtr
<ui::Compositor
> compositor
)
39 : OutputSurface(software_device
.Pass()),
40 surface_id_(surface_id
),
41 output_surface_map_(output_surface_map
),
42 compositor_message_loop_(compositor_message_loop
),
43 compositor_(compositor
) {
47 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() {
48 DCHECK(CalledOnValidThread());
51 output_surface_map_
->Remove(surface_id_
);
54 void BrowserCompositorOutputSurface::Initialize() {
55 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
56 if (command_line
->HasSwitch(switches::kUIMaxFramesPending
)) {
57 std::string string_value
= command_line
->GetSwitchValueASCII(
58 switches::kUIMaxFramesPending
);
60 if (base::StringToInt(string_value
, &int_value
))
61 capabilities_
.max_frames_pending
= int_value
;
63 LOG(ERROR
) << "Trouble parsing --" << switches::kUIMaxFramesPending
;
65 capabilities_
.adjust_deadline_for_parent
= false;
70 bool BrowserCompositorOutputSurface::BindToClient(
71 cc::OutputSurfaceClient
* client
) {
72 DCHECK(CalledOnValidThread());
74 if (!OutputSurface::BindToClient(client
))
77 output_surface_map_
->AddWithID(this, surface_id_
);
79 reflector_
->OnSourceSurfaceReady(surface_id_
);
83 void BrowserCompositorOutputSurface::Reshape(gfx::Size size
,
85 OutputSurface::Reshape(size
, scale_factor
);
87 reflector_
->OnReshape(size
);
90 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters(
91 base::TimeTicks timebase
,
92 base::TimeDelta interval
) {
93 DCHECK(CalledOnValidThread());
95 OnVSyncParametersChanged(timebase
, interval
);
96 compositor_message_loop_
->PostTask(
98 base::Bind(&ui::Compositor::OnUpdateVSyncParameters
,
99 compositor_
, timebase
, interval
));
102 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl
* reflector
) {
103 reflector_
= reflector
;
106 } // namespace content