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

Commit

Permalink
[core][cp] Backport #15092 to oolong
Browse files Browse the repository at this point in the history
Backports #15092 to release-oolong.
  • Loading branch information
pozdnyakov committed Jul 19, 2019
1 parent e05bf8d commit 676c6e3
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 22 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
8 changes: 4 additions & 4 deletions src/mbgl/renderer/layers/render_background_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ void RenderBackgroundLayer::evaluate(const PropertyEvaluationParameters &paramet
parameters.getCrossfadeParameters(),
unevaluated.evaluate(parameters));

passes = properties->evaluated.get<style::BackgroundOpacity>() > 0 ? RenderPass::Translucent
: RenderPass::None;
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 @@ -133,8 +133,8 @@ void RenderBackgroundLayer::render(PaintParameters& parameters) {
}

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) {
}

for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = 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 @@ -116,7 +117,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters) {
// Draw solid color extrusions
auto drawTiles = [&](const gfx::StencilMode& stencilMode_, const gfx::ColorMode& colorMode_, const std::string& name) {
for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = tile.getLayerRenderData(*baseImpl);
const LayerRenderData* renderData = getRenderDataForPass(tile, parameters.pass);
if (!renderData) {
continue;
}
Expand Down Expand Up @@ -163,7 +164,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters) {
const auto fillPatternValue = evaluated.get<FillExtrusionPattern>().constantOr(mbgl::Faded<std::basic_string<char> >{"", ""});
auto drawTiles = [&](const gfx::StencilMode& stencilMode_, const gfx::ColorMode& colorMode_, const std::string& name) {
for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = 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 @@ -60,7 +60,7 @@ void RenderFillLayer::evaluate(const PropertyEvaluationParameters& parameters) {
} else {
passes |= RenderPass::Opaque;
}

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

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

for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = 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::Upload)
: RenderPass::None;

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

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

for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = 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_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 All @@ -66,7 +66,8 @@ bool RenderHillshadeLayer::hasCrossfade() const {
}

void RenderHillshadeLayer::prepare(const LayerPrepareParameters& params) {
RenderLayer::prepare(params);
assert(params.source);
renderTiles = filterRenderTiles(params.source->getRenderedTiles());
if (auto* demsrc = params.source->as<RenderRasterDEMSource>()) {
maxzoom = demsrc->getMaxZoom();
}
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 @@ -48,6 +48,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::Upload : RenderPass::None;
properties->renderPasses = mbgl::underlying_type(passes);
evaluatedProperties = std::move(properties);
}

Expand Down Expand Up @@ -98,7 +99,7 @@ void RenderLineLayer::render(PaintParameters& parameters) {
parameters.renderTileClippingMasks(renderTiles);

for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = tile.getLayerRenderData(*baseImpl);
const LayerRenderData* renderData = getRenderDataForPass(tile, parameters.pass);
if (!renderData) {
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion src/mbgl/renderer/layers/render_raster_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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 Expand Up @@ -73,7 +74,8 @@ static std::array<float, 3> spinWeights(float spin) {
}

void RenderRasterLayer::prepare(const LayerPrepareParameters& params) {
RenderLayer::prepare(params);
assert(params.source);
renderTiles = filterRenderTiles(params.source->getRenderedTiles());
auto* imageSource = params.source->as<RenderImageSource>();
if (imageSource && imageSource->isLoaded()) {
assert(imageSource->isEnabled());
Expand Down
5 changes: 3 additions & 2 deletions src/mbgl/renderer/layers/render_symbol_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,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::Upload : RenderPass::None;

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

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

for (const RenderTile& tile : renderTiles) {
const LayerRenderData* renderData = tile.getLayerRenderData(*baseImpl);
const LayerRenderData* renderData = getRenderDataForPass(tile, parameters.pass);
if (!renderData) {
continue;
}
Expand Down Expand Up @@ -494,6 +494,7 @@ style::TextPaintProperties::PossiblyEvaluated RenderSymbolLayer::textPaintProper

void RenderSymbolLayer::prepare(const LayerPrepareParameters& params) {
renderTiles = params.source->getRenderedTiles();
addRenderPassesFromTiles();
const auto comp = [bearing = params.state.getBearing()](const RenderTile& a, const RenderTile& b) {
Point<float> pa(a.id.canonical.x, a.id.canonical.y);
Point<float> pb(b.id.canonical.x, b.id.canonical.y);
Expand Down
16 changes: 16 additions & 0 deletions src/mbgl/renderer/render_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ bool RenderLayer::supportsZoom(float zoom) const {
void RenderLayer::prepare(const LayerPrepareParameters& params) {
assert(params.source);
renderTiles = filterRenderTiles(params.source->getRenderedTiles());
addRenderPassesFromTiles();
}

optional<Color> RenderLayer::getSolidBackground() const {
Expand Down Expand Up @@ -97,5 +98,20 @@ void RenderLayer::checkRenderability(const PaintParameters& parameters,
}
}

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

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

} //namespace mbgl

7 changes: 6 additions & 1 deletion src/mbgl/renderer/render_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class RenderLayer {
// in the console to inform the developer.
void checkRenderability(const PaintParameters&, uint32_t activeBindingCount);

void addRenderPassesFromTiles();

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

protected:
using RenderTiles = std::vector<std::reference_wrapper<RenderTile>>;
// Stores current set of tiles to be rendered for this layer.
Expand All @@ -122,8 +126,9 @@ class RenderLayer {

std::vector<LayerPlacementData> placementData;

private:
RenderTiles filterRenderTiles(RenderTiles) const;

private:
// Some layers may not render correctly on some hardware when the vertex attribute limit of
// that GPU is exceeded. More attributes are used when adding many data driven paint properties
// to a layer.
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 @@ -249,14 +249,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 @@ -268,7 +268,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 676c6e3

Please sign in to comment.