@asdf-overlay/electron 0.9.7 → 1.0.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/lib/surface.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { WebContents } from 'electron';
2
2
  import type { OverlayWindow } from './index.js';
3
3
  import EventEmitter from 'node:events';
4
+ import { type GpuLuid } from '@asdf-overlay/core';
4
5
  type Emitter = EventEmitter<{
5
6
  /**
6
7
  * An error has been occured while copying to overlay surface.
@@ -18,11 +19,12 @@ export declare class ElectronOverlaySurface {
18
19
  */
19
20
  readonly events: Emitter;
20
21
  private handler;
22
+ private readonly surface;
21
23
  private constructor();
22
24
  /**
23
25
  * Connect Electron `WebContents` surface to target overlay window.
24
26
  */
25
- static connect(window: OverlayWindow, contents: WebContents): ElectronOverlaySurface;
27
+ static connect(window: OverlayWindow, luid: GpuLuid, contents: WebContents): ElectronOverlaySurface;
26
28
  /**
27
29
  * Disconnect surface from Electron window and clear overlay surface.
28
30
  */
package/lib/surface.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import EventEmitter from 'node:events';
2
+ import { OverlaySurface } from '@asdf-overlay/core';
2
3
  /**
3
4
  * Connection from a Electron offscreen window to a overlay surface.
4
5
  */
@@ -10,9 +11,11 @@ export class ElectronOverlaySurface {
10
11
  */
11
12
  events = new EventEmitter();
12
13
  handler;
13
- constructor(window, contents) {
14
+ surface;
15
+ constructor(window, luid, contents) {
14
16
  this.window = window;
15
17
  this.contents = contents;
18
+ this.surface = OverlaySurface.create(luid);
16
19
  this.handler = (e, rect, image) => {
17
20
  const offscreenTexture = e.texture;
18
21
  if (offscreenTexture) {
@@ -35,15 +38,16 @@ export class ElectronOverlaySurface {
35
38
  /**
36
39
  * Connect Electron `WebContents` surface to target overlay window.
37
40
  */
38
- static connect(window, contents) {
39
- return new ElectronOverlaySurface({ ...window }, contents);
41
+ static connect(window, luid, contents) {
42
+ return new ElectronOverlaySurface({ ...window }, luid, contents);
40
43
  }
41
44
  /**
42
45
  * Disconnect surface from Electron window and clear overlay surface.
43
46
  */
44
47
  async disconnect() {
45
48
  this.contents.off('paint', this.handler);
46
- await this.window.overlay.clearSurface(this.window.id);
49
+ await this.window.overlay.updateHandle(this.window.id, {});
50
+ this.surface.destroy();
47
51
  }
48
52
  /**
49
53
  * Copy overlay texture in gpu accelerated shared texture mode.
@@ -55,11 +59,14 @@ export class ElectronOverlaySurface {
55
59
  const rect = texture.metadata.captureUpdateRect ?? texture.contentRect;
56
60
  // update only changed part
57
61
  try {
58
- await this.window.overlay.updateShtex(this.window.id, texture.codedSize.width, texture.codedSize.height, texture.sharedTextureHandle, {
62
+ const update = this.surface.updateShtex(texture.codedSize.width, texture.codedSize.height, texture.sharedTextureHandle, {
59
63
  dstX: rect.x,
60
64
  dstY: rect.y,
61
65
  src: rect,
62
66
  });
67
+ if (update) {
68
+ await this.window.overlay.updateHandle(this.window.id, update);
69
+ }
63
70
  }
64
71
  catch (e) {
65
72
  this.emitError(e);
@@ -71,7 +78,10 @@ export class ElectronOverlaySurface {
71
78
  async paintSoftware(_dirtyRect, image) {
72
79
  // TODO:: update only changed part
73
80
  try {
74
- await this.window.overlay.updateBitmap(this.window.id, image.getSize().width, image.toBitmap());
81
+ const update = this.surface.updateBitmap(image.getSize().width, image.toBitmap());
82
+ if (update) {
83
+ await this.window.overlay.updateHandle(this.window.id, update);
84
+ }
75
85
  }
76
86
  catch (e) {
77
87
  this.emitError(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asdf-overlay/electron",
3
- "version": "0.9.7",
3
+ "version": "1.0.1",
4
4
  "description": "Asdf overlay Electron integration",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "peerDependencies": {
36
36
  "electron": "^37.3.1",
37
- "@asdf-overlay/core": "0.9.7"
37
+ "@asdf-overlay/core": "1.0.1"
38
38
  },
39
39
  "scripts": {
40
40
  "build:dist": "tsc",