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

Commit

Permalink
Eliminate some unnecessary pointer indirection
Browse files Browse the repository at this point in the history
Buckets had a pointer to the associated layout type, when they can just
have a direct member.
  • Loading branch information
jfirebaugh committed Mar 31, 2015
1 parent 1cf4799 commit 3d9b441
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 107 deletions.
135 changes: 59 additions & 76 deletions src/mbgl/map/tile_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <mbgl/style/style.hpp>
#include <mbgl/style/style_layer.hpp>
#include <mbgl/style/style_layer_group.hpp>
#include <mbgl/style/style_layout.hpp>
#include <mbgl/renderer/fill_bucket.hpp>
#include <mbgl/renderer/line_bucket.hpp>
#include <mbgl/renderer/symbol_bucket.hpp>
Expand Down Expand Up @@ -49,13 +48,10 @@ TileParser::TileParser(const GeometryTile& geometryTile_,
assert(collision);
}

void TileParser::parse() {
parseStyleLayers(style->layers);
}

bool TileParser::obsolete() const { return tile.state == TileData::State::obsolete; }

void TileParser::parseStyleLayers(util::ptr<const StyleLayerGroup> group) {
void TileParser::parse() {
util::ptr<const StyleLayerGroup> group = style->layers;
if (!group) {
return;
}
Expand Down Expand Up @@ -122,65 +118,6 @@ void applyLayoutProperty(PropertyKey key, const ClassProperties &classProperties
}
}

std::unique_ptr<StyleLayoutFill> parseStyleLayoutFill(const StyleBucket &/*bucket*/, const float /*z*/) {
// no-op; Fill buckets don't currently have any applicable layout properties
auto fillPtr = util::make_unique<StyleLayoutFill>();
return fillPtr;
}

std::unique_ptr<StyleLayoutLine> parseStyleLayoutLine(const StyleBucket &bucket_desc, const float z) {
auto linePtr = util::make_unique<StyleLayoutLine>();
auto &line = *linePtr;
applyLayoutProperty(PropertyKey::LineCap, bucket_desc.layout, line.cap, z);
applyLayoutProperty(PropertyKey::LineJoin, bucket_desc.layout, line.join, z);
applyLayoutProperty(PropertyKey::LineMiterLimit, bucket_desc.layout, line.miter_limit, z);
applyLayoutProperty(PropertyKey::LineRoundLimit, bucket_desc.layout, line.round_limit, z);
return linePtr;
}

std::unique_ptr<StyleLayoutSymbol> parseStyleLayoutSymbol(const StyleBucket &bucket_desc, const float z) {
auto symbolPtr = util::make_unique<StyleLayoutSymbol>();
auto &symbol = *symbolPtr;
applyLayoutProperty(PropertyKey::SymbolPlacement, bucket_desc.layout, symbol.placement, z);
if (symbol.placement == PlacementType::Line) {
symbol.icon.rotation_alignment = RotationAlignmentType::Map;
symbol.text.rotation_alignment = RotationAlignmentType::Map;
};
applyLayoutProperty(PropertyKey::SymbolMinDistance, bucket_desc.layout, symbol.min_distance, z);
applyLayoutProperty(PropertyKey::SymbolAvoidEdges, bucket_desc.layout, symbol.avoid_edges, z);

applyLayoutProperty(PropertyKey::IconAllowOverlap, bucket_desc.layout, symbol.icon.allow_overlap, z);
applyLayoutProperty(PropertyKey::IconIgnorePlacement, bucket_desc.layout, symbol.icon.ignore_placement, z);
applyLayoutProperty(PropertyKey::IconOptional, bucket_desc.layout, symbol.icon.optional, z);
applyLayoutProperty(PropertyKey::IconRotationAlignment, bucket_desc.layout, symbol.icon.rotation_alignment, z);
applyLayoutProperty(PropertyKey::IconMaxSize, bucket_desc.layout, symbol.icon.max_size, z);
applyLayoutProperty(PropertyKey::IconImage, bucket_desc.layout, symbol.icon.image, z);
applyLayoutProperty(PropertyKey::IconPadding, bucket_desc.layout, symbol.icon.padding, z);
applyLayoutProperty(PropertyKey::IconRotate, bucket_desc.layout, symbol.icon.rotate, z);
applyLayoutProperty(PropertyKey::IconKeepUpright, bucket_desc.layout, symbol.icon.keep_upright, z);
applyLayoutProperty(PropertyKey::IconOffset, bucket_desc.layout, symbol.icon.offset, z);

applyLayoutProperty(PropertyKey::TextRotationAlignment, bucket_desc.layout, symbol.text.rotation_alignment, z);
applyLayoutProperty(PropertyKey::TextField, bucket_desc.layout, symbol.text.field, z);
applyLayoutProperty(PropertyKey::TextFont, bucket_desc.layout, symbol.text.font, z);
applyLayoutProperty(PropertyKey::TextMaxSize, bucket_desc.layout, symbol.text.max_size, z);
applyLayoutProperty(PropertyKey::TextMaxWidth, bucket_desc.layout, symbol.text.max_width, z);
applyLayoutProperty(PropertyKey::TextLineHeight, bucket_desc.layout, symbol.text.line_height, z);
applyLayoutProperty(PropertyKey::TextLetterSpacing, bucket_desc.layout, symbol.text.letter_spacing, z);
applyLayoutProperty(PropertyKey::TextMaxAngle, bucket_desc.layout, symbol.text.max_angle, z);
applyLayoutProperty(PropertyKey::TextRotate, bucket_desc.layout, symbol.text.rotate, z);
applyLayoutProperty(PropertyKey::TextPadding, bucket_desc.layout, symbol.text.padding, z);
applyLayoutProperty(PropertyKey::TextIgnorePlacement, bucket_desc.layout, symbol.text.ignore_placement, z);
applyLayoutProperty(PropertyKey::TextOptional, bucket_desc.layout, symbol.text.optional, z);
applyLayoutProperty(PropertyKey::TextJustify, bucket_desc.layout, symbol.text.justify, z);
applyLayoutProperty(PropertyKey::TextAnchor, bucket_desc.layout, symbol.text.anchor, z);
applyLayoutProperty(PropertyKey::TextKeepUpright, bucket_desc.layout, symbol.text.keep_upright, z);
applyLayoutProperty(PropertyKey::TextTransform, bucket_desc.layout, symbol.text.transform, z);
applyLayoutProperty(PropertyKey::TextOffset, bucket_desc.layout, symbol.text.offset, z);
applyLayoutProperty(PropertyKey::TextAllowOverlap, bucket_desc.layout, symbol.text.allow_overlap, z);
return symbolPtr;
}

std::unique_ptr<Bucket> TileParser::createBucket(const StyleBucket &bucketDesc) {
// Skip this bucket if we are to not render this
if (tile.id.z < std::floor(bucketDesc.min_zoom) && std::floor(bucketDesc.min_zoom) < tile.source.max_zoom) return nullptr;
Expand Down Expand Up @@ -230,32 +167,78 @@ void TileParser::addBucketGeometries(Bucket& bucket, const GeometryTileLayer& la

std::unique_ptr<Bucket> TileParser::createFillBucket(const GeometryTileLayer& layer,
const StyleBucket& bucket_desc) {
auto fill = parseStyleLayoutFill(bucket_desc, tile.id.z);
auto bucket = util::make_unique<FillBucket>(std::move(fill),
tile.fillVertexBuffer,
auto bucket = util::make_unique<FillBucket>(tile.fillVertexBuffer,
tile.triangleElementsBuffer,
tile.lineElementsBuffer);
addBucketGeometries(bucket, layer, bucket_desc.filter);
return obsolete() ? nullptr : std::move(bucket);
return std::move(bucket);
}

std::unique_ptr<Bucket> TileParser::createLineBucket(const GeometryTileLayer& layer,
const StyleBucket& bucket_desc) {
auto line = parseStyleLayoutLine(bucket_desc, tile.id.z);
auto bucket = util::make_unique<LineBucket>(std::move(line),
tile.lineVertexBuffer,
auto bucket = util::make_unique<LineBucket>(tile.lineVertexBuffer,
tile.triangleElementsBuffer,
tile.pointElementsBuffer);

const float z = tile.id.z;
auto& layout = bucket->layout;

applyLayoutProperty(PropertyKey::LineCap, bucket_desc.layout, layout.cap, z);
applyLayoutProperty(PropertyKey::LineJoin, bucket_desc.layout, layout.join, z);
applyLayoutProperty(PropertyKey::LineMiterLimit, bucket_desc.layout, layout.miter_limit, z);
applyLayoutProperty(PropertyKey::LineRoundLimit, bucket_desc.layout, layout.round_limit, z);

addBucketGeometries(bucket, layer, bucket_desc.filter);
return obsolete() ? nullptr : std::move(bucket);
return std::move(bucket);
}

std::unique_ptr<Bucket> TileParser::createSymbolBucket(const GeometryTileLayer& layer,
const StyleBucket& bucket_desc) {
auto symbol = parseStyleLayoutSymbol(bucket_desc, tile.id.z);
auto bucket = util::make_unique<SymbolBucket>(std::move(symbol), *collision);
auto bucket = util::make_unique<SymbolBucket>(*collision);

const float z = tile.id.z;
auto& layout = bucket->layout;

applyLayoutProperty(PropertyKey::SymbolPlacement, bucket_desc.layout, layout.placement, z);
if (layout.placement == PlacementType::Line) {
layout.icon.rotation_alignment = RotationAlignmentType::Map;
layout.text.rotation_alignment = RotationAlignmentType::Map;
};
applyLayoutProperty(PropertyKey::SymbolMinDistance, bucket_desc.layout, layout.min_distance, z);
applyLayoutProperty(PropertyKey::SymbolAvoidEdges, bucket_desc.layout, layout.avoid_edges, z);

applyLayoutProperty(PropertyKey::IconAllowOverlap, bucket_desc.layout, layout.icon.allow_overlap, z);
applyLayoutProperty(PropertyKey::IconIgnorePlacement, bucket_desc.layout, layout.icon.ignore_placement, z);
applyLayoutProperty(PropertyKey::IconOptional, bucket_desc.layout, layout.icon.optional, z);
applyLayoutProperty(PropertyKey::IconRotationAlignment, bucket_desc.layout, layout.icon.rotation_alignment, z);
applyLayoutProperty(PropertyKey::IconMaxSize, bucket_desc.layout, layout.icon.max_size, z);
applyLayoutProperty(PropertyKey::IconImage, bucket_desc.layout, layout.icon.image, z);
applyLayoutProperty(PropertyKey::IconPadding, bucket_desc.layout, layout.icon.padding, z);
applyLayoutProperty(PropertyKey::IconRotate, bucket_desc.layout, layout.icon.rotate, z);
applyLayoutProperty(PropertyKey::IconKeepUpright, bucket_desc.layout, layout.icon.keep_upright, z);
applyLayoutProperty(PropertyKey::IconOffset, bucket_desc.layout, layout.icon.offset, z);

applyLayoutProperty(PropertyKey::TextRotationAlignment, bucket_desc.layout, layout.text.rotation_alignment, z);
applyLayoutProperty(PropertyKey::TextField, bucket_desc.layout, layout.text.field, z);
applyLayoutProperty(PropertyKey::TextFont, bucket_desc.layout, layout.text.font, z);
applyLayoutProperty(PropertyKey::TextMaxSize, bucket_desc.layout, layout.text.max_size, z);
applyLayoutProperty(PropertyKey::TextMaxWidth, bucket_desc.layout, layout.text.max_width, z);
applyLayoutProperty(PropertyKey::TextLineHeight, bucket_desc.layout, layout.text.line_height, z);
applyLayoutProperty(PropertyKey::TextLetterSpacing, bucket_desc.layout, layout.text.letter_spacing, z);
applyLayoutProperty(PropertyKey::TextMaxAngle, bucket_desc.layout, layout.text.max_angle, z);
applyLayoutProperty(PropertyKey::TextRotate, bucket_desc.layout, layout.text.rotate, z);
applyLayoutProperty(PropertyKey::TextPadding, bucket_desc.layout, layout.text.padding, z);
applyLayoutProperty(PropertyKey::TextIgnorePlacement, bucket_desc.layout, layout.text.ignore_placement, z);
applyLayoutProperty(PropertyKey::TextOptional, bucket_desc.layout, layout.text.optional, z);
applyLayoutProperty(PropertyKey::TextJustify, bucket_desc.layout, layout.text.justify, z);
applyLayoutProperty(PropertyKey::TextAnchor, bucket_desc.layout, layout.text.anchor, z);
applyLayoutProperty(PropertyKey::TextKeepUpright, bucket_desc.layout, layout.text.keep_upright, z);
applyLayoutProperty(PropertyKey::TextTransform, bucket_desc.layout, layout.text.transform, z);
applyLayoutProperty(PropertyKey::TextOffset, bucket_desc.layout, layout.text.offset, z);
applyLayoutProperty(PropertyKey::TextAllowOverlap, bucket_desc.layout, layout.text.allow_overlap, z);

bucket->addFeatures(
layer, bucket_desc.filter, reinterpret_cast<uintptr_t>(&tile), spriteAtlas, *sprite, glyphAtlas, glyphStore);
return obsolete() ? nullptr : std::move(bucket);
return std::move(bucket);
}
}
2 changes: 0 additions & 2 deletions src/mbgl/map/tile_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class TileParser : private util::noncopyable {

private:
bool obsolete() const;
void parseStyleLayers(util::ptr<const StyleLayerGroup> group);

std::unique_ptr<Bucket> createBucket(const StyleBucket&);
std::unique_ptr<Bucket> createFillBucket(const GeometryTileLayer&, const StyleBucket&);
Expand All @@ -58,7 +57,6 @@ class TileParser : private util::noncopyable {
template <class Bucket>
void addBucketGeometries(Bucket&, const GeometryTileLayer&, const FilterExpression&);

private:
const GeometryTile& geometryTile;
VectorTileData& tile;

Expand Down
7 changes: 2 additions & 5 deletions src/mbgl/renderer/fill_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ void FillBucket::free(void *, void *ptr) {
::free(ptr);
}

FillBucket::FillBucket(std::unique_ptr<const StyleLayoutFill> styleLayout_,
FillVertexBuffer &vertexBuffer_,
FillBucket::FillBucket(FillVertexBuffer &vertexBuffer_,
TriangleElementsBuffer &triangleElementsBuffer_,
LineElementsBuffer &lineElementsBuffer_)
: styleLayout(std::move(styleLayout_)),
allocator(new TESSalloc{
: allocator(new TESSalloc{
&alloc,
&realloc,
&free,
Expand All @@ -53,7 +51,6 @@ FillBucket::FillBucket(std::unique_ptr<const StyleLayoutFill> styleLayout_,
triangle_elements_start(triangleElementsBuffer_.index()),
line_elements_start(lineElementsBuffer.index()) {
assert(tesselator);
assert(styleLayout);
}

FillBucket::~FillBucket() {
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/renderer/fill_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <mbgl/geometry/elements_buffer.hpp>
#include <mbgl/geometry/fill_buffer.hpp>
#include <mbgl/style/style_bucket.hpp>
#include <mbgl/style/style_layout.hpp>

#include <clipper/clipper.hpp>
#include <libtess2/tesselator.h>
Expand Down Expand Up @@ -39,8 +40,7 @@ class FillBucket : public Bucket {
typedef ElementGroup<1> line_group_type;

public:
FillBucket(std::unique_ptr<const StyleLayoutFill> styleLayout,
FillVertexBuffer &vertexBuffer,
FillBucket(FillVertexBuffer &vertexBuffer,
TriangleElementsBuffer &triangleElementsBuffer,
LineElementsBuffer &lineElementsBuffer);
~FillBucket() override;
Expand All @@ -57,7 +57,7 @@ class FillBucket : public Bucket {
void drawVertices(OutlineShader& shader);

public:
const std::unique_ptr<const StyleLayoutFill> styleLayout;
StyleLayoutFill layout;

private:
TESSalloc *allocator;
Expand Down
8 changes: 2 additions & 6 deletions src/mbgl/renderer/line_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@

using namespace mbgl;

LineBucket::LineBucket(std::unique_ptr<const StyleLayoutLine> styleLayout_,
LineVertexBuffer &vertexBuffer_,
LineBucket::LineBucket(LineVertexBuffer &vertexBuffer_,
TriangleElementsBuffer &triangleElementsBuffer_,
PointElementsBuffer &pointElementsBuffer_)
: styleLayout(std::move(styleLayout_)),
vertexBuffer(vertexBuffer_),
: vertexBuffer(vertexBuffer_),
triangleElementsBuffer(triangleElementsBuffer_),
pointElementsBuffer(pointElementsBuffer_),
vertex_start(vertexBuffer_.index()),
triangle_elements_start(triangleElementsBuffer_.index()),
point_elements_start(pointElementsBuffer_.index()) {
assert(styleLayout);
}

LineBucket::~LineBucket() {
Expand All @@ -46,7 +43,6 @@ void LineBucket::addGeometry(const GeometryCollection& geometryCollection) {
}

void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) {
auto &layout = *styleLayout;
// TODO: use roundLimit
// const float roundLimit = geometry.round_limit;

Expand Down
7 changes: 3 additions & 4 deletions src/mbgl/renderer/line_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#include <mbgl/geometry/elements_buffer.hpp>
#include <mbgl/geometry/line_buffer.hpp>
#include <mbgl/style/style_bucket.hpp>
#include <mbgl/style/style_layout.hpp>
#include <mbgl/util/vec.hpp>

#include <vector>

namespace mbgl {

class Style;
class StyleLayoutLine;
class LineVertexBuffer;
class TriangleElementsBuffer;
class LineShader;
Expand All @@ -27,8 +27,7 @@ class LineBucket : public Bucket {
typedef ElementGroup<1> point_group_type;

public:
LineBucket(std::unique_ptr<const StyleLayoutLine> styleLayout,
LineVertexBuffer &vertexBuffer,
LineBucket(LineVertexBuffer &vertexBuffer,
TriangleElementsBuffer &triangleElementsBuffer,
PointElementsBuffer &pointElementsBuffer);
~LineBucket() override;
Expand All @@ -48,7 +47,7 @@ class LineBucket : public Bucket {
void drawPoints(LinejoinShader& shader);

public:
const std::unique_ptr<const StyleLayoutLine> styleLayout;
StyleLayoutLine layout;

private:
LineVertexBuffer& vertexBuffer;
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/painter_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void Painter::renderLine(LineBucket& bucket, const StyleLayer &layer_desc, const
depthMask(false);

const auto &properties = layer_desc.getProperties<LineProperties>();
const auto &layout = *bucket.styleLayout;
const auto &layout = bucket.layout;

// the distance over which the line edge fades out.
// Retina devices need a smaller distance to avoid aliasing.
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/painter_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void Painter::renderSymbol(SymbolBucket &bucket, const StyleLayer &layer_desc, c
}

const auto &properties = layer_desc.getProperties<SymbolProperties>();
const auto &layout = *bucket.styleLayout;
const auto &layout = bucket.layout;

MBGL_CHECK_ERROR(glDisable(GL_STENCIL_TEST));
depthMask(false);
Expand Down
8 changes: 2 additions & 6 deletions src/mbgl/renderer/symbol_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@

namespace mbgl {

SymbolBucket::SymbolBucket(std::unique_ptr<const StyleLayoutSymbol> styleLayout_, Collision &collision_)
: styleLayout(std::move(styleLayout_)), collision(collision_) {
assert(styleLayout);
SymbolBucket::SymbolBucket(Collision &collision_)
: collision(collision_) {
}

SymbolBucket::~SymbolBucket() {
Expand All @@ -46,7 +45,6 @@ std::vector<SymbolFeature> SymbolBucket::processFeatures(const GeometryTileLayer
const FilterExpression& filter,
GlyphStore &glyphStore,
const Sprite &sprite) {
auto &layout = *styleLayout;
const bool has_text = layout.text.field.size();
const bool has_icon = layout.icon.image.size();

Expand Down Expand Up @@ -129,7 +127,6 @@ void SymbolBucket::addFeatures(const GeometryTileLayer& layer,
Sprite& sprite,
GlyphAtlas& glyphAtlas,
GlyphStore& glyphStore) {
auto &layout = *styleLayout;
const std::vector<SymbolFeature> features = processFeatures(layer, filter, glyphStore, sprite);

float horizontalAlign = 0.5;
Expand Down Expand Up @@ -228,7 +225,6 @@ const PlacementRange fullRange{{2 * M_PI, 0}};
void SymbolBucket::addFeature(const std::vector<Coordinate> &line, const Shaping &shaping,
const GlyphPositions &face, const Rect<uint16_t> &image) {
assert(line.size());
auto &layout = *styleLayout;

const float minScale = 0.5f;
const float glyphSize = 24.0f;
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/renderer/symbol_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <mbgl/text/types.hpp>
#include <mbgl/text/glyph.hpp>
#include <mbgl/style/style_bucket.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/style/style_layout.hpp>

#include <memory>
#include <map>
Expand Down Expand Up @@ -56,7 +56,7 @@ class SymbolBucket : public Bucket {
typedef ElementGroup<2> IconElementGroup;

public:
SymbolBucket(std::unique_ptr<const StyleLayoutSymbol> styleLayout, Collision &collision);
SymbolBucket(Collision &collision);
~SymbolBucket() override;

void render(Painter &painter, const StyleLayer &layer_desc, const Tile::ID &id,
Expand Down Expand Up @@ -90,7 +90,7 @@ class SymbolBucket : public Bucket {
void addSymbols(Buffer &buffer, const PlacedGlyphs &symbols, float scale, PlacementRange placementRange);

public:
const std::unique_ptr<const StyleLayoutSymbol> styleLayout;
StyleLayoutSymbol layout;
bool sdfIcons = false;

private:
Expand Down

0 comments on commit 3d9b441

Please sign in to comment.