diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp index 188a1aee0..2c7e75778 100644 --- a/android/cpp/jni.cpp +++ b/android/cpp/jni.cpp @@ -290,7 +290,7 @@ void JNICALL nativeResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint assert(fbWidth <= UINT16_MAX); assert(fbHeight <= UINT16_MAX); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - nativeMapView->resize(width, height, ratio, fbWidth, fbHeight); + nativeMapView->getMap().resize(width, height, ratio); } void JNICALL nativeRemoveClass(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring clazz) { diff --git a/android/cpp/native_map_view.cpp b/android/cpp/native_map_view.cpp index 6eb6628a6..325484ec7 100644 --- a/android/cpp/native_map_view.cpp +++ b/android/cpp/native_map_view.cpp @@ -800,9 +800,5 @@ void NativeMapView::updateFps() { env = nullptr; } -void NativeMapView::resize(uint16_t width, uint16_t height, float ratio, uint16_t, uint16_t) { - map.resize(width, height, ratio); -} - } } diff --git a/include/mbgl/android/native_map_view.hpp b/include/mbgl/android/native_map_view.hpp index 059f4b111..a050ad149 100644 --- a/include/mbgl/android/native_map_view.hpp +++ b/include/mbgl/android/native_map_view.hpp @@ -45,8 +45,6 @@ public: void enableFps(bool enable); void updateFps(); - void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight); - private: EGLConfig chooseConfig(const EGLConfig configs[], EGLint numConfigs); diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp index b73629016..41d57bdc9 100644 --- a/include/mbgl/map/view.hpp +++ b/include/mbgl/map/view.hpp @@ -40,6 +40,9 @@ public: virtual void notify() = 0; + // Called from the render thread. The implementation should resize the framebuffer. + virtual void resize(uint16_t width, uint16_t height, float pixelRatio); + // Called from the render thread. The implementation must trigger a rerender. // (i.e. either the passed render() function for rendering immediately on the map thread, // or map->renderSync() from the main thread must be called as a result of this) diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp index a0a3847c8..66f13cf5b 100644 --- a/include/mbgl/platform/default/headless_view.hpp +++ b/include/mbgl/platform/default/headless_view.hpp @@ -29,11 +29,10 @@ public: HeadlessView(std::shared_ptr display, uint16_t width = 256, uint16_t height = 256, float pixelRatio = 1); ~HeadlessView(); - void resize(uint16_t width, uint16_t height, float pixelRatio); - void activate() override; void deactivate() override; void notify() override; + void resize(uint16_t width, uint16_t height, float pixelRatio) override; void invalidate(std::function render) override; std::unique_ptr readStillImage() override; diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index 549c16d8c..35c796e92 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -41,7 +41,9 @@ namespace mbgl { HeadlessView::HeadlessView(uint16_t width, uint16_t height, float pixelRatio) : display(std::make_shared()) { + activate(); resize(width, height, pixelRatio); + deactivate(); } HeadlessView::HeadlessView(std::shared_ptr display_, @@ -49,7 +51,9 @@ HeadlessView::HeadlessView(std::shared_ptr display_, uint16_t height, float pixelRatio) : display(display_) { + activate(); resize(width, height, pixelRatio); + deactivate(); } void HeadlessView::loadExtensions() { @@ -155,8 +159,6 @@ HeadlessView::Dimensions::Dimensions(uint16_t width_, uint16_t height_, float pi } void HeadlessView::resize(const uint16_t width, const uint16_t height, const float pixelRatio) { - activate(); - dimensions = { width, height, pixelRatio }; clearBuffers(); @@ -197,8 +199,6 @@ void HeadlessView::resize(const uint16_t width, const uint16_t height, const flo } throw std::runtime_error(error.str()); } - - deactivate(); } std::unique_ptr HeadlessView::readStillImage() { diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index c82c2c7c7..6c207c0d5 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -131,7 +131,7 @@ std::string Map::getStyleJSON() const { void Map::resize(uint16_t width, uint16_t height, float ratio) { if (data->transform.resize(width, height, ratio, width * ratio, height * ratio)) { - triggerUpdate(); + context->invoke(&MapContext::resize, width, height, ratio); } } diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 981191140..13fdd085f 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -85,6 +85,11 @@ void MapContext::pause() { view.activate(); } +void MapContext::resize(uint16_t width, uint16_t height, float ratio) { + view.resize(width, height, ratio); + triggerUpdate(); +} + void MapContext::triggerUpdate(const Update u) { updated |= static_cast(u); asyncUpdate->send(); diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp index bdebdb1b6..c56dabf70 100644 --- a/src/mbgl/map/map_context.hpp +++ b/src/mbgl/map/map_context.hpp @@ -43,6 +43,8 @@ public: void pause(); void render(); + void resize(uint16_t width, uint16_t height, float ratio); + // Notifies the Map thread that the state has changed and an update might be necessary. void triggerUpdate(Update = Update::Nothing); diff --git a/src/mbgl/map/view.cpp b/src/mbgl/map/view.cpp index 773f799e8..fb771a8c4 100644 --- a/src/mbgl/map/view.cpp +++ b/src/mbgl/map/view.cpp @@ -11,6 +11,10 @@ void View::initialize(Map *map_) { map = map_; } +void View::resize(uint16_t, uint16_t, float) { + // no-op +} + std::unique_ptr View::readStillImage() { return nullptr; } diff --git a/test/api/repeated_render.cpp b/test/api/repeated_render.cpp index 58df8e83b..ce7e6cbb0 100644 --- a/test/api/repeated_render.cpp +++ b/test/api/repeated_render.cpp @@ -25,7 +25,7 @@ TEST(API, RepeatedRender) { Map map(view, fileSource, MapMode::Still); { - view.resize(128, 512, 1); + map.resize(128, 512, 1); map.setStyleJSON(style, "test/suite"); std::promise> promise; map.renderStill([&promise](std::unique_ptr image) { @@ -39,7 +39,7 @@ TEST(API, RepeatedRender) { } { - view.resize(512, 512, 2); + map.resize(512, 512, 2); map.setStyleJSON(style, "TEST_DATA/suite"); std::promise> promise; map.renderStill([&promise](std::unique_ptr image) {