[core] Per-tile glyph/icon atlases
This commit is contained in:
@@ -78,10 +78,27 @@ public:
|
||||
std::fill(data.get(), data.get() + bytes(), value);
|
||||
}
|
||||
|
||||
void resize(Size size_) {
|
||||
if (size == size_) {
|
||||
return;
|
||||
}
|
||||
Image newImage(size_);
|
||||
newImage.fill(0);
|
||||
copy(*this, newImage, {0, 0}, {0, 0}, {
|
||||
std::min(size.width, size_.width),
|
||||
std::min(size.height, size_.height)
|
||||
});
|
||||
operator=(std::move(newImage));
|
||||
}
|
||||
|
||||
// Copy image data within `rect` from `src` to the rectangle of the same size at `pt`
|
||||
// in `dst`. If the specified bounds exceed the bounds of the source or destination,
|
||||
// throw `std::out_of_range`. Must not be used to move data within a single Image.
|
||||
static void copy(const Image& srcImg, Image& dstImg, const Point<uint32_t>& srcPt, const Point<uint32_t>& dstPt, const Size& size) {
|
||||
if (size.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!srcImg.valid()) {
|
||||
throw std::invalid_argument("invalid source for image copy");
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ SymbolInstance::SymbolInstance(Anchor& anchor,
|
||||
const float iconBoxScale,
|
||||
const float iconPadding,
|
||||
const SymbolPlacementType iconPlacement,
|
||||
const GlyphPositions& face,
|
||||
const GlyphPositionMap& positions,
|
||||
const IndexedSubfeature& indexedFeature,
|
||||
const std::size_t featureIndex_) :
|
||||
point(anchor.point),
|
||||
@@ -38,11 +38,11 @@ SymbolInstance::SymbolInstance(Anchor& anchor,
|
||||
iconQuad = getIconQuad(anchor, *shapedIcon, line, layout, layoutTextSize, iconPlacement, shapedTextOrientations.first);
|
||||
}
|
||||
if (shapedTextOrientations.first) {
|
||||
auto quads = getGlyphQuads(anchor, shapedTextOrientations.first, textBoxScale, line, layout, textPlacement, face);
|
||||
auto quads = getGlyphQuads(anchor, shapedTextOrientations.first, textBoxScale, line, layout, textPlacement, positions);
|
||||
glyphQuads.insert(glyphQuads.end(), quads.begin(), quads.end());
|
||||
}
|
||||
if (shapedTextOrientations.second) {
|
||||
auto quads = getGlyphQuads(anchor, shapedTextOrientations.second, textBoxScale, line, layout, textPlacement, face);
|
||||
auto quads = getGlyphQuads(anchor, shapedTextOrientations.second, textBoxScale, line, layout, textPlacement, positions);
|
||||
glyphQuads.insert(glyphQuads.end(), quads.begin(), quads.end());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
const float iconBoxScale,
|
||||
const float iconPadding,
|
||||
style::SymbolPlacementType iconPlacement,
|
||||
const GlyphPositions& face,
|
||||
const GlyphPositionMap&,
|
||||
const IndexedSubfeature&,
|
||||
const std::size_t featureIndex);
|
||||
|
||||
|
||||
@@ -175,7 +175,8 @@ bool SymbolLayout::hasSymbolInstances() const {
|
||||
return !symbolInstances.empty();
|
||||
}
|
||||
|
||||
void SymbolLayout::prepare(const GlyphMap& glyphs, const ImageMap& images) {
|
||||
void SymbolLayout::prepare(const GlyphMap& glyphMap, const GlyphPositions& glyphPositions,
|
||||
const ImageMap& imageMap, const ImagePositions& imagePositions) {
|
||||
float horizontalAlign = 0.5;
|
||||
float verticalAlign = 0.5;
|
||||
|
||||
@@ -220,12 +221,13 @@ void SymbolLayout::prepare(const GlyphMap& glyphs, const ImageMap& images) {
|
||||
const bool textAlongLine = layout.get<TextRotationAlignment>() == AlignmentType::Map &&
|
||||
layout.get<SymbolPlacement>() == SymbolPlacementType::Line;
|
||||
|
||||
auto glyphPositionsIt = glyphs.find(layout.get<TextFont>());
|
||||
if (glyphPositionsIt != glyphs.end()) {
|
||||
glyphAtlas = makeGlyphAtlas(glyphPositionsIt->second);
|
||||
}
|
||||
auto glyphMapIt = glyphMap.find(layout.get<TextFont>());
|
||||
const Glyphs& glyphs = glyphMapIt != glyphMap.end()
|
||||
? glyphMapIt->second : Glyphs();
|
||||
|
||||
imageAtlas = makeImageAtlas(images);
|
||||
auto glyphPositionsIt = glyphPositions.find(layout.get<TextFont>());
|
||||
const GlyphPositionMap& glyphPositionMap = glyphPositionsIt != glyphPositions.end()
|
||||
? glyphPositionsIt->second : GlyphPositionMap();
|
||||
|
||||
for (auto it = features.begin(); it != features.end(); ++it) {
|
||||
auto& feature = *it;
|
||||
@@ -236,42 +238,39 @@ void SymbolLayout::prepare(const GlyphMap& glyphs, const ImageMap& images) {
|
||||
|
||||
// if feature has text, shape the text
|
||||
if (feature.text) {
|
||||
auto glyphPositions = glyphs.find(layout.get<TextFont>());
|
||||
if (glyphPositions != glyphs.end()) { // If there are no glyphs available for this feature, skip shaping
|
||||
auto applyShaping = [&] (const std::u16string& text, WritingModeType writingMode) {
|
||||
const float oneEm = 24.0f;
|
||||
const Shaping result = getShaping(
|
||||
/* string */ text,
|
||||
/* maxWidth: ems */ layout.get<SymbolPlacement>() != SymbolPlacementType::Line ?
|
||||
layout.get<TextMaxWidth>() * oneEm : 0,
|
||||
/* lineHeight: ems */ layout.get<TextLineHeight>() * oneEm,
|
||||
/* horizontalAlign */ horizontalAlign,
|
||||
/* verticalAlign */ verticalAlign,
|
||||
/* justify */ justify,
|
||||
/* spacing: ems */ util::i18n::allowsLetterSpacing(*feature.text) ? layout.get<TextLetterSpacing>() * oneEm : 0.0f,
|
||||
/* translate */ Point<float>(layout.evaluate<TextOffset>(zoom, feature)[0] * oneEm, layout.evaluate<TextOffset>(zoom, feature)[1] * oneEm),
|
||||
/* verticalHeight */ oneEm,
|
||||
/* writingMode */ writingMode,
|
||||
/* bidirectional algorithm object */ bidi,
|
||||
/* glyphs */ glyphPositions->second);
|
||||
auto applyShaping = [&] (const std::u16string& text, WritingModeType writingMode) {
|
||||
const float oneEm = 24.0f;
|
||||
const Shaping result = getShaping(
|
||||
/* string */ text,
|
||||
/* maxWidth: ems */ layout.get<SymbolPlacement>() != SymbolPlacementType::Line ?
|
||||
layout.get<TextMaxWidth>() * oneEm : 0,
|
||||
/* lineHeight: ems */ layout.get<TextLineHeight>() * oneEm,
|
||||
/* horizontalAlign */ horizontalAlign,
|
||||
/* verticalAlign */ verticalAlign,
|
||||
/* justify */ justify,
|
||||
/* spacing: ems */ util::i18n::allowsLetterSpacing(*feature.text) ? layout.get<TextLetterSpacing>() * oneEm : 0.0f,
|
||||
/* translate */ Point<float>(layout.evaluate<TextOffset>(zoom, feature)[0] * oneEm, layout.evaluate<TextOffset>(zoom, feature)[1] * oneEm),
|
||||
/* verticalHeight */ oneEm,
|
||||
/* writingMode */ writingMode,
|
||||
/* bidirectional algorithm object */ bidi,
|
||||
/* glyphs */ glyphs);
|
||||
|
||||
return result;
|
||||
};
|
||||
return result;
|
||||
};
|
||||
|
||||
shapedTextOrientations.first = applyShaping(*feature.text, WritingModeType::Horizontal);
|
||||
shapedTextOrientations.first = applyShaping(*feature.text, WritingModeType::Horizontal);
|
||||
|
||||
if (util::i18n::allowsVerticalWritingMode(*feature.text) && textAlongLine) {
|
||||
shapedTextOrientations.second = applyShaping(util::i18n::verticalizePunctuation(*feature.text), WritingModeType::Vertical);
|
||||
}
|
||||
if (util::i18n::allowsVerticalWritingMode(*feature.text) && textAlongLine) {
|
||||
shapedTextOrientations.second = applyShaping(util::i18n::verticalizePunctuation(*feature.text), WritingModeType::Vertical);
|
||||
}
|
||||
}
|
||||
|
||||
// if feature has icon, get sprite atlas position
|
||||
if (feature.icon) {
|
||||
auto image = images.find(*feature.icon);
|
||||
if (image != images.end()) {
|
||||
auto image = imageMap.find(*feature.icon);
|
||||
if (image != imageMap.end()) {
|
||||
shapedIcon = PositionedIcon::shapeIcon(
|
||||
imageAtlas.positions.at(*feature.icon),
|
||||
imagePositions.at(*feature.icon),
|
||||
layout.evaluate<IconOffset>(zoom, feature),
|
||||
layout.evaluate<IconRotate>(zoom, feature) * util::DEG2RAD);
|
||||
if (image->second->sdf) {
|
||||
@@ -287,7 +286,7 @@ void SymbolLayout::prepare(const GlyphMap& glyphs, const ImageMap& images) {
|
||||
|
||||
// if either shapedText or icon position is present, add the feature
|
||||
if (shapedTextOrientations.first || shapedIcon) {
|
||||
addFeature(std::distance(features.begin(), it), feature, shapedTextOrientations, shapedIcon);
|
||||
addFeature(std::distance(features.begin(), it), feature, shapedTextOrientations, shapedIcon, glyphPositionMap);
|
||||
}
|
||||
|
||||
feature.geometry.clear();
|
||||
@@ -299,7 +298,8 @@ void SymbolLayout::prepare(const GlyphMap& glyphs, const ImageMap& images) {
|
||||
void SymbolLayout::addFeature(const std::size_t index,
|
||||
const SymbolFeature& feature,
|
||||
const std::pair<Shaping, Shaping>& shapedTextOrientations,
|
||||
optional<PositionedIcon> shapedIcon) {
|
||||
optional<PositionedIcon> shapedIcon,
|
||||
const GlyphPositionMap& glyphPositionMap) {
|
||||
const float minScale = 0.5f;
|
||||
const float glyphSize = 24.0f;
|
||||
|
||||
@@ -356,7 +356,7 @@ void SymbolLayout::addFeature(const std::size_t index,
|
||||
addToBuffers, symbolInstances.size(),
|
||||
textBoxScale, textPadding, textPlacement,
|
||||
iconBoxScale, iconPadding, iconPlacement,
|
||||
glyphAtlas.positions, indexedFeature, index);
|
||||
glyphPositionMap, indexedFeature, index);
|
||||
};
|
||||
|
||||
const auto& type = feature.getType();
|
||||
@@ -430,9 +430,6 @@ bool SymbolLayout::anchorIsTooClose(const std::u16string& text, const float repe
|
||||
std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile) {
|
||||
auto bucket = std::make_unique<SymbolBucket>(layout, layerPaintProperties, textSize, iconSize, zoom, sdfIcons, iconsNeedLinear);
|
||||
|
||||
bucket->text.atlasImage = glyphAtlas.image.clone();
|
||||
bucket->icon.atlasImage = imageAtlas.image.clone();
|
||||
|
||||
// Calculate which labels can be shown and when they can be shown and
|
||||
// create the bufers used for rendering.
|
||||
|
||||
|
||||
@@ -33,7 +33,8 @@ public:
|
||||
ImageDependencies&,
|
||||
GlyphDependencies&);
|
||||
|
||||
void prepare(const GlyphMap& glyphs, const ImageMap& icons);
|
||||
void prepare(const GlyphMap&, const GlyphPositions&,
|
||||
const ImageMap&, const ImagePositions&);
|
||||
|
||||
std::unique_ptr<SymbolBucket> place(CollisionTile&);
|
||||
|
||||
@@ -53,7 +54,8 @@ private:
|
||||
void addFeature(const size_t,
|
||||
const SymbolFeature&,
|
||||
const std::pair<Shaping, Shaping>& shapedTextOrientations,
|
||||
optional<PositionedIcon> shapedIcon);
|
||||
optional<PositionedIcon> shapedIcon,
|
||||
const GlyphPositionMap&);
|
||||
|
||||
bool anchorIsTooClose(const std::u16string& text, const float repeatDistance, const Anchor&);
|
||||
std::map<std::u16string, std::vector<Anchor>> compareText;
|
||||
@@ -93,9 +95,6 @@ private:
|
||||
std::vector<SymbolInstance> symbolInstances;
|
||||
std::vector<SymbolFeature> features;
|
||||
|
||||
GlyphAtlas glyphAtlas;
|
||||
ImageAtlas imageAtlas;
|
||||
|
||||
BiDi bidi; // Consider moving this up to geometry tile worker to reduce reinstantiation costs; use of BiDi/ubiditransform object must be constrained to one thread
|
||||
};
|
||||
|
||||
|
||||
@@ -39,14 +39,12 @@ void SymbolBucket::upload(gl::Context& context) {
|
||||
if (hasTextData()) {
|
||||
text.vertexBuffer = context.createVertexBuffer(std::move(text.vertices));
|
||||
text.indexBuffer = context.createIndexBuffer(std::move(text.triangles));
|
||||
text.atlasTexture = context.createTexture(std::move(text.atlasImage), 0);
|
||||
textSizeBinder->upload(context);
|
||||
}
|
||||
|
||||
if (hasIconData()) {
|
||||
icon.vertexBuffer = context.createVertexBuffer(std::move(icon.vertices));
|
||||
icon.indexBuffer = context.createIndexBuffer(std::move(icon.triangles));
|
||||
icon.atlasTexture = context.createTexture(std::move(icon.atlasImage), 0);
|
||||
iconSizeBinder->upload(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,11 +46,9 @@ public:
|
||||
gl::VertexVector<SymbolLayoutVertex> vertices;
|
||||
gl::IndexVector<gl::Triangles> triangles;
|
||||
gl::SegmentVector<SymbolTextAttributes> segments;
|
||||
AlphaImage atlasImage;
|
||||
|
||||
optional<gl::VertexBuffer<SymbolLayoutVertex>> vertexBuffer;
|
||||
optional<gl::IndexBuffer<gl::Triangles>> indexBuffer;
|
||||
optional<gl::Texture> atlasTexture;
|
||||
} text;
|
||||
|
||||
std::unique_ptr<SymbolSizeBinder> iconSizeBinder;
|
||||
@@ -63,7 +61,6 @@ public:
|
||||
|
||||
optional<gl::VertexBuffer<SymbolLayoutVertex>> vertexBuffer;
|
||||
optional<gl::IndexBuffer<gl::Triangles>> indexBuffer;
|
||||
optional<gl::Texture> atlasTexture;
|
||||
} icon;
|
||||
|
||||
struct CollisionBoxBuffer {
|
||||
|
||||
@@ -23,31 +23,17 @@ ImageAtlas makeImageAtlas(const ImageMap& images) {
|
||||
options.autoResize = true;
|
||||
mapbox::ShelfPack pack(0, 0, options);
|
||||
|
||||
std::vector<const style::Image::Impl*> pointers;
|
||||
pointers.reserve(images.size());
|
||||
|
||||
std::vector<mapbox::Bin> bins;
|
||||
bins.reserve(images.size());
|
||||
|
||||
for (const auto& entry : images) {
|
||||
const style::Image::Impl& image = *entry.second;
|
||||
pointers.emplace_back(&image);
|
||||
bins.emplace_back(pointers.size() - 1,
|
||||
image.image.size.width + 2 * padding,
|
||||
image.image.size.height + 2 * padding);
|
||||
}
|
||||
|
||||
mapbox::ShelfPack::PackOptions packOptions;
|
||||
packOptions.inPlace = true;
|
||||
pack.pack(bins, packOptions);
|
||||
const mapbox::Bin& bin = *pack.packOne(-1,
|
||||
image.image.size.width + 2 * padding,
|
||||
image.image.size.height + 2 * padding);
|
||||
|
||||
result.image = PremultipliedImage({
|
||||
static_cast<uint32_t>(pack.width()),
|
||||
static_cast<uint32_t>(pack.height())
|
||||
});
|
||||
|
||||
for (const auto& bin : bins) {
|
||||
const style::Image::Impl& image = *pointers.at(bin.id);
|
||||
result.image.resize({
|
||||
static_cast<uint32_t>(pack.width()),
|
||||
static_cast<uint32_t>(pack.height())
|
||||
});
|
||||
|
||||
PremultipliedImage::copy(image.image,
|
||||
result.image,
|
||||
@@ -62,6 +48,12 @@ ImageAtlas makeImageAtlas(const ImageMap& images) {
|
||||
ImagePosition { bin, image });
|
||||
}
|
||||
|
||||
// pack.shrink();
|
||||
// result.image.resize({
|
||||
// static_cast<uint32_t>(pack.width()),
|
||||
// static_cast<uint32_t>(pack.height())
|
||||
// });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,14 +119,7 @@ optional<ImagePosition> ImageManager::getPattern(const std::string& id) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!atlasImage.valid()) {
|
||||
atlasImage = PremultipliedImage(getPixelSize());
|
||||
atlasImage.fill(0);
|
||||
} else if (atlasImage.size != getPixelSize()) {
|
||||
PremultipliedImage newImage(getPixelSize());
|
||||
PremultipliedImage::copy(atlasImage, newImage, { 0, 0 }, { 0, 0 }, atlasImage.size);
|
||||
atlasImage = std::move(newImage);
|
||||
}
|
||||
atlasImage.resize(getPixelSize());
|
||||
|
||||
const PremultipliedImage& src = image->image;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <mbgl/programs/symbol_program.hpp>
|
||||
#include <mbgl/programs/collision_box_program.hpp>
|
||||
#include <mbgl/util/math.hpp>
|
||||
#include <mbgl/tile/tile.hpp>
|
||||
#include <mbgl/tile/geometry_tile.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@@ -62,6 +62,9 @@ void Painter::renderSymbol(PaintParameters& parameters,
|
||||
);
|
||||
};
|
||||
|
||||
assert(dynamic_cast<GeometryTile*>(&tile.tile));
|
||||
GeometryTile& geometryTile = static_cast<GeometryTile&>(tile.tile);
|
||||
|
||||
if (bucket.hasIconData()) {
|
||||
auto values = layer.iconPropertyValues(layout);
|
||||
auto paintPropertyValues = layer.iconPaintProperties();
|
||||
@@ -69,11 +72,11 @@ void Painter::renderSymbol(PaintParameters& parameters,
|
||||
const bool iconScaled = layout.get<IconSize>().constantOr(1.0) != 1.0 || bucket.iconsNeedLinear;
|
||||
const bool iconTransformed = values.rotationAlignment == AlignmentType::Map || state.getPitch() != 0;
|
||||
|
||||
context.bindTexture(*bucket.icon.atlasTexture, 0,
|
||||
context.bindTexture(*geometryTile.iconAtlasTexture, 0,
|
||||
bucket.sdfIcons || state.isChanging() || iconScaled || iconTransformed
|
||||
? gl::TextureFilter::Linear : gl::TextureFilter::Nearest);
|
||||
|
||||
const Size texsize = bucket.icon.atlasTexture->size;
|
||||
const Size texsize = geometryTile.iconAtlasTexture->size;
|
||||
|
||||
if (bucket.sdfIcons) {
|
||||
if (values.hasHalo) {
|
||||
@@ -107,12 +110,12 @@ void Painter::renderSymbol(PaintParameters& parameters,
|
||||
}
|
||||
|
||||
if (bucket.hasTextData()) {
|
||||
context.bindTexture(*bucket.text.atlasTexture, 0, gl::TextureFilter::Linear);
|
||||
context.bindTexture(*geometryTile.glyphAtlasTexture, 0, gl::TextureFilter::Linear);
|
||||
|
||||
auto values = layer.textPropertyValues(layout);
|
||||
auto paintPropertyValues = layer.textPaintProperties();
|
||||
|
||||
const Size texsize = bucket.text.atlasTexture->size;
|
||||
const Size texsize = geometryTile.glyphAtlasTexture->size;
|
||||
|
||||
if (values.hasHalo) {
|
||||
draw(parameters.programs.symbolGlyph,
|
||||
|
||||
@@ -6,57 +6,58 @@ namespace mbgl {
|
||||
|
||||
static constexpr uint32_t padding = 1;
|
||||
|
||||
GlyphAtlas makeGlyphAtlas(const Glyphs& glyphs) {
|
||||
GlyphAtlas makeGlyphAtlas(const GlyphMap& glyphs) {
|
||||
GlyphAtlas result;
|
||||
|
||||
mapbox::ShelfPack::ShelfPackOptions options;
|
||||
options.autoResize = true;
|
||||
mapbox::ShelfPack pack(0, 0, options);
|
||||
|
||||
std::vector<mapbox::Bin> bins;
|
||||
bins.reserve(glyphs.size());
|
||||
for (const auto& glyphMapEntry : glyphs) {
|
||||
const FontStack& fontStack = glyphMapEntry.first;
|
||||
GlyphPositionMap& positions = result.positions[fontStack];
|
||||
|
||||
for (const auto& entry : glyphs) {
|
||||
if (entry.second && (*entry.second)->bitmap.valid()) {
|
||||
const Glyph& glyph = **entry.second;
|
||||
bins.emplace_back(glyph.id,
|
||||
glyph.bitmap.size.width + 2 * padding,
|
||||
glyph.bitmap.size.height + 2 * padding);
|
||||
for (const auto& entry : glyphMapEntry.second) {
|
||||
if (entry.second && (*entry.second)->bitmap.valid()) {
|
||||
const Glyph& glyph = **entry.second;
|
||||
|
||||
const mapbox::Bin& bin = *pack.packOne(-1,
|
||||
glyph.bitmap.size.width + 2 * padding,
|
||||
glyph.bitmap.size.height + 2 * padding);
|
||||
|
||||
result.image.resize({
|
||||
static_cast<uint32_t>(pack.width()),
|
||||
static_cast<uint32_t>(pack.height())
|
||||
});
|
||||
|
||||
AlphaImage::copy(glyph.bitmap,
|
||||
result.image,
|
||||
{ 0, 0 },
|
||||
{
|
||||
bin.x + padding,
|
||||
bin.y + padding
|
||||
},
|
||||
glyph.bitmap.size);
|
||||
|
||||
positions.emplace(glyph.id,
|
||||
GlyphPosition {
|
||||
Rect<uint16_t> {
|
||||
static_cast<uint16_t>(bin.x),
|
||||
static_cast<uint16_t>(bin.y),
|
||||
static_cast<uint16_t>(bin.w),
|
||||
static_cast<uint16_t>(bin.h)
|
||||
},
|
||||
glyph.metrics
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mapbox::ShelfPack::PackOptions packOptions;
|
||||
packOptions.inPlace = true;
|
||||
pack.pack(bins, packOptions);
|
||||
|
||||
result.image = AlphaImage({
|
||||
static_cast<uint32_t>(pack.width()),
|
||||
static_cast<uint32_t>(pack.height())
|
||||
});
|
||||
|
||||
for (const auto& bin : bins) {
|
||||
const Glyph& glyph = **glyphs.at(bin.id);
|
||||
|
||||
AlphaImage::copy(glyph.bitmap,
|
||||
result.image,
|
||||
{ 0, 0 },
|
||||
{
|
||||
bin.x + padding,
|
||||
bin.y + padding
|
||||
},
|
||||
glyph.bitmap.size);
|
||||
|
||||
result.positions.emplace(glyph.id,
|
||||
GlyphPosition {
|
||||
Rect<uint16_t> {
|
||||
static_cast<uint16_t>(bin.x),
|
||||
static_cast<uint16_t>(bin.y),
|
||||
static_cast<uint16_t>(bin.w),
|
||||
static_cast<uint16_t>(bin.h)
|
||||
},
|
||||
glyph.metrics
|
||||
});
|
||||
}
|
||||
// pack.shrink();
|
||||
// result.image.resize({
|
||||
// static_cast<uint32_t>(pack.width()),
|
||||
// static_cast<uint32_t>(pack.height())
|
||||
// });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ struct GlyphPosition {
|
||||
GlyphMetrics metrics;
|
||||
};
|
||||
|
||||
using GlyphPositions = std::map<GlyphID, GlyphPosition>;
|
||||
using GlyphPositionMap = std::map<GlyphID, GlyphPosition>;
|
||||
using GlyphPositions = std::map<FontStack, GlyphPositionMap>;
|
||||
|
||||
class GlyphAtlas {
|
||||
public:
|
||||
@@ -19,6 +20,6 @@ public:
|
||||
GlyphPositions positions;
|
||||
};
|
||||
|
||||
GlyphAtlas makeGlyphAtlas(const Glyphs&);
|
||||
GlyphAtlas makeGlyphAtlas(const GlyphMap&);
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -307,18 +307,18 @@ SymbolQuads getGlyphQuads(Anchor& anchor,
|
||||
const GeometryCoordinates& line,
|
||||
const SymbolLayoutProperties::Evaluated& layout,
|
||||
const style::SymbolPlacementType placement,
|
||||
const GlyphPositions& face) {
|
||||
const GlyphPositionMap& positions) {
|
||||
const float textRotate = layout.get<TextRotate>() * util::DEG2RAD;
|
||||
const bool keepUpright = layout.get<TextKeepUpright>();
|
||||
|
||||
SymbolQuads quads;
|
||||
|
||||
for (const PositionedGlyph &positionedGlyph: shapedText.positionedGlyphs) {
|
||||
auto face_it = face.find(positionedGlyph.glyph);
|
||||
if (face_it == face.end())
|
||||
auto positionsIt = positions.find(positionedGlyph.glyph);
|
||||
if (positionsIt == positions.end())
|
||||
continue;
|
||||
|
||||
const GlyphPosition& glyph = face_it->second;
|
||||
const GlyphPosition& glyph = positionsIt->second;
|
||||
const Rect<uint16_t>& rect = glyph.rect;
|
||||
const float centerX = (positionedGlyph.x + glyph.metrics.advance / 2.0f) * boxScale;
|
||||
|
||||
|
||||
@@ -65,6 +65,6 @@ SymbolQuads getGlyphQuads(Anchor& anchor,
|
||||
const GeometryCoordinates& line,
|
||||
const style::SymbolLayoutProperties::Evaluated&,
|
||||
style::SymbolPlacementType placement,
|
||||
const GlyphPositions& face);
|
||||
const GlyphPositionMap& positions);
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <mbgl/renderer/layers/render_custom_layer.hpp>
|
||||
#include <mbgl/renderer/layers/render_symbol_layer.hpp>
|
||||
#include <mbgl/renderer/buckets/symbol_bucket.hpp>
|
||||
#include <mbgl/text/glyph_atlas.hpp>
|
||||
#include <mbgl/renderer/image_atlas.hpp>
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/geometry/feature_index.hpp>
|
||||
#include <mbgl/text/collision_tile.hpp>
|
||||
@@ -135,6 +137,12 @@ void GeometryTile::onPlacement(PlacementResult result) {
|
||||
}
|
||||
symbolBuckets = std::move(result.symbolBuckets);
|
||||
collisionTile = std::move(result.collisionTile);
|
||||
if (result.glyphAtlasImage) {
|
||||
glyphAtlasImage = std::move(*result.glyphAtlasImage);
|
||||
}
|
||||
if (result.iconAtlasImage) {
|
||||
iconAtlasImage = std::move(*result.iconAtlasImage);
|
||||
}
|
||||
observer->onTileChanged(*this);
|
||||
}
|
||||
|
||||
@@ -175,6 +183,16 @@ void GeometryTile::upload(gl::Context& context) {
|
||||
for (auto& entry : symbolBuckets) {
|
||||
upload(*entry.second);
|
||||
}
|
||||
|
||||
if (glyphAtlasImage) {
|
||||
glyphAtlasTexture = context.createTexture(*glyphAtlasImage, 0);
|
||||
glyphAtlasImage = {};
|
||||
}
|
||||
|
||||
if (iconAtlasImage) {
|
||||
iconAtlasTexture = context.createTexture(*iconAtlasImage, 0);
|
||||
iconAtlasImage = {};
|
||||
}
|
||||
}
|
||||
|
||||
Bucket* GeometryTile::getBucket(const Layer::Impl& layer) const {
|
||||
|
||||
@@ -23,6 +23,8 @@ class RenderStyle;
|
||||
class RenderLayer;
|
||||
class SourceQueryOptions;
|
||||
class TileParameters;
|
||||
class GlyphAtlas;
|
||||
class ImageAtlas;
|
||||
|
||||
class GeometryTile : public Tile, public GlyphRequestor, ImageRequestor {
|
||||
public:
|
||||
@@ -47,6 +49,9 @@ public:
|
||||
void upload(gl::Context&) override;
|
||||
Bucket* getBucket(const style::Layer::Impl&) const override;
|
||||
|
||||
Size bindGlyphAtlas(gl::Context&);
|
||||
Size bindIconAtlas(gl::Context&);
|
||||
|
||||
void queryRenderedFeatures(
|
||||
std::unordered_map<std::string, std::vector<Feature>>& result,
|
||||
const GeometryCoordinates& queryGeometry,
|
||||
@@ -73,6 +78,8 @@ public:
|
||||
public:
|
||||
std::unordered_map<std::string, std::shared_ptr<Bucket>> symbolBuckets;
|
||||
std::unique_ptr<CollisionTile> collisionTile;
|
||||
optional<AlphaImage> glyphAtlasImage;
|
||||
optional<PremultipliedImage> iconAtlasImage;
|
||||
uint64_t correlationID;
|
||||
};
|
||||
void onPlacement(PlacementResult);
|
||||
@@ -106,10 +113,17 @@ private:
|
||||
std::unique_ptr<FeatureIndex> featureIndex;
|
||||
std::unique_ptr<const GeometryTileData> data;
|
||||
|
||||
optional<AlphaImage> glyphAtlasImage;
|
||||
optional<PremultipliedImage> iconAtlasImage;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<Bucket>> symbolBuckets;
|
||||
std::unique_ptr<CollisionTile> collisionTile;
|
||||
|
||||
util::Throttler placementThrottler;
|
||||
|
||||
public:
|
||||
optional<gl::Texture> glyphAtlasTexture;
|
||||
optional<gl::Texture> iconAtlasTexture;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -386,14 +386,24 @@ void GeometryTileWorker::attemptPlacement() {
|
||||
auto collisionTile = std::make_unique<CollisionTile>(*placementConfig);
|
||||
std::unordered_map<std::string, std::shared_ptr<Bucket>> buckets;
|
||||
|
||||
optional<AlphaImage> glyphAtlasImage;
|
||||
optional<PremultipliedImage> iconAtlasImage;
|
||||
|
||||
for (auto& symbolLayout : symbolLayouts) {
|
||||
if (obsolete) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (symbolLayout->state == SymbolLayout::Pending) {
|
||||
symbolLayout->prepare(glyphMap, imageMap);
|
||||
GlyphAtlas glyphAtlas = makeGlyphAtlas(glyphMap);
|
||||
ImageAtlas imageAtlas = makeImageAtlas(imageMap);
|
||||
|
||||
symbolLayout->prepare(glyphMap, glyphAtlas.positions,
|
||||
imageMap, imageAtlas.positions);
|
||||
symbolLayout->state = SymbolLayout::Placed;
|
||||
|
||||
glyphAtlasImage = std::move(glyphAtlas.image);
|
||||
iconAtlasImage = std::move(imageAtlas.image);
|
||||
}
|
||||
|
||||
if (!symbolLayout->hasSymbolInstances()) {
|
||||
@@ -409,6 +419,8 @@ void GeometryTileWorker::attemptPlacement() {
|
||||
parent.invoke(&GeometryTile::onPlacement, GeometryTile::PlacementResult {
|
||||
std::move(buckets),
|
||||
std::move(collisionTile),
|
||||
std::move(glyphAtlasImage),
|
||||
std::move(iconAtlasImage),
|
||||
correlationID
|
||||
});
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ TEST(AnnotationTile, Issue8289) {
|
||||
// Simulate layout and placement of a symbol layer.
|
||||
tile.onLayout(GeometryTile::LayoutResult {
|
||||
{},
|
||||
std::make_unique<FeatureIndex>(),
|
||||
std::move(data),
|
||||
0
|
||||
std::make_unique<FeatureIndex>(),
|
||||
std::move(data),
|
||||
0
|
||||
});
|
||||
|
||||
auto collisionTile = std::make_unique<CollisionTile>(PlacementConfig());
|
||||
@@ -69,16 +69,18 @@ TEST(AnnotationTile, Issue8289) {
|
||||
|
||||
tile.onPlacement(GeometryTile::PlacementResult {
|
||||
{},
|
||||
std::move(collisionTile),
|
||||
0
|
||||
std::move(collisionTile),
|
||||
{},
|
||||
{},
|
||||
0
|
||||
});
|
||||
|
||||
// Simulate a second layout with empty data.
|
||||
tile.onLayout(GeometryTile::LayoutResult {
|
||||
{},
|
||||
std::make_unique<FeatureIndex>(),
|
||||
std::make_unique<AnnotationTileData>(),
|
||||
0
|
||||
std::make_unique<FeatureIndex>(),
|
||||
std::make_unique<AnnotationTileData>(),
|
||||
0
|
||||
});
|
||||
|
||||
std::unordered_map<std::string, std::vector<Feature>> result;
|
||||
|
||||
@@ -81,6 +81,8 @@ TEST(VectorTile, Issue7615) {
|
||||
symbolBucket
|
||||
}},
|
||||
nullptr,
|
||||
{},
|
||||
{},
|
||||
0
|
||||
});
|
||||
|
||||
|
||||
@@ -86,33 +86,49 @@ TEST(Image, WebPTile) {
|
||||
}
|
||||
#endif // !defined(__ANDROID__) && !defined(__APPLE__) && !defined(QT_IMAGE_DECODERS)
|
||||
|
||||
TEST(Image, Resize) {
|
||||
AlphaImage image({0, 0});
|
||||
|
||||
image.resize({1, 1});
|
||||
EXPECT_EQ(image.size, Size({1, 1}));
|
||||
|
||||
image.fill(100);
|
||||
image.resize({2, 1});
|
||||
EXPECT_EQ(image.size, Size({2, 1}));
|
||||
EXPECT_EQ(image.data[0], 100);
|
||||
EXPECT_EQ(image.data[1], 0);
|
||||
|
||||
image.resize({0, 0});
|
||||
EXPECT_EQ(image.size, Size({0, 0}));
|
||||
}
|
||||
|
||||
TEST(Image, Copy) {
|
||||
PremultipliedImage src5({5, 5});
|
||||
PremultipliedImage dst5({5, 5});
|
||||
PremultipliedImage src10({10, 10});
|
||||
PremultipliedImage dst10({10, 10});
|
||||
|
||||
EXPECT_THROW(PremultipliedImage::copy(src5, dst10, {0, 0}, {0, 0}, {6, 0}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src5, dst10, {0, 0}, {0, 0}, {0, 6}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src5, dst10, {1, 1}, {0, 0}, {5, 0}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src5, dst10, {1, 1}, {0, 0}, {0, 5}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src5, dst10, {0, 0}, {0, 0}, {6, 1}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src5, dst10, {0, 0}, {0, 0}, {1, 6}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src5, dst10, {1, 1}, {0, 0}, {5, 1}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src5, dst10, {1, 1}, {0, 0}, {1, 5}), std::out_of_range);
|
||||
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst5, {0, 0}, {0, 0}, {6, 0}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst5, {0, 0}, {0, 0}, {0, 6}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst5, {0, 0}, {1, 1}, {5, 0}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst5, {0, 0}, {1, 1}, {0, 5}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst5, {0, 0}, {0, 0}, {6, 1}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst5, {0, 0}, {0, 0}, {1, 6}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst5, {0, 0}, {1, 1}, {5, 1}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst5, {0, 0}, {1, 1}, {1, 5}), std::out_of_range);
|
||||
|
||||
const uint32_t max = std::numeric_limits<uint32_t>::max();
|
||||
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {max, 0}, {0, 0}, {1, 0}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {0, max}, {0, 0}, {0, 1}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {0, 0}, {max, 0}, {1, 0}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {0, 0}, {0, max}, {0, 1}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {max, 0}, {0, 0}, {1, 1}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {0, max}, {0, 0}, {1, 1}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {0, 0}, {max, 0}, {1, 1}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {0, 0}, {0, max}, {1, 1}), std::out_of_range);
|
||||
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {1, 0}, {0, 0}, {max, 0}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {0, 1}, {0, 0}, {0, max}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {0, 0}, {1, 0}, {max, 0}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {0, 0}, {0, 1}, {0, max}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {1, 0}, {0, 0}, {max, 1}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {0, 1}, {0, 0}, {1, max}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {0, 0}, {1, 0}, {max, 1}), std::out_of_range);
|
||||
EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {0, 0}, {0, 1}, {1, max}), std::out_of_range);
|
||||
}
|
||||
|
||||
TEST(Image, Move) {
|
||||
|
||||
Reference in New Issue
Block a user