Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Android: use system-provided image decoding + encoding - #7828

Merged
kkaefer merged 2 commits into
masterfrom
android-bitmap-decoding
Jan 27, 2017
Merged

kkaefer merged 2 commits into
masterfrom
android-bitmap-decoding

Conversation

@kkaefer

@kkaefer kkaefer commented Jan 24, 2017

Copy link
Copy Markdown
Member

Another take at #7329.

  • Removes libjpeg-turbo and libpng in favor of calls to BitmapFactory.decodeByteArray. We're doing a bunch of copies, but I don't think we can avoid any of them. I implemented a version that used java.nio.ByteBuffer and supplying the pointer address directly, but Java can't generate a byte[] required for decodeByteArray. We could alternatively implement a NativeInputStream (similar to the NativeOutputStream contained in this PR) and use BitmapFactory.decodeStream to avoid one copy. We are doing a second copy from the decoded Bitmap object to memory we manage ourselves (using libjnigraphics. Instead, we could completely replace util::Image for android builds with a version that keeps around the Bitmap object and keeps the pixels locked so they don't go away.
  • Removes indirection for the snapshot functionality: Previously, we were compressing to a PNG, only to decompress to a Bitmap object right away. Instead, we're now directly converting the raw C++ PremultipliedImage to a Java Bitmap object. This reduces the snapshotting time on my test device from ~550ms to ~80ms.

Build size for Release/arm-v8 drops from 5620 KB to 5259 KB.

Fixes #7329, #6238.

@kkaefer
kkaefer requested review from jfirebaugh and tobrun January 24, 2017 15:46
@mention-bot

Copy link
Copy Markdown

@kkaefer, thanks for your PR! By analyzing this pull request, we identified @jfirebaugh, @zugaldia and @1ec5 to be potential reviewers.

@kkaefer
kkaefer force-pushed the android-bitmap-decoding branch from 9a696ac to 8df51f1 Compare January 24, 2017 15:53
@kkaefer

kkaefer commented Jan 24, 2017

Copy link
Copy Markdown
Member Author

Implementing a native InputStream also requires a copy.

kkaefer added a commit that referenced this pull request Jan 24, 2017
rationale: encodePNG is only used in tests + sample apps, but shouldn't actually be part of the core library. In #7828, we're removing the libpng dependency for Android, and using a libpng-free version of encodePNG allows us to run the core unit tests on Android without pulling in libpng just for the test suite. In a next step, we should remove encodePNG() from the image.hpp header, which is a public header.
@jfirebaugh

Copy link
Copy Markdown
Contributor

Decoding part looks good. For the encoding part, I like the solution in #7813 better, given that it is only used in tests.

@kkaefer

kkaefer commented Jan 24, 2017

Copy link
Copy Markdown
Member Author

@jfirebaugh yeah, plan is to get #7318 in first, then remove encoding from this PR.

kkaefer added a commit that referenced this pull request Jan 25, 2017
rationale: encodePNG is only used in tests + sample apps, but shouldn't actually be part of the core library. In #7828, we're removing the libpng dependency for Android, and using a libpng-free version of encodePNG allows us to run the core unit tests on Android without pulling in libpng just for the test suite. In a next step, we should remove encodePNG() from the image.hpp header, which is a public header.
@kkaefer
kkaefer force-pushed the android-bitmap-decoding branch from 8df51f1 to 39ce9bb Compare January 26, 2017 14:07
…set up an Android runtime environment

Instead of mocking android.util.Log, we're registering the real libraries so that we can use the full runtime environment
@kkaefer
kkaefer force-pushed the android-bitmap-decoding branch from 39ce9bb to 883e46c Compare January 26, 2017 14:32
@kkaefer

kkaefer commented Jan 26, 2017

Copy link
Copy Markdown
Member Author

Read for review

// We're declaring the function, which is libandroid_runtime.so.
// It is defined in AndroidRuntime.cpp:
// https://github.com/android/platform_frameworks_base/blob/master/core/jni/AndroidRuntime.cpp
// Once this symbol goes away, we'll have to revisit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this symbol goes away, the Mapbox GL SDK will start failing, right? It would be worse than a build time failure -- existing installations might stop working after an OS or software upgrade.

If this is not a public API, let's find a different way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This file is not part of the SDK; it is only used to bootstrap the core unit tests (with Google Test). If this symbol went away, the only thing that would break is launching the unit tests, but it does not impact in any way the function of a deployed version of Mapbox GL.

I've checked the past couple of Android versions and this symbol remained stable from (at least) 4.4 to 7.0.

@kkaefer
kkaefer merged commit 4d35826 into master Jan 27, 2017
@kkaefer
kkaefer deleted the android-bitmap-decoding branch January 27, 2017 17:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants