summaryrefslogtreecommitdiffstats
path: root/cc/scheduler.h
blob: 52a7a4c4807afc0488d4e8fa67e9f3f871e9b8ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_SCHEDULER_H_
#define CC_SCHEDULER_H_

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/time.h"
#include "cc/cc_export.h"
#include "cc/frame_rate_controller.h"
#include "cc/layer_tree_host.h"
#include "cc/scheduler_settings.h"
#include "cc/scheduler_state_machine.h"

namespace cc {

class Thread;

struct ScheduledActionDrawAndSwapResult {
    ScheduledActionDrawAndSwapResult()
            : didDraw(false)
            , didSwap(false)
    {
    }
    ScheduledActionDrawAndSwapResult(bool didDraw, bool didSwap)
            : didDraw(didDraw)
            , didSwap(didSwap)
    {
    }
    bool didDraw;
    bool didSwap;
};

class SchedulerClient {
public:
    virtual void scheduledActionBeginFrame() = 0;
    virtual ScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossible() = 0;
    virtual ScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced() = 0;
    virtual void scheduledActionCommit() = 0;
    virtual void scheduledActionCheckForCompletedTileUploads() = 0;
    virtual void scheduledActionActivatePendingTreeIfNeeded() = 0;
    virtual void scheduledActionBeginContextRecreation() = 0;
    virtual void scheduledActionAcquireLayerTexturesForMainThread() = 0;
    virtual void didAnticipatedDrawTimeChange(base::TimeTicks) = 0;

protected:
    virtual ~SchedulerClient() { }
};

class CC_EXPORT Scheduler : FrameRateControllerClient {
public:
    static scoped_ptr<Scheduler> create(SchedulerClient* client,
                                        scoped_ptr<FrameRateController> frameRateController,
                                        const SchedulerSettings& schedulerSettings)
    {
        return make_scoped_ptr(new Scheduler(client, frameRateController.Pass(), schedulerSettings));
    }

    virtual ~Scheduler();

    void setCanBeginFrame(bool);

    void setVisible(bool);
    void setCanDraw(bool);
    void setHasPendingTree(bool);

    void setNeedsCommit();

    // Like setNeedsCommit(), but ensures a commit will definitely happen even if we are not visible.
    void setNeedsForcedCommit();

    void setNeedsRedraw();

    void setMainThreadNeedsLayerTextures();

    // Like setNeedsRedraw(), but ensures the draw will definitely happen even if we are not visible.
    void setNeedsForcedRedraw();

    void didSwapUseIncompleteTile();

    void beginFrameComplete();
    void beginFrameAborted();

    void setMaxFramesPending(int);
    int maxFramesPending() const;

    void setSwapBuffersCompleteSupported(bool);
    void didSwapBuffersComplete();

    void didLoseOutputSurface();
    void didRecreateOutputSurface();

    bool commitPending() const { return m_stateMachine.commitPending(); }
    bool redrawPending() const { return m_stateMachine.redrawPending(); }

    void setTimebaseAndInterval(base::TimeTicks timebase, base::TimeDelta interval);

    base::TimeTicks anticipatedDrawTime();

    // FrameRateControllerClient implementation
    virtual void vsyncTick(bool throttled) OVERRIDE;

private:
    Scheduler(SchedulerClient*, scoped_ptr<FrameRateController>,
              const SchedulerSettings& schedulerSettings);

    void processScheduledActions();

    const SchedulerSettings m_settings;
    SchedulerClient* m_client;
    scoped_ptr<FrameRateController> m_frameRateController;
    SchedulerStateMachine m_stateMachine;
    bool m_insideProcessScheduledActions;

    DISALLOW_COPY_AND_ASSIGN(Scheduler);
};

}  // namespace cc

#endif  // CC_SCHEDULER_H_