Skip to content

Commit

Permalink
Merge remote-tracking branch 'mapbox/master' into android-annotations m…
Browse files Browse the repository at this point in the history
  • Loading branch information
hallahan committed Jul 17, 2015
2 parents 5e9f3e5 + 7a42e0c commit bcf6ebf
Show file tree
Hide file tree
Showing 50 changed files with 710 additions and 321 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.5.1

### iOS

- Added support for CocoaPods 0.38.0. ([#1876](https://github.com/mapbox/mapbox-gl-native/pull/1876))

## 0.5.0

### Core
Expand Down
29 changes: 16 additions & 13 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ class Map : private util::noncopyable {
void renderStill(StillImageCallback callback);

// Triggers a synchronous or asynchronous render.
void renderSync();
bool renderSync();

// Nudges transitions one step, possibly notifying of the need for a rerender.
void nudgeTransitions(bool forceRerender);

// Notifies the Map thread that the state has changed and an update might be necessary.
void update(Update update = Update::Nothing);
Expand All @@ -79,8 +82,8 @@ class Map : private util::noncopyable {
void setClasses(const std::vector<std::string>&);
std::vector<std::string> getClasses() const;

void setDefaultTransitionDuration(Duration = Duration::zero());
Duration getDefaultTransitionDuration();
void setDefaultTransitionDuration(const Duration& = Duration::zero());
Duration getDefaultTransitionDuration() const;
void setStyleURL(const std::string& url);
void setStyleJSON(const std::string& json, const std::string& base = "");
std::string getStyleURL() const;
Expand All @@ -91,27 +94,27 @@ class Map : private util::noncopyable {
void setGestureInProgress(bool);

// Position
void moveBy(double dx, double dy, Duration = Duration::zero());
void setLatLng(LatLng latLng, Duration = Duration::zero());
void moveBy(double dx, double dy, const Duration& = Duration::zero());
void setLatLng(LatLng latLng, const Duration& = Duration::zero());
LatLng getLatLng() const;
void resetPosition();

// Scale
void scaleBy(double ds, double cx = -1, double cy = -1, Duration = Duration::zero());
void setScale(double scale, double cx = -1, double cy = -1, Duration = Duration::zero());
void scaleBy(double ds, double cx = -1, double cy = -1, const Duration& = Duration::zero());
void setScale(double scale, double cx = -1, double cy = -1, const Duration& = Duration::zero());
double getScale() const;
void setZoom(double zoom, Duration = Duration::zero());
void setZoom(double zoom, const Duration& = Duration::zero());
double getZoom() const;
void setLatLngZoom(LatLng latLng, double zoom, Duration = Duration::zero());
void fitBounds(LatLngBounds bounds, EdgeInsets padding, Duration duration = Duration::zero());
void fitBounds(AnnotationSegment segment, EdgeInsets padding, Duration duration = Duration::zero());
void setLatLngZoom(LatLng latLng, double zoom, const Duration& = Duration::zero());
void fitBounds(LatLngBounds bounds, EdgeInsets padding, const Duration& duration = Duration::zero());
void fitBounds(AnnotationSegment segment, EdgeInsets padding, const Duration& duration = Duration::zero());
void resetZoom();
double getMinZoom() const;
double getMaxZoom() const;

// Rotation
void rotateBy(double sx, double sy, double ex, double ey, Duration = Duration::zero());
void setBearing(double degrees, Duration = Duration::zero());
void rotateBy(double sx, double sy, double ex, double ey, const Duration& = Duration::zero());
void setBearing(double degrees, const Duration& = Duration::zero());
void setBearing(double degrees, double cx, double cy);
double getBearing() const;
void resetNorth();
Expand Down
2 changes: 1 addition & 1 deletion ios/MapboxGL.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |m|

m.name = 'MapboxGL'
m.version = '0.4.5-symbols'
m.version = '0.5.2-symbols'

m.summary = 'Open source vector map solution for iOS with full styling capabilities.'
m.description = 'Open source OpenGL-based vector map solution for iOS with full styling capabilities and Cocoa bindings.'
Expand Down
3 changes: 2 additions & 1 deletion platform/default/default_styles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const std::vector<std::pair<std::string, std::string>> defaultStyles = {
{ "asset://styles/mapbox-streets-v7.json", "Mapbox Streets" },
{ "asset://styles/emerald-v7.json", "Emerald" },
{ "asset://styles/light-v7.json", "Light" },
{ "asset://styles/dark-v7.json", "Dark" }
{ "asset://styles/dark-v7.json", "Dark" },
{ "asset://styles/satellite-v7.json", "Satellite" }
};

} // end namespace util
Expand Down
4 changes: 3 additions & 1 deletion platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,11 @@ - (void)glkView:(__unused GLKView *)view drawInRect:(__unused CGRect)rect

_mbglMap->setSourceTileCacheSize(cacheSize);

_mbglMap->renderSync();
bool needsRerender = _mbglMap->renderSync();

[self updateUserLocationAnnotationView];

_mbglMap->nudgeTransitions(needsRerender);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/mbgl/annotation/sprite_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ std::shared_ptr<const SpriteImage> SpriteStore::getSprite(const std::string& nam
if (it != sprites.end()) {
return it->second;
} else {
Log::Info(Event::Sprite, "Can't find sprite named '%s'", name.c_str());
if (!sprites.empty()) {
Log::Info(Event::Sprite, "Can't find sprite named '%s'", name.c_str());
}
return nullptr;
}
}
Expand Down
32 changes: 18 additions & 14 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void Map::renderStill(StillImageCallback callback) {
FrameData{ view.getFramebufferSize() }, callback);
}

void Map::renderSync() {
bool Map::renderSync() {
if (renderState == RenderState::never) {
view.notifyMapChange(MapChangeWillStartRenderingMap);
}
Expand All @@ -69,9 +69,13 @@ void Map::renderSync() {
view.notifyMapChange(MapChangeDidFinishRenderingMapFullyRendered);
}

return result.needsRerender;
}

void Map::nudgeTransitions(bool forceRerender) {
if (transform->needsTransition()) {
update(Update(transform->updateTransitions(Clock::now())));
} else if (result.needsRerender) {
} else if (forceRerender) {
update();
}
}
Expand Down Expand Up @@ -116,12 +120,12 @@ void Map::setGestureInProgress(bool inProgress) {

#pragma mark - Position

void Map::moveBy(double dx, double dy, Duration duration) {
void Map::moveBy(double dx, double dy, const Duration& duration) {
transform->moveBy(dx, dy, duration);
update();
}

void Map::setLatLng(LatLng latLng, Duration duration) {
void Map::setLatLng(LatLng latLng, const Duration& duration) {
transform->setLatLng(latLng, duration);
update();
}
Expand All @@ -140,12 +144,12 @@ void Map::resetPosition() {

#pragma mark - Scale

void Map::scaleBy(double ds, double cx, double cy, Duration duration) {
void Map::scaleBy(double ds, double cx, double cy, const Duration& duration) {
transform->scaleBy(ds, cx, cy, duration);
update(Update::Zoom);
}

void Map::setScale(double scale, double cx, double cy, Duration duration) {
void Map::setScale(double scale, double cx, double cy, const Duration& duration) {
transform->setScale(scale, cx, cy, duration);
update(Update::Zoom);
}
Expand All @@ -154,7 +158,7 @@ double Map::getScale() const {
return transform->getScale();
}

void Map::setZoom(double zoom, Duration duration) {
void Map::setZoom(double zoom, const Duration& duration) {
transform->setZoom(zoom, duration);
update(Update::Zoom);
}
Expand All @@ -163,12 +167,12 @@ double Map::getZoom() const {
return transform->getZoom();
}

void Map::setLatLngZoom(LatLng latLng, double zoom, Duration duration) {
void Map::setLatLngZoom(LatLng latLng, double zoom, const Duration& duration) {
transform->setLatLngZoom(latLng, zoom, duration);
update(Update::Zoom);
}

void Map::fitBounds(LatLngBounds bounds, EdgeInsets padding, Duration duration) {
void Map::fitBounds(LatLngBounds bounds, EdgeInsets padding, const Duration& duration) {
AnnotationSegment segment = {
{bounds.ne.latitude, bounds.sw.longitude},
bounds.sw,
Expand All @@ -178,7 +182,7 @@ void Map::fitBounds(LatLngBounds bounds, EdgeInsets padding, Duration duration)
fitBounds(segment, padding, duration);
}

void Map::fitBounds(AnnotationSegment segment, EdgeInsets padding, Duration duration) {
void Map::fitBounds(AnnotationSegment segment, EdgeInsets padding, const Duration& duration) {
if (segment.empty()) {
return;
}
Expand Down Expand Up @@ -243,12 +247,12 @@ uint16_t Map::getHeight() const {

#pragma mark - Rotation

void Map::rotateBy(double sx, double sy, double ex, double ey, Duration duration) {
void Map::rotateBy(double sx, double sy, double ex, double ey, const Duration& duration) {
transform->rotateBy(sx, sy, ex, ey, duration);
update();
}

void Map::setBearing(double degrees, Duration duration) {
void Map::setBearing(double degrees, const Duration& duration) {
transform->setAngle(-degrees * M_PI / 180, duration);
update();
}
Expand Down Expand Up @@ -416,12 +420,12 @@ std::vector<std::string> Map::getClasses() const {
return data->getClasses();
}

void Map::setDefaultTransitionDuration(Duration duration) {
void Map::setDefaultTransitionDuration(const Duration& duration) {
data->setDefaultTransitionDuration(duration);
update(Update::DefaultTransitionDuration);
}

Duration Map::getDefaultTransitionDuration() {
Duration Map::getDefaultTransitionDuration() const {
return data->getDefaultTransitionDuration();
}

Expand Down
49 changes: 22 additions & 27 deletions src/mbgl/map/map_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,13 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));

style->setJSON(json, base);
style->cascade(data.getClasses());
style->setDefaultTransitionDuration(data.getDefaultTransitionDuration());
style->setObserver(this);

// force style cascade, causing all pending transitions to complete.
style->cascade();

updated |= static_cast<UpdateType>(Update::DefaultTransitionDuration);
updated |= static_cast<UpdateType>(Update::Classes);
updated |= static_cast<UpdateType>(Update::Zoom);
asyncUpdate->send();

Expand Down Expand Up @@ -240,45 +243,37 @@ void MapContext::updateAnnotationTiles(const std::unordered_set<TileID, TileID::
}
}

cascadeClasses();

updated |= static_cast<UpdateType>(Update::Classes);
asyncUpdate->send();

annotationManager->resetStaleTiles();
}

void MapContext::cascadeClasses() {
style->cascade(data.getClasses());
}

void MapContext::update() {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));

const auto now = Clock::now();
data.setAnimationTime(now);
if (!style) {
updated = static_cast<UpdateType>(Update::Nothing);
return;
}

if (style) {
if (updated & static_cast<UpdateType>(Update::DefaultTransitionDuration)) {
style->setDefaultTransitionDuration(data.getDefaultTransitionDuration());
}
data.setAnimationTime(Clock::now());

if (updated & static_cast<UpdateType>(Update::Classes)) {
cascadeClasses();
}
if (updated & static_cast<UpdateType>(Update::Classes)) {
style->cascade();
}

if (updated & static_cast<UpdateType>(Update::Classes) ||
if (updated & static_cast<UpdateType>(Update::Classes) ||
updated & static_cast<UpdateType>(Update::Zoom)) {
style->recalculate(transformState.getNormalizedZoom(), now);
}
style->recalculate(transformState.getNormalizedZoom());
}

style->update(transformState, *texturePool);
style->update(transformState, *texturePool);

if (data.mode == MapMode::Continuous) {
view.invalidate();
} else if (callback && style->isLoaded()) {
renderSync(transformState, frameData);
}
if (data.mode == MapMode::Continuous) {
view.invalidate();
} else if (callback && style->isLoaded()) {
renderSync(transformState, frameData);
}

updated = static_cast<UpdateType>(Update::Nothing);
Expand Down Expand Up @@ -332,7 +327,7 @@ MapContext::RenderResult MapContext::renderSync(const TransformState& state, con
glObjectStore.performCleanup();

if (!painter) {
painter = std::make_unique<Painter>(data.pixelRatio);
painter = std::make_unique<Painter>(data);
painter->setup();
}

Expand Down
3 changes: 0 additions & 3 deletions src/mbgl/map/map_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ class MapContext : public Style::Observer {
void onResourceLoadingFailed(std::exception_ptr error) override;

private:
// Style-related updates.
void cascadeClasses();

// Update the state indicated by the accumulated Update flags, then render.
void update();

Expand Down
33 changes: 28 additions & 5 deletions src/mbgl/map/map_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ class MapData {
using Lock = std::lock_guard<std::mutex>;

public:
inline MapData(MapMode mode_, const float pixelRatio_) : mode(mode_), pixelRatio(pixelRatio_) {
inline MapData(MapMode mode_, const float pixelRatio_)
: mode(mode_)
, pixelRatio(pixelRatio_)
, animationTime(Duration::zero())
, defaultFadeDuration(std::chrono::milliseconds(300))
, defaultTransitionDuration(Duration::zero())
, defaultTransitionDelay(Duration::zero()) {
assert(pixelRatio > 0);
setAnimationTime(TimePoint::min());
setDefaultTransitionDuration(Duration::zero());
}

// Adds the class if it's not yet set. Returns true when it added the class, and false when it
Expand Down Expand Up @@ -69,17 +73,34 @@ class MapData {
// has a bug that doesn't allow TimePoints to be atomic.
return TimePoint(animationTime);
}
inline void setAnimationTime(TimePoint timePoint) {
inline void setAnimationTime(const TimePoint& timePoint) {
animationTime = timePoint.time_since_epoch();
};

inline Duration getDefaultFadeDuration() const {
return defaultFadeDuration;
}

inline void setDefaultFadeDuration(const Duration& duration) {
defaultFadeDuration = duration;
}

inline Duration getDefaultTransitionDuration() const {
return defaultTransitionDuration;
}
inline void setDefaultTransitionDuration(Duration duration) {

inline void setDefaultTransitionDuration(const Duration& duration) {
defaultTransitionDuration = duration;
}

inline Duration getDefaultTransitionDelay() const {
return defaultTransitionDelay;
}

inline void setDefaultTransitionDelay(const Duration& delay) {
defaultTransitionDelay = delay;
}

util::exclusive<AnnotationManager> getAnnotationManager() {
return util::exclusive<AnnotationManager>(
&annotationManager,
Expand All @@ -100,7 +121,9 @@ class MapData {
std::atomic<uint8_t> debug { false };
std::atomic<uint8_t> collisionDebug { false };
std::atomic<Duration> animationTime;
std::atomic<Duration> defaultFadeDuration;
std::atomic<Duration> defaultTransitionDuration;
std::atomic<Duration> defaultTransitionDelay;

// TODO: make private
public:
Expand Down
Loading

0 comments on commit bcf6ebf

Please sign in to comment.