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

Commit

Permalink
Revert "Revert "[core][cp] Backport #15092 to mojito""
Browse files Browse the repository at this point in the history
This reverts commit 0bd3a8a.
  • Loading branch information
friedbunny committed Jul 19, 2019
1 parent 1b53433 commit 46e15df
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 16 deletions.
2 changes: 2 additions & 0 deletions include/mbgl/style/layer_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class LayerProperties {
virtual ~LayerProperties() = default;

Immutable<Layer::Impl> baseImpl;
// Contains render passes used by the renderer, see `mbgl::RenderPass`.
uint8_t renderPasses = 0u;

protected:
LayerProperties(Immutable<Layer::Impl> impl) : baseImpl(std::move(impl)) {}
Expand Down
5 changes: 3 additions & 2 deletions src/mbgl/renderer/layers/render_background_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void RenderBackgroundLayer::evaluate(const PropertyEvaluationParameters &paramet

passes = properties->evaluated.get<style::BackgroundOpacity>() > 0 ? RenderPass::Translucent
: RenderPass::None;
properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
}

Expand Down Expand Up @@ -129,8 +130,8 @@ void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) {
}

optional<Color> RenderBackgroundLayer::getSolidBackground() const {
const auto& evaluated = static_cast<const BackgroundLayerProperties&>(*evaluatedProperties).evaluated;
if (!evaluated.get<BackgroundPattern>().from.empty()) {
const auto& evaluated = getEvaluated<BackgroundLayerProperties>(evaluatedProperties);
if (!evaluated.get<BackgroundPattern>().from.empty() || evaluated.get<style::BackgroundOpacity>() <= 0.0f) {
return nullopt;
}

Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/renderer/layers/render_circle_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void RenderCircleLayer::evaluate(const PropertyEvaluationParameters& parameters)
&& (evaluated.get<style::CircleOpacity>().constantOr(1) > 0 ||
evaluated.get<style::CircleStrokeOpacity>().constantOr(1) > 0))
? RenderPass::Translucent : RenderPass::None;
properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
}

Expand All @@ -58,7 +59,7 @@ void RenderCircleLayer::render(PaintParameters& parameters, RenderSource*) {
}

for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = tile.tile.getLayerRenderData(*baseImpl);
const LayerRenderData* renderData = getRenderDataForPass(tile, parameters.pass);
if (!renderData) {
continue;
}
Expand Down
5 changes: 3 additions & 2 deletions src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void RenderFillExtrusionLayer::evaluate(const PropertyEvaluationParameters& para
passes = (properties->evaluated.get<style::FillExtrusionOpacity>() > 0)
? (RenderPass::Translucent | RenderPass::Pass3D)
: RenderPass::None;
properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
}

Expand Down Expand Up @@ -119,7 +120,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*

if (unevaluated.get<FillExtrusionPattern>().isUndefined()) {
for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = tile.tile.getLayerRenderData(*baseImpl);
const LayerRenderData* renderData = getRenderDataForPass(tile, parameters.pass);
if (!renderData) {
continue;
}
Expand All @@ -145,7 +146,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*
}
} else {
for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = tile.tile.getLayerRenderData(*baseImpl);
const LayerRenderData* renderData = getRenderDataForPass(tile, parameters.pass);
if (!renderData) {
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/renderer/layers/render_fill_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void RenderFillLayer::evaluate(const PropertyEvaluationParameters& parameters) {
} else {
passes |= RenderPass::Opaque;
}

properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
}

Expand All @@ -74,7 +74,7 @@ bool RenderFillLayer::hasCrossfade() const {
void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) {
if (unevaluated.get<FillPattern>().isUndefined()) {
for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = tile.tile.getLayerRenderData(*baseImpl);
const LayerRenderData* renderData = getRenderDataForPass(tile, parameters.pass);
if (!renderData) {
continue;
}
Expand Down Expand Up @@ -158,7 +158,7 @@ void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) {
}

for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = tile.tile.getLayerRenderData(*baseImpl);
const LayerRenderData* renderData = getRenderDataForPass(tile, parameters.pass);
if (!renderData) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/renderer/layers/render_heatmap_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void RenderHeatmapLayer::evaluate(const PropertyEvaluationParameters& parameters
passes = (properties->evaluated.get<style::HeatmapOpacity>() > 0)
? (RenderPass::Translucent | RenderPass::Pass3D)
: RenderPass::None;

properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
}

Expand Down Expand Up @@ -89,7 +89,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) {
"heatmap texture", { *renderTexture, Color{ 0.0f, 0.0f, 0.0f, 1.0f }, {}, {} });

for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = tile.tile.getLayerRenderData(*baseImpl);
const LayerRenderData* renderData = getRenderDataForPass(tile, parameters.pass);
if (!renderData) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/layers/render_hillshade_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void RenderHillshadeLayer::evaluate(const PropertyEvaluationParameters& paramete
passes = (properties->evaluated.get<style::HillshadeExaggeration >() > 0)
? (RenderPass::Translucent | RenderPass::Pass3D)
: RenderPass::None;

properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
}

Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/renderer/layers/render_line_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void RenderLineLayer::evaluate(const PropertyEvaluationParameters& parameters) {
&& evaluated.get<style::LineColor>().constantOr(Color::black()).a > 0
&& evaluated.get<style::LineWidth>().constantOr(1.0) > 0)
? RenderPass::Translucent : RenderPass::None;
properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
}

Expand All @@ -63,7 +64,7 @@ void RenderLineLayer::render(PaintParameters& parameters, RenderSource*) {
}

for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = tile.tile.getLayerRenderData(*baseImpl);
const LayerRenderData* renderData = getRenderDataForPass(tile, parameters.pass);
if (!renderData) {
continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/renderer/layers/render_raster_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void RenderRasterLayer::evaluate(const PropertyEvaluationParameters& parameters)
staticImmutableCast<RasterLayer::Impl>(baseImpl),
unevaluated.evaluate(parameters));
passes = properties->evaluated.get<style::RasterOpacity>() > 0 ? RenderPass::Translucent : RenderPass::None;
properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
}

Expand Down
4 changes: 3 additions & 1 deletion src/mbgl/renderer/layers/render_symbol_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ void RenderSymbolLayer::evaluate(const PropertyEvaluationParameters& parameters)
passes = ((evaluated.get<style::IconOpacity>().constantOr(1) > 0 && hasIconOpacity && iconSize > 0)
|| (evaluated.get<style::TextOpacity>().constantOr(1) > 0 && hasTextOpacity && textSize > 0))
? RenderPass::Translucent : RenderPass::None;
properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
}

Expand Down Expand Up @@ -471,7 +472,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
};

for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = tile.tile.getLayerRenderData(*baseImpl);
const LayerRenderData* renderData = getRenderDataForPass(tile, parameters.pass);
if (!renderData) {
continue;
}
Expand Down Expand Up @@ -619,6 +620,7 @@ style::TextPaintProperties::PossiblyEvaluated RenderSymbolLayer::textPaintProper
void RenderSymbolLayer::setRenderTiles(RenderTiles tiles, const TransformState& state) {
auto filterFn = [](auto& tile){ return !tile.tile.isRenderable(); };
renderTiles = RenderLayer::filterRenderTiles(std::move(tiles), filterFn);
addRenderPassesFromTiles();
// Sort symbol tiles in opposite y position, so tiles with overlapping symbols are drawn
// on top of each other, with lower symbols being drawn on top of higher symbols.
std::sort(renderTiles.begin(), renderTiles.end(), [&state](const auto& a, const auto& b) {
Expand Down
18 changes: 18 additions & 0 deletions src/mbgl/renderer/render_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ bool RenderLayer::supportsZoom(float zoom) const {
void RenderLayer::setRenderTiles(RenderTiles tiles, const TransformState&) {
auto filterFn = [](auto& tile){ return !tile.tile.isRenderable() || tile.tile.holdForFade(); };
renderTiles = filterRenderTiles(std::move(tiles), filterFn);
addRenderPassesFromTiles();
}

const RenderLayerSymbolInterface* RenderLayer::getSymbolInterface() const {
Expand Down Expand Up @@ -96,5 +97,22 @@ void RenderLayer::checkRenderability(const PaintParameters& parameters,
}
}

void RenderLayer::addRenderPassesFromTiles() {
for (const RenderTile& tile : renderTiles) {
if (tile.tile.kind != Tile::Kind::Geometry) break;
if (const LayerRenderData* renderData = tile.tile.getLayerRenderData(*baseImpl)) {
passes |= RenderPass(renderData->layerProperties->renderPasses);
}
}
}

const LayerRenderData* RenderLayer::getRenderDataForPass(const RenderTile& tile, RenderPass pass) const {
assert(tile.tile.kind == Tile::Kind::Geometry);
if (const LayerRenderData* renderData = tile.tile.getLayerRenderData(*baseImpl)) {
return bool(RenderPass(renderData->layerProperties->renderPasses) & pass) ? renderData : nullptr;
}
return nullptr;
}

} //namespace mbgl

4 changes: 4 additions & 0 deletions src/mbgl/renderer/render_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ class RenderLayer {
using FilterFunctionPtr = bool (*)(RenderTile&);
RenderTiles filterRenderTiles(RenderTiles, FilterFunctionPtr) const;

void addRenderPassesFromTiles();

const LayerRenderData* getRenderDataForPass(const RenderTile&, RenderPass) const;

protected:
// Stores current set of tiles to be rendered for this layer.
std::vector<std::reference_wrapper<RenderTile>> renderTiles;
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/renderer/renderer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
const Immutable<Layer::Impl>& layerImpl = *it;
RenderLayer* layer = getRenderLayer(layerImpl->id);
const auto* layerInfo = layerImpl->getTypeInfo();
const bool layerNeedsRendering = layer->needsRendering();
const bool layerIsVisible = layer->baseImpl->visibility != style::VisibilityType::None;
const bool zoomFitsLayer = layer->supportsZoom(zoomHistory.lastZoom);
staticData->has3D = (staticData->has3D || layerInfo->pass3d == LayerTypeInfo::Pass3D::Required);

if (layerInfo->source != LayerTypeInfo::Source::NotRequired) {
if (layerImpl->source == sourceImpl->id) {
sourceNeedsRelayout = (sourceNeedsRelayout || hasImageDiff || hasLayoutDifference(layerDiff, layerImpl->id));
if (layerNeedsRendering) {
if (layerIsVisible) {
filteredLayersForSource.push_back(layer->evaluatedProperties);
if (zoomFitsLayer) {
sourceNeedsRendering = true;
Expand All @@ -269,7 +269,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
}

// Handle layers without source.
if (layerNeedsRendering && zoomFitsLayer && sourceImpl.get() == sourceImpls->at(0).get()) {
if (layerIsVisible && zoomFitsLayer && sourceImpl.get() == sourceImpls->at(0).get()) {
if (!backend.contextIsShared() && layerImpl.get() == layerImpls->at(0).get()) {
const auto& solidBackground = layer->getSolidBackground();
if (solidBackground) {
Expand Down

0 comments on commit 46e15df

Please sign in to comment.