Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
format codes
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin committed Mar 20, 2020
1 parent cd91d5e commit 12a060b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
37 changes: 18 additions & 19 deletions platform/android/src/snapshotter/map_snapshotter.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "map_snapshotter.hpp"

#include <mapbox/weak.hpp>
#include <mbgl/actor/scheduler.hpp>
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/actor/scheduler.hpp>

#include <mapbox/weak.hpp>

#include "../attach_env.hpp"
#include "map_snapshot.hpp"
Expand All @@ -15,14 +14,14 @@ namespace mbgl {
namespace android {

MapSnapshotter::DeleteOnThread::DeleteOnThread() = default;
MapSnapshotter::DeleteOnThread::DeleteOnThread(mapbox::base::WeakPtr<mbgl::Scheduler> weakScheduler_) : weakScheduler(weakScheduler_) {}
MapSnapshotter::DeleteOnThread::DeleteOnThread(mapbox::base::WeakPtr<mbgl::Scheduler> weakScheduler_)
: weakScheduler(weakScheduler_) {}

void MapSnapshotter::DeleteOnThread::operator()(mbgl::MapSnapshotter* p) const {
auto guard = weakScheduler.lock();
if (weakScheduler && weakScheduler.get() != mbgl::Scheduler::GetCurrent()) {
weakScheduler->schedule([ptr = std::shared_ptr<mbgl::MapSnapshotter>(p, DeleteOnThread(weakScheduler))] {
(void)ptr;
});
weakScheduler->schedule(
[ptr = std::shared_ptr<mbgl::MapSnapshotter>(p, DeleteOnThread(weakScheduler))] { (void)ptr; });
} else {
delete p;
}
Expand Down Expand Up @@ -55,13 +54,14 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
showLogo = _showLogo;

// Create the core snapshotter
snapshotter = std::unique_ptr<mbgl::MapSnapshotter, DeleteOnThread>(new mbgl::MapSnapshotter(
size,
pixelRatio,
mbgl::android::FileSource::getSharedResourceOptions(_env, _jFileSource),
*this,
_localIdeographFontFamily ? jni::Make<std::string>(_env, _localIdeographFontFamily) : optional<std::string>{}),
DeleteOnThread(mbgl::Scheduler::GetCurrent()->makeWeakPtr()));
snapshotter = std::unique_ptr<mbgl::MapSnapshotter, DeleteOnThread>(
new mbgl::MapSnapshotter(size,
pixelRatio,
mbgl::android::FileSource::getSharedResourceOptions(_env, _jFileSource),
*this,
_localIdeographFontFamily ? jni::Make<std::string>(_env, _localIdeographFontFamily)
: optional<std::string>{}),
DeleteOnThread(mbgl::Scheduler::GetCurrent()->makeWeakPtr()));

if (position) {
snapshotter->setCameraOptions(CameraPosition::getCameraOptions(_env, position, pixelRatio));
Expand Down Expand Up @@ -196,7 +196,7 @@ void MapSnapshotter::onStyleImageMissing(const std::string& imageName) {
void MapSnapshotter::addLayerAt(JNIEnv& env, jlong nativeLayerPtr, jni::jint index) {
assert(nativeLayerPtr != 0);
auto layers = snapshotter->getStyle().getLayers();
Layer* layer = reinterpret_cast<Layer*>(nativeLayerPtr);
auto* layer = reinterpret_cast<Layer*>(nativeLayerPtr);
// Check index
int numLayers = layers.size() - 1;
if (index > numLayers || index < 0) {
Expand All @@ -217,7 +217,7 @@ void MapSnapshotter::addLayerAt(JNIEnv& env, jlong nativeLayerPtr, jni::jint ind
void MapSnapshotter::addLayerBelow(JNIEnv& env, jlong nativeLayerPtr, const jni::String& below) {
assert(nativeLayerPtr != 0);

Layer* layer = reinterpret_cast<Layer*>(nativeLayerPtr);
auto* layer = reinterpret_cast<Layer*>(nativeLayerPtr);
try {
layer->addToStyle(
snapshotter->getStyle(),
Expand All @@ -230,7 +230,7 @@ void MapSnapshotter::addLayerBelow(JNIEnv& env, jlong nativeLayerPtr, const jni:

void MapSnapshotter::addLayerAbove(JNIEnv& env, jlong nativeLayerPtr, const jni::String& above) {
assert(nativeLayerPtr != 0);
Layer* layer = reinterpret_cast<Layer*>(nativeLayerPtr);
auto* layer = reinterpret_cast<Layer*>(nativeLayerPtr);

// Find the sibling
auto layers = snapshotter->getStyle().getLayers();
Expand All @@ -251,7 +251,6 @@ void MapSnapshotter::addLayerAbove(JNIEnv& env, jlong nativeLayerPtr, const jni:
jni::ThrowNew(env,
jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/CannotAddLayerException"),
std::string("Could not find layer: ").append(siblingId).c_str());
return;
} else if (index + 1 < layers.size()) {
// Place before the sibling
before = {layers.at(index + 1)->getID()};
Expand All @@ -269,7 +268,7 @@ void MapSnapshotter::addLayerAbove(JNIEnv& env, jlong nativeLayerPtr, const jni:
void MapSnapshotter::addSource(JNIEnv& env, const jni::Object<Source>& obj, jlong sourcePtr) {
assert(sourcePtr != 0);

Source* source = reinterpret_cast<Source*>(sourcePtr);
auto* source = reinterpret_cast<Source*>(sourcePtr);
try {
source->addToStyle(env, obj, snapshotter->getStyle());
} catch (const std::runtime_error& error) {
Expand Down
1 change: 1 addition & 0 deletions platform/android/src/snapshotter/map_snapshotter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class MapSnapshotter final : public mbgl::MapSnapshotterObserver {
DeleteOnThread();
explicit DeleteOnThread(mapbox::base::WeakPtr<mbgl::Scheduler>);
void operator()(mbgl::MapSnapshotter* p) const;

private:
mapbox::base::WeakPtr<mbgl::Scheduler> weakScheduler;
};
Expand Down

0 comments on commit 12a060b

Please sign in to comment.