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

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

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