@geastack/geatsc-plugin-gea 0.1.19 → 0.1.21-uart.1

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/dist/cpp-ir.js CHANGED
@@ -1260,6 +1260,143 @@ function changeRecordHelperSource() {
1260
1260
  "",
1261
1261
  ];
1262
1262
  }
1263
+ // `ctx.createImageData565(w, h)` / `ctx.putImageData(img, x, y)`: an app-owned
1264
+ // RGB565 pixel buffer (`img.data16`, plain RGB565 whatever the panel wants)
1265
+ // drawn with one blit. The buffer is registered with the image store once, so
1266
+ // `putImageData` is an ordinary `drawImage` of that slot. Where the target's
1267
+ // native pixel already IS plain RGB565 the store reads `data16`'s own memory
1268
+ // (no copy); otherwise (a byte-swapped panel, a 24/32-bit or grayscale
1269
+ // framebuffer) a native staging buffer owned by the store is filled from
1270
+ // `data16` on each put.
1271
+ //
1272
+ // These helpers sit in `gea_ir`, which is emitted BEFORE gea_runtime.h, where
1273
+ // `gea::TypedArray` is only a name. So the record is a class template whose
1274
+ // pixel member is dependent: nothing is instantiated -- and the type need not
1275
+ // be complete -- until generated code after the runtime include uses it.
1276
+ const imageData565InteropSource = [
1277
+ "} // namespace gea_ir",
1278
+ '#include "image.h"',
1279
+ '#include "memory.h"',
1280
+ "#include <memory>",
1281
+ "namespace gea {",
1282
+ "template <typename T> class TypedArray;",
1283
+ "template <typename T> struct Ref;",
1284
+ "template <typename T, typename... Arguments> inline Ref<T> makeRef(Arguments&&... arguments);",
1285
+ "} // namespace gea",
1286
+ "namespace gea_ir {",
1287
+ "",
1288
+ "template <typename D = void>",
1289
+ "struct ImageData565T {",
1290
+ " using array_type = gea::TypedArray<std::conditional_t<std::is_void_v<D>, std::uint16_t, std::uint16_t>>;",
1291
+ " using pixels_type = gea::Ref<array_type>;",
1292
+ " double width = 0;",
1293
+ " double height = 0;",
1294
+ " pixels_type data16;",
1295
+ " int id = -1;",
1296
+ " gea::framework::graphics::pixel::native_t *staging = nullptr;",
1297
+ "};",
1298
+ "using ImageData565 = ImageData565T<>;",
1299
+ "",
1300
+ "inline constexpr bool imageData565ZeroCopy =",
1301
+ " std::is_same_v<gea::framework::graphics::pixel::native_t, std::uint16_t> && !GEA_EMBEDDED_PIXEL_PANEL_ENDIAN;",
1302
+ "",
1303
+ "template <typename W, typename H>",
1304
+ "inline ImageData565T<std::conditional_t<true, void, W>> canvasCreateImageData565(gea::embedded::ui::CanvasRenderingContext2D &, const W &w, const H &h) {",
1305
+ " ImageData565T<std::conditional_t<true, void, W>> out;",
1306
+ " const int width = canvasInt(w) > 0 ? canvasInt(w) : 0;",
1307
+ " const int height = canvasInt(h) > 0 ? canvasInt(h) : 0;",
1308
+ " out.width = width;",
1309
+ " out.height = height;",
1310
+ " using __gea_image_t = decltype(out);",
1311
+ " out.data16 = gea::makeRef<typename __gea_image_t::array_type>(static_cast<std::size_t>(width) * static_cast<std::size_t>(height));",
1312
+ " if (width == 0 || height == 0) return out;",
1313
+ " auto &store = gea::framework::graphics::ImageStore::instance();",
1314
+ " if constexpr (imageData565ZeroCopy) {",
1315
+ " out.id = store.registerBuffer(reinterpret_cast<gea::framework::graphics::pixel::native_t *>((*out.data16).data()), width, height);",
1316
+ " } else {",
1317
+ " const std::size_t count = static_cast<std::size_t>(width) * static_cast<std::size_t>(height);",
1318
+ " out.staging = static_cast<gea::framework::graphics::pixel::native_t *>(",
1319
+ " gea::framework::memory::Allocator::allocatePreferSpiram(count * sizeof(gea::framework::graphics::pixel::native_t), 128));",
1320
+ " if (out.staging) {",
1321
+ " for (std::size_t i = 0; i < count; ++i) out.staging[i] = gea::framework::graphics::pixel::toNative(0);",
1322
+ " out.id = store.registerBuffer(out.staging, width, height, -1, true);",
1323
+ " if (out.id < 0) {",
1324
+ " gea::framework::memory::Allocator::free(out.staging);",
1325
+ " out.staging = nullptr;",
1326
+ " }",
1327
+ " }",
1328
+ " }",
1329
+ " return out;",
1330
+ "}",
1331
+ "",
1332
+ "template <typename D, typename X, typename Y>",
1333
+ "inline void canvasPutImageData(gea::embedded::ui::CanvasRenderingContext2D &ctx, const ImageData565T<D> &image, const X &x, const Y &y) {",
1334
+ " if (image.id < 0) return;",
1335
+ " if constexpr (!imageData565ZeroCopy) {",
1336
+ " if (!image.staging) return;",
1337
+ " const std::uint16_t *src = (*image.data16).data();",
1338
+ " const std::size_t count = (*image.data16).size();",
1339
+ " gea::framework::graphics::pixel::native_t *dst = image.staging;",
1340
+ " // `toNative` is a format conversion only; the panel byte-swap of a 16-bit",
1341
+ " // framebuffer is `fromRgb565`'s.",
1342
+ " if constexpr (std::is_same_v<gea::framework::graphics::pixel::native_t, std::uint16_t>) {",
1343
+ " for (std::size_t i = 0; i < count; ++i) dst[i] = gea::framework::graphics::pixel::fromRgb565(src[i]);",
1344
+ " } else {",
1345
+ " for (std::size_t i = 0; i < count; ++i) dst[i] = gea::framework::graphics::pixel::toNative(src[i]);",
1346
+ " }",
1347
+ " }",
1348
+ " ctx.putImage(image.id, canvasInt(x), canvasInt(y));",
1349
+ "}",
1350
+ "",
1351
+ "// `putImageData(image, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight)`: only",
1352
+ "// the dirty rectangle of the image is drawn, at (dx + dirtyX, dy + dirtyY),",
1353
+ "// after the HTML spec's normalisation (negative sizes flip, then clamp).",
1354
+ "template <typename D, typename X, typename Y, typename RX, typename RY, typename RW, typename RH>",
1355
+ "inline void canvasPutImageData(gea::embedded::ui::CanvasRenderingContext2D &ctx, const ImageData565T<D> &image, const X &x, const Y &y,",
1356
+ " const RX &dirtyX, const RY &dirtyY, const RW &dirtyWidth, const RH &dirtyHeight) {",
1357
+ " const int width = static_cast<int>(image.width);",
1358
+ " const int height = static_cast<int>(image.height);",
1359
+ " if (width <= 0 || height <= 0 || image.id < 0) return;",
1360
+ " int rx = canvasInt(dirtyX);",
1361
+ " int ry = canvasInt(dirtyY);",
1362
+ " int rw = canvasInt(dirtyWidth);",
1363
+ " int rh = canvasInt(dirtyHeight);",
1364
+ " if (rw < 0) { rx += rw; rw = -rw; }",
1365
+ " if (rh < 0) { ry += rh; rh = -rh; }",
1366
+ " if (rx < 0) { rw += rx; rx = 0; }",
1367
+ " if (ry < 0) { rh += ry; ry = 0; }",
1368
+ " if (rx + rw > width) rw = width - rx;",
1369
+ " if (ry + rh > height) rh = height - ry;",
1370
+ " if (rw <= 0 || rh <= 0) return;",
1371
+ " if (rx == 0 && ry == 0 && rw == width && rh == height) {",
1372
+ " canvasPutImageData(ctx, image, x, y);",
1373
+ " return;",
1374
+ " }",
1375
+ " // Only the rectangle is converted, in place in the staging copy, and its",
1376
+ " // rows are drawn straight out of it: each row is contiguous, so no scratch",
1377
+ " // buffer is needed and several puts in one frame stay independent.",
1378
+ " const gea::framework::graphics::pixel::native_t *rows = nullptr;",
1379
+ " if constexpr (imageData565ZeroCopy) {",
1380
+ " rows = reinterpret_cast<const gea::framework::graphics::pixel::native_t *>((*image.data16).data());",
1381
+ " } else {",
1382
+ " if (!image.staging) return;",
1383
+ " const std::uint16_t *src = (*image.data16).data();",
1384
+ " for (int row = ry; row < ry + rh; ++row) {",
1385
+ " const std::size_t start = static_cast<std::size_t>(row) * static_cast<std::size_t>(width) + static_cast<std::size_t>(rx);",
1386
+ " gea::framework::graphics::pixel::native_t *dst = image.staging + start;",
1387
+ " if constexpr (std::is_same_v<gea::framework::graphics::pixel::native_t, std::uint16_t>) {",
1388
+ " for (int i = 0; i < rw; ++i) dst[i] = gea::framework::graphics::pixel::fromRgb565(src[start + i]);",
1389
+ " } else {",
1390
+ " for (int i = 0; i < rw; ++i) dst[i] = gea::framework::graphics::pixel::toNative(src[start + i]);",
1391
+ " }",
1392
+ " }",
1393
+ " rows = image.staging;",
1394
+ " }",
1395
+ " rows += static_cast<std::size_t>(ry) * static_cast<std::size_t>(width) + static_cast<std::size_t>(rx);",
1396
+ " ctx.drawPixelRows(rows, width, rw, rh, canvasInt(x) + rx, canvasInt(y) + ry);",
1397
+ "}",
1398
+ "",
1399
+ ];
1263
1400
  export function directCanvasInteropSource(usesCanvas, options = {}) {
1264
1401
  if (!usesCanvas)
1265
1402
  return [];
@@ -1511,12 +1648,12 @@ export function directCanvasInteropSource(usesCanvas, options = {}) {
1511
1648
  "}",
1512
1649
  "",
1513
1650
  "template <typename Image, typename X, typename Y>",
1514
- "inline void canvasDrawImage(gea::embedded::ui::CanvasRenderingContext2D ctx, const Image &image, const X &x, const Y &y) {",
1651
+ "inline void canvasDrawImage(gea::embedded::ui::CanvasRenderingContext2D &ctx, const Image &image, const X &x, const Y &y) {",
1515
1652
  " ctx.drawImage(canvasImageId(image), canvasInt(x), canvasInt(y));",
1516
1653
  "}",
1517
1654
  "",
1518
1655
  "template <typename Image, typename X, typename Y, typename W, typename H>",
1519
- "inline void canvasDrawImage(gea::embedded::ui::CanvasRenderingContext2D ctx, const Image &image, const X &x, const Y &y, const W &w, const H &h) {",
1656
+ "inline void canvasDrawImage(gea::embedded::ui::CanvasRenderingContext2D &ctx, const Image &image, const X &x, const Y &y, const W &w, const H &h) {",
1520
1657
  " ctx.drawImage(canvasImageId(image), canvasInt(x), canvasInt(y), canvasInt(w), canvasInt(h));",
1521
1658
  "}",
1522
1659
  "",
@@ -1545,6 +1682,7 @@ export function directCanvasInteropSource(usesCanvas, options = {}) {
1545
1682
  " ctx.drawImageTiledX(canvasImageId(image), canvasInt(x), canvasInt(y), canvasInt(w));",
1546
1683
  "}",
1547
1684
  "",
1685
+ ...imageData565InteropSource,
1548
1686
  "inline void canvasFlush(gea::embedded::ui::CanvasRenderingContext2D &ctx) {",
1549
1687
  " ctx.flush();",
1550
1688
  "}",
@@ -2256,12 +2394,12 @@ function canvasInteropSource(usesCanvas, directCanvas) {
2256
2394
  "}",
2257
2395
  "",
2258
2396
  "template <typename Image, typename X, typename Y>",
2259
- "inline void canvasDrawImage(gea::embedded::ui::CanvasRenderingContext2D ctx, const Image &image, const X &x, const Y &y) {",
2397
+ "inline void canvasDrawImage(gea::embedded::ui::CanvasRenderingContext2D &ctx, const Image &image, const X &x, const Y &y) {",
2260
2398
  " ctx.drawImage(canvasImageId(image), canvasInt(x), canvasInt(y));",
2261
2399
  "}",
2262
2400
  "",
2263
2401
  "template <typename Image, typename X, typename Y, typename W, typename H>",
2264
- "inline void canvasDrawImage(gea::embedded::ui::CanvasRenderingContext2D ctx, const Image &image, const X &x, const Y &y, const W &w, const H &h) {",
2402
+ "inline void canvasDrawImage(gea::embedded::ui::CanvasRenderingContext2D &ctx, const Image &image, const X &x, const Y &y, const W &w, const H &h) {",
2265
2403
  " ctx.drawImage(canvasImageId(image), canvasInt(x), canvasInt(y), canvasInt(w), canvasInt(h));",
2266
2404
  "}",
2267
2405
  "",
@@ -2290,6 +2428,7 @@ function canvasInteropSource(usesCanvas, directCanvas) {
2290
2428
  " ctx.drawImageTiledX(canvasImageId(image), canvasInt(x), canvasInt(y), canvasInt(w));",
2291
2429
  "}",
2292
2430
  "",
2431
+ ...imageData565InteropSource,
2293
2432
  "inline void canvasFlush(gea::embedded::ui::CanvasRenderingContext2D &ctx) {",
2294
2433
  " ctx.flush();",
2295
2434
  "}",
@@ -60,6 +60,7 @@ const geaGeolocationHostMethods = [
60
60
  'clearWatch',
61
61
  ];
62
62
  const geaInputHostMethods = ['consumeBackButton'];
63
+ const geaUartHostMethods = ['open', 'isOpen', 'close', 'read', 'write', 'available', 'writable'];
63
64
  const geaGpioHostMethods = ['configureOutput', 'configureInput', 'write', 'read'];
64
65
  const geaLedHostMethods = ['set', 'off', 'attach', 'setPixel', 'show', 'detach'];
65
66
  const geaClockHostMethods = ['epochMs'];
@@ -138,6 +139,7 @@ const rawGeaHostExternDeclarations = Object.fromEntries([
138
139
  ...geaTouchHostMethods.map((method) => [`gea::host::touch.${method}`, geaHostDeclarations]),
139
140
  ...geaMemoryHostMethods.map((method) => [`gea::host::Memory.${method}`, geaHostDeclarations]),
140
141
  ...geaInputHostMethods.map((method) => [`gea::host::Input.${method}`, geaHostDeclarations]),
142
+ ...geaUartHostMethods.map((method) => [`gea::host::Uart.${method}`, geaHostDeclarations]),
141
143
  ...geaGpioHostMethods.map((method) => [`gea::host::Gpio.${method}`, geaHostDeclarations]),
142
144
  ...geaLedHostMethods.map((method) => [`gea::host::Led.${method}`, geaHostDeclarations]),
143
145
  ...geaClockHostMethods.map((method) => [`gea::host::Clock.${method}`, geaHostDeclarations]),
@@ -75,6 +75,8 @@ const IMAGE_RECEIVER_TYPES = [
75
75
  "GeaEmbeddedImage",
76
76
  "LoadedImage",
77
77
  ];
78
+ // Receiver type names for `gea_ir::ImageData565` (ctx.createImageData565).
79
+ const IMAGE_DATA_565_RECEIVER_TYPES = ["gea_ir::ImageData565", "ImageData565"];
78
80
  const DISPLAY_NO_THROW_METHODS = [
79
81
  "getBrightness",
80
82
  "setBrightness",
@@ -371,6 +373,10 @@ export function createGeaHostShims() {
371
373
  // images — including a `GeaEmbeddedImage[]` tile cache — flow as native
372
374
  // structs with no `gea_cpp_value` boxing. `canvasImageId` reads `.id`.
373
375
  GeaEmbeddedImage: "gea::host::GeaEmbeddedImage",
376
+ // `ctx.createImageData565(w, h)` yields this record (width, height, the
377
+ // `data16` Uint16Array, and the image-store slot it is drawn through);
378
+ // see `imageData565InteropSource` in cpp-ir.ts.
379
+ ImageData565: "gea_ir::ImageData565",
374
380
  // `touch.read()` yields this concrete {touching,x,y} struct. Without the
375
381
  // native mapping the binding boxes it to a gea_cpp_value whose fields the
376
382
  // host struct can't expose, so `sample.touching` reads nullish — the device
@@ -546,6 +552,7 @@ export function createGeaHostShims() {
546
552
  __gea_Display: "gea::host::Display",
547
553
  __gea_Memory: "gea::host::Memory",
548
554
  __gea_Input: "gea::host::Input",
555
+ __gea_Uart: "gea::host::Uart",
549
556
  __gea_Gpio: "gea::host::Gpio",
550
557
  __gea_Led: "gea::host::Led",
551
558
  __gea_Clock: "gea::host::Clock",
@@ -1262,6 +1269,15 @@ export function createGeaHostShims() {
1262
1269
  write: "gea::host::Gpio.write",
1263
1270
  read: "gea::host::Gpio.read",
1264
1271
  },
1272
+ __gea_Uart: {
1273
+ open: "gea::host::Uart.open",
1274
+ isOpen: "gea::host::Uart.isOpen",
1275
+ close: "gea::host::Uart.close",
1276
+ read: "gea::host::Uart.read",
1277
+ write: "gea::host::Uart.write",
1278
+ available: "gea::host::Uart.available",
1279
+ writable: "gea::host::Uart.writable",
1280
+ },
1265
1281
  __gea_Gpio: {
1266
1282
  configureOutput: "gea::host::Gpio.configureOutput",
1267
1283
  configureInput: "gea::host::Gpio.configureInput",
@@ -1337,6 +1353,7 @@ export function createGeaHostShims() {
1337
1353
  Input: ["consumeBackButton"],
1338
1354
  __gea_Input: ["consumeBackButton"],
1339
1355
  Gpio: ["configureOutput", "configureInput", "write", "read"],
1356
+ __gea_Uart: ["open", "isOpen", "close", "available", "writable"],
1340
1357
  __gea_Gpio: ["configureOutput", "configureInput", "write", "read"],
1341
1358
  Led: ["set", "off", "attach", "setPixel", "show", "detach"],
1342
1359
  __gea_Led: ["set", "off", "attach", "setPixel", "show", "detach"],
@@ -1822,6 +1839,11 @@ export function createGeaHostShims() {
1822
1839
  returnType: "double",
1823
1840
  receiverTypes: IMAGE_RECEIVER_TYPES,
1824
1841
  },
1842
+ {
1843
+ emit: "({receiver}).width",
1844
+ returnType: "double",
1845
+ receiverTypes: IMAGE_DATA_565_RECEIVER_TYPES,
1846
+ },
1825
1847
  ],
1826
1848
  height: [
1827
1849
  {
@@ -1829,6 +1851,18 @@ export function createGeaHostShims() {
1829
1851
  returnType: "double",
1830
1852
  receiverTypes: IMAGE_RECEIVER_TYPES,
1831
1853
  },
1854
+ {
1855
+ emit: "({receiver}).height",
1856
+ returnType: "double",
1857
+ receiverTypes: IMAGE_DATA_565_RECEIVER_TYPES,
1858
+ },
1859
+ ],
1860
+ data16: [
1861
+ {
1862
+ emit: "({receiver}).data16",
1863
+ returnType: "gea::Ref<gea::TypedArray<std::uint16_t>>",
1864
+ receiverTypes: IMAGE_DATA_565_RECEIVER_TYPES,
1865
+ },
1832
1866
  ],
1833
1867
  frameCount: [
1834
1868
  {
@@ -2294,6 +2328,8 @@ export function createGeaHostShims() {
2294
2328
  drawImageCircle: "gea_ir::canvasDrawImageCircle($receiver, $args)",
2295
2329
  drawImageRotated90CW: "gea_ir::canvasDrawImageRotated90CW($receiver, $args)",
2296
2330
  drawImageTiledX: "gea_ir::canvasDrawImageTiledX($receiver, $args)",
2331
+ createImageData565: "gea_ir::canvasCreateImageData565($receiver, $args)",
2332
+ putImageData: "gea_ir::canvasPutImageData($receiver, $args)",
2297
2333
  flush: "gea_ir::canvasFlush($receiver /*$args*/)",
2298
2334
  beginBatch: "gea_ir::canvasBeginBatch($receiver /*$args*/)",
2299
2335
  endBatch: "gea_ir::canvasEndBatch($receiver /*$args*/)",
@@ -2309,6 +2345,7 @@ export function createGeaHostShims() {
2309
2345
  "fillCirclesRgb565",
2310
2346
  "fillCirclesRgb565Uniform",
2311
2347
  "fillTrianglesRgb565Sorted",
2348
+ "putImageData",
2312
2349
  "beginPath",
2313
2350
  "arc",
2314
2351
  "moveTo",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/geatsc-plugin-gea",
3
- "version": "0.1.19",
3
+ "version": "0.1.21-uart.1",
4
4
  "description": "Gea IR backend plugin for geatsc.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {