summaryrefslogtreecommitdiff
path: root/include/mbgl/map
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-10-10 17:16:37 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-10-25 13:52:36 -0700
commita4d259c33f9bb890bba97fd89552720e3e0ec09b (patch)
tree342ecc27a6993c48f3a2e1d739fce890350bc44d /include/mbgl/map
parent5cc390d694fc7510d445310d8eb9e32429a5e67b (diff)
downloadqtlocation-mapboxgl-a4d259c33f9bb890bba97fd89552720e3e0ec09b.tar.gz
[core] move gl::Context to Backend and refactor View
Diffstat (limited to 'include/mbgl/map')
-rw-r--r--include/mbgl/map/backend.hpp15
-rw-r--r--include/mbgl/map/map.hpp17
-rw-r--r--include/mbgl/map/update.hpp31
-rw-r--r--include/mbgl/map/view.hpp28
4 files changed, 25 insertions, 66 deletions
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 <mbgl/map/change.hpp>
+#include <memory>
+
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<gl::Context> 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 <mbgl/util/optional.hpp>
#include <mbgl/util/chrono.hpp>
-#include <mbgl/util/image.hpp>
-#include <mbgl/map/update.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/feature.hpp>
@@ -35,7 +33,7 @@ class Layer;
class Map : private util::noncopyable {
public:
explicit Map(Backend&,
- View&,
+ std::array<uint16_t, 2> 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 (std::exception_ptr, PremultipliedImage&&)>;
- void renderStill(StillImageCallback callback);
+ using StillImageCallback = std::function<void (std::exception_ptr)>;
+ 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, 2>&);
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 <mbgl/util/traits.hpp>
-
-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 <mbgl/util/image.hpp>
-
-#include <array>
+#include <mbgl/util/noncopyable.hpp>
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<uint16_t, 2> 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<uint16_t, 2> 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<uint16_t, 2> size = {{ 0, 0 }});
-
-protected:
- mbgl::Map *map = nullptr;
};
} // namespace mbgl