Repository navigation
Conversation
17a1012 to
b28423d
Compare
ivovandongen
left a comment
There was a problem hiding this comment.
@tobrun I did a first review. There are a couple of issues that need to be addressed. Sorry for the "From mbgl::RendererBackend" comment in the header. This is misleading as it is not true anymore... :(
| @@ -184,21 +184,32 @@ void onPostMapReady() { | |||
| /** | |||
| * Called when the region is changing or has changed. | |||
There was a problem hiding this comment.
Is this javadoc still correct?
| nativeMapView.setReachability(ConnectivityReceiver.instance(context).isConnected(context)); | ||
|
|
||
| // bind internal components for map change events | ||
| mapChangeDispatcher.bind(mapCallback = new MapChangeResultHandler(mapboxMap)); |
There was a problem hiding this comment.
Would it somehow be feasible to make this a constructor argument? Since it is required. That would make it possible to skip a lot of null checks in MapChangeDispatcher
There was a problem hiding this comment.
Been looking into it but don't think so at the moment though this clearly shows we need to rethink our architecture. The issue here is a cyclic class dependency: NativeMapview depends on MapChangeDispatcher, MapboxMap depends on NativeMapView and MapChangeDispatcher depends on MapboxMap.
Somewhere during initialization we need to bind them together and require us to have null checking. Current setup follows the requirement of being able to listen to map change events as soon as possible. I don't see an a issue with internal components missing out on the initialization change events.
| namespace mbgl { | ||
| namespace android { | ||
|
|
||
| NativeMapView::NativeMapView(jni::JNIEnv& _env, |
There was a problem hiding this comment.
Could you revert indentation changes?
| : javaPeer(_obj.NewWeakGlobalRef(_env)), | ||
| pixelRatio(_pixelRatio), | ||
| threadPool(sharedThreadPool()) { | ||
| : javaPeer(_obj.NewWeakGlobalRef(_env)), |
| * From mbgl::RendererBackend. | ||
| */ | ||
| gl::ProcAddress NativeMapView::initializeExtension(const char* name) { | ||
| gl::ProcAddress NativeMapView::initializeExtension(const char *name) { |
| * | ||
| * May be called from any thread | ||
| */ | ||
| void NativeMapView::notifyMapChange(mbgl::MapChange change) { |
There was a problem hiding this comment.
Please also remove the declaration here: https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/src/native_map_view.hpp#L67
| void NativeMapView::onDidFailLoadingMap(std::exception_ptr eptr) { | ||
| assert(vm != nullptr); | ||
| try { | ||
| std::rethrow_exception(eptr); |
There was a problem hiding this comment.
Do we want to throw an exception here? Seems like we always want to invoke the listener. If re-throwing is required, it should happen where the exception is produced.
There was a problem hiding this comment.
rethrowing was a way of getting the string message for the listener, let me try a different approach.
There was a problem hiding this comment.
the exception is produced in core in style_impl.cpp and passed to the MapObserver, which invokes the method above. Don't think I can move re-throwing up the chain as it would impact other bindings. The code for retrieving the exception message was based of http://en.cppreference.com/w/cpp/error/exception_ptr.
There was a problem hiding this comment.
No, you're right. That's a valid way to do it. Should've read more carefully.
|
|
||
| /** | ||
| * From mbgl::RendererBackend. Callback to java NativeMapView#onMapChanged(int). | ||
| * From mbgl::RendererBackend. Callback to java NativeMapView#onCameraWillChange(). |
There was a problem hiding this comment.
Actually. This is from MapObserver and will only be coming from the main (map) thread. Could you update the comment in the header file as well?
| void NativeMapView::onCameraIsChanging() { | ||
| notifyMapChange(MapChange::MapChangeRegionIsChanging); | ||
| assert(vm != nullptr); | ||
| android::UniqueEnv _env = android::AttachEnv(); |
There was a problem hiding this comment.
As this is not actually coming from any other thread then the main/map thread, this is not needed.
There was a problem hiding this comment.
I changed it to something as:
void NativeMapView::onDidFinishLoadingStyle() {
JNIEnv* env = nullptr;
int resultCode = vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
if(resultCode == JNI_OK) {
static auto onDidFinishLoadingStyle = javaClass.GetMethod<void()>(*env, "onDidFinishLoadingStyle");
javaPeer->Call(*env, onDidFinishLoadingStyle);
}
}
lmk if there is a better way of getting the env
| _createSurface(ANativeWindow_fromSurface(&env, jni::Unwrap(*_surface))); | ||
| } | ||
|
|
||
| void NativeMapView::destroySurface(jni::JNIEnv&) { |
There was a problem hiding this comment.
more formatting changes
3bf83d2 to
6122934
Compare
6122934 to
24b95fc
Compare
8dea25d to
be86668
Compare
|
I redid this PR in light of moving to GLSurfaceView (reason this PR was on hold).
|
ivovandongen
left a comment
There was a problem hiding this comment.
Looks good. The only thing is that I found the naming of MapChangeHandler and MapChangeDispatcher a little confusing while reading the PR. But since neither is public that will probably not be a problem.
| void NativeMapView::onDidFailLoadingMap(std::exception_ptr eptr) { | ||
| try { | ||
| if(eptr) { | ||
| std::rethrow_exception(eptr); |
There was a problem hiding this comment.
be86668 to
9e9f999
Compare
|
Thank you for the review @ivovandongen, |
9e9f999 to
8847b41
Compare
|
stale |
This PR deprecates using OnMapChangeListeners and replaces them with dedicated callbacks.
onMapFailedLoadedwith the thrown error messageonSourceChangedcallback to provide source/attribution that has changedProposed API:
Closes #8389 / refs #9476