Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/tile_pyramid.cpp
src/mbgl/renderer/tile_pyramid.hpp
src/mbgl/renderer/transitioning_property.hpp
src/mbgl/renderer/update_parameters.hpp

# renderer/sources
src/mbgl/renderer/sources/render_geojson_source.cpp
Expand Down
35 changes: 12 additions & 23 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <mbgl/style/light.hpp>
#include <mbgl/style/observer.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/renderer/tile_parameters.hpp>
#include <mbgl/renderer/update_parameters.hpp>
#include <mbgl/renderer/painter.hpp>
#include <mbgl/renderer/render_source.hpp>
#include <mbgl/storage/file_source.hpp>
Expand Down Expand Up @@ -243,28 +243,17 @@ void Map::Impl::render(View& view) {
annotationManager->updateData();
}

if (updateFlags & Update::Classes) {
style->cascade(timePoint, mode);
}

if (updateFlags & Update::Classes || updateFlags & Update::RecalculateStyle) {
style->recalculate(transform.getZoom(), timePoint, mode);
}

if (updateFlags & Update::Layout) {
style->relayout();
}

TileParameters parameters(pixelRatio,
debugOptions,
transform.getState(),
scheduler,
fileSource,
mode,
*annotationManager,
*style);

style->updateTiles(parameters);
style->update({
mode,
updateFlags,
pixelRatio,
debugOptions,
timePoint,
transform.getState(),
scheduler,
fileSource,
*annotationManager
});

updateFlags = Update::Nothing;

Expand Down
3 changes: 1 addition & 2 deletions src/mbgl/map/update.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ enum class Update {
Classes = 1 << 2,
RecalculateStyle = 1 << 3,
AnnotationStyle = 1 << 6,
AnnotationData = 1 << 7,
Layout = 1 << 8
AnnotationData = 1 << 7
};

constexpr Update operator|(Update lhs, Update rhs) {
Expand Down
10 changes: 6 additions & 4 deletions src/mbgl/renderer/property_evaluation_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ namespace mbgl {
class PropertyEvaluationParameters {
public:
explicit PropertyEvaluationParameters(float z_)
: z(z_) {}
: z(z_),
now(Clock::time_point::max()),
zoomHistory(),
defaultFadeDuration(0) {}

PropertyEvaluationParameters(float z_,
PropertyEvaluationParameters(ZoomHistory zoomHistory_,
TimePoint now_,
ZoomHistory zoomHistory_,
Duration defaultFadeDuration_)
: z(z_),
: z(zoomHistory_.lastZoom),
now(std::move(now_)),
zoomHistory(std::move(zoomHistory_)),
defaultFadeDuration(std::move(defaultFadeDuration_)) {}
Expand Down
26 changes: 26 additions & 0 deletions src/mbgl/renderer/update_parameters.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <mbgl/map/mode.hpp>
#include <mbgl/map/update.hpp>

namespace mbgl {

class TransformState;
class Scheduler;
class FileSource;
class AnnotationManager;

class UpdateParameters {
public:
const MapMode mode;
const Update updateFlags;
const float pixelRatio;
const MapDebugOptions debugOptions;
const TimePoint timePoint;
const TransformState& transformState;
Scheduler& scheduler;
FileSource& fileSource;
AnnotationManager& annotationManager;
};

} // namespace mbgl
112 changes: 52 additions & 60 deletions src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
#include <mbgl/sprite/sprite_atlas.hpp>
#include <mbgl/text/glyph_atlas.hpp>
#include <mbgl/geometry/line_atlas.hpp>
#include <mbgl/renderer/render_source.hpp>
#include <mbgl/renderer/tile_parameters.hpp>
#include <mbgl/renderer/update_parameters.hpp>
#include <mbgl/renderer/cascade_parameters.hpp>
#include <mbgl/renderer/property_evaluation_parameters.hpp>
#include <mbgl/renderer/tile_parameters.hpp>
#include <mbgl/renderer/render_source.hpp>
#include <mbgl/renderer/render_item.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/renderer/render_background_layer.hpp>
Expand Down Expand Up @@ -327,68 +328,56 @@ double Style::getDefaultPitch() const {
return defaultPitch;
}

void Style::updateTiles(const TileParameters& parameters) {
for (const auto& renderSource : renderSources) {
if (renderSource->enabled) {
renderSource->updateTiles(parameters);
}
}
}

void Style::relayout() {
for (const auto& sourceID : updateBatch.sourceIDs) {
RenderSource* renderSource = getRenderSource(sourceID);
if (renderSource && renderSource->enabled) {
renderSource->reloadTiles();
} else if (renderSource) {
renderSource->invalidateTiles();
}
}
updateBatch.sourceIDs.clear();
}

void Style::cascade(const TimePoint& timePoint, MapMode mode) {
// When in continuous mode, we can either have user- or style-defined
// transitions. Still mode is always immediate.
static const TransitionOptions immediateTransition {};
void Style::update(const UpdateParameters& parameters) {
zoomHistory.update(parameters.transformState.getZoom(), parameters.timePoint);

std::vector<ClassID> classIDs;
for (const auto& className : classes) {
classIDs.push_back(ClassDictionary::Get().lookup(className));
}
classIDs.push_back(ClassID::Default);

const CascadeParameters parameters {
const CascadeParameters cascadeParameters {
classIDs,
timePoint,
mode == MapMode::Continuous ? transitionOptions : immediateTransition
parameters.timePoint,
parameters.mode == MapMode::Continuous ? transitionOptions : TransitionOptions()
};

for (const auto& layer : renderLayers) {
layer->cascade(parameters);
const PropertyEvaluationParameters evaluationParameters {
zoomHistory,
parameters.timePoint,
parameters.mode == MapMode::Continuous ? util::DEFAULT_FADE_DURATION : Duration::zero()
};

const TileParameters tileParameters(parameters.pixelRatio,
parameters.debugOptions,
parameters.transformState,
parameters.scheduler,
parameters.fileSource,
parameters.mode,
parameters.annotationManager,
*this);

if (parameters.updateFlags & Update::Classes) {
transitioningLight = TransitioningLight(*light, std::move(transitioningLight), cascadeParameters);
}

transitioningLight = TransitioningLight(*light, std::move(transitioningLight), parameters);
}
if (parameters.updateFlags & Update::RecalculateStyle) {
evaluatedLight = EvaluatedLight(transitioningLight, evaluationParameters);
}

void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) {
// Disable all sources first. If we find an enabled layer that uses this source, we will
// re-enable it later.
for (const auto& renderSource : renderSources) {
renderSource->enabled = false;
}

zoomHistory.update(z, timePoint);

const PropertyEvaluationParameters parameters {
z,
timePoint,
zoomHistory,
mode == MapMode::Continuous ? util::DEFAULT_FADE_DURATION : Duration::zero()
};

for (const auto& layer : renderLayers) {
layer->evaluate(parameters);
if (parameters.updateFlags & Update::Classes) {
layer->cascade(cascadeParameters);
}

if (parameters.updateFlags & Update::Classes || parameters.updateFlags & Update::RecalculateStyle) {
layer->evaluate(evaluationParameters);
}

if (layer->needsRendering(zoomHistory.lastZoom)) {
if (RenderSource* renderSource = getRenderSource(layer->baseImpl.source)) {
Expand All @@ -397,14 +386,21 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) {
}
}

evaluatedLight = EvaluatedLight(transitioningLight, parameters);

// Remove the existing tiles if we didn't end up re-enabling the source.
for (const auto& renderSource : renderSources) {
if (!renderSource->enabled) {
bool updated = updateBatch.sourceIDs.count(renderSource->baseImpl.id);
if (renderSource->enabled) {
if (updated) {
renderSource->reloadTiles();
}
renderSource->updateTiles(tileParameters);
} else if (updated) {
renderSource->invalidateTiles();
} else {
renderSource->removeTiles();
}
}

updateBatch.sourceIDs.clear();
}

std::vector<const Source*> Style::getSources() const {
Expand Down Expand Up @@ -720,12 +716,12 @@ struct QueueSourceReloadVisitor {

void Style::onLayerFilterChanged(Layer& layer) {
layer.accept(QueueSourceReloadVisitor { updateBatch });
observer->onUpdate(Update::Layout);
observer->onUpdate(Update::Repaint);
}

void Style::onLayerVisibilityChanged(Layer& layer) {
layer.accept(QueueSourceReloadVisitor { updateBatch });
observer->onUpdate(Update::RecalculateStyle | Update::Layout);
observer->onUpdate(Update::RecalculateStyle);
}

void Style::onLayerPaintPropertyChanged(Layer&) {
Expand All @@ -734,20 +730,16 @@ void Style::onLayerPaintPropertyChanged(Layer&) {

void Style::onLayerDataDrivenPaintPropertyChanged(Layer& layer) {
layer.accept(QueueSourceReloadVisitor { updateBatch });
observer->onUpdate(Update::RecalculateStyle | Update::Classes | Update::Layout);
observer->onUpdate(Update::RecalculateStyle | Update::Classes);
}

void Style::onLayerLayoutPropertyChanged(Layer& layer, const char * property) {
layer.accept(QueueSourceReloadVisitor { updateBatch });

auto update = Update::Layout;

// Recalculate the style for certain properties
bool needsRecalculation = strcmp(property, "icon-size") == 0 || strcmp(property, "text-size") == 0;
if (needsRecalculation) {
update |= Update::RecalculateStyle;
}
observer->onUpdate(update);
observer->onUpdate((strcmp(property, "icon-size") == 0 || strcmp(property, "text-size") == 0)
? Update::RecalculateStyle
: Update::Repaint);
}

void Style::dumpDebugLogs() const {
Expand Down
10 changes: 2 additions & 8 deletions src/mbgl/style/style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class RenderedQueryOptions;
class Scheduler;
class RenderLayer;
class RenderSource;
class TileParameters;
class UpdateParameters;

namespace style {

Expand All @@ -59,13 +59,7 @@ class Style : public GlyphAtlasObserver,

bool isLoaded() const;

// Fetch the tiles needed by the current viewport and emit a signal when
// a tile is ready so observers can render the tile.
void updateTiles(const TileParameters&);

void relayout();
void cascade(const TimePoint&, MapMode);
void recalculate(float z, const TimePoint&, MapMode);
void update(const UpdateParameters&);

bool hasTransitions() const;

Expand Down
5 changes: 1 addition & 4 deletions src/mbgl/tile/geometry_tile_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,7 @@ static std::vector<std::unique_ptr<RenderLayer>> toRenderLayers(const std::vecto
});

renderLayers.back()->evaluate(PropertyEvaluationParameters {
zoom,
Clock::time_point::max(),
ZoomHistory(),
Duration(0)
zoom
});
}
return renderLayers;
Expand Down
12 changes: 8 additions & 4 deletions test/style/paint_property.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ using namespace mbgl::style;
using namespace std::literals::chrono_literals;

float evaluate(TransitioningProperty<PropertyValue<float>>& property, Duration delta = Duration::zero()) {
ZoomHistory zoomHistory;
zoomHistory.update(0, TimePoint::min() + delta);

PropertyEvaluationParameters parameters {
0,
zoomHistory,
TimePoint::min() + delta,
ZoomHistory(),
Duration::zero()
};

Expand All @@ -24,10 +26,12 @@ float evaluate(TransitioningProperty<PropertyValue<float>>& property, Duration d
}

PossiblyEvaluatedPropertyValue<float> evaluate(TransitioningProperty<DataDrivenPropertyValue<float>>& property, Duration delta = Duration::zero()) {
ZoomHistory zoomHistory;
zoomHistory.update(0, TimePoint::min() + delta);

PropertyEvaluationParameters parameters {
0,
zoomHistory,
TimePoint::min() + delta,
ZoomHistory(),
Duration::zero()
};

Expand Down