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

Commit

Permalink
[core] Reserve size for filtered render layers
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshalamov committed Jun 15, 2019
1 parent d7ac45d commit 5d6b06a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/mbgl/renderer/renderer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,20 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {

// Update all sources and initialize renderItems.
staticData->has3D = false;

// Reserve size for filteredLayersForSource if there are sources.
std::vector<Immutable<LayerProperties>> filteredLayersForSource;
std::size_t maxRenderedLayersPerSource = 0ull;
if (!sourceImpls->empty()) {
const std::size_t reservedSize = prevFrameRenderedLayersCount == 0ull ?
layerImpls->size() : prevFrameRenderedLayersCount;
filteredLayersForSource.reserve(reservedSize);
}

for (const auto& sourceImpl : *sourceImpls) {
RenderSource* source = renderSources.at(sourceImpl->id).get();
std::vector<Immutable<LayerProperties>> filteredLayersForSource;
filteredLayersForSource.reserve(layerImpls->size());
bool sourceNeedsRendering = false;
bool sourceNeedsRelayout = false;

uint32_t index = 0u;
const auto begin = layerImpls->begin();
const auto end = layerImpls->end();
Expand Down Expand Up @@ -284,8 +291,14 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
sourceNeedsRendering,
sourceNeedsRelayout,
tileParameters);

maxRenderedLayersPerSource = std::max(maxRenderedLayersPerSource, filteredLayersForSource.size());
filteredLayersForSource.clear();
}

// Update value indicating how many layers were rendered on this frame.
prevFrameRenderedLayersCount = maxRenderedLayersPerSource;

const bool loaded = updateParameters.styleLoaded && isLoaded();
if (!isMapModeContinuous && !loaded) {
return;
Expand Down
3 changes: 3 additions & 0 deletions src/mbgl/renderer/renderer_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ class Renderer::Impl : public GlyphManagerObserver,
std::unique_ptr<Placement> placement;

bool contextLost = false;

// Number of rendered layers from the previous frame.
std::size_t prevFrameRenderedLayersCount = 0ull;
};

} // namespace mbgl

0 comments on commit 5d6b06a

Please sign in to comment.