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

Commit

Permalink
Move Worker to Style
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jfirebaugh committed Apr 28, 2015
1 parent 2bfd1cf commit 3c10829
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/mbgl/map/map_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/mbgl/map/map_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class MapContext {
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;
Expand Down
11 changes: 5 additions & 6 deletions src/mbgl/map/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions src/mbgl/map/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace mbgl {

class MapData;
class Environment;
class Worker;
class GlyphAtlas;
class GlyphStore;
class SpriteAtlas;
Expand Down Expand Up @@ -65,7 +64,6 @@ class Source : public std::enable_shared_from_this<Source>, private util::noncop
void load(MapData&, Environment&, std::function<void()> callback);
void update(MapData&,
const TransformState&,
Worker&,
util::ptr<Style>,
GlyphAtlas&,
GlyphStore&,
Expand Down Expand Up @@ -97,7 +95,6 @@ class Source : public std::enable_shared_from_this<Source>, private util::noncop

TileData::State addTile(MapData&,
const TransformState&,
Worker&,
util::ptr<Style>,
GlyphAtlas&,
GlyphStore&,
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/map/tile_parser.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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>

Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/style/style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -44,6 +45,9 @@ class Style : public util::noncopyable {
PropertyTransition defaultTransition;
std::unique_ptr<uv::rwlock> mtx;
ZoomHistory zoomHistory;

public:
Worker workers;
};

}
Expand Down

0 comments on commit 3c10829

Please sign in to comment.