From 3832f8d0d8194b81ea34a045e19b0d5bc7a89e25 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Tue, 13 Jun 2017 10:50:16 +0300 Subject: [core] renderer interface --- include/mbgl/map/backend.hpp | 9 +++-- include/mbgl/map/map.hpp | 25 +++---------- include/mbgl/map/query.hpp | 43 ----------------------- include/mbgl/renderer/query.hpp | 43 +++++++++++++++++++++++ include/mbgl/renderer/renderer.hpp | 54 +++++++++++++++++++++++++++++ include/mbgl/renderer/renderer_frontend.hpp | 31 +++++++++++++++++ 6 files changed, 136 insertions(+), 69 deletions(-) delete mode 100644 include/mbgl/map/query.hpp create mode 100644 include/mbgl/renderer/query.hpp create mode 100644 include/mbgl/renderer/renderer.hpp create mode 100644 include/mbgl/renderer/renderer_frontend.hpp (limited to 'include/mbgl') diff --git a/include/mbgl/map/backend.hpp b/include/mbgl/map/backend.hpp index 434f68779c..3347086571 100644 --- a/include/mbgl/map/backend.hpp +++ b/include/mbgl/map/backend.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -15,8 +16,6 @@ using ProcAddress = void (*)(); using FramebufferID = uint32_t; } // namespace gl -class BackendScope; - class Backend { public: Backend(); @@ -28,9 +27,9 @@ public: // Called prior to rendering to update the internally assumed OpenGL state. virtual void updateAssumedState() = 0; - // Called when the map needs to be rendered; the backend should call Map::render() at some point - // in the near future. (Not called for Map::renderStill() mode.) - virtual void invalidate() = 0; + inline virtual BackendScope::ScopeType getScopeType() const { + return BackendScope::ScopeType::Explicit; + }; protected: // Called with the name of an OpenGL extension that should be loaded. Backend implementations diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 22ac100c40..14f42d7fd5 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -4,13 +4,10 @@ #include #include #include -#include -#include #include #include #include #include -#include #include #include @@ -24,6 +21,7 @@ class Backend; class View; class FileSource; class Scheduler; +class RendererFrontend; namespace style { class Image; @@ -32,30 +30,25 @@ class Style; class Map : private util::noncopyable { public: - explicit Map(Backend&, + explicit Map(RendererFrontend&, MapObserver&, Size size, float pixelRatio, FileSource&, Scheduler&, MapMode mapMode = MapMode::Continuous, - GLContextMode contextMode = GLContextMode::Unique, ConstrainMode constrainMode = ConstrainMode::HeightOnly, - ViewportMode viewportMode = ViewportMode::Default, - optional programCacheDir = optional()); + ViewportMode viewportMode = ViewportMode::Default); ~Map(); // Register a callback that will get called (on the render thread) when all resources have // been loaded and a complete render occurs. using StillImageCallback = std::function; - void renderStill(View&, StillImageCallback callback); + void renderStill(StillImageCallback callback); // Triggers a repaint. void triggerRepaint(); - // Main render function. - void render(View&); - style::Style& getStyle(); const style::Style& getStyle() const; @@ -150,13 +143,6 @@ public: void updateAnnotation(AnnotationID, const Annotation&); void removeAnnotation(AnnotationID); - // Feature queries - std::vector queryRenderedFeatures(const ScreenCoordinate&, const RenderedQueryOptions& options = {}); - std::vector queryRenderedFeatures(const ScreenBox&, const RenderedQueryOptions& options = {}); - std::vector querySourceFeatures(const std::string& sourceID, const SourceQueryOptions& options = {}); - - AnnotationIDs queryPointAnnotations(const ScreenBox&); - // Tile prefetching // // When loading a map, if `PrefetchZoomDelta` is set to any number greater than 0, the map will @@ -166,9 +152,6 @@ public: void setPrefetchZoomDelta(uint8_t delta); uint8_t getPrefetchZoomDelta() const; - // Memory - void onLowMemory(); - // Debug void setDebug(MapDebugOptions); void cycleDebugOptions(); diff --git a/include/mbgl/map/query.hpp b/include/mbgl/map/query.hpp deleted file mode 100644 index b9d5f21a44..0000000000 --- a/include/mbgl/map/query.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include -#include - -#include -#include - -namespace mbgl { - -/** - * Options for query rendered features. - */ -class RenderedQueryOptions { -public: - RenderedQueryOptions(optional> layerIDs_ = optional>(), - optional filter_ = optional()) - : layerIDs(std::move(layerIDs_)), - filter(std::move(filter_)) {} - - /** layerIDs to include in the query */ - optional> layerIDs; - - optional filter; -}; - -/** - * Options for query source features - */ -class SourceQueryOptions { -public: - SourceQueryOptions(optional> sourceLayers_ = optional> (), - optional filter_ = optional()) - : sourceLayers(std::move(sourceLayers_)), - filter(std::move(filter_)) {} - - // Required for VectorSource, ignored for GeoJSONSource - optional> sourceLayers; - - optional filter; -}; - -} // namespace mbgl diff --git a/include/mbgl/renderer/query.hpp b/include/mbgl/renderer/query.hpp new file mode 100644 index 0000000000..b9d5f21a44 --- /dev/null +++ b/include/mbgl/renderer/query.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include +#include + +#include +#include + +namespace mbgl { + +/** + * Options for query rendered features. + */ +class RenderedQueryOptions { +public: + RenderedQueryOptions(optional> layerIDs_ = optional>(), + optional filter_ = optional()) + : layerIDs(std::move(layerIDs_)), + filter(std::move(filter_)) {} + + /** layerIDs to include in the query */ + optional> layerIDs; + + optional filter; +}; + +/** + * Options for query source features + */ +class SourceQueryOptions { +public: + SourceQueryOptions(optional> sourceLayers_ = optional> (), + optional filter_ = optional()) + : sourceLayers(std::move(sourceLayers_)), + filter(std::move(filter_)) {} + + // Required for VectorSource, ignored for GeoJSONSource + optional> sourceLayers; + + optional filter; +}; + +} // namespace mbgl diff --git a/include/mbgl/renderer/renderer.hpp b/include/mbgl/renderer/renderer.hpp new file mode 100644 index 0000000000..6626f74d3d --- /dev/null +++ b/include/mbgl/renderer/renderer.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace mbgl { + +class Backend; +class FileSource; +class RendererObserver; +class RenderedQueryOptions; +class Scheduler; +class SourceQueryOptions; +class UpdateParameters; +class View; + +class Renderer { +public: + Renderer(Backend&, float pixelRatio_, FileSource&, Scheduler&, + GLContextMode = GLContextMode::Unique, + const optional programCacheDir = optional()); + ~Renderer(); + + void setObserver(RendererObserver*); + + void render(View& view, const UpdateParameters&); + + // Feature queries + std::vector queryRenderedFeatures(const ScreenLineString&, const RenderedQueryOptions& options = {}) const; + std::vector queryRenderedFeatures(const ScreenCoordinate& point, const RenderedQueryOptions& options = {}) const; + std::vector queryRenderedFeatures(const ScreenBox& box, const RenderedQueryOptions& options = {}) const; + std::vector querySourceFeatures(const std::string& sourceID, const SourceQueryOptions& options = {}) const; + AnnotationIDs queryPointAnnotations(const ScreenBox& box) const; + + // Debug + void dumpDebugLogs(); + + // Memory + void onLowMemory(); + +private: + class Impl; + std::unique_ptr impl; +}; + +} // namespace mbgl diff --git a/include/mbgl/renderer/renderer_frontend.hpp b/include/mbgl/renderer/renderer_frontend.hpp new file mode 100644 index 0000000000..f72b0ccdde --- /dev/null +++ b/include/mbgl/renderer/renderer_frontend.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include + +namespace mbgl { + +class RendererObserver; +class UpdateParameters; + +// The RenderFrontend is the bridge between the Map and +// platform used to update and observer the Renderer +// +// It hides any threading specifics and always replies on +// the original thread. +class RendererFrontend { +public: + + virtual ~RendererFrontend() = default; + + // Must synchronously clean up the Renderer if set + virtual void reset() = 0; + + // Implementer must bind the renderer observer to the renderer in a + // appropriate manner so that the callbacks occur on the main thread + virtual void setObserver(RendererObserver&) = 0; + + // Coalescing updates is up to the implementer + virtual void update(std::shared_ptr) = 0; +}; + +} // namespace mbgl -- cgit v1.2.1