Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] Suppress network requests for invisible tiles #15741

Merged
merged 3 commits into from
Oct 2, 2019
Merged
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: 2 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,8 @@ commands:
- run:
name: Run tests
command: |
# Source.RenderTileSetSourceUpdate is filtered out due to #15294
xvfb-run --server-args="-screen 0 1024x768x24" make run-test--Source.RenderTileSetSourceUpdate 2> >(tee sanitizer 1>&2)
# Source.RenderTileSetSourceUpdate and Source.InvisibleSourcesTileNecessity are filtered out due to #15294
xvfb-run --server-args="-screen 0 1024x768x24" make run-test--Source.RenderTileSetSourceUpdate:Source.InvisibleSourcesTileNecessity 2> >(tee sanitizer 1>&2)
# Unfortunately, Google Test eats the status code, so we'll have to check the output.
[ -z "$(sed -n '/^SUMMARY: .*Sanitizer:/p' sanitizer)" ]

Expand Down
3 changes: 3 additions & 0 deletions platform/android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to

## master

### Bug fixes
- Suppress network requests for expired tiles update, if these tiles are invisible. [#15741](https://github.com/mapbox/mapbox-gl-native/pull/15741)

## 8.4.0 - September 25, 2019
[Changes](https://github.com/mapbox/mapbox-gl-native/compare/android-v8.4.0-beta.1...android-v8.4.0) since [Mapbox Maps SDK for Android v8.4.0-beta.1](https://github.com/mapbox/mapbox-gl-native/releases/tag/android-v8.4.0-beta.1):

Expand Down
6 changes: 6 additions & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Mapbox welcomes participation and contributions from everyone. Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) to get started.

## master

### Other changes

* Suppress network requests for expired tiles update, if these tiles are invisible. ([#15741](https://github.com/mapbox/mapbox-gl-native/pull/15741))

## 5.4.0 - September 25, 2019

### Styles and rendering
Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/renderer/tile_pyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
if (!needsRendering) {
if (!needsRelayout) {
for (auto& entry : tiles) {
// These tiles are invisible, we set optional necessity
// for them and thus suppress network requests on
// tiles expiration (see `OnlineFileRequest`).
entry.second->setNecessity(TileNecessity::Optional);
cache.add(entry.first, std::move(entry.second));
}
}
Expand Down
76 changes: 75 additions & 1 deletion test/style/source.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
#include <mbgl/util/optional.hpp>
#include <mbgl/util/range.hpp>

#include <mbgl/map/transform.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/annotation/annotation_source.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/renderer/image_manager.hpp>
#include <mbgl/renderer/tile_render_data.hpp>
#include <mbgl/text/glyph_manager.hpp>

#include <cstdint>
Expand Down Expand Up @@ -793,6 +794,79 @@ TEST(Source, CustomGeometrySourceSetTileData) {

test.run();
}
namespace {

class FakeTileSource;

class FakeTile : public Tile {
public:
FakeTile(FakeTileSource& source_, const OverscaledTileID& tileID)
: Tile(Tile::Kind::Geometry, tileID), source(source_) {
renderable = true;
}
void setNecessity(TileNecessity necessity) override;
bool layerPropertiesUpdated(const Immutable<style::LayerProperties>&) override { return true; }

std::unique_ptr<TileRenderData> createRenderData() override { return nullptr; }

private:
FakeTileSource& source;
};

class FakeTileSource : public RenderTileSetSource {
public:
MOCK_METHOD1(tileSetNecessity, void(TileNecessity));

explicit FakeTileSource(Immutable<style::Source::Impl> impl_) : RenderTileSetSource(std::move(impl_)) {}
void updateInternal(const Tileset& tileset,
const std::vector<Immutable<style::LayerProperties>>& layers,
const bool needsRendering,
const bool needsRelayout,
const TileParameters& parameters) override {
tilePyramid.update(layers,
needsRendering,
needsRelayout,
parameters,
SourceType::Vector,
util::tileSize,
tileset.zoomRange,
tileset.bounds,
[&](const OverscaledTileID& tileID) { return std::make_unique<FakeTile>(*this, tileID); });
}

const optional<Tileset>& getTileset() const override {
return static_cast<const style::VectorSource::Impl&>(*baseImpl).tileset;
}
};

void FakeTile::setNecessity(TileNecessity necessity) {
source.tileSetNecessity(necessity);
}

} // namespace

TEST(Source, InvisibleSourcesTileNecessity) {
SourceTest test;
VectorSource initialized("source", Tileset{{"tiles"}});
initialized.loadDescription(*test.fileSource);

FakeTileSource renderTilesetSource{initialized.baseImpl};
RenderSource* renderSource = &renderTilesetSource;
LineLayer layer("id", "source");
Immutable<LayerProperties> layerProperties =
makeMutable<LineLayerProperties>(staticImmutableCast<LineLayer::Impl>(layer.baseImpl));
std::vector<Immutable<LayerProperties>> layers{layerProperties};
EXPECT_CALL(renderTilesetSource, tileSetNecessity(TileNecessity::Required)).Times(1);
renderSource->update(initialized.baseImpl, layers, true, true, test.tileParameters);

// Necessity for invisible tiles must be set to `optional`.
EXPECT_CALL(renderTilesetSource, tileSetNecessity(TileNecessity::Optional)).Times(1);
renderSource->update(initialized.baseImpl, layers, false, false, test.tileParameters);

// Necessity is again `required` once tiles get back visible.
EXPECT_CALL(renderTilesetSource, tileSetNecessity(TileNecessity::Required)).Times(1);
renderSource->update(initialized.baseImpl, layers, true, false, test.tileParameters);
}

TEST(Source, RenderTileSetSourceUpdate) {
SourceTest test;
Expand Down