diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2017-08-22 12:57:11 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2017-08-22 12:57:11 +0300 |
commit | 1c633072fcea7ad153ab6f8ec40dd72d83541ead (patch) | |
tree | fa90c930a58672fa48bf46840f6b88ec645864f0 | |
parent | c53896caefc96a8c18ab746026330ddc4fc0338e (diff) | |
download | qtlocation-mapboxgl-1c633072fcea7ad153ab6f8ec40dd72d83541ead.tar.gz |
Bump Mapbox GL Native
mapbox-gl-native @ bd15e273dce767458d335aeb1f50aa081390d593
36 files changed, 172 insertions, 168 deletions
diff --git a/include/mbgl/actor/scheduler.hpp b/include/mbgl/actor/scheduler.hpp index 83689c3348..d8a26ebeab 100644 --- a/include/mbgl/actor/scheduler.hpp +++ b/include/mbgl/actor/scheduler.hpp @@ -21,18 +21,21 @@ class Mailbox; Subject to these constraints, processing can happen on whatever thread in the pool is available. - * `RunLoop` is a `Scheduler` that is typically used to create a mailbox and - `ActorRef` for an object that lives on the main thread and is not itself wrapped - as an `Actor`: - - auto mailbox = std::make_shared<Mailbox>(*util::RunLoop::Get()); + * `Scheduler::GetCurrent()` is typically used to create a mailbox and `ActorRef` + for an object that lives on the main thread and is not itself wrapped an + `Actor`. The underlying implementation of this Scheduler should usually be + a `RunLoop` + auto mailbox = std::make_shared<Mailbox>(*Scheduler::Get()); Actor<Worker> worker(threadPool, ActorRef<Foo>(*this, mailbox)); */ - class Scheduler { public: virtual ~Scheduler() = default; virtual void schedule(std::weak_ptr<Mailbox>) = 0; + + // Set/Get the current Scheduler for this thread + static Scheduler* GetCurrent(); + static void SetCurrent(Scheduler*); }; } // namespace mbgl diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp index cb84922b4d..d6fdbd8f2c 100644 --- a/include/mbgl/style/style.hpp +++ b/include/mbgl/style/style.hpp @@ -1,6 +1,7 @@ #pragma once #include <mbgl/style/transition_options.hpp> +#include <mbgl/map/camera.hpp> #include <mbgl/util/geo.hpp> #include <string> @@ -32,10 +33,7 @@ public: // Defaults std::string getName() const; - LatLng getDefaultLatLng() const; - double getDefaultZoom() const; - double getDefaultBearing() const; - double getDefaultPitch() const; + CameraOptions getDefaultCamera() const; // TransitionOptions TransitionOptions getTransitionOptions() const; diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp index c2250c6f2e..eb5c201793 100644 --- a/include/mbgl/util/constants.hpp +++ b/include/mbgl/util/constants.hpp @@ -19,7 +19,8 @@ constexpr float tileSize = 512; * * Positions are stored as signed 16bit integers. * One bit is lost for signedness to support features extending past the left edge of the tile. - * One bit is lost because the line vertex buffer packs 1 bit of other data into the int. + * One bit is lost because the line vertex buffer used to pack 1 bit of other data into the int. + * This is no longer the case but we're reserving this bit anyway. * One bit is lost to support features extending past the extent on the right edge of the tile. * This leaves us with 2^13 = 8192 */ @@ -37,6 +38,7 @@ constexpr double MIN_ZOOM = 0.0; constexpr double MAX_ZOOM = 25.5; constexpr float MIN_ZOOM_F = MIN_ZOOM; constexpr float MAX_ZOOM_F = MAX_ZOOM; +constexpr uint8_t DEFAULT_MAX_ZOOM = 22; constexpr uint8_t DEFAULT_PREFETCH_ZOOM_DELTA = 4; diff --git a/include/mbgl/util/run_loop.hpp b/include/mbgl/util/run_loop.hpp index 14352ca823..acbea80273 100644 --- a/include/mbgl/util/run_loop.hpp +++ b/include/mbgl/util/run_loop.hpp @@ -62,6 +62,12 @@ public: push(task); return std::make_unique<WorkRequest>(task); } + + void schedule(std::weak_ptr<Mailbox> mailbox) override { + invoke([mailbox] () { + Mailbox::maybeReceive(mailbox); + }); + } class Impl; @@ -72,12 +78,6 @@ private: void push(std::shared_ptr<WorkTask>); - void schedule(std::weak_ptr<Mailbox> mailbox) override { - invoke([mailbox] () { - Mailbox::maybeReceive(mailbox); - }); - } - void withMutex(std::function<void()>&& fn) { std::lock_guard<std::mutex> lock(mutex); fn(); diff --git a/include/mbgl/util/tileset.hpp b/include/mbgl/util/tileset.hpp index 2fa19d3f53..61aa47d4ea 100644 --- a/include/mbgl/util/tileset.hpp +++ b/include/mbgl/util/tileset.hpp @@ -1,6 +1,7 @@ #pragma once #include <mbgl/util/range.hpp> +#include <mbgl/util/constants.hpp> #include <vector> #include <string> @@ -18,7 +19,7 @@ public: Scheme scheme; Tileset(std::vector<std::string> tiles_ = std::vector<std::string>(), - Range<uint8_t> zoomRange_ = { 0, 22 }, + Range<uint8_t> zoomRange_ = { 0, util::DEFAULT_MAX_ZOOM }, std::string attribution_ = {}, Scheme scheme_ = Scheme::XYZ) : tiles(std::move(tiles_)), diff --git a/mapbox-gl-native.pro b/mapbox-gl-native.pro index 7065849d83..0cf5d8de11 100644 --- a/mapbox-gl-native.pro +++ b/mapbox-gl-native.pro @@ -83,6 +83,7 @@ SOURCES += \ platform/qt/src/utf.cpp \ src/csscolorparser/csscolorparser.cpp \ src/mbgl/actor/mailbox.cpp \ + src/mbgl/actor/scheduler.cpp \ src/mbgl/algorithm/generate_clip_ids.cpp \ src/mbgl/annotation/annotation_manager.cpp \ src/mbgl/annotation/annotation_source.cpp \ diff --git a/platform/default/mbgl/gl/headless_backend.cpp b/platform/default/mbgl/gl/headless_backend.cpp index a854fe9731..fe77b80985 100644 --- a/platform/default/mbgl/gl/headless_backend.cpp +++ b/platform/default/mbgl/gl/headless_backend.cpp @@ -11,9 +11,9 @@ namespace mbgl { class HeadlessBackend::View { public: - View(gl::Context& context, Size size) - : color(context.createRenderbuffer<gl::RenderbufferType::RGBA>(size)), - depthStencil(context.createRenderbuffer<gl::RenderbufferType::DepthStencil>(size)), + View(gl::Context& context, Size size_) + : color(context.createRenderbuffer<gl::RenderbufferType::RGBA>(size_)), + depthStencil(context.createRenderbuffer<gl::RenderbufferType::DepthStencil>(size_)), framebuffer(context.createFramebuffer(color, depthStencil)) { } diff --git a/platform/default/mbgl/storage/offline_database.cpp b/platform/default/mbgl/storage/offline_database.cpp index d38f0c9108..65c2097182 100644 --- a/platform/default/mbgl/storage/offline_database.cpp +++ b/platform/default/mbgl/storage/offline_database.cpp @@ -51,7 +51,7 @@ void OfflineDatabase::ensureSchema() { case 4: migrateToVersion5(); // fall through case 5: migrateToVersion6(); // fall through case 6: return; - default: throw std::runtime_error("unknown schema version"); + default: break; // downgrade, delete the database } removeExisting(); diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp index 08011f5ac1..1c594f87a0 100644 --- a/platform/default/online_file_source.cpp +++ b/platform/default/online_file_source.cpp @@ -383,7 +383,7 @@ ActorRef<OnlineFileRequest> OnlineFileRequest::actor() { if (!mailbox) { // Lazy constructed because this can be costly and // the ResourceTransform is not used by many apps. - mailbox = std::make_shared<Mailbox>(*util::RunLoop::Get()); + mailbox = std::make_shared<Mailbox>(*Scheduler::GetCurrent()); } return ActorRef<OnlineFileRequest>(*this, mailbox); diff --git a/platform/default/run_loop.cpp b/platform/default/run_loop.cpp index 98d1badcb5..6375dba78e 100644 --- a/platform/default/run_loop.cpp +++ b/platform/default/run_loop.cpp @@ -1,6 +1,7 @@ #include <mbgl/util/run_loop.hpp> #include <mbgl/util/async_task.hpp> #include <mbgl/util/thread_local.hpp> +#include <mbgl/actor/scheduler.hpp> #include <uv.h> @@ -10,9 +11,6 @@ namespace { -using namespace mbgl::util; -static ThreadLocal<RunLoop>& current = *new ThreadLocal<RunLoop>; - void dummyCallback(uv_async_t*) {} } // namespace @@ -53,7 +51,8 @@ struct Watch { }; RunLoop* RunLoop::Get() { - return current.get(); + assert(static_cast<RunLoop*>(Scheduler::GetCurrent())); + return static_cast<RunLoop*>(Scheduler::GetCurrent()); } class RunLoop::Impl { @@ -98,12 +97,12 @@ RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) { impl->type = type; - current.set(this); + Scheduler::SetCurrent(this); impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this)); } RunLoop::~RunLoop() { - current.set(nullptr); + Scheduler::SetCurrent(nullptr); // Close the dummy handle that we have // just to keep the main loop alive. @@ -127,7 +126,7 @@ RunLoop::~RunLoop() { } LOOP_HANDLE RunLoop::getLoopHandle() { - return current.get()->impl->loop; + return Get()->impl->loop; } void RunLoop::push(std::shared_ptr<WorkTask> task) { diff --git a/platform/default/thread_local.cpp b/platform/default/thread_local.cpp index 7abbaa0146..db70773c12 100644 --- a/platform/default/thread_local.cpp +++ b/platform/default/thread_local.cpp @@ -58,8 +58,8 @@ void ThreadLocal<T>::set(T* ptr) { } } -template class ThreadLocal<RunLoop>; template class ThreadLocal<BackendScope>; +template class ThreadLocal<Scheduler>; template class ThreadLocal<int>; // For unit tests } // namespace util diff --git a/platform/qt/src/run_loop.cpp b/platform/qt/src/run_loop.cpp index c44f284852..71ea19032a 100644 --- a/platform/qt/src/run_loop.cpp +++ b/platform/qt/src/run_loop.cpp @@ -1,6 +1,6 @@ #include "run_loop_impl.hpp" -#include <mbgl/util/thread_local.hpp> +#include <mbgl/actor/scheduler.hpp> #include <QCoreApplication> @@ -8,13 +8,6 @@ #include <functional> #include <utility> -namespace { - -using namespace mbgl::util; -static ThreadLocal<RunLoop>& current = *new ThreadLocal<RunLoop>; - -} - namespace mbgl { namespace util { @@ -27,7 +20,8 @@ void RunLoop::Impl::onWriteEvent(int fd) { } RunLoop* RunLoop::Get() { - return current.get(); + assert(static_cast<RunLoop*>(Scheduler::GetCurrent())); + return static_cast<RunLoop*>(Scheduler::GetCurrent()); } RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) { @@ -42,14 +36,14 @@ RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) { impl->type = type; - current.set(this); + Scheduler::SetCurrent(this); impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this)); } RunLoop::~RunLoop() { MBGL_VERIFY_THREAD(tid); - current.set(nullptr); + Scheduler::SetCurrent(nullptr); } LOOP_HANDLE RunLoop::getLoopHandle() { diff --git a/platform/qt/src/thread_local.cpp b/platform/qt/src/thread_local.cpp index bf2103c98f..467bfb0d05 100644 --- a/platform/qt/src/thread_local.cpp +++ b/platform/qt/src/thread_local.cpp @@ -1,6 +1,6 @@ #include <mbgl/util/thread_local.hpp> -#include <mbgl/util/run_loop.hpp> +#include <mbgl/actor/scheduler.hpp> #include <mbgl/renderer/backend_scope.hpp> #include <array> @@ -41,7 +41,7 @@ void ThreadLocal<T>::set(T* ptr) { impl->local.localData()[0] = ptr; } -template class ThreadLocal<RunLoop>; +template class ThreadLocal<Scheduler>; template class ThreadLocal<BackendScope>; template class ThreadLocal<int>; // For unit tests diff --git a/src/mbgl/actor/scheduler.cpp b/src/mbgl/actor/scheduler.cpp new file mode 100644 index 0000000000..d7cdb2737b --- /dev/null +++ b/src/mbgl/actor/scheduler.cpp @@ -0,0 +1,19 @@ +#include <mbgl/actor/scheduler.hpp> +#include <mbgl/util/thread_local.hpp> + +namespace mbgl { + +static auto& current() { + static util::ThreadLocal<Scheduler> scheduler; + return scheduler; +}; + +void Scheduler::SetCurrent(Scheduler* scheduler) { + current().set(scheduler); +} + +Scheduler* Scheduler::GetCurrent() { + return current().get(); +} + +} //namespace mbgl diff --git a/src/mbgl/annotation/render_annotation_source.cpp b/src/mbgl/annotation/render_annotation_source.cpp index de38b596d5..c2e6191d1d 100644 --- a/src/mbgl/annotation/render_annotation_source.cpp +++ b/src/mbgl/annotation/render_annotation_source.cpp @@ -38,7 +38,7 @@ void RenderAnnotationSource::update(Immutable<style::Source::Impl> baseImpl_, parameters, SourceType::Annotations, util::tileSize, - { 0, 22 }, + { 0, util::DEFAULT_MAX_ZOOM }, [&] (const OverscaledTileID& tileID) { return std::make_unique<AnnotationTile>(tileID, parameters); }); diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 7d57f6863e..d5a5923e6c 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -727,11 +727,7 @@ void Map::Impl::onStyleLoading() { void Map::Impl::onStyleLoaded() { if (!cameraMutated) { - // Zoom first because it may constrain subsequent operations. - map.setZoom(style->getDefaultZoom()); - map.setLatLng(style->getDefaultLatLng()); - map.setBearing(style->getDefaultBearing()); - map.setPitch(style->getDefaultPitch()); + map.jumpTo(style->getDefaultCamera()); } annotationManager.onStyleLoaded(); diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp index f35f570549..4d6b89573e 100644 --- a/src/mbgl/map/transform_state.hpp +++ b/src/mbgl/map/transform_state.hpp @@ -96,7 +96,7 @@ private: // Limit the amount of zooming possible on the map. double min_scale = std::pow(2, 0); - double max_scale = std::pow(2, 20); + double max_scale = std::pow(2, util::DEFAULT_MAX_ZOOM); double min_pitch = 0.0; double max_pitch = util::PITCH_MAX; diff --git a/src/mbgl/map/zoom_history.hpp b/src/mbgl/map/zoom_history.hpp index 697e28573c..ddec53e6af 100644 --- a/src/mbgl/map/zoom_history.hpp +++ b/src/mbgl/map/zoom_history.hpp @@ -8,34 +8,39 @@ namespace mbgl { struct ZoomHistory { float lastZoom; + float lastFloorZoom; float lastIntegerZoom; TimePoint lastIntegerZoomTime; bool first = true; bool update(float z, const TimePoint& now) { constexpr TimePoint zero = TimePoint(Duration::zero()); + const float floorZ = std::floor(z); + if (first) { first = false; - lastIntegerZoom = std::floor(z); + lastIntegerZoom = floorZ; lastIntegerZoomTime = zero; lastZoom = z; + lastFloorZoom = floorZ; + return true; + } + + if (lastFloorZoom > floorZ) { + lastIntegerZoom = floorZ + 1; + lastIntegerZoomTime = now == Clock::time_point::max() ? zero : now; + } else if (lastFloorZoom < floorZ || lastIntegerZoom != floorZ) { + lastIntegerZoom = floorZ; + lastIntegerZoomTime = now == Clock::time_point::max() ? zero : now; + } + + if (z != lastZoom) { + lastZoom = z; + lastFloorZoom = floorZ; return true; - } else { - if (std::floor(lastZoom) < std::floor(z)) { - lastIntegerZoom = std::floor(z); - lastIntegerZoomTime = now == Clock::time_point::max() ? zero : now; - } else if (std::floor(lastZoom) > std::floor(z)) { - lastIntegerZoom = std::floor(z + 1); - lastIntegerZoomTime = now == Clock::time_point::max() ? zero : now; - } - - if (z != lastZoom) { - lastZoom = z; - return true; - } - - return false; } + + return false; } }; diff --git a/src/mbgl/programs/attributes.hpp b/src/mbgl/programs/attributes.hpp index 684d9d6099..3a38453d30 100644 --- a/src/mbgl/programs/attributes.hpp +++ b/src/mbgl/programs/attributes.hpp @@ -23,6 +23,7 @@ inline uint16_t packUint8Pair(T a, T b) { MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_pos); MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_extrude); MBGL_DEFINE_ATTRIBUTE(int16_t, 4, a_pos_offset); +MBGL_DEFINE_ATTRIBUTE(int16_t, 3, a_pos_normal); MBGL_DEFINE_ATTRIBUTE(float, 3, a_projected_pos); MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_label_pos); MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_anchor_pos); diff --git a/src/mbgl/programs/line_program.cpp b/src/mbgl/programs/line_program.cpp index db5c916d32..f9e91f569f 100644 --- a/src/mbgl/programs/line_program.cpp +++ b/src/mbgl/programs/line_program.cpp @@ -10,7 +10,7 @@ namespace mbgl { using namespace style; -static_assert(sizeof(LineLayoutVertex) == 8, "expected LineLayoutVertex size"); +static_assert(sizeof(LineLayoutVertex) == 10, "expected LineLayoutVertex size"); template <class Values, class...Args> Values makeValues(const RenderLinePaintProperties::PossiblyEvaluated& properties, diff --git a/src/mbgl/programs/line_program.hpp b/src/mbgl/programs/line_program.hpp index ed4a09bf10..95b9362b85 100644 --- a/src/mbgl/programs/line_program.hpp +++ b/src/mbgl/programs/line_program.hpp @@ -30,7 +30,7 @@ MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_gl_units_to_pixels); } // namespace uniforms struct LineLayoutAttributes : gl::Attributes< - attributes::a_pos, + attributes::a_pos_normal, attributes::a_data<uint8_t, 4>> {}; @@ -50,14 +50,16 @@ public: /* * @param p vertex position * @param e extrude normal - * @param t texture normal + * @param round whether the vertex uses a round line cap + * @param up whether the line normal points up or down * @param dir direction of the line cap (-1/0/1) */ - static LayoutVertex layoutVertex(Point<int16_t> p, Point<double> e, Point<bool> t, int8_t dir, int32_t linesofar = 0) { + static LayoutVertex layoutVertex(Point<int16_t> p, Point<double> e, bool round, bool up, int8_t dir, int32_t linesofar = 0) { return LayoutVertex { {{ - static_cast<int16_t>((p.x * 2) | t.x), - static_cast<int16_t>((p.y * 2) | t.y) + p.x, + p.y, + static_cast<int16_t>(attributes::packUint8Pair(round ? 1 : 0, up ? 1 : 0)) }}, {{ // add 128 to store a byte in an unsigned byte diff --git a/src/mbgl/renderer/buckets/line_bucket.cpp b/src/mbgl/renderer/buckets/line_bucket.cpp index 194b012eee..a96518df38 100644 --- a/src/mbgl/renderer/buckets/line_bucket.cpp +++ b/src/mbgl/renderer/buckets/line_bucket.cpp @@ -401,7 +401,7 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate, Point<double> extrude = normal; if (endLeft) extrude = extrude - (util::perp(normal) * endLeft); - vertices.emplace_back(LineProgram::layoutVertex(currentCoordinate, extrude, { round, false }, endLeft, distance * LINE_DISTANCE_SCALE)); + vertices.emplace_back(LineProgram::layoutVertex(currentCoordinate, extrude, round, false, endLeft, distance * LINE_DISTANCE_SCALE)); e3 = vertices.vertexSize() - 1 - startVertex; if (e1 >= 0 && e2 >= 0) { triangleStore.emplace_back(e1, e2, e3); @@ -412,7 +412,7 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate, extrude = normal * -1.0; if (endRight) extrude = extrude - (util::perp(normal) * endRight); - vertices.emplace_back(LineProgram::layoutVertex(currentCoordinate, extrude, { round, true }, -endRight, distance * LINE_DISTANCE_SCALE)); + vertices.emplace_back(LineProgram::layoutVertex(currentCoordinate, extrude, round, true, -endRight, distance * LINE_DISTANCE_SCALE)); e3 = vertices.vertexSize() - 1 - startVertex; if (e1 >= 0 && e2 >= 0) { triangleStore.emplace_back(e1, e2, e3); @@ -437,7 +437,7 @@ void LineBucket::addPieSliceVertex(const GeometryCoordinate& currentVertex, std::size_t startVertex, std::vector<TriangleElement>& triangleStore) { Point<double> flippedExtrude = extrude * (lineTurnsLeft ? -1.0 : 1.0); - vertices.emplace_back(LineProgram::layoutVertex(currentVertex, flippedExtrude, { false, lineTurnsLeft }, 0, distance * LINE_DISTANCE_SCALE)); + vertices.emplace_back(LineProgram::layoutVertex(currentVertex, flippedExtrude, false, lineTurnsLeft, 0, distance * LINE_DISTANCE_SCALE)); e3 = vertices.vertexSize() - 1 - startVertex; if (e1 >= 0 && e2 >= 0) { triangleStore.emplace_back(e1, e2, e3); diff --git a/src/mbgl/shaders/line.cpp b/src/mbgl/shaders/line.cpp index 26dda5e73c..f68cc91377 100644 --- a/src/mbgl/shaders/line.cpp +++ b/src/mbgl/shaders/line.cpp @@ -21,7 +21,7 @@ const char* line::vertexSource = R"MBGL_SHADER( // #define scale 63.0 #define scale 0.015873016 -attribute vec2 a_pos; +attribute vec3 a_pos_normal; attribute vec4 a_data; uniform mat4 u_matrix; @@ -131,20 +131,21 @@ void main() { vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; - // We store the texture normals in the most insignificant bit - // transform y so that 0 => -1 and 1 => 1 + vec2 pos = a_pos_normal.xy; + + // transform y normal so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down - mediump vec2 normal = mod(a_pos, 2.0); + mediump vec2 normal = unpack_float(a_pos_normal.z); normal.y = sign(normal.y - 0.5); - v_normal = normal; + v_normal = normal; - // these transformations used to be applied in the JS and native code bases. - // moved them into the shader for clarity and simplicity. + // these transformations used to be applied in the JS and native code bases. + // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; float halfwidth = width / 2.0; - offset = -1.0 * offset; + offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; @@ -161,9 +162,6 @@ void main() { mediump float t = 1.0 - abs(u); mediump vec2 offset2 = offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); - // Remove the texture normal bit to get the position - vec2 pos = floor(a_pos * 0.5); - vec4 projected_extrude = u_matrix * vec4(dist / u_ratio, 0.0, 0.0); gl_Position = u_matrix * vec4(pos + offset2 / u_ratio, 0.0, 1.0) + projected_extrude; diff --git a/src/mbgl/shaders/line_pattern.cpp b/src/mbgl/shaders/line_pattern.cpp index 9eee9192d4..f1e64577e2 100644 --- a/src/mbgl/shaders/line_pattern.cpp +++ b/src/mbgl/shaders/line_pattern.cpp @@ -23,7 +23,7 @@ const char* line_pattern::vertexSource = R"MBGL_SHADER( // Retina devices need a smaller distance to avoid aliasing. #define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0 -attribute vec2 a_pos; +attribute vec3 a_pos_normal; attribute vec4 a_data; uniform mat4 u_matrix; @@ -119,19 +119,21 @@ void main() { float a_direction = mod(a_data.z, 4.0) - 1.0; float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; - // We store the texture normals in the most insignificant bit - // transform y so that 0 => -1 and 1 => 1 + vec2 pos = a_pos_normal.xy; + + // transform y normal so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down - mediump vec2 normal = mod(a_pos, 2.0); + mediump vec2 normal = unpack_float(a_pos_normal.z); normal.y = sign(normal.y - 0.5); + v_normal = normal; - // these transformations used to be applied in the JS and native code bases. - // moved them into the shader for clarity and simplicity. + // these transformations used to be applied in the JS and native code bases. + // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; float halfwidth = width / 2.0; - offset = -1.0 * offset; + offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; @@ -148,9 +150,6 @@ void main() { mediump float t = 1.0 - abs(u); mediump vec2 offset2 = offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); - // Remove the texture normal bit to get the position - vec2 pos = floor(a_pos * 0.5); - vec4 projected_extrude = u_matrix * vec4(dist / u_ratio, 0.0, 0.0); gl_Position = u_matrix * vec4(pos + offset2 / u_ratio, 0.0, 1.0) + projected_extrude; diff --git a/src/mbgl/shaders/line_sdf.cpp b/src/mbgl/shaders/line_sdf.cpp index e1aadffcf4..dd81433543 100644 --- a/src/mbgl/shaders/line_sdf.cpp +++ b/src/mbgl/shaders/line_sdf.cpp @@ -23,7 +23,7 @@ const char* line_sdf::vertexSource = R"MBGL_SHADER( // Retina devices need a smaller distance to avoid aliasing. #define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0 -attribute vec2 a_pos; +attribute vec3 a_pos_normal; attribute vec4 a_data; uniform mat4 u_matrix; @@ -157,20 +157,22 @@ void main() { float a_direction = mod(a_data.z, 4.0) - 1.0; float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; - // We store the texture normals in the most insignificant bit - // transform y so that 0 => -1 and 1 => 1 + vec2 pos = a_pos_normal.xy; + + // transform y normal so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down - mediump vec2 normal = mod(a_pos, 2.0); + mediump vec2 normal = unpack_float(a_pos_normal.z); normal.y = sign(normal.y - 0.5); + v_normal = normal; - // these transformations used to be applied in the JS and native code bases. - // moved them into the shader for clarity and simplicity. + // these transformations used to be applied in the JS and native code bases. + // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; float halfwidth = width / 2.0; offset = -1.0 * offset; - + float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; @@ -186,9 +188,6 @@ void main() { mediump float t = 1.0 - abs(u); mediump vec2 offset2 = offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); - // Remove the texture normal bit to get the position - vec2 pos = floor(a_pos * 0.5); - vec4 projected_extrude = u_matrix * vec4(dist / u_ratio, 0.0, 0.0); gl_Position = u_matrix * vec4(pos + offset2 / u_ratio, 0.0, 1.0) + projected_extrude; diff --git a/src/mbgl/sprite/sprite_loader.cpp b/src/mbgl/sprite/sprite_loader.cpp index 60ece5ed73..93d6dfd9ae 100644 --- a/src/mbgl/sprite/sprite_loader.cpp +++ b/src/mbgl/sprite/sprite_loader.cpp @@ -10,8 +10,8 @@ #include <mbgl/storage/file_source.hpp> #include <mbgl/storage/resource.hpp> #include <mbgl/storage/response.hpp> -#include <mbgl/util/run_loop.hpp> #include <mbgl/actor/actor.hpp> +#include <mbgl/actor/scheduler.hpp> #include <cassert> @@ -21,7 +21,7 @@ static SpriteLoaderObserver nullObserver; struct SpriteLoader::Loader { Loader(Scheduler& scheduler, SpriteLoader& imageManager) - : mailbox(std::make_shared<Mailbox>(*util::RunLoop::Get())), + : mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())), worker(scheduler, ActorRef<SpriteLoader>(imageManager, mailbox)) { } diff --git a/src/mbgl/storage/file_source_request.cpp b/src/mbgl/storage/file_source_request.cpp index 8a6fb21181..09ea8cc32a 100644 --- a/src/mbgl/storage/file_source_request.cpp +++ b/src/mbgl/storage/file_source_request.cpp @@ -1,13 +1,13 @@ #include <mbgl/storage/file_source_request.hpp> #include <mbgl/actor/mailbox.hpp> -#include <mbgl/util/run_loop.hpp> +#include <mbgl/actor/scheduler.hpp> namespace mbgl { FileSourceRequest::FileSourceRequest(FileSource::Callback&& callback) : responseCallback(callback) - , mailbox(std::make_shared<Mailbox>(*util::RunLoop::Get())) { + , mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())) { } FileSourceRequest::~FileSourceRequest() { diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 5fe1ab4a06..bd8631fc52 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -34,20 +34,8 @@ std::string Style::getName() const { return impl->getName(); } -LatLng Style::getDefaultLatLng() const { - return impl->getDefaultLatLng(); -} - -double Style::getDefaultZoom() const { - return impl->getDefaultZoom(); -} - -double Style::getDefaultBearing() const { - return impl->getDefaultBearing(); -} - -double Style::getDefaultPitch() const { - return impl->getDefaultPitch(); +CameraOptions Style::getDefaultCamera() const { + return impl->getDefaultCamera(); } TransitionOptions Style::getTransitionOptions() const { diff --git a/src/mbgl/style/style_impl.cpp b/src/mbgl/style/style_impl.cpp index 604af4be20..0fb49d1d22 100644 --- a/src/mbgl/style/style_impl.cpp +++ b/src/mbgl/style/style_impl.cpp @@ -107,10 +107,11 @@ void Style::Impl::parse(const std::string& json_) { } name = parser.name; - defaultLatLng = parser.latLng; - defaultZoom = parser.zoom; - defaultBearing = parser.bearing; - defaultPitch = parser.pitch; + defaultCamera.center = parser.latLng; + defaultCamera.zoom = parser.zoom; + defaultCamera.angle = parser.bearing; + defaultCamera.pitch = parser.pitch; + setLight(std::make_unique<Light>(parser.light)); spriteLoaded = false; @@ -232,20 +233,8 @@ std::string Style::Impl::getName() const { return name; } -LatLng Style::Impl::getDefaultLatLng() const { - return defaultLatLng; -} - -double Style::Impl::getDefaultZoom() const { - return defaultZoom; -} - -double Style::Impl::getDefaultBearing() const { - return defaultBearing; -} - -double Style::Impl::getDefaultPitch() const { - return defaultPitch; +CameraOptions Style::Impl::getDefaultCamera() const { + return defaultCamera; } std::vector<Source*> Style::Impl::getSources() { diff --git a/src/mbgl/style/style_impl.hpp b/src/mbgl/style/style_impl.hpp index 76f244d5a4..3dc222bfad 100644 --- a/src/mbgl/style/style_impl.hpp +++ b/src/mbgl/style/style_impl.hpp @@ -12,6 +12,8 @@ #include <mbgl/style/layer.hpp> #include <mbgl/style/collection.hpp> +#include <mbgl/map/camera.hpp> + #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/optional.hpp> #include <mbgl/util/geo.hpp> @@ -69,10 +71,7 @@ public: std::unique_ptr<Layer> removeLayer(const std::string& layerID); std::string getName() const; - LatLng getDefaultLatLng() const; - double getDefaultZoom() const; - double getDefaultBearing() const; - double getDefaultPitch() const; + CameraOptions getDefaultCamera() const; TransitionOptions getTransitionOptions() const; void setTransitionOptions(const TransitionOptions&); @@ -117,10 +116,7 @@ private: // Defaults std::string name; - LatLng defaultLatLng; - double defaultZoom = 0; - double defaultBearing = 0; - double defaultPitch = 0; + CameraOptions defaultCamera; // SpriteLoaderObserver implementation. void onSpriteLoaded(std::vector<std::unique_ptr<Image>>&&) override; diff --git a/src/mbgl/text/glyph.hpp b/src/mbgl/text/glyph.hpp index 19ecdfd17c..6cccb72ebe 100644 --- a/src/mbgl/text/glyph.hpp +++ b/src/mbgl/text/glyph.hpp @@ -58,13 +58,13 @@ using GlyphMap = std::map<FontStack, Glyphs>; class PositionedGlyph { public: - explicit PositionedGlyph(GlyphID glyph_, float x_, float y_, float angle_) - : glyph(glyph_), x(x_), y(y_), angle(angle_) {} + explicit PositionedGlyph(GlyphID glyph_, float x_, float y_, bool vertical_) + : glyph(glyph_), x(x_), y(y_), vertical(vertical_) {} GlyphID glyph = 0; float x = 0; float y = 0; - float angle = 0; + bool vertical = false; }; enum class WritingModeType : uint8_t; diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp index 7908ea4abc..0014ae8d01 100644 --- a/src/mbgl/text/quads.cpp +++ b/src/mbgl/text/quads.cpp @@ -133,18 +133,27 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText, const float x2 = x1 + rect.w; const float y2 = y1 + rect.h; - const Point<float> center{builtInOffset.x - halfAdvance, static_cast<float>(static_cast<float>(glyph.metrics.advance) / 2.0)}; - Point<float> tl{x1, y1}; Point<float> tr{x2, y1}; Point<float> bl{x1, y2}; Point<float> br{x2, y2}; - if (positionedGlyph.angle != 0) { - tl = util::rotate(tl - center, positionedGlyph.angle) + center; - tr = util::rotate(tr - center, positionedGlyph.angle) + center; - bl = util::rotate(bl - center, positionedGlyph.angle) + center; - br = util::rotate(br - center, positionedGlyph.angle) + center; + if (alongLine && positionedGlyph.vertical) { + // Vertical-supporting glyphs are laid out in 24x24 point boxes (1 square em) + // In horizontal orientation, the y values for glyphs are below the midline + // and we use a "yOffset" of -17 to pull them up to the middle. + // By rotating counter-clockwise around the point at the center of the left + // edge of a 24x24 layout box centered below the midline, we align the center + // of the glyphs with the horizontal midline, so the yOffset is no longer + // necessary, but we also pull the glyph to the left along the x axis + const Point<float> center{-halfAdvance, halfAdvance}; + const float verticalRotation = -M_PI_2; + const Point<float> xOffsetCorrection{5, 0}; + + tl = util::rotate(tl - center, verticalRotation) + center + xOffsetCorrection; + tr = util::rotate(tr - center, verticalRotation) + center + xOffsetCorrection; + bl = util::rotate(bl - center, verticalRotation) + center + xOffsetCorrection; + br = util::rotate(br - center, verticalRotation) + center + xOffsetCorrection; } if (textRotate) { diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp index 4a206e9bae..a40ef0cf39 100644 --- a/src/mbgl/text/shaping.cpp +++ b/src/mbgl/text/shaping.cpp @@ -237,10 +237,10 @@ void shapeLines(Shaping& shaping, const Glyph& glyph = **it->second; if (writingMode == WritingModeType::Horizontal || !util::i18n::hasUprightVerticalOrientation(chr)) { - shaping.positionedGlyphs.emplace_back(chr, x, y, 0); + shaping.positionedGlyphs.emplace_back(chr, x, y, false); x += glyph.metrics.advance + spacing; } else { - shaping.positionedGlyphs.emplace_back(chr, x, 0, -M_PI_2); + shaping.positionedGlyphs.emplace_back(chr, x, 0, true); x += verticalHeight + spacing; } } diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index 33911df9ed..20056e355d 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -17,10 +17,10 @@ #include <mbgl/geometry/feature_index.hpp> #include <mbgl/text/collision_tile.hpp> #include <mbgl/map/transform_state.hpp> -#include <mbgl/util/run_loop.hpp> #include <mbgl/style/filter_evaluator.hpp> #include <mbgl/util/chrono.hpp> #include <mbgl/util/logging.hpp> +#include <mbgl/actor/scheduler.hpp> #include <iostream> @@ -33,7 +33,7 @@ GeometryTile::GeometryTile(const OverscaledTileID& id_, const TileParameters& parameters) : Tile(id_), sourceID(std::move(sourceID_)), - mailbox(std::make_shared<Mailbox>(*util::RunLoop::Get())), + mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())), worker(parameters.workerScheduler, ActorRef<GeometryTile>(*this, mailbox), id_, diff --git a/src/mbgl/tile/geometry_tile_worker.cpp b/src/mbgl/tile/geometry_tile_worker.cpp index c622d82e31..add1ea343c 100644 --- a/src/mbgl/tile/geometry_tile_worker.cpp +++ b/src/mbgl/tile/geometry_tile_worker.cpp @@ -218,7 +218,12 @@ void GeometryTileWorker::onGlyphsAvailable(GlyphMap newGlyphMap) { void GeometryTileWorker::onImagesAvailable(ImageMap newImageMap) { imageMap = std::move(newImageMap); - pendingImageDependencies.clear(); + for (const auto& pair : imageMap) { + auto it = pendingImageDependencies.find(pair.first); + if (it != pendingImageDependencies.end()) { + pendingImageDependencies.erase(it); + } + } symbolDependenciesChanged(); } diff --git a/src/mbgl/tile/raster_tile.cpp b/src/mbgl/tile/raster_tile.cpp index 1260fd1edd..b940e342d7 100644 --- a/src/mbgl/tile/raster_tile.cpp +++ b/src/mbgl/tile/raster_tile.cpp @@ -8,7 +8,7 @@ #include <mbgl/storage/file_source.hpp> #include <mbgl/renderer/tile_parameters.hpp> #include <mbgl/renderer/buckets/raster_bucket.hpp> -#include <mbgl/util/run_loop.hpp> +#include <mbgl/actor/scheduler.hpp> namespace mbgl { @@ -17,7 +17,7 @@ RasterTile::RasterTile(const OverscaledTileID& id_, const Tileset& tileset) : Tile(id_), loader(*this, id_, parameters, tileset), - mailbox(std::make_shared<Mailbox>(*util::RunLoop::Get())), + mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())), worker(parameters.workerScheduler, ActorRef<RasterTile>(*this, mailbox)) { } |