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

Rewire map initialisation #9462

Merged
merged 1 commit into from
Jul 19, 2017
Merged

Rewire map initialisation #9462

merged 1 commit into from
Jul 19, 2017

Conversation

tobrun
Copy link
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
@@ -81,8 +81,6 @@ class NativeMapView : public View, public Backend {

// JNI //

void destroy(jni::JNIEnv&);
Copy link
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

@@ -73,6 +55,9 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env,
pixelRatio, mbgl::android::FileSource::getDefaultFileSource(_env, jFileSource), *threadPool,
MapMode::Continuous, GLContextMode::Unique, ConstrainMode::HeightOnly,
ViewportMode::Default, jni::Make<std::string>(_env, _programCacheDir));

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

@@ -57,9 +56,6 @@
// Device density
private final float pixelRatio;

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

this.mapboxMap = mapboxMap;
}

@Override
public void onMapChanged(@MapChange int change) {
if (change == DID_FINISH_LOADING_STYLE && initialLoad) {
initialLoad = false;
new Handler().post(new Runnable() {
Copy link
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
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
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
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.

@@ -384,7 +391,10 @@ public void setStyleUrl(@NonNull String url) {
if (destroyed) {
return;
}

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

@@ -86,6 +86,10 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env,
static_cast<uint32_t>(height) }, pixelRatio,
fileSource, *threadPool, MapMode::Continuous,
ConstrainMode::HeightOnly, ViewportMode::Default);

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

2 participants