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

Cherry pick fixes to release-tequila #16074

Merged
merged 2 commits into from
Dec 19, 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
1 change: 1 addition & 0 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class Map : private util::noncopyable {

// Debug
void setDebug(MapDebugOptions);
void cycleDebugOptions();
MapDebugOptions getDebug() const;

bool isFullyLoaded() const;
Expand Down
5 changes: 5 additions & 0 deletions platform/android/src/native_map_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,10 @@ void NativeMapView::setDebug(JNIEnv&, jni::jboolean debug) {
map->setDebug(debugOptions);
}

void NativeMapView::cycleDebugOptions(JNIEnv&) {
map->cycleDebugOptions();
}

jni::jboolean NativeMapView::getDebug(JNIEnv&) {
return map->getDebug() != DebugOptions::NoDebug;
}
Expand Down Expand Up @@ -1168,6 +1172,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
METHOD(&NativeMapView::updateMarker, "nativeUpdateMarker"),
METHOD(&NativeMapView::addMarkers, "nativeAddMarkers"),
METHOD(&NativeMapView::setDebug, "nativeSetDebug"),
METHOD(&NativeMapView::cycleDebugOptions, "nativeCycleDebugOptions"),
METHOD(&NativeMapView::getDebug, "nativeGetDebug"),
METHOD(&NativeMapView::isFullyLoaded, "nativeIsFullyLoaded"),
METHOD(&NativeMapView::onLowMemory, "nativeOnLowMemory"),
Expand Down
2 changes: 2 additions & 0 deletions platform/android/src/native_map_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class NativeMapView : public MapObserver {

void setDebug(JNIEnv&, jni::jboolean);

void cycleDebugOptions(JNIEnv&);

jni::jboolean getDebug(JNIEnv&);

jni::jboolean isFullyLoaded(JNIEnv&);
Expand Down
1 change: 1 addition & 0 deletions platform/default/src/mbgl/storage/offline_download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ void OfflineDownload::deactivateDownload() {
requiredSourceURLs.clear();
resourcesRemaining.clear();
requests.clear();
buffer.clear();
}

void OfflineDownload::queueResource(Resource&& resource) {
Expand Down
26 changes: 1 addition & 25 deletions platform/glfw/glfw_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
glfwSetWindowShouldClose(window, true);
break;
case GLFW_KEY_TAB:
view->cycleDebugOptions();
view->map->cycleDebugOptions();
break;
case GLFW_KEY_X:
if (!mods)
Expand Down Expand Up @@ -496,30 +496,6 @@ void GLFWView::updateAnimatedAnnotations() {
}
}

void GLFWView::cycleDebugOptions() {
auto debug = map->getDebug();
#if not MBGL_USE_GLES2
if (debug & mbgl::MapDebugOptions::StencilClip)
debug = mbgl::MapDebugOptions::NoDebug;
else if (debug & mbgl::MapDebugOptions::Overdraw)
debug = mbgl::MapDebugOptions::StencilClip;
#else
if (debug & mbgl::MapDebugOptions::Overdraw) debug = mbgl::MapDebugOptions::NoDebug;
#endif // MBGL_USE_GLES2
else if (debug & mbgl::MapDebugOptions::Collision)
debug = mbgl::MapDebugOptions::Overdraw;
else if (debug & mbgl::MapDebugOptions::Timestamps)
debug = debug | mbgl::MapDebugOptions::Collision;
else if (debug & mbgl::MapDebugOptions::ParseStatus)
debug = debug | mbgl::MapDebugOptions::Timestamps;
else if (debug & mbgl::MapDebugOptions::TileBorders)
debug = debug | mbgl::MapDebugOptions::ParseStatus;
else
debug = mbgl::MapDebugOptions::TileBorders;

map->setDebug(debug);
}

void GLFWView::clearAnnotations() {
for (const auto& id : annotationIDs) {
map->removeAnnotation(id);
Expand Down
1 change: 0 additions & 1 deletion platform/glfw/glfw_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class GLFWView : public mbgl::MapObserver {
void updateAnimatedAnnotations();
void toggleCustomSource();

void cycleDebugOptions();
void clearAnnotations();
void popAnnotation();

Expand Down
3 changes: 3 additions & 0 deletions platform/qt/app/mapwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ void MapWindow::keyPressEvent(QKeyEvent *ev)
}
}
break;
case Qt::Key_Tab:
m_map->cycleDebugOptions();
break;
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions platform/qt/include/qmapboxgl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class Q_MAPBOXGL_EXPORT QMapboxGL : public QObject
qreal pixelRatio = 1);
virtual ~QMapboxGL();

void cycleDebugOptions();

QString styleJson() const;
QString styleUrl() const;

Expand Down
9 changes: 9 additions & 0 deletions platform/qt/src/qmapboxgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,15 @@ QMapboxGL::~QMapboxGL()
delete d_ptr;
}

/*!
Cycles through several debug options like showing the tile borders,
tile numbers, expiration time and wireframe.
*/
void QMapboxGL::cycleDebugOptions()
{
d_ptr->mapObj->cycleDebugOptions();
}

/*!
\property QMapboxGL::styleJson
\brief the map style JSON.
Expand Down
24 changes: 24 additions & 0 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,30 @@ void Map::setDebug(MapDebugOptions debugOptions) {
impl->onUpdate();
}

void Map::cycleDebugOptions() {
#if not MBGL_USE_GLES2
if (impl->debugOptions & MapDebugOptions::StencilClip)
impl->debugOptions = MapDebugOptions::NoDebug;
else if (impl->debugOptions & MapDebugOptions::Overdraw)
impl->debugOptions = MapDebugOptions::StencilClip;
#else
if (impl->debugOptions & MapDebugOptions::Overdraw)
impl->debugOptions = MapDebugOptions::NoDebug;
#endif // MBGL_USE_GLES2
else if (impl->debugOptions & MapDebugOptions::Collision)
impl->debugOptions = MapDebugOptions::Overdraw;
else if (impl->debugOptions & MapDebugOptions::Timestamps)
impl->debugOptions = impl->debugOptions | MapDebugOptions::Collision;
else if (impl->debugOptions & MapDebugOptions::ParseStatus)
impl->debugOptions = impl->debugOptions | MapDebugOptions::Timestamps;
else if (impl->debugOptions & MapDebugOptions::TileBorders)
impl->debugOptions = impl->debugOptions | MapDebugOptions::ParseStatus;
else
impl->debugOptions = MapDebugOptions::TileBorders;

impl->onUpdate();
}

MapDebugOptions Map::getDebug() const {
return impl->debugOptions;
}
Expand Down
83 changes: 82 additions & 1 deletion test/storage/offline_download.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,6 @@ TEST(OfflineDownload, Deactivate) {
test.loop.run();
}


TEST(OfflineDownload, AllOfflineRequestsHaveLowPriorityAndOfflineUsage) {
OfflineTest test;
auto region = test.createRegion();
Expand Down Expand Up @@ -947,3 +946,85 @@ TEST(OfflineDownload, ResourceOfflineUsageUnset) {
test.loop.run();
}
#endif // __QT__

// Test verifies that resource batch buffer is cleared at loading interrupt.
TEST(OfflineDownload, InterruptAndResume) {
OfflineTest test;
auto region = test.createRegion();
ASSERT_TRUE(region);
OfflineDownload download(region->getID(),
OfflineTilePyramidRegionDefinition(
"http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0, true),
test.db,
test.fileSource);

test.fileSource.styleResponse = [&](const Resource& resource) {
EXPECT_EQ("http://127.0.0.1:3000/style.json", resource.url);
return test.response("style.json");
};

test.fileSource.spriteImageResponse = [&](const Resource& resource) {
EXPECT_TRUE(resource.url == "http://127.0.0.1:3000/sprite.png" ||
resource.url == "http://127.0.0.1:3000/sprite@2x.png");
return test.response("sprite.png");
};

test.fileSource.imageResponse = [&](const Resource& resource) {
EXPECT_EQ("http://127.0.0.1:3000/radar.gif", resource.url);
return test.response("radar.gif");
};

test.fileSource.spriteJSONResponse = [&](const Resource& resource) {
EXPECT_TRUE(resource.url == "http://127.0.0.1:3000/sprite.json" ||
resource.url == "http://127.0.0.1:3000/sprite@2x.json");
return test.response("sprite.json");
};

test.fileSource.glyphsResponse = [&](const Resource&) { return test.response("glyph.pbf"); };

test.fileSource.sourceResponse = [&](const Resource& resource) {
EXPECT_EQ("http://127.0.0.1:3000/streets.json", resource.url);
return test.response("streets.json");
};

test.fileSource.tileResponse = [&](const Resource& resource) {
const Resource::TileData& tile = *resource.tileData;
EXPECT_EQ("http://127.0.0.1:3000/{z}-{x}-{y}.vector.pbf", tile.urlTemplate);
EXPECT_EQ(1, tile.pixelRatio);
EXPECT_EQ(0, tile.x);
EXPECT_EQ(0, tile.y);
EXPECT_EQ(0, tile.z);
return test.response("0-0-0.vector.pbf");
};

auto observer = std::make_unique<MockObserver>();
bool interrupted = false;
observer->statusChangedFn = [&](OfflineRegionStatus status) {
if (!interrupted && status.completedResourceCount > 0) {
interrupted = true;
assert(!status.complete());
test.loop.schedule([&]() {
download.setState(OfflineRegionDownloadState::Inactive);
test.loop.stop();
});
}
};

download.setObserver(std::move(observer));
download.setState(OfflineRegionDownloadState::Active);
test.loop.run();

auto newObserver = std::make_unique<MockObserver>();
newObserver->statusChangedFn = [&](OfflineRegionStatus status) {
if (status.complete()) {
EXPECT_EQ(status.completedTileCount, status.requiredTileCount);
EXPECT_EQ(264u, status.completedResourceCount); // 256 glyphs, 2 sprite images, 2 sprite jsons, 1 tile, 1
// style, source, image
test.loop.stop();
}
};

download.setObserver(std::move(newObserver));
download.setState(OfflineRegionDownloadState::Active);
test.loop.run();
}