@windowkit/appkit 0.34.1 → 0.35.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/README.md CHANGED
@@ -627,6 +627,63 @@ native.ctxDrawSurfaceFiltered(win, card, 0, 0, 556, 300, 100, 100, 556, 300, {
627
627
  });
628
628
  ```
629
629
 
630
+ - **`native.ctxDrawFilterGraph(dst, src, graph, dx, dy, images?)`** — an SVG filter
631
+ graph (`<filter>` and its `fe*` primitives) run over `src` by Metal compute kernels,
632
+ and what it makes drawn with its corner at (`dx`, `dy`), a `graph.width` x
633
+ `graph.height` rect under the destination's transform, clip, alpha and blend mode, as
634
+ `ctxDrawSurface` draws. It is the macOS half of react-x11-components'
635
+ `docs/prd-svg-filters-gpu.md`: `src` is the source graphic, premultiplied, the filter
636
+ region's size (its top-left `width` x `height` is read), and nothing is read back.
637
+ `graph` is that document's `FilterGraph`, `{ width, height, matrix, primitives,
638
+ precision? }`: `matrix` maps user units to region pixels (what `feTurbulence` and the
639
+ lights are placed by), and each primitive is `{ kind, inputs, sub, space, params }` —
640
+ its element name in lower case, its inputs (a result's index, `'SourceGraphic'`,
641
+ `'SourceAlpha'`, or `null` for the one before), its subregion `[x, y, w, h]` in region
642
+ pixels, `'srgb'` or `'linear'`, and its numbers, with colours premultiplied sRGB in
643
+ 0–1 and lengths in region pixels: `feflood {rgba}`, `feoffset {dx, dy}`,
644
+ `fegaussianblur {sdx, sdy}`, `fedropshadow {rgba, dx, dy, sdx, sdy}`,
645
+ `fecolormatrix {matrix}` (4x5, over straight colour), `fecomponenttransfer {funcs}`
646
+ (four of `null` or `{ type: 'table' | 'discrete', tableValues }`, `{ type: 'linear',
647
+ slope, intercept }`, `{ type: 'gamma', amplitude, exponent, offset }`), `fecomposite
648
+ {op, k}`, `feblend {mode}`, `femerge`, `fetile`, `femorphology {op, rx, ry}`,
649
+ `fedisplacementmap {scale | scaleX, scaleY, xc, yc}` (a channel's index or letter; a
650
+ tainted map is the caller's to resolve, as scale 0), `feconvolvematrix {ox, oy,
651
+ kernel, divisor, bias, tx, ty, edge, preserveAlpha}` (up to 1024 entries),
652
+ `fediffuselighting` and `fespecularlighting {rgba, surfaceScale, kd, ks, exp, light}`
653
+ (`light` `{ kind: 'distant' | 'point' | 'spot', azimuth, elevation, x, y, z, px, py,
654
+ pz, exponent, cone }`, positions in region pixels), `feturbulence {bx, by, octaves,
655
+ fractal, sel, grad}` (the reference code's lattice, 514 selector entries and 4 x 514 x
656
+ 2 gradients, or a `seed` it is made from here) and `feimage {image}`, an index into
657
+ `images`, surfaces the region's size. Each primitive is one pass (two to six for a
658
+ blur) into RGBA16F textures kept between runs, of every size a page runs as far
659
+ as 384MB, each in its colour space, with a result's texture free again after its
660
+ last read; an `feTurbulence` is kept, as far as 192MB, by every number it is made
661
+ from, so a graph run again over a source that changed makes its noise once;
662
+ `precision: 'float'` makes them RGBA32F, which matches react-x11-components'
663
+ `runFilter` within 2 levels where half floats lose the colour of a pixel all but
664
+ transparent that a later primitive makes opaque. The source is read where it lies, without a copy. All of a graph or none:
665
+ answers false, drawing nothing, for a primitive or a value it does not take, a region
666
+ past 16384 pixels a side, or no Metal device, so the caller runs the filter itself.
667
+ A FreeHand-sized group (`feTurbulence` of 4 octaves displacing the source) is 6.6ms
668
+ at 2198x1172 and 18ms at 4400x2340 on an M1 Pro the first time, where `runFilter`
669
+ took 319 and 1319, and 2.5ms at 2198x1172 each time after, its noise kept. The shaders compile at the first call, some 100–200ms.
670
+ - **`native.filterGraphPrimitives()`** — the primitives `ctxDrawFilterGraph` runs, by
671
+ element name in lower case (`'feturbulence'`, `'fedisplacementmap'`, …), what the
672
+ PRD's `filterGraph.primitives` is: empty where there is no Metal device or its shaders
673
+ did not compile. The first call compiles them.
674
+
675
+ ```js
676
+ native.ctxDrawFilterGraph(win, group, {
677
+ width: 2198, height: 1172, matrix: [1, 0, 0, 1, -40, -1200],
678
+ primitives: [
679
+ { kind: 'feturbulence', inputs: [], sub: [0, 0, 2198, 1172], space: 'linear',
680
+ params: { bx: 0.02, by: 0.02, octaves: 4, fractal: false, sel, grad } },
681
+ { kind: 'fedisplacementmap', inputs: ['SourceGraphic', 0], sub: [0, 0, 2198, 1172],
682
+ space: 'linear', params: { scale: 8, xc: 'R', yc: 'G' } },
683
+ ],
684
+ }, 40, 1200);
685
+ ```
686
+
630
687
  - **`native.ctxSetImageSmoothing(surface, quality)`** — how an image or a surface drawn
631
688
  scaled or turned is resampled: `'none'` (the nearest pixel), `'low'`, `'medium'` or
632
689
  `'high'`, the 2D canvas's `imageSmoothingEnabled` and `imageSmoothingQuality`. It is
package/binding.gyp CHANGED
@@ -14,7 +14,8 @@
14
14
  "src/player.mm",
15
15
  "src/capture.mm",
16
16
  "src/systemaudio.mm",
17
- "src/displaystream.mm"
17
+ "src/displaystream.mm",
18
+ "src/filtergraph.mm"
18
19
  ],
19
20
  "include_dirs": [
20
21
  "<!@(node -p \"require('node-addon-api').include\")"
@@ -29,6 +30,7 @@
29
30
  "libraries": [
30
31
  "-framework Cocoa",
31
32
  "-framework QuartzCore",
33
+ "-framework Metal",
32
34
  "-framework Accelerate",
33
35
  "-framework CoreText",
34
36
  "-framework CoreGraphics",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windowkit/appkit",
3
- "version": "0.34.1",
3
+ "version": "0.35.1",
4
4
  "description": "Retained-mode AppKit backend for Node.js: Core Animation (CALayer) layer trees, CoreText layout and drawing, IOSurface presentation, NSMenu, and native control bezels — the macOS half of react-x11.",
5
5
  "author": "Andrey Sidorov <andrey.sidorov@gmail.com>",
6
6
  "license": "MIT",
@@ -43,7 +43,7 @@
43
43
  "install": "node scripts/install.js",
44
44
  "build": "node-gyp rebuild",
45
45
  "demo": "node demo/demo.js",
46
- "test": "node test/app-lifecycle.js && node test/animation.js && node test/layer-transform.js && node test/contents-gravity.js && node test/contents-center.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/popup-menu.js && node test/pasteboard-write.js && node test/surface-blit.js && node test/surface-faded.js && node test/surface-filtered.js && node test/image-smoothing.js && node test/surface-colorspace.js && node test/video-surface.js && node test/player.js && node test/player-vp9.js && node test/capture.js && node test/capture-threaded.js && node test/display-stream.js && node test/system-audio.js && node test/system-audio-threaded.js && node test/round-rect-xy.js && node test/clip-rule.js && node test/radial-gradient.js && node test/control-bezels.js && node test/text-features.js && node test/font-from-data.js && node test/font-download.js && node test/text-coverage.js && node test/text-typesetter.js && node test/text-line-height.js && node test/text-line-width.js && node test/text-justify.js && node test/text-scale.js && node test/symbols.js && node test/eventkit-permissions.js && node test/calendars.js && node test/calendar-writes.js && node test/screencolor.js && node test/notifications.js && node test/threaded.js && node test/threaded-verbs.js && node test/threaded-frames.js && node test/threaded-resize.js && node test/ending-worker.js && node test/live-resize.js && node test/resize-no-crossing.js && node test/window-states.js && node test/threaded-window-states.js && node test/activation-policy.js && node test/last-input.js"
46
+ "test": "node test/app-lifecycle.js && node test/animation.js && node test/layer-transform.js && node test/contents-gravity.js && node test/contents-center.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/popup-menu.js && node test/pasteboard-write.js && node test/surface-blit.js && node test/surface-faded.js && node test/surface-filtered.js && node test/filter-graph.js && node test/image-smoothing.js && node test/surface-colorspace.js && node test/video-surface.js && node test/player.js && node test/player-vp9.js && node test/capture.js && node test/capture-threaded.js && node test/display-stream.js && node test/system-audio.js && node test/system-audio-threaded.js && node test/round-rect-xy.js && node test/clip-rule.js && node test/radial-gradient.js && node test/control-bezels.js && node test/text-features.js && node test/font-from-data.js && node test/font-download.js && node test/text-coverage.js && node test/text-typesetter.js && node test/text-line-height.js && node test/text-line-width.js && node test/text-justify.js && node test/text-scale.js && node test/symbols.js && node test/eventkit-permissions.js && node test/calendars.js && node test/calendar-writes.js && node test/screencolor.js && node test/notifications.js && node test/threaded.js && node test/threaded-verbs.js && node test/threaded-frames.js && node test/threaded-resize.js && node test/ending-worker.js && node test/live-resize.js && node test/resize-no-crossing.js && node test/window-states.js && node test/threaded-window-states.js && node test/activation-policy.js && node test/last-input.js"
47
47
  },
48
48
  "dependencies": {
49
49
  "node-addon-api": "^8.3.0"
Binary file
package/src/addon.mm CHANGED
@@ -1874,6 +1874,8 @@ void InitCapture(Napi::Env env, Napi::Object exports);
1874
1874
  void InitSystemAudio(Napi::Env env, Napi::Object exports);
1875
1875
  // src/displaystream.mm — a display or a window as ScreenCaptureKit's stream.
1876
1876
  void InitDisplayStream(Napi::Env env, Napi::Object exports);
1877
+ // filtergraph.mm: ctxDrawFilterGraph, an SVG filter graph run by Metal.
1878
+ void InitFilterGraph(Napi::Env env, Napi::Object exports);
1877
1879
 
1878
1880
  static Napi::Object Init(Napi::Env env, Napi::Object exports) {
1879
1881
  #define FN(js, fn) exports.Set(js, Napi::Function::New(env, fn))
@@ -1925,6 +1927,7 @@ static Napi::Object Init(Napi::Env env, Napi::Object exports) {
1925
1927
  InitCapture(env, exports);
1926
1928
  InitSystemAudio(env, exports);
1927
1929
  InitDisplayStream(env, exports);
1930
+ InitFilterGraph(env, exports);
1928
1931
  return exports;
1929
1932
  }
1930
1933
 
package/src/backend.mm CHANGED
@@ -1774,6 +1774,27 @@ bool CALSurfaceBitmap(Napi::Value v, CALSurfaceBits* out) {
1774
1774
  return true;
1775
1775
  }
1776
1776
 
1777
+ // A surface's parts, for filtergraph.mm's ctxDrawFilterGraph: its context,
1778
+ // its bitmap and the IOSurface under it, if any. False, with the error
1779
+ // pending, where the handle is not a live surface.
1780
+ struct CALSurfaceView {
1781
+ CGContextRef ctx;
1782
+ IOSurfaceRef iosurface;
1783
+ uint8_t* data;
1784
+ size_t width, height, bytesPerRow;
1785
+ };
1786
+ bool CALSurfaceViewOf(Napi::Value v, CALSurfaceView* out) {
1787
+ CALSurface* s = SurfaceFrom(v);
1788
+ if (!s) return false;
1789
+ out->ctx = s->ctx;
1790
+ out->iosurface = s->iosurface;
1791
+ out->data = (uint8_t*)CGBitmapContextGetData(s->ctx);
1792
+ out->width = s->width;
1793
+ out->height = s->height;
1794
+ out->bytesPerRow = CGBitmapContextGetBytesPerRow(s->ctx);
1795
+ return true;
1796
+ }
1797
+
1777
1798
  // For the fire-and-forget drawing verbs: the context to draw into, or a
1778
1799
  // scratch bitmap when the surface is released (the error is already
1779
1800
  // pending; the stroke lands nowhere anyone looks).