align static render mode and still image render mode
- static rendering now also runs in a separate thread; you have to start it with map.start(Map::Mode::Static) and join the thread with map.stop() before destructing the Map object - map.renderStill() takes a callback with will be invoked on the *map* thread, so you'll have to figure out your own method of dispatching back to the main thread.
This commit is contained in:
@@ -42,16 +42,24 @@ class EnvironmentScope;
|
||||
class AnnotationManager;
|
||||
class MapData;
|
||||
class Worker;
|
||||
class StillImage;
|
||||
|
||||
class Map : private util::noncopyable {
|
||||
friend class View;
|
||||
|
||||
public:
|
||||
enum class Mode : uint8_t {
|
||||
None, // we're not doing any processing
|
||||
Continuous, // continually updating map
|
||||
Static, // a once-off static image.
|
||||
};
|
||||
|
||||
explicit Map(View&, FileSource&);
|
||||
~Map();
|
||||
|
||||
// Start the map render thread. It is asynchronous.
|
||||
void start(bool startPaused = false);
|
||||
void start(bool startPaused = false, Mode mode = Mode::Continuous);
|
||||
inline void start(Mode renderMode) { start(false, renderMode); }
|
||||
|
||||
// Stop the map render thread. This call will block until the map rendering thread stopped.
|
||||
// The optional callback function will be invoked repeatedly until the map thread is stopped.
|
||||
@@ -65,10 +73,8 @@ public:
|
||||
// Resumes a paused render thread
|
||||
void resume();
|
||||
|
||||
// Runs the map event loop. ONLY run this function when you want to get render a single frame
|
||||
// with this map object. It will *not* spawn a separate thread and instead block until the
|
||||
// frame is completely rendered.
|
||||
void run();
|
||||
using StillImageCallback = std::function<void(std::unique_ptr<const StillImage>)>;
|
||||
void renderStill(StillImageCallback callback);
|
||||
|
||||
// Triggers a synchronous or asynchronous render.
|
||||
void renderSync();
|
||||
@@ -167,6 +173,11 @@ public:
|
||||
inline AnnotationManager& getAnnotationManager() const { return *annotationManager; }
|
||||
|
||||
private:
|
||||
// Runs the map event loop. ONLY run this function when you want to get render a single frame
|
||||
// with this map object. It will *not* spawn a separate thread and instead block until the
|
||||
// frame is completely rendered.
|
||||
void run();
|
||||
|
||||
// This may only be called by the View object.
|
||||
void resize(uint16_t width, uint16_t height, float ratio = 1);
|
||||
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight);
|
||||
@@ -203,12 +214,6 @@ private:
|
||||
|
||||
size_t sourceCacheSize;
|
||||
|
||||
enum class Mode : uint8_t {
|
||||
None, // we're not doing any processing
|
||||
Continuous, // continually updating map
|
||||
Static, // a once-off static image.
|
||||
};
|
||||
|
||||
Mode mode = Mode::None;
|
||||
|
||||
const std::unique_ptr<Environment> env;
|
||||
@@ -260,6 +265,7 @@ private:
|
||||
|
||||
std::mutex mutexTask;
|
||||
std::queue<std::function<void()>> tasks;
|
||||
StillImageCallback callback;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
21
include/mbgl/map/still_image.hpp
Normal file
21
include/mbgl/map/still_image.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef MBGL_MAP_STILL_IMAGE
|
||||
#define MBGL_MAP_STILL_IMAGE
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class StillImage : util::noncopyable {
|
||||
public:
|
||||
uint16_t width = 0;
|
||||
uint16_t height = 0;
|
||||
using Pixel = uint32_t;
|
||||
std::unique_ptr<Pixel[]> pixels;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef MBGL_MAP_UPDATE
|
||||
#define MBGL_MAP_UPDATE
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
using UpdateType = uint32_t;
|
||||
@@ -12,6 +14,7 @@ enum class Update : UpdateType {
|
||||
DefaultTransitionDuration = 1 << 2,
|
||||
Classes = 1 << 3,
|
||||
Zoom = 1 << 4,
|
||||
RenderStill = 1 << 5,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class Map;
|
||||
class StillImage;
|
||||
|
||||
enum MapChange : uint8_t {
|
||||
MapChangeRegionWillChange = 0,
|
||||
@@ -40,6 +43,14 @@ public:
|
||||
// (i.e. map->renderSync() or map->renderAsync() must be called as a result of this)
|
||||
virtual void invalidate() = 0;
|
||||
|
||||
// Called from the render (=GL) thread. Signals that the contents of the contents
|
||||
// may be discarded. The default is a no-op.
|
||||
virtual void discard();
|
||||
|
||||
// Reads the pixel data from the current framebuffer. If your View implementation
|
||||
// doesn't support reading from the framebuffer, return a null pointer.
|
||||
virtual std::unique_ptr<StillImage> readStillImage();
|
||||
|
||||
// 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.
|
||||
|
||||
@@ -24,32 +24,47 @@ class HeadlessDisplay;
|
||||
|
||||
class HeadlessView : public View {
|
||||
public:
|
||||
HeadlessView();
|
||||
HeadlessView(std::shared_ptr<HeadlessDisplay> display);
|
||||
HeadlessView(uint16_t width = 256, uint16_t height = 256, float pixelRatio = 1);
|
||||
HeadlessView(std::shared_ptr<HeadlessDisplay> display, uint16_t width = 256, uint16_t height = 256, float pixelRatio = 1);
|
||||
~HeadlessView();
|
||||
|
||||
void createContext();
|
||||
void loadExtensions();
|
||||
|
||||
void resize(uint16_t width, uint16_t height, float pixelRatio);
|
||||
std::unique_ptr<uint32_t[]> readPixels();
|
||||
|
||||
void activate() override;
|
||||
void deactivate() override;
|
||||
void notify() override;
|
||||
void invalidate() override;
|
||||
void discard() override;
|
||||
std::unique_ptr<StillImage> readStillImage() override;
|
||||
|
||||
private:
|
||||
void createContext();
|
||||
void loadExtensions();
|
||||
void clearBuffers();
|
||||
bool isActive();
|
||||
|
||||
private:
|
||||
std::shared_ptr<HeadlessDisplay> display_;
|
||||
uint16_t width_;
|
||||
uint16_t height_;
|
||||
float pixelRatio_;
|
||||
std::shared_ptr<HeadlessDisplay> display;
|
||||
|
||||
struct Dimensions {
|
||||
inline Dimensions(uint16_t width = 0, uint16_t height = 0, float pixelRatio = 0);
|
||||
inline uint16_t pixelWidth() const { return width * pixelRatio; }
|
||||
inline uint16_t pixelHeight() const { return height * pixelRatio; }
|
||||
|
||||
uint16_t width = 0;
|
||||
uint16_t height = 0;
|
||||
float pixelRatio = 0;
|
||||
};
|
||||
|
||||
// These are the values that represent the state of the current framebuffer.
|
||||
Dimensions current;
|
||||
|
||||
// These are the values that will be used after the next discard() event.
|
||||
std::mutex prospectiveMutex;
|
||||
Dimensions prospective;
|
||||
|
||||
#if MBGL_USE_CGL
|
||||
CGLContextObj glContext;
|
||||
CGLContextObj glContext = nullptr;
|
||||
#endif
|
||||
|
||||
#if MBGL_USE_GLX
|
||||
@@ -64,6 +79,8 @@ private:
|
||||
GLuint fbo = 0;
|
||||
GLuint fboDepthStencil = 0;
|
||||
GLuint fboColor = 0;
|
||||
|
||||
std::thread::id thread;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user