-
Notifications
You must be signed in to change notification settings - Fork 9
/
PixelToasterApple.h
executable file
·126 lines (99 loc) · 2.88 KB
/
PixelToasterApple.h
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
123
124
125
126
// Apple MacOS X Platform
// Copyright © 2004-2007 Glenn Fiedler
// Part of the PixelToaster Framebuffer Library - http://www.pixeltoaster.com
// native Cocoa output implemented by Thorsten Schaaps <[email protected]>
#ifndef PIXELTOASTER_APPLE_USE_X11
# define PIXELTOASTER_APPLE_USE_X11 0
#endif
#include "CoreServices/CoreServices.h"
#include <mach/mach_time.h>
#if PIXELTOASTER_APPLE_USE_X11
# define PIXELTOASTER_NO_UNIX_TIMER
# include "PixelToasterUnix.h"
#endif
// display implementation
namespace PixelToaster {
#if !PIXELTOASTER_APPLE_USE_X11
class AppleDisplay : public DisplayAdapter
{
class AppleDisplayPrivate;
public:
AppleDisplay();
virtual ~AppleDisplay();
bool open(const char title[],
int width, int height,
Output output,
Mode mode) override;
void close() override;
bool update(const TrueColorPixel* trueColorPixels,
const FloatingPointPixel* floatingPointPixels,
const Rectangle* dirtyBox) override;
void title(const char title[]) override;
bool windowed() override;
bool fullscreen() override;
void listener(Listener* listener) override;
void setShouldClose() { _shouldClose = true; }
void setShouldToggle() { _shouldToggle = true; }
void shutdown();
protected:
void defaults() override;
private:
AppleDisplayPrivate* _private;
bool _shouldClose;
bool _shouldToggle;
};
#else
class AppleDisplay : public UnixDisplay
{
// ...
};
#endif
// timer implementation
class AppleTimer : public TimerInterface
{
public:
AppleTimer()
{
mach_timebase_info_data_t timebase;
mach_timebase_info(&timebase);
_resolution = (double)timebase.numer / ((double)timebase.denom * 1.0e9);
reset();
}
void reset()
{
_deltaCounter = mach_absolute_time();
_time = 0;
}
double time()
{
uint64_t counter = mach_absolute_time();
uint64_t delta = counter - _timeCounter;
_timeCounter = counter;
_time += delta * _resolution;
return _time;
}
double delta()
{
uint64_t counter = mach_absolute_time();
uint64_t delta = counter - _deltaCounter;
_deltaCounter = counter;
return delta * _resolution;
}
double resolution()
{
return _resolution;
}
void wait(double seconds)
{
uint64_t counter = mach_absolute_time();
uint64_t finish = counter + uint64_t(seconds / _resolution);
while (counter < finish)
counter = mach_absolute_time();
}
private:
double _time; ///< current time in seconds
uint64_t _timeCounter; ///< time counter in timebase
uint64_t _deltaCounter; ///< delta counter in timebase
double _resolution;
};
} // namespace PixelToaster