#pragma once #include #include #include #include #include #include #include #include namespace mbgl { template class ActorRef; class Mailbox; class Renderer; class RendererBackend; class RendererObserver; class ThreadPool; class UpdateParameters; namespace android { class AndroidRendererBackend; /** * The MapRenderer is a peer class that encapsulates the actions * performed on the GL Thread. * * The public methods are safe to call from the main thread, others are not. */ class MapRenderer : public Scheduler { public: static constexpr auto Name() { return "com/mapbox/mapboxsdk/maps/renderer/MapRenderer"; }; static void registerNative(jni::JNIEnv&); static MapRenderer& getNativePeer(JNIEnv&, const jni::Object&); MapRenderer(jni::JNIEnv& _env, const jni::Object&, jni::jfloat pixelRatio, const jni::String& localIdeographFontFamily); ~MapRenderer() override; // Resets the renderer to clean up on the calling thread void reset(); // Takes the RendererObserver by shared_ptr so we // don't have to make the header public. Use // this instead of Renderer#setObserver directly void setObserver(std::shared_ptr); // Sets the new update parameters to use on subsequent // renders. Be sure to trigger a render with // requestRender(). void update(std::shared_ptr); // Gives a handle to the Renderer to enable actions on // any thread. ActorRef actor() const; // From Scheduler. Schedules by using callbacks to the // JVM to process the mailbox on the right thread. void schedule(std::function scheduled) override; void requestRender(); // Snapshot - requires a RunLoop on the calling thread using SnapshotCallback = std::function; void requestSnapshot(SnapshotCallback); protected: // Called from the GL Thread // void scheduleSnapshot(std::unique_ptr); private: // Called from the GL Thread // // Resets the renderer void resetRenderer(); // Renders a frame. void render(JNIEnv&); void onSurfaceCreated(JNIEnv&); void onSurfaceChanged(JNIEnv&, jint width, jint height); void onSurfaceDestroyed(JNIEnv&); private: // Called on either Main or GL thread // void onRendererReset(JNIEnv&); private: jni::WeakReference, jni::EnvAttachingDeleter> javaPeer; float pixelRatio; optional localIdeographFontFamily; std::shared_ptr threadPool; std::shared_ptr mailbox; std::mutex initialisationMutex; std::shared_ptr rendererObserver; std::unique_ptr backend; std::unique_ptr renderer; std::unique_ptr> rendererRef; std::shared_ptr updateParameters; std::mutex updateMutex; bool framebufferSizeChanged = false; std::atomic destroyed {false}; std::unique_ptr snapshotCallback; }; } // namespace android } // namespace mbgl