diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/coffeecatch/coffeecatch.h | 226 | ||||
-rw-r--r-- | include/coffeecatch/coffeejni.h | 133 | ||||
-rw-r--r-- | include/mbgl/android/jni.hpp | 40 | ||||
-rw-r--r-- | include/mbgl/android/native_map_view.hpp | 86 | ||||
-rw-r--r-- | include/mbgl/map/map.hpp | 29 | ||||
-rw-r--r-- | include/mbgl/platform/android/log_android.hpp | 24 | ||||
-rw-r--r-- | include/mbgl/platform/default/headless_view.hpp | 1 | ||||
-rw-r--r-- | include/mbgl/platform/event.hpp | 8 | ||||
-rw-r--r-- | include/mbgl/platform/gl.hpp | 12 | ||||
-rw-r--r-- | include/mbgl/storage/asset_request_baton.hpp | 38 | ||||
-rw-r--r-- | include/mbgl/storage/caching_http_file_source.hpp | 5 | ||||
-rw-r--r-- | include/mbgl/storage/http_request_baton.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/util/uv.hpp | 2 |
13 files changed, 600 insertions, 6 deletions
diff --git a/include/coffeecatch/coffeecatch.h b/include/coffeecatch/coffeecatch.h new file mode 100644 index 0000000000..3aa00ddd40 --- /dev/null +++ b/include/coffeecatch/coffeecatch.h @@ -0,0 +1,226 @@ +/* CoffeeCatch, a tiny native signal handler/catcher for JNI code. + * (especially for Android/Dalvik) + * + * Copyright (c) 2013, Xavier Roche (http://www.httrack.com/) + * All rights reserved. + * See the "License" section below for the licensing terms. + * + * Description: + * + * Allows to "gracefully" recover from a signal (segv, sibus...) as if it was + * a Java exception. It will not gracefully recover from allocator/mutexes + * corruption etc., however, but at least "most" gentle crashes (null pointer + * dereferencing, integer division, stack overflow etc.) should be handled + * without too much troubles. + * + * The handler is thread-safe, but client must have exclusive control on the + * signal handlers (ie. the library is installing its own signal handlers on + * top of the existing ones). + * + * You must build all your libraries with `-funwind-tables', to get proper + * unwinding information on all binaries. On ARM, you may also use the + * `--no-merge-exidx-entries` linker switch, to solve certain issues with + * unwinding (the switch is possibly not needed anymore). + * On Android, this can be achieved by using this line in the Android.mk file + * in each library block: + * LOCAL_CFLAGS := -funwind-tables -Wl,--no-merge-exidx-entries + * + * Example: + * + * COFFEE_TRY() { + * call_some_native_function() + * } COFFEE_CATCH() { + * const char*const message = coffeecatch_get_message(); + * jclass cls = (*env)->FindClass(env, "java/lang/RuntimeException"); + * (*env)->ThrowNew(env, cls, strdup(message)); + * } COFFEE_END(); + * + * Implementation notes: + * + * Currently the library is installing both alternate stack and signal + * handlers for known signals (SIGABRT, SIGILL, SIGTRAP, SIGBUS, SIGFPE, + * SIGSEGV, SIGSTKFLT), and is using sigsetjmp()/siglongjmp() to return to + * "userland" (compared to signal handler context). As a security, an alarm + * is started as soon as a fatal signal is detected (ie. not something the + * JVM will handle) to kill the process after a grace period. Be sure your + * program will exit quickly after the error is caught, or call alarm(0) + * to cancel the pending time-bomb. + * The signal handlers had to be written with caution, because the virtual + * machine might be using signals (including SEGV) to handle JIT compiler, + * and some clever optimizations (such as NullPointerException handling) + * We are using several signal-unsafe functions, namely: + * - siglongjmp() to return to userland + * - pthread_getspecific() to get thread-specific setup + * + * License: + * + * Copyright (c) 2013, Xavier Roche (http://www.httrack.com/) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef COFFEECATCH_H +#define COFFEECATCH_H + +#include <stdint.h> +#include <sys/types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Setup crash handler to enter in a protected section. If a recognized signal + * is received in this section, the execution will be diverted to the + * COFFEE_CATCH() block. + * + * Note: you MUST use the following pattern when using this macro: + * COFFEE_TRY() { + * .. protected section without exit point + * } COFFEE_CATCH() { + * .. handler section without exit point + * } COFFEE_END(); + * + * You can not exit the protected section block, or the handler section block, + * using statements such as "return", because the cleanup code would not be + * executed. + * + * It is advised to enclose this complete try/catch/end block in a dedicated + * function declared extern or __attribute__ ((noinline)). + * + * Example: + * + * void my_native_function(JNIEnv* env, jobject object, jint *retcode) { + * COFFEE_TRY() { + * *retcode = call_dangerous_function(env, object); + * } COFFEE_CATCH() { + * const char*const message = coffeecatch_get_message(); + * jclass cls = (*env)->FindClass(env, "java/lang/RuntimeException"); + * (*env)->ThrowNew(env, cls, strdup(message)); + * *retcode = -1; + * } COFFEE_END(); + * } + * + * In addition, the following restrictions MUST be followed: + * - the function must be declared extern, or with the special attribute + * __attribute__ ((noinline)). + * - you must not use local variables before the complete try/catch/end block, + * or define them as "volatile". + * - your function should not ignore the crash silently, as the library will + * ensure the process is killed after a grace period (typically 30s) to + * prevent any deadlock that may occur if the crash was caught inside a + * non-signal-safe function, for example (such as malloc()). + * +COFFEE_TRY() + **/ + +/** + * Declare the signal handler block. This block will be executed if a signal + * was received, and recognized, in the previous COFFEE_TRY() {} section. + * You may call audit functions in this block, such as coffeecatch_get_signal() + * or coffeecatch_get_message(). + * +COFFEE_CATCH() + **/ + +/** + * Declare the end of the COFFEE_TRY()/COFFEE_CATCH() section. + * Diagnostic functions must not be called beyond this point. + * +COFFEE_END() + **/ + +/** + * Get the signal associated with the crash. + * This function can only be called inside a COFFEE_CATCH() block. + */ +extern int coffeecatch_get_signal(void); + +/** + * Get the full error message associated with the crash. + * This function can only be called inside a COFFEE_CATCH() block, and the + * returned pointer is only valid within this block. (you may want to copy + * the string in a static buffer, or use strdup()) + */ +const char* coffeecatch_get_message(void); + +/** + * Raise an abort() signal in the current thread. If the current code section + * is protected, the 'exp', 'file' and 'line' information are stored for + * further audit. + */ +extern void coffeecatch_abort(const char* exp, const char* file, int line); + +/** + * Assertion check. If the expression is false, an abort() signal is raised + * using coffeecatch_abort(). + */ +#define coffeecatch_assert(EXP) (void)( (EXP) || (coffeecatch_abort(#EXP, __FILE__, __LINE__), 0) ) + +/** + * Get the backtrace size, or 0 upon error. + * This function can only be called inside a COFFEE_CATCH() block. + */ +extern size_t coffeecatch_get_backtrace_size(void); + +/** + * Get the backtrace pointer, or 0 upon error. + * This function can only be called inside a COFFEE_CATCH() block. + */ +extern uintptr_t coffeecatch_get_backtrace(ssize_t index); + +/** + * Enumerate the backtrace with information. + * This function can only be called inside a COFFEE_CATCH() block. + */ +extern void coffeecatch_get_backtrace_info(void (*fun)(void *arg, + const char *module, + uintptr_t addr, + const char *function, + uintptr_t offset), void *arg); + +/** + * Cancel any pending alarm() triggered after a signal was caught. + * Calling this function is dangerous, because it exposes the process to + * a possible deadlock if the signal was caught due to internal low-level + * library error (mutex being in a locked state, for example). + */ +extern int coffeecatch_cancel_pending_alarm(void); + +/** Internal functions & definitions, not to be used directly. **/ +#include <setjmp.h> +extern int coffeecatch_setup(void); +extern sigjmp_buf* coffeecatch_get_ctx(void); +extern void coffeecatch_cleanup(void); +#define COFFEE_TRY() \ + if (coffeecatch_setup() == 0 \ + && sigsetjmp(*coffeecatch_get_ctx(), 1) == 0) +#define COFFEE_CATCH() else +#define COFFEE_END() coffeecatch_cleanup() +/** End of internal functions & definitions. **/ + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/coffeecatch/coffeejni.h b/include/coffeecatch/coffeejni.h new file mode 100644 index 0000000000..3d7fe1b289 --- /dev/null +++ b/include/coffeecatch/coffeejni.h @@ -0,0 +1,133 @@ +/* CoffeeCatch, a tiny native signal handler/catcher for JNI code. + * (especially for Android/Dalvik) + * + * Copyright (c) 2013, Xavier Roche (http://www.httrack.com/) + * All rights reserved. + * See the "License" section below for the licensing terms. + * + * Description: + * + * Allows to "gracefully" recover from a signal (segv, sibus...) as if it was + * a Java exception. It will not gracefully recover from allocator/mutexes + * corruption etc., however, but at least "most" gentle crashes (null pointer + * dereferencing, integer division, stack overflow etc.) should be handled + * without too much troubles. + * + * The handler is thread-safe, but client must have exclusive control on the + * signal handlers (ie. the library is installing its own signal handlers on + * top of the existing ones). + * + * You must build all your libraries with `-funwind-tables', to get proper + * unwinding information on all binaries. On ARM, you may also use the + * `--no-merge-exidx-entries` linker switch, to solve certain issues with + * unwinding (the switch is possibly not needed anymore). + * On Android, this can be achieved by using this line in the Android.mk file + * in each library block: + * LOCAL_CFLAGS := -funwind-tables -Wl,--no-merge-exidx-entries + * + * Example: + * COFFEE_TRY_JNI(env, *retcode = call_dangerous_function(env, object)); + * + * Implementation notes: + * + * Currently the library is installing both alternate stack and signal + * handlers for known signals (SIGABRT, SIGILL, SIGTRAP, SIGBUS, SIGFPE, + * SIGSEGV, SIGSTKFLT), and is using sigsetjmp()/siglongjmp() to return to + * "userland" (compared to signal handler context). As a security, an alarm + * is started as soon as a fatal signal is detected (ie. not something the + * JVM will handle) to kill the process after a grace period. Be sure your + * program will exit quickly after the error is caught, or call alarm(0) + * to cancel the pending time-bomb. + * The signal handlers had to be written with caution, because the virtual + * machine might be using signals (including SEGV) to handle JIT compiler, + * and some clever optimizations (such as NullPointerException handling) + * We are using several signal-unsafe functions, namely: + * - siglongjmp() to return to userland + * - pthread_getspecific() to get thread-specific setup + * + * License: + * + * Copyright (c) 2013, Xavier Roche (http://www.httrack.com/) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef COFFEECATCH_JNI_H +#define COFFEECATCH_JNI_H + +#include <jni.h> + +#include <coffeecatch/coffeecatch.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Setup crash handler to enter in a protected section. If a recognized signal + * is received in this section, an appropriate native Java Error will be + * raised. + * + * You can not exit the protected section block CODE_TO_BE_EXECUTED, using + * statements such as "return", because the cleanup code would not be + * executed. + * + * It is advised to enclose the complete CODE_TO_BE_EXECUTED block in a + * dedicated function declared extern or __attribute__ ((noinline)). + * + * You must build all your libraries with `-funwind-tables', to get proper + * unwinding information on all binaries. On Android, this can be achieved + * by using this line in the Android.mk file in each library block: + * LOCAL_CFLAGS := -funwind-tables + * + * Example: + * + * void my_native_function(JNIEnv* env, jobject object, jint *retcode) { + * COFFEE_TRY_JNI(env, *retcode = call_dangerous_function(env, object)); + * } + * + * In addition, the following restrictions MUST be followed: + * - the function must be declared extern, or with the special attribute + * __attribute__ ((noinline)). + * - you must not use local variables before the COFFEE_TRY_JNI block, + * or define them as "volatile". + * +COFFEE_TRY_JNI(JNIEnv* env, CODE_TO_BE_EXECUTED) + */ + +/** Internal functions & definitions, not to be used directly. **/ +extern void coffeecatch_throw_exception(JNIEnv* env); +#define COFFEE_TRY_JNI(ENV, CODE) \ + do { \ + COFFEE_TRY() { \ + CODE; \ + } COFFEE_CATCH() { \ + coffeecatch_throw_exception(ENV); \ + } COFFEE_END(); \ + } while(0) +/** End of internal functions & definitions. **/ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/mbgl/android/jni.hpp b/include/mbgl/android/jni.hpp new file mode 100644 index 0000000000..31772cf59c --- /dev/null +++ b/include/mbgl/android/jni.hpp @@ -0,0 +1,40 @@ +#ifndef MBGL_ANDROID_JNI +#define MBGL_ANDROID_JNI + +#include <string> +#include <jni.h> + +namespace mbgl { +namespace android { + +extern std::string cachePath; +extern std::string dataPath; +extern std::string apkPath; + +extern jmethodID onMapChangedId; +extern jmethodID onFpsChangedId; + +extern jclass lonLatClass; +extern jmethodID lonLatConstructorId; +extern jfieldID lonLatLonId; +extern jfieldID lonLatLatId; + +extern jclass lonLatZoomClass; +extern jmethodID lonLatZoomConstructorId; +extern jfieldID lonLatZoomLonId; +extern jfieldID lonLatZoomLatId; +extern jfieldID lonLatZoomZoomId; + +extern jclass runtimeExceptionClass; +extern jclass nullPointerExceptionClass;; + +extern jmethodID listToArrayId; + +extern jclass arrayListClass; +extern jmethodID arrayListConstructorId; +extern jmethodID arrayListAddId; + +} +} + +#endif diff --git a/include/mbgl/android/native_map_view.hpp b/include/mbgl/android/native_map_view.hpp new file mode 100644 index 0000000000..f8cf34d3b4 --- /dev/null +++ b/include/mbgl/android/native_map_view.hpp @@ -0,0 +1,86 @@ +#ifndef MBGL_ANDROID_NATIVE_MAP_VIEW +#define MBGL_ANDROID_NATIVE_MAP_VIEW + +#include <mbgl/map/map.hpp> +#include <mbgl/map/view.hpp> +#include <mbgl/util/noncopyable.hpp> +#include <mbgl/storage/caching_http_file_source.hpp> + +#include <string> +#include <jni.h> +#include <android/native_window.h> +#include <EGL/egl.h> + +namespace mbgl { +namespace android { + +class NativeMapView : public mbgl::View, private mbgl::util::noncopyable { +public: + NativeMapView(JNIEnv* env, jobject obj); + virtual ~NativeMapView(); + + void make_active() override; + void make_inactive() override; + + void swap() override; + + void notify() override; + void notify_map_change(mbgl::MapChange change, mbgl::timestamp delay) override; + + mbgl::Map& getMap(); + mbgl::CachingHTTPFileSource& getFileSource(); + + bool initializeDisplay(); + void terminateDisplay(); + + bool initializeContext(); + void terminateContext(); + + bool createSurface(ANativeWindow* window); + void destroySurface(); + + void start(); + void stop(); + + void resume(); + void pause(bool waitForPause = false); + + void enableFps(bool enable); + void updateFps(); + +private: + EGLConfig chooseConfig(const EGLConfig configs[], EGLint numConfigs); + + void loadExtensions(); + +private: + JavaVM* vm = nullptr; + jobject obj = nullptr; + + ANativeWindow* window = nullptr; + + mbgl::CachingHTTPFileSource fileSource; + mbgl::Map map; + + EGLDisplay display = EGL_NO_DISPLAY; + EGLSurface surface = EGL_NO_SURFACE; + EGLContext context = EGL_NO_CONTEXT; + + EGLConfig config = nullptr; + EGLint format = -1; + + std::string styleUrl; + std::string apiKey; + + bool firstTime = false; + + bool usingDepth24 = false; + + bool fpsEnabled = false; + double fps = 0.0; +}; + +} +} + +#endif diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 245aaf9ea7..750dbbe023 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -13,6 +13,8 @@ #include <iosfwd> #include <set> #include <vector> +#include <mutex> +#include <condition_variable> #include <functional> namespace mbgl { @@ -37,7 +39,7 @@ public: ~Map(); // Start the map render thread. It is asynchronous. - void start(); + void start(bool startPaused = false); // Stop the map render thread. This call will block until the map rendering thread stopped. // The optional callback function will be invoked repeatedly until the map thread is stopped. @@ -45,6 +47,12 @@ public: // this will be a busy waiting loop. void stop(std::function<void ()> callback = std::function<void ()>()); + // Pauses the render thread. The render thread will stop running but will not be terminated and will not lose state until resumed. + void pause(bool waitForPause = false); + + // Resumes a paused render thread + void resume(); + // Runs the map event loop. ONLY run this function when you want to get render a single frame // with this map object. It will *not* spawn a separate thread and instead block until the // frame is completely rendered. @@ -65,13 +73,14 @@ public: // Size void resize(uint16_t width, uint16_t height, float ratio = 1); - void resize(uint16_t width, uint16_t height, float ratio, uint16_t fb_width, uint16_t fb_height); + void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight); // Styling void setAppliedClasses(const std::vector<std::string> &classes); void toggleClass(const std::string &name); const std::vector<std::string> &getAppliedClasses() const; void setDefaultTransitionDuration(uint64_t milliseconds = 0); + uint64_t getDefaultTransitionDuration(); void setStyleURL(const std::string &url); void setStyleJSON(std::string newStyleJSON, const std::string &base = ""); std::string getStyleJSON() const; @@ -122,6 +131,9 @@ private: util::ptr<Sprite> getSprite(); uv::worker& getWorker(); + // Checks if render thread needs to pause + void checkForPause(); + // Setup void setup(); @@ -143,6 +155,14 @@ private: std::unique_ptr<uv::async> asyncTerminate; std::unique_ptr<uv::async> asyncRender; + bool terminating = false; + bool pausing = false; + bool isPaused = false; + std::mutex mutexRun; + std::condition_variable condRun; + std::mutex mutexPause; + std::condition_variable condPause; + // If cleared, the next time the render thread attempts to render the map, it will *actually* // render the map. std::atomic_flag isClean = ATOMIC_FLAG_INIT; @@ -182,6 +202,11 @@ private: std::string styleURL; std::string styleJSON = ""; + std::atomic_uint_fast64_t defaultTransitionDuration; + + util::ptr<std::vector<std::string>> appliedClasses; + std::mutex appliedClassesMutex; + bool debug = false; timestamp animationTime = 0; diff --git a/include/mbgl/platform/android/log_android.hpp b/include/mbgl/platform/android/log_android.hpp new file mode 100644 index 0000000000..94d90a9b36 --- /dev/null +++ b/include/mbgl/platform/android/log_android.hpp @@ -0,0 +1,24 @@ +#ifndef MBGL_PLATFORM_ANDROID_LOG_ANDROID +#define MBGL_PLATFORM_ANDROID_LOG_ANDROID + +#include <mbgl/platform/log.hpp> + +namespace mbgl { + +class AndroidLogBackend : public LogBackend { +private: + int severityToPriority(EventSeverity severity); + +public: + inline ~AndroidLogBackend() = default; + + void record(EventSeverity severity, Event event, const std::string &msg); + void record(EventSeverity severity, Event event, const char* format, ...); + void record(EventSeverity severity, Event event, int64_t code); + void record(EventSeverity severity, Event event, int64_t code, const std::string &msg); +}; + + +} + +#endif diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp index 9d8acf70f7..f3b897e760 100644 --- a/include/mbgl/platform/default/headless_view.hpp +++ b/include/mbgl/platform/default/headless_view.hpp @@ -59,6 +59,7 @@ private: GLuint fbo = 0; GLuint fbo_depth_stencil = 0; GLuint fbo_color = 0; + bool usingGl3OrNewer = false; }; } diff --git a/include/mbgl/platform/event.hpp b/include/mbgl/platform/event.hpp index df2d8b03e9..5fd64119cc 100644 --- a/include/mbgl/platform/event.hpp +++ b/include/mbgl/platform/event.hpp @@ -32,7 +32,11 @@ enum class Event : uint8_t { Database, HttpRequest, Sprite, + Image, OpenGL, + JNI, + Android, + Crash }; MBGL_DEFINE_ENUM_CLASS(EventClass, Event, { @@ -45,7 +49,11 @@ MBGL_DEFINE_ENUM_CLASS(EventClass, Event, { { Event::Database, "Database" }, { Event::HttpRequest, "HttpRequest" }, { Event::Sprite, "Sprite" }, + { Event::Image, "Image" }, { Event::OpenGL, "OpenGL" }, + { Event::JNI, "JNI" }, + { Event::Android, "Android" }, + { Event::Crash, "Crash" }, { Event(-1), "Unknown" }, }); diff --git a/include/mbgl/platform/gl.hpp b/include/mbgl/platform/gl.hpp index 6a35ab8006..cb0fb4892c 100644 --- a/include/mbgl/platform/gl.hpp +++ b/include/mbgl/platform/gl.hpp @@ -17,7 +17,8 @@ #else #error Unsupported Apple platform #endif -#elif MBGL_USE_GLES2 +#elif __ANDROID__ + #define GL_GLEXT_PROTOTYPES #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> #else @@ -129,6 +130,14 @@ extern PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays; extern PFNGLGENVERTEXARRAYSPROC GenVertexArrays; extern PFNGLISVERTEXARRAYPROC IsVertexArray; +// GL_EXT_packed_depth_stencil / GL_OES_packed_depth_stencil +extern bool isPackedDepthStencilSupported; +#define GL_DEPTH24_STENCIL8 0x88F0 + +// GL_OES_depth24 +extern bool isDepth24Supported; +#define GL_DEPTH_COMPONENT24 0x81A6 + // GL_ARB_get_program_binary / GL_OES_get_program_binary #define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257 #define GL_PROGRAM_BINARY_LENGTH 0x8741 @@ -167,7 +176,6 @@ inline void start_group(const std::string &) {} inline void end_group() {} #endif - struct group { inline group(const std::string &str) { start_group(str); } ~group() { end_group(); }; diff --git a/include/mbgl/storage/asset_request_baton.hpp b/include/mbgl/storage/asset_request_baton.hpp new file mode 100644 index 0000000000..2cbb6c51c0 --- /dev/null +++ b/include/mbgl/storage/asset_request_baton.hpp @@ -0,0 +1,38 @@ +#ifndef MBGL_STORAGE_ASSET_REQUEST_BATON +#define MBGL_STORAGE_ASSET_REQUEST_BATON + +#include <mbgl/util/uv.hpp> +#include <thread> + +#include <uv.h> + +namespace mbgl { + +class AssetRequest; + +struct AssetRequestBaton { + AssetRequestBaton(AssetRequest *request_, const std::string &path, uv_loop_t *loop); + + const std::thread::id threadId; + AssetRequest *request = nullptr; + std::unique_ptr<uv::async> asyncRun; + std::string path; + bool canceled = false; + + void cancel(); + static void notifyError(AssetRequestBaton *ptr, const int code, const char *message); + static void notifySuccess(AssetRequestBaton *ptr, const std::string body); + static void cleanup(AssetRequestBaton *ptr); + + // IMPLEMENT THIS PLATFORM SPECIFIC FUNCTION: + + // Called to load the asset. Platform-specific implementation. + static void run(AssetRequestBaton *ptr); + +}; + + +} + + +#endif diff --git a/include/mbgl/storage/caching_http_file_source.hpp b/include/mbgl/storage/caching_http_file_source.hpp index 6d7d852d2a..655afa6396 100644 --- a/include/mbgl/storage/caching_http_file_source.hpp +++ b/include/mbgl/storage/caching_http_file_source.hpp @@ -29,6 +29,9 @@ public: // Set the Mapbox API access token void setAccessToken(std::string); + // Get the Mapbox API access token + std::string getAccessToken() const; + std::unique_ptr<Request> request(ResourceType type, const std::string &url); void prepare(std::function<void()> fn); @@ -37,7 +40,7 @@ public: void setReachability(bool reachable); private: - std::thread::id thread_id; + std::thread::id threadId; // Mapbox API access token. std::string accessToken; diff --git a/include/mbgl/storage/http_request_baton.hpp b/include/mbgl/storage/http_request_baton.hpp index 545f9e236c..11abfb71d4 100644 --- a/include/mbgl/storage/http_request_baton.hpp +++ b/include/mbgl/storage/http_request_baton.hpp @@ -48,7 +48,7 @@ struct HTTPRequestBaton { HTTPRequestBaton(const std::string &path); ~HTTPRequestBaton(); - const std::thread::id thread_id; + const std::thread::id threadId; const std::string path; HTTPRequest *request = nullptr; diff --git a/include/mbgl/util/uv.hpp b/include/mbgl/util/uv.hpp index 74ed9c87a8..f59037c1d8 100644 --- a/include/mbgl/util/uv.hpp +++ b/include/mbgl/util/uv.hpp @@ -16,6 +16,8 @@ class rwlock; class loop; class async; class worker; +class mutex; +class cond; } |