Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] Implement "smart setStyle" #9256

Merged
merged 4 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/mbgl/util/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ constexpr float MAX_ZOOM_F = MAX_ZOOM;

constexpr uint64_t DEFAULT_MAX_CACHE_SIZE = 50 * 1024 * 1024;

constexpr Duration DEFAULT_FADE_DURATION = Milliseconds(300);
constexpr Duration DEFAULT_TRANSITION_DURATION = Milliseconds(300);
constexpr Seconds CLOCK_SKEW_RETRY_TIMEOUT { 30 };

constexpr UnitBezier DEFAULT_TRANSITION_EASE = { 0, 0, 0.25, 1 };
Expand Down
149 changes: 38 additions & 111 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ Map::Impl::Impl(Map& map_,
renderStill();
}
}) {
style = std::make_unique<Style>(scheduler, fileSource, pixelRatio);
style->setObserver(this);
}

Map::~Map() {
Expand All @@ -175,7 +177,6 @@ Map::~Map() {
// Explicit resets currently necessary because these abandon resources that need to be
// cleaned up by context.reset();
impl->renderStyle.reset();
impl->style.reset();
impl->painter.reset();
}

Expand All @@ -195,11 +196,6 @@ void Map::renderStill(View& view, StillImageCallback callback) {
return;
}

if (!impl->style) {
callback(std::make_exception_ptr(util::MisuseException("Map doesn't have a style")));
return;
}

if (impl->style->getLastError()) {
callback(impl->style->getLastError());
return;
Expand Down Expand Up @@ -228,10 +224,6 @@ void Map::render(View& view) {
}

void Map::Impl::render(View& view) {
if (!style) {
return;
}

TimePoint timePoint = Clock::now();

transform.updateTransitions(timePoint);
Expand All @@ -244,6 +236,15 @@ void Map::Impl::render(View& view) {
annotationManager.updateData();
}

updateFlags = Update::Nothing;

gl::Context& context = backend.getContext();
if (!painter) {
renderStyle = std::make_unique<RenderStyle>(scheduler, fileSource);
renderStyle->setObserver(this);
painter = std::make_unique<Painter>(context, transform.getState(), pixelRatio, programCacheDir);
}

renderStyle->update({
mode,
pixelRatio,
Expand All @@ -262,13 +263,6 @@ void Map::Impl::render(View& view) {
annotationManager
});

updateFlags = Update::Nothing;

gl::Context& context = backend.getContext();
if (!painter) {
painter = std::make_unique<Painter>(context, transform.getState(), pixelRatio, programCacheDir);
}

bool loaded = style->isLoaded() && renderStyle->isLoaded();

if (mode == MapMode::Continuous) {
Expand Down Expand Up @@ -346,10 +340,9 @@ void Map::setStyleURL(const std::string& url) {
impl->styleRequest = nullptr;
impl->styleURL = url;
impl->styleJSON.clear();
impl->styleMutated = false;

impl->style = std::make_unique<Style>(impl->scheduler, impl->fileSource, impl->pixelRatio);
impl->renderStyle = std::make_unique<RenderStyle>(impl->scheduler, impl->fileSource);
impl->style->loaded = false;
impl->styleMutated = false;

impl->styleRequest = impl->fileSource.request(Resource::style(impl->styleURL), [this](Response res) {
// Once we get a fresh style, or the style is mutated, stop revalidating.
Expand Down Expand Up @@ -395,16 +388,10 @@ void Map::setStyleJSON(const std::string& json) {
impl->styleJSON.clear();
impl->styleMutated = false;

impl->style = std::make_unique<Style>(impl->scheduler, impl->fileSource, impl->pixelRatio);
impl->renderStyle = std::make_unique<RenderStyle>(impl->scheduler, impl->fileSource);

impl->loadStyleJSON(json);
}

void Map::Impl::loadStyleJSON(const std::string& json) {
style->setObserver(this);
renderStyle->setObserver(this);

style->setJSON(json);
styleJSON = json;

Expand Down Expand Up @@ -834,7 +821,7 @@ void Map::removeAnnotation(AnnotationID annotation) {
#pragma mark - Feature query api

std::vector<Feature> Map::queryRenderedFeatures(const ScreenCoordinate& point, const RenderedQueryOptions& options) {
if (!impl->style) return {};
if (!impl->renderStyle) return {};

return impl->renderStyle->queryRenderedFeatures(
{ point },
Expand All @@ -844,7 +831,7 @@ std::vector<Feature> Map::queryRenderedFeatures(const ScreenCoordinate& point, c
}

std::vector<Feature> Map::queryRenderedFeatures(const ScreenBox& box, const RenderedQueryOptions& options) {
if (!impl->style) return {};
if (!impl->renderStyle) return {};

return impl->renderStyle->queryRenderedFeatures(
{
Expand All @@ -860,7 +847,7 @@ std::vector<Feature> Map::queryRenderedFeatures(const ScreenBox& box, const Rend
}

std::vector<Feature> Map::querySourceFeatures(const std::string& sourceID, const SourceQueryOptions& options) {
if (!impl->style) return {};
if (!impl->renderStyle) return {};

const RenderSource* source = impl->renderStyle->getRenderSource(sourceID);
if (!source) return {};
Expand Down Expand Up @@ -888,49 +875,34 @@ AnnotationIDs Map::queryPointAnnotations(const ScreenBox& box) {
#pragma mark - Style API

std::vector<style::Source*> Map::getSources() {
return impl->style ? impl->style->getSources() : std::vector<style::Source*>();
return impl->style->getSources();
}

style::Source* Map::getSource(const std::string& sourceID) {
if (impl->style) {
impl->styleMutated = true;
return impl->style->getSource(sourceID);
}
return nullptr;
impl->styleMutated = true;
return impl->style->getSource(sourceID);
}

void Map::addSource(std::unique_ptr<style::Source> source) {
if (impl->style) {
impl->styleMutated = true;
impl->style->addSource(std::move(source));
}
impl->styleMutated = true;
impl->style->addSource(std::move(source));
}

std::unique_ptr<Source> Map::removeSource(const std::string& sourceID) {
if (impl->style) {
impl->styleMutated = true;
return impl->style->removeSource(sourceID);
}
return nullptr;
impl->styleMutated = true;
return impl->style->removeSource(sourceID);
}

std::vector<style::Layer*> Map::getLayers() {
return impl->style ? impl->style->getLayers() : std::vector<style::Layer*>();
return impl->style->getLayers();
}

Layer* Map::getLayer(const std::string& layerID) {
if (impl->style) {
impl->styleMutated = true;
return impl->style->getLayer(layerID);
}
return nullptr;
impl->styleMutated = true;
return impl->style->getLayer(layerID);
}

void Map::addLayer(std::unique_ptr<Layer> layer, const optional<std::string>& before) {
if (!impl->style) {
return;
}

impl->styleMutated = true;
BackendScope guard(impl->backend);

Expand All @@ -939,10 +911,6 @@ void Map::addLayer(std::unique_ptr<Layer> layer, const optional<std::string>& be
}

std::unique_ptr<Layer> Map::removeLayer(const std::string& id) {
if (!impl->style) {
return nullptr;
}

impl->styleMutated = true;
BackendScope guard(impl->backend);

Expand All @@ -953,81 +921,47 @@ std::unique_ptr<Layer> Map::removeLayer(const std::string& id) {
}

void Map::addImage(std::unique_ptr<style::Image> image) {
if (!impl->style) {
return;
}

impl->styleMutated = true;
impl->style->addImage(std::move(image));
}

void Map::removeImage(const std::string& id) {
if (!impl->style) {
return;
}

impl->styleMutated = true;
impl->style->removeImage(id);
}

const style::Image* Map::getImage(const std::string& id) {
if (impl->style) {
return impl->style->getImage(id);
}
return nullptr;
return impl->style->getImage(id);
}

void Map::setLight(std::unique_ptr<style::Light> light) {
if (!impl->style) {
return;
}

impl->style->setLight(std::move(light));
}

style::Light* Map::getLight() {
if (!impl->style) {
return nullptr;
}

return impl->style->getLight();
}

#pragma mark - Defaults

std::string Map::getStyleName() const {
if (impl->style) {
return impl->style->getName();
}
return {};
return impl->style->getName();
}

LatLng Map::getDefaultLatLng() const {
if (impl->style) {
return impl->style->getDefaultLatLng();
}
return {};
return impl->style->getDefaultLatLng();
}

double Map::getDefaultZoom() const {
if (impl->style) {
return impl->style->getDefaultZoom();
}
return {};
return impl->style->getDefaultZoom();
}

double Map::getDefaultBearing() const {
if (impl->style) {
return impl->style->getDefaultBearing();
}
return {};
return impl->style->getDefaultBearing();
}

double Map::getDefaultPitch() const {
if (impl->style) {
return impl->style->getDefaultPitch();
}
return {};
return impl->style->getDefaultPitch();
}

#pragma mark - Toggles
Expand Down Expand Up @@ -1066,26 +1000,21 @@ MapDebugOptions Map::getDebug() const {
}

bool Map::isFullyLoaded() const {
return impl->style && impl->style->isLoaded() && impl->renderStyle->isLoaded();
return impl->style && impl->style->isLoaded() && impl->renderStyle && impl->renderStyle->isLoaded();
}

style::TransitionOptions Map::getTransitionOptions() const {
if (impl->style) {
return impl->style->getTransitionOptions();
}
return {};
return impl->style->getTransitionOptions();
}

void Map::setTransitionOptions(const style::TransitionOptions& options) {
if (impl->style) {
impl->style->setTransitionOptions(options);
}
impl->style->setTransitionOptions(options);
}

void Map::setSourceTileCacheSize(size_t size) {
if (size != impl->sourceCacheSize) {
impl->sourceCacheSize = size;
if (!impl->style) return;
if (!impl->renderStyle) return;
impl->renderStyle->setSourceTileCacheSize(size);
impl->backend.invalidate();
}
Expand Down Expand Up @@ -1133,11 +1062,9 @@ void Map::Impl::onResourceError(std::exception_ptr error) {
void Map::dumpDebugLogs() const {
Log::Info(Event::General, "--------------------------------------------------------------------------------");
Log::Info(Event::General, "MapContext::styleURL: %s", impl->styleURL.c_str());
if (impl->style) {
impl->style->dumpDebugLogs();
impl->style->dumpDebugLogs();
if (impl->renderStyle) {
impl->renderStyle->dumpDebugLogs();
} else {
Log::Info(Event::General, "no style loaded");
}
Log::Info(Event::General, "--------------------------------------------------------------------------------");
}
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/renderer/painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Painter::Painter(gl::Context& context_,
Painter::~Painter() = default;

bool Painter::needsAnimation() const {
return frameHistory.needsAnimation(util::DEFAULT_FADE_DURATION);
return frameHistory.needsAnimation(util::DEFAULT_TRANSITION_DURATION);
}

void Painter::cleanup() {
Expand Down Expand Up @@ -159,7 +159,7 @@ void Painter::render(RenderStyle& style, const FrameData& frame_, View& view) {
}

frameHistory.record(frame.timePoint, state.getZoom(),
frame.mapMode == MapMode::Continuous ? util::DEFAULT_FADE_DURATION : Milliseconds(0));
frame.mapMode == MapMode::Continuous ? util::DEFAULT_TRANSITION_DURATION : Milliseconds(0));


// - UPLOAD PASS -------------------------------------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions src/mbgl/renderer/render_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void RenderStyle::update(const UpdateParameters& parameters) {
const PropertyEvaluationParameters evaluationParameters {
zoomHistory,
parameters.mode == MapMode::Continuous ? parameters.timePoint : Clock::time_point::max(),
parameters.mode == MapMode::Continuous ? util::DEFAULT_FADE_DURATION : Duration::zero()
parameters.mode == MapMode::Continuous ? util::DEFAULT_TRANSITION_DURATION : Duration::zero()
};

const TileParameters tileParameters {
Expand Down Expand Up @@ -203,14 +203,15 @@ void RenderStyle::update(const UpdateParameters& parameters) {
continue;
}

if (getRenderLayer(layer->id)->needsRendering(zoomHistory.lastZoom)) {
if (!needsRendering && getRenderLayer(layer->id)->needsRendering(zoomHistory.lastZoom)) {
needsRendering = true;
}

if (hasLayoutDifference(layerDiff, layer->id) ||
if (!needsRelayout && (
hasLayoutDifference(layerDiff, layer->id) ||
!imageDiff.added.empty() ||
!imageDiff.removed.empty() ||
!imageDiff.changed.empty()) {
!imageDiff.changed.empty())) {
needsRelayout = true;
}

Expand Down
Loading