summaryrefslogtreecommitdiff
path: root/platform/android/src/map_renderer_runnable.hpp
blob: 46fb028d2697f3851c3a3dc92d2af619dcf70f07 (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
#pragma once

#include <mbgl/actor/mailbox.hpp>
#include <mbgl/actor/scheduler.hpp>

#include <memory>
#include <utility>

#include <jni/jni.hpp>

namespace mbgl {
namespace android {

/**
 * The MapRendererRunnable is a peer class that encapsulates
 * a scheduled mailbox in a Java Runnable so it can be
 * scheduled on the map renderer thread.
 *
 */
class MapRendererRunnable {
public:

    static constexpr auto Name() { return "com/mapbox/mapboxsdk/maps/renderer/MapRendererRunnable"; };

    static jni::Class<MapRendererRunnable> javaClass;

    static void registerNative(jni::JNIEnv&);

    MapRendererRunnable(jni::JNIEnv&, std::weak_ptr<Mailbox>);

    // Only for jni registration, unused
    MapRendererRunnable(jni::JNIEnv&) {
        assert(false);
    }

    ~MapRendererRunnable();

    void run(jni::JNIEnv&);

    // Transfers ownership of the Peer object to the caller
    jni::UniqueObject<MapRendererRunnable> peer();

private:
    jni::UniqueObject<MapRendererRunnable> javaPeer;
    std::weak_ptr<Mailbox> mailbox;
};

} // namespace android
} // namespace mbgl