summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/map/map.hpp1
-rw-r--r--include/mbgl/platform/default/glfw_view.hpp10
-rw-r--r--linux/main.cpp13
-rw-r--r--macosx/main.mm53
-rw-r--r--macosx/mapboxgl-app.gypi1
-rw-r--r--platform/default/glfw_view.cpp34
-rw-r--r--src/mbgl/map/map.cpp4
7 files changed, 96 insertions, 20 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index ae43dc8a8f..ebd79620d6 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -164,6 +164,7 @@ public:
void setDebug(bool value);
void toggleDebug();
bool getDebug() const;
+ void setNeedsRepaint();
void setCollisionDebug(bool value);
void toggleCollisionDebug();
bool getCollisionDebug() const;
diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp
index 1bc210b29e..ec99080732 100644
--- a/include/mbgl/platform/default/glfw_view.hpp
+++ b/include/mbgl/platform/default/glfw_view.hpp
@@ -12,7 +12,7 @@
class GLFWView : public mbgl::View {
public:
- GLFWView(bool fullscreen = false);
+ GLFWView(bool fullscreen = false, bool benchmark = false);
~GLFWView();
float getPixelRatio() const override;
@@ -42,7 +42,7 @@ public:
void setWindowTitle(const std::string&);
void run();
- void fps();
+ void report(float duration);
private:
mbgl::LatLng makeRandomPoint() const;
@@ -61,9 +61,15 @@ private:
private:
bool fullscreen = false;
+ const bool benchmark = false;
bool tracking = false;
bool rotating = false;
+ // Frame timer
+ int frames = 0;
+ float frameTime = 0;
+ double lastReported = 0;
+
int width = 1024;
int height = 768;
int fbWidth;
diff --git a/linux/main.cpp b/linux/main.cpp
index c21d7446e8..0892ce8f1e 100644
--- a/linux/main.cpp
+++ b/linux/main.cpp
@@ -32,17 +32,19 @@ void quit_handler(int) {
int main(int argc, char *argv[]) {
bool fullscreen = false;
+ bool benchmark = false;
std::string style;
const struct option long_options[] = {
{"fullscreen", no_argument, 0, 'f'},
+ {"benchmark", no_argument, 0, 'b'},
{"style", required_argument, 0, 's'},
{0, 0, 0, 0}
};
while (true) {
int option_index = 0;
- int opt = getopt_long(argc, argv, "fs:", long_options, &option_index);
+ int opt = getopt_long(argc, argv, "fbs:", long_options, &option_index);
if (opt == -1) break;
switch (opt)
{
@@ -52,6 +54,9 @@ int main(int argc, char *argv[]) {
case 'f':
fullscreen = true;
break;
+ case 'b':
+ benchmark = true;
+ break;
case 's':
style = std::string("asset://") + std::string(optarg);
default:
@@ -67,7 +72,11 @@ int main(int argc, char *argv[]) {
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
- view = std::make_unique<GLFWView>(fullscreen);
+ if (benchmark) {
+ mbgl::Log::Info(mbgl::Event::General, "BENCHMARK MODE: Some optimizations are disabled.");
+ }
+
+ view = std::make_unique<GLFWView>(fullscreen, benchmark);
mbgl::SQLiteCache cache("/tmp/mbgl-cache.db");
mbgl::DefaultFileSource fileSource(&cache);
diff --git a/macosx/main.mm b/macosx/main.mm
index 4a786f5772..24251e6d4f 100644
--- a/macosx/main.mm
+++ b/macosx/main.mm
@@ -12,6 +12,19 @@
#import <Foundation/Foundation.h>
+#pragma GCC diagnostic push
+#ifndef __clang__
+#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
+#pragma GCC diagnostic ignored "-Wshadow"
+#endif
+#include <boost/program_options.hpp>
+#pragma GCC diagnostic pop
+
+#include <iostream>
+
+namespace po = boost::program_options;
+
+
@interface URLHandler : NSObject
@property (nonatomic) mbgl::Map *map;
@@ -101,8 +114,33 @@ const std::string &defaultCacheDatabase() {
return path;
}
-int main() {
- GLFWView view;
+int main(int argc, char* argv[]) {
+ bool fullscreen = false;
+ bool benchmark = false;
+ std::string style;
+
+ po::options_description desc("Allowed options");
+ desc.add_options()
+ ("fullscreen,f", po::bool_switch(&fullscreen)->default_value(fullscreen), "Fullscreen mode")
+ ("style,s", po::value(&style)->value_name("json"), "Map stylesheet")
+ ("benchmark,b", po::bool_switch(&benchmark)->default_value(benchmark), "Benchmark mode")
+ ;
+
+ try {
+ auto parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
+ po::variables_map vm;
+ po::store(parsed, vm);
+ po::notify(vm);
+ } catch(std::exception& e) {
+ std::cout << "Error: " << e.what() << std::endl << desc;
+ exit(1);
+ }
+
+ if (benchmark) {
+ mbgl::Log::Info(mbgl::Event::General, "BENCHMARK MODE: Some optimizations are disabled.");
+ }
+
+ GLFWView view(fullscreen, benchmark);
mbgl::SQLiteCache cache(defaultCacheDatabase());
mbgl::DefaultFileSource fileSource(&cache);
@@ -146,10 +184,15 @@ int main() {
mbgl::Log::Info(mbgl::Event::Setup, std::string("Changed style to: ") + newStyle.first);
});
+
// Load style
- const auto& newStyle = mbgl::util::defaultStyles.front();
- map.setStyleURL(newStyle.first);
- view.setWindowTitle(newStyle.second);
+ if (style.empty()) {
+ const auto& newStyle = mbgl::util::defaultStyles.front();
+ style = newStyle.first;
+ view.setWindowTitle(newStyle.second);
+ }
+
+ map.setStyleURL(style);
view.run();
diff --git a/macosx/mapboxgl-app.gypi b/macosx/mapboxgl-app.gypi
index 589ae29bd5..e1d9476e1d 100644
--- a/macosx/mapboxgl-app.gypi
+++ b/macosx/mapboxgl-app.gypi
@@ -43,6 +43,7 @@
],
'libraries': [
'<@(glfw_static_libs)',
+ '<@(boost_libprogram_options_static_libs)'
],
},
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index 078c26feef..3ac60621e6 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -15,7 +15,8 @@ void glfwError(int error, const char *description) {
assert(false);
}
-GLFWView::GLFWView(bool fullscreen_) : fullscreen(fullscreen_) {
+GLFWView::GLFWView(bool fullscreen_, bool benchmark_)
+ : fullscreen(fullscreen_), benchmark(benchmark_) {
glfwSetErrorCallback(glfwError);
std::srand(std::time(0));
@@ -56,7 +57,13 @@ GLFWView::GLFWView(bool fullscreen_) : fullscreen(fullscreen_) {
glfwSetWindowUserPointer(window, this);
glfwMakeContextCurrent(window);
- glfwSwapInterval(1);
+ if (benchmark) {
+ // Disables vsync on platforms that support it.
+ glfwSwapInterval(0);
+ } else {
+ glfwSwapInterval(1);
+ }
+
glfwSetCursorPosCallback(window, onMouseMove);
glfwSetMouseButtonCallback(window, onMouseClick);
@@ -336,7 +343,12 @@ void GLFWView::run() {
glfwWaitEvents();
const bool dirty = !clean.test_and_set();
if (dirty) {
+ const double started = glfwGetTime();
map->renderSync();
+ report(1000 * (glfwGetTime() - started));
+ if (benchmark) {
+ map->setNeedsRepaint();
+ }
map->nudgeTransitions();
}
}
@@ -373,20 +385,20 @@ void GLFWView::invalidate() {
void GLFWView::swap() {
glfwSwapBuffers(window);
- fps();
}
-void GLFWView::fps() {
- static int frames = 0;
- static double timeElapsed = 0;
-
+void GLFWView::report(float duration) {
frames++;
- double currentTime = glfwGetTime();
+ frameTime += duration;
- if (currentTime - timeElapsed >= 1) {
- mbgl::Log::Info(mbgl::Event::OpenGL, "FPS: %4.2f", frames / (currentTime - timeElapsed));
- timeElapsed = currentTime;
+ const double currentTime = glfwGetTime();
+ if (currentTime - lastReported >= 1) {
+ frameTime /= frames;
+ mbgl::Log::Info(mbgl::Event::OpenGL, "Frame time: %6.2fms (%6.2f fps)", frameTime,
+ 1000 / frameTime);
frames = 0;
+ frameTime = 0;
+ lastReported = currentTime;
}
}
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index fadd4c48d9..a7015695c1 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -375,6 +375,10 @@ bool Map::getDebug() const {
return data->getDebug();
}
+void Map::setNeedsRepaint() {
+ data->setNeedsRepaint(true);
+}
+
void Map::setCollisionDebug(bool value) {
data->setCollisionDebug(value);
update(Update::Repaint);