summaryrefslogtreecommitdiff
path: root/platform/android/src/snapshotter/map_snapshotter.hpp
blob: 4cdf4bcf2b6a1892865ba1ee94deee18f37a0afb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once

#include <mbgl/map/map_snapshotter.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/util.hpp>

#include "../file_source.hpp"
#include "../geometry/lat_lng_bounds.hpp"
#include "../map/camera_position.hpp"

#include <jni/jni.hpp>
#include "../jni/generic_global_ref_deleter.hpp"

#include <memory>

namespace mbgl {
namespace android {

class SnapshotterRendererFrontend;

class MapSnapshotter {
public:

    static constexpr auto Name() { return "com/mapbox/mapboxsdk/snapshotter/MapSnapshotter"; };

    static jni::Class<MapSnapshotter> javaClass;

    static void registerNative(jni::JNIEnv&);

    MapSnapshotter(jni::JNIEnv&,
                   jni::Object<MapSnapshotter>,
                   jni::Object<FileSource>,
                   jni::jfloat pixelRatio,
                   jni::jint width,
                   jni::jint height,
                   jni::String styleURL,
                   jni::Object<LatLngBounds> region,
                   jni::Object<CameraPosition> position,
                   jni::jboolean showLogo,
                   jni::String programCacheDir);

    ~MapSnapshotter();

    void setStyleUrl(JNIEnv&, jni::String styleURL);

    void setSize(JNIEnv&, jni::jint width, jni::jint height);

    void setCameraPosition(JNIEnv&, jni::Object<CameraPosition> position);

    void setRegion(JNIEnv&, jni::Object<LatLngBounds> region);

    void start(JNIEnv&);

    void cancel(JNIEnv&);

private:
    MBGL_STORE_THREAD(tid);

    JavaVM *vm = nullptr;
    GenericUniqueWeakObject<MapSnapshotter> javaPeer;

    float pixelRatio;
    bool showLogo;

    std::shared_ptr<mbgl::ThreadPool> threadPool;
    std::unique_ptr<Actor<mbgl::MapSnapshotter::Callback>> snapshotCallback;
    std::unique_ptr<mbgl::MapSnapshotter> snapshotter;

    FileSource *jFileSource;
    void activateFilesource(JNIEnv&);
    void deactivateFilesource(JNIEnv&);
    bool activatedFilesource = false;
};

} // namespace android
} // namespace mbgl