1 // Copyright 2015 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 #ifndef CC_SURFACES_DISPLAY_SCHEDULER_H_
6 #define CC_SURFACES_DISPLAY_SCHEDULER_H_
8 #include "base/cancelable_callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/single_thread_task_runner.h"
12 #include "cc/scheduler/begin_frame_source.h"
13 #include "cc/surfaces/surface_id.h"
14 #include "cc/surfaces/surfaces_export.h"
19 class BeginFrameSource
;
21 // TODO(brianderson): Reconcile with SurfacesScheduler crbug.com/476676
22 class CC_SURFACES_EXPORT DisplaySchedulerClient
{
24 virtual ~DisplaySchedulerClient() {}
26 virtual bool DrawAndSwap() = 0;
29 class CC_SURFACES_EXPORT DisplayScheduler
: public BeginFrameObserverBase
{
31 DisplayScheduler(DisplaySchedulerClient
* client
,
32 BeginFrameSource
* begin_frame_source
,
33 base::SingleThreadTaskRunner
* task_runner
,
34 int max_pending_swaps
);
35 ~DisplayScheduler() override
;
37 void SetRootSurfaceResourcesLocked(bool locked
);
38 void ForceImmediateSwapIfPossible();
39 virtual void DisplayResized();
40 virtual void SetNewRootSurface(SurfaceId root_surface_id
);
41 virtual void SurfaceDamaged(SurfaceId surface_id
);
43 virtual void DidSwapBuffers();
44 void DidSwapBuffersComplete();
46 void OutputSurfaceLost();
48 // BeginFrameObserverBase implementation
49 bool OnBeginFrameDerivedImpl(const BeginFrameArgs
& args
) override
;
52 base::TimeTicks
DesiredBeginFrameDeadlineTime();
53 virtual void ScheduleBeginFrameDeadline();
54 void AttemptDrawAndSwap();
55 void OnBeginFrameDeadline();
58 DisplaySchedulerClient
* client_
;
59 BeginFrameSource
* begin_frame_source_
;
60 base::SingleThreadTaskRunner
* task_runner_
;
62 BeginFrameArgs current_begin_frame_args_
;
63 base::Closure begin_frame_deadline_closure_
;
64 base::CancelableClosure begin_frame_deadline_task_
;
65 base::TimeTicks begin_frame_deadline_task_time_
;
67 bool output_surface_lost_
;
68 bool root_surface_resources_locked_
;
70 bool inside_begin_frame_deadline_interval_
;
72 bool expecting_root_surface_damage_because_of_resize_
;
73 bool all_active_child_surfaces_ready_to_draw_
;
76 int max_pending_swaps_
;
78 SurfaceId root_surface_id_
;
79 bool root_surface_damaged_
;
80 bool expect_damage_from_root_surface_
;
82 std::set
<SurfaceId
> child_surface_ids_damaged_
;
83 std::set
<SurfaceId
> child_surface_ids_damaged_prev_
;
84 std::vector
<SurfaceId
> child_surface_ids_to_expect_damage_from_
;
86 base::WeakPtrFactory
<DisplayScheduler
> weak_ptr_factory_
;
89 DISALLOW_COPY_AND_ASSIGN(DisplayScheduler
);
94 #endif // CC_SURFACES_DISPLAY_SCHEDULER_H_