Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ run-android-test-app-center:
run-android-upload-to-bintray: gradle/configuration.gradle
$(MBGL_ANDROID_GRADLE) -Pmapbox.abis=all :MapboxGLAndroidSDK:bintrayUpload

.PHONY: run-android-upload-to-nexus
run-android-upload-to-nexus: gradle/configuration.gradle
$(MBGL_ANDROID_GRADLE) -Pmapbox.abis=all :MapboxGLAndroidSDK:publishMapboxMapsSdkPublicationPublicationToNexusRepository

# Uploads the compiled Android SDK SNAPSHOT to oss.jfrog.org
.PHONY: run-android-upload-to-artifactory
run-android-upload-to-artifactory: gradle/configuration.gradle
Expand Down
2 changes: 1 addition & 1 deletion MapboxGLAndroidSDK/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=9.1.0-SNAPSHOT
VERSION_NAME=9.2.1-RC4

# Only build native dependencies for the current ABI
# See https://code.google.com/p/android/issues/detail?id=221098#c20
Expand Down
109 changes: 65 additions & 44 deletions MapboxGLAndroidSDK/src/cpp/map_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/logging.hpp>

#include <string>

Expand Down Expand Up @@ -37,69 +38,89 @@ std::shared_ptr<Mailbox> MapRenderer::MailboxData::getMailbox() const noexcept {
MapRenderer::~MapRenderer() = default;

void MapRenderer::reset() {
destroyed = true;

if (renderer) {
// Make sure to destroy the renderer on the GL Thread
auto self = ActorRef<MapRenderer>(*this, mailboxData.getMailbox());
self.ask(&MapRenderer::resetRenderer).wait();
try {
destroyed = true;

if (renderer) {
// Make sure to destroy the renderer on the GL Thread
auto self = ActorRef<MapRenderer>(*this, mailboxData.getMailbox());
self.ask(&MapRenderer::resetRenderer).wait();
}

// Lock to make sure there is no concurrent initialisation on the gl thread
std::lock_guard<std::mutex> lock(initialisationMutex);
rendererObserver.reset();
} catch (const std::exception& exception) {
Log::Error(Event::Android, "MapRenderer::reset failed: %s", exception.what());
}

// Lock to make sure there is no concurrent initialisation on the gl thread
std::lock_guard<std::mutex> lock(initialisationMutex);
rendererObserver.reset();
}

ActorRef<Renderer> MapRenderer::actor() const {
return *rendererRef;
}

void MapRenderer::schedule(std::function<void()> scheduled) {
// Create a runnable
android::UniqueEnv _env = android::AttachEnv();
auto runnable = std::make_unique<MapRendererRunnable>(*_env, std::move(scheduled));

// Obtain ownership of the peer (gets transferred to the MapRenderer on the JVM for later GC)
auto peer = runnable->peer();

// Queue the event on the Java Peer
static auto& javaClass = jni::Class<MapRenderer>::Singleton(*_env);
static auto queueEvent = javaClass.GetMethod<void(
jni::Object<MapRendererRunnable>)>(*_env, "queueEvent");
auto weakReference = javaPeer.get(*_env);
if (weakReference) {
weakReference.Call(*_env, queueEvent, peer);
try {
// Create a runnable
android::UniqueEnv _env = android::AttachEnv();
auto runnable = std::make_unique<MapRendererRunnable>(*_env, std::move(scheduled));

// Obtain ownership of the peer (gets transferred to the MapRenderer on the JVM for later GC)
auto peer = runnable->peer();

// Queue the event on the Java Peer
static auto& javaClass = jni::Class<MapRenderer>::Singleton(*_env);
static auto queueEvent = javaClass.GetMethod<void(
jni::Object<MapRendererRunnable>)>(*_env, "queueEvent");
auto weakReference = javaPeer.get(*_env);
if (weakReference) {
weakReference.Call(*_env, queueEvent, peer);
}

// Release the c++ peer as it will be destroyed on GC of the Java Peer
runnable.release();
} catch (const std::exception& exception) {
Log::Error(Event::Android, "MapRenderer::schedule failed: %s", exception.what());
}

// Release the c++ peer as it will be destroyed on GC of the Java Peer
runnable.release();
}

void MapRenderer::requestRender() {
android::UniqueEnv _env = android::AttachEnv();
static auto& javaClass = jni::Class<MapRenderer>::Singleton(*_env);
static auto onInvalidate = javaClass.GetMethod<void()>(*_env, "requestRender");
auto weakReference = javaPeer.get(*_env);
if (weakReference) {
weakReference.Call(*_env, onInvalidate);
try {
android::UniqueEnv _env = android::AttachEnv();
static auto& javaClass = jni::Class<MapRenderer>::Singleton(*_env);
static auto onInvalidate = javaClass.GetMethod<void()>(*_env, "requestRender");
auto weakReference = javaPeer.get(*_env);
if (weakReference) {
weakReference.Call(*_env, onInvalidate);
}
} catch (const std::exception& exception) {
Log::Error(Event::Android, "MapRenderer::requestRender failed: %s", exception.what());
}
}

void MapRenderer::update(std::shared_ptr<UpdateParameters> params) {
// Lock on the parameters
std::lock_guard<std::mutex> lock(updateMutex);
updateParameters = std::move(params);
try {
// Lock on the parameters
std::lock_guard<std::mutex> lock(updateMutex);
updateParameters = std::move(params);
} catch (const std::exception& exception) {
Log::Error(Event::Android, "MapRenderer::update failed: %s", exception.what());
}
}

void MapRenderer::setObserver(std::shared_ptr<RendererObserver> _rendererObserver) {
// Lock as the initialization can come from the main thread or the GL thread first
std::lock_guard<std::mutex> lock(initialisationMutex);

rendererObserver = std::move(_rendererObserver);

// Set the new observer on the Renderer implementation
if (renderer) {
renderer->setObserver(rendererObserver.get());
try {
// Lock as the initialization can come from the main thread or the GL thread first
std::lock_guard<std::mutex> lock(initialisationMutex);

rendererObserver = std::move(_rendererObserver);

// Set the new observer on the Renderer implementation
if (renderer) {
renderer->setObserver(rendererObserver.get());
}
} catch (const std::exception& exception) {
Log::Error(Event::Android, "MapRenderer::setObserver failed: %s", exception.what());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ namespace android {
static auto& javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
static auto releaseThreads = javaClass.GetMethod<void ()>(*_env, "releaseThreads");

assert(javaPeer);

auto peer = jni::Cast(*_env, javaClass, javaPeer);
peer.Call(*_env, releaseThreads);
if(javaPeer) {
auto peer = jni::Cast(*_env, javaClass, javaPeer);
peer.Call(*_env, releaseThreads);
}
};

bool CustomGeometrySource::isCancelled(jni::jint z,
Expand Down
6 changes: 5 additions & 1 deletion MapboxGLAndroidSDK/src/cpp/style/sources/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ static std::unique_ptr<Source> createSourcePeer(jni::JNIEnv& env,
}

Source::~Source() {
if (ownedSource) {
ownedSource.reset();
ownedSource.release();
}
// Before being added to a map, the Java peer owns this C++ peer and cleans
// up after itself correctly through the jni native peer bindings.
// After being added to the map, the ownership is flipped and the C++ peer has a strong reference
Expand Down Expand Up @@ -209,7 +213,7 @@ static std::unique_ptr<Source> createSourcePeer(jni::JNIEnv& env,

// Release the strong reference to the java peer
assert(javaPeer);
javaPeer.release();
javaPeer.reset();

rendererFrontend = nullptr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ void feedNewLocation(@NonNull @Size(min = 1) Location[] newLocations,
// replace the animation start with the camera's previous value
latLngValues[0] = previousCameraLatLng;
if (isGpsNorth) {
bearingValues = new Float[] {previousCameraBearing, 0f};
bearingValues = new Float[] {previousCameraBearing, shortestRotation(0f, previousCameraBearing)};
} else {
bearingValues[0] = previousCameraBearing;
bearingValues = getBearingValues(previousCameraBearing, newLocations);
}
updateCameraAnimators(latLngValues, bearingValues);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,21 +530,33 @@ public boolean onTouchEvent(MotionEvent event) {

@Override
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
if (!isKeyDetectorInitialized()) {
return super.onKeyDown(keyCode, event);
}
return mapKeyListener.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
}

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (!isKeyDetectorInitialized()) {
return super.onKeyLongPress(keyCode, event);
}
return mapKeyListener.onKeyLongPress(keyCode, event) || super.onKeyLongPress(keyCode, event);
}

@Override
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
if (!isKeyDetectorInitialized()) {
return super.onKeyUp(keyCode, event);
}
return mapKeyListener.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event);
}

@Override
public boolean onTrackballEvent(@NonNull MotionEvent event) {
if (!isKeyDetectorInitialized()) {
return super.onTrackballEvent(event);
}
return mapKeyListener.onTrackballEvent(event) || super.onTrackballEvent(event);
}

Expand Down Expand Up @@ -1126,6 +1138,10 @@ private boolean isGestureDetectorInitialized() {
return mapGestureDetector != null;
}

private boolean isKeyDetectorInitialized() {
return mapKeyListener != null;
}

@Nullable
MapboxMap getMapboxMap() {
return mapboxMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public final class MapboxMap {
private Style style;

private boolean debugActive;
private boolean started;

MapboxMap(NativeMap map, Transform transform, UiSettings ui, Projection projection,
OnGesturesManagerInteractionListener listener, CameraChangeDispatcher cameraChangeDispatcher,
Expand Down Expand Up @@ -143,13 +144,15 @@ public Style getStyle() {
* Called when the hosting Activity/Fragment onStart() method is called.
*/
void onStart() {
started = true;
locationComponent.onStart();
}

/**
* Called when the hosting Activity/Fragment onStop() method is called.
*/
void onStop() {
started = false;
locationComponent.onStop();
}

Expand Down Expand Up @@ -2003,6 +2006,9 @@ public OnInfoWindowCloseListener getOnInfoWindowCloseListener() {
* @param callback Callback method invoked when the snapshot is taken.
*/
public void snapshot(@NonNull SnapshotReadyCallback callback) {
if (!started) {
return;
}
nativeMapView.addSnapshotCallback(callback);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import android.opengl.GLSurfaceView;
import android.os.Build;

import androidx.annotation.NonNull;

import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.log.Logger;

import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -74,7 +77,6 @@ public EGLConfig chooseConfig(@NonNull EGL10 egl, EGLDisplay display) {
int[] numConfigs = getNumberOfConfigurations(egl, display, configAttribs);
if (numConfigs[0] < 1) {
Logger.e(TAG, "eglChooseConfig() returned no configs.");
throw new EGLConfigException("eglChooseConfig() failed");
}

// Get all possible configurations
Expand All @@ -84,7 +86,6 @@ public EGLConfig chooseConfig(@NonNull EGL10 egl, EGLDisplay display) {
EGLConfig config = chooseBestMatchConfig(egl, display, possibleConfigurations);
if (config == null) {
Logger.e(TAG, "No config chosen");
throw new EGLConfigException("No config chosen");
}

return config;
Expand All @@ -97,7 +98,6 @@ private int[] getNumberOfConfigurations(EGL10 egl, EGLDisplay display, int[] con
Logger.e(TAG, String.format(
MapboxConstants.MAPBOX_LOCALE, "eglChooseConfig(NULL) returned error %d", egl.eglGetError())
);
throw new EGLConfigException("eglChooseConfig() failed");
}
return numConfigs;
}
Expand All @@ -110,7 +110,6 @@ private EGLConfig[] getPossibleConfigurations(EGL10 egl, EGLDisplay display,
Logger.e(TAG, String.format(
MapboxConstants.MAPBOX_LOCALE, "eglChooseConfig() returned error %d", egl.eglGetError())
);
throw new EGLConfigException("eglChooseConfig() failed");
}
return configs;
}
Expand Down Expand Up @@ -255,7 +254,8 @@ public int compareTo(@NonNull Config other) {
Collections.sort(matches);

if (matches.size() == 0) {
throw new EGLConfigException("No matching configurations after filtering");
Logger.e(TAG, "No matching configurations after filtering");
return null;
}

Config bestMatch = matches.get(0);
Expand All @@ -277,7 +277,6 @@ private int getConfigAttr(EGL10 egl, EGLDisplay display, EGLConfig config, int a
Logger.e(TAG, String.format(
MapboxConstants.MAPBOX_LOCALE, "eglGetConfigAttrib(%d) returned error %d", attributeName, egl.eglGetError())
);
throw new EGLConfigException("eglGetConfigAttrib() failed");
}
return attributevalue[0];
}
Expand Down

This file was deleted.

Loading