From 204c7fee032bf8509747046b43a788366a189ae7 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 1 Sep 2015 15:07:17 +0300 Subject: [core] Render from the main thread Do not create a thread for the MapContext anymore. --- include/mbgl/map/map.hpp | 19 ++++------------- include/mbgl/map/view.hpp | 52 +++++++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 42 deletions(-) (limited to 'include/mbgl/map') diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 9d586d8b8a..b70c388183 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -32,10 +32,6 @@ class ShapeAnnotation; struct CameraOptions; struct AnimationOptions; -namespace util { -template class Thread; -} // namespace util - class Map : private util::noncopyable { friend class View; @@ -46,22 +42,15 @@ public: ConstrainMode constrainMode = ConstrainMode::HeightOnly); ~Map(); - // Pauses the render thread. The render thread will stop running but will not be terminated and will not lose state until resumed. - void pause(); - bool isPaused(); - - // Resumes a paused render thread - void resume(); - // Register a callback that will get called (on the render thread) when all resources have // been loaded and a complete render occurs. using StillImageCallback = std::function; void renderStill(StillImageCallback callback); - // Triggers a synchronous render. - void renderSync(); + // Main render function. + void render(); - // Notifies the Map thread that the state has changed and an update might be necessary. + // Notifies the Map that the state has changed and an update might be necessary. void update(Update update); // Styling @@ -189,7 +178,7 @@ public: private: View& view; const std::unique_ptr transform; - const std::unique_ptr> context; + const std::unique_ptr context; MapData* data; enum class RenderState { diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp index 6f481c4458..fd11080064 100644 --- a/include/mbgl/map/view.hpp +++ b/include/mbgl/map/view.hpp @@ -30,44 +30,42 @@ enum MapChange : uint8_t { class View { public: - // Called from the main thread directly after initialization. Must always return the same value, - // i.e. it may not change over time. + virtual ~View() = default; + + // Called directly after initialization. Must always return the same value, i.e. it may + // not change over time. virtual float getPixelRatio() const = 0; - // Called from the main thread when the View signaled a dimension change. Must return the - // logical dimension of this map in pixels. + // Called when the View signaled a dimension change. Must return the logical dimension + // of this map in pixels. virtual std::array getSize() const = 0; - // Called from the main thread for every frame that is being rendered. Must return the absolute - // dimensions of the current framebuffer. Typically, this is the logical width scaled by the - // pixel ratio, but in case the view was moved to display with a different pixel ratio, it can - // also be different from that rule. + // Called for every frame that is being rendered. Must return the absolute dimensions of + // the current framebuffer. Typically, this is the logical width scaled by the pixel ratio, + // but in case the view was moved to display with a different pixel ratio, it can also be + // different from that rule. virtual std::array getFramebufferSize() const = 0; - // Called from the main thread when this View is associated with a Map object. - 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 - // renderer setup since the render thread doesn't switch the contexts. + // Called when this View is associated with a Map object. + virtual void initialize(Map*); + + // Called when the view's GL context needs to be made active or inactive. These are called, + // as a matched pair, in four situations: + // + // 1. When releasing GL resources during Map destruction + // 2. When calling a CustomLayerInitializeFunction, during Map::addCustomLayer + // 3. When calling a CustomLayerDeinitializeFunction, during Map::removeCustomLayer + // 4. When rendering for Map::renderStill + // + // They are *not* called for Map::render; it is assumed that the correct context is already + // activated prior to calling Map::render. virtual void activate() = 0; - - // Called from the render thread. Makes the GL context inactive in the current - // thread. This is called once just before the rendering thread terminates. virtual void deactivate() = 0; - virtual void notify() = 0; - - // Called from the render thread. The implementation must trigger a rerender. - // (map->renderSync() from the main thread must be called as a result of this) + // Called when the map needs to be rendered; the view should call Map::render() at some point + // in the near future. (Not called for Map::renderStill() mode.) virtual void invalidate() = 0; - // Called from the render thread before the render begins. - virtual void beforeRender() = 0; - - // Called from the render thread after the render is complete. - virtual void afterRender() = 0; - // Reads the pixel data from the current framebuffer. If your View implementation // doesn't support reading from the framebuffer, return a null pointer. virtual PremultipliedImage readStillImage(); -- cgit v1.2.1