https://github.com/discretetom/hyperdesktopduplication
Desktop Duplication API implementation for Unity with shared memory and gRPC.
https://github.com/discretetom/hyperdesktopduplication
desktop-duplication-api grpc rust rusty-duplication shared-memory shremdup unity unity3d windows
Last synced: about 1 year ago
JSON representation
Desktop Duplication API implementation for Unity with shared memory and gRPC.
- Host: GitHub
- URL: https://github.com/discretetom/hyperdesktopduplication
- Owner: DiscreteTom
- License: mit
- Created: 2023-05-06T14:51:48.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-11T03:00:57.000Z (almost 3 years ago)
- Last Synced: 2025-03-19T22:53:20.651Z (about 1 year ago)
- Topics: desktop-duplication-api, grpc, rust, rusty-duplication, shared-memory, shremdup, unity, unity3d, windows
- Language: C#
- Homepage:
- Size: 25.7 MB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# HyperDesktopDuplication




HyperDesktopDuplication is an Unity asset to use the realtime screen capture as `Texture2D` using Windows Desktop Duplication API, shared memory, gRPC and Rust.
## Why this Project?
This project is based on [uDesktopDuplication](https://github.com/hecomi/uDesktopDuplication), which is a great project to capture screen to Unity3D. However, it is not working with a standalone/discrete GPU. See https://github.com/hecomi/uDesktopDuplication/issues/30.
## Usage
First, start a [shremdup](https://github.com/DiscreteTom/shremdup) (v0.1.7+) server with administrator privilege (to use shared memory across processes).
Then, enable `Allow 'unsafe' Code` in the Player Settings, and copy all `Assets` in this repo into your Unity project.
Finally, add the `HDD_Manager` prefab to your scene, and write a driver script. Here is an example:
```cs
using HyperDesktopDuplication;
using UnityEngine;
public class Example : MonoBehaviour {
const float scale = 100;
async void Start() {
// assume we have an HDD_Manager component on the same GameObject
var manager = this.GetComponent();
// refresh monitor infos
await manager.Refresh();
// get the center position of the primary monitor
var primaryCenter = Vector3.zero;
for (int i = 0; i < manager.Monitors.Count; ++i) {
var info = manager.Monitors[i];
if (info.IsPrimary) {
primaryCenter = new Vector3((info.Right - info.Left) / 2 + info.Left, (info.Top - info.Bottom) / 2 + info.Bottom, 0) / scale;
break;
}
}
// create all monitors
for (int i = 0; i < manager.Monitors.Count; ++i) {
var info = manager.Monitors[i];
// HDD_Manager will use the HDD_Monitor prefab
var obj = manager.CreateMonitor(i);
obj.transform.localScale = new Vector3(1 / scale, 1 / scale, 1);
// place the monitor according to the system settings
obj.transform.localPosition = new Vector3((info.Right - info.Left) / 2 + info.Left, (info.Top - info.Bottom) / 2 + info.Bottom, 0) / scale - primaryCenter;
// if you want to destroy a monitor, you can do this:
// await obj.GetComponent().DestroyMonitor();
// or just:
// Destroy(obj);
}
// on destroy, HDD_Manager will destroy all monitors and close the gRPC channel
}
}
```
## Adopted Optimizations
- Invisible screens won't be updated.
- Update the desktop image and the mouse cursor image separately to reduce the texture update frequency.
## [CHANGELOG](https://github.com/DiscreteTom/HyperDesktopDuplication/blob/main/CHANGELOG.md)