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

Commit

Permalink
update based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Feb 10, 2020
1 parent 7f73d24 commit 410a2b4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 59 deletions.
11 changes: 10 additions & 1 deletion src/mbgl/renderer/layers/render_symbol_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,16 @@ void RenderSymbolLayer::prepare(const LayerPrepareParameters& params) {
const Tile* tile = params.source->getRenderedTile(renderTile.id);
assert(tile);
assert(tile->kind == Tile::Kind::Geometry);
placementData.push_back({*bucket, renderTile, static_cast<const GeometryTile*>(tile)->getFeatureIndex()});

if (bucket->sortKeyRanges.size() == 0) {
placementData.push_back({*bucket, renderTile, static_cast<const GeometryTile*>(tile)->getFeatureIndex(), 0.0f, 0, bucket->symbolInstances.size()});
} else {
for (const SortKeyRange& sortKeyRange : bucket->sortKeyRanges) {
LayerPlacementData layerData{*bucket, renderTile, static_cast<const GeometryTile*>(tile)->getFeatureIndex(), sortKeyRange.sortKey, sortKeyRange.symbolInstanceStart, sortKeyRange.symbolInstanceEnd};
auto sortPosition = std::upper_bound(placementData.cbegin(), placementData.cend(), layerData);
placementData.insert(sortPosition, std::move(layerData));
}
}
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/mbgl/renderer/render_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <memory>
#include <string>
#include <list>

namespace mbgl {

Expand All @@ -30,9 +31,15 @@ class LayerRenderData {

class LayerPlacementData {
public:
friend bool operator<(const LayerPlacementData& lhs, const LayerPlacementData& rhs) {
return lhs.sortKey < rhs.sortKey;
}
std::reference_wrapper<SymbolBucket> bucket;
std::reference_wrapper<const RenderTile> tile;
std::shared_ptr<FeatureIndex> featureIndex;
float sortKey;
size_t symbolInstanceStart;
size_t symbolInstanceEnd;
};

class LayerPrepareParameters {
Expand Down Expand Up @@ -96,7 +103,7 @@ class RenderLayer {

virtual void prepare(const LayerPrepareParameters&);

const std::vector<LayerPlacementData>& getPlacementData() const {
const std::list<LayerPlacementData>& getPlacementData() const {
return placementData;
}

Expand Down Expand Up @@ -127,7 +134,7 @@ class RenderLayer {
// evaluated StyleProperties object and is updated accordingly.
RenderPass passes = RenderPass::None;

std::vector<LayerPlacementData> placementData;
std::list<LayerPlacementData> placementData;

private:
// Some layers may not render correctly on some hardware when the vertex attribute limit of
Expand Down
52 changes: 2 additions & 50 deletions src/mbgl/text/placement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,58 +111,14 @@ Placement::Placement() : collisionIndex({}, MapMode::Static), collisionGroups(tr

void Placement::placeLayer(const RenderLayer& layer) {
std::set<uint32_t> seenCrossTileIDs;
std::list<BucketPlacementParameters> parameters;

for (const auto& item : layer.getPlacementData()) {
SymbolBucket& bucket = item.bucket;
if (bucket.sortKeyRanges.size() == 0) {
BucketPlacementParameters params{item.bucket,
item.tile,
projMatrix,
layer.baseImpl->source,
item.featureIndex,
showCollisionBoxes,
0.0f,
0,
bucket.symbolInstances.size()};
parameters.push_back(params);

} else {
for (const SortKeyRange& sortKeyRange : bucket.sortKeyRanges) {
BucketPlacementParameters params{item.bucket,
item.tile,
projMatrix,
layer.baseImpl->source,
item.featureIndex,
showCollisionBoxes,
sortKeyRange.sortKey,
sortKeyRange.symbolInstanceStart,
sortKeyRange.symbolInstanceEnd};

auto sortPosition = std::upper_bound(parameters.cbegin(), parameters.cend(), params);
parameters.insert(sortPosition, std::move(params));
}
}
}

for (auto& params : parameters) {
SymbolBucket& bucket = params.bucket;
Bucket& bucket = item.bucket;
BucketPlacementParameters params{item.tile, layer.baseImpl->source, item.featureIndex, item.sortKey, item.symbolInstanceStart, item.symbolInstanceEnd};
bucket.place(*this, params, seenCrossTileIDs);

bucket.justReloaded = false;

const OverscaledTileID& overscaledID = params.tile.getOverscaledTileID();

// As long as this placement lives, we have to hold onto this bucket's
// matching FeatureIndex/data for querying purposes
retainedQueryData.emplace(std::piecewise_construct,
std::forward_as_tuple(bucket.bucketInstanceId),
std::forward_as_tuple(bucket.bucketInstanceId, params.featureIndex, overscaledID));
}
}

namespace {
<<<<<<< HEAD
Point<float> calculateVariableLayoutOffset(style::SymbolAnchorType anchor,
float width,
float height,
Expand All @@ -171,10 +127,6 @@ Point<float> calculateVariableLayoutOffset(style::SymbolAnchorType anchor,
bool rotateWithMap,
bool pitchWithMap,
float bearing) {
=======
Point<float> calculateVariableLayoutOffset(
style::SymbolAnchorType anchor, float width, float height, std::array<float, 2> offset, float textBoxScale) {
>>>>>>> fixup
AnchorAlignment alignment = AnchorAlignment::getAnchorAlignment(anchor);
float shiftX = -(alignment.horizontalAlign - 0.5f) * width;
float shiftY = -(alignment.verticalAlign - 0.5f) * height;
Expand Down
5 changes: 0 additions & 5 deletions src/mbgl/text/placement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,9 @@ class CollisionGroups {

class BucketPlacementParameters {
public:
friend bool operator<(const BucketPlacementParameters& lhs, const BucketPlacementParameters& rhs) {
return lhs.sortKey < rhs.sortKey;
}
SymbolBucket& bucket;
const RenderTile& tile;
std::string sourceId;
std::shared_ptr<FeatureIndex> featureIndex;
bool showCollisionBoxes;
float sortKey;
size_t symbolInstanceStart;
size_t symbolInstanceEnd;
Expand Down
4 changes: 3 additions & 1 deletion test/text/cross_tile_symbol_index.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ TEST(CrossTileSymbolLayerIndex, offscreenSymbols) {
std::vector<SymbolInstance> mainInstances;
mainInstances.push_back(makeSymbolInstance(1000, 1000, u"Washington"));
mainInstances.push_back(makeSymbolInstance(2000, 2000, u"Richmond"));
std::vector<SortKeyRange> mainRanges;
SymbolBucket symbolBucket{layout,
{},
16.0f,
Expand All @@ -398,6 +399,7 @@ TEST(CrossTileSymbolLayerIndex, offscreenSymbols) {
sortFeaturesByY,
bucketLeaderID,
std::move(mainInstances),
std::move(mainRanges),
1.0f,
false,
{},
Expand All @@ -414,4 +416,4 @@ TEST(CrossTileSymbolLayerIndex, offscreenSymbols) {

EXPECT_EQ(symbolBucket.symbolInstances.at(0).crossTileID, 1u);
EXPECT_EQ(symbolBucket.symbolInstances.at(1).crossTileID, 2u);
}
}

0 comments on commit 410a2b4

Please sign in to comment.