diff options
23 files changed, 106 insertions, 59 deletions
diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index c1b720cf27..dba17ece6a 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -1330,8 +1330,8 @@ public final class MapView extends FrameLayout { * @see MapView#isDebugActive() */ @UiThread - public void toggleDebug() { - mNativeMapView.toggleDebug(); + public void cycleDebugOptions() { + mNativeMapView.cycleDebugOptions(); mNativeMapView.toggleCollisionDebug(); } diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/NativeMapView.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/NativeMapView.java index dce90b64d6..d75b83cf8d 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/NativeMapView.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/NativeMapView.java @@ -401,7 +401,7 @@ final class NativeMapView { nativeSetDebug(mNativeMapViewPtr, debug); } - public void toggleDebug() { + public void cycleDebugOptions() { nativeToggleDebug(mNativeMapViewPtr); } diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java index 9995a15840..1c9d611145 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java +++ b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java @@ -322,8 +322,8 @@ public class MainActivity extends AppCompatActivity { switch (menuItem.getItemId()) { case R.id.action_debug: - // Toggle debug mode - mMapView.toggleDebug(); + // Cycle map debug options + mMapView.cycleDebugOptions(); toggleFpsCounter(mMapView.isDebugActive()); return true; diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index 26b44060ea..b8277797ce 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -20,7 +20,7 @@ <string name="action_gps">Toggle GPS location</string> <string name="action_user_location_tracking">User location tracking</string> <string name="action_compass">Toggle compass</string> - <string name="action_debug">Toggle debug mode</string> + <string name="action_debug">Cycle map debug options</string> <string name="action_point_annotations">Toggle point annotations</string> <string name="action_info_window_adapter">InfoWindow Adapter</string> <string name="action_map_fragment">MapFragment</string> diff --git a/bin/render.cpp b/bin/render.cpp index ceb95c165c..6762d28c1b 100644 --- a/bin/render.cpp +++ b/bin/render.cpp @@ -99,7 +99,7 @@ int main(int argc, char *argv[]) { map.setBearing(bearing); if (debug) { - map.setDebug(debug); + map.setDebug(debug ? mbgl::MapDebugOptions::TileBorders | mbgl::MapDebugOptions::ParseStatus : mbgl::MapDebugOptions::NoDebug); } uv_async_t *async = new uv_async_t; diff --git a/docs/DEVELOP_IOS_OSX.md b/docs/DEVELOP_IOS_OSX.md index dbdb43cd0e..8f05b98218 100644 --- a/docs/DEVELOP_IOS_OSX.md +++ b/docs/DEVELOP_IOS_OSX.md @@ -46,4 +46,4 @@ If you want to run the tests in Xcode instead, first `make ipackage` to create a - Double-tap to zoom in one level - Two-finger single-tap to zoom out one level - Double-tap, long-pressing the second, then pan up and down to "quick zoom" (iPhone only, meant for one-handed use) -- Use the debug menu to add test annotations, reset position, and toggle debug info. +- Use the debug menu to add test annotations, reset position, and cycle through the debug options. diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h index edc3ca53f3..ff13ae3a2c 100644 --- a/include/mbgl/ios/MGLMapView.h +++ b/include/mbgl/ios/MGLMapView.h @@ -405,8 +405,8 @@ IB_DESIGNABLE * The default value of this property is `NO`. */ @property (nonatomic, getter=isDebugActive) BOOL debugActive; -/** Toggle the current value of debugActive. */ -- (void)toggleDebug; +/** Cycle map debug options. */ +- (void)cycleDebugOptions; /** Empties the in-memory tile cache. */ - (void)emptyMemoryCache; diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 35895660f2..43c3b1452e 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -168,12 +168,13 @@ public: void onLowMemory(); // Debug - void setDebug(bool value); - void toggleDebug(); - bool getDebug() const; + void setDebug(MapDebugOptions); + void cycleDebugOptions(); + MapDebugOptions getDebug() const; void setCollisionDebug(bool value); void toggleCollisionDebug(); bool getCollisionDebug() const; + bool isFullyLoaded() const; void dumpDebugLogs() const; diff --git a/include/mbgl/map/mode.hpp b/include/mbgl/map/mode.hpp index 8b65baf99f..0fe2c46dd8 100644 --- a/include/mbgl/map/mode.hpp +++ b/include/mbgl/map/mode.hpp @@ -5,7 +5,9 @@ namespace mbgl { -enum class MapMode : uint8_t { +using EnumType = uint32_t; + +enum class MapMode : EnumType { Continuous, // continually updating map Still, // a once-off still image }; @@ -14,18 +16,38 @@ enum class MapMode : uint8_t { // being shared. In a shared GL context case, we need to make sure that the // correct GL configurations are in use - they might have changed between render // calls. -enum class GLContextMode : uint8_t { +enum class GLContextMode : EnumType { Unique, Shared, }; // We can choose to constrain the map both horizontally or vertically, or only // vertically e.g. while panning. -enum class ConstrainMode : uint8_t { +enum class ConstrainMode : EnumType { HeightOnly, WidthAndHeight, }; +enum class MapDebugOptions : EnumType { + NoDebug = 0, + TileBorders = 1 << 1, + ParseStatus = 1 << 2, + Timestamps = 1 << 3, +}; + +inline MapDebugOptions operator| (const MapDebugOptions& lhs, const MapDebugOptions& rhs) { + return MapDebugOptions(static_cast<EnumType>(lhs) | static_cast<EnumType>(rhs)); +} + +inline MapDebugOptions& operator|=(MapDebugOptions& lhs, const MapDebugOptions& rhs) { + lhs = lhs | rhs; + return lhs; +} + +inline bool operator& (const MapDebugOptions& lhs, const MapDebugOptions& rhs) { + return static_cast<EnumType>(lhs) & static_cast<EnumType>(rhs); +} + } // namespace mbgl #endif // MBGL_MAP_MODE diff --git a/include/mbgl/platform/darwin/settings_nsuserdefaults.hpp b/include/mbgl/platform/darwin/settings_nsuserdefaults.hpp index 615320ee55..6364f249dd 100644 --- a/include/mbgl/platform/darwin/settings_nsuserdefaults.hpp +++ b/include/mbgl/platform/darwin/settings_nsuserdefaults.hpp @@ -22,7 +22,7 @@ public: MGLUserTrackingMode userTrackingMode = MGLUserTrackingModeNone; bool showsUserLocation = false; - bool debug = false; + uint32_t debug = 0; }; } diff --git a/include/mbgl/platform/default/settings_json.hpp b/include/mbgl/platform/default/settings_json.hpp index 154a7e3769..ceec1e7fde 100644 --- a/include/mbgl/platform/default/settings_json.hpp +++ b/include/mbgl/platform/default/settings_json.hpp @@ -1,6 +1,8 @@ #ifndef MBGL_JSON_SETTINGS #define MBGL_JSON_SETTINGS +#include <mbgl/map/mode.hpp> + namespace mbgl { class Settings_JSON { @@ -17,7 +19,7 @@ public: double bearing = 0; double pitch = 0; - bool debug = false; + EnumType debug = 0; }; } diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm index 2acfe8c297..4c73f2f171 100644 --- a/ios/app/MBXViewController.mm +++ b/ios/app/MBXViewController.mm @@ -132,7 +132,7 @@ static UIColor *const kTintColor = [UIColor colorWithRed:0.120 green:0.550 blue: destructiveButtonTitle:nil otherButtonTitles:@"Reset North", @"Reset Position", - @"Toggle Debug", + @"Cycle debug options", @"Empty Memory", @"Add 100 Points", @"Add 1,000 Points", @@ -156,7 +156,7 @@ static UIColor *const kTintColor = [UIColor colorWithRed:0.120 green:0.550 blue: } else if (buttonIndex == actionSheet.firstOtherButtonIndex + 2) { - [self.mapView toggleDebug]; + [self.mapView cycleDebugOptions]; } else if (buttonIndex == actionSheet.firstOtherButtonIndex + 3) { diff --git a/linux/main.cpp b/linux/main.cpp index 97f400dd41..4ccf7f3529 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) { map.setLatLngZoom(mbgl::LatLng(settings.latitude, settings.longitude), settings.zoom); map.setBearing(settings.bearing); map.setPitch(settings.pitch); - map.setDebug(settings.debug); + map.setDebug(mbgl::MapDebugOptions(settings.debug)); } view->setChangeStyleCallback([&map] () { @@ -167,7 +167,7 @@ int main(int argc, char *argv[]) { settings.zoom = map.getZoom(); settings.bearing = map.getBearing(); settings.pitch = map.getPitch(); - settings.debug = map.getDebug(); + settings.debug = mbgl::EnumType(map.getDebug()); if (!skipConfig) { settings.save(); } diff --git a/macosx/main.mm b/macosx/main.mm index 264924edcf..6b8aef3814 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -168,7 +168,7 @@ int main(int argc, char* argv[]) { map.setLatLngZoom(mbgl::LatLng(settings.latitude, settings.longitude), settings.zoom); map.setBearing(settings.bearing); map.setPitch(settings.pitch); - map.setDebug(settings.debug); + map.setDebug(mbgl::MapDebugOptions(settings.debug)); view.setChangeStyleCallback([&map, &view] () { static uint8_t currentStyleIndex; @@ -205,7 +205,7 @@ int main(int argc, char* argv[]) { settings.zoom = map.getZoom(); settings.bearing = map.getBearing(); settings.pitch = map.getPitch(); - settings.debug = map.getDebug(); + settings.debug = uint32_t(map.getDebug()); settings.save(); return 0; diff --git a/platform/android/jni.cpp b/platform/android/jni.cpp index 9b80013da2..f3181b2a83 100644 --- a/platform/android/jni.cpp +++ b/platform/android/jni.cpp @@ -375,6 +375,7 @@ std::pair<mbgl::AnnotationSegment, mbgl::ShapeAnnotation::Properties> annotation namespace { using namespace mbgl::android; +using DebugOptions = mbgl::MapDebugOptions; jlong JNICALL nativeCreate(JNIEnv *env, jobject obj, jstring cachePath_, jstring dataPath_, jstring apkPath_, jfloat pixelRatio, jint availableProcessors, jlong totalMemory) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeCreate"); @@ -1293,7 +1294,10 @@ void JNICALL nativeSetDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jb mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetDebug"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - nativeMapView->getMap().setDebug(debug); + + DebugOptions debugOptions = debug ? DebugOptions::TileBorders | DebugOptions::ParseStatus + : DebugOptions::NoDebug; + nativeMapView->getMap().setDebug(debugOptions); nativeMapView->enableFps(debug); } @@ -1301,15 +1305,15 @@ void JNICALL nativeToggleDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) mbgl::Log::Debug(mbgl::Event::JNI, "nativeToggleDebug"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - nativeMapView->getMap().toggleDebug(); - nativeMapView->enableFps(nativeMapView->getMap().getDebug()); + nativeMapView->getMap().cycleDebugOptions(); + nativeMapView->enableFps(nativeMapView->getMap().getDebug() != DebugOptions::NoDebug); } jboolean JNICALL nativeGetDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetDebug"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - return nativeMapView->getMap().getDebug(); + return nativeMapView->getMap().getDebug() != DebugOptions::NoDebug; } void JNICALL nativeSetCollisionDebug(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean debug) { diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index eae2c3610a..998eb64791 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -102,7 +102,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_) printf("- `Control` + mouse drag to rotate\n"); printf("- `Shift` + mouse drag to tilt\n"); printf("\n"); - printf("- Press `Tab` to toggle debug information\n"); + printf("- Press `Tab` to cycle through the map debug options\n"); printf("- Press `Esc` to quit\n"); printf("\n"); printf("================================================================================\n"); @@ -127,7 +127,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, glfwSetWindowShouldClose(window, true); break; case GLFW_KEY_TAB: - view->map->toggleDebug(); + view->map->cycleDebugOptions(); break; case GLFW_KEY_C: view->map->toggleCollisionDebug(); diff --git a/platform/default/settings_json.cpp b/platform/default/settings_json.cpp index 8c1c8ff739..2c1bb3d242 100644 --- a/platform/default/settings_json.cpp +++ b/platform/default/settings_json.cpp @@ -35,5 +35,5 @@ void Settings_JSON::clear() { zoom = 0; bearing = 0; pitch = 0; - debug = false; + debug = 0; } diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index c923adb160..d3faf8c099 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -747,7 +747,7 @@ std::chrono::steady_clock::duration durationInSeconds(float duration) self.glSnapshotView.image = self.glView.snapshot; self.glSnapshotView.hidden = NO; - if (_mbglMap->getDebug() && [self.glSnapshotView.subviews count] == 0) + if (_mbglMap->getDebug() != mbgl::MapDebugOptions::NoDebug && [self.glSnapshotView.subviews count] == 0) { UIView *snapshotTint = [[UIView alloc] initWithFrame:self.glSnapshotView.bounds]; snapshotTint.autoresizingMask = self.glSnapshotView.autoresizingMask; @@ -1502,13 +1502,14 @@ std::chrono::steady_clock::duration durationInSeconds(float duration) - (void)setDebugActive:(BOOL)debugActive { - _mbglMap->setDebug(debugActive); + _mbglMap->setDebug(debugActive ? mbgl::MapDebugOptions::TileBorders | mbgl::MapDebugOptions::ParseStatus + : mbgl::MapDebugOptions::NoDebug); _mbglMap->setCollisionDebug(debugActive); } - (BOOL)isDebugActive { - return (_mbglMap->getDebug() || _mbglMap->getCollisionDebug()); + return (_mbglMap->getDebug() != mbgl::MapDebugOptions::NoDebug || _mbglMap->getCollisionDebug()); } - (void)resetNorth @@ -1527,9 +1528,9 @@ std::chrono::steady_clock::duration durationInSeconds(float duration) _mbglMap->resetPosition(); } -- (void)toggleDebug +- (void)cycleDebugOptions { - _mbglMap->toggleDebug(); + _mbglMap->cycleDebugOptions(); _mbglMap->toggleCollisionDebug(); } diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 713222fe54..573500fd65 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -420,17 +420,17 @@ void Map::removeSprite(const std::string& name) { #pragma mark - Toggles -void Map::setDebug(bool value) { - data->setDebug(value); +void Map::setDebug(MapDebugOptions mode) { + data->setDebug(mode); update(Update::Repaint); } -void Map::toggleDebug() { - data->toggleDebug(); +void Map::cycleDebugOptions() { + data->cycleDebugOptions(); update(Update::Repaint); } -bool Map::getDebug() const { +MapDebugOptions Map::getDebug() const { return data->getDebug(); } diff --git a/src/mbgl/map/map_data.hpp b/src/mbgl/map/map_data.hpp index c1898fc37f..597048167c 100644 --- a/src/mbgl/map/map_data.hpp +++ b/src/mbgl/map/map_data.hpp @@ -49,14 +49,23 @@ public: std::vector<std::string> getClasses() const; - inline bool getDebug() const { - return debug; + inline MapDebugOptions getDebug() const { + return debugOptions; } - inline bool toggleDebug() { - return debug ^= 1u; + + inline void cycleDebugOptions() { + if (debugOptions & MapDebugOptions::Timestamps) + debugOptions = MapDebugOptions::NoDebug; + else if (debugOptions & MapDebugOptions::ParseStatus) + debugOptions = debugOptions | MapDebugOptions::Timestamps; + else if (debugOptions & MapDebugOptions::TileBorders) + debugOptions = debugOptions | MapDebugOptions::ParseStatus; + else + debugOptions = MapDebugOptions::TileBorders; } - inline void setDebug(bool value) { - debug = value; + + inline void setDebug(MapDebugOptions debugOptions_) { + debugOptions = debugOptions_; } inline bool getCollisionDebug() const { @@ -136,7 +145,7 @@ private: mutable std::mutex mtx; std::vector<std::string> classes; - std::atomic<uint8_t> debug { false }; + std::atomic<MapDebugOptions> debugOptions { MapDebugOptions::NoDebug }; std::atomic<uint8_t> collisionDebug { false }; std::atomic<Duration> animationTime; std::atomic<Duration> defaultFadeDuration; diff --git a/src/mbgl/renderer/debug_bucket.cpp b/src/mbgl/renderer/debug_bucket.cpp index 048ded2cda..a1a24eab73 100644 --- a/src/mbgl/renderer/debug_bucket.cpp +++ b/src/mbgl/renderer/debug_bucket.cpp @@ -10,19 +10,24 @@ using namespace mbgl; -DebugBucket::DebugBucket(const TileID id, const TileData::State state_, Seconds modified_, Seconds expires_) +DebugBucket::DebugBucket(const TileID id, const TileData::State state_, Seconds modified_, Seconds expires_, MapDebugOptions debugMode_) : state(state_), modified(modified_), - expires(expires_) { - const std::string text = std::string(id) + " - " + TileData::StateToString(state); - fontBuffer.addText(text.c_str(), 50, 200, 5); + expires(expires_), + debugMode(debugMode_) { + double baseline = 200; + if (debugMode & MapDebugOptions::ParseStatus) { + const std::string text = std::string(id) + " - " + TileData::StateToString(state); + fontBuffer.addText(text.c_str(), 50, baseline, 5); + baseline += 200; + } - if (modified > Seconds::zero() && expires > Seconds::zero()) { + if (debugMode & MapDebugOptions::Timestamps && modified > Seconds::zero() && expires > Seconds::zero()) { const std::string modifiedText = "modified: " + util::iso8601(modified.count()); - fontBuffer.addText(modifiedText.c_str(), 50, 400, 5); + fontBuffer.addText(modifiedText.c_str(), 50, baseline, 5); const std::string expiresText = "expires: " + util::iso8601(expires.count()); - fontBuffer.addText(expiresText.c_str(), 50, 600, 5); + fontBuffer.addText(expiresText.c_str(), 50, baseline + 200, 5); } } diff --git a/src/mbgl/renderer/debug_bucket.hpp b/src/mbgl/renderer/debug_bucket.hpp index fe09afc03f..7edee6beec 100644 --- a/src/mbgl/renderer/debug_bucket.hpp +++ b/src/mbgl/renderer/debug_bucket.hpp @@ -2,6 +2,7 @@ #define MBGL_RENDERER_DEBUGBUCKET #include <mbgl/map/tile_data.hpp> +#include <mbgl/map/mode.hpp> #include <mbgl/geometry/debug_font_buffer.hpp> #include <mbgl/geometry/vao.hpp> #include <mbgl/util/chrono.hpp> @@ -12,7 +13,7 @@ class PlainShader; class DebugBucket : private util::noncopyable { public: - DebugBucket(TileID id, TileData::State, Seconds modified, Seconds expires); + DebugBucket(TileID id, TileData::State, Seconds modified, Seconds expires, MapDebugOptions); void drawLines(PlainShader& shader); void drawPoints(PlainShader& shader); @@ -20,6 +21,7 @@ public: const TileData::State state; const Seconds modified; const Seconds expires; + const MapDebugOptions debugMode; private: DebugFontBuffer fontBuffer; diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp index 88eca9ffb1..0a0900526a 100644 --- a/src/mbgl/renderer/painter_debug.cpp +++ b/src/mbgl/renderer/painter_debug.cpp @@ -12,7 +12,7 @@ using namespace mbgl; void Painter::renderTileDebug(const Tile& tile) { MBGL_DEBUG_GROUP(std::string { "debug " } + std::string(tile.id)); assert(tile.data); - if (data.getDebug()) { + if (data.getDebug() != MapDebugOptions::NoDebug) { prepareTile(tile); renderDebugText(*tile.data, tile.matrix); renderDebugFrame(tile.matrix); @@ -26,8 +26,9 @@ void Painter::renderDebugText(TileData& tileData, const mat4 &matrix) { if (!tileData.debugBucket || tileData.debugBucket->state != tileData.getState() || tileData.debugBucket->modified != tileData.modified - || tileData.debugBucket->expires != tileData.expires) { - tileData.debugBucket = std::make_unique<DebugBucket>(tileData.id, tileData.getState(), tileData.modified, tileData.expires); + || tileData.debugBucket->expires != tileData.expires + || tileData.debugBucket->debugMode != data.getDebug()) { + tileData.debugBucket = std::make_unique<DebugBucket>(tileData.id, tileData.getState(), tileData.modified, tileData.expires, data.getDebug()); } config.program = plainShader->program; |