diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-06-27 17:04:09 -0700 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-07-18 10:45:12 +0200 |
commit | d68d8a7846ef0b4d06c31e0ed451b31354a7dec9 (patch) | |
tree | 8236d0ce48b0d90baab947e044ce3a61aa9a615b /platform/android/src/native_map_view.cpp | |
parent | b6d56ad634e2b3048e97bedd9f674aa4ec975453 (diff) | |
download | qtlocation-mapboxgl-d68d8a7846ef0b4d06c31e0ed451b31354a7dec9.tar.gz |
[android] rendering interface changes
Diffstat (limited to 'platform/android/src/native_map_view.cpp')
-rwxr-xr-x | platform/android/src/native_map_view.cpp | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 986cc73f0b..5faad75d5d 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -28,6 +28,7 @@ #include <mbgl/style/style.hpp> #include <mbgl/style/image.hpp> #include <mbgl/style/filter.hpp> +#include <mbgl/renderer/renderer.hpp> // Java -> C++ conversion #include "style/android_conversion.hpp" @@ -42,6 +43,7 @@ #include "jni.hpp" #include "attach_env.hpp" +#include "android_renderer_frontend.hpp" #include "bitmap.hpp" #include "run_loop_impl.hpp" #include "java/util.hpp" @@ -67,12 +69,23 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env, return; } + auto& fileSource = mbgl::android::FileSource::getDefaultFileSource(_env, jFileSource); + + // Create a renderer + auto renderer = std::make_unique<Renderer>(*this, pixelRatio, fileSource, *threadPool, + GLContextMode::Unique, + jni::Make<std::string>(_env, _programCacheDir)); + + // Create a renderer frontend + rendererFrontend = std::make_unique<AndroidRendererFrontend>(std::move(renderer), + [this] { this->invalidate(); }); + // Create the core map - map = std::make_unique<mbgl::Map>( - *this, *this, mbgl::Size{ static_cast<uint32_t>(width), static_cast<uint32_t>(height) }, - pixelRatio, mbgl::android::FileSource::getDefaultFileSource(_env, jFileSource), *threadPool, - MapMode::Continuous, GLContextMode::Unique, ConstrainMode::HeightOnly, - ViewportMode::Default, jni::Make<std::string>(_env, _programCacheDir)); + map = std::make_unique<mbgl::Map>(*rendererFrontend, *this, + mbgl::Size{ static_cast<uint32_t>(width), + static_cast<uint32_t>(height) }, pixelRatio, + fileSource, *threadPool, MapMode::Continuous, + ConstrainMode::HeightOnly, ViewportMode::Default); } /** @@ -273,14 +286,14 @@ void NativeMapView::destroySurface(jni::JNIEnv&) { } void NativeMapView::render(jni::JNIEnv& env) { - BackendScope guard(*this); + BackendScope guard { *this }; if (framebufferSizeChanged) { setViewport(0, 0, getFramebufferSize()); framebufferSizeChanged = false; } - map->render(*this); + rendererFrontend->render(*this); if(snapshot){ snapshot = false; @@ -587,7 +600,7 @@ jni::Array<jni::jlong> NativeMapView::addMarkers(jni::JNIEnv& env, jni::Array<jn } void NativeMapView::onLowMemory(JNIEnv&) { - map->onLowMemory(); + rendererFrontend->onLowMemory(); } using DebugOptions = mbgl::MapDebugOptions; @@ -758,7 +771,7 @@ jni::Array<jlong> NativeMapView::queryPointAnnotations(JNIEnv& env, jni::Object< }; // Assume only points for now - mbgl::AnnotationIDs ids = map->queryPointAnnotations(box); + mbgl::AnnotationIDs ids = rendererFrontend->queryPointAnnotations(box); // Convert result std::vector<jlong> longIds(ids.begin(), ids.end()); @@ -780,7 +793,9 @@ jni::Array<jni::Object<geojson::Feature>> NativeMapView::queryRenderedFeaturesFo } mapbox::geometry::point<double> point = {x, y}; - return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, map->queryRenderedFeatures(point, { layers, toFilter(env, jfilter) })); + return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>( + env, + rendererFrontend->queryRenderedFeatures(point, { layers, toFilter(env, jfilter) })); } jni::Array<jni::Object<geojson::Feature>> NativeMapView::queryRenderedFeaturesForBox(JNIEnv& env, jni::jfloat left, jni::jfloat top, @@ -798,7 +813,9 @@ jni::Array<jni::Object<geojson::Feature>> NativeMapView::queryRenderedFeaturesFo mapbox::geometry::point<double>{ right, bottom } }; - return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, map->queryRenderedFeatures(box, { layers, toFilter(env, jfilter) })); + return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>( + env, + rendererFrontend->queryRenderedFeatures(box, { layers, toFilter(env, jfilter) })); } jni::Object<Light> NativeMapView::getLight(JNIEnv& env) { @@ -966,7 +983,7 @@ jni::Array<jni::Object<Source>> NativeMapView::getSources(JNIEnv& env) { jni::Array<jni::Object<Source>> jSources = jni::Array<jni::Object<Source>>::New(env, sources.size(), Source::javaClass); int index = 0; for (auto source : sources) { - auto jSource = jni::Object<Source>(createJavaSourcePeer(env, *map, *source)); + auto jSource = jni::Object<Source>(createJavaSourcePeer(env, *rendererFrontend, *source)); jSources.Set(env, index, jSource); jni::DeleteLocalRef(env, jSource); index++; @@ -984,7 +1001,7 @@ jni::Object<Source> NativeMapView::getSource(JNIEnv& env, jni::String sourceId) } // Create and return the source's native peer - return jni::Object<Source>(createJavaSourcePeer(env, *map, *coreSource)); + return jni::Object<Source>(createJavaSourcePeer(env, *rendererFrontend, *coreSource)); } void NativeMapView::addSource(JNIEnv& env, jni::jlong sourcePtr) { @@ -993,6 +1010,7 @@ void NativeMapView::addSource(JNIEnv& env, jni::jlong sourcePtr) { Source *source = reinterpret_cast<Source *>(sourcePtr); try { source->addToMap(*map); + source->setRendererFrontend(*rendererFrontend); } catch (const std::runtime_error& error) { jni::ThrowNew(env, jni::FindClass(env, "com/mapbox/mapboxsdk/style/sources/CannotAddSourceException"), error.what()); } @@ -1001,7 +1019,7 @@ void NativeMapView::addSource(JNIEnv& env, jni::jlong sourcePtr) { jni::Object<Source> NativeMapView::removeSourceById(JNIEnv& env, jni::String id) { std::unique_ptr<mbgl::style::Source> coreSource = map->getStyle().removeSource(jni::Make<std::string>(env, id)); if (coreSource) { - return jni::Object<Source>(createJavaSourcePeer(env, *map, *coreSource)); + return jni::Object<Source>(createJavaSourcePeer(env, *rendererFrontend, *coreSource)); } else { return jni::Object<Source>(); } |