Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Android] Speed up the method 'FlutterRenderer.getBitmap' #37342

Merged
merged 1 commit into from
Nov 7, 2022

Conversation

ColdPaleLight
Copy link
Member

@ColdPaleLight ColdPaleLight commented Nov 5, 2022

The pixel order of ARGB_8888 after storage is ABGR on the Java side. Java is big endian and native is little endian, so the order is RGBA on the C++ side.

So we can use 'Bitmap.copyPixelsFromBuffer' to do pixel copy, which can avoid the conversion of RGBA to BGRA here.

// Our configuration of Skia does not support rendering to the
// BitmapConfig.ARGB_8888 format expected by android.graphics.Bitmap.
// Convert from kRGBA_8888 to kBGRA_8888 (equivalent to ARGB_8888).
for (int i = 0; i < pixels_size; i++) {
int32_t src_pixel = pixels_src[i];
uint8_t* src_bytes = reinterpret_cast<uint8_t*>(&src_pixel);
std::swap(src_bytes[0], src_bytes[2]);
pixels[i] = src_pixel;
}

In my local test, the average time consumption of the method FlutterRenderer.getBitmap before optimization is 99.7ms, and it is 66.2ms after optimization.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@dnfield
Copy link
Contributor

dnfield commented Nov 6, 2022

It'd be really nice to have a test of this, perhaps either in flutter_shell_native_unittests or in the scenario_app. Right now AFAICT this code is unused in the engine but it is used in a test in the framework, althogh it's not clear to me whether that test runs on CI or not (https://github.com/flutter/flutter/blob/master/examples/platform_channel/android/app/src/androidTest/java/com/example/platformchannel/ExampleInstrumentedTest.java)

@ColdPaleLight
Copy link
Member Author

It'd be really nice to have a test of this, perhaps either in flutter_shell_native_unittests or in the scenario_app. Right now AFAICT this code is unused in the engine but it is used in a test in the framework, althogh it's not clear to me whether that test runs on CI or not (https://github.com/flutter/flutter/blob/master/examples/platform_channel/android/app/src/androidTest/java/com/example/platformchannel/ExampleInstrumentedTest.java)

@dnfield
The test has been added, However I found an issue related to scenario test flutter/flutter#114805

@dnfield dnfield added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 7, 2022
@auto-submit auto-submit bot merged commit 4e03d05 into flutter:main Nov 7, 2022
sourcegraph-bot pushed a commit to sgtest/megarepo that referenced this pull request Nov 7, 2022
…Bitmap' (flutter/engine#37342) (#114833)

Commit: e901832333931b31a266366cb57144d551dbb2cf
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Nov 8, 2022
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Nov 8, 2022
* 5280135 ecd3c4857 Roll Fuchsia Mac SDK from sNXsQVxntMX8f42LE... to 9Jb1-3tRPQ2ZhpTQC... (flutter/engine#37363) (flutter/flutter#114772)

* a6da104 Adds support for the Material Badge widget, BadgeTheme, BadgeThemeData (flutter/flutter#114560)

* 19c5fc5 0cbdf464c Add Matrix::LookAt (flutter/engine#37361) (flutter/flutter#114786)

* c551fe3 4e45cfb4a Roll Fuchsia Mac SDK from 9Jb1-3tRPQ2ZhpTQC... to 5XOj9l5e2wkSpMKT1... (flutter/engine#37369) (flutter/flutter#114789)

* a54a46d 6b57fddd1 Bump github/codeql-action from 2.1.29 to 2.1.31 (flutter/engine#37374) (flutter/flutter#114798)

* 3c9288c Increase minimum supported macOS version from 10.13 to 10.14 (flutter/flutter#114713)

* a1289a4 891d4a357 Roll Skia from c3c31be8729b to 513f0fd34590 (2 revisions) (flutter/engine#37377) (flutter/flutter#114802)

* 04d6fd2 Roll Plugins from a279b9d to 3ca3410 (4 revisions) (flutter/flutter#114813)

* 151c831 92d9ad27f Roll Skia from 513f0fd34590 to da9fad017aee (2 revisions) (flutter/engine#37379) (flutter/flutter#114816)

* d6a8e92 Revert "Adds support for the Material Badge widget, BadgeTheme, BadgeThemeData (#114560)" (flutter/flutter#114819)

* 7de60bb 334549704 Roll buildroot to d13d64086f5e301bd0415eede895b34af220ef42 (flutter/engine#37380) (flutter/flutter#114821)

* 496cf62 Delegate TestWindow.updateSemantics to the wrapped SingletonFlutterWindow (flutter/flutter#114733)

* 497a528 Fix TextField/CupertinoTextField hint style overflow not work. (flutter/flutter#114335)

* 7e36cf1 Mac Page Up / Page Down in text fields (flutter/flutter#105497)

* 77c06c2 0075e10bc Move gclient var property to ci.yaml (flutter/engine#37351) (flutter/flutter#114828)

* 378387b when getting xcworkspace, exclude hidden files (flutter/flutter#114099)

* e901832 4e03d059d [Android] Speed up the method 'FlutterRenderer.getBitmap' (flutter/engine#37342) (flutter/flutter#114833)

* 3cde69e Revert "Revert "Scribble mixin (#104128)" (#114647)" (flutter/flutter#114698)

* e1adc96 feat: provide a way to set the initial child's alignment (flutter/flutter#114745)

* fe5eb2d ee48c0392 Roll Fuchsia Mac SDK from 5XOj9l5e2wkSpMKT1... to sa5bVGimNo3JwLV27... (flutter/engine#37386) (flutter/flutter#114836)

* 5628ebf [RawKeyboard] Allow inconsistent modifiers for Web (flutter/flutter#114499)

* f1cdfa2 Use AppBar.systemOverlayStyle to style system navigation bar (flutter/flutter#104827)

* e4e902d [flutter_tools] add compilation failure tests for new cases added in impellerc (flutter/flutter#114757)

* 7640f31 a81a715ce Revert "Remove deprecated calls to updateSemantics in `PlatformDispatcher` (#36673)" (flutter/engine#37388) (flutter/flutter#114842)

* 585d445 Roll Flutter Engine from a81a715ce6b2 to df602070ac4b (3 revisions) (flutter/flutter#114847)

* 1ca2e0b Fix `CastError` in `StadiumBorder.lerpTo` and  `StadiumBorder.lerpFrom` when using `BorderRadiusDirectional` (flutter/flutter#114826)

* 2e85e74 004a30516 [fuchsia] embedding-flutter test (flutter/engine#37052) (flutter/flutter#114854)

* 139b8f4 Roll Flutter Engine from 004a305166d5 to e7d7edab98ad (2 revisions) (flutter/flutter#114855)

* 53e6876 Allow Flutter golden file tests to be flaky (flutter/flutter#114450)

* a1432a9 Refactor fix_data.yaml (flutter/flutter#114192)
auto-submit bot pushed a commit to flutter/plugins that referenced this pull request Nov 8, 2022
* 04d6fd2 Roll Plugins from a279b9d to 3ca3410 (4 revisions) (flutter/flutter#114813)

* 151c831 92d9ad27f Roll Skia from 513f0fd34590 to da9fad017aee (2 revisions) (flutter/engine#37379) (flutter/flutter#114816)

* d6a8e92 Revert "Adds support for the Material Badge widget, BadgeTheme, BadgeThemeData (#114560)" (flutter/flutter#114819)

* 7de60bb 334549704 Roll buildroot to d13d64086f5e301bd0415eede895b34af220ef42 (flutter/engine#37380) (flutter/flutter#114821)

* 496cf62 Delegate TestWindow.updateSemantics to the wrapped SingletonFlutterWindow (flutter/flutter#114733)

* 497a528 Fix TextField/CupertinoTextField hint style overflow not work. (flutter/flutter#114335)

* 7e36cf1 Mac Page Up / Page Down in text fields (flutter/flutter#105497)

* 77c06c2 0075e10bc Move gclient var property to ci.yaml (flutter/engine#37351) (flutter/flutter#114828)

* 378387b when getting xcworkspace, exclude hidden files (flutter/flutter#114099)

* e901832 4e03d059d [Android] Speed up the method 'FlutterRenderer.getBitmap' (flutter/engine#37342) (flutter/flutter#114833)

* 3cde69e Revert "Revert "Scribble mixin (#104128)" (#114647)" (flutter/flutter#114698)

* e1adc96 feat: provide a way to set the initial child's alignment (flutter/flutter#114745)

* fe5eb2d ee48c0392 Roll Fuchsia Mac SDK from 5XOj9l5e2wkSpMKT1... to sa5bVGimNo3JwLV27... (flutter/engine#37386) (flutter/flutter#114836)

* 5628ebf [RawKeyboard] Allow inconsistent modifiers for Web (flutter/flutter#114499)

* f1cdfa2 Use AppBar.systemOverlayStyle to style system navigation bar (flutter/flutter#104827)

* e4e902d [flutter_tools] add compilation failure tests for new cases added in impellerc (flutter/flutter#114757)

* 7640f31 a81a715ce Revert "Remove deprecated calls to updateSemantics in `PlatformDispatcher` (#36673)" (flutter/engine#37388) (flutter/flutter#114842)

* 585d445 Roll Flutter Engine from a81a715ce6b2 to df602070ac4b (3 revisions) (flutter/flutter#114847)

* 1ca2e0b Fix `CastError` in `StadiumBorder.lerpTo` and  `StadiumBorder.lerpFrom` when using `BorderRadiusDirectional` (flutter/flutter#114826)

* 2e85e74 004a30516 [fuchsia] embedding-flutter test (flutter/engine#37052) (flutter/flutter#114854)

* 139b8f4 Roll Flutter Engine from 004a305166d5 to e7d7edab98ad (2 revisions) (flutter/flutter#114855)

* 53e6876 Allow Flutter golden file tests to be flaky (flutter/flutter#114450)

* a1432a9 Refactor fix_data.yaml (flutter/flutter#114192)
naudzghebre pushed a commit to naudzghebre/engine that referenced this pull request Nov 9, 2022
IVLIVS-III pushed a commit to IVLIVS-III/flutter_plugins_fork that referenced this pull request Nov 11, 2022
* 04d6fd2 Roll Plugins from a279b9d to 3ca3410 (4 revisions) (flutter/flutter#114813)

* 151c831 92d9ad27f Roll Skia from 513f0fd34590 to da9fad017aee (2 revisions) (flutter/engine#37379) (flutter/flutter#114816)

* d6a8e92 Revert "Adds support for the Material Badge widget, BadgeTheme, BadgeThemeData (#114560)" (flutter/flutter#114819)

* 7de60bb 334549704 Roll buildroot to d13d64086f5e301bd0415eede895b34af220ef42 (flutter/engine#37380) (flutter/flutter#114821)

* 496cf62 Delegate TestWindow.updateSemantics to the wrapped SingletonFlutterWindow (flutter/flutter#114733)

* 497a528 Fix TextField/CupertinoTextField hint style overflow not work. (flutter/flutter#114335)

* 7e36cf1 Mac Page Up / Page Down in text fields (flutter/flutter#105497)

* 77c06c2 0075e10bc Move gclient var property to ci.yaml (flutter/engine#37351) (flutter/flutter#114828)

* 378387b when getting xcworkspace, exclude hidden files (flutter/flutter#114099)

* e901832 4e03d059d [Android] Speed up the method 'FlutterRenderer.getBitmap' (flutter/engine#37342) (flutter/flutter#114833)

* 3cde69e Revert "Revert "Scribble mixin (#104128)" (#114647)" (flutter/flutter#114698)

* e1adc96 feat: provide a way to set the initial child's alignment (flutter/flutter#114745)

* fe5eb2d ee48c0392 Roll Fuchsia Mac SDK from 5XOj9l5e2wkSpMKT1... to sa5bVGimNo3JwLV27... (flutter/engine#37386) (flutter/flutter#114836)

* 5628ebf [RawKeyboard] Allow inconsistent modifiers for Web (flutter/flutter#114499)

* f1cdfa2 Use AppBar.systemOverlayStyle to style system navigation bar (flutter/flutter#104827)

* e4e902d [flutter_tools] add compilation failure tests for new cases added in impellerc (flutter/flutter#114757)

* 7640f31 a81a715ce Revert "Remove deprecated calls to updateSemantics in `PlatformDispatcher` (#36673)" (flutter/engine#37388) (flutter/flutter#114842)

* 585d445 Roll Flutter Engine from a81a715ce6b2 to df602070ac4b (3 revisions) (flutter/flutter#114847)

* 1ca2e0b Fix `CastError` in `StadiumBorder.lerpTo` and  `StadiumBorder.lerpFrom` when using `BorderRadiusDirectional` (flutter/flutter#114826)

* 2e85e74 004a30516 [fuchsia] embedding-flutter test (flutter/engine#37052) (flutter/flutter#114854)

* 139b8f4 Roll Flutter Engine from 004a305166d5 to e7d7edab98ad (2 revisions) (flutter/flutter#114855)

* 53e6876 Allow Flutter golden file tests to be flaky (flutter/flutter#114450)

* a1432a9 Refactor fix_data.yaml (flutter/flutter#114192)
schwa423 pushed a commit to schwa423/engine that referenced this pull request Nov 16, 2022
adam-harwood pushed a commit to adam-harwood/flutter_plugins that referenced this pull request Nov 21, 2022
* 04d6fd2 Roll Plugins from a279b9d to 3ca3410 (4 revisions) (flutter/flutter#114813)

* 151c831 92d9ad27f Roll Skia from 513f0fd34590 to da9fad017aee (2 revisions) (flutter/engine#37379) (flutter/flutter#114816)

* d6a8e92 Revert "Adds support for the Material Badge widget, BadgeTheme, BadgeThemeData (#114560)" (flutter/flutter#114819)

* 7de60bb 334549704 Roll buildroot to d13d64086f5e301bd0415eede895b34af220ef42 (flutter/engine#37380) (flutter/flutter#114821)

* 496cf62 Delegate TestWindow.updateSemantics to the wrapped SingletonFlutterWindow (flutter/flutter#114733)

* 497a528 Fix TextField/CupertinoTextField hint style overflow not work. (flutter/flutter#114335)

* 7e36cf1 Mac Page Up / Page Down in text fields (flutter/flutter#105497)

* 77c06c2 0075e10bc Move gclient var property to ci.yaml (flutter/engine#37351) (flutter/flutter#114828)

* 378387b when getting xcworkspace, exclude hidden files (flutter/flutter#114099)

* e901832 4e03d059d [Android] Speed up the method 'FlutterRenderer.getBitmap' (flutter/engine#37342) (flutter/flutter#114833)

* 3cde69e Revert "Revert "Scribble mixin (#104128)" (#114647)" (flutter/flutter#114698)

* e1adc96 feat: provide a way to set the initial child's alignment (flutter/flutter#114745)

* fe5eb2d ee48c0392 Roll Fuchsia Mac SDK from 5XOj9l5e2wkSpMKT1... to sa5bVGimNo3JwLV27... (flutter/engine#37386) (flutter/flutter#114836)

* 5628ebf [RawKeyboard] Allow inconsistent modifiers for Web (flutter/flutter#114499)

* f1cdfa2 Use AppBar.systemOverlayStyle to style system navigation bar (flutter/flutter#104827)

* e4e902d [flutter_tools] add compilation failure tests for new cases added in impellerc (flutter/flutter#114757)

* 7640f31 a81a715ce Revert "Remove deprecated calls to updateSemantics in `PlatformDispatcher` (#36673)" (flutter/engine#37388) (flutter/flutter#114842)

* 585d445 Roll Flutter Engine from a81a715ce6b2 to df602070ac4b (3 revisions) (flutter/flutter#114847)

* 1ca2e0b Fix `CastError` in `StadiumBorder.lerpTo` and  `StadiumBorder.lerpFrom` when using `BorderRadiusDirectional` (flutter/flutter#114826)

* 2e85e74 004a30516 [fuchsia] embedding-flutter test (flutter/engine#37052) (flutter/flutter#114854)

* 139b8f4 Roll Flutter Engine from 004a305166d5 to e7d7edab98ad (2 revisions) (flutter/flutter#114855)

* 53e6876 Allow Flutter golden file tests to be flaky (flutter/flutter#114450)

* a1432a9 Refactor fix_data.yaml (flutter/flutter#114192)
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
* 04d6fd2 Roll Plugins from a279b9d to 3ca3410 (4 revisions) (flutter/flutter#114813)

* 151c831 92d9ad27f Roll Skia from 513f0fd34590 to da9fad017aee (2 revisions) (flutter/engine#37379) (flutter/flutter#114816)

* d6a8e92 Revert "Adds support for the Material Badge widget, BadgeTheme, BadgeThemeData (#114560)" (flutter/flutter#114819)

* 7de60bb 334549704 Roll buildroot to d13d64086f5e301bd0415eede895b34af220ef42 (flutter/engine#37380) (flutter/flutter#114821)

* 496cf62 Delegate TestWindow.updateSemantics to the wrapped SingletonFlutterWindow (flutter/flutter#114733)

* 497a528 Fix TextField/CupertinoTextField hint style overflow not work. (flutter/flutter#114335)

* 7e36cf1 Mac Page Up / Page Down in text fields (flutter/flutter#105497)

* 77c06c2 0075e10bc Move gclient var property to ci.yaml (flutter/engine#37351) (flutter/flutter#114828)

* 378387b when getting xcworkspace, exclude hidden files (flutter/flutter#114099)

* e901832 4e03d059d [Android] Speed up the method 'FlutterRenderer.getBitmap' (flutter/engine#37342) (flutter/flutter#114833)

* 3cde69e Revert "Revert "Scribble mixin (#104128)" (#114647)" (flutter/flutter#114698)

* e1adc96 feat: provide a way to set the initial child's alignment (flutter/flutter#114745)

* fe5eb2d ee48c0392 Roll Fuchsia Mac SDK from 5XOj9l5e2wkSpMKT1... to sa5bVGimNo3JwLV27... (flutter/engine#37386) (flutter/flutter#114836)

* 5628ebf [RawKeyboard] Allow inconsistent modifiers for Web (flutter/flutter#114499)

* f1cdfa2 Use AppBar.systemOverlayStyle to style system navigation bar (flutter/flutter#104827)

* e4e902d [flutter_tools] add compilation failure tests for new cases added in impellerc (flutter/flutter#114757)

* 7640f31 a81a715ce Revert "Remove deprecated calls to updateSemantics in `PlatformDispatcher` (#36673)" (flutter/engine#37388) (flutter/flutter#114842)

* 585d445 Roll Flutter Engine from a81a715ce6b2 to df602070ac4b (3 revisions) (flutter/flutter#114847)

* 1ca2e0b Fix `CastError` in `StadiumBorder.lerpTo` and  `StadiumBorder.lerpFrom` when using `BorderRadiusDirectional` (flutter/flutter#114826)

* 2e85e74 004a30516 [fuchsia] embedding-flutter test (flutter/engine#37052) (flutter/flutter#114854)

* 139b8f4 Roll Flutter Engine from 004a305166d5 to e7d7edab98ad (2 revisions) (flutter/flutter#114855)

* 53e6876 Allow Flutter golden file tests to be flaky (flutter/flutter#114450)

* a1432a9 Refactor fix_data.yaml (flutter/flutter#114192)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants