Files
MapLibreParticleLab/src/mbgl/renderer/render_source.cpp
John Firebaugh 095dc7b167 [core] Replace createRender{Source,Layer} with Render{Source,Layer}::create
* Eliminates the need for EnableImmutableFromThis
* Eliminates the dependency of {Source,Layer}::Impl on corresponding Render class (circular dependency)
2017-05-12 11:26:27 -07:00

57 lines
1.7 KiB
C++

#include <mbgl/renderer/render_source.hpp>
#include <mbgl/renderer/render_source_observer.hpp>
#include <mbgl/renderer/sources/render_geojson_source.hpp>
#include <mbgl/renderer/sources/render_raster_source.hpp>
#include <mbgl/renderer/sources/render_vector_source.hpp>
#include <mbgl/annotation/render_annotation_source.hpp>
#include <mbgl/tile/tile.hpp>
namespace mbgl {
using namespace style;
std::unique_ptr<RenderSource> RenderSource::create(Immutable<Source::Impl> impl) {
switch (impl->type) {
case SourceType::Vector:
return std::make_unique<RenderVectorSource>(staticImmutableCast<VectorSource::Impl>(impl));
case SourceType::Raster:
return std::make_unique<RenderRasterSource>(staticImmutableCast<RasterSource::Impl>(impl));
case SourceType::GeoJSON:
return std::make_unique<RenderGeoJSONSource>(staticImmutableCast<GeoJSONSource::Impl>(impl));
case SourceType::Video:
assert(false);
return nullptr;
case SourceType::Annotations:
return std::make_unique<RenderAnnotationSource>(staticImmutableCast<AnnotationSource::Impl>(impl));
}
// Not reachable, but placate GCC.
assert(false);
return nullptr;
}
static RenderSourceObserver nullObserver;
RenderSource::RenderSource(Immutable<style::Source::Impl> impl)
: baseImpl(impl),
observer(&nullObserver) {
}
void RenderSource::setObserver(RenderSourceObserver* observer_) {
observer = observer_;
}
void RenderSource::setImpl(Immutable<style::Source::Impl> impl) {
baseImpl = impl;
}
void RenderSource::onTileChanged(Tile& tile) {
observer->onTileChanged(*this, tile.id);
}
void RenderSource::onTileError(Tile& tile, std::exception_ptr error) {
observer->onTileError(*this, tile.id, error);
}
} // namespace mbgl