Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add emscripten support #509

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions all/native/graphics/BitmapCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#elif defined(__ANDROID__)
#define CARTO_BITMAP_CANVAS_IMPL AndroidImpl
#include "graphics/BitmapCanvasAndroidImpl.h"
#elif defined(__EMSCRIPTEN__)
#define CARTO_BITMAP_CANVAS_IMPL EmscriptenImpl
#include "graphics/BitmapCanvasEmscriptenImpl.h"
#else
#error "Unsupported platform"
#endif
Expand Down
1 change: 1 addition & 0 deletions all/native/graphics/BitmapCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ namespace carto {
class AndroidImpl;
class IOSImpl;
class UWPImpl;
class EmscriptenImpl;

std::unique_ptr<Impl> _impl;
};
Expand Down
3 changes: 3 additions & 0 deletions all/native/network/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#elif defined(__ANDROID__)
#define CARTO_HTTP_SOCKET_IMPL AndroidImpl
#include "network/HTTPClientAndroidImpl.h"
#elif defined(__EMSCRIPTEN__)
#define CARTO_HTTP_SOCKET_IMPL EmscriptenImpl
#include "network/HTTPClientEmscriptenImpl.h"
#else
#define CARTO_HTTP_SOCKET_IMPL PionImpl
#include "HTTPClientPionImpl.h"
Expand Down
1 change: 1 addition & 0 deletions all/native/network/HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace carto {
class AndroidImpl;
class IOSImpl;
class WinSockImpl;
class EmscriptenImpl;

int makeRequest(Request request, Response& response, HandlerFunc handlerFn, std::uint64_t offset) const;

Expand Down
11 changes: 11 additions & 0 deletions all/native/utils/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include <windows.h>
#endif

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif

namespace carto {

#ifdef __ANDROID__
Expand All @@ -39,6 +43,13 @@ namespace carto {
OutputDebugStringA("\n");
}
#endif
#ifdef __EMSCRIPTEN__
enum LogType { LOG_TYPE_FATAL = EM_LOG_ERROR, LOG_TYPE_ERROR = EM_LOG_ERROR, LOG_TYPE_WARNING = EM_LOG_WARN, LOG_TYPE_INFO = EM_LOG_INFO, LOG_TYPE_DEBUG = EM_LOG_DEBUG };

static void OutputLog(LogType logType, const std::string& tag, const char* text) {
emscripten_log(static_cast<int>(logType), text);
}
#endif

bool Log::IsShowError() {
std::lock_guard<std::mutex> lock(_Mutex);
Expand Down
3 changes: 2 additions & 1 deletion all/native/utils/PlatformUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace carto {
PLATFORM_TYPE_WINDOWS,
PLATFORM_TYPE_WINDOWS_PHONE,
PLATFORM_TYPE_XAMARIN_IOS,
PLATFORM_TYPE_XAMARIN_ANDROID
PLATFORM_TYPE_XAMARIN_ANDROID,
PLATFORM_TYPE_WEB
};
}

Expand Down
29 changes: 29 additions & 0 deletions emscripten/modules/ui/MapView.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef _MAPVIEW_I
#define _MAPVIEW_I

%module MAPVIEW

!proxy_imports(carto::MapView, ui.MapView)

%{
#include "ui/MapView.h"
#include "ui/BaseMapView.h"
#include "ui/MapEventListener.h"
#include "ui/MapRedrawRequestListener.h"
#include "ui/EmscriptenInput.h"
#include "components/Options.h"
#include "components/Layers.h"
#include "core/MapBounds.h"
#include "core/MapPos.h"
#include "core/MapVec.h"
#include "core/ScreenPos.h"
#include "core/ScreenBounds.h"
#include "utils/Const.h"
#include "renderers/MapRenderer.h"
%}

%include <std_string.i>

%include "ui/MapView.h"

#endif
18 changes: 18 additions & 0 deletions emscripten/modules/utils/AssetUtils.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _ASSETUTILS_I
#define _ASSETUTILS_I

%module AssetUtils

!proxy_imports(carto::AssetUtils, core.BinaryData)

%{
#include "utils/AssetUtils.h"
%}

%include <std_string.i>

%import "core/BinaryData.i"

%include "utils/AssetUtils.h"

#endif
24 changes: 24 additions & 0 deletions emscripten/modules/utils/BitmapUtils.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef _BITMAPUTILS_I
#define _BITMAPUTILS_I

%module BitmapUtils

!proxy_imports(carto::BitmapUtils, graphics.Bitmap)

%{
#include "utils/BitmapUtils.h"
#include "components/Exceptions.h"
%}

%include <std_shared_ptr.i>
%include <std_string.i>
%include <cartoswig.i>

%import "graphics/Bitmap.i"

%std_exceptions(carto::BitmapUtils::CreateBitmapFromUIImage)
%std_exceptions(carto::BitmapUtils::CreateUIImageFromBitmap)

%include "utils/BitmapUtils.h"

#endif
9 changes: 9 additions & 0 deletions emscripten/native/components/Task.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "components/Task.h"

namespace carto {

void Task::operator()() {
run();
}

}
Loading