diff options
-rw-r--r-- | android/cpp/native_map_view.cpp | 4 | ||||
-rw-r--r-- | include/mbgl/map/map.hpp | 5 | ||||
-rw-r--r-- | include/mbgl/map/view.hpp | 8 | ||||
-rw-r--r-- | include/mbgl/platform/default/headless_view.hpp | 8 | ||||
-rw-r--r-- | platform/default/glfw_view.cpp | 2 | ||||
-rw-r--r-- | platform/default/headless_view.cpp | 28 | ||||
-rw-r--r-- | platform/ios/MGLMapView.mm | 9 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/map/map_context.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/map/view.cpp | 9 | ||||
-rw-r--r-- | test/headless/headless.cpp | 5 |
11 files changed, 18 insertions, 73 deletions
diff --git a/android/cpp/native_map_view.cpp b/android/cpp/native_map_view.cpp index 7b319d8b03..8d12d5af16 100644 --- a/android/cpp/native_map_view.cpp +++ b/android/cpp/native_map_view.cpp @@ -825,8 +825,8 @@ void NativeMapView::updateFps() { env = nullptr; } -void NativeMapView::resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) { - View::resize(width, height, ratio, fbWidth, fbHeight); +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/map/map.hpp b/include/mbgl/map/map.hpp index b217a685f9..2374f0a442 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -107,6 +107,7 @@ public: void resetNorth(); // Size + void resize(uint16_t width, uint16_t height, float ratio = 1); uint16_t getWidth() const; uint16_t getHeight() const; @@ -146,10 +147,6 @@ public: private: void triggerUpdate(Update update = Update::Nothing); - // This may only be called by the View object. - void resize(uint16_t width, uint16_t height, float ratio = 1); - void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight); - const std::unique_ptr<Environment> env; std::unique_ptr<EnvironmentScope> scope; View &view; diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp index 9fdbd62784..b736290169 100644 --- a/include/mbgl/map/view.hpp +++ b/include/mbgl/map/view.hpp @@ -45,10 +45,6 @@ public: // or map->renderSync() from the main thread must be called as a result of this) virtual void invalidate(std::function<void()> render) = 0; - // Called from the render (=GL) thread. Signals that the contents of the contents - // may be discarded. The default is a no-op. - virtual void discard(); - // Reads the pixel data from the current framebuffer. If your View implementation // doesn't support reading from the framebuffer, return a null pointer. virtual std::unique_ptr<StillImage> readStillImage(); @@ -61,10 +57,6 @@ public: Duration delay = Duration::zero()); protected: - // Resizes the view - void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight); - -protected: mbgl::Map *map = nullptr; }; } diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp index fd7a69f96d..a0a3847c83 100644 --- a/include/mbgl/platform/default/headless_view.hpp +++ b/include/mbgl/platform/default/headless_view.hpp @@ -35,7 +35,6 @@ public: void deactivate() override; void notify() override; void invalidate(std::function<void()> render) override; - void discard() override; std::unique_ptr<StillImage> readStillImage() override; private: @@ -57,12 +56,7 @@ private: float pixelRatio = 0; }; - // These are the values that represent the state of the current framebuffer. - Dimensions current; - - // These are the values that will be used after the next discard() event. - std::mutex prospectiveMutex; - Dimensions prospective; + Dimensions dimensions; #if MBGL_USE_CGL CGLContextObj glContext = nullptr; diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index 66f4bf67e1..7be2d119c7 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -223,7 +223,7 @@ void GLFWView::onResize(GLFWwindow *window, int width, int height ) { int fbWidth, fbHeight; glfwGetFramebufferSize(window, &fbWidth, &fbHeight); - view->resize(width, height, static_cast<float>(fbWidth) / static_cast<float>(width), fbWidth, fbHeight); + view->map->resize(width, height, static_cast<float>(fbWidth) / static_cast<float>(width)); } void GLFWView::onMouseClick(GLFWwindow *window, int button, int action, int modifiers) { diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index d84e223e49..549c16d8c2 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -150,30 +150,19 @@ bool HeadlessView::isActive() { return std::this_thread::get_id() == thread; } -void HeadlessView::resize(const uint16_t width, const uint16_t height, const float pixelRatio) { - std::lock_guard<std::mutex> lock(prospectiveMutex); - prospective = { width, height, pixelRatio }; -} - HeadlessView::Dimensions::Dimensions(uint16_t width_, uint16_t height_, float pixelRatio_) : width(width_), height(height_), pixelRatio(pixelRatio_) { } -void HeadlessView::discard() { - assert(isActive()); +void HeadlessView::resize(const uint16_t width, const uint16_t height, const float pixelRatio) { + activate(); - { // Obtain the new values. - std::lock_guard<std::mutex> lock(prospectiveMutex); - if (current.pixelWidth() == prospective.pixelWidth() && current.pixelHeight() == prospective.pixelHeight()) { - return; - } - current = prospective; - } + dimensions = { width, height, pixelRatio }; clearBuffers(); - const unsigned int w = current.width * current.pixelRatio; - const unsigned int h = current.height * current.pixelRatio; + const unsigned int w = dimensions.width * dimensions.pixelRatio; + const unsigned int h = dimensions.height * dimensions.pixelRatio; // Create depth/stencil buffer MBGL_CHECK_ERROR(glGenRenderbuffersEXT(1, &fboDepthStencil)); @@ -209,14 +198,14 @@ void HeadlessView::discard() { throw std::runtime_error(error.str()); } - View::resize(current.width, current.height, current.pixelRatio, w, h); + deactivate(); } std::unique_ptr<StillImage> HeadlessView::readStillImage() { assert(isActive()); - const unsigned int w = current.pixelWidth(); - const unsigned int h = current.pixelHeight(); + const unsigned int w = dimensions.pixelWidth(); + const unsigned int h = dimensions.pixelHeight(); auto image = util::make_unique<StillImage>(); image->width = w; @@ -305,7 +294,6 @@ void HeadlessView::activate() { #endif loadExtensions(); - discard(); } void HeadlessView::deactivate() { diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index a0e2ccb244..5101a2c981 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -278,7 +278,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; mbglFileCache = new mbgl::SQLiteCache(defaultCacheDatabase()); mbglFileSource = new mbgl::DefaultFileSource(mbglFileCache); mbglMap = new mbgl::Map(*mbglView, *mbglFileSource); - mbglView->resize(self.bounds.size.width, self.bounds.size.height, _glView.contentScaleFactor, _glView.drawableWidth, _glView.drawableHeight); + mbglMap->resize(self.bounds.size.width, self.bounds.size.height, _glView.contentScaleFactor); // Notify map object when network reachability status changes. [[NSNotificationCenter defaultCenter] addObserver:self @@ -623,7 +623,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; { if ( ! self.glSnapshotView || self.glSnapshotView.hidden) { - mbglView->resize(rect.size.width, rect.size.height, view.contentScaleFactor, view.drawableWidth, view.drawableHeight); + mbglMap->resize(rect.size.width, rect.size.height, view.contentScaleFactor); CGFloat zoomFactor = mbglMap->getMaxZoom() - mbglMap->getMinZoom() + 1; CGFloat cpuFactor = (CGFloat)[[NSProcessInfo processInfo] processorCount]; @@ -2528,11 +2528,6 @@ class MBGLView : public mbgl::View [EAGLContext setCurrentContext:nil]; } - void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) - { - View::resize(width, height, ratio, fbWidth, fbHeight); - } - void invalidate(std::function<void()>) override { [nativeView performSelectorOnMainThread:@selector(invalidate) diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 1d05c073de..a9a83bc736 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -174,11 +174,7 @@ std::string Map::getStyleJSON() const { #pragma mark - Size void Map::resize(uint16_t width, uint16_t height, float ratio) { - resize(width, height, ratio, width * ratio, height * ratio); -} - -void Map::resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) { - if (data->transform.resize(width, height, ratio, fbWidth, fbHeight)) { + if (data->transform.resize(width, height, ratio, width * ratio, height * ratio)) { triggerUpdate(); } } diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 1a5543447b..51a24b11b3 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -200,11 +200,6 @@ void MapContext::update() { painter->setDebug(data.getDebug()); } - if (u & static_cast<UpdateType>(Update::RenderStill)) { - // Triggers a view resize. - view.discard(); - } - if (style) { if (u & static_cast<UpdateType>(Update::DefaultTransitionDuration)) { style->setDefaultTransitionDuration(data.getDefaultTransitionDuration()); @@ -233,8 +228,6 @@ void MapContext::update() { void MapContext::render() { assert(Environment::currentlyOn(ThreadType::Map)); - view.discard(); - // Cleanup OpenGL objects that we abandoned since the last render call. env.performCleanup(); diff --git a/src/mbgl/map/view.cpp b/src/mbgl/map/view.cpp index 67211ae24d..773f799e87 100644 --- a/src/mbgl/map/view.cpp +++ b/src/mbgl/map/view.cpp @@ -11,19 +11,10 @@ void View::initialize(Map *map_) { map = map_; } -void View::discard() { - // no-op -} - std::unique_ptr<StillImage> View::readStillImage() { return nullptr; } -void View::resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) { - assert(map); - map->resize(width, height, ratio, fbWidth, fbHeight); -} - void View::notifyMapChange(MapChange, Duration) { // no-op } diff --git a/test/headless/headless.cpp b/test/headless/headless.cpp index 7e22f76211..24f9fd1a6f 100644 --- a/test/headless/headless.cpp +++ b/test/headless/headless.cpp @@ -141,16 +141,15 @@ TEST_P(HeadlessTest, render) { } } - HeadlessView view(display); + HeadlessView view(display, width, height, pixelRatio); DefaultFileSource fileSource(nullptr); Map map(view, fileSource); + map.resize(width, height, pixelRatio); map.start(MapMode::Still); map.setClasses(classes); map.setStyleJSON(style, "test/suite"); - - view.resize(width, height, pixelRatio); map.setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom); map.setBearing(bearing); |