Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clang-format #1086

Merged
merged 12 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 19 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: Inline
BinPackArguments: false
BinPackParameters: false
ColumnLimit: 120
IncludeBlocks: Preserve
IndentWidth: 4
Language: Cpp
PackConstructorInitializers: Never
PenaltyBreakAssignment: 80
SortIncludes: false
SpacesBeforeTrailingComments: 1
Standard: c++17
...
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v14.0.6
hooks:
- id: clang-format
files: '.*\.(hpp|cpp|h)'
exclude: '(vendor/.*|platform/(ios|darwin)/.*|test/ios/.*|render-test/ios/.*|benchmark/ios/.*)'
15 changes: 15 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Developing


## Pre-commit hooks

Install [pre-commit](https://pre-commit.com/) and run

```
pre-commit install
```

to install the pre-commit hooks configured in `.pre-commit-config.yml`.

## Render Tests

To check that the output of the rendering is correct, we compare actual rendered PNGs for simple styles with expected PNGs. The content of the tests is stored in the MapLibre GL JS submodule which means that GL JS and Native are in fact quasi pixel-identical in their rendering.
Expand Down Expand Up @@ -76,6 +87,7 @@ or any of the platform make files:
* iOS developers can use [Xcode](https://developer.apple.com/support/debugging/). See also [Advanced Debugging with Xcode and LLDB](https://developer.apple.com/videos/play/wwdc2018/412/).

## Static Analysis

We use [`clang-tidy`](https://clang.llvm.org/extra/clang-tidy/) for static analysis and run it on CI for each pull request. If you want to run it locally use `-DMLN_WITH_CLANG_TIDY=ON` CMake option and just run regular build. For the list of enabled checks please see:
[`.clang-tidy`](.clang-tidy) and [`test/.clang-tidy`](test/.clang-tidy)(for tests we are less strict and use different set of checks).

Expand Down Expand Up @@ -166,3 +178,6 @@ autoload -Uz compinit && compinit
### Kotlin and Java compatibility

We are moving the Android SDK to Kotlin, which is backward compatible with Java, but if you need a Java version of the Android SDK there is a `before-kotlin-port` tag available.



23 changes: 13 additions & 10 deletions benchmark/api/query.benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ class QueryBenchmark {
NetworkStatus::Set(NetworkStatus::Status::Offline);

map.getStyle().loadJSON(util::read_file("benchmark/fixtures/api/style.json"));
map.jumpTo(CameraOptions().withCenter(LatLng { 40.726989, -73.992857 }).withZoom(15.0)); // Manhattan
map.getStyle().addImage(std::make_unique<style::Image>("test-icon",
decodeImage(util::read_file("benchmark/fixtures/api/default_marker.png")), 1.0f));
map.jumpTo(CameraOptions().withCenter(LatLng{40.726989, -73.992857}).withZoom(15.0)); // Manhattan
map.getStyle().addImage(std::make_unique<style::Image>(
"test-icon", decodeImage(util::read_file("benchmark/fixtures/api/default_marker.png")), 1.0f
));

frontend.render(map);
}

util::RunLoop loop;
HeadlessFrontend frontend { { 1000, 1000 }, 1 };
Map map { frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()),
ResourceOptions().withCachePath("benchmark/fixtures/api/cache.db").withAssetPath(".").withApiKey("foobar") };
ScreenBox box{{ 0, 0 }, { 1000, 1000 }};
HeadlessFrontend frontend{{1000, 1000}, 1};
Map map{
frontend,
MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()),
ResourceOptions().withCachePath("benchmark/fixtures/api/cache.db").withAssetPath(".").withApiKey("foobar")};
ScreenBox box{{0, 0}, {1000, 1000}};
};

} // end namespace
Expand Down Expand Up @@ -74,15 +77,15 @@ static void API_queryRenderedFeaturesLayerFromLowDensity(::benchmark::State& sta
QueryBenchmark bench;

while (state.KeepRunning()) {
bench.frontend.getRenderer()->queryRenderedFeatures(bench.box, {{{ "testlayer" }}, {}});
bench.frontend.getRenderer()->queryRenderedFeatures(bench.box, {{{"testlayer"}}, {}});
}
}

static void API_queryRenderedFeaturesLayerFromHighDensity(::benchmark::State& state) {
QueryBenchmark bench;

while (state.KeepRunning()) {
bench.frontend.getRenderer()->queryRenderedFeatures(bench.box, {{{"road-street" }}, {}});
bench.frontend.getRenderer()->queryRenderedFeatures(bench.box, {{{"road-street"}}, {}});
}
}
BENCHMARK(API_queryPixelsForLatLngs);
Expand Down
72 changes: 40 additions & 32 deletions benchmark/api/render.benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@ using namespace mbgl;

namespace {

static std::string cachePath { "benchmark/fixtures/api/cache.db" };
constexpr double pixelRatio { 1.0 };
constexpr Size size { 1000, 1000 };
static std::string cachePath{"benchmark/fixtures/api/cache.db"};
constexpr double pixelRatio{1.0};
constexpr Size size{1000, 1000};

class RenderBenchmark {
public:
RenderBenchmark() {
NetworkStatus::Set(NetworkStatus::Status::Offline);
}
RenderBenchmark() { NetworkStatus::Set(NetworkStatus::Status::Offline); }

util::RunLoop loop;
};

void prepare(Map& map, std::optional<std::string> json = std::nullopt) {
map.getStyle().loadJSON(json ? *json : util::read_file("benchmark/fixtures/api/style.json"));
map.jumpTo(CameraOptions().withCenter(LatLng { 40.726989, -73.992857 }).withZoom(15.0)); // Manhattan
map.jumpTo(CameraOptions().withCenter(LatLng{40.726989, -73.992857}).withZoom(15.0)); // Manhattan

auto image = decodeImage(util::read_file("benchmark/fixtures/api/default_marker.png"));
map.getStyle().addImage(std::make_unique<style::Image>("test-icon", std::move(image), 1.0f));
Expand All @@ -55,10 +53,12 @@ void prepare_map2(Map& map, std::optional<std::string> json = std::nullopt) {

static void API_renderStill_reuse_map(::benchmark::State& state) {
RenderBenchmark bench;
HeadlessFrontend frontend { size, pixelRatio };
Map map { frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withApiKey("foobar") };
HeadlessFrontend frontend{size, pixelRatio};
Map map{
frontend,
MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withApiKey("foobar")};
prepare(map);

for (auto _ : state) {
Expand All @@ -68,10 +68,12 @@ static void API_renderStill_reuse_map(::benchmark::State& state) {

static void API_renderStill_reuse_map_formatted_labels(::benchmark::State& state) {
RenderBenchmark bench;
HeadlessFrontend frontend { size, pixelRatio };
Map map { frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withApiKey("foobar") };
HeadlessFrontend frontend{size, pixelRatio};
Map map{
frontend,
MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withApiKey("foobar")};
prepare(map, util::read_file("benchmark/fixtures/api/style_formatted_labels.json"));

for (auto _ : state) {
Expand All @@ -81,13 +83,15 @@ static void API_renderStill_reuse_map_formatted_labels(::benchmark::State& state

static void API_renderStill_reuse_map_switch_styles(::benchmark::State& state) {
RenderBenchmark bench;
HeadlessFrontend frontend { size, pixelRatio };
Map map { frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withApiKey("foobar") };
HeadlessFrontend frontend{size, pixelRatio};
Map map{
frontend,
MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withApiKey("foobar")};

for (auto _ : state) {
prepare(map, { "{}" });
prepare(map, {"{}"});
frontend.render(map);
prepare(map);
frontend.render(map);
Expand All @@ -98,10 +102,12 @@ static void API_renderStill_recreate_map(::benchmark::State& state) {
RenderBenchmark bench;

for (auto _ : state) {
HeadlessFrontend frontend { size, pixelRatio };
Map map { frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withApiKey("foobar") };
HeadlessFrontend frontend{size, pixelRatio};
Map map{
frontend,
MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withApiKey("foobar")};
prepare(map);
frontend.render(map);
}
Expand All @@ -112,10 +118,11 @@ static void API_renderStill_recreate_map_2(::benchmark::State& state) {

for (auto _ : state) {
HeadlessFrontend frontend{size, pixelRatio};
Map map{frontend,
MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withApiKey("foobar")};
Map map{
frontend,
MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withApiKey("foobar")};
prepare_map2(map);
frontend.render(map);
}
Expand All @@ -125,10 +132,11 @@ static void API_renderStill_multiple_sources(::benchmark::State& state) {
using namespace mbgl::style;
RenderBenchmark bench;
HeadlessFrontend frontend{size, pixelRatio};
Map map{frontend,
MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withApiKey("foobar")};
Map map{
frontend,
MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withApiKey("foobar")};
prepare(map);
auto& style = map.getStyle();
const int kSourcesCount = 50;
Expand Down
24 changes: 12 additions & 12 deletions benchmark/function/camera_function.benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ static std::string createFunctionJSON(size_t stopCount) {

static void Parse_CameraFunction(benchmark::State& state) {
size_t stopCount = state.range(0);

while (state.KeepRunning()) {
conversion::Error error;
state.PauseTiming();
auto doc = createFunctionJSON(stopCount);
state.ResumeTiming();
std::optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(doc, error, false, false);
std::optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(
doc, error, false, false
);
if (!result) {
state.SkipWithError(error.message.c_str());
}
Expand All @@ -39,23 +41,21 @@ static void Evaluate_CameraFunction(benchmark::State& state) {
size_t stopCount = state.range(0);
auto doc = createFunctionJSON(stopCount);
conversion::Error error;
std::optional<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(doc, error, false, false);
std::optional<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(
doc, error, false, false
);
if (!function) {
state.SkipWithError(error.message.c_str());
}
while(state.KeepRunning()) {

while (state.KeepRunning()) {
float z = 24.0f * static_cast<float>(rand() % 100) / 100;
function->asExpression().evaluate(z);
}

state.SetLabel(std::to_string(stopCount).c_str());
}

BENCHMARK(Parse_CameraFunction)
->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);

BENCHMARK(Evaluate_CameraFunction)
->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);

BENCHMARK(Parse_CameraFunction)->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);

BENCHMARK(Evaluate_CameraFunction)->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);
24 changes: 13 additions & 11 deletions benchmark/function/composite_function.benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static std::string createFunctionJSON(size_t stopCount) {
std::string value = std::to_string(100.0f / stopCount * innerStop);

if (stops.size() > 1) stops += ",";
stops += R"([{"zoom":)" + zoom + R"(,"value":)" + value + "}, " + value + "]";
stops += R"([{"zoom":)" + zoom + R"(,"value":)" + value + "}, " + value + "]";
}
}
stops += "]";
Expand All @@ -33,7 +33,9 @@ static void Parse_CompositeFunction(benchmark::State& state) {
state.PauseTiming();
auto doc = createFunctionJSON(stopCount);
state.ResumeTiming();
std::optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(doc, error, true, false);
std::optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(
doc, error, true, false
);
if (!result) {
state.SkipWithError(error.message.c_str());
}
Expand All @@ -45,23 +47,23 @@ static void Evaluate_CompositeFunction(benchmark::State& state) {
size_t stopCount = state.range(0);
auto doc = createFunctionJSON(stopCount);
conversion::Error error;
std::optional<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(doc, error, true, false);
std::optional<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(
doc, error, true, false
);
if (!function) {
state.SkipWithError(error.message.c_str());
}

while(state.KeepRunning()) {
while (state.KeepRunning()) {
float z = 24.0f * static_cast<float>(rand() % 100) / 100;
function->asExpression().evaluate(z, StubGeometryTileFeature(PropertyMap { { "x", static_cast<int64_t>(rand() % 100) } }), -1.0f);
function->asExpression().evaluate(
z, StubGeometryTileFeature(PropertyMap{{"x", static_cast<int64_t>(rand() % 100)}}), -1.0f
);
}

state.SetLabel(std::to_string(stopCount).c_str());
}

BENCHMARK(Parse_CompositeFunction)
->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);

BENCHMARK(Evaluate_CompositeFunction)
->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);

BENCHMARK(Parse_CompositeFunction)->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);

BENCHMARK(Evaluate_CompositeFunction)->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);
22 changes: 12 additions & 10 deletions benchmark/function/source_function.benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ static void Parse_SourceFunction(benchmark::State& state) {
state.PauseTiming();
auto doc = createFunctionJSON(stopCount);
state.ResumeTiming();
std::optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(doc, error, true, false);
std::optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(
doc, error, true, false
);
if (!result) {
state.SkipWithError(error.message.c_str());
}
Expand All @@ -40,22 +42,22 @@ static void Evaluate_SourceFunction(benchmark::State& state) {
size_t stopCount = state.range(0);
auto doc = createFunctionJSON(stopCount);
conversion::Error error;
std::optional<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(doc, error, true, false);
std::optional<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(
doc, error, true, false
);
if (!function) {
state.SkipWithError(error.message.c_str());
}

while(state.KeepRunning()) {
function->asExpression().evaluate(StubGeometryTileFeature(PropertyMap { { "x", static_cast<int64_t>(rand() % 100) } }), -1.0f);
while (state.KeepRunning()) {
function->asExpression().evaluate(
StubGeometryTileFeature(PropertyMap{{"x", static_cast<int64_t>(rand() % 100)}}), -1.0f
);
}

state.SetLabel(std::to_string(stopCount).c_str());
}

BENCHMARK(Parse_SourceFunction)
->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);

BENCHMARK(Evaluate_SourceFunction)
->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);

BENCHMARK(Parse_SourceFunction)->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);

BENCHMARK(Evaluate_SourceFunction)->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);
2 changes: 1 addition & 1 deletion benchmark/parse/filter.benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void Parse_Filter(benchmark::State& state) {

static void Parse_EvaluateFilter(benchmark::State& state) {
const style::Filter filter = parse(R"FILTER(["==", "foo", "bar"])FILTER");
const StubGeometryTileFeature feature = { {}, FeatureType::Unknown , {}, {{ "foo", std::string("bar") }} };
const StubGeometryTileFeature feature = {{}, FeatureType::Unknown, {}, {{"foo", std::string("bar")}}};
const style::expression::EvaluationContext context(&feature);

while (state.KeepRunning()) {
Expand Down
Loading