Perf: Optimize macOS screen capture with CGDisplayStream

Core optimization:
- Use CGDisplayStream instead of per-frame CGDisplayCreateImage
- Push model: CPU sleeps when screen is static (condition_variable wait)
- IOSurface capture avoids expensive image creation per frame
- ~47% CPU reduction during active remote desktop (45% → 24%)

Additional optimizations:
- vImageVerticalReflect (SIMD) replaces manual row-by-row flip
- Cache CGColorSpaceRef to avoid per-frame creation/release
- Cache tempBuffer to avoid per-frame memory allocation
- Throttle getCursorTypeIndex to 250ms (Accessibility API is expensive)

Bug fixes:
- Fix unreliable screen capture permission check (use actual capture test)
- Improve permission logging

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
yuanyuanxiang
2026-05-03 23:18:30 +02:00
parent b732f841d0
commit 92f3df8464
7 changed files with 483 additions and 43 deletions

31
macos/uninstall.sh Normal file
View File

@@ -0,0 +1,31 @@
#!/bin/bash
# macOS Ghost Client 卸载脚本
echo "=== Ghost Client 卸载程序 ==="
# 1. 停止并卸载 launchd 服务
echo "[1/4] 停止服务..."
sudo launchctl unload /Library/LaunchDaemons/com.ghost.client.plist 2>/dev/null
launchctl unload ~/Library/LaunchAgents/com.ghost.client.plist 2>/dev/null
# 2. 杀死残留进程
echo "[2/4] 终止进程..."
sudo pkill -9 -f "/usr/local/bin/ghost" 2>/dev/null
# 3. 删除文件
echo "[3/4] 删除文件..."
sudo rm -f /Library/LaunchDaemons/com.ghost.client.plist
rm -f ~/Library/LaunchAgents/com.ghost.client.plist
sudo rm -f /usr/local/bin/ghost
rm -rf ~/.config/ghost
sudo rm -f /var/log/ghost.log
# 4. 完成
echo "[4/4] 卸载完成!"
echo ""
echo "注意: 系统权限(屏幕录制/辅助功能)未重置。"
echo ""
echo "如需重置系统权限(会影响所有应用),请手动执行:"
echo " tccutil reset ScreenCapture"
echo " tccutil reset Accessibility"
echo " tccutil reset SystemPolicyAllFiles"