@blotch/angular-lynx-native 22.2.7 → 22.2.9

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.
@@ -0,0 +1,220 @@
1
+ package dev.angularlynx.shell
2
+
3
+ import android.content.Context
4
+ import android.graphics.Bitmap
5
+ import android.graphics.BitmapFactory
6
+ import com.lynx.jsbridge.LynxMethod
7
+ import com.lynx.jsbridge.LynxModule
8
+ import com.lynx.react.bridge.JavaOnlyArray
9
+ import com.lynx.react.bridge.JavaOnlyMap
10
+ import com.lynx.react.bridge.ReadableArray
11
+ import com.lynx.react.bridge.ReadableMap
12
+ import com.lynx.react.bridge.ReadableType
13
+ import java.lang.ref.WeakReference
14
+ import java.nio.ByteBuffer
15
+ import java.nio.ByteOrder
16
+
17
+ /**
18
+ * `<canvas>` with WebGL2 for the AngularLynx runtime: the `AngularLynxWebGL`
19
+ * module the runtime's WebGL2RenderingContext sends its GL calls to. Each
20
+ * context (WebGLContext) runs them on OpenGL ES 3.0 and shows its frames in
21
+ * a canvas element's view (CanvasUI).
22
+ *
23
+ * Lynx has no canvas, and runs Angular on its main thread, where WebGL's
24
+ * synchronous answers (a program's link status, a uniform's location) can
25
+ * only come from a main-thread module: MainActivity turns those on
26
+ * (`setEnableMTSModule`). The runtime batches the calls into one `run` per
27
+ * frame; see packages/runtime/src/lib/canvas/webgl-bridge.ts for the
28
+ * protocol. Lynx calls these methods on the UI thread, where GL runs.
29
+ */
30
+ class WebGLModule(context: Context, param: Any?) : LynxModule(context, param) {
31
+ private val contexts = HashMap<Int, WebGLContext>()
32
+
33
+ @LynxMethod
34
+ fun create(contextId: Int, canvasId: String, attributes: ReadableMap?): JavaOnlyMap {
35
+ contexts.remove(contextId)?.destroy()
36
+ return try {
37
+ val context = WebGLContext(canvasId, attributes)
38
+ contexts[contextId] = context
39
+ CanvasRegistry.setContext(canvasId, context)
40
+ JavaOnlyMap.from(mapOf("ok" to true))
41
+ } catch (error: RuntimeException) {
42
+ JavaOnlyMap.from(mapOf("ok" to false, "error" to (error.message ?: "OpenGL ES 3.0 is not available")))
43
+ }
44
+ }
45
+
46
+ @LynxMethod
47
+ fun run(contextId: Int, commands: ReadableArray?): JavaOnlyArray {
48
+ val context = contexts[contextId] ?: return JavaOnlyArray()
49
+ return context.run(commands ?: return JavaOnlyArray())
50
+ }
51
+
52
+ @LynxMethod
53
+ fun destroy(contextId: Int): Boolean {
54
+ val context = contexts.remove(contextId) ?: return true
55
+ CanvasRegistry.setContext(context.canvasId, null)
56
+ context.destroy()
57
+ return true
58
+ }
59
+
60
+ @LynxMethod
61
+ fun decodeImage(imageId: Int, bytes: ReadableArray?, options: ReadableMap?): JavaOnlyMap {
62
+ val image = bytes?.let { decode(bytesFromWords(it), options) }
63
+ ?: return JavaOnlyMap.from(mapOf("width" to 0, "height" to 0, "error" to "The data is not an image Android can decode"))
64
+ DecodedImages.put(imageId, image)
65
+ return JavaOnlyMap.from(mapOf("width" to image.width, "height" to image.height))
66
+ }
67
+
68
+ @LynxMethod
69
+ fun releaseImage(imageId: Int): Boolean {
70
+ DecodedImages.remove(imageId)
71
+ return true
72
+ }
73
+
74
+ override fun destroy() {
75
+ for (context in contexts.values) context.destroy()
76
+ contexts.clear()
77
+ super.destroy()
78
+ }
79
+
80
+ /**
81
+ * Decodes an image file to RGBA bytes, as createImageBitmap's options ask:
82
+ * `imageOrientation: 'flipY'` flips it, `premultiplyAlpha: 'premultiply'`
83
+ * premultiplies it (otherwise it's kept straight), and
84
+ * `resizeWidth`/`resizeHeight` scale it.
85
+ */
86
+ private fun decode(bytes: ByteBuffer, options: ReadableMap?): DecodedImage? {
87
+ val array = ByteArray(bytes.remaining()).also { bytes.get(it) }
88
+ val premultiply = options?.optString("premultiplyAlpha") == "premultiply"
89
+ val resizeWidth = options?.optInt("resizeWidth") ?: 0
90
+ val resizeHeight = options?.optInt("resizeHeight") ?: 0
91
+ val resize = resizeWidth > 0 || resizeHeight > 0
92
+ // Scaling draws, which Android only does on premultiplied bitmaps:
93
+ // those are divided back after.
94
+ val decodeOptions = BitmapFactory.Options().apply {
95
+ inPreferredConfig = Bitmap.Config.ARGB_8888
96
+ inPremultiplied = premultiply || resize
97
+ }
98
+ var bitmap = BitmapFactory.decodeByteArray(array, 0, array.size, decodeOptions) ?: return null
99
+ if (resize) {
100
+ val width = if (resizeWidth > 0) resizeWidth else maxOf(1, bitmap.width * resizeHeight / bitmap.height)
101
+ val height = if (resizeHeight > 0) resizeHeight else maxOf(1, bitmap.height * resizeWidth / bitmap.width)
102
+ bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true)
103
+ }
104
+ if (bitmap.config != Bitmap.Config.ARGB_8888) bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false)
105
+ val pixels = ByteBuffer.allocateDirect(bitmap.width * bitmap.height * 4).order(ByteOrder.nativeOrder())
106
+ // ARGB_8888 is R, G, B, A in memory: what GL_RGBA reads.
107
+ bitmap.copyPixelsToBuffer(pixels)
108
+ pixels.rewind()
109
+ if (resize && !premultiply) unpremultiply(pixels)
110
+ if (options?.optString("imageOrientation") == "flipY") flipRows(pixels, bitmap.width * 4, bitmap.height)
111
+ return DecodedImage(pixels, bitmap.width, bitmap.height, premultiply)
112
+ }
113
+
114
+ private fun ReadableMap.optString(key: String): String? =
115
+ if (hasKey(key) && getType(key) == ReadableType.String) getString(key) else null
116
+
117
+ private fun ReadableMap.optInt(key: String): Int =
118
+ if (hasKey(key) && getType(key) in NUMBER_TYPES) getDouble(key).toInt() else 0
119
+
120
+ companion object {
121
+ const val NAME = "AngularLynxWebGL"
122
+ }
123
+ }
124
+
125
+ internal val NUMBER_TYPES = setOf(ReadableType.Int, ReadableType.Long, ReadableType.Number)
126
+
127
+ /** Pixels the module decoded, which texture uploads read by id: RGBA, rows top to bottom. */
128
+ internal class DecodedImage(val pixels: ByteBuffer, val width: Int, val height: Int, val premultiplied: Boolean)
129
+
130
+ internal object DecodedImages {
131
+ private val images = HashMap<Int, DecodedImage>()
132
+ fun put(id: Int, image: DecodedImage) { images[id] = image }
133
+ fun get(id: Int): DecodedImage? = images[id]
134
+ fun remove(id: Int) { images.remove(id) }
135
+ }
136
+
137
+ /**
138
+ * Pairs canvases with contexts by canvas id: either can come first, as the
139
+ * runtime may make the context before Lynx has made the element's view.
140
+ */
141
+ internal object CanvasRegistry {
142
+ private val views = HashMap<String, WeakReference<CanvasUI>>()
143
+ private val contexts = HashMap<String, WeakReference<WebGLContext>>()
144
+
145
+ fun setView(canvasId: String, view: CanvasUI?) {
146
+ if (view == null) views.remove(canvasId) else views[canvasId] = WeakReference(view)
147
+ contexts[canvasId]?.get()?.attachView(view)
148
+ }
149
+
150
+ fun view(canvasId: String): CanvasUI? = views[canvasId]?.get()
151
+
152
+ fun setContext(canvasId: String, context: WebGLContext?) {
153
+ if (context == null) {
154
+ contexts.remove(canvasId)
155
+ } else {
156
+ contexts[canvasId] = WeakReference(context)
157
+ context.attachView(views[canvasId]?.get())
158
+ }
159
+ }
160
+
161
+ fun context(canvasId: String): WebGLContext? = contexts[canvasId]?.get()
162
+ }
163
+
164
+ /**
165
+ * The bytes the runtime sends as 32-bit words, with the byte count last (see
166
+ * toWords in webgl-bridge.ts). Android runs little-endian, so the words land
167
+ * in memory as the bytes were.
168
+ */
169
+ internal fun bytesFromWords(words: ReadableArray): ByteBuffer {
170
+ val count = words.size()
171
+ if (count == 0) return ByteBuffer.allocateDirect(0)
172
+ val byteLength = words.getDouble(count - 1).toLong().toInt()
173
+ val buffer = ByteBuffer.allocateDirect((count - 1) * 4).order(ByteOrder.LITTLE_ENDIAN)
174
+ for (i in 0 until count - 1) buffer.putInt(words.getDouble(i).toLong().toInt())
175
+ buffer.rewind()
176
+ buffer.limit(minOf(byteLength, (count - 1) * 4))
177
+ return buffer
178
+ }
179
+
180
+ /** Bytes as words for the trip back, the byte count last. */
181
+ internal fun wordsFromBytes(bytes: ByteBuffer, length: Int): JavaOnlyArray {
182
+ val words = JavaOnlyArray()
183
+ val source = bytes.duplicate().order(ByteOrder.LITTLE_ENDIAN)
184
+ source.rewind()
185
+ val wordCount = (length + 3) / 4
186
+ for (i in 0 until wordCount) {
187
+ var word = 0L
188
+ for (b in 0 until 4) {
189
+ val index = i * 4 + b
190
+ if (index < length) word = word or ((source.get(index).toLong() and 0xff) shl (8 * b))
191
+ }
192
+ words.pushDouble(word.toDouble())
193
+ }
194
+ words.pushInt(length)
195
+ return words
196
+ }
197
+
198
+ internal fun flipRows(pixels: ByteBuffer, stride: Int, height: Int) {
199
+ val top = ByteArray(stride)
200
+ val bottom = ByteArray(stride)
201
+ for (row in 0 until height / 2) {
202
+ val other = height - 1 - row
203
+ pixels.position(row * stride); pixels.get(top)
204
+ pixels.position(other * stride); pixels.get(bottom)
205
+ pixels.position(row * stride); pixels.put(bottom)
206
+ pixels.position(other * stride); pixels.put(top)
207
+ }
208
+ pixels.rewind()
209
+ }
210
+
211
+ internal fun unpremultiply(pixels: ByteBuffer) {
212
+ for (i in 0 until pixels.limit() step 4) {
213
+ val alpha = pixels.get(i + 3).toInt() and 0xff
214
+ if (alpha == 0 || alpha == 255) continue
215
+ for (c in 0 until 3) {
216
+ val value = pixels.get(i + c).toInt() and 0xff
217
+ pixels.put(i + c, minOf(255, (value * 255 + alpha / 2) / alpha).toByte())
218
+ }
219
+ }
220
+ }
@@ -0,0 +1,211 @@
1
+ // Generated from packages/runtime/src/lib/canvas/webgl-ops.ts by
2
+ // packages/native/scripts/webgl-ops.ts: run `npm run generate:webgl-ops -w
3
+ // packages/native` rather than editing it.
4
+
5
+ package dev.angularlynx.shell
6
+
7
+ /**
8
+ * The commands of the WebGL bridge, as `<canvas>`'s context in the runtime
9
+ * records them: below 200 they return nothing, from 200 each answers one
10
+ * query.
11
+ */
12
+ internal object WebGLOps {
13
+ const val ACTIVE_TEXTURE = 1
14
+ const val ATTACH_SHADER = 2
15
+ const val BIND_ATTRIB_LOCATION = 3
16
+ const val BIND_BUFFER = 4
17
+ const val BIND_BUFFER_BASE = 5
18
+ const val BIND_BUFFER_RANGE = 6
19
+ const val BIND_FRAMEBUFFER = 7
20
+ const val BIND_RENDERBUFFER = 8
21
+ const val BIND_SAMPLER = 9
22
+ const val BIND_TEXTURE = 10
23
+ const val BIND_TRANSFORM_FEEDBACK = 11
24
+ const val BIND_VERTEX_ARRAY = 12
25
+ const val BEGIN_QUERY = 13
26
+ const val BEGIN_TRANSFORM_FEEDBACK = 14
27
+ const val BLEND_COLOR = 15
28
+ const val BLEND_EQUATION = 16
29
+ const val BLEND_EQUATION_SEPARATE = 17
30
+ const val BLEND_FUNC = 18
31
+ const val BLEND_FUNC_SEPARATE = 19
32
+ const val BLIT_FRAMEBUFFER = 20
33
+ const val BUFFER_DATA = 21
34
+ const val BUFFER_SUB_DATA = 22
35
+ const val CLEAR = 23
36
+ const val CLEAR_BUFFERFV = 24
37
+ const val CLEAR_BUFFERIV = 25
38
+ const val CLEAR_BUFFERUIV = 26
39
+ const val CLEAR_BUFFERFI = 27
40
+ const val CLEAR_COLOR = 28
41
+ const val CLEAR_DEPTH = 29
42
+ const val CLEAR_STENCIL = 30
43
+ const val COLOR_MASK = 31
44
+ const val COMPILE_SHADER = 32
45
+ const val COMPRESSED_TEX_IMAGE2D = 33
46
+ const val COMPRESSED_TEX_IMAGE3D = 34
47
+ const val COMPRESSED_TEX_SUB_IMAGE2D = 35
48
+ const val COMPRESSED_TEX_SUB_IMAGE3D = 36
49
+ const val COPY_BUFFER_SUB_DATA = 37
50
+ const val COPY_TEX_IMAGE2D = 38
51
+ const val COPY_TEX_SUB_IMAGE2D = 39
52
+ const val COPY_TEX_SUB_IMAGE3D = 40
53
+ const val CREATE_BUFFER = 41
54
+ const val CREATE_FRAMEBUFFER = 42
55
+ const val CREATE_PROGRAM = 43
56
+ const val CREATE_QUERY = 44
57
+ const val CREATE_RENDERBUFFER = 45
58
+ const val CREATE_SAMPLER = 46
59
+ const val CREATE_SHADER = 47
60
+ const val CREATE_TEXTURE = 48
61
+ const val CREATE_TRANSFORM_FEEDBACK = 49
62
+ const val CREATE_VERTEX_ARRAY = 50
63
+ const val CULL_FACE = 51
64
+ const val DELETE_BUFFER = 52
65
+ const val DELETE_FRAMEBUFFER = 53
66
+ const val DELETE_PROGRAM = 54
67
+ const val DELETE_QUERY = 55
68
+ const val DELETE_RENDERBUFFER = 56
69
+ const val DELETE_SAMPLER = 57
70
+ const val DELETE_SHADER = 58
71
+ const val DELETE_SYNC = 59
72
+ const val DELETE_TEXTURE = 60
73
+ const val DELETE_TRANSFORM_FEEDBACK = 61
74
+ const val DELETE_VERTEX_ARRAY = 62
75
+ const val DEPTH_FUNC = 63
76
+ const val DEPTH_MASK = 64
77
+ const val DEPTH_RANGE = 65
78
+ const val DETACH_SHADER = 66
79
+ const val DISABLE = 67
80
+ const val DISABLE_VERTEX_ATTRIB_ARRAY = 68
81
+ const val DRAW_ARRAYS = 69
82
+ const val DRAW_ARRAYS_INSTANCED = 70
83
+ const val DRAW_BUFFERS = 71
84
+ const val DRAW_ELEMENTS = 72
85
+ const val DRAW_ELEMENTS_INSTANCED = 73
86
+ const val DRAW_RANGE_ELEMENTS = 74
87
+ const val ENABLE = 75
88
+ const val ENABLE_VERTEX_ATTRIB_ARRAY = 76
89
+ const val END_QUERY = 77
90
+ const val END_TRANSFORM_FEEDBACK = 78
91
+ const val FENCE_SYNC = 79
92
+ const val FINISH = 80
93
+ const val FLUSH = 81
94
+ const val FRAMEBUFFER_RENDERBUFFER = 82
95
+ const val FRAMEBUFFER_TEXTURE2D = 83
96
+ const val FRAMEBUFFER_TEXTURE_LAYER = 84
97
+ const val FRONT_FACE = 85
98
+ const val GENERATE_MIPMAP = 86
99
+ const val HINT = 87
100
+ const val INVALIDATE_FRAMEBUFFER = 88
101
+ const val INVALIDATE_SUB_FRAMEBUFFER = 89
102
+ const val LINE_WIDTH = 90
103
+ const val LINK_PROGRAM = 91
104
+ const val PAUSE_TRANSFORM_FEEDBACK = 92
105
+ const val PIXEL_STOREI = 93
106
+ const val POLYGON_OFFSET = 94
107
+ const val READ_BUFFER = 95
108
+ const val READ_PIXELS_TO_BUFFER = 96
109
+ const val RENDERBUFFER_STORAGE = 97
110
+ const val RENDERBUFFER_STORAGE_MULTISAMPLE = 98
111
+ const val RESUME_TRANSFORM_FEEDBACK = 99
112
+ const val SAMPLE_COVERAGE = 100
113
+ const val SAMPLER_PARAMETERF = 101
114
+ const val SAMPLER_PARAMETERI = 102
115
+ const val SCISSOR = 103
116
+ const val SHADER_SOURCE = 104
117
+ const val STENCIL_FUNC = 105
118
+ const val STENCIL_FUNC_SEPARATE = 106
119
+ const val STENCIL_MASK = 107
120
+ const val STENCIL_MASK_SEPARATE = 108
121
+ const val STENCIL_OP = 109
122
+ const val STENCIL_OP_SEPARATE = 110
123
+ const val TEX_IMAGE2D = 111
124
+ const val TEX_IMAGE3D = 112
125
+ const val TEX_PARAMETERF = 113
126
+ const val TEX_PARAMETERI = 114
127
+ const val TEX_STORAGE2D = 115
128
+ const val TEX_STORAGE3D = 116
129
+ const val TEX_SUB_IMAGE2D = 117
130
+ const val TEX_SUB_IMAGE3D = 118
131
+ const val TRANSFORM_FEEDBACK_VARYINGS = 119
132
+ const val UNIFORM1F = 120
133
+ const val UNIFORM2F = 121
134
+ const val UNIFORM3F = 122
135
+ const val UNIFORM4F = 123
136
+ const val UNIFORM1I = 124
137
+ const val UNIFORM2I = 125
138
+ const val UNIFORM3I = 126
139
+ const val UNIFORM4I = 127
140
+ const val UNIFORM1UI = 128
141
+ const val UNIFORM2UI = 129
142
+ const val UNIFORM3UI = 130
143
+ const val UNIFORM4UI = 131
144
+ const val UNIFORM1FV = 132
145
+ const val UNIFORM2FV = 133
146
+ const val UNIFORM3FV = 134
147
+ const val UNIFORM4FV = 135
148
+ const val UNIFORM1IV = 136
149
+ const val UNIFORM2IV = 137
150
+ const val UNIFORM3IV = 138
151
+ const val UNIFORM4IV = 139
152
+ const val UNIFORM1UIV = 140
153
+ const val UNIFORM2UIV = 141
154
+ const val UNIFORM3UIV = 142
155
+ const val UNIFORM4UIV = 143
156
+ const val UNIFORM_MATRIX2FV = 144
157
+ const val UNIFORM_MATRIX3FV = 145
158
+ const val UNIFORM_MATRIX4FV = 146
159
+ const val UNIFORM_MATRIX2X3FV = 147
160
+ const val UNIFORM_MATRIX3X2FV = 148
161
+ const val UNIFORM_MATRIX2X4FV = 149
162
+ const val UNIFORM_MATRIX4X2FV = 150
163
+ const val UNIFORM_MATRIX3X4FV = 151
164
+ const val UNIFORM_MATRIX4X3FV = 152
165
+ const val UNIFORM_BLOCK_BINDING = 153
166
+ const val USE_PROGRAM = 154
167
+ const val VALIDATE_PROGRAM = 155
168
+ const val VERTEX_ATTRIB4F = 156
169
+ const val VERTEX_ATTRIB_I4I = 157
170
+ const val VERTEX_ATTRIB_I4UI = 158
171
+ const val VERTEX_ATTRIB_DIVISOR = 159
172
+ const val VERTEX_ATTRIB_IPOINTER = 160
173
+ const val VERTEX_ATTRIB_POINTER = 161
174
+ const val VIEWPORT = 162
175
+ const val WAIT_SYNC = 163
176
+ const val RESIZE = 164
177
+ const val PRESENT = 165
178
+ const val GET_PARAMETER = 200
179
+ const val GET_ERROR = 201
180
+ const val SHADER_INFO = 202
181
+ const val PROGRAM_INFO = 203
182
+ const val GET_UNIFORM_LOCATION = 204
183
+ const val GET_ATTRIB_LOCATION = 205
184
+ const val CHECK_FRAMEBUFFER_STATUS = 206
185
+ const val GET_BUFFER_PARAMETER = 207
186
+ const val GET_FRAMEBUFFER_ATTACHMENT_PARAMETER = 208
187
+ const val GET_RENDERBUFFER_PARAMETER = 209
188
+ const val GET_TEX_PARAMETER = 210
189
+ const val GET_SAMPLER_PARAMETER = 211
190
+ const val GET_VERTEX_ATTRIB = 212
191
+ const val GET_VERTEX_ATTRIB_OFFSET = 213
192
+ const val GET_INDEXED_PARAMETER = 214
193
+ const val GET_INTERNALFORMAT_PARAMETER = 215
194
+ const val GET_QUERY_PARAMETER = 216
195
+ const val GET_SYNC_PARAMETER = 217
196
+ const val CLIENT_WAIT_SYNC = 218
197
+ const val GET_UNIFORM = 219
198
+ const val GET_UNIFORM_BLOCK_INDEX = 220
199
+ const val GET_ACTIVE_UNIFORM_BLOCK_NAME = 221
200
+ const val GET_ACTIVE_UNIFORM_BLOCK_PARAMETER = 222
201
+ const val GET_ACTIVE_UNIFORMS = 223
202
+ const val GET_UNIFORM_INDICES = 224
203
+ const val GET_FRAG_DATA_LOCATION = 225
204
+ const val GET_TRANSFORM_FEEDBACK_VARYING = 226
205
+ const val READ_PIXELS = 227
206
+ const val GET_BUFFER_SUB_DATA = 228
207
+ const val IS_ENABLED = 229
208
+ const val GET_SHADER_PRECISION_FORMAT = 230
209
+ const val GET_SUPPORTED_EXTENSIONS = 231
210
+ const val GET_PROGRAM_PARAMETER = 232
211
+ }
@@ -0,0 +1,80 @@
1
+ // `<canvas>` with WebGL2 for the AngularLynx runtime: the `canvas` element
2
+ // (AngularLynxCanvas), the `AngularLynxWebGL` main-thread module the runtime's
3
+ // WebGL2RenderingContext sends its GL calls to (AngularLynxWebGLModule), and
4
+ // the OpenGL ES 3.0 context that runs them (AngularLynxWebGLContext).
5
+ //
6
+ // Lynx has no canvas, and runs Angular on its main thread, where WebGL's
7
+ // synchronous answers (a program's link status, a uniform's location) can
8
+ // only come from a main-thread module: LynxViewController turns those on
9
+ // (`enableMTSModule`). The runtime batches the calls into one `run` per frame;
10
+ // see packages/runtime/src/lib/canvas/webgl-bridge.ts for the protocol.
11
+ //
12
+ // OpenGL ES is deprecated on iOS but still in the SDK, and its shading
13
+ // language, GLSL ES 3.00, is WebGL2's, so three.js's shaders compile as they
14
+ // are. GLES_SILENCE_DEPRECATION keeps each GL call from warning.
15
+
16
+ #define GLES_SILENCE_DEPRECATION 1
17
+
18
+ #import <Foundation/Foundation.h>
19
+ #import <Lynx/LynxModule.h>
20
+ #import <Lynx/LynxUI.h>
21
+ #import <OpenGLES/EAGL.h>
22
+ #import <UIKit/UIKit.h>
23
+
24
+ NS_ASSUME_NONNULL_BEGIN
25
+
26
+ @class AngularLynxCanvasView;
27
+
28
+ /// The drawing surface: a view backed by a CAEAGLLayer, which the context
29
+ /// copies each finished frame into.
30
+ @interface AngularLynxCanvasView : UIView
31
+ @property(nonatomic, copy, nullable) NSString *canvasId;
32
+ @end
33
+
34
+ /// The `canvas` element. Its `canvas-id` attribute, which the runtime sets,
35
+ /// pairs it with the context the runtime made for it.
36
+ @interface AngularLynxCanvas : LynxUI <AngularLynxCanvasView *>
37
+ @end
38
+
39
+ /// Pixels the module decoded (`decodeImage`), which texture uploads read by
40
+ /// id. RGBA, 8 bits a channel, rows top to bottom.
41
+ @interface AngularLynxDecodedImage : NSObject
42
+ @property(nonatomic, readonly) NSData *pixels;
43
+ @property(nonatomic, readonly) NSInteger width;
44
+ @property(nonatomic, readonly) NSInteger height;
45
+ /// Whether the pixels are premultiplied by alpha.
46
+ @property(nonatomic, readonly) BOOL premultiplied;
47
+ + (nullable AngularLynxDecodedImage *)imageWithId:(NSInteger)imageId;
48
+ @end
49
+
50
+ /// One WebGL context: an EAGLContext with an offscreen default framebuffer
51
+ /// the size of the canvas's `width` and `height`.
52
+ @interface AngularLynxWebGLContext : NSObject
53
+ @property(nonatomic, readonly, copy) NSString *canvasId;
54
+ - (nullable instancetype)initWithCanvasId:(NSString *)canvasId
55
+ attributes:(NSDictionary *)attributes
56
+ error:(NSString *_Nullable *_Nonnull)error;
57
+ /// Runs the commands in order; returns one result per query.
58
+ - (NSArray *)run:(NSArray *)commands;
59
+ /// Shows frames in this view, or nowhere while it's nil.
60
+ - (void)attachView:(nullable AngularLynxCanvasView *)view;
61
+ /// The view's size changed: the next frame reallocates its layer's storage.
62
+ - (void)viewDidResize;
63
+ - (void)destroy;
64
+ @end
65
+
66
+ /// Pairs canvases with contexts by canvas id: either can come first, as the
67
+ /// runtime may make the context before Lynx has made the element's view.
68
+ @interface AngularLynxCanvasRegistry : NSObject
69
+ + (void)setView:(nullable AngularLynxCanvasView *)view forCanvasId:(NSString *)canvasId;
70
+ + (nullable AngularLynxCanvasView *)viewForCanvasId:(NSString *)canvasId;
71
+ + (void)setContext:(nullable AngularLynxWebGLContext *)context forCanvasId:(NSString *)canvasId;
72
+ + (nullable AngularLynxWebGLContext *)contextForCanvasId:(NSString *)canvasId;
73
+ @end
74
+
75
+ /// The `AngularLynxWebGL` module. Registered on the LynxView's config, and
76
+ /// called from the main thread.
77
+ @interface AngularLynxWebGLModule : NSObject <LynxModule>
78
+ @end
79
+
80
+ NS_ASSUME_NONNULL_END