Skip to content

Conversation

@DiscreteTom
Copy link
Owner

Summary

This PR implements the delta-update feature for the Windows Desktop Duplication API screen capture library, enabling efficient capture by only updating dirty (changed) regions instead of copying the entire GPU texture to memory each frame.

Requirements Implemented

Core Changes

  • Added dirty region detection: Implemented GetFrameDirtyRects to retrieve the list of dirty rectangles (changed screen regions) after AcquireNextFrame
  • Added moved region detection: Implemented GetFrameMoveRects to retrieve the list of moved rectangles (scrolled/moved screen regions)
  • Optimized texture copying: Replaced full CopyResource call with targeted CopySubresourceRegion calls that only copy the dirty and moved rectangular regions from GPU texture to memory
  • Comprehensive region handling: Both dirty rects and move rects are properly handled to ensure all changed areas are captured

API & Compatibility

  • Backward compatibility maintained: Existing capture() and capture_with_pointer_shape() methods continue to work without any breaking changes
  • Multi-buffer support: Implementation works correctly with both VecCapturer and SharedMemory buffer types
  • Error handling: Added appropriate error handling for all new API calls (GetFrameDirtyRects, GetFrameMoveRects, CopySubresourceRegion)

Modified Files

  • src/monitor.rs: Core implementation of delta-update feature with dirty/moved region tracking
  • src/capturer.rs: Added new capture methods that expose dirty region information
  • examples/delta_updates.rs: Example demonstrating delta-update usage
  • DELTA_UPDATES.md: Documentation explaining the feature and usage patterns

Technical Details

The implementation adds new methods to work alongside the existing capture API:

  • capture_frame_dirty_rects() - Captures frame with dirty region information
  • capture_frame_with_pointer_dirty_rects() - Captures frame with pointer shape and dirty region information

These methods return both the frame data and a list of dirty/moved rectangles, allowing applications to optimize their processing by only updating the changed regions.

Benefits

  • Performance improvement: Significantly reduces memory bandwidth usage by only copying changed regions
  • Reduced CPU/GPU load: Less data transfer between GPU and CPU memory
  • Power efficiency: Lower memory operations lead to better power consumption
  • Scalability: More efficient for high-resolution or high-refresh-rate captures

Testing

The implementation has been tested to ensure:

  • Dirty regions are correctly identified and captured
  • Moved regions are properly handled
  • Backward compatibility is preserved
  • Both buffer types (VecCapturer and SharedMemory) work correctly
  • Error conditions are handled gracefully

This feature is particularly useful for applications that need efficient screen capture, such as remote desktop applications, screen recording tools, and streaming software.

- Add GetFrameDirtyRects and GetFrameMoveRects support
- Replace full CopyResource with CopySubresourceRegion for dirty regions
- Add delta capture methods and dirty region tracking
- Include example and documentation for delta updates
- Maintain backward compatibility with existing capture API

Co-authored-by: DiscreteTom <discrete_tom@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants