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

Commit

Permalink
[core] Eliminate MapData
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Apr 15, 2016
1 parent 9d18d65 commit 1ee0055
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 111 deletions.
3 changes: 2 additions & 1 deletion src/mbgl/annotation/annotation_tile.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <mbgl/annotation/annotation_tile.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/map/map_data.hpp>
#include <mbgl/storage/file_source.hpp>

#include <utility>

namespace mbgl {
Expand Down
92 changes: 54 additions & 38 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <mbgl/map/view.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/map/map_data.hpp>
#include <mbgl/annotation/point_annotation.hpp>
#include <mbgl/annotation/shape_annotation.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/style_layer.hpp>
#include <mbgl/style/property_transition.hpp>
Expand Down Expand Up @@ -49,13 +49,17 @@ class Map::Impl : public Style::Observer {
RenderState renderState = RenderState::never;
Transform transform;

std::unique_ptr<MapData> dataPtr;
MapData& data;
const MapMode mode;
const GLContextMode contextMode;
const float pixelRatio;

MapDebugOptions debugOptions { MapDebugOptions::NoDebug };

gl::GLObjectStore glObjectStore;
Update updateFlags = Update::Nothing;
util::AsyncTask asyncUpdate;

std::unique_ptr<AnnotationManager> annotationManager;
std::unique_ptr<gl::TexturePool> texturePool;
std::unique_ptr<Painter> painter;
std::unique_ptr<Style> style;
Expand All @@ -82,9 +86,11 @@ Map::Impl::Impl(View& view_, FileSource& fileSource_, MapMode mode_, GLContextMo
: view(view_),
fileSource(fileSource_),
transform(view, constrainMode_),
dataPtr(std::make_unique<MapData>(mode_, contextMode_, view_.getPixelRatio())),
data(*dataPtr),
mode(mode_),
contextMode(contextMode_),
pixelRatio(view.getPixelRatio()),
asyncUpdate([this] { update(); }),
annotationManager(std::make_unique<AnnotationManager>(pixelRatio)),
texturePool(std::make_unique<gl::TexturePool>()) {
}

Expand All @@ -98,7 +104,7 @@ Map::~Map() {
impl->style.reset();
impl->painter.reset();
impl->texturePool.reset();
impl->dataPtr.reset();
impl->annotationManager.reset();

impl->glObjectStore.performCleanup();

Expand All @@ -111,7 +117,7 @@ void Map::renderStill(StillImageCallback callback) {
return;
}

if (impl->data.mode != MapMode::Still) {
if (impl->mode != MapMode::Still) {
callback(std::make_exception_ptr(util::MisuseException("Map is not in still image render mode")), {});
return;
}
Expand Down Expand Up @@ -189,7 +195,7 @@ void Map::Impl::update() {
updateFlags = Update::Nothing;
}

if (updateFlags == Update::Nothing || (data.mode == MapMode::Still && !callback)) {
if (updateFlags == Update::Nothing || (mode == MapMode::Still && !callback)) {
return;
}

Expand All @@ -199,33 +205,33 @@ void Map::Impl::update() {
timePoint = Clock::now();

if (style->loaded && updateFlags & Update::Annotations) {
data.getAnnotationManager()->updateStyle(*style);
annotationManager->updateStyle(*style);
updateFlags |= Update::Classes;
}

if (updateFlags & Update::Classes) {
style->cascade(timePoint, data.mode);
style->cascade(timePoint, mode);
}

if (updateFlags & Update::Classes || updateFlags & Update::RecalculateStyle) {
style->recalculate(transformState.getZoom(), timePoint, data.mode);
style->recalculate(transformState.getZoom(), timePoint, mode);
}

StyleUpdateParameters parameters(data.pixelRatio,
data.getDebug(),
StyleUpdateParameters parameters(pixelRatio,
debugOptions,
timePoint,
transformState,
style->workers,
fileSource,
*texturePool,
style->shouldReparsePartialTiles,
data.mode,
*data.getAnnotationManager(),
mode,
*annotationManager,
*style);

style->update(parameters);

if (data.mode == MapMode::Continuous) {
if (mode == MapMode::Continuous) {
view.invalidate();
} else if (callback && style->isLoaded()) {
view.activate();
Expand All @@ -245,16 +251,16 @@ void Map::Impl::render() {

FrameData frameData { view.getFramebufferSize(),
timePoint,
data.pixelRatio,
data.mode,
data.contextMode,
data.getDebug() };
pixelRatio,
mode,
contextMode,
debugOptions };

painter->render(*style,
frameData,
data.getAnnotationManager()->getSpriteAtlas());
annotationManager->getSpriteAtlas());

if (data.mode == MapMode::Still) {
if (mode == MapMode::Still) {
callback(nullptr, view.readStillImage());
callback = nullptr;
}
Expand Down Expand Up @@ -285,7 +291,7 @@ void Map::setStyleURL(const std::string& url) {
impl->styleURL = url;
impl->styleJSON.clear();

impl->style = std::make_unique<Style>(impl->fileSource, impl->data.pixelRatio);
impl->style = std::make_unique<Style>(impl->fileSource, impl->pixelRatio);

const size_t pos = impl->styleURL.rfind('/');
std::string base = "";
Expand Down Expand Up @@ -320,7 +326,7 @@ void Map::setStyleJSON(const std::string& json, const std::string& base) {

impl->styleURL.clear();
impl->styleJSON.clear();
impl->style = std::make_unique<Style>(impl->fileSource, impl->data.pixelRatio);
impl->style = std::make_unique<Style>(impl->fileSource, impl->pixelRatio);

impl->loadStyleJSON(json, base);
}
Expand All @@ -331,7 +337,7 @@ void Map::Impl::loadStyleJSON(const std::string& json, const std::string& base)
styleJSON = json;

// force style cascade, causing all pending transitions to complete.
style->cascade(Clock::now(), data.mode);
style->cascade(Clock::now(), mode);

updateFlags |= Update::Classes | Update::RecalculateStyle | Update::Annotations;
asyncUpdate.send();
Expand Down Expand Up @@ -657,23 +663,23 @@ LatLng Map::latLngForPixel(const ScreenCoordinate& pixel) const {
#pragma mark - Annotations

void Map::addAnnotationIcon(const std::string& name, std::shared_ptr<const SpriteImage> sprite) {
impl->data.getAnnotationManager()->addIcon(name, sprite);
impl->annotationManager->addIcon(name, sprite);
}

void Map::removeAnnotationIcon(const std::string& name) {
impl->data.getAnnotationManager()->removeIcon(name);
impl->annotationManager->removeIcon(name);
}

double Map::getTopOffsetPixelsForAnnotationIcon(const std::string& name) {
return impl->data.getAnnotationManager()->getTopOffsetPixelsForIcon(name);
return impl->annotationManager->getTopOffsetPixelsForIcon(name);
}

AnnotationID Map::addPointAnnotation(const PointAnnotation& annotation) {
return addPointAnnotations({ annotation }).front();
}

AnnotationIDs Map::addPointAnnotations(const std::vector<PointAnnotation>& annotations) {
auto result = impl->data.getAnnotationManager()->addPointAnnotations(annotations, getMaxZoom());
auto result = impl->annotationManager->addPointAnnotations(annotations, getMaxZoom());
update(Update::Annotations);
return result;
}
Expand All @@ -683,13 +689,13 @@ AnnotationID Map::addShapeAnnotation(const ShapeAnnotation& annotation) {
}

AnnotationIDs Map::addShapeAnnotations(const std::vector<ShapeAnnotation>& annotations) {
auto result = impl->data.getAnnotationManager()->addShapeAnnotations(annotations, getMaxZoom());
auto result = impl->annotationManager->addShapeAnnotations(annotations, getMaxZoom());
update(Update::Annotations);
return result;
}

void Map::updatePointAnnotation(AnnotationID annotationId, const PointAnnotation& annotation) {
impl->data.getAnnotationManager()->updatePointAnnotation(annotationId, annotation, getMaxZoom());
impl->annotationManager->updatePointAnnotation(annotationId, annotation, getMaxZoom());
update(Update::Annotations);
}

Expand All @@ -698,12 +704,12 @@ void Map::removeAnnotation(AnnotationID annotation) {
}

void Map::removeAnnotations(const AnnotationIDs& annotations) {
impl->data.getAnnotationManager()->removeAnnotations(annotations);
impl->annotationManager->removeAnnotations(annotations);
update(Update::Annotations);
}

AnnotationIDs Map::getPointAnnotationsInBounds(const LatLngBounds& bounds) {
return impl->data.getAnnotationManager()->getPointAnnotationsInBounds(bounds);
return impl->annotationManager->getPointAnnotationsInBounds(bounds);
}

#pragma mark - Style API
Expand Down Expand Up @@ -737,18 +743,28 @@ void Map::removeCustomLayer(const std::string& id) {

#pragma mark - Toggles

void Map::setDebug(MapDebugOptions mode) {
impl->data.setDebug(mode);
void Map::setDebug(MapDebugOptions debugOptions) {
impl->debugOptions = debugOptions;
update(Update::Repaint);
}

void Map::cycleDebugOptions() {
impl->data.cycleDebugOptions();
if (impl->debugOptions & MapDebugOptions::Collision)
impl->debugOptions = MapDebugOptions::NoDebug;
else if (impl->debugOptions & MapDebugOptions::Timestamps)
impl->debugOptions = impl->debugOptions | MapDebugOptions::Collision;
else if (impl->debugOptions & MapDebugOptions::ParseStatus)
impl->debugOptions = impl->debugOptions | MapDebugOptions::Timestamps;
else if (impl->debugOptions & MapDebugOptions::TileBorders)
impl->debugOptions = impl->debugOptions | MapDebugOptions::ParseStatus;
else
impl->debugOptions = MapDebugOptions::TileBorders;

update(Update::Repaint);
}

MapDebugOptions Map::getDebug() const {
return impl->data.getDebug();
return impl->debugOptions;
}

bool Map::isFullyLoaded() const {
Expand Down Expand Up @@ -801,7 +817,7 @@ void Map::Impl::onResourceLoaded() {
}

void Map::Impl::onResourceError(std::exception_ptr error) {
if (data.mode == MapMode::Still && callback) {
if (mode == MapMode::Still && callback) {
callback(error, {});
callback = nullptr;
}
Expand Down
64 changes: 0 additions & 64 deletions src/mbgl/map/map_data.hpp

This file was deleted.

1 change: 0 additions & 1 deletion src/mbgl/renderer/painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <mbgl/source/source.hpp>
#include <mbgl/tile/tile.hpp>
#include <mbgl/map/map_data.hpp>

#include <mbgl/platform/log.hpp>
#include <mbgl/gl/debugging.hpp>
Expand Down
1 change: 0 additions & 1 deletion src/mbgl/renderer/painter_circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <mbgl/layer/circle_layer.hpp>

#include <mbgl/map/tile_id.hpp>
#include <mbgl/map/map_data.hpp>

#include <mbgl/shader/circle_shader.hpp>

Expand Down
1 change: 0 additions & 1 deletion src/mbgl/renderer/painter_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <mbgl/renderer/debug_bucket.hpp>
#include <mbgl/tile/tile.hpp>
#include <mbgl/tile/tile_data.hpp>
#include <mbgl/map/map_data.hpp>
#include <mbgl/shader/plain_shader.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/gl/debugging.hpp>
Expand Down
1 change: 0 additions & 1 deletion src/mbgl/renderer/painter_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <mbgl/renderer/line_bucket.hpp>
#include <mbgl/layer/line_layer.hpp>
#include <mbgl/map/tile_id.hpp>
#include <mbgl/map/map_data.hpp>
#include <mbgl/shader/line_shader.hpp>
#include <mbgl/shader/linesdf_shader.hpp>
#include <mbgl/shader/linepattern_shader.hpp>
Expand Down
1 change: 0 additions & 1 deletion src/mbgl/renderer/painter_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <mbgl/shader/icon_shader.hpp>
#include <mbgl/shader/box_shader.hpp>
#include <mbgl/map/tile_id.hpp>
#include <mbgl/map/map_data.hpp>
#include <mbgl/util/math.hpp>

#include <cmath>
Expand Down
1 change: 0 additions & 1 deletion src/mbgl/source/source.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <mbgl/source/source.hpp>
#include <mbgl/map/map_data.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/tile/tile.hpp>
#include <mbgl/tile/vector_tile.hpp>
Expand Down
1 change: 0 additions & 1 deletion src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <mbgl/style/style.hpp>
#include <mbgl/map/map_data.hpp>
#include <mbgl/source/source.hpp>
#include <mbgl/tile/tile.hpp>
#include <mbgl/map/transform_state.hpp>
Expand Down
1 change: 0 additions & 1 deletion test/style/style.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <mbgl/test/util.hpp>
#include <mbgl/test/stub_file_source.hpp>

#include <mbgl/map/map_data.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/util/io.hpp>

Expand Down

0 comments on commit 1ee0055

Please sign in to comment.