@geastack/geatsc-plugin-gea 0.1.18 → 0.1.20

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,94 @@ 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
+ "namespace gea {",
1281
+ "template <typename T> class TypedArray;",
1282
+ "template <typename T> struct Ref;",
1283
+ "template <typename T, typename... Arguments> inline Ref<T> makeRef(Arguments&&... arguments);",
1284
+ "} // namespace gea",
1285
+ "namespace gea_ir {",
1286
+ "",
1287
+ "template <typename D = void>",
1288
+ "struct ImageData565T {",
1289
+ " using array_type = gea::TypedArray<std::conditional_t<std::is_void_v<D>, std::uint16_t, std::uint16_t>>;",
1290
+ " using pixels_type = gea::Ref<array_type>;",
1291
+ " double width = 0;",
1292
+ " double height = 0;",
1293
+ " pixels_type data16;",
1294
+ " int id = -1;",
1295
+ " gea::framework::graphics::pixel::native_t *staging = nullptr;",
1296
+ "};",
1297
+ "using ImageData565 = ImageData565T<>;",
1298
+ "",
1299
+ "inline constexpr bool imageData565ZeroCopy =",
1300
+ " std::is_same_v<gea::framework::graphics::pixel::native_t, std::uint16_t> && !GEA_EMBEDDED_PIXEL_PANEL_ENDIAN;",
1301
+ "",
1302
+ "template <typename W, typename H>",
1303
+ "inline ImageData565T<std::conditional_t<true, void, W>> canvasCreateImageData565(gea::embedded::ui::CanvasRenderingContext2D &, const W &w, const H &h) {",
1304
+ " ImageData565T<std::conditional_t<true, void, W>> out;",
1305
+ " const int width = canvasInt(w) > 0 ? canvasInt(w) : 0;",
1306
+ " const int height = canvasInt(h) > 0 ? canvasInt(h) : 0;",
1307
+ " out.width = width;",
1308
+ " out.height = height;",
1309
+ " using __gea_image_t = decltype(out);",
1310
+ " out.data16 = gea::makeRef<typename __gea_image_t::array_type>(static_cast<std::size_t>(width) * static_cast<std::size_t>(height));",
1311
+ " if (width == 0 || height == 0) return out;",
1312
+ " auto &store = gea::framework::graphics::ImageStore::instance();",
1313
+ " if constexpr (imageData565ZeroCopy) {",
1314
+ " out.id = store.registerBuffer(reinterpret_cast<gea::framework::graphics::pixel::native_t *>((*out.data16).data()), width, height);",
1315
+ " } else {",
1316
+ " const std::size_t count = static_cast<std::size_t>(width) * static_cast<std::size_t>(height);",
1317
+ " out.staging = static_cast<gea::framework::graphics::pixel::native_t *>(",
1318
+ " gea::framework::memory::Allocator::allocatePreferSpiram(count * sizeof(gea::framework::graphics::pixel::native_t), 128));",
1319
+ " if (out.staging) {",
1320
+ " for (std::size_t i = 0; i < count; ++i) out.staging[i] = gea::framework::graphics::pixel::toNative(0);",
1321
+ " out.id = store.registerBuffer(out.staging, width, height, -1, true);",
1322
+ " if (out.id < 0) {",
1323
+ " gea::framework::memory::Allocator::free(out.staging);",
1324
+ " out.staging = nullptr;",
1325
+ " }",
1326
+ " }",
1327
+ " }",
1328
+ " return out;",
1329
+ "}",
1330
+ "",
1331
+ "template <typename D, typename X, typename Y>",
1332
+ "inline void canvasPutImageData(gea::embedded::ui::CanvasRenderingContext2D &ctx, const ImageData565T<D> &image, const X &x, const Y &y) {",
1333
+ " if (image.id < 0) return;",
1334
+ " if constexpr (!imageData565ZeroCopy) {",
1335
+ " if (!image.staging) return;",
1336
+ " const std::uint16_t *src = (*image.data16).data();",
1337
+ " const std::size_t count = (*image.data16).size();",
1338
+ " gea::framework::graphics::pixel::native_t *dst = image.staging;",
1339
+ " // `toNative` is a format conversion only; the panel byte-swap of a 16-bit",
1340
+ " // framebuffer is `fromRgb565`'s.",
1341
+ " if constexpr (std::is_same_v<gea::framework::graphics::pixel::native_t, std::uint16_t>) {",
1342
+ " for (std::size_t i = 0; i < count; ++i) dst[i] = gea::framework::graphics::pixel::fromRgb565(src[i]);",
1343
+ " } else {",
1344
+ " for (std::size_t i = 0; i < count; ++i) dst[i] = gea::framework::graphics::pixel::toNative(src[i]);",
1345
+ " }",
1346
+ " }",
1347
+ " ctx.drawImage(image.id, canvasInt(x), canvasInt(y));",
1348
+ "}",
1349
+ "",
1350
+ ];
1263
1351
  export function directCanvasInteropSource(usesCanvas, options = {}) {
1264
1352
  if (!usesCanvas)
1265
1353
  return [];
@@ -1545,6 +1633,7 @@ export function directCanvasInteropSource(usesCanvas, options = {}) {
1545
1633
  " ctx.drawImageTiledX(canvasImageId(image), canvasInt(x), canvasInt(y), canvasInt(w));",
1546
1634
  "}",
1547
1635
  "",
1636
+ ...imageData565InteropSource,
1548
1637
  "inline void canvasFlush(gea::embedded::ui::CanvasRenderingContext2D &ctx) {",
1549
1638
  " ctx.flush();",
1550
1639
  "}",
@@ -2290,6 +2379,7 @@ function canvasInteropSource(usesCanvas, directCanvas) {
2290
2379
  " ctx.drawImageTiledX(canvasImageId(image), canvasInt(x), canvasInt(y), canvasInt(w));",
2291
2380
  "}",
2292
2381
  "",
2382
+ ...imageData565InteropSource,
2293
2383
  "inline void canvasFlush(gea::embedded::ui::CanvasRenderingContext2D &ctx) {",
2294
2384
  " ctx.flush();",
2295
2385
  "}",
@@ -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
@@ -1822,6 +1828,11 @@ export function createGeaHostShims() {
1822
1828
  returnType: "double",
1823
1829
  receiverTypes: IMAGE_RECEIVER_TYPES,
1824
1830
  },
1831
+ {
1832
+ emit: "({receiver}).width",
1833
+ returnType: "double",
1834
+ receiverTypes: IMAGE_DATA_565_RECEIVER_TYPES,
1835
+ },
1825
1836
  ],
1826
1837
  height: [
1827
1838
  {
@@ -1829,6 +1840,18 @@ export function createGeaHostShims() {
1829
1840
  returnType: "double",
1830
1841
  receiverTypes: IMAGE_RECEIVER_TYPES,
1831
1842
  },
1843
+ {
1844
+ emit: "({receiver}).height",
1845
+ returnType: "double",
1846
+ receiverTypes: IMAGE_DATA_565_RECEIVER_TYPES,
1847
+ },
1848
+ ],
1849
+ data16: [
1850
+ {
1851
+ emit: "({receiver}).data16",
1852
+ returnType: "gea::Ref<gea::TypedArray<std::uint16_t>>",
1853
+ receiverTypes: IMAGE_DATA_565_RECEIVER_TYPES,
1854
+ },
1832
1855
  ],
1833
1856
  frameCount: [
1834
1857
  {
@@ -2294,6 +2317,8 @@ export function createGeaHostShims() {
2294
2317
  drawImageCircle: "gea_ir::canvasDrawImageCircle($receiver, $args)",
2295
2318
  drawImageRotated90CW: "gea_ir::canvasDrawImageRotated90CW($receiver, $args)",
2296
2319
  drawImageTiledX: "gea_ir::canvasDrawImageTiledX($receiver, $args)",
2320
+ createImageData565: "gea_ir::canvasCreateImageData565($receiver, $args)",
2321
+ putImageData: "gea_ir::canvasPutImageData($receiver, $args)",
2297
2322
  flush: "gea_ir::canvasFlush($receiver /*$args*/)",
2298
2323
  beginBatch: "gea_ir::canvasBeginBatch($receiver /*$args*/)",
2299
2324
  endBatch: "gea_ir::canvasEndBatch($receiver /*$args*/)",
@@ -2309,6 +2334,7 @@ export function createGeaHostShims() {
2309
2334
  "fillCirclesRgb565",
2310
2335
  "fillCirclesRgb565Uniform",
2311
2336
  "fillTrianglesRgb565Sorted",
2337
+ "putImageData",
2312
2338
  "beginPath",
2313
2339
  "arc",
2314
2340
  "moveTo",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/geatsc-plugin-gea",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "Gea IR backend plugin for geatsc.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {