Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Refactor screenshot capture for improved performance and reliability #147

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thisames
Copy link
Contributor

@thisames thisames commented Jan 8, 2025

This commit refactors the captureScreenshot method in ScreenshotCapturer
to improve performance and reliability. The changes include:

  • Synchronous Setup: The method now performs synchronous operations first
    (getting context, render object, calculating pixel ratio, and getting the
    initial image) before executing the main process asynchronously. This
    ensures that the initial setup is done on the main UI thread, as required.

  • Asynchronous Processing: The main image processing and masking logic
    are now executed asynchronously using a Future and Completer.

💡 Motivation and Context

#140

💚 How did you test it?

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

…ility

This commit refactors the `captureScreenshot` method in `ScreenshotCapturer`
to improve performance and reliability. The changes include:

-   **Synchronous Setup:** The method now performs synchronous operations first
    (getting context, render object, calculating pixel ratio, and getting the
    initial image) before executing the main process asynchronously. This
    ensures that the initial setup is done on the main UI thread, as required.

-   **Asynchronous Processing:** The main image processing and masking logic
    are now executed asynchronously using a `Future` and `Completer`,
    preventing UI jank.

-   **Snapshot Management:** The `_views` Expando is replaced with a
    `SnapshotManager` to manage the status of the view, improving code
    organization and maintainability.
@@ -30,8 +34,8 @@ class ViewTreeSnapshotStatus {
class ScreenshotCapturer {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about changing the class name? ScreenshotCapturer looks weird to me

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