diff --git a/include/mbgl/renderer/renderer_observer.hpp b/include/mbgl/renderer/renderer_observer.hpp index 5cb107356f9..8d56e0fdc90 100644 --- a/include/mbgl/renderer/renderer_observer.hpp +++ b/include/mbgl/renderer/renderer_observer.hpp @@ -61,9 +61,9 @@ class RendererObserver { // Entry point for custom shader registration virtual void onRegisterShaders(gfx::ShaderRegistry&) {}; - virtual void onPreCompileShader(shaders::BuiltIn, gfx::Backend::Type, const std::string&){}; - virtual void onPostCompileShader(shaders::BuiltIn, gfx::Backend::Type, const std::string&){}; - virtual void onShaderCompileFailed(shaders::BuiltIn, gfx::Backend::Type, const std::string&){}; + virtual void onPreCompileShader(shaders::BuiltIn, gfx::Backend::Type, const std::string&) {}; + virtual void onPostCompileShader(shaders::BuiltIn, gfx::Backend::Type, const std::string&) {}; + virtual void onShaderCompileFailed(shaders::BuiltIn, gfx::Backend::Type, const std::string&) {}; // Glyph loading virtual void onGlyphsLoaded(const FontStack&, const GlyphRange&) {} diff --git a/platform/android/MapLibreAndroid/src/cpp/android_renderer_frontend.cpp b/platform/android/MapLibreAndroid/src/cpp/android_renderer_frontend.cpp index a6a39199f7d..0f5ddb66235 100644 --- a/platform/android/MapLibreAndroid/src/cpp/android_renderer_frontend.cpp +++ b/platform/android/MapLibreAndroid/src/cpp/android_renderer_frontend.cpp @@ -53,15 +53,21 @@ class ForwardingRendererObserver : public RendererObserver { delegate.invoke(&RendererObserver::onRemoveUnusedStyleImages, ids); } - void onPreCompileShader(mbgl::shaders::BuiltIn id, mbgl::gfx::Backend::Type type, const std::string& additionalDefines) override { + void onPreCompileShader(mbgl::shaders::BuiltIn id, + mbgl::gfx::Backend::Type type, + const std::string& additionalDefines) override { delegate.invoke(&RendererObserver::onPreCompileShader, id, type, additionalDefines); } - void onPostCompileShader(mbgl::shaders::BuiltIn id, mbgl::gfx::Backend::Type type, const std::string& additionalDefines) override { + void onPostCompileShader(mbgl::shaders::BuiltIn id, + mbgl::gfx::Backend::Type type, + const std::string& additionalDefines) override { delegate.invoke(&RendererObserver::onPostCompileShader, id, type, additionalDefines); } - void onShaderCompileFailed(mbgl::shaders::BuiltIn id, mbgl::gfx::Backend::Type type, const std::string& additionalDefines) override { + void onShaderCompileFailed(mbgl::shaders::BuiltIn id, + mbgl::gfx::Backend::Type type, + const std::string& additionalDefines) override { delegate.invoke(&RendererObserver::onShaderCompileFailed, id, type, additionalDefines); } diff --git a/platform/android/MapLibreAndroid/src/cpp/native_map_view.cpp b/platform/android/MapLibreAndroid/src/cpp/native_map_view.cpp index e74bd1d43ef..ed2e06252c0 100644 --- a/platform/android/MapLibreAndroid/src/cpp/native_map_view.cpp +++ b/platform/android/MapLibreAndroid/src/cpp/native_map_view.cpp @@ -1345,42 +1345,60 @@ void NativeMapView::registerNative(jni::JNIEnv& env) { void NativeMapView::onRegisterShaders(gfx::ShaderRegistry&) {}; // Shader compilation -void NativeMapView::onPreCompileShader(shaders::BuiltIn id, gfx::Backend::Type type, const std::string& additionalDefines) { +void NativeMapView::onPreCompileShader(shaders::BuiltIn id, + gfx::Backend::Type type, + const std::string& additionalDefines) { assert(vm != nullptr); android::UniqueEnv _env = android::AttachEnv(); static auto& javaClass = jni::Class::Singleton(*_env); - static auto onPreCompileShader = javaClass.GetMethod(*_env, "onPreCompileShader"); + static auto onPreCompileShader = javaClass.GetMethod(*_env, + "onPreCompileShader"); auto weakReference = javaPeer.get(*_env); if (weakReference) { - weakReference.Call(*_env, onPreCompileShader, static_cast(id), static_cast(type), - jni::Make(additionalDefines)); + weakReference.Call(*_env, + onPreCompileShader, + static_cast(id), + static_cast(type), + jni::Make(additionalDefines)); } } -void NativeMapView::onPostCompileShader(shaders::BuiltIn id, gfx::Backend::Type type, const std::string& additionalDefines) { +void NativeMapView::onPostCompileShader(shaders::BuiltIn id, + gfx::Backend::Type type, + const std::string& additionalDefines) { assert(vm != nullptr); android::UniqueEnv _env = android::AttachEnv(); static auto& javaClass = jni::Class::Singleton(*_env); - static auto onPostCompileShader = javaClass.GetMethod(*_env, "onPostCompileShader"); + static auto onPostCompileShader = javaClass.GetMethod( + *_env, "onPostCompileShader"); auto weakReference = javaPeer.get(*_env); if (weakReference) { - weakReference.Call(*_env, onPostCompileShader, static_cast(id), static_cast(type), - jni::Make(additionalDefines)); + weakReference.Call(*_env, + onPostCompileShader, + static_cast(id), + static_cast(type), + jni::Make(additionalDefines)); } } -void NativeMapView::onShaderCompileFailed(shaders::BuiltIn id, gfx::Backend::Type type, const std::string& additionalDefines) { +void NativeMapView::onShaderCompileFailed(shaders::BuiltIn id, + gfx::Backend::Type type, + const std::string& additionalDefines) { assert(vm != nullptr); android::UniqueEnv _env = android::AttachEnv(); static auto& javaClass = jni::Class::Singleton(*_env); - static auto onShaderCompileFailed = javaClass.GetMethod(*_env, "onShaderCompileFailed"); + static auto onShaderCompileFailed = javaClass.GetMethod( + *_env, "onShaderCompileFailed"); auto weakReference = javaPeer.get(*_env); if (weakReference) { - weakReference.Call(*_env, onShaderCompileFailed, static_cast(id), static_cast(type), - jni::Make(additionalDefines)); + weakReference.Call(*_env, + onShaderCompileFailed, + static_cast(id), + static_cast(type), + jni::Make(additionalDefines)); } } diff --git a/src/mbgl/map/map_impl.cpp b/src/mbgl/map/map_impl.cpp index df782a9d9ee..6b5a6454f18 100644 --- a/src/mbgl/map/map_impl.cpp +++ b/src/mbgl/map/map_impl.cpp @@ -244,15 +244,21 @@ void Map::Impl::onRegisterShaders(gfx::ShaderRegistry& registry) { observer.onRegisterShaders(registry); } -void Map::Impl::onPreCompileShader(shaders::BuiltIn shaderID, gfx::Backend::Type type, const std::string& additionalDefines) { +void Map::Impl::onPreCompileShader(shaders::BuiltIn shaderID, + gfx::Backend::Type type, + const std::string& additionalDefines) { observer.onPreCompileShader(shaderID, type, additionalDefines); } -void Map::Impl::onPostCompileShader(shaders::BuiltIn shaderID, gfx::Backend::Type type, const std::string& additionalDefines) { +void Map::Impl::onPostCompileShader(shaders::BuiltIn shaderID, + gfx::Backend::Type type, + const std::string& additionalDefines) { observer.onPostCompileShader(shaderID, type, additionalDefines); } -void Map::Impl::onShaderCompileFailed(shaders::BuiltIn shaderID, gfx::Backend::Type type, const std::string& additionalDefines) { +void Map::Impl::onShaderCompileFailed(shaders::BuiltIn shaderID, + gfx::Backend::Type type, + const std::string& additionalDefines) { observer.onShaderCompileFailed(shaderID, type, additionalDefines); } diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index 49846ea92ad..2c4f23a935b 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -68,15 +68,21 @@ Renderer::Impl::~Impl() { assert(gfx::BackendScope::exists()); }; -void Renderer::Impl::onPreCompileShader(shaders::BuiltIn shaderID, gfx::Backend::Type type, const std::string& additionalDefines) { +void Renderer::Impl::onPreCompileShader(shaders::BuiltIn shaderID, + gfx::Backend::Type type, + const std::string& additionalDefines) { observer->onPreCompileShader(shaderID, type, additionalDefines); } -void Renderer::Impl::onPostCompileShader(shaders::BuiltIn shaderID, gfx::Backend::Type type, const std::string& additionalDefines) { +void Renderer::Impl::onPostCompileShader(shaders::BuiltIn shaderID, + gfx::Backend::Type type, + const std::string& additionalDefines) { observer->onPostCompileShader(shaderID, type, additionalDefines); } -void Renderer::Impl::onShaderCompileFailed(shaders::BuiltIn shaderID, gfx::Backend::Type type, const std::string& additionalDefines) { +void Renderer::Impl::onShaderCompileFailed(shaders::BuiltIn shaderID, + gfx::Backend::Type type, + const std::string& additionalDefines) { observer->onShaderCompileFailed(shaderID, type, additionalDefines); } diff --git a/src/mbgl/shaders/gl/shader_program_gl.cpp b/src/mbgl/shaders/gl/shader_program_gl.cpp index b90375a0e66..f56920b091b 100644 --- a/src/mbgl/shaders/gl/shader_program_gl.cpp +++ b/src/mbgl/shaders/gl/shader_program_gl.cpp @@ -119,7 +119,8 @@ std::shared_ptr ShaderProgramGL::create( const std::string& fragmentSource, const std::string& additionalDefines) noexcept(false) { try { - context.getObserver().onPreCompileShader(programParameters.getProgramType(), gfx::Backend::Type::OpenGL, additionalDefines); + context.getObserver().onPreCompileShader( + programParameters.getProgramType(), gfx::Backend::Type::OpenGL, additionalDefines); // throws on compile error auto vertProg = context.createShader( @@ -139,7 +140,8 @@ std::shared_ptr ShaderProgramGL::create( fragmentSource.c_str()}); auto program = context.createProgram(vertProg, fragProg, firstAttribName.data()); - context.getObserver().onPostCompileShader(programParameters.getProgramType(), gfx::Backend::Type::OpenGL, additionalDefines); + context.getObserver().onPostCompileShader( + programParameters.getProgramType(), gfx::Backend::Type::OpenGL, additionalDefines); UniformBlockArrayGL uniformBlocks; for (const auto& blockInfo : uniformBlocksInfo) { @@ -183,7 +185,8 @@ std::shared_ptr ShaderProgramGL::create( return std::make_shared( std::move(program), std::move(uniformBlocks), std::move(attrs), std::move(samplerLocations)); } catch (const std::exception& e) { - context.getObserver().onShaderCompileFailed(programParameters.getProgramType(), gfx::Backend::Type::OpenGL, additionalDefines); + context.getObserver().onShaderCompileFailed( + programParameters.getProgramType(), gfx::Backend::Type::OpenGL, additionalDefines); std::rethrow_exception(std::current_exception()); } } diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp index 4fbcac721ee..549854d46ed 100644 --- a/src/mbgl/tile/geometry_tile.hpp +++ b/src/mbgl/tile/geometry_tile.hpp @@ -29,7 +29,7 @@ class TileAtlasTextures; class GeometryTile : public Tile, public GlyphRequestor, public ImageRequestor { public: const std::thread::id renderThreadID = std::this_thread::get_id(); - + GeometryTile(const OverscaledTileID&, std::string sourceID, const TileParameters&, diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index be851fbffee..4677e6a0bf6 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -1717,12 +1717,14 @@ TEST(Map, ObserveTileLifecycle) { std::lock_guard lock(tileMutex); tileOps.push_back(TileEntry{id, sourceID, op}); }; - observer.onPreCompileShaderCallback = [&](shaders::BuiltIn id, gfx::Backend::Type type, const std::string& additionalDefines) { - shaderOps.push_back(ShaderEntry{id, type, additionalDefines, false}); - }; - observer.onPostCompileShaderCallback = [&](shaders::BuiltIn id, gfx::Backend::Type type, const std::string& additionalDefines) { - shaderOps.push_back(ShaderEntry{id, type, additionalDefines, true}); - }; + observer.onPreCompileShaderCallback = + [&](shaders::BuiltIn id, gfx::Backend::Type type, const std::string& additionalDefines) { + shaderOps.push_back(ShaderEntry{id, type, additionalDefines, false}); + }; + observer.onPostCompileShaderCallback = + [&](shaders::BuiltIn id, gfx::Backend::Type type, const std::string& additionalDefines) { + shaderOps.push_back(ShaderEntry{id, type, additionalDefines, true}); + }; HeadlessFrontend frontend{{512, 512}, 1}; MapAdapter map( @@ -1743,23 +1745,25 @@ TEST(Map, ObserveTileLifecycle) { auto img = frontend.render(map).image; test::checkImage("test/fixtures/map/tile_lifecycle", img, 0.0002, 0.1); - + std::unordered_map seen; for (auto& shader : shaderOps) { auto shaderStr = std::to_string(static_cast(shader.id)) + shader.defines; auto it = seen.find(shaderStr); if (it != seen.end()) continue; seen.insert({shaderStr, true}); - Log::Info(Event::General, std::to_string(static_cast(shader.id)) + " " + std::to_string(std::hash()(shader.defines))); + Log::Info(Event::General, + std::to_string(static_cast(shader.id)) + " " + + std::to_string(std::hash()(shader.defines))); } - + // We expect to see a valid shader lifecycle for every entry in this list. const std::vector> expectedShaders = { {shaders::BuiltIn::FillShader, 16114602744458825542ULL}, {shaders::BuiltIn::FillOutlineShader, 16114602744458825542ULL}, }; - for (const auto& [id, defineHash] : expectedShaders) { + for (const auto& [id, defineHash] : expectedShaders) { bool seenPreEvent = false; for (const auto& op : shaderOps) { @@ -1779,21 +1783,21 @@ TEST(Map, ObserveTileLifecycle) { // We expect to see a valid lifecycle for every tile in this list. const std::vector expectedTiles = { - {10, 0, 10, 163, 395 }, - {10, 0, 10, 163, 396 }, - {10, 0, 10, 164, 395 }, - {10, 0, 10, 164, 396 }, - {9, 0, 9, 81, 197 }, - {9, 0, 9, 81, 198 }, - {9, 0, 9, 82, 197 }, - {9, 0, 9, 82, 198 }, - {8, 0, 8, 40, 98 }, - {8, 0, 8, 40, 99 }, - {8, 0, 8, 41, 98 }, - {8, 0, 8, 41, 99 }, - {7, 0, 7, 20, 49 }, - {6, 0, 6, 10, 24 }, - {5, 0, 5, 5, 12 }, + {10, 0, 10, 163, 395}, + {10, 0, 10, 163, 396}, + {10, 0, 10, 164, 395}, + {10, 0, 10, 164, 396}, + {9, 0, 9, 81, 197}, + {9, 0, 9, 81, 198}, + {9, 0, 9, 82, 197}, + {9, 0, 9, 82, 198}, + {8, 0, 8, 40, 98}, + {8, 0, 8, 40, 99}, + {8, 0, 8, 41, 98}, + {8, 0, 8, 41, 99}, + {7, 0, 7, 20, 49}, + {6, 0, 6, 10, 24}, + {5, 0, 5, 5, 12}, // Lower zooms can also be seen, but not always, so we // ignore them. }; @@ -1810,11 +1814,10 @@ TEST(Map, ObserveTileLifecycle) { break; } case TileOperation::RequestedFromNetwork: { - EXPECT_THAT(stage, testing::AnyOf( - TileOperation::StartParse, - TileOperation::EndParse, - TileOperation::RequestedFromCache - )); + EXPECT_THAT( + stage, + testing::AnyOf( + TileOperation::StartParse, TileOperation::EndParse, TileOperation::RequestedFromCache)); stage = TileOperation::RequestedFromNetwork; break; } @@ -1844,14 +1847,15 @@ TEST(Map, ObserveTileLifecycle) { break; } case TileOperation::EndParse: { - // The tile loader will try the cache first. If a cache hit is found, it starts parsing it while loading - // from the network. In the event data the cache is invalid, the network request will return newer data - // and update the geometry tile worker, which was already parsing the cached data. + // The tile loader will try the cache first. If a cache hit is found, it starts parsing it while + // loading from the network. In the event data the cache is invalid, the network request will return + // newer data and update the geometry tile worker, which was already parsing the cached data. EXPECT_THAT(stage, testing::AnyOf(TileOperation::StartParse, TileOperation::LoadFromNetwork)); stage = TileOperation::EndParse; break; } - case TileOperation::NullOp: [[fallthrough]]; + case TileOperation::NullOp: + [[fallthrough]]; case TileOperation::Error: { ADD_FAILURE(); break; diff --git a/test/src/mbgl/test/stub_map_observer.hpp b/test/src/mbgl/test/stub_map_observer.hpp index fc7d36dbaf4..76972a62dc9 100644 --- a/test/src/mbgl/test/stub_map_observer.hpp +++ b/test/src/mbgl/test/stub_map_observer.hpp @@ -62,7 +62,9 @@ class StubMapObserver : public MapObserver { } } - void onShaderCompileFailed(shaders::BuiltIn id, gfx::Backend::Type type, const std::string& additionalDefines) final { + void onShaderCompileFailed(shaders::BuiltIn id, + gfx::Backend::Type type, + const std::string& additionalDefines) final { if (onShaderCompileFailedCallback) { onShaderCompileFailedCallback(id, type, additionalDefines); }