diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-05-11 13:45:27 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-05-18 12:07:21 +0200 |
commit | 002393bdead2f036982ea3adb8a13a3d58f3428a (patch) | |
tree | 73da2311cb98ec7f0acf6f6bf2b1f9858846000c | |
parent | 1d84a8964e39bd6a35de1dc64c03496bcdcf2c4f (diff) | |
download | qtlocation-mapboxgl-002393bdead2f036982ea3adb8a13a3d58f3428a.tar.gz |
[core] remove MockView and View dependency in Transform
-rw-r--r-- | include/mbgl/map/view.hpp | 18 | ||||
-rw-r--r-- | src/mbgl/map/change.hpp | 27 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/map/transform.cpp | 30 | ||||
-rw-r--r-- | src/mbgl/map/transform.hpp | 9 | ||||
-rw-r--r-- | test/map/transform.cpp | 37 | ||||
-rw-r--r-- | test/src/mbgl/test/mock_view.hpp | 26 | ||||
-rw-r--r-- | test/style/source.cpp | 4 | ||||
-rw-r--r-- | test/test.gypi | 1 | ||||
-rw-r--r-- | test/util/tile_cover.cpp | 4 |
10 files changed, 76 insertions, 91 deletions
diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp index ea63daa70e..c62cc32bfc 100644 --- a/include/mbgl/map/view.hpp +++ b/include/mbgl/map/view.hpp @@ -1,6 +1,7 @@ #ifndef MBGL_MAP_VIEW #define MBGL_MAP_VIEW +#include <mbgl/map/change.hpp> #include <mbgl/util/chrono.hpp> #include <mbgl/util/image.hpp> @@ -11,23 +12,6 @@ namespace mbgl { class Map; -enum MapChange : uint8_t { - MapChangeRegionWillChange = 0, - MapChangeRegionWillChangeAnimated = 1, - MapChangeRegionIsChanging = 2, - MapChangeRegionDidChange = 3, - MapChangeRegionDidChangeAnimated = 4, - MapChangeWillStartLoadingMap = 5, - MapChangeDidFinishLoadingMap = 6, - MapChangeDidFailLoadingMap = 7, - MapChangeWillStartRenderingFrame = 8, - MapChangeDidFinishRenderingFrame = 9, - MapChangeDidFinishRenderingFrameFullyRendered = 10, - MapChangeWillStartRenderingMap = 11, - MapChangeDidFinishRenderingMap = 12, - MapChangeDidFinishRenderingMapFullyRendered = 13, -}; - class View { public: virtual ~View() = default; diff --git a/src/mbgl/map/change.hpp b/src/mbgl/map/change.hpp new file mode 100644 index 0000000000..01adc497d3 --- /dev/null +++ b/src/mbgl/map/change.hpp @@ -0,0 +1,27 @@ +#ifndef MBGL_MAP_CHANGE +#define MBGL_MAP_CHANGE + +#include <cstdint> + +namespace mbgl { + +enum MapChange : uint8_t { + MapChangeRegionWillChange = 0, + MapChangeRegionWillChangeAnimated = 1, + MapChangeRegionIsChanging = 2, + MapChangeRegionDidChange = 3, + MapChangeRegionDidChangeAnimated = 4, + MapChangeWillStartLoadingMap = 5, + MapChangeDidFinishLoadingMap = 6, + MapChangeDidFailLoadingMap = 7, + MapChangeWillStartRenderingFrame = 8, + MapChangeDidFinishRenderingFrame = 9, + MapChangeDidFinishRenderingFrameFullyRendered = 10, + MapChangeWillStartRenderingMap = 11, + MapChangeDidFinishRenderingMap = 12, + MapChangeDidFinishRenderingMapFullyRendered = 13, +}; + +} // namespace mbgl + +#endif diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 5773b3f658..0a6adfc565 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -83,10 +83,17 @@ Map::Map(View& view, FileSource& fileSource, MapMode mapMode, GLContextMode cont update(Update::Dimensions); } -Map::Impl::Impl(View& view_, FileSource& fileSource_, MapMode mode_, GLContextMode contextMode_, ConstrainMode constrainMode_, ViewportMode viewportMode_) +Map::Impl::Impl(View& view_, + FileSource& fileSource_, + MapMode mode_, + GLContextMode contextMode_, + ConstrainMode constrainMode_, + ViewportMode viewportMode_) : view(view_), fileSource(fileSource_), - transform(view, constrainMode_, viewportMode_), + transform([this](MapChange change) { view.notifyMapChange(change); }, + constrainMode_, + viewportMode_), mode(mode_), contextMode(contextMode_), pixelRatio(view.getPixelRatio()), diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 4a40e13202..d2f32acb67 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -36,10 +36,10 @@ static double _normalizeAngle(double angle, double anchorAngle) return angle; } -Transform::Transform(View &view_, ConstrainMode constrainMode, ViewportMode viewportMode) - : view(view_) - , state(constrainMode, viewportMode) -{ +Transform::Transform(std::function<void(MapChange)> callback_, + ConstrainMode constrainMode, + ViewportMode viewportMode) + : callback(std::move(callback_)), state(constrainMode, viewportMode) { } #pragma mark - Map View @@ -47,13 +47,17 @@ Transform::Transform(View &view_, ConstrainMode constrainMode, ViewportMode view bool Transform::resize(const std::array<uint16_t, 2> size) { if (state.width != size[0] || state.height != size[1]) { - view.notifyMapChange(MapChangeRegionWillChange); + if (callback) { + callback(MapChangeRegionWillChange); + } state.width = size[0]; state.height = size[1]; state.constrain(state.scale, state.x, state.y); - view.notifyMapChange(MapChangeRegionDidChange); + if (callback) { + callback(MapChangeRegionDidChange); + } return true; } else { @@ -560,8 +564,10 @@ void Transform::startTransition(const CameraOptions& camera, } bool isAnimated = duration != Duration::zero(); - view.notifyMapChange(isAnimated ? MapChangeRegionWillChangeAnimated : MapChangeRegionWillChange); - + if (callback) { + callback(isAnimated ? MapChangeRegionWillChangeAnimated : MapChangeRegionWillChange); + } + // Associate the anchor, if given, with a coordinate. optional<ScreenCoordinate> anchor = camera.anchor; LatLng anchorLatLng; @@ -590,7 +596,9 @@ void Transform::startTransition(const CameraOptions& camera, if (animation.transitionFrameFn) { animation.transitionFrameFn(t); } - view.notifyMapChange(MapChangeRegionIsChanging); + if (callback) { + callback(MapChangeRegionIsChanging); + } } else { transitionFinishFn(); transitionFinishFn = nullptr; @@ -609,7 +617,9 @@ void Transform::startTransition(const CameraOptions& camera, if (animation.transitionFinishFn) { animation.transitionFinishFn(); } - view.notifyMapChange(isAnimated ? MapChangeRegionDidChangeAnimated : MapChangeRegionDidChange); + if (callback) { + callback(isAnimated ? MapChangeRegionDidChangeAnimated : MapChangeRegionDidChange); + } }; if (!isAnimated) { diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index cd2d7a33f3..8752af9b41 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -3,6 +3,7 @@ #include <mbgl/map/camera.hpp> #include <mbgl/map/mode.hpp> +#include <mbgl/map/change.hpp> #include <mbgl/map/transform_state.hpp> #include <mbgl/map/update.hpp> #include <mbgl/util/chrono.hpp> @@ -16,11 +17,11 @@ namespace mbgl { -class View; - class Transform : private util::noncopyable { public: - Transform(View&, ConstrainMode, ViewportMode); + Transform(std::function<void(MapChange)> = nullptr, + ConstrainMode = ConstrainMode::HeightOnly, + ViewportMode = ViewportMode::Default); // Map view bool resize(std::array<uint16_t, 2> size); @@ -163,7 +164,7 @@ public: LatLng screenCoordinateToLatLng(const ScreenCoordinate&) const; private: - View &view; + std::function<void(MapChange)> callback; TransformState state; diff --git a/test/map/transform.cpp b/test/map/transform.cpp index b9a905274a..3cf542c4f3 100644 --- a/test/map/transform.cpp +++ b/test/map/transform.cpp @@ -1,5 +1,4 @@ #include <mbgl/test/util.hpp> -#include <mbgl/test/mock_view.hpp> #include <mbgl/map/transform.hpp> #include <mbgl/util/geo.hpp> @@ -7,8 +6,7 @@ using namespace mbgl; TEST(Transform, InvalidScale) { - MockView view; - Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default); + Transform transform; ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude); @@ -47,8 +45,7 @@ TEST(Transform, InvalidScale) { } TEST(Transform, InvalidLatLng) { - MockView view; - Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default); + Transform transform; ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude); @@ -83,8 +80,7 @@ TEST(Transform, InvalidLatLng) { TEST(Transform, InvalidBearing) { - MockView view; - Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default); + Transform transform; ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude); @@ -108,10 +104,9 @@ TEST(Transform, InvalidBearing) { } TEST(Transform, PerspectiveProjection) { - MockView view; LatLng loc; - Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default); + Transform transform; transform.resize({{ 1000, 1000 }}); transform.setScale(2 << 9); transform.setPitch(0.9); @@ -141,8 +136,7 @@ TEST(Transform, PerspectiveProjection) { } TEST(Transform, UnwrappedLatLng) { - MockView view; - Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default); + Transform transform; transform.resize({{ 1000, 1000 }}); transform.setScale(2 << 9); transform.setPitch(0.9); @@ -172,10 +166,9 @@ TEST(Transform, UnwrappedLatLng) { } TEST(Transform, ConstrainHeightOnly) { - MockView view; LatLng loc; - Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default); + Transform transform; transform.resize({{ 1000, 1000 }}); transform.setScale(std::pow(2, util::MAX_ZOOM)); @@ -191,10 +184,9 @@ TEST(Transform, ConstrainHeightOnly) { } TEST(Transform, ConstrainWidthAndHeight) { - MockView view; LatLng loc; - Transform transform(view, ConstrainMode::WidthAndHeight, ViewportMode::Default); + Transform transform(nullptr, ConstrainMode::WidthAndHeight); transform.resize({{ 1000, 1000 }}); transform.setScale(std::pow(2, util::MAX_ZOOM)); @@ -210,8 +202,7 @@ TEST(Transform, ConstrainWidthAndHeight) { } TEST(Transform, Anchor) { - MockView view; - Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default); + Transform transform; transform.resize({{ 1000, 1000 }}); const LatLng latLng { 10, -100 }; @@ -311,8 +302,7 @@ TEST(Transform, Anchor) { } TEST(Transform, Padding) { - MockView view; - Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default); + Transform transform; transform.resize({{ 1000, 1000 }}); ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude); @@ -349,8 +339,7 @@ TEST(Transform, Padding) { } TEST(Transform, MoveBy) { - MockView view; - Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default); + Transform transform; transform.resize({{ 1000, 1000 }}); transform.setLatLngZoom({ 0, 0 }, 10); @@ -377,8 +366,7 @@ TEST(Transform, MoveBy) { } TEST(Transform, Antimeridian) { - MockView view; - Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default); + Transform transform; transform.resize({{ 1000, 1000 }}); transform.setLatLngZoom({ 0, 0 }, 1); @@ -421,8 +409,7 @@ TEST(Transform, Antimeridian) { } TEST(Transform, Camera) { - MockView view; - Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default); + Transform transform; transform.resize({{ 1000, 1000 }}); const LatLng latLng1 { 45, 135 }; diff --git a/test/src/mbgl/test/mock_view.hpp b/test/src/mbgl/test/mock_view.hpp deleted file mode 100644 index 50ae466d19..0000000000 --- a/test/src/mbgl/test/mock_view.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef TEST_FIXTURES_MOCK_VIEW -#define TEST_FIXTURES_MOCK_VIEW - -#include <mbgl/map/view.hpp> - -#include <array> - -namespace mbgl { - -class MockView : public View { -public: - MockView() = default; - - // View implementation. - float getPixelRatio() const override { return 1; } - std::array<uint16_t, 2> getSize() const override { return {{ 0, 0 }}; } - std::array<uint16_t, 2> getFramebufferSize() const override { return {{ 0, 0 }}; } - - void activate() override {}; - void deactivate() override {}; - void invalidate() override {} -}; - -} - -#endif diff --git a/test/style/source.cpp b/test/style/source.cpp index 156aff71ad..622ec7ae7e 100644 --- a/test/style/source.cpp +++ b/test/style/source.cpp @@ -1,6 +1,5 @@ #include <mbgl/test/util.hpp> #include <mbgl/test/stub_file_source.hpp> -#include <mbgl/test/mock_view.hpp> #include <mbgl/test/stub_style_observer.hpp> #include <mbgl/source/source.hpp> @@ -24,8 +23,7 @@ public: util::RunLoop loop; StubFileSource fileSource; StubStyleObserver observer; - MockView view; - Transform transform { view, ConstrainMode::HeightOnly, ViewportMode::Default }; + Transform transform; TransformState transformState; Worker worker { 1 }; gl::TexturePool texturePool; diff --git a/test/test.gypi b/test/test.gypi index 1db886e097..5c04262644 100644 --- a/test/test.gypi +++ b/test/test.gypi @@ -80,7 +80,6 @@ 'src/mbgl/test/stub_file_source.hpp', 'src/mbgl/test/stub_file_source.cpp', - 'src/mbgl/test/mock_view.hpp', 'src/mbgl/test/util.hpp', 'src/mbgl/test/util.cpp', 'src/mbgl/test/fixture_log_observer.hpp', diff --git a/test/util/tile_cover.cpp b/test/util/tile_cover.cpp index a0cc8eb3eb..cc183509d9 100644 --- a/test/util/tile_cover.cpp +++ b/test/util/tile_cover.cpp @@ -1,7 +1,6 @@ #include <mbgl/util/tile_cover.hpp> #include <mbgl/util/geo.hpp> #include <mbgl/map/transform.hpp> -#include <mbgl/test/mock_view.hpp> #include <gtest/gtest.h> @@ -29,8 +28,7 @@ TEST(TileCover, WorldZ0) { } TEST(TileCover, Pitch) { - MockView view; - Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default); + Transform transform; transform.resize({ { 512, 512 } }); transform.setZoom(2); transform.setPitch(40.0 * M_PI / 180.0); |