summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-03-11 19:43:13 +0100
committerKonstantin Käfer <mail@kkaefer.com>2015-03-12 12:16:38 +0100
commit47ede853c4c0dd8e953f3ee98b807f044d178d76 (patch)
tree75d56f01853cb64b200d8977069dfe992266e9de /include
parentba9d2420699507c6d32b12272151529663c8d2fd (diff)
downloadqtlocation-mapboxgl-47ede853c4c0dd8e953f3ee98b807f044d178d76.tar.gz
fixes black flicker on rotating the device
fixes #838 instead of rendering ad libitum on the map thread, we are now driving rendering from the UI thread on iOS via the map.renderSync() function. There are still white bars during the rotation, but the general content of the view is kept visible. - upgrades GLFW to 3.1 - removes swapped/needsSwap in favor of a more explicit scheme - View#invalidate() now replaces View#swap() and is called whenever the View needs to trigger a rerender. GLFW and Android to this right away, while iOS goes back to the main thread and does the Map redrawing as part of the GLKView update - sets all iOS deployment targets to 7.0 - disables SQLite3 version check, since the library version changed on iOS 8.2
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/android/native_map_view.hpp5
-rw-r--r--include/mbgl/map/map.hpp38
-rw-r--r--include/mbgl/map/view.hpp16
-rw-r--r--include/mbgl/platform/default/glfw_view.hpp13
-rw-r--r--include/mbgl/platform/default/headless_view.hpp11
5 files changed, 36 insertions, 47 deletions
diff --git a/include/mbgl/android/native_map_view.hpp b/include/mbgl/android/native_map_view.hpp
index d02d43e58a..62446bf15a 100644
--- a/include/mbgl/android/native_map_view.hpp
+++ b/include/mbgl/android/native_map_view.hpp
@@ -22,10 +22,9 @@ public:
void activate() override;
void deactivate() override;
-
- void swap() override;
-
void notify() override;
+ void invalidate() override;
+
void notifyMapChange(mbgl::MapChange change, std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero()) override;
mbgl::Map &getMap();
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 00719aa382..44a560a468 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -65,19 +65,22 @@ public:
// frame is completely rendered.
void run();
- // Triggers a lazy rerender: only performs a render when the map is not clean.
- void rerender();
+ // Triggers a synchronous or asynchronous render.
+ void renderSync();
- // Forces a map update: always triggers a rerender.
- void update();
+ // Unconditionally performs a render with the current map state. May only be called from the Map
+ // thread.
+ void render();
+
+ // Notifies the Map thread that the state has changed and an update might be necessary.
+ void triggerUpdate();
+
+ // Triggers a render. Can be called from any thread.
+ void triggerRender();
// Releases resources immediately
void terminate();
- // Controls buffer swapping.
- bool needsSwap();
- void swapped();
-
// Styling
void addClass(const std::string&);
void removeClass(const std::string&);
@@ -167,9 +170,6 @@ private:
// the stylesheet.
void prepare();
- // Unconditionally performs a render with the current map state.
- void render();
-
enum class Mode : uint8_t {
None, // we're not doing any processing
Continuous, // continually updating map
@@ -185,6 +185,7 @@ private:
std::unique_ptr<uv::worker> workers;
std::thread thread;
std::unique_ptr<uv::async> asyncTerminate;
+ std::unique_ptr<uv::async> asyncUpdate;
std::unique_ptr<uv::async> asyncRender;
bool terminating = false;
@@ -195,17 +196,10 @@ private:
std::mutex mutexPause;
std::condition_variable condPause;
- // If cleared, the next time the render thread attempts to render the map, it will *actually*
- // render the map.
- std::atomic_flag isClean = ATOMIC_FLAG_INIT;
-
- // If this flag is cleared, the current back buffer is ready for being swapped with the front
- // buffer (i.e. it has rendered data).
- std::atomic_flag isSwapped = ATOMIC_FLAG_INIT;
-
- // This is cleared once the current front buffer has been presented and the back buffer is
- // ready for rendering.
- std::atomic_flag isRendered = ATOMIC_FLAG_INIT;
+ // Used to signal that rendering completed.
+ bool rendered = false;
+ std::condition_variable condRendered;
+ std::mutex mutexRendered;
// Stores whether the map thread has been stopped already.
std::atomic_bool isStopped;
diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp
index 7d8c25f445..1ee9d300c5 100644
--- a/include/mbgl/map/view.hpp
+++ b/include/mbgl/map/view.hpp
@@ -22,13 +22,7 @@ enum MapChange : uint8_t {
class View {
public:
- virtual void initialize(Map *map_) {
- map = map_;
- }
-
- // Called from the render (=GL) thread. Signals that the context should
- // swap the front and the back buffer.
- virtual void swap() = 0;
+ virtual void initialize(Map *map_);
// Called from the render thread. Makes the GL context active in the current
// thread. This is typically just called once at the beginning of the
@@ -41,10 +35,16 @@ public:
virtual void notify() = 0;
+ // Called from the render thread. The implementation must trigger a rerender.
+ // (i.e. map->renderSync() or map->renderAsync() must be called as a result of this)
+ virtual void invalidate() = 0;
+
// Notifies a watcher of map x/y/scale/rotation changes.
// Must only be called from the same thread that caused the change.
// Must not be called from the render thread.
- virtual void notifyMapChange(MapChange change, std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero()) = 0;
+ virtual void notifyMapChange(
+ MapChange change,
+ std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero());
protected:
// Resizes the view
diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp
index 8f5cfb7281..234568e4b7 100644
--- a/include/mbgl/platform/default/glfw_view.hpp
+++ b/include/mbgl/platform/default/glfw_view.hpp
@@ -13,12 +13,11 @@ public:
GLFWView(bool fullscreen = false);
~GLFWView();
- void initialize(mbgl::Map *map);
- void swap();
- void activate();
- void deactivate();
- void notify();
- void notifyMapChange(mbgl::MapChange change, std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero());
+ void initialize(mbgl::Map *map) override;
+ void activate() override;
+ void deactivate() override;
+ void notify() override;
+ void invalidate() override;
static void onKey(GLFWwindow *window, int key, int scancode, int action, int mods);
static void onScroll(GLFWwindow *window, double xoffset, double yoffset);
@@ -26,8 +25,6 @@ public:
static void onMouseClick(GLFWwindow *window, int button, int action, int modifiers);
static void onMouseMove(GLFWwindow *window, double x, double y);
- static void eventloop(void *arg);
-
int run();
void fps();
diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp
index 5d0e55d69a..5ba6709a4f 100644
--- a/include/mbgl/platform/default/headless_view.hpp
+++ b/include/mbgl/platform/default/headless_view.hpp
@@ -13,7 +13,7 @@ typedef long unsigned int XID;
typedef XID GLXPbuffer;
#endif
-#include <mbgl/map/view.hpp>
+#include <mbgl/mbgl.hpp>
#include <mbgl/platform/gl.hpp>
#include <memory>
@@ -34,11 +34,10 @@ public:
void resize(uint16_t width, uint16_t height, float pixelRatio);
std::unique_ptr<uint32_t[]> readPixels();
- void notify();
- void notifyMapChange(MapChange change, std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero());
- void activate();
- void deactivate();
- void swap();
+ void activate() override;
+ void deactivate() override;
+ void notify() override;
+ void invalidate() override;
private:
void clearBuffers();