Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 28, 2024
1 parent b188487 commit acb6cea
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 63 deletions.
6 changes: 3 additions & 3 deletions include/mbgl/renderer/renderer_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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&) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
42 changes: 30 additions & 12 deletions platform/android/MapLibreAndroid/src/cpp/native_map_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<NativeMapView>::Singleton(*_env);
static auto onPreCompileShader = javaClass.GetMethod<void(jni::jint, jni::jint, jni::String)>(*_env, "onPreCompileShader");
static auto onPreCompileShader = javaClass.GetMethod<void(jni::jint, jni::jint, jni::String)>(*_env,
"onPreCompileShader");
auto weakReference = javaPeer.get(*_env);
if (weakReference) {
weakReference.Call(*_env, onPreCompileShader, static_cast<jni::jint>(id), static_cast<jni::jint>(type),
jni::Make<jni::String>(additionalDefines));
weakReference.Call(*_env,
onPreCompileShader,
static_cast<jni::jint>(id),
static_cast<jni::jint>(type),
jni::Make<jni::String>(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<NativeMapView>::Singleton(*_env);
static auto onPostCompileShader = javaClass.GetMethod<void(jni::jint, jni::jint, jni::String)>(*_env, "onPostCompileShader");
static auto onPostCompileShader = javaClass.GetMethod<void(jni::jint, jni::jint, jni::String)>(
*_env, "onPostCompileShader");
auto weakReference = javaPeer.get(*_env);
if (weakReference) {
weakReference.Call(*_env, onPostCompileShader, static_cast<jni::jint>(id), static_cast<jni::jint>(type),
jni::Make<jni::String>(additionalDefines));
weakReference.Call(*_env,
onPostCompileShader,
static_cast<jni::jint>(id),
static_cast<jni::jint>(type),
jni::Make<jni::String>(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<NativeMapView>::Singleton(*_env);
static auto onShaderCompileFailed = javaClass.GetMethod<void(jni::jint, jni::jint, jni::String)>(*_env, "onShaderCompileFailed");
static auto onShaderCompileFailed = javaClass.GetMethod<void(jni::jint, jni::jint, jni::String)>(
*_env, "onShaderCompileFailed");
auto weakReference = javaPeer.get(*_env);
if (weakReference) {
weakReference.Call(*_env, onShaderCompileFailed, static_cast<jni::jint>(id), static_cast<jni::jint>(type),
jni::Make<jni::String>(additionalDefines));
weakReference.Call(*_env,
onShaderCompileFailed,
static_cast<jni::jint>(id),
static_cast<jni::jint>(type),
jni::Make<jni::String>(additionalDefines));
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/mbgl/map/map_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 9 additions & 3 deletions src/mbgl/renderer/renderer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 6 additions & 3 deletions src/mbgl/shaders/gl/shader_program_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ std::shared_ptr<ShaderProgramGL> 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(
Expand All @@ -139,7 +140,8 @@ std::shared_ptr<ShaderProgramGL> 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) {
Expand Down Expand Up @@ -183,7 +185,8 @@ std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create(
return std::make_shared<ShaderProgramGL>(
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());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/tile/geometry_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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&,
Expand Down
72 changes: 38 additions & 34 deletions test/map/map.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1717,12 +1717,14 @@ TEST(Map, ObserveTileLifecycle) {
std::lock_guard<std::mutex> 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(
Expand All @@ -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<std::string, bool> seen;
for (auto& shader : shaderOps) {
auto shaderStr = std::to_string(static_cast<size_t>(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<size_t>(shader.id)) + " " + std::to_string(std::hash<std::string>()(shader.defines)));
Log::Info(Event::General,
std::to_string(static_cast<size_t>(shader.id)) + " " +
std::to_string(std::hash<std::string>()(shader.defines)));
}

// We expect to see a valid shader lifecycle for every entry in this list.
const std::vector<std::pair<shaders::BuiltIn, size_t>> 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) {
Expand All @@ -1779,21 +1783,21 @@ TEST(Map, ObserveTileLifecycle) {

// We expect to see a valid lifecycle for every tile in this list.
const std::vector<OverscaledTileID> 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.
};
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion test/src/mbgl/test/stub_map_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit acb6cea

Please sign in to comment.