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 "cc/surfaces/onscreen_display_client.h"
7 #include "base/trace_event/trace_event.h"
8 #include "cc/output/output_surface.h"
9 #include "cc/output/vsync_parameter_observer.h"
10 #include "cc/scheduler/begin_frame_source.h"
11 #include "cc/surfaces/display_scheduler.h"
12 #include "cc/surfaces/surface_display_output_surface.h"
13 #include "cc/surfaces/surface_factory.h"
14 #include "cc/surfaces/surface_manager.h"
18 OnscreenDisplayClient::OnscreenDisplayClient(
19 scoped_ptr
<OutputSurface
> output_surface
,
20 SurfaceManager
* manager
,
21 SharedBitmapManager
* bitmap_manager
,
22 gpu::GpuMemoryBufferManager
* gpu_memory_buffer_manager
,
23 const RendererSettings
& settings
,
24 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner
)
25 : output_surface_(output_surface
.Pass()),
26 display_(new Display(this,
29 gpu_memory_buffer_manager
,
31 vsync_observer_(nullptr),
32 task_runner_(task_runner
),
33 output_surface_lost_(false),
34 disable_gpu_vsync_(settings
.disable_gpu_vsync
) {
37 OnscreenDisplayClient::~OnscreenDisplayClient() {
40 bool OnscreenDisplayClient::Initialize() {
41 int max_frames_pending
=
42 output_surface_
? output_surface_
->capabilities().max_frames_pending
: 0;
43 if (max_frames_pending
<= 0)
44 max_frames_pending
= OutputSurface::DEFAULT_MAX_FRAMES_PENDING
;
46 if (disable_gpu_vsync_
) {
48 BackToBackBeginFrameSource::Create(task_runner_
.get());
50 scoped_ptr
<SyntheticBeginFrameSource
> synthetic_source
=
51 SyntheticBeginFrameSource::Create(task_runner_
.get(), base::TimeTicks(),
52 BeginFrameArgs::DefaultInterval());
53 vsync_observer_
= synthetic_source
.get();
54 begin_frame_source_
= synthetic_source
.Pass();
57 scheduler_
.reset(new DisplayScheduler(display_
.get(),
58 begin_frame_source_
.get(), task_runner_
,
61 return display_
->Initialize(output_surface_
.Pass(), scheduler_
.get());
64 void OnscreenDisplayClient::CommitVSyncParameters(base::TimeTicks timebase
,
65 base::TimeDelta interval
) {
66 if (interval
== base::TimeDelta()) {
67 // TODO(brianderson): We should not be receiving 0 intervals.
68 interval
= BeginFrameArgs::DefaultInterval();
71 surface_display_output_surface_
->ReceivedVSyncParameters(timebase
, interval
);
73 vsync_observer_
->OnUpdateVSyncParameters(timebase
, interval
);
76 void OnscreenDisplayClient::OutputSurfaceLost() {
77 output_surface_lost_
= true;
78 surface_display_output_surface_
->DidLoseOutputSurface();
81 void OnscreenDisplayClient::SetMemoryPolicy(const ManagedMemoryPolicy
& policy
) {
82 surface_display_output_surface_
->SetMemoryPolicy(policy
);