summaryrefslogtreecommitdiff
path: root/include/mbgl/platform
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-07-16 18:53:56 -0700
committerKonstantin Käfer <mail@kkaefer.com>2014-07-16 18:53:56 -0700
commit4ea281c750c5afcc68f2832bb42d98a1cbce6735 (patch)
tree60bc7d3ccba2c54859e2e023997cc027cc67aea7 /include/mbgl/platform
parentc1a64dc5fa73b54cc5de77629781dfc74302a1e7 (diff)
downloadqtlocation-mapboxgl-4ea281c750c5afcc68f2832bb42d98a1cbce6735.tar.gz
rename llmr => mbgl
Diffstat (limited to 'include/mbgl/platform')
-rw-r--r--include/mbgl/platform/event.hpp79
-rw-r--r--include/mbgl/platform/gl.hpp83
-rw-r--r--include/mbgl/platform/log.hpp71
-rw-r--r--include/mbgl/platform/platform.hpp46
-rw-r--r--include/mbgl/platform/request.hpp48
5 files changed, 327 insertions, 0 deletions
diff --git a/include/mbgl/platform/event.hpp b/include/mbgl/platform/event.hpp
new file mode 100644
index 0000000000..b55c721c99
--- /dev/null
+++ b/include/mbgl/platform/event.hpp
@@ -0,0 +1,79 @@
+#ifndef MBGL_PLATFORM_EVENT
+#define MBGL_PLATFORM_EVENT
+
+#include <mbgl/util/enum.hpp>
+
+#include <cstdint>
+
+namespace mbgl {
+
+enum class EventSeverity : uint8_t {
+ Debug,
+ Info,
+ Test,
+ Warning,
+ Error,
+};
+
+MBGL_DEFINE_ENUM_CLASS(EventSeverityClass, EventSeverity, {
+ { EventSeverity::Debug, "DEBUG" },
+ { EventSeverity::Info, "INFO" },
+ { EventSeverity::Test, "TEST" },
+ { EventSeverity::Warning, "WARNING" },
+ { EventSeverity::Error, "ERROR" },
+ { EventSeverity(-1), "UNKNOWN" },
+});
+
+enum class Event : uint8_t {
+ General,
+ Setup,
+ Shader,
+ ParseStyle,
+ ParseTile,
+ Render,
+ HttpRequest,
+ Sprite,
+};
+
+MBGL_DEFINE_ENUM_CLASS(EventClass, Event, {
+ { Event::General, "General" },
+ { Event::Setup, "Setup" },
+ { Event::Shader, "Shader" },
+ { Event::ParseStyle, "ParseStyle" },
+ { Event::ParseTile, "ParseTile" },
+ { Event::Render, "Render" },
+ { Event::HttpRequest, "HttpRequest" },
+ { Event::Sprite, "Sprite" },
+ { Event(-1), "Unknown" },
+});
+
+
+struct EventPermutation {
+ const EventSeverity severity;
+ const Event event;
+
+ constexpr bool operator==(const EventPermutation &rhs) const {
+ return severity == rhs.severity && event == rhs.event;
+ }
+};
+
+constexpr EventSeverity disabledEventSeverities[] = {
+#if !DEBUG
+ EventSeverity::Debug,
+#endif
+#if !TESTING
+ EventSeverity::Test,
+#endif
+};
+
+
+constexpr Event disabledEvents[] = {
+};
+
+constexpr EventPermutation disabledEventPermutations[] = {
+ { EventSeverity::Debug, Event::Shader }
+};
+
+}
+
+#endif
diff --git a/include/mbgl/platform/gl.hpp b/include/mbgl/platform/gl.hpp
new file mode 100644
index 0000000000..a29b230dbf
--- /dev/null
+++ b/include/mbgl/platform/gl.hpp
@@ -0,0 +1,83 @@
+#ifndef MBGL_RENDERER_GL
+#define MBGL_RENDERER_GL
+
+#include <string>
+
+#ifdef NVIDIA
+ #include <GLES2/gl2.h>
+ #include <GLES2/gl2ext.h>
+
+ extern PFNGLDISCARDFRAMEBUFFEREXTPROC glDiscardFramebufferEXT;
+
+ #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
+#elif __APPLE__
+ #include "TargetConditionals.h"
+ #if TARGET_OS_IPHONE
+ #include <OpenGLES/ES2/gl.h>
+ #include <OpenGLES/ES2/glext.h>
+ #define glGenVertexArrays glGenVertexArraysOES
+ #define glBindVertexArray glBindVertexArrayOES
+ #define glDeleteVertexArrays glDeleteVertexArraysOES
+ #define GL_ARB_vertex_array_object 1
+ #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
+ #elif TARGET_IPHONE_SIMULATOR
+ #include <OpenGLES/ES2/gl.h>
+ #include <OpenGLES/ES2/glext.h>
+ #elif TARGET_OS_MAC
+ #include <OpenGL/OpenGL.h>
+ #include <OpenGL/gl.h>
+ #define glGenVertexArrays glGenVertexArraysAPPLE
+ #define glBindVertexArray glBindVertexArrayAPPLE
+ #define glDeleteVertexArrays glDeleteVertexArraysAPPLE
+ #else
+ #error Unsupported Apple platform
+ #endif
+#else
+ #define GL_GLEXT_PROTOTYPES
+ #include <GL/gl.h>
+ #include <GL/glu.h>
+ #include <GL/glext.h>
+#endif
+
+namespace mbgl {
+namespace gl {
+// Debug group markers, useful for debuggin on iOS
+#if defined(__APPLE__) && defined(DEBUG) && defined(GL_EXT_debug_marker)
+// static int indent = 0;
+inline void start_group(const std::string &str) {
+ glPushGroupMarkerEXT(0, str.c_str());
+ // fprintf(stderr, "%s%s\n", std::string(indent * 4, ' ').c_str(), str.c_str());
+ // indent++;
+}
+
+inline void end_group() {
+ glPopGroupMarkerEXT();
+ // indent--;
+}
+#else
+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(); };
+};
+}
+}
+
+#ifdef GL_ES_VERSION_2_0
+ #define glClearDepth glClearDepthf
+ #define glDepthRange glDepthRangef
+#endif
+
+void _CHECK_GL_ERROR(const char *cmd, const char *file, int line);
+
+#define _CHECK_ERROR(cmd, file, line) \
+ cmd; \
+ do { _CHECK_GL_ERROR(#cmd, file, line); } while (false);
+
+#define CHECK_ERROR(cmd) _CHECK_ERROR(cmd, __FILE__, __LINE__)
+
+#endif
diff --git a/include/mbgl/platform/log.hpp b/include/mbgl/platform/log.hpp
new file mode 100644
index 0000000000..dc000b4d52
--- /dev/null
+++ b/include/mbgl/platform/log.hpp
@@ -0,0 +1,71 @@
+#ifndef MBGL_PLATFORM_LOG
+#define MBGL_PLATFORM_LOG
+
+#include "event.hpp"
+
+#include <memory>
+#include <string>
+
+namespace mbgl {
+
+class LogBackend {
+public:
+ virtual inline ~LogBackend() = default;
+ virtual void record(EventSeverity severity, Event event, const std::string &msg) = 0;
+ virtual void record(EventSeverity severity, Event event, const char* format, ...) = 0;
+ virtual void record(EventSeverity severity, Event event, int64_t code) = 0;
+ virtual void record(EventSeverity severity, Event event, int64_t code, const std::string &msg) = 0;
+};
+
+class Log {
+private:
+ template <typename T>
+ constexpr static bool includes(const T e, T const *l, const size_t i = 0) {
+ return i >= sizeof l ? false : *(l + i) == e ? true : includes(e, l, i + 1);
+ }
+
+public:
+ template <typename ...Args>
+ static inline void Debug(Event event, Args&& ...args) {
+ Record(EventSeverity::Debug, event, ::std::forward<Args>(args)...);
+ }
+
+ template <typename ...Args>
+ static inline void Info(Event event, Args&& ...args) {
+ Record(EventSeverity::Info, event, ::std::forward<Args>(args)...);
+ }
+
+ template <typename ...Args>
+ static inline void Warning(Event event, Args&& ...args) {
+ Record(EventSeverity::Warning, event, ::std::forward<Args>(args)...);
+ }
+
+ template <typename ...Args>
+ static inline void Error(Event event, Args&& ...args) {
+ Record(EventSeverity::Error, event, ::std::forward<Args>(args)...);
+ }
+
+ template <typename ...Args>
+ static inline void Record(EventSeverity severity, Event event, Args&& ...args) {
+ if (!includes(severity, disabledEventSeverities) &&
+ !includes(event, disabledEvents) &&
+ !includes({ severity, event }, disabledEventPermutations)) {
+ if (Backend) {
+ Backend->record(severity, event, ::std::forward<Args>(args)...);
+ }
+ }
+ }
+
+ template<typename T, typename ...Args>
+ static inline const T &Set(Args&& ...args) {
+ Backend = ::std::unique_ptr<T>(new T(::std::forward<Args>(args)...));
+ return *dynamic_cast<T *>(Backend.get());
+ }
+
+private:
+ static std::unique_ptr<LogBackend> Backend;
+};
+
+}
+
+#endif
diff --git a/include/mbgl/platform/platform.hpp b/include/mbgl/platform/platform.hpp
new file mode 100644
index 0000000000..02aeb594b6
--- /dev/null
+++ b/include/mbgl/platform/platform.hpp
@@ -0,0 +1,46 @@
+#ifndef MBGL_PLATFORM_PLATFORM
+#define MBGL_PLATFORM_PLATFORM
+
+#include <memory>
+#include <functional>
+#include <string>
+
+typedef struct uv_loop_s uv_loop_t;
+
+namespace uv {
+class loop;
+}
+
+namespace mbgl {
+namespace platform {
+
+class Request;
+
+struct Response {
+ Response(std::function<void(Response *)> callback) : callback(callback) {}
+ int16_t code = -1;
+ std::string body;
+ std::string error_message;
+ std::function<void(Response *)> callback;
+};
+
+// Makes an HTTP request of a URL, preferrably on a background thread, and calls a function with the
+// results in the original thread (which runs the libuv loop).
+// If the loop pointer is NULL, the callback function will be called on an arbitrary thread.
+// Returns a cancellable request.
+std::shared_ptr<Request> request_http(const std::string &url,
+ std::function<void(Response *)> callback,
+ std::shared_ptr<uv::loop> loop = nullptr);
+
+// Cancels an HTTP request.
+void cancel_request_http(const std::shared_ptr<Request> &req);
+
+// Shows an alpha image with the specified dimensions in a named window.
+void show_debug_image(std::string name, const char *data, size_t width, size_t height);
+
+// Shows an alpha image with the specified dimensions in a named window.
+void show_color_debug_image(std::string name, const char *data, size_t logical_width, size_t logical_height, size_t width, size_t height);
+}
+}
+
+#endif
diff --git a/include/mbgl/platform/request.hpp b/include/mbgl/platform/request.hpp
new file mode 100644
index 0000000000..7d2da8888c
--- /dev/null
+++ b/include/mbgl/platform/request.hpp
@@ -0,0 +1,48 @@
+#ifndef MBGL_PLATFORM_REQUEST
+#define MBGL_PLATFORM_REQUEST
+
+#include <string>
+#include <functional>
+#include <memory>
+#include <atomic>
+
+#include <mbgl/util/noncopyable.hpp>
+
+// Forward definition.
+typedef struct uv_loop_s uv_loop_t;
+typedef struct uv_async_s uv_async_t;
+
+namespace uv {
+class loop;
+}
+
+namespace mbgl {
+namespace platform {
+
+struct Response;
+
+class Request : public std::enable_shared_from_this<Request>, private util::noncopyable {
+public:
+ Request(const std::string &url,
+ std::function<void(Response *)> callback,
+ std::shared_ptr<uv::loop> loop);
+ ~Request();
+
+ void complete();
+
+private:
+ static void complete(uv_async_t *async);
+
+public:
+ const std::string url;
+ std::unique_ptr<Response> res;
+ std::atomic<bool> cancelled;
+
+public:
+ uv_async_t *async = nullptr;
+ std::shared_ptr<uv::loop> loop;
+};
+}
+}
+
+#endif