From a4d259c33f9bb890bba97fd89552720e3e0ec09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Mon, 10 Oct 2016 17:16:37 +0200 Subject: [core] move gl::Context to Backend and refactor View --- include/mbgl/map/backend.hpp | 15 +++++++++++++-- include/mbgl/map/map.hpp | 17 ++++++++--------- include/mbgl/map/update.hpp | 31 ------------------------------- include/mbgl/map/view.hpp | 28 ++++------------------------ 4 files changed, 25 insertions(+), 66 deletions(-) delete mode 100644 include/mbgl/map/update.hpp (limited to 'include/mbgl/map') diff --git a/include/mbgl/map/backend.hpp b/include/mbgl/map/backend.hpp index e4a5634b88..c11d094906 100644 --- a/include/mbgl/map/backend.hpp +++ b/include/mbgl/map/backend.hpp @@ -2,13 +2,21 @@ #include +#include + namespace mbgl { -class Map; +namespace gl { +class Context; +} // namespace gl class Backend { public: - virtual ~Backend() = default; + Backend(); + virtual ~Backend(); + + // Returns the backend's context which manages OpenGL state. + gl::Context& getContext(); // Called when the backend's GL context needs to be made active or inactive. These are called, // as a matched pair, in four situations: @@ -29,6 +37,9 @@ public: // Notifies a watcher of map x/y/scale/rotation changes. virtual void notifyMapChange(MapChange change); + +private: + const std::unique_ptr context; }; } // namespace mbgl diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 4f6207fc6f..b1c840e68d 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -2,8 +2,6 @@ #include #include -#include -#include #include #include #include @@ -35,7 +33,7 @@ class Layer; class Map : private util::noncopyable { public: explicit Map(Backend&, - View&, + std::array size, float pixelRatio, FileSource&, Scheduler&, @@ -47,14 +45,14 @@ public: // 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); + using StillImageCallback = std::function; + void renderStill(View&, StillImageCallback callback); - // Main render function. - void render(); + // Triggers a repaint. + void triggerRepaint(); - // Notifies the Map that the state has changed and an update might be necessary. - void update(Update update); + // Main render function. + void render(View&); // Styling void addClass(const std::string&); @@ -138,6 +136,7 @@ public: ViewportMode getViewportMode() const; // Size + void setSize(const std::array&); uint16_t getWidth() const; uint16_t getHeight() const; diff --git a/include/mbgl/map/update.hpp b/include/mbgl/map/update.hpp deleted file mode 100644 index 1da7e3ac92..0000000000 --- a/include/mbgl/map/update.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include - -namespace mbgl { - -enum class Update { - Nothing = 0, - Dimensions = 1 << 1, - Classes = 1 << 2, - RecalculateStyle = 1 << 3, - RenderStill = 1 << 4, - Repaint = 1 << 5, - AnnotationStyle = 1 << 6, - AnnotationData = 1 << 7, - Layout = 1 << 8 -}; - -constexpr Update operator|(Update lhs, Update rhs) { - return Update(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs)); -} - -constexpr Update& operator|=(Update& lhs, const Update& rhs) { - return (lhs = lhs | rhs); -} - -constexpr bool operator& (Update lhs, Update rhs) { - return mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs); -} - -} // namespace mbgl diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp index 0dff4b3602..6517c6b220 100644 --- a/include/mbgl/map/view.hpp +++ b/include/mbgl/map/view.hpp @@ -1,8 +1,6 @@ #pragma once -#include - -#include +#include namespace mbgl { @@ -12,29 +10,11 @@ class View : private util::noncopyable { public: virtual ~View() = default; - // Called when this View is associated with a Map object. - virtual void initialize(Map*); - // Called when this View is used for rendering. Implementations should ensure that a renderable - // object is bound and glClear/glDraw* calls can be done. + // object is bound and glClear/glDraw* calls can be done. They should also make sure that + // calling .bind() repeatedly is a no-op and that the appropriate gl::Context values are + // set to the current state. virtual void bind() = 0; - - // 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 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; - - // 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(std::array size = {{ 0, 0 }}); - -protected: - mbgl::Map *map = nullptr; }; } // namespace mbgl -- cgit v1.2.1