@kmamal/sdl 0.11.12 → 1.0.0-2

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.
Files changed (86) hide show
  1. package/CHANGELOG.md +257 -1
  2. package/README.md +26 -2685
  3. package/binding.gyp +82 -65
  4. package/package.json +17 -11
  5. package/scripts/build-sdl.mjs +15 -7
  6. package/scripts/build.mjs +30 -15
  7. package/scripts/download-release.mjs +9 -6
  8. package/scripts/download-sdl.mjs +9 -6
  9. package/scripts/install.mjs +13 -5
  10. package/scripts/util/common.js +9 -1
  11. package/src/javascript/audio/audio-playback-stream.js +50 -0
  12. package/src/javascript/audio/audio-recording-stream.js +32 -0
  13. package/src/javascript/audio/{audio-instance.js → audio-stream.js} +35 -32
  14. package/src/javascript/audio/device.js +34 -6
  15. package/src/javascript/audio/format-helpers.js +26 -35
  16. package/src/javascript/audio/index.js +37 -26
  17. package/src/javascript/audio/prevent-exit.js +19 -9
  18. package/src/javascript/cleanup.js +19 -10
  19. package/src/javascript/enums.js +5 -0
  20. package/src/javascript/events/events-via-poll.js +25 -7
  21. package/src/javascript/events/index.js +274 -175
  22. package/src/javascript/gamepad/device.js +23 -0
  23. package/src/javascript/gamepad/gamepad-instance.js +209 -0
  24. package/src/javascript/gamepad/index.js +51 -0
  25. package/src/javascript/globals.js +8 -5
  26. package/src/javascript/helpers.js +34 -7
  27. package/src/javascript/index.js +5 -3
  28. package/src/javascript/joystick/device.js +5 -10
  29. package/src/javascript/joystick/index.js +7 -7
  30. package/src/javascript/joystick/joystick-instance.js +79 -42
  31. package/src/javascript/joystick/shared.js +88 -0
  32. package/src/javascript/keyboard/index.js +6 -4
  33. package/src/javascript/keyboard/key-mapping.js +70 -28
  34. package/src/javascript/mouse/index.js +21 -10
  35. package/src/javascript/sensor/devices.js +17 -0
  36. package/src/javascript/sensor/index.js +2 -16
  37. package/src/javascript/sensor/sensor-instance.js +20 -6
  38. package/src/javascript/touch/devices.js +17 -0
  39. package/src/javascript/touch/index.js +3 -7
  40. package/src/javascript/video/format-helpers.js +99 -0
  41. package/src/javascript/video/index.js +37 -5
  42. package/src/javascript/video/window.js +280 -134
  43. package/src/native/audio.cpp +182 -58
  44. package/src/native/audio.h +10 -5
  45. package/src/native/clipboard.cpp +22 -5
  46. package/src/native/cocoa-window.h +1 -0
  47. package/src/native/cocoa-window.mm +1 -1
  48. package/src/native/enums.cpp +91 -58
  49. package/src/native/events.cpp +437 -284
  50. package/src/native/events.h +18 -12
  51. package/src/native/gamepad.cpp +185 -0
  52. package/src/native/gamepad.h +27 -0
  53. package/src/native/global.cpp +173 -167
  54. package/src/native/global.h +0 -2
  55. package/src/native/joystick.cpp +287 -225
  56. package/src/native/joystick.h +7 -6
  57. package/src/native/keyboard.cpp +28 -8
  58. package/src/native/keyboard.h +4 -2
  59. package/src/native/module.cpp +14 -8
  60. package/src/native/mouse.cpp +54 -34
  61. package/src/native/mouse.h +0 -1
  62. package/src/native/power.cpp +10 -4
  63. package/src/native/power.h +1 -1
  64. package/src/native/sensor.cpp +52 -52
  65. package/src/native/sensor.h +1 -1
  66. package/src/native/touch.cpp +45 -24
  67. package/src/native/touch.h +1 -1
  68. package/src/native/video.cpp +115 -75
  69. package/src/native/video.h +5 -2
  70. package/src/native/window.cpp +415 -305
  71. package/src/native/window.h +3 -1
  72. package/src/types/helpers.d.ts +44 -19
  73. package/src/types/index.d.ts +343 -255
  74. package/scripts/util/fetch.js +0 -85
  75. package/src/javascript/audio/audio-playback-instance.js +0 -23
  76. package/src/javascript/audio/audio-recording-instance.js +0 -17
  77. package/src/javascript/controller/controller-instance.js +0 -160
  78. package/src/javascript/controller/device.js +0 -26
  79. package/src/javascript/controller/index.js +0 -33
  80. package/src/javascript/events/reconcile-audio-devices.js +0 -16
  81. package/src/javascript/events/reconcile-displays.js +0 -17
  82. package/src/javascript/events/reconcile-joystick-and-controller-devices.js +0 -40
  83. package/src/javascript/events/reconcile.js +0 -61
  84. package/src/javascript/video/display.js +0 -4
  85. package/src/native/controller.cpp +0 -192
  86. package/src/native/controller.h +0 -26
@@ -1,49 +1,78 @@
1
1
  #include "audio.h"
2
- #include "global.h"
3
- #include <SDL.h>
2
+ #include <SDL3/SDL.h>
4
3
  #include <string>
5
4
  #include <sstream>
6
5
 
7
-
8
6
  std::map<bool, std::string> audio::device_types;
7
+ std::map<SDL_AudioFormat, std::string> audio::formats;
9
8
 
9
+ static std::map<SDL_AudioDeviceID, SDL_AudioStream *> open_streams;
10
10
 
11
- Napi::Array
12
- audio::_getDevices(Napi::Env &env, bool is_capture)
11
+ static SDL_AudioStream *
12
+ _getStream (Napi::Env &env, SDL_AudioDeviceID audio_id)
13
13
  {
14
- int num_devices = SDL_GetNumAudioDevices(is_capture ? 1 : 0);
15
- if (num_devices == -1) {
16
- // SDL_GetNumAudioDevices can return -1 even if there is no error
17
- const char *error = SDL_GetError();
18
- if (error != global::no_error) {
19
- std::ostringstream message;
20
- message << "SDL_GetNumAudioDevices(" << is_capture << ") error: " << error;
21
- SDL_ClearError();
22
- throw Napi::Error::New(env, message.str());
23
- }
24
- return Napi::Array::New(env);
14
+ auto entry = open_streams.find(audio_id);
15
+ if (entry == open_streams.end()) {
16
+ std::ostringstream message;
17
+ message << "getAudioStream(" << audio_id << ") error: invalid audio stream id";
18
+ throw Napi::Error::New(env, message.str());
25
19
  }
20
+ return entry->second;
21
+ }
26
22
 
27
- Napi::Array devices = Napi::Array::New(env, num_devices);
28
23
 
29
- std::string device_type = audio::device_types[is_capture];
24
+ static Napi::Value
25
+ _packDevice (Napi::Env &env, SDL_AudioDeviceID id)
26
+ {
27
+ const char *name = SDL_GetAudioDeviceName(id);
28
+ if (name == nullptr) {
29
+ SDL_ClearError();
30
+ return env.Null();
31
+ }
30
32
 
31
- for (int i = 0; i < num_devices; i++) {
32
- const char *name = SDL_GetAudioDeviceName(i, is_capture);
33
- if (name == nullptr) {
34
- std::ostringstream message;
35
- message << "SDL_GetAudioDeviceName(" << i << ", " << is_capture << ") error: " << SDL_GetError();
36
- SDL_ClearError();
37
- throw Napi::Error::New(env, message.str());
38
- }
33
+ Napi::Object device = Napi::Object::New(env);
34
+ device.Set("id", id);
35
+ device.Set("name", name);
39
36
 
40
- Napi::Object device = Napi::Object::New(env);
41
- device.Set("name", name);
42
- device.Set("type", device_type);
37
+ return device;
38
+ }
43
39
 
44
- devices.Set(i, device);
40
+ Napi::Value
41
+ audio::_getDevice(Napi::Env &env, SDL_AudioDeviceID id)
42
+ {
43
+ return _packDevice(env, id);
44
+ }
45
+
46
+ Napi::Array
47
+ audio::_getDevices(Napi::Env &env, bool is_recording)
48
+ {
49
+ int num_devices;
50
+ SDL_AudioDeviceID *device_ids = is_recording
51
+ ? SDL_GetAudioRecordingDevices(&num_devices)
52
+ : SDL_GetAudioPlaybackDevices(&num_devices);
53
+ if (device_ids == nullptr) {
54
+ std::ostringstream message;
55
+ message << "SDL_GetAudio" << (is_recording ? "Recording" : "Playback") << "Devices() error: " << SDL_GetError();
56
+ SDL_ClearError();
57
+ throw Napi::Error::New(env, message.str());
45
58
  }
46
59
 
60
+ Napi::Array devices = Napi::Array::New(env);
61
+
62
+ try {
63
+ int num_returned = 0;
64
+ for (int i = 0; i < num_devices; i++) {
65
+ Napi::Value device = _packDevice(env, device_ids[i]);
66
+ if (device.IsNull()) { continue; }
67
+ devices.Set(num_returned++, device);
68
+ }
69
+ }
70
+ catch (...) {
71
+ SDL_free(device_ids);
72
+ throw;
73
+ }
74
+ SDL_free(device_ids);
75
+
47
76
  return devices;
48
77
  }
49
78
 
@@ -53,45 +82,91 @@ audio::getDevices(const Napi::CallbackInfo &info)
53
82
  {
54
83
  Napi::Env env = info.Env();
55
84
 
56
- bool is_capture = info[0].As<Napi::Boolean>().Value();
85
+ bool is_recording = info[0].As<Napi::Boolean>().Value();
57
86
 
58
- return audio::_getDevices(env, is_capture);
87
+ return audio::_getDevices(env, is_recording);
59
88
  }
60
89
 
61
- #include <iostream>
62
-
63
90
  Napi::Value
64
91
  audio::open (const Napi::CallbackInfo &info)
65
92
  {
66
93
  Napi::Env env = info.Env();
67
94
 
68
- std::string name;
69
- bool has_name = !info[0].IsNull();
70
- if (has_name) { name = info[0].As<Napi::String>().Utf8Value(); }
71
- bool is_capture = info[1].As<Napi::Boolean>().Value();
95
+ bool has_id = !info[0].IsNull();
96
+ bool is_recording = info[1].As<Napi::Boolean>().Value();
72
97
  int freq = info[2].As<Napi::Number>().Int32Value();
73
98
  int format = info[3].As<Napi::Number>().Int32Value();
74
99
  int channels = info[4].As<Napi::Number>().Int32Value();
75
100
  int samples = info[5].As<Napi::Number>().Int32Value();
76
101
 
102
+ SDL_AudioDeviceID device_id = has_id
103
+ ? info[0].As<Napi::Number>().Uint32Value()
104
+ : is_recording
105
+ ? SDL_AUDIO_DEVICE_DEFAULT_RECORDING
106
+ : SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK;
107
+
77
108
  SDL_AudioSpec desired;
78
109
  SDL_memset(&desired, 0, sizeof(desired));
79
110
  desired.freq = freq;
80
- desired.format = format;
111
+ desired.format = (SDL_AudioFormat) format;
81
112
  desired.channels = channels;
82
- desired.samples = samples;
83
113
 
84
- SDL_AudioDeviceID audio_id = SDL_OpenAudioDevice(has_name ? name.c_str() : nullptr, is_capture ? 1 : 0, &desired, nullptr, 0);
114
+ std::string samples_string = std::to_string(samples);
115
+ SDL_SetHint(SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES, samples_string.c_str());
116
+
117
+ SDL_AudioStream *stream = SDL_OpenAudioDeviceStream(device_id, &desired, nullptr, nullptr);
118
+ SDL_ResetHint(SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES);
119
+ if (stream == nullptr) {
120
+ std::ostringstream message;
121
+ message << "SDL_OpenAudioDeviceStream() error: " << SDL_GetError();
122
+ SDL_ClearError();
123
+ throw Napi::Error::New(env, message.str());
124
+ }
125
+
126
+ SDL_AudioDeviceID audio_id = SDL_GetAudioStreamDevice(stream);
85
127
  if (audio_id == 0) {
86
128
  std::ostringstream message;
87
- message << "SDL_OpenAudioDevice() error: " << SDL_GetError();
129
+ message << "SDL_GetAudioStreamDevice() error: " << SDL_GetError();
88
130
  SDL_ClearError();
131
+ SDL_DestroyAudioStream(stream);
89
132
  throw Napi::Error::New(env, message.str());
90
133
  }
91
134
 
135
+ open_streams[audio_id] = stream;
136
+
92
137
  return Napi::Number::New(env, audio_id);
93
138
  }
94
139
 
140
+ Napi::Value
141
+ audio::getDeviceFormat (const Napi::CallbackInfo &info)
142
+ {
143
+ Napi::Env env = info.Env();
144
+
145
+ int audio_id = info[0].As<Napi::Number>().Int32Value();
146
+
147
+ SDL_AudioSpec spec;
148
+ int sample_frames;
149
+ if (!SDL_GetAudioDeviceFormat(audio_id, &spec, &sample_frames)) {
150
+ std::ostringstream message;
151
+ message << "SDL_GetAudioDeviceFormat(" << audio_id << ") error: " << SDL_GetError();
152
+ SDL_ClearError();
153
+ throw Napi::Error::New(env, message.str());
154
+ }
155
+
156
+ auto format_entry = audio::formats.find(spec.format);
157
+ Napi::Value format = format_entry != audio::formats.end()
158
+ ? Napi::String::New(env, format_entry->second)
159
+ : env.Null();
160
+
161
+ Napi::Object result = Napi::Object::New(env);
162
+ result.Set("format", format);
163
+ result.Set("channels", spec.channels);
164
+ result.Set("frequency", spec.freq);
165
+ result.Set("buffered", sample_frames);
166
+
167
+ return result;
168
+ }
169
+
95
170
  Napi::Value
96
171
  audio::play (const Napi::CallbackInfo &info)
97
172
  {
@@ -100,37 +175,82 @@ audio::play (const Napi::CallbackInfo &info)
100
175
  int audio_id = info[0].As<Napi::Number>().Int32Value();
101
176
  bool should_play = info[1].As<Napi::Boolean>().Value();
102
177
 
103
- SDL_PauseAudioDevice(audio_id, should_play ? 0 : 1);
178
+ SDL_AudioStream *stream = _getStream(env, audio_id);
179
+
180
+ bool success = should_play
181
+ ? SDL_ResumeAudioStreamDevice(stream)
182
+ : SDL_PauseAudioStreamDevice(stream);
183
+ if (!success) {
184
+ std::ostringstream message;
185
+ message << (should_play ? "SDL_ResumeAudioStreamDevice(" : "SDL_PauseAudioStreamDevice(") << audio_id << ") error: " << SDL_GetError();
186
+ SDL_ClearError();
187
+ throw Napi::Error::New(env, message.str());
188
+ }
104
189
 
105
190
  return env.Undefined();
106
191
  }
107
192
 
108
193
  Napi::Value
109
- audio::getQueueSize (const Napi::CallbackInfo &info)
194
+ audio::getQueued (const Napi::CallbackInfo &info)
110
195
  {
111
196
  Napi::Env env = info.Env();
112
197
 
113
198
  int audio_id = info[0].As<Napi::Number>().Int32Value();
114
199
 
115
- int size = SDL_GetQueuedAudioSize(audio_id);
200
+ SDL_AudioStream *stream = _getStream(env, audio_id);
201
+
202
+ int size = SDL_GetAudioStreamQueued(stream);
203
+ if (size == -1) {
204
+ std::ostringstream message;
205
+ message << "SDL_GetAudioStreamQueued(" << audio_id << ") error: " << SDL_GetError();
206
+ SDL_ClearError();
207
+ throw Napi::Error::New(env, message.str());
208
+ }
116
209
 
117
210
  return Napi::Number::New(env, size);
118
211
  }
119
212
 
120
213
  Napi::Value
121
- audio::clearQueue (const Napi::CallbackInfo &info)
214
+ audio::getAvailable (const Napi::CallbackInfo &info)
122
215
  {
123
216
  Napi::Env env = info.Env();
124
217
 
125
218
  int audio_id = info[0].As<Napi::Number>().Int32Value();
126
219
 
127
- SDL_ClearQueuedAudio(audio_id);
220
+ SDL_AudioStream *stream = _getStream(env, audio_id);
221
+
222
+ int size = SDL_GetAudioStreamAvailable(stream);
223
+ if (size == -1) {
224
+ std::ostringstream message;
225
+ message << "SDL_GetAudioStreamAvailable(" << audio_id << ") error: " << SDL_GetError();
226
+ SDL_ClearError();
227
+ throw Napi::Error::New(env, message.str());
228
+ }
229
+
230
+ return Napi::Number::New(env, size);
231
+ }
232
+
233
+ Napi::Value
234
+ audio::clear (const Napi::CallbackInfo &info)
235
+ {
236
+ Napi::Env env = info.Env();
237
+
238
+ int audio_id = info[0].As<Napi::Number>().Int32Value();
239
+
240
+ SDL_AudioStream *stream = _getStream(env, audio_id);
241
+
242
+ if (!SDL_ClearAudioStream(stream)) {
243
+ std::ostringstream message;
244
+ message << "SDL_ClearAudioStream(" << audio_id << ") error: " << SDL_GetError();
245
+ SDL_ClearError();
246
+ throw Napi::Error::New(env, message.str());
247
+ }
128
248
 
129
249
  return env.Undefined();
130
250
  }
131
251
 
132
252
  Napi::Value
133
- audio::enqueue (const Napi::CallbackInfo &info)
253
+ audio::putData (const Napi::CallbackInfo &info)
134
254
  {
135
255
  Napi::Env env = info.Env();
136
256
 
@@ -138,9 +258,11 @@ audio::enqueue (const Napi::CallbackInfo &info)
138
258
  void *src = info[1].As<Napi::Buffer<char>>().Data();
139
259
  int size = info[2].As<Napi::Number>().Int32Value();
140
260
 
141
- if (SDL_QueueAudio(audio_id, src, size) < 0) {
261
+ SDL_AudioStream *stream = _getStream(env, audio_id);
262
+
263
+ if (!SDL_PutAudioStreamData(stream, src, size)) {
142
264
  std::ostringstream message;
143
- message << "SDL_QueueAudio() error: " << SDL_GetError();
265
+ message << "SDL_PutAudioStreamData(" << audio_id << ") error: " << SDL_GetError();
144
266
  SDL_ClearError();
145
267
  throw Napi::Error::New(env, message.str());
146
268
  }
@@ -149,7 +271,7 @@ audio::enqueue (const Napi::CallbackInfo &info)
149
271
  }
150
272
 
151
273
  Napi::Value
152
- audio::dequeue (const Napi::CallbackInfo &info)
274
+ audio::getData (const Napi::CallbackInfo &info)
153
275
  {
154
276
  Napi::Env env = info.Env();
155
277
 
@@ -157,11 +279,12 @@ audio::dequeue (const Napi::CallbackInfo &info)
157
279
  void *dst = info[1].As<Napi::Buffer<char>>().Data();
158
280
  int size = info[2].As<Napi::Number>().Int32Value();
159
281
 
160
- int num = SDL_DequeueAudio(audio_id, dst, size);
161
- const char *error = SDL_GetError();
162
- if (error != global::no_error) {
282
+ SDL_AudioStream *stream = _getStream(env, audio_id);
283
+
284
+ int num = SDL_GetAudioStreamData(stream, dst, size);
285
+ if (num == -1) {
163
286
  std::ostringstream message;
164
- message << "SDL_DequeueAudio(" << audio_id << ") error: " << error;
287
+ message << "SDL_GetAudioStreamData(" << audio_id << ") error: " << SDL_GetError();
165
288
  SDL_ClearError();
166
289
  throw Napi::Error::New(env, message.str());
167
290
  }
@@ -176,9 +299,10 @@ audio::close (const Napi::CallbackInfo &info)
176
299
 
177
300
  int audio_id = info[0].As<Napi::Number>().Int32Value();
178
301
 
179
- SDL_PauseAudioDevice(audio_id, 1);
180
- SDL_ClearQueuedAudio(audio_id);
181
- SDL_CloseAudioDevice(audio_id);
302
+ SDL_AudioStream *stream = _getStream(env, audio_id);
303
+
304
+ SDL_DestroyAudioStream(stream);
305
+ open_streams.erase(audio_id);
182
306
 
183
307
  return env.Undefined();
184
308
  }
@@ -2,22 +2,27 @@
2
2
  #define _AUDIO_H_
3
3
 
4
4
  #include <napi.h>
5
+ #include <SDL3/SDL.h>
5
6
  #include <map>
6
7
  #include <string>
7
8
 
8
9
  namespace audio {
9
10
 
10
11
  extern std::map<bool, std::string> device_types;
12
+ extern std::map<SDL_AudioFormat, std::string> formats;
11
13
 
12
- Napi::Array _getDevices(Napi::Env &env, bool is_capture);
14
+ Napi::Value _getDevice(Napi::Env &env, SDL_AudioDeviceID id);
15
+ Napi::Array _getDevices(Napi::Env &env, bool is_recording);
13
16
 
14
17
  Napi::Value getDevices(const Napi::CallbackInfo &info);
15
18
  Napi::Value open(const Napi::CallbackInfo &info);
19
+ Napi::Value getDeviceFormat(const Napi::CallbackInfo &info);
16
20
  Napi::Value play(const Napi::CallbackInfo &info);
17
- Napi::Value getQueueSize(const Napi::CallbackInfo &info);
18
- Napi::Value enqueue(const Napi::CallbackInfo &info);
19
- Napi::Value dequeue(const Napi::CallbackInfo &info);
20
- Napi::Value clearQueue(const Napi::CallbackInfo &info);
21
+ Napi::Value getQueued(const Napi::CallbackInfo &info);
22
+ Napi::Value getAvailable(const Napi::CallbackInfo &info);
23
+ Napi::Value putData(const Napi::CallbackInfo &info);
24
+ Napi::Value getData(const Napi::CallbackInfo &info);
25
+ Napi::Value clear(const Napi::CallbackInfo &info);
21
26
  Napi::Value close(const Napi::CallbackInfo &info);
22
27
 
23
28
  }; // namespace audio
@@ -1,5 +1,5 @@
1
1
  #include "clipboard.h"
2
- #include <SDL.h>
2
+ #include <SDL3/SDL.h>
3
3
  #include <string>
4
4
  #include <sstream>
5
5
 
@@ -8,20 +8,37 @@ clipboard::getText (const Napi::CallbackInfo &info)
8
8
  {
9
9
  Napi::Env env = info.Env();
10
10
 
11
- if (SDL_HasClipboardText() == SDL_FALSE) {
11
+ bool has_text = SDL_HasClipboardText();
12
+
13
+ // Clear any stale error, since an empty result is otherwise ambiguous
14
+ SDL_ClearError();
15
+
16
+ if (!has_text) {
12
17
  return Napi::String::New(env, "");
13
18
  }
14
19
 
15
20
  char *text = SDL_GetClipboardText();
16
21
  if (text[0] == '\0') {
17
22
  SDL_free(text);
23
+
24
+ // The clipboard may have been legitimately emptied since the check above
25
+ const char *error = SDL_GetError();
26
+ if (error[0] == '\0') {
27
+ return Napi::String::New(env, "");
28
+ }
29
+
18
30
  std::ostringstream message;
19
- message << "SDL_GetClipboardText() error: " << SDL_GetError();
31
+ message << "SDL_GetClipboardText() error: " << error;
20
32
  SDL_ClearError();
21
33
  throw Napi::Error::New(env, message.str());
22
34
  }
23
35
 
24
- Napi::String result = Napi::String::New(env, text);
36
+ Napi::String result;
37
+ try { result = Napi::String::New(env, text); }
38
+ catch (...) {
39
+ SDL_free(text);
40
+ throw;
41
+ }
25
42
  SDL_free(text);
26
43
 
27
44
  return result;
@@ -34,7 +51,7 @@ clipboard::setText (const Napi::CallbackInfo &info)
34
51
 
35
52
  std::string text = info[0].As<Napi::String>().Utf8Value();
36
53
 
37
- if (SDL_SetClipboardText(text.c_str()) < 0) {
54
+ if (!SDL_SetClipboardText(text.c_str())) {
38
55
  std::ostringstream message;
39
56
  message << "SDL_SetClipboardText() error: " << SDL_GetError();
40
57
  SDL_ClearError();
@@ -3,6 +3,7 @@
3
3
 
4
4
 
5
5
  #ifndef __OBJC__
6
+ class NSWindow;
6
7
  class NSView;
7
8
  class CALayer;
8
9
  #endif
@@ -22,8 +22,8 @@ extern "C" CALayer *getCocoaGlView(NSWindow *window) {
22
22
  extern "C" CALayer *getCocoaGpuView(NSWindow *window) {
23
23
  @autoreleasepool {
24
24
  NSView *view = [window contentView];
25
- [view setWantsLayer:YES];
26
25
  [view setLayer:[CAMetalLayer layer]];
26
+ [view setWantsLayer:YES];
27
27
  [[view layer] setContentsScale:[window backingScaleFactor]];
28
28
  return [view layer];
29
29
  }