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

Commit

Permalink
[core] Refactor Source::*Impls into RenderSources and TilePyramid
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed May 2, 2017
1 parent 197751b commit 3f0c89d
Show file tree
Hide file tree
Showing 44 changed files with 1,401 additions and 710 deletions.
15 changes: 15 additions & 0 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ set(MBGL_CORE_FILES
src/mbgl/annotation/fill_annotation_impl.hpp
src/mbgl/annotation/line_annotation_impl.cpp
src/mbgl/annotation/line_annotation_impl.hpp
src/mbgl/annotation/render_annotation_source.cpp
src/mbgl/annotation/render_annotation_source.hpp
src/mbgl/annotation/shape_annotation_impl.cpp
src/mbgl/annotation/shape_annotation_impl.hpp
src/mbgl/annotation/style_sourced_annotation_impl.cpp
Expand Down Expand Up @@ -208,10 +210,23 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/render_raster_layer.hpp
src/mbgl/renderer/render_symbol_layer.cpp
src/mbgl/renderer/render_symbol_layer.hpp
src/mbgl/renderer/render_source.cpp
src/mbgl/renderer/render_source.hpp
src/mbgl/renderer/render_source_observer.hpp
src/mbgl/renderer/render_tile.cpp
src/mbgl/renderer/render_tile.hpp
src/mbgl/renderer/symbol_bucket.cpp
src/mbgl/renderer/symbol_bucket.hpp
src/mbgl/renderer/tile_pyramid.cpp
src/mbgl/renderer/tile_pyramid.hpp

# renderer/sources
src/mbgl/renderer/sources/render_geojson_source.cpp
src/mbgl/renderer/sources/render_geojson_source.hpp
src/mbgl/renderer/sources/render_raster_source.cpp
src/mbgl/renderer/sources/render_raster_source.hpp
src/mbgl/renderer/sources/render_vector_source.cpp
src/mbgl/renderer/sources/render_vector_source.hpp

# shaders
src/mbgl/shaders/circle.cpp
Expand Down
1 change: 0 additions & 1 deletion include/mbgl/style/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class Source : public mbgl::util::noncopyable {
std::unique_ptr<Source> copy(const std::string& id) const;

optional<std::string> getAttribution() const;
optional<Range<uint8_t>> getZoomRange() const;

// Private implementation
class Impl;
Expand Down
19 changes: 1 addition & 18 deletions include/mbgl/style/sources/geojson_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,9 @@
#include <mbgl/util/geojson.hpp>
#include <mbgl/util/optional.hpp>

#include <mapbox/geojson.hpp>

namespace mapbox {

namespace geojsonvt {
class GeoJSONVT;
} // namespace geojsonvt

namespace supercluster {
class Supercluster;
} // namespace supercluster

} // namespace mapbox

namespace mbgl {
namespace style {

using GeoJSONVTPointer = std::unique_ptr<mapbox::geojsonvt::GeoJSONVT>;
using SuperclusterPointer = std::unique_ptr<mapbox::supercluster::Supercluster>;

struct GeoJSONOptions {
// GeoJSON-VT options
uint8_t maxzoom = 18;
Expand All @@ -38,7 +21,7 @@ struct GeoJSONOptions {

class GeoJSONSource : public Source {
public:
GeoJSONSource(const std::string& id, const GeoJSONOptions options_ = GeoJSONOptions());
GeoJSONSource(const std::string& id, const GeoJSONOptions& = {});

void setURL(const std::string& url);
void setGeoJSON(const GeoJSON&);
Expand Down
4 changes: 1 addition & 3 deletions platform/default/mbgl/storage/offline_download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ OfflineRegionStatus OfflineDownload::getStatus() const {
}

case SourceType::GeoJSON: {
style::GeoJSONSource::Impl* geojsonSource =
static_cast<style::GeoJSONSource::Impl*>(source->baseImpl.get());

style::GeoJSONSource* geojsonSource = source->as<style::GeoJSONSource>();
if (geojsonSource->getURL()) {
result.requiredResourceCount += 1;
}
Expand Down
11 changes: 3 additions & 8 deletions src/mbgl/annotation/annotation_source.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <mbgl/annotation/annotation_source.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/annotation/annotation_tile.hpp>
#include <mbgl/annotation/render_annotation_source.hpp>

namespace mbgl {

Expand All @@ -14,17 +14,12 @@ AnnotationSource::Impl::Impl(Source& base_)
: Source::Impl(SourceType::Annotations, AnnotationManager::SourceID, base_) {
}

optional<Range<uint8_t>> AnnotationSource::Impl::getZoomRange() const {
return { { 0, 22 } };
}

void AnnotationSource::Impl::loadDescription(FileSource&) {
loaded = true;
}

std::unique_ptr<Tile> AnnotationSource::Impl::createTile(const OverscaledTileID& tileID,
const style::UpdateParameters& parameters) {
return std::make_unique<AnnotationTile>(tileID, parameters);
std::unique_ptr<RenderSource> AnnotationSource::Impl::createRenderSource() const {
return std::make_unique<RenderAnnotationSource>(*this);
}

} // namespace mbgl
8 changes: 1 addition & 7 deletions src/mbgl/annotation/annotation_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ class AnnotationSource::Impl : public style::Source::Impl {
Impl(Source&);

void loadDescription(FileSource&) final;

optional<Range<uint8_t>> getZoomRange() const final;

private:
uint16_t getTileSize() const final { return util::tileSize; }

std::unique_ptr<Tile> createTile(const OverscaledTileID&, const style::UpdateParameters&) final;
std::unique_ptr<RenderSource> createRenderSource() const final;
};

} // namespace mbgl
79 changes: 79 additions & 0 deletions src/mbgl/annotation/render_annotation_source.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <mbgl/annotation/render_annotation_source.hpp>
#include <mbgl/annotation/annotation_tile.hpp>
#include <mbgl/renderer/render_tile.hpp>

#include <mbgl/algorithm/generate_clip_ids.hpp>
#include <mbgl/algorithm/generate_clip_ids_impl.hpp>

namespace mbgl {

using namespace style;

RenderAnnotationSource::RenderAnnotationSource(const AnnotationSource::Impl& impl_)
: RenderSource(impl_) {
tilePyramid.setObserver(this);
}

bool RenderAnnotationSource::isLoaded() const {
return tilePyramid.isLoaded();
}

void RenderAnnotationSource::invalidateTiles() {
tilePyramid.invalidateTiles();
}

void RenderAnnotationSource::startRender(algorithm::ClipIDGenerator& generator, const mat4& projMatrix, const mat4& clipMatrix, const TransformState& transform) {
generator.update(tilePyramid.getRenderTiles());
tilePyramid.startRender(projMatrix, clipMatrix, transform);
}

void RenderAnnotationSource::finishRender(Painter& painter) {
tilePyramid.finishRender(painter);
}

std::map<UnwrappedTileID, RenderTile>& RenderAnnotationSource::getRenderTiles() {
return tilePyramid.getRenderTiles();
}

void RenderAnnotationSource::updateTiles(const UpdateParameters& parameters) {
tilePyramid.updateTiles(parameters,
SourceType::Annotations,
util::tileSize,
{ 0, 22 },
[&] (const OverscaledTileID& tileID) {
return std::make_unique<AnnotationTile>(tileID, parameters);
});
}

void RenderAnnotationSource::removeTiles() {
tilePyramid.removeTiles();
}

void RenderAnnotationSource::reloadTiles() {
tilePyramid.reloadTiles();
}

std::unordered_map<std::string, std::vector<Feature>>
RenderAnnotationSource::queryRenderedFeatures(const ScreenLineString& geometry,
const TransformState& transformState,
const RenderedQueryOptions& options) const {
return tilePyramid.queryRenderedFeatures(geometry, transformState, options);
}

std::vector<Feature> RenderAnnotationSource::querySourceFeatures(const SourceQueryOptions&) const {
return {};
}

void RenderAnnotationSource::setCacheSize(size_t size) {
tilePyramid.setCacheSize(size);
}

void RenderAnnotationSource::onLowMemory() {
tilePyramid.onLowMemory();
}

void RenderAnnotationSource::dumpDebugLogs() const {
tilePyramid.dumpDebugLogs();
}

} // namespace mbgl
53 changes: 53 additions & 0 deletions src/mbgl/annotation/render_annotation_source.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma once

#include <mbgl/renderer/render_source.hpp>
#include <mbgl/renderer/tile_pyramid.hpp>
#include <mbgl/annotation/annotation_source.hpp>

namespace mbgl {

class RenderAnnotationSource : public RenderSource {
public:
RenderAnnotationSource(const AnnotationSource::Impl&);

bool isLoaded() const final;

// Called when the camera has changed. May load new tiles, unload obsolete tiles, or
// trigger re-placement of existing complete tiles.
void updateTiles(const style::UpdateParameters&) final;

// Removes all tiles (by putting them into the cache).
void removeTiles() final;

// Remove all tiles and clear the cache.
void invalidateTiles() final;

// Request that all loaded tiles re-run the layout operation on the existing source
// data with fresh style information.
void reloadTiles() final;

void startRender(algorithm::ClipIDGenerator&,
const mat4& projMatrix,
const mat4& clipMatrix,
const TransformState&) final;
void finishRender(Painter&) final;

std::map<UnwrappedTileID, RenderTile>& getRenderTiles() final;

std::unordered_map<std::string, std::vector<Feature>>
queryRenderedFeatures(const ScreenLineString& geometry,
const TransformState& transformState,
const RenderedQueryOptions& options) const final;

std::vector<Feature>
querySourceFeatures(const SourceQueryOptions&) const final;

void setCacheSize(size_t) final;
void onLowMemory() final;
void dumpDebugLogs() const final;

private:
TilePyramid tilePyramid;
};

} // namespace mbgl
7 changes: 4 additions & 3 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
#include <mbgl/map/transform_state.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/source.hpp>
#include <mbgl/style/layer.hpp>
#include <mbgl/style/light.hpp>
#include <mbgl/style/observer.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/update_parameters.hpp>
#include <mbgl/renderer/painter.hpp>
#include <mbgl/renderer/render_source.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
Expand Down Expand Up @@ -871,10 +872,10 @@ std::vector<Feature> Map::queryRenderedFeatures(const ScreenBox& box, const Rend
std::vector<Feature> Map::querySourceFeatures(const std::string& sourceID, const SourceQueryOptions& options) {
if (!impl->style) return {};

const style::Source* source = impl->style->getSource(sourceID);
const RenderSource* source = impl->style->getRenderSource(sourceID);
if (!source) return {};

return source->baseImpl->querySourceFeatures(options);
return source->querySourceFeatures(options);
}

AnnotationIDs Map::queryPointAnnotations(const ScreenBox& box) {
Expand Down
8 changes: 5 additions & 3 deletions src/mbgl/renderer/painter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <mbgl/renderer/painter.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/renderer/render_source.hpp>

#include <mbgl/style/source.hpp>
#include <mbgl/style/source_impl.hpp>
Expand All @@ -13,6 +14,7 @@
#include <mbgl/style/style.hpp>
#include <mbgl/style/layer_impl.hpp>

#include <mbgl/tile/tile.hpp>
#include <mbgl/renderer/render_background_layer.hpp>
#include <mbgl/renderer/render_custom_layer.hpp>
#include <mbgl/style/layers/custom_layer_impl.hpp>
Expand Down Expand Up @@ -148,7 +150,7 @@ void Painter::render(const Style& style, const FrameData& frame_, View& view, Sp

RenderData renderData = style.getRenderData(frame.debugOptions, state.getAngle());
const std::vector<RenderItem>& order = renderData.order;
const std::unordered_set<Source*>& sources = renderData.sources;
const std::unordered_set<RenderSource*>& sources = renderData.sources;

// Update the default matrices to the current viewport dimensions.
state.getProjMatrix(projMatrix);
Expand Down Expand Up @@ -209,7 +211,7 @@ void Painter::render(const Style& style, const FrameData& frame_, View& view, Sp
// Update all clipping IDs.
algorithm::ClipIDGenerator generator;
for (const auto& source : sources) {
source->baseImpl->startRender(generator, projMatrix, nearClippedProjMatrix, state);
source->startRender(generator, projMatrix, nearClippedProjMatrix, state);
}

MBGL_DEBUG_GROUP(context, "clipping masks");
Expand Down Expand Up @@ -258,7 +260,7 @@ void Painter::render(const Style& style, const FrameData& frame_, View& view, Sp
// When only rendering layers via the stylesheet, it's possible that we don't
// ever visit a tile during rendering.
for (const auto& source : sources) {
source->baseImpl->finishRender(*this);
source->finishRender(*this);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/mbgl/renderer/painter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class RenderBackgroundLayer;

class Programs;
class PaintParameters;
class TilePyramid;

struct ClipID;

Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/renderer/render_item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
namespace mbgl {

class RenderLayer;
class RenderSource;
class RenderTile;
class Bucket;

namespace style {
class Source;
} // namespace style

class RenderItem {
Expand All @@ -29,7 +29,7 @@ class RenderItem {
class RenderData {
public:
Color backgroundColor;
std::unordered_set<style::Source*> sources;
std::unordered_set<RenderSource*> sources;
std::vector<RenderItem> order;
};

Expand Down
26 changes: 26 additions & 0 deletions src/mbgl/renderer/render_source.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <mbgl/renderer/render_source.hpp>
#include <mbgl/renderer/render_source_observer.hpp>
#include <mbgl/tile/tile.hpp>

namespace mbgl {

static RenderSourceObserver nullObserver;

RenderSource::RenderSource(const style::Source::Impl& impl)
: baseImpl(impl),
observer(&nullObserver) {
}

void RenderSource::setObserver(RenderSourceObserver* observer_) {
observer = observer_;
}

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);
}

}
Loading

0 comments on commit 3f0c89d

Please sign in to comment.