From 66c020034e8260e5e071481e68ab61cd264723ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Mon, 1 Apr 2019 16:56:24 +0200 Subject: [core] refactor RendererBackend --- platform/ios/src/MGLMapView.mm | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'platform/ios') diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index f78b2d150c..4cbe839179 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -19,7 +19,8 @@ #include #include #include -#include +#import +#import #include #include #include @@ -6719,10 +6720,26 @@ public: return _annotationViewReuseQueueByIdentifier[identifier]; } -class MBGLView : public mbgl::RendererBackend, public mbgl::MapObserver -{ +class MBGLView; + +class MBGLMapViewRenderable final : public mbgl::gl::RenderableResource { +public: + MBGLMapViewRenderable(MBGLView& backend_) : backend(backend_) { + } + + void bind() override; + +private: + MBGLView& backend; +}; + +class MBGLView : public mbgl::gl::RendererBackend, + public mbgl::gfx::Renderable, + public mbgl::MapObserver { public: - MBGLView(MGLMapView* nativeView_) : nativeView(nativeView_) { + MBGLView(MGLMapView* nativeView_) : mbgl::gfx::Renderable( + nativeView_.framebufferSize, + std::make_unique(*this)), nativeView(nativeView_) { } /// This function is called before we start rendering, when iOS invokes our rendering method. @@ -6733,7 +6750,7 @@ public: assumeViewport(0, 0, nativeView.framebufferSize); } - void bind() override { + void restoreFramebufferBinding() { if (!implicitFramebufferBound()) { // Something modified our state, and we need to bind the original drawable again. // Doing this also sets the viewport to the full framebuffer. @@ -6747,10 +6764,6 @@ public: } } - mbgl::Size getFramebufferSize() const override { - return nativeView.framebufferSize; - } - void onCameraWillChange(mbgl::MapObserver::CameraChangeMode mode) override { bool animated = mode == mbgl::MapObserver::CameraChangeMode::Animated; [nativeView cameraWillChangeAnimated:animated]; @@ -6855,6 +6868,10 @@ public: return reinterpret_cast(symbol); } + mbgl::gfx::Renderable& getDefaultRenderable() override { + return *this; + } + void activate() override { if (activationCount++) @@ -6876,11 +6893,15 @@ public: } private: - __weak MGLMapView *nativeView = nullptr; + __weak MGLMapView* nativeView = nullptr; NSUInteger activationCount = 0; }; +void MBGLMapViewRenderable::bind() { + backend.restoreFramebufferBinding(); +} + @end #pragma mark - IBAdditions methods -- cgit v1.2.1