@kmamal/sdl 1.0.0-5 → 1.0.0-8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -6
- package/binding.gyp +3 -0
- package/package.json +5 -12
- package/scripts/util/common.js +2 -2
- package/src/javascript/audio/audio-playback-stream.js +9 -10
- package/src/javascript/audio/audio-recording-stream.js +9 -8
- package/src/javascript/audio/audio-stream.js +100 -44
- package/src/javascript/audio/conversion.js +41 -0
- package/src/javascript/audio/devices.js +11 -0
- package/src/javascript/audio/events.js +65 -0
- package/src/javascript/audio/format-helpers.js +8 -4
- package/src/javascript/audio/index.js +25 -20
- package/src/javascript/audio/prevent-exit.js +12 -9
- package/src/javascript/audio/validate.js +9 -0
- package/src/javascript/cleanup.js +9 -6
- package/src/javascript/clipboard/index.js +8 -3
- package/src/javascript/device-instance.js +61 -0
- package/src/javascript/events/events-via-poll.js +33 -27
- package/src/javascript/events/index.js +75 -482
- package/src/javascript/events/try.js +22 -0
- package/src/javascript/gamepad/{device.js → devices.js} +4 -5
- package/src/javascript/gamepad/events.js +66 -0
- package/src/javascript/gamepad/gamepad-instance.js +12 -160
- package/src/javascript/gamepad/index.js +15 -16
- package/src/javascript/globals.js +10 -1
- package/src/javascript/index.js +2 -5
- package/src/javascript/joystick/devices.js +43 -0
- package/src/javascript/joystick/events.js +129 -0
- package/src/javascript/joystick/index.js +9 -18
- package/src/javascript/joystick/joystick-device-instance.js +175 -0
- package/src/javascript/joystick/joystick-instance.js +12 -158
- package/src/javascript/keyboard/index.js +20 -10
- package/src/javascript/keyboard/key-mapping.js +46 -27
- package/src/javascript/mouse/index.js +36 -29
- package/src/javascript/sensor/events.js +21 -0
- package/src/javascript/sensor/index.js +13 -2
- package/src/javascript/sensor/sensor-instance.js +7 -47
- package/src/javascript/subsystems.js +56 -0
- package/src/javascript/touch/index.js +9 -4
- package/src/javascript/validate.js +114 -0
- package/src/javascript/video/conversion.js +63 -0
- package/src/javascript/video/events.js +179 -0
- package/src/javascript/video/format-helpers.js +10 -8
- package/src/javascript/video/index.js +28 -14
- package/src/javascript/video/validate.js +45 -0
- package/src/javascript/video/window.js +144 -161
- package/src/native/audio.cpp +457 -151
- package/src/native/audio.h +12 -6
- package/src/native/clipboard.cpp +8 -37
- package/src/native/enums.cpp +2 -0
- package/src/native/events.cpp +416 -354
- package/src/native/events.h +67 -65
- package/src/native/gamepad.cpp +86 -103
- package/src/native/gamepad.h +7 -8
- package/src/native/global.cpp +190 -85
- package/src/native/global.h +48 -2
- package/src/native/joystick.cpp +180 -274
- package/src/native/joystick.h +12 -6
- package/src/native/keyboard.cpp +60 -22
- package/src/native/keyboard.h +2 -1
- package/src/native/module.cpp +20 -3
- package/src/native/mouse.cpp +27 -58
- package/src/native/packed.cpp +106 -0
- package/src/native/packed.h +91 -0
- package/src/native/power.cpp +7 -1
- package/src/native/power.h +2 -2
- package/src/native/sensor.cpp +61 -69
- package/src/native/sensor.h +3 -3
- package/src/native/testing.cpp +131 -0
- package/src/native/testing.h +16 -0
- package/src/native/threads.cpp +300 -0
- package/src/native/threads.h +36 -0
- package/src/native/touch.cpp +32 -43
- package/src/native/touch.h +2 -1
- package/src/native/video.cpp +145 -95
- package/src/native/video.h +6 -3
- package/src/native/window.cpp +155 -218
- package/src/native/window.h +21 -20
- package/src/types/index.d.ts +141 -69
- package/src/javascript/audio/device.js +0 -37
- package/src/javascript/joystick/device.js +0 -13
- package/src/javascript/joystick/shared.js +0 -90
- package/src/javascript/worker.js +0 -88
- package/src/types/worker.d.ts +0 -71
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const Os = require('node:os')
|
|
2
|
+
const { validateString } = require('../validate')
|
|
2
3
|
|
|
3
4
|
const minStride = (bytesPerPixel) => (width) => width * bytesPerPixel
|
|
4
5
|
const minStridePacked = (width) => 4 * Math.ceil(width / 2)
|
|
@@ -13,15 +14,17 @@ const rgb = (bytesPerPixel) => ({
|
|
|
13
14
|
minStride: minStride(bytesPerPixel),
|
|
14
15
|
minBufferSize,
|
|
15
16
|
isRenderable: true,
|
|
17
|
+
isConvertible: true,
|
|
16
18
|
})
|
|
17
19
|
|
|
18
|
-
const yuv = (bytesPerPixel, isPlanarYuv,
|
|
20
|
+
const yuv = (bytesPerPixel, isPlanarYuv, isSupported = true) => ({
|
|
19
21
|
bytesPerPixel,
|
|
20
22
|
isYuv: true,
|
|
21
23
|
isPlanarYuv,
|
|
22
24
|
minStride: isPlanarYuv ? minStride(bytesPerPixel) : minStridePacked,
|
|
23
25
|
minBufferSize: isPlanarYuv ? minBufferSizePlanar : minBufferSize,
|
|
24
|
-
isRenderable,
|
|
26
|
+
isRenderable: isSupported,
|
|
27
|
+
isConvertible: isSupported,
|
|
25
28
|
})
|
|
26
29
|
|
|
27
30
|
const VideoFormatHelpers = Object.assign(Object.create(null), {
|
|
@@ -82,10 +85,6 @@ const VideoFormatHelpers = Object.assign(Object.create(null), {
|
|
|
82
85
|
p010: { ...yuv(2, true, false), minStride: minStridePacked },
|
|
83
86
|
})
|
|
84
87
|
|
|
85
|
-
for (const [ key, value ] of Object.entries(VideoFormatHelpers)) {
|
|
86
|
-
value.name = key
|
|
87
|
-
}
|
|
88
|
-
|
|
89
88
|
if (Os.endianness() === 'LE') {
|
|
90
89
|
VideoFormatHelpers.rgba32 = VideoFormatHelpers.abgr8888
|
|
91
90
|
VideoFormatHelpers.argb32 = VideoFormatHelpers.bgra8888
|
|
@@ -108,10 +107,13 @@ else {
|
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
const getFormatHelpers = (format) => {
|
|
111
|
-
|
|
110
|
+
validateString('format', format)
|
|
112
111
|
const helpers = VideoFormatHelpers[format]
|
|
113
112
|
if (helpers === undefined) { throw Object.assign(new Error("invalid format"), { format }) }
|
|
114
113
|
return helpers
|
|
115
114
|
}
|
|
116
115
|
|
|
117
|
-
module.exports = {
|
|
116
|
+
module.exports = {
|
|
117
|
+
VideoFormatHelpers,
|
|
118
|
+
getFormatHelpers,
|
|
119
|
+
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
const Globals = require('../globals')
|
|
2
|
+
const { assertInitialized, isAvailable } = require('../subsystems')
|
|
2
3
|
const Bindings = require('../bindings')
|
|
3
4
|
const { EventsViaPoll } = require('../events/events-via-poll')
|
|
4
5
|
const { Window } = require('./window')
|
|
5
6
|
const { getFormatHelpers } = require('./format-helpers')
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Globals.displays = Globals.info.initialized.video
|
|
9
|
-
? Bindings.video_getDisplays()
|
|
10
|
-
: []
|
|
7
|
+
const { convert } = require('./conversion')
|
|
8
|
+
const { validateNonNegativeInteger } = require('../validate')
|
|
11
9
|
|
|
12
10
|
|
|
13
11
|
const validEvents = [
|
|
@@ -21,26 +19,45 @@ const validEvents = [
|
|
|
21
19
|
]
|
|
22
20
|
|
|
23
21
|
const video = new class extends EventsViaPoll {
|
|
24
|
-
constructor () { super(validEvents) }
|
|
22
|
+
constructor () { super(validEvents, () => { assertInitialized('video') }) }
|
|
23
|
+
|
|
24
|
+
isAvailable () { return isAvailable('video') }
|
|
25
|
+
|
|
26
|
+
get drivers () {
|
|
27
|
+
assertInitialized('video')
|
|
28
|
+
return Bindings.video_getDrivers()
|
|
29
|
+
}
|
|
25
30
|
|
|
26
31
|
get displays () {
|
|
32
|
+
assertInitialized('video')
|
|
27
33
|
Globals.events.poll()
|
|
28
34
|
return [ ...Globals.displays ]
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
get windows () {
|
|
37
|
+
get windows () {
|
|
38
|
+
assertInitialized('video')
|
|
39
|
+
Globals.events.poll()
|
|
40
|
+
return [ ...Globals.windows.all.values() ]
|
|
41
|
+
}
|
|
32
42
|
|
|
33
43
|
get focused () {
|
|
44
|
+
assertInitialized('video')
|
|
34
45
|
Globals.events.poll()
|
|
35
46
|
return Globals.windows.focused
|
|
36
47
|
}
|
|
37
48
|
|
|
38
49
|
get hovered () {
|
|
50
|
+
assertInitialized('video')
|
|
39
51
|
Globals.events.poll()
|
|
40
52
|
return Globals.windows.hovered
|
|
41
53
|
}
|
|
42
54
|
|
|
43
|
-
createWindow (options) {
|
|
55
|
+
createWindow (options) {
|
|
56
|
+
assertInitialized('video')
|
|
57
|
+
return new Window(options)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
convert (...args) { return convert(...args) }
|
|
44
61
|
|
|
45
62
|
bytesPerPixel (format) { return getFormatHelpers(format).bytesPerPixel }
|
|
46
63
|
isYuv (format) { return getFormatHelpers(format).isYuv }
|
|
@@ -48,17 +65,14 @@ const video = new class extends EventsViaPoll {
|
|
|
48
65
|
|
|
49
66
|
minStride (format, width) {
|
|
50
67
|
const helpers = getFormatHelpers(format)
|
|
51
|
-
|
|
52
|
-
if (width < 0) { throw Object.assign(new Error("width must be non-negative"), { width }) }
|
|
68
|
+
validateNonNegativeInteger('width', width)
|
|
53
69
|
return helpers.minStride(width)
|
|
54
70
|
}
|
|
55
71
|
|
|
56
72
|
minBufferSize (format, stride, height) {
|
|
57
73
|
const helpers = getFormatHelpers(format)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (!Number.isInteger(height)) { throw Object.assign(new Error("height must be an integer"), { height }) }
|
|
61
|
-
if (height < 0) { throw Object.assign(new Error("height must be non-negative"), { height }) }
|
|
74
|
+
validateNonNegativeInteger('stride', stride)
|
|
75
|
+
validateNonNegativeInteger('height', height)
|
|
62
76
|
return helpers.minBufferSize(stride, height)
|
|
63
77
|
}
|
|
64
78
|
}()
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const { VideoFormatHelpers } = require('./format-helpers')
|
|
2
|
+
const { INT32_MAX, validateString, validateBuffer, validateInteger, validateIntegerRange, validatePositiveInt32 } = require('../validate')
|
|
3
|
+
|
|
4
|
+
const validateVsync = (vsync) => {
|
|
5
|
+
validateIntegerRange('vsync', vsync, -1, INT32_MAX, "must be -1 or a non-negative 32-bit integer")
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const validateStride = (name, stride, minStride, details) => {
|
|
9
|
+
validateInteger(name, stride)
|
|
10
|
+
if (stride > INT32_MAX) { throw Object.assign(new Error(`${name} must be a 32-bit integer`), details) }
|
|
11
|
+
if (stride < minStride) { throw Object.assign(new Error(`${name} is smaller than expected`), details) }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const validateImageBuffer = (name, buffer, minSize, details) => {
|
|
15
|
+
validateBuffer(name, buffer)
|
|
16
|
+
if (buffer.length < minSize) { throw Object.assign(new Error(`${name} is smaller than expected`), details) }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const validateImage = (width, height, stride, format, buffer, validateHelpers) => {
|
|
20
|
+
validatePositiveInt32('width', width)
|
|
21
|
+
validatePositiveInt32('height', height)
|
|
22
|
+
validateString('format', format)
|
|
23
|
+
const helpers = VideoFormatHelpers[format]
|
|
24
|
+
if (helpers === undefined) { throw Object.assign(new Error("invalid format"), { format }) }
|
|
25
|
+
validateHelpers(helpers, format)
|
|
26
|
+
validateStride('stride', stride, helpers.minStride(width), { stride, width, format })
|
|
27
|
+
validateImageBuffer('buffer', buffer, helpers.minBufferSize(stride, height), { buffer, stride, height, format })
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const validateRenderableFormat = (helpers, format) => {
|
|
31
|
+
if (!helpers.isRenderable) { throw Object.assign(new Error("format can't be rendered"), { format }) }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const validateRgbFormat = (helpers, format) => {
|
|
35
|
+
if (helpers.isYuv) { throw Object.assign(new Error("format must be an RGB format"), { format }) }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
validateVsync,
|
|
40
|
+
validateStride,
|
|
41
|
+
validateImageBuffer,
|
|
42
|
+
validateImage,
|
|
43
|
+
validateRenderableFormat,
|
|
44
|
+
validateRgbFormat,
|
|
45
|
+
}
|