feat(android): Vulkan graphics backend support for Android custom layers (#4348)

Co-authored-by: Vladyslav Odobesku <VladyslavOdobesku@intellias.com>
Co-authored-by: Claude Opus 4 <noreply@anthropic.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Vladyslav Odobesku
2026-06-26 19:53:00 +03:00
committed by GitHub
parent 9f6f8e3f1b
commit aa90185d42
25 changed files with 791 additions and 67 deletions

View File

@@ -9,6 +9,9 @@
#if MLN_RENDER_BACKEND_METAL
#include <mbgl/style/layers/mtl/custom_layer_render_parameters.hpp>
#include <mbgl/mtl/render_pass.hpp>
#elif MLN_RENDER_BACKEND_VULKAN
#include <mbgl/style/layers/vulkan/custom_layer_render_parameters.hpp>
#include <mbgl/vulkan/render_pass.hpp>
#endif
#include <memory>
@@ -28,6 +31,8 @@ void DrawableCustomLayerHostTweaker::execute([[maybe_unused]] gfx::Drawable& dra
mtlRenderPass->resetState();
style::mtl::CustomLayerRenderParameters parameters(paintParameters);
#elif MLN_RENDER_BACKEND_VULKAN
style::vulkan::CustomLayerRenderParameters parameters(paintParameters);
#else
style::CustomLayerRenderParameters parameters(paintParameters);
#endif

View File

@@ -13,6 +13,12 @@
#include <mbgl/gfx/drawable_custom_layer_host_tweaker.hpp>
#include <mbgl/gfx/drawable_builder.hpp>
#if MLN_RENDER_BACKEND_VULKAN
#include <mbgl/vulkan/context.hpp>
#include <mbgl/vulkan/renderer_backend.hpp>
#include <mbgl/style/layers/vulkan/custom_layer_init_parameters.hpp>
#endif
// TODO: platform agnostic error checks
#define MBGL_CHECK_ERROR(cmd) (cmd)
@@ -27,13 +33,27 @@ inline const CustomLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl)
return static_cast<const CustomLayer::Impl&>(*impl);
}
void initializeHost(const std::shared_ptr<style::CustomLayerHost>& host, [[maybe_unused]] gfx::Context& context) {
#if MLN_RENDER_BACKEND_VULKAN
{
auto& vkBackend = static_cast<mbgl::vulkan::Context&>(context).getBackend();
style::vulkan::CustomLayerInitParameters params(
vkBackend.getDispatcher(), vkBackend.getDevice().get(), vkBackend.getPhysicalDevice());
host->initialize(params);
}
#else
{
style::CustomLayerInitParameters params;
host->initialize(params);
}
#endif
}
} // namespace
RenderCustomLayer::RenderCustomLayer(Immutable<style::CustomLayer::Impl> _impl)
: RenderLayer(makeMutable<CustomLayerProperties>(std::move(_impl))),
host(impl(baseImpl).host) {
assert(gfx::BackendScope::exists());
MBGL_CHECK_ERROR(host->initialize());
}
RenderCustomLayer::~RenderCustomLayer() {
@@ -86,7 +106,12 @@ void RenderCustomLayer::update([[maybe_unused]] gfx::ShaderRegistry& shaders,
MBGL_CHECK_ERROR(host->deinitialize());
}
host = impl(baseImpl).host;
MBGL_CHECK_ERROR(host->initialize());
needsInitialize = true;
}
if (needsInitialize) {
MBGL_CHECK_ERROR(initializeHost(host, context));
needsInitialize = false;
}
// create drawable

View File

@@ -27,6 +27,7 @@ private:
void prepare(const LayerPrepareParameters&) override;
bool contextDestroyed = false;
bool needsInitialize = true;
std::shared_ptr<style::CustomLayerHost> host;
};

View File

@@ -0,0 +1,29 @@
// Include this before including custom_layer_render_parameters as custom_layer_render_parameters needs to be
// "lightweight". It shouldn't touch the full <mbgl/vulkan/renderer_backend.hpp> as it brings the whole new big
#include <mbgl/vulkan/renderer_backend.hpp>
#include <mbgl/style/layers/vulkan/custom_layer_render_parameters.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/vulkan/command_encoder.hpp>
#include <mbgl/vulkan/render_pass.hpp>
#include <mbgl/vulkan/renderable_resource.hpp>
namespace mbgl {
namespace style {
namespace vulkan {
CustomLayerRenderParameters::CustomLayerRenderParameters(const mbgl::PaintParameters& paintParameters)
: mbgl::style::CustomLayerRenderParameters(paintParameters),
dispatcher(static_cast<mbgl::vulkan::RendererBackend&>(paintParameters.backend).getDispatcher()) {
device = static_cast<mbgl::vulkan::RendererBackend&>(paintParameters.backend).getDevice().get();
auto& vulkanRenderPass = static_cast<mbgl::vulkan::RenderPass&>(*paintParameters.renderPass);
commandBuffer = vulkanRenderPass.getEncoder().getCommandBuffer().get();
const auto& renderable = paintParameters.backend.getDefaultRenderable();
const auto& resource = renderable.getResource<mbgl::vulkan::RenderableResource>();
renderPass = resource.getRenderPass().get();
screenPreRotationRadiansClockwise = resource.getRotation();
}
} // namespace vulkan
} // namespace style
} // namespace mbgl

View File

@@ -389,7 +389,7 @@ bool SurfaceRenderableResource::didSurfaceTransformUpdate() const {
return capabilities.currentTransform != updatedCapabilities.currentTransform;
}
float SurfaceRenderableResource::getRotation() {
float SurfaceRenderableResource::getRotation() const {
switch (capabilities.currentTransform) {
default:
case vk::SurfaceTransformFlagBitsKHR::eIdentity: