#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { class FileSource; class GlyphPBF; class GlyphAtlasObserver; namespace gl { class Context; } // namespace gl class GlyphAtlas : public util::noncopyable { public: GlyphAtlas(Size, FileSource&); ~GlyphAtlas(); util::exclusive getGlyphSet(const FontStack&); // Returns true if the set of GlyphRanges are available and parsed or false // if they are not. For the missing ranges, a request on the FileSource is // made and when the glyph if finally parsed, it gets added to the respective // GlyphSet and a signal is emitted to notify the observers. This method // can be called from any thread. bool hasGlyphRanges(const FontStack&, const GlyphRangeSet&); void setURL(const std::string &url) { glyphURL = url; } std::string getURL() const { return glyphURL; } void setObserver(GlyphAtlasObserver* observer); void addGlyphs(uintptr_t tileUID, const std::u16string& text, const FontStack&, const util::exclusive&, GlyphPositions&); void removeGlyphs(uintptr_t tileUID); // Binds the atlas texture to the GPU, and uploads data if it is out of date. void bind(gl::Context&, gl::TextureUnit unit); // Uploads the texture to the GPU to be available when we need it. This is a lazy operation; // the texture is only bound when the data is out of date (=dirty). void upload(gl::Context&, gl::TextureUnit unit); Size getSize() const; private: void requestGlyphRange(const FontStack&, const GlyphRange&); Rect addGlyph(uintptr_t tileID, const FontStack&, const SDFGlyph&); FileSource& fileSource; std::string glyphURL; struct GlyphValue { GlyphValue(Rect rect_, uintptr_t id) : rect(std::move(rect_)), ids({ id }) {} Rect rect; std::unordered_set ids; }; struct Entry { std::map ranges; GlyphSet glyphSet; std::map glyphValues; }; std::unordered_map entries; std::mutex mutex; util::WorkQueue workQueue; GlyphAtlasObserver* observer = nullptr; BinPack bin; AlphaImage image; std::atomic dirty; mbgl::optional texture; }; } // namespace mbgl