-
Notifications
You must be signed in to change notification settings - Fork 0
/
Platform.cs
95 lines (77 loc) · 2.24 KB
/
Platform.cs
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
using System;
using System.IO;
using PiGameSharp.Dispmanx;
using PiGameSharp.EGL;
namespace PiGameSharp
{
/// <summary>
/// Initialization for the PiGameSharp platform
/// </summary>
public static class Platform
{
private static Action deinit;
/// <summary>
/// Detect the current platform and perform relevant initialisation
/// </summary>
public static void Init(object target)
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
WindowsInit(target);
else if (Environment.OSVersion.Platform == PlatformID.Unix)
{
string hw = File.ReadAllText("/proc/cpuinfo").ToLower();
if (hw.Contains("bcm2708") || hw.Contains("bcm2709") || hw.Contains("bcm2837") || hw.Contains("bcm2836") || hw.Contains("bcm2835"))
PiInit();
else
LinuxInit();
}
Input.Init();
PerformanceCounter.StartStatsSampling();
}
/// <summary>
/// Deinitialize and release all resources.
/// </summary>
public static void Deinit()
{
PerformanceCounter.StopStatsSampling();
ResourceLibrary.Dispose();
PiGameSharp.EGL.EGL.Deinit();
if (deinit != null)
deinit();
Input.Deinit();
}
private static void WindowsInit(object target)
{
if (!(target is IntPtr))
throw new ArgumentException("Windows init expects a window handle IntPtr");
PiGameSharp.EGL.EGL.InitWin32((IntPtr)target, EglApi.OpenVG);
PiGameSharp.Sound.PCM.play = PiGameSharp.Sound.Windows.Play;
}
private static void PiInit()
{
deinit = PiDeinit;
BcmHost.Init();
if (BcmHost.Devices == null || BcmHost.Devices.Count < 0)
throw new Exception("No dispmanx display available");
PiGameSharp.EGL.EGL.InitDispmanx(BcmHost.Devices[0], EglApi.OpenVG);
PiGameSharp.Sound.ALSA.Init();
PiGameSharp.Sound.PCM.play = PiGameSharp.Sound.ALSA.Play;
}
private static void PiDeinit()
{
PiGameSharp.Sound.ALSA.Deinit();
BcmHost.Deinit();
}
private static void LinuxInit()
{
deinit = LinuxDeinit;
//TODO: egl+vg init on linux
PiGameSharp.Sound.ALSA.Init();
PiGameSharp.Sound.PCM.play = PiGameSharp.Sound.ALSA.Play;
}
private static void LinuxDeinit()
{
PiGameSharp.Sound.ALSA.Deinit();
}
}
}