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

Rewire map initialisation#9462

Merged
tobrun merged 1 commit into
masterfrom
9136-post-mapboxmap
Jul 19, 2017
Merged

Rewire map initialisation#9462
tobrun merged 1 commit into
masterfrom
9136-post-mapboxmap

Conversation

@tobrun
Copy link
Copy Markdown
Member

@tobrun tobrun commented Jul 10, 2017

This PR rewrites the way we do map initialisation. Before this PR we created the map object when the hosting MapView was inflated. This PR now postpones creating the map object until the Surface of the MapView is ready. A benefit of this is that the view will be measured by the time that MapboxMap will be created and thus removes the necessity of posting the OnMapReadyCallback invocations.

Closes #9136

@tobrun tobrun added the Android Mapbox Maps SDK for Android label Jul 10, 2017
@tobrun tobrun added this to the android-v5.2.0 milestone Jul 10, 2017
@tobrun tobrun requested a review from ivovandongen July 10, 2017 10:50
@tobrun tobrun force-pushed the 9136-post-mapboxmap branch 2 times, most recently from 4b2720c to 774ab89 Compare July 10, 2017 13:10

// JNI //

void destroy(jni::JNIEnv&);
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 was unused, we are using the destructor of native_map_view for this

ViewportMode::Default, jni::Make<std::string>(_env, _programCacheDir));

_initializeDisplay();
_initializeContext();
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.

current codebase always requires to have one map object for one display/context. This is now consolidated in the constructor of the map object. This as a result removes NativeMapView::initializeDisplay, NativeMapView::terminateDisplay, ....

private final float pixelRatio;

// Listeners for Map change events
private CopyOnWriteArrayList<MapView.OnMapChangedListener> onMapChangedListeners;
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.

postponing map creation requires to manage OnMapChangeListeners in MapView.java instead.

public void onMapChanged(@MapChange int change) {
if (change == DID_FINISH_LOADING_STYLE && initialLoad) {
initialLoad = false;
new Handler().post(new Runnable() {
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 resolves a memory leak when quickly rotating the device on map start.

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.

This does change the timing of the event a little though. The handler ensured that it was fired after the current loop cycle. Not sure if that is a big deal.

Copy link
Copy Markdown
Member Author

@tobrun tobrun Jul 18, 2017

Choose a reason for hiding this comment

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

afaik, we posted to the end of message queue to make sure the view was measured (to be able to initialize all components with correct width/height) . Now with this PR, we postpone map creation and thus style loading to after onResume (when the view is toggled visible). Can't really think of another reason why we needed that post there?

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.

Ok. Just noting. As long as the tests succeed it shouldn't be a big deal.

}

if (nativeMapView == null) {
mapboxMapOptions.styleUrl(url);
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.

keeping state in mapboxMapOptions is map isn't ready yet, this will be applied to the map when started later on.

Copy link
Copy Markdown
Contributor

@ivovandongen ivovandongen left a comment

Choose a reason for hiding this comment

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

There are quite a few unrelated changes in this pr (removing #includes). Could you separate those if they are intentional?

@tobrun tobrun force-pushed the 9136-post-mapboxmap branch from 774ab89 to b4aebb5 Compare July 11, 2017 08:57
@tobrun tobrun self-assigned this Jul 11, 2017
@tobrun tobrun force-pushed the 9136-post-mapboxmap branch 4 times, most recently from 58a9746 to 96c11f4 Compare July 18, 2017 16:05
@tobrun tobrun force-pushed the 9136-post-mapboxmap branch from 96c11f4 to d52030c Compare July 18, 2017 16:08
@tobrun
Copy link
Copy Markdown
Member Author

tobrun commented Jul 18, 2017

There are quite a few unrelated changes in this pr (removing #includes). Could you separate those if they are intentional?

I removed the cpp cleanup from this PR

ConstrainMode::HeightOnly, ViewportMode::Default);

// initialize egl components
_initializeDisplay();
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.

The only problem I see here is that when we move to rendering on a separate thread, these should probably not be called from the main thread. But we can adjust to that lateron.

@tobrun tobrun mentioned this pull request Nov 3, 2017
21 tasks
This was referenced Nov 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Android Mapbox Maps SDK for Android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants