Move Worker to Style

This ensures that worker tasks are entirely complete by the
time the style is destructed, and enables us to pass Style&
rather than a shared pointer.
This commit is contained in:
John Firebaugh
2015-04-23 17:05:37 -07:00
parent 4ccf246c10
commit 0c280adebc
7 changed files with 13 additions and 14 deletions

View File

@@ -37,7 +37,6 @@ MapContext::MapContext(uv_loop_t* loop, View& view_, FileSource& fileSource, Map
envScope(env, ThreadType::Map, "Map"),
updated(static_cast<UpdateType>(Update::Nothing)),
asyncUpdate(util::make_unique<uv::async>(loop, [this] { update(); })),
workers(util::make_unique<Worker>(4)),
glyphStore(util::make_unique<GlyphStore>(env)),
glyphAtlas(util::make_unique<GlyphAtlas>(1024, 1024)),
spriteAtlas(util::make_unique<SpriteAtlas>(512, 512)),
@@ -163,7 +162,7 @@ void MapContext::updateTiles() {
assert(Environment::currentlyOn(ThreadType::Map));
if (!style) return;
for (const auto& source : style->sources) {
source->update(data, transformState, *workers, style, *glyphAtlas, *glyphStore, *spriteAtlas,
source->update(data, transformState, style, *glyphAtlas, *glyphStore, *spriteAtlas,
getSprite(), *texturePool, [this]() {
assert(Environment::currentlyOn(ThreadType::Map));
triggerUpdate();

View File

@@ -77,7 +77,6 @@ private:
UpdateType updated { static_cast<UpdateType>(Update::Nothing) };
std::unique_ptr<uv::async> asyncUpdate;
std::unique_ptr<Worker> workers;
std::unique_ptr<GlyphStore> glyphStore;
std::unique_ptr<GlyphAtlas> glyphAtlas;
std::unique_ptr<SpriteAtlas> spriteAtlas;

View File

@@ -20,6 +20,7 @@
#include <mbgl/map/vector_tile_data.hpp>
#include <mbgl/map/raster_tile_data.hpp>
#include <mbgl/map/live_tile_data.hpp>
#include <mbgl/style/style.hpp>
#include <algorithm>
@@ -226,7 +227,6 @@ TileData::State Source::hasTile(const TileID& id) {
TileData::State Source::addTile(MapData& data,
const TransformState& transformState,
Worker& worker,
util::ptr<Style> style,
GlyphAtlas& glyphAtlas,
GlyphStore& glyphStore,
@@ -269,15 +269,15 @@ TileData::State Source::addTile(MapData& data,
new_tile.data =
std::make_shared<VectorTileData>(normalized_id, data.transform.getMaxZoom(), style, glyphAtlas,
glyphStore, spriteAtlas, sprite, info);
new_tile.data->request(worker, transformState.getPixelRatio(), callback);
new_tile.data->request(style->workers, transformState.getPixelRatio(), callback);
} else if (info.type == SourceType::Raster) {
new_tile.data = std::make_shared<RasterTileData>(normalized_id, texturePool, info);
new_tile.data->request(worker, transformState.getPixelRatio(), callback);
new_tile.data->request(style->workers, transformState.getPixelRatio(), callback);
} else if (info.type == SourceType::Annotations) {
new_tile.data = std::make_shared<LiveTileData>(normalized_id, data.annotationManager,
data.transform.getMaxZoom(), style, glyphAtlas,
glyphStore, spriteAtlas, sprite, info);
new_tile.data->reparse(worker, callback);
new_tile.data->reparse(style->workers, callback);
} else {
throw std::runtime_error("source type not implemented");
}
@@ -368,7 +368,6 @@ bool Source::findLoadedParent(const TileID& id, int32_t minCoveringZoom, std::fo
void Source::update(MapData& data,
const TransformState& transformState,
Worker& worker,
util::ptr<Style> style,
GlyphAtlas& glyphAtlas,
GlyphStore& glyphStore,
@@ -394,7 +393,7 @@ void Source::update(MapData& data,
// Add existing child/parent tiles if the actual tile is not yet loaded
for (const auto& id : required) {
const TileData::State state = addTile(data, transformState, worker, style, glyphAtlas, glyphStore,
const TileData::State state = addTile(data, transformState, style, glyphAtlas, glyphStore,
spriteAtlas, sprite, texturePool, id, callback);
if (state != TileData::State::parsed) {

View File

@@ -22,7 +22,6 @@ namespace mbgl {
class MapData;
class Environment;
class Worker;
class GlyphAtlas;
class GlyphStore;
class SpriteAtlas;
@@ -65,7 +64,6 @@ public:
void load(MapData&, Environment&, std::function<void()> callback);
void update(MapData&,
const TransformState&,
Worker&,
util::ptr<Style>,
GlyphAtlas&,
GlyphStore&,
@@ -97,7 +95,6 @@ private:
TileData::State addTile(MapData&,
const TransformState&,
Worker&,
util::ptr<Style>,
GlyphAtlas&,
GlyphStore&,

View File

@@ -1,7 +1,6 @@
#include <mbgl/map/tile_parser.hpp>
#include <mbgl/map/vector_tile_data.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/style_layer.hpp>
#include <mbgl/map/source.hpp>
#include <mbgl/renderer/fill_bucket.hpp>
@@ -10,6 +9,7 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/text/collision.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/style/style.hpp>
#include <locale>

View File

@@ -17,7 +17,8 @@
namespace mbgl {
Style::Style()
: mtx(util::make_unique<uv::rwlock>()) {
: mtx(util::make_unique<uv::rwlock>()),
workers(4) {
}
// Note: This constructor is seemingly empty, but we need to declare it anyway

View File

@@ -8,6 +8,7 @@
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/worker.hpp>
#include <cstdint>
#include <string>
@@ -44,6 +45,9 @@ private:
PropertyTransition defaultTransition;
std::unique_ptr<uv::rwlock> mtx;
ZoomHistory zoomHistory;
public:
Worker workers;
};
}