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>
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user