summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/layers/render_custom_layer.cpp
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2018-04-02 16:15:25 -0700
committerGitHub <noreply@github.com>2018-04-02 16:15:25 -0700
commit099fcc3b3c72b117e93d4da39ee6f70c6c5a2bc8 (patch)
tree523c8c884404f82075702b6ea707e2b2b8015089 /src/mbgl/renderer/layers/render_custom_layer.cpp
parentc3079c6155d7ba2a0c8dd36571f17d7652a2092e (diff)
downloadqtlocation-mapboxgl-099fcc3b3c72b117e93d4da39ee6f70c6c5a2bc8.tar.gz
Use a host interface for CustomLayer instead of function pointers (#11553)
Use a host interface for CustomLayer instead of function pointers Co-authored-by: Julian Rex <julian.rex@mapbox.com>
Diffstat (limited to 'src/mbgl/renderer/layers/render_custom_layer.cpp')
-rw-r--r--src/mbgl/renderer/layers/render_custom_layer.cpp29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/mbgl/renderer/layers/render_custom_layer.cpp b/src/mbgl/renderer/layers/render_custom_layer.cpp
index a429b8d82e..85ca5b074e 100644
--- a/src/mbgl/renderer/layers/render_custom_layer.cpp
+++ b/src/mbgl/renderer/layers/render_custom_layer.cpp
@@ -12,17 +12,17 @@ namespace mbgl {
using namespace style;
RenderCustomLayer::RenderCustomLayer(Immutable<style::CustomLayer::Impl> _impl)
- : RenderLayer(LayerType::Custom, _impl) {
+ : RenderLayer(LayerType::Custom, _impl), host(_impl->host) {
+ assert(BackendScope::exists());
+ host->initialize();
}
RenderCustomLayer::~RenderCustomLayer() {
assert(BackendScope::exists());
- if (initialized) {
- if (contextDestroyed && impl().contextLostFn ) {
- impl().contextLostFn(impl().context);
- } else if (!contextDestroyed && impl().deinitializeFn) {
- impl().deinitializeFn(impl().context);
- }
+ if (contextDestroyed) {
+ host->contextLost();
+ } else {
+ host->deinitialize();
}
}
@@ -44,15 +44,13 @@ std::unique_ptr<Bucket> RenderCustomLayer::createBucket(const BucketParameters&,
}
void RenderCustomLayer::render(PaintParameters& paintParameters, RenderSource*) {
- if (context != impl().context || !initialized) {
+ if (host != impl().host) {
//If the context changed, deinitialize the previous one before initializing the new one.
- if (context && !contextDestroyed && impl().deinitializeFn) {
- MBGL_CHECK_ERROR(impl().deinitializeFn(context));
+ if (host && !contextDestroyed) {
+ MBGL_CHECK_ERROR(host->deinitialize());
}
- context = impl().context;
- assert(impl().initializeFn);
- MBGL_CHECK_ERROR(impl().initializeFn(impl().context));
- initialized = true;
+ host = impl().host;
+ MBGL_CHECK_ERROR(host->initialize());
}
gl::Context& glContext = paintParameters.context;
@@ -75,8 +73,7 @@ void RenderCustomLayer::render(PaintParameters& paintParameters, RenderSource*)
parameters.pitch = state.getPitch();
parameters.fieldOfView = state.getFieldOfView();
- assert(impl().renderFn);
- MBGL_CHECK_ERROR(impl().renderFn(context, parameters));
+ MBGL_CHECK_ERROR(host->render(parameters));
// Reset the view back to our original one, just in case the CustomLayer changed
// the viewport or Framebuffer.