@geastack/geatsc-plugin-gea 0.1.19 → 0.1.21
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 +143 -4
- package/dist/host-shims.js +26 -0
- package/package.json +1 -1
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
|
"}",
|
package/dist/host-shims.js
CHANGED
|
@@ -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",
|