Skip to content

Conversation

@li-manssing
Copy link

Summary

Add support for capturing screenshot of multiple windows with hardware bitmap enabled

Issue:

  • Falcon library fails when processing hardware-accelerated bitmaps with
    error: "Software rendering doesn't support hardware bitmaps".
  • The fallback method is not capable of capturing screenshots of multiple
    window surfaces (dialogs, bottom sheets, Compose overlays).

Cause:

  • Falcon library requires software bitmaps for processing but modern
    Android uses hardware bitmaps for performance, hence failing to capture
    screenshot of some screens.
  • The fallback approach used PixelCopy API that supports hardware bitmaps
    but could capture the screenshot of only the root window provided and
    not any additional windows layered on top (dialogs, bottom sheets, etc.).

Fix:

  • Created new ScreenshotCapture.java utility class to handle
    hardware-accelerated bitmap capture using PixelCopy API.
  • Implemented PixelCopy API for Android O+ to capture hardware-accelerated
    bitmaps correctly.
  • Implemented getRootViews() to detect all active windows using reflection.
  • Added captureAsync() method with dual capture strategy:
    • Primary: Capture from Surface (via reflection on ViewRoot's mSurface) for
      per-window isolation.
    • Fallback: Capture from Window object when Surface unavailable
  • Created ViewRootData class to encapsulate window hierarchy information:
    • View reference, window frame bounds, layout parameters, ViewRoot object
    • Window type detection (activity vs dialog/bottom sheet)
    • Window association for parent-child relationships
  • Created dedicated utility class ScreenshotCaptureUtils.java for bitmap manipulation and merging.

Testing done

Tested locally and verified that the changes work as expected for traditional as well as compose bottom-sheets (that have hardware bitmaps enabled).

Note for reviewers

While the changes work as expected for bottom-sheets, we are observing some issue when capturing screenshots of dialogs. The dialog appears squeezed in the bitmap. We are still trying to debuga nd fix the issue hence keeping PR as draft.

…e bitmap enabled

Issue:
- Falcon library fails when processing hardware-accelerated bitmaps with
  error: "Software rendering doesn't support hardware bitmaps".
- The fallback method is not capable of capturing screenshots of multiple
  window surfaces (dialogs, bottom sheets, Compose overlays).

Cause:
- Falcon library requires software bitmaps for processing but modern
  Android uses hardware bitmaps for performance, hence failing to capture
  screenshot of some screens.
- The fallback approach used PixelCopy API that supports hardware bitmaps
  but could capture the screenshot of only the root window provided and
  not any additional windows layered on top (dialogs, bottom sheets, etc.).

Fix:
- Created new `ScreenshotCapture.java` utility class to handle
  hardware-accelerated bitmap capture using `PixelCopy` API.
- Implemented `PixelCopy` API for Android O+ to capture hardware-accelerated
  bitmaps correctly.
- Implemented `getRootViews()` to detect all active windows using reflection.
- Added `captureAsync()` method with dual capture strategy:
  - Primary: Capture from Surface (via reflection on ViewRoot's mSurface) for
    per-window isolation.
  - Fallback: Capture from Window object when Surface unavailable
- Created `ViewRootData` class to encapsulate window hierarchy information:
     - View reference, window frame bounds, layout parameters, ViewRoot object
     - Window type detection (activity vs dialog/bottom sheet)
     - Window association for parent-child relationships
- Created dedicated utility class `ScreenshotCaptureUtils.java` for bitmap manipulation and merging.
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.

1 participant