|
1 | 1 | #include <mbgl/renderer/group_by_layout.hpp> |
2 | | -#include <mbgl/style/conversion/stringify.hpp> |
3 | | -#include <mbgl/util/rapidjson.hpp> |
| 2 | +#include <mbgl/util/instrumentation.hpp> |
| 3 | +#include <mbgl/util/containers.hpp> |
| 4 | +#include <mbgl/style/layer_properties.hpp> |
4 | 5 |
|
5 | | -#include <rapidjson/writer.h> |
6 | | -#include <rapidjson/stringbuffer.h> |
7 | | - |
8 | | -#include <unordered_map> |
| 6 | +#include <string> |
9 | 7 |
|
10 | 8 | namespace mbgl { |
11 | 9 |
|
12 | | -std::string layoutKey(const style::Layer::Impl& impl) { |
| 10 | +std::string createLayoutKey(const style::Layer::Impl& impl) { |
13 | 11 | using namespace style::conversion; |
| 12 | + std::string key; |
| 13 | + key += std::to_string(reinterpret_cast<uint64_t>(impl.getTypeInfo())); |
| 14 | + key += impl.source; |
| 15 | + key += impl.sourceLayer; |
| 16 | + key += std::to_string(impl.maxZoom); |
| 17 | + key += std::to_string(impl.minZoom); |
| 18 | + key += std::to_string(static_cast<uint32_t>(impl.visibility)); |
| 19 | + return key; |
| 20 | +} |
14 | 21 |
|
15 | | - rapidjson::StringBuffer s; |
16 | | - rapidjson::Writer<rapidjson::StringBuffer> writer(s); |
17 | | - |
18 | | - writer.StartArray(); |
19 | | - writer.Uint64(reinterpret_cast<uint64_t>(impl.getTypeInfo())); |
20 | | - writer.String(impl.source); |
21 | | - writer.String(impl.sourceLayer); |
22 | | - writer.Double(impl.minZoom); |
23 | | - writer.Double(impl.maxZoom); |
24 | | - writer.Uint(static_cast<uint32_t>(impl.visibility)); |
25 | | - stringify(writer, impl.filter); |
26 | | - impl.stringifyLayout(writer); |
27 | | - writer.EndArray(); |
28 | | - |
29 | | - return s.GetString(); |
| 22 | +GroupMap groupLayers(const std::vector<Immutable<style::LayerProperties>>& layers) { |
| 23 | + MLN_TRACE_FUNC(); |
| 24 | + |
| 25 | + mbgl::unordered_map<std::string, std::vector<Immutable<style::LayerProperties>>> groupMap; |
| 26 | + groupMap.reserve(layers.size()); |
| 27 | + |
| 28 | + for (auto layer : layers) { |
| 29 | + // this part of the key is unique per filter |
| 30 | + auto layoutFilterKey = 0; |
| 31 | + while (true) { |
| 32 | + auto layoutKey = createLayoutKey(*layer->baseImpl) + std::to_string(layoutFilterKey); |
| 33 | + if (groupMap.contains(layoutKey)) { |
| 34 | + if (groupMap[layoutKey].front()->baseImpl->filter != layer->baseImpl->filter) { |
| 35 | + ++layoutFilterKey; |
| 36 | + continue; |
| 37 | + } |
| 38 | + } |
| 39 | + groupMap[layoutKey].push_back(std::move(layer)); |
| 40 | + break; |
| 41 | + } |
| 42 | + } |
| 43 | + return groupMap; |
30 | 44 | } |
31 | 45 |
|
32 | 46 | } // namespace mbgl |
0 commit comments