Skip to content

Commit

Permalink
add zero copy mode hareware codec for windows (rustdesk#6778)
Browse files Browse the repository at this point in the history
Signed-off-by: 21pages <[email protected]>
  • Loading branch information
21pages authored Jan 2, 2024
1 parent f47faa5 commit 8915031
Show file tree
Hide file tree
Showing 55 changed files with 2,537 additions and 426 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/flutter-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
shell: bash

- name: Build rustdesk
run: python3 .\build.py --portable --hwcodec --flutter --feature IddDriver
run: python3 .\build.py --portable --hwcodec --flutter --gpucodec --feature IddDriver

- name: find Runner.res
# Windows: find Runner.res (compiled from ./flutter/windows/runner/Runner.rc), copy to ./Runner.res
Expand Down Expand Up @@ -225,7 +225,7 @@ jobs:
python3 res/inline-sciter.py
# Patch sciter x86
sed -i 's/branch = "dyn"/branch = "dyn_x86"/g' ./Cargo.toml
cargo build --features inline --release --bins
cargo build --features inline,gpucodec --release --bins
mkdir -p ./Release
mv ./target/release/rustdesk.exe ./Release/rustdesk.exe
curl -LJ -o ./Release/sciter.dll https://github.com/c-smile/sciter-sdk/raw/master/bin.win/x32/sciter.dll
Expand Down
68 changes: 66 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use_dasp = ["dasp"]
flutter = ["flutter_rust_bridge"]
default = ["use_dasp"]
hwcodec = ["scrap/hwcodec"]
gpucodec = ["scrap/gpucodec"]
mediacodec = ["scrap/mediacodec"]
linux_headless = ["pam" ]
virtual_display_driver = ["virtual_display"]
Expand Down
7 changes: 7 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ def make_parser():
help='Enable feature hwcodec' + (
'' if windows or osx else ', need libva-dev, libvdpau-dev.')
)
parser.add_argument(
'--gpucodec',
action='store_true',
help='Enable feature gpucodec, only available on windows now.'
)
parser.add_argument(
'--portable',
action='store_true',
Expand Down Expand Up @@ -274,6 +279,8 @@ def get_features(args):
features.append('virtual_display_driver')
if args.hwcodec:
features.append('hwcodec')
if args.gpucodec:
features.append('gpucodec')
if args.flutter:
features.append('flutter')
features.append('flutter_texture_render')
Expand Down
6 changes: 4 additions & 2 deletions flutter/lib/desktop/pages/desktop_setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,12 @@ class _GeneralState extends State<_General> {
}

Widget hwcodec() {
final hwcodec = bind.mainHasHwcodec();
final gpucodec = bind.mainHasGpucodec();
return Offstage(
offstage: !bind.mainHasHwcodec(),
offstage: !(hwcodec || gpucodec),
child: _Card(title: 'Hardware Codec', children: [
_OptionCheckBox(context, 'Enable hardware codec', 'enable-hwcodec'),
_OptionCheckBox(context, 'Enable hardware codec', 'enable-hwcodec')
]),
);
}
Expand Down
63 changes: 18 additions & 45 deletions flutter/lib/desktop/pages/remote_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class _RemotePageState extends State<RemotePage>
late RxBool _zoomCursor;
late RxBool _remoteCursorMoved;
late RxBool _keyboardEnabled;
final Map<int, RenderTexture> _renderTextures = {};

var _blockableOverlayState = BlockableOverlayState();

Expand Down Expand Up @@ -212,9 +211,7 @@ class _RemotePageState extends State<RemotePage>
// https://github.com/flutter/flutter/issues/64935
super.dispose();
debugPrint("REMOTE PAGE dispose session $sessionId ${widget.id}");
for (final texture in _renderTextures.values) {
await texture.destroy(closeSession);
}
_ffi.textureModel.onRemotePageDispose(closeSession);
// ensure we leave this session, this is a double check
_ffi.inputModel.enterOrLeave(false);
DesktopMultiWindow.removeListener(this);
Expand Down Expand Up @@ -429,38 +426,6 @@ class _RemotePageState extends State<RemotePage>
);
}

Map<int, RenderTexture> _updateGetRenderTextures(int curDisplay) {
tryCreateTexture(int idx) {
if (!_renderTextures.containsKey(idx)) {
final renderTexture = RenderTexture();
_renderTextures[idx] = renderTexture;
renderTexture.create(idx, sessionId);
}
}

tryRemoveTexture(int idx) {
if (_renderTextures.containsKey(idx)) {
_renderTextures[idx]!.destroy(true);
_renderTextures.remove(idx);
}
}

if (curDisplay == kAllDisplayValue) {
final displays = _ffi.ffiModel.pi.getCurDisplays();
for (var i = 0; i < displays.length; i++) {
tryCreateTexture(i);
}
} else {
tryCreateTexture(curDisplay);
for (var i = 0; i < _ffi.ffiModel.pi.displays.length; i++) {
if (i != curDisplay) {
tryRemoveTexture(i);
}
}
}
return _renderTextures;
}

Widget getBodyForDesktop(BuildContext context) {
var paints = <Widget>[
MouseRegion(onEnter: (evt) {
Expand All @@ -475,16 +440,19 @@ class _RemotePageState extends State<RemotePage>
return Obx(
() => _ffi.ffiModel.pi.isSet.isFalse
? Container(color: Colors.transparent)
: Obx(() => ImagePaint(
: Obx(() {
_ffi.textureModel.updateCurrentDisplay(peerDisplay.value);
return ImagePaint(
id: widget.id,
zoomCursor: _zoomCursor,
cursorOverImage: _cursorOverImage,
keyboardEnabled: _keyboardEnabled,
remoteCursorMoved: _remoteCursorMoved,
renderTextures: _updateGetRenderTextures(peerDisplay.value),
listenerBuilder: (child) => _buildRawTouchAndPointerRegion(
child, enterView, leaveView),
)),
ffi: _ffi,
);
}),
);
}))
];
Expand Down Expand Up @@ -515,22 +483,22 @@ class _RemotePageState extends State<RemotePage>
}

class ImagePaint extends StatefulWidget {
final FFI ffi;
final String id;
final RxBool zoomCursor;
final RxBool cursorOverImage;
final RxBool keyboardEnabled;
final RxBool remoteCursorMoved;
final Map<int, RenderTexture> renderTextures;
final Widget Function(Widget)? listenerBuilder;

ImagePaint(
{Key? key,
required this.ffi,
required this.id,
required this.zoomCursor,
required this.cursorOverImage,
required this.keyboardEnabled,
required this.remoteCursorMoved,
required this.renderTextures,
this.listenerBuilder})
: super(key: key);

Expand All @@ -548,6 +516,11 @@ class _ImagePaintState extends State<ImagePaint> {
RxBool get remoteCursorMoved => widget.remoteCursorMoved;
Widget Function(Widget)? get listenerBuilder => widget.listenerBuilder;

@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
final m = Provider.of<ImageModel>(context);
Expand Down Expand Up @@ -668,10 +641,10 @@ class _ImagePaintState extends State<ImagePaint> {
}
final curDisplay = ffiModel.pi.currentDisplay;
for (var i = 0; i < displays.length; i++) {
final textureId = widget
.renderTextures[curDisplay == kAllDisplayValue ? i : curDisplay]
?.textureId;
if (textureId != null) {
final textureId = widget.ffi.textureModel
.getTextureId(curDisplay == kAllDisplayValue ? i : curDisplay);
if (true) {
// both "textureId.value != -1" and "true" seems ok
children.add(Positioned(
left: (displays[i].x - rect.left) * s + offset.dx,
top: (displays[i].y - rect.top) * s + offset.dy,
Expand Down
26 changes: 14 additions & 12 deletions flutter/lib/desktop/widgets/tabbar_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,20 @@ class DesktopTabController {
return false;
}
state.update((val) {
val!.selected = index;
Future.delayed(Duration(milliseconds: 100), (() {
if (val.pageController.hasClients) {
val.pageController.jumpToPage(index);
}
val.scrollController.itemCount = val.tabs.length;
if (val.scrollController.hasClients &&
val.scrollController.itemCount > index) {
val.scrollController
.scrollToItem(index, center: false, animate: true);
}
}));
if (val != null) {
val.selected = index;
Future.delayed(Duration(milliseconds: 100), (() {
if (val.pageController.hasClients) {
val.pageController.jumpToPage(index);
}
val.scrollController.itemCount = val.tabs.length;
if (val.scrollController.hasClients &&
val.scrollController.itemCount > index) {
val.scrollController
.scrollToItem(index, center: false, animate: true);
}
}));
}
});
if (callOnSelected) {
if (state.value.tabs.length > index) {
Expand Down
Loading

0 comments on commit 8915031

Please sign in to comment.