summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2018-10-17 13:38:11 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2018-10-17 13:58:49 +0200
commitefac5b34796edcc98c8bd19cef8fc2cb3281ed59 (patch)
tree9378a08b6b9ffcc1742e6a5406bf92cf9130f964
parenteb4d5b797fcd845dfbc4879d756ab0034147fcc0 (diff)
downloadqtlocation-mapboxgl-upstream/renderer-state.tar.gz
[core] Introduce mbgl::RendererStateupstream/renderer-state
-rw-r--r--cmake/core-files.txt2
-rw-r--r--include/mbgl/renderer/renderer_state.hpp22
-rw-r--r--platform/default/mbgl/gl/headless_frontend.cpp1
-rw-r--r--src/mbgl/map/transform_state.hpp1
-rw-r--r--src/mbgl/renderer/renderer_state.cpp10
-rw-r--r--test/map/map.test.cpp28
6 files changed, 64 insertions, 0 deletions
diff --git a/cmake/core-files.txt b/cmake/core-files.txt
index 1d7d2ef41f..7c52e08ccf 100644
--- a/cmake/core-files.txt
+++ b/cmake/core-files.txt
@@ -180,6 +180,7 @@ include/mbgl/renderer/renderer.hpp
include/mbgl/renderer/renderer_backend.hpp
include/mbgl/renderer/renderer_frontend.hpp
include/mbgl/renderer/renderer_observer.hpp
+include/mbgl/renderer/renderer_state.hpp
src/mbgl/renderer/backend_scope.cpp
src/mbgl/renderer/bucket.hpp
src/mbgl/renderer/bucket_parameters.cpp
@@ -216,6 +217,7 @@ src/mbgl/renderer/renderer.cpp
src/mbgl/renderer/renderer_backend.cpp
src/mbgl/renderer/renderer_impl.cpp
src/mbgl/renderer/renderer_impl.hpp
+src/mbgl/renderer/renderer_state.cpp
src/mbgl/renderer/style_diff.cpp
src/mbgl/renderer/style_diff.hpp
src/mbgl/renderer/tile_mask.hpp
diff --git a/include/mbgl/renderer/renderer_state.hpp b/include/mbgl/renderer/renderer_state.hpp
new file mode 100644
index 0000000000..1b300c190b
--- /dev/null
+++ b/include/mbgl/renderer/renderer_state.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <mbgl/map/camera.hpp>
+#include <mbgl/util/geo.hpp>
+
+namespace mbgl {
+
+class UpdateParameters;
+
+/**
+ * RendererState acts as a Memento-like object that is able to extract data out of UpdateParameters (an opaque object
+ * from the public API perspective).
+ */
+class RendererState {
+public:
+
+ // Obtains a CameraOptions out of a given UpdateParameters object.
+ static CameraOptions getCameraOptions(UpdateParameters&, const EdgeInsets& = {});
+
+};
+
+} // namespace mbgl
diff --git a/platform/default/mbgl/gl/headless_frontend.cpp b/platform/default/mbgl/gl/headless_frontend.cpp
index c87a2796c9..1ec11a195f 100644
--- a/platform/default/mbgl/gl/headless_frontend.cpp
+++ b/platform/default/mbgl/gl/headless_frontend.cpp
@@ -1,5 +1,6 @@
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/renderer/renderer.hpp>
+#include <mbgl/renderer/renderer_state.hpp>
#include <mbgl/renderer/update_parameters.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/map/transform_state.hpp>
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index 4049965618..fe716d8ea8 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -20,6 +20,7 @@ class UnwrappedTileID;
class TransformState {
friend class Transform;
+ friend class RendererState;
public:
TransformState(ConstrainMode = ConstrainMode::HeightOnly, ViewportMode = ViewportMode::Default);
diff --git a/src/mbgl/renderer/renderer_state.cpp b/src/mbgl/renderer/renderer_state.cpp
new file mode 100644
index 0000000000..dc5c4c1292
--- /dev/null
+++ b/src/mbgl/renderer/renderer_state.cpp
@@ -0,0 +1,10 @@
+#include <mbgl/renderer/renderer_state.hpp>
+#include <mbgl/renderer/update_parameters.hpp>
+
+namespace mbgl {
+
+CameraOptions RendererState::getCameraOptions(UpdateParameters& updateParameters, const EdgeInsets& padding) {
+ return updateParameters.transformState.getCameraOptions(padding);
+}
+
+} // namespace mbgl
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index 88ddfa6cee..cd15c5c278 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -49,6 +49,34 @@ public:
}
};
+TEST(Map, RendererState) {
+ MapTest<> test;
+
+ // Map hasn't notified the frontend about an update yet.
+ CameraOptions nullOptions;
+ ASSERT_EQ(test.frontend.getCameraOptions(), nullOptions);
+
+ LatLng coordinate { 1, 1 };
+ double zoom = 12.0;
+ double pitchInDegrees = 45.0;
+ double bearingInDegrees = 30.0;
+
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.setLatLngZoom(coordinate, zoom);
+ test.map.setPitch(pitchInDegrees);
+ test.map.setBearing(bearingInDegrees);
+
+ test.runLoop.runOnce();
+ test.frontend.render(test.map);
+
+ const CameraOptions& options = test.frontend.getCameraOptions();
+ EXPECT_NEAR(options.center->latitude(), coordinate.latitude(), 1e-7);
+ EXPECT_NEAR(options.center->longitude(), coordinate.longitude(), 1e-7);
+ ASSERT_DOUBLE_EQ(*options.zoom, zoom);
+ ASSERT_DOUBLE_EQ(*options.pitch, pitchInDegrees);
+ EXPECT_NEAR(*options.angle, bearingInDegrees, 1e-7);
+}
+
TEST(Map, LatLngBehavior) {
MapTest<> test;