summaryrefslogtreecommitdiff
path: root/platform/android/src/native_map_view.hpp
blob: 81274f3a24aa888e9d39abe79522bef5de763231 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma once

#include <mbgl/map/map.hpp>
#include <mbgl/map/view.hpp>
#include <mbgl/map/backend.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/storage/default_file_source.hpp>

#include <string>
#include <jni.h>

namespace mbgl {
namespace android {

class NativeMapView : public mbgl::View, public mbgl::Backend {
public:
    NativeMapView(JNIEnv *env, jobject obj, float pixelRatio, int availableProcessors, size_t totalMemory);
    virtual ~NativeMapView();

    // mbgl::View //

    void bind() override;

    // mbgl::Backend //

    void invalidate() override;
    void notifyMapChange(mbgl::MapChange) override;

    // JNI //

    mbgl::Map &getMap();
    mbgl::DefaultFileSource &getFileSource();

    void render();

    void enableFps(bool enable);

    void onViewportChanged(int width, int height);

    mbgl::EdgeInsets getInsets() { return insets;}
    void setInsets(mbgl::EdgeInsets insets_);

    void scheduleTakeSnapshot();

protected:
    // Unused //

    void activate() override {};
    void deactivate() override {};

private:
    void wake();
    void updateViewBinding();
    mbgl::Size getFramebufferSize() const;

    void resizeView(int width, int height);
    void resizeFramebuffer(int width, int height);

    void updateFps();

private:

    JavaVM *vm = nullptr;
    JNIEnv *env = nullptr;
    jweak obj = nullptr;

    std::string styleUrl;
    std::string apiKey;

    float pixelRatio;
    bool fpsEnabled = false;
    bool snapshot = false;
    double fps = 0.0;

    int width = 0;
    int height = 0;
    int fbWidth = 0;
    int fbHeight = 0;
    bool framebufferSizeChanged = true;

    int availableProcessors = 0;
    size_t totalMemory = 0;

    // Ensure these are initialised last
    std::unique_ptr<mbgl::util::RunLoop> runLoop;
    std::unique_ptr<mbgl::DefaultFileSource> fileSource;
    mbgl::ThreadPool threadPool;
    std::unique_ptr<mbgl::Map> map;
    mbgl::EdgeInsets insets;

};
}
}