summaryrefslogtreecommitdiff
path: root/src/helpers/MonitorFrameScheduler.hpp
blob: b12d8789c8cd1c439d3a3608fa0b462c64d056e3 (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
#pragma once

#include "Monitor.hpp"
#include "../render/SyncFDManager.hpp"

#include <chrono>

class CMonitorFrameScheduler {
  public:
    using hrc = std::chrono::high_resolution_clock;

    CMonitorFrameScheduler(PHLMONITOR m);

    CMonitorFrameScheduler(const CMonitorFrameScheduler&)            = delete;
    CMonitorFrameScheduler(CMonitorFrameScheduler&&)                 = delete;
    CMonitorFrameScheduler& operator=(const CMonitorFrameScheduler&) = delete;
    CMonitorFrameScheduler& operator=(CMonitorFrameScheduler&&)      = delete;

    void                    onSyncFired();
    void                    onPresented();
    void                    onFrame();

  private:
    bool                       canRender();
    void                       onFinishRender();
    bool                       newSchedulingEnabled();

    bool                       m_renderAtFrame = true;
    bool                       m_pendingThird  = false;
    hrc::time_point            m_lastRenderBegun;

    PHLMONITORREF              m_monitor;

    UP<Render::ISyncFDManager> m_sync;

    WP<CMonitorFrameScheduler> m_self;

    friend class CMonitor;
};