blob: dab00d77c9bd352158bfb9203fe66360480b7938 (
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
|
#pragma once
#include <memory>
#include <vector>
#include "../helpers/Timer.hpp"
#include "eventLoop/EventLoopTimer.hpp"
#ifndef GLES2
#include <GLES3/gl32.h>
#else
#define GLsync void*
#endif
class CMonitor;
struct wlr_buffer;
struct wlr_output_event_present;
class CFrameSchedulingManager {
public:
void registerMonitor(CMonitor* pMonitor);
void unregisterMonitor(CMonitor* pMonitor);
void gpuDone(CMonitor* pMonitor);
void registerBuffer(wlr_buffer* pBuffer, CMonitor* pMonitor);
void dropBuffer(wlr_buffer* pBuffer);
void onFenceTimer(CMonitor* pMonitor);
void onFrameNeeded(CMonitor* pMonitor);
void onPresent(CMonitor* pMonitor, wlr_output_event_present* presentationData);
void onFrame(CMonitor* pMonitor);
void onVblankTimer(void* data);
bool isMonitorUsingLegacyScheduler(CMonitor* pMonitor);
private:
struct SSchedulingData {
CMonitor* pMonitor = nullptr;
// CPU frame rendering has been finished
bool rendered = false;
// GPU didn't manage to render last frame in time.
// we got a vblank before we got a gpuDone()
bool delayed = false;
// whether the frame was submitted from gpuDone
bool delayedFrameSubmitted = false;
// we need to render a few full frames at the beginning to catch all buffers
int forceFrames = 10;
// last present timer
CTimer lastPresent;
// buffers associated with this monitor
std::vector<wlr_buffer*> buffers;
// whether we're actively pushing frames
bool activelyPushing = false;
// legacy scheduler: for backends that do not send us reliable present events
// these rely on onFrame
bool legacyScheduler = false;
// next predicted vblank
std::chrono::system_clock::time_point nextVblank;
// for delayed fence stuff
std::shared_ptr<CEventLoopTimer> fenceTimer;
std::shared_ptr<CEventLoopTimer> vblankTimer;
// fence sync
GLsync fenceSync = 0;
};
std::vector<SSchedulingData> m_vSchedulingData;
SSchedulingData* dataFor(CMonitor* pMonitor);
SSchedulingData* dataFor(wlr_buffer* pBuffer);
void renderMonitor(SSchedulingData* data);
};
inline std::unique_ptr<CFrameSchedulingManager> g_pFrameSchedulingManager;
|