drive map rendering from main thread

This commit is contained in:
Konstantin Käfer
2015-05-22 15:56:05 +02:00
committed by John Firebaugh
parent 740281cc89
commit 84e2ea886d
14 changed files with 71 additions and 35 deletions

View File

@@ -23,7 +23,8 @@ public:
void activate() override;
void deactivate() override;
void notify() override;
void invalidate(std::function<void()> render) override;
void invalidate() override;
void swap() override;
void notifyMapChange(mbgl::MapChange change, Duration delay = Duration::zero()) override;

View File

@@ -44,9 +44,11 @@ public:
virtual void resize(uint16_t width, uint16_t height, float pixelRatio);
// Called from the render thread. The implementation must trigger a rerender.
// (i.e. either the passed render() function for rendering immediately on the map thread,
// or map->renderSync() from the main thread must be called as a result of this)
virtual void invalidate(std::function<void()> render) = 0;
// (map->renderSync() from the main thread must be called as a result of this)
virtual void invalidate() = 0;
// Called from the render thread after the render is complete.
virtual void swap() = 0;
// Reads the pixel data from the current framebuffer. If your View implementation
// doesn't support reading from the framebuffer, return a null pointer.

View File

@@ -8,6 +8,8 @@
#endif
#include <GLFW/glfw3.h>
#include <atomic>
class GLFWView : public mbgl::View {
public:
GLFWView(bool fullscreen = false);
@@ -17,7 +19,8 @@ public:
void activate() override;
void deactivate() override;
void notify() override;
void invalidate(std::function<void()> render) override;
void invalidate() override;
void swap() override;
static void onKey(GLFWwindow *window, int key, int scancode, int action, int mods);
static void onScroll(GLFWwindow *window, double xoffset, double yoffset);
@@ -62,6 +65,7 @@ private:
std::function<void()> changeStyleCallback;
GLFWwindow *window = nullptr;
std::atomic_flag clean = ATOMIC_FLAG_INIT;
};
#endif

View File

@@ -33,7 +33,8 @@ public:
void deactivate() override;
void notify() override;
void resize(uint16_t width, uint16_t height, float pixelRatio) override;
void invalidate(std::function<void()> render) override;
void invalidate() override;
void swap() override;
std::unique_ptr<StillImage> readStillImage() override;
private: