#include <string>
#include <cstdio>
+#include <sys/syscall.h> // SYS_gettid
+
#define NORMAL_SCENE_FILE_PATH "/usr/share/maps/mapzen/scenes/bubble-wrap/bubble-wrap.yaml"
#define TERRAIN_SCENE_FILE_PATH "/usr/share/maps/mapzen/scenes/walkabout-style/walkabout-style.yaml"
Tangram::UrlClient::Options urlOptions;
char* proxyAddress = NULL;
get_proxy_address(&proxyAddress);
- urlOptions.proxyAddress = proxyAddress;
- if (proxyAddress)
+ if (proxyAddress) {
+ urlOptions.proxyAddress = proxyAddress;
free(proxyAddress);
+ }
+
+ m_platform = std::make_shared<Tangram::TizenPlatform>(urlOptions);
+
+ m_uiThreadId = syscall(SYS_gettid);
- auto platform = std::shared_ptr<Tangram::TizenPlatform>(new Tangram::TizenPlatform(urlOptions));
- //auto platform = std::make_shared<Tangram::TizenPlatform>();
+ m_platform->setRenderCallbackFunction([&]() {
- platform->setRenderCallbackFunction([=](){
- ecore_main_loop_thread_safe_call_async(&renderingCb, m_image);
+ if (m_uiThreadId == syscall(SYS_gettid)) {
+ m_dirty = false;
+ evas_object_image_pixels_dirty_set(m_image, EINA_TRUE);
+ } else {
+ m_dirty = true;
+ }
});
+ // NB: Since there is no safe way to use ecore_main_loop_thread_safe_call_async in a
+ // module that could be unloaded at runtime we use polling to check on the mainloop
+ // whether a render request came in.
+ // TODO only run timer when async tasks (Tile- and Scene-Loading) are in progress.
+ m_renderRequestTimer = ecore_timer_add(0.05, [](void *data){
+ auto tv = static_cast<TangramView*>(data);
+ if (tv->m_dirty) {
+ tv->m_dirty = false;
+ evas_object_image_pixels_dirty_set((Evas_Object*)tv->m_image, EINA_TRUE);
+ }
+ return EINA_TRUE;
+ }, this);
+
// Set up the tangram map.
- m_map = new Tangram::Map(platform);
+ m_map.reset(new Tangram::Map(m_platform));
float scaleFactor = elm_config_scale_get();
MAPS_LOGD("evas_gl_context_create() set PixelScale %f", scaleFactor);
m_isInitialized = false;
m_sceneLoaded = false;
+ if (m_renderRequestTimer) {
+ ecore_timer_del(m_renderRequestTimer);
+ m_renderRequestTimer = nullptr;
+ }
+
if (m_image) {
evas_object_image_pixels_get_callback_set(m_image, nullptr, nullptr);
}
if (m_surface && m_context) {
evas_gl_make_current(m_gl, m_surface, m_context);
}
+ }
+
+ if (m_map) {
+ removeAllObjects();
+
+ m_map.reset();
+ m_platform.reset();
+ }
+
+ if (m_gl) {
if (m_surface) {
evas_object_image_native_surface_set(m_image, nullptr);
evas_gl_surface_destroy(m_gl, m_surface);
evas_gl_config_free(m_config);
}
- if (m_map) {
- static_cast<Tangram::TizenPlatform*>(m_map->getPlatform().get())->setRenderCallbackFunction(nullptr);
- removeAllObjects();
- delete m_map;
- m_map = nullptr;
- }
-
-
return MAPZEN_ERROR_NONE;
}
{
TangramView *tv = nullptr;
int maps_error = maps_view_get_maps_plugin_view_handle(data, (void**)&tv);
- if (maps_error != MAPS_ERROR_NONE || !tv || !tv->m_gl || !tv->m_surface || !tv->m_context) {
+ if (maps_error != MAPS_ERROR_NONE || !tv) {
+ return;
+ }
+
+ tv->m_dirty = false;
+
+ if (!tv->m_gl || !tv->m_surface || !tv->m_context) {
return;
}
MAPS_LOGD("tv->m_map is null, in pixelGelCb");
}
}
-
-void TangramView::renderingCb(void *data) {
- if (!data) {
- return;
- }
- evas_object_image_pixels_dirty_set((Evas_Object*)data, EINA_TRUE);
-}
#include <Ecore_Evas.h>
#include <Evas_GL.h>
#include <map>
+#include <memory>
#include <mutex>
#include "mapzen_types.h"
#include "tangram/util/types.h"
+#include <sys/types.h> // pid_t, gettid()
+
namespace Tangram {
class Map;
+ class TizenPlatform;
}
typedef std::map<maps_view_object_h, Tangram::MarkerID> MapViewObjects;
static void sceneLoadedCb(void *data);
static void readyMapCb(void *view);
- static void renderingCb(void *data);
static void pixelGetCb(void *data, Evas_Object *obj);
// Emplaces the lng/lat from `coordinate` to `user_data` (Tangram::Coordinates)
static bool emplaceCoord(int index, maps_coordinates_h coordinate, void *user_data);
- Tangram::Map *m_map = nullptr;
+ std::unique_ptr<Tangram::Map> m_map;
+ std::shared_ptr<Tangram::TizenPlatform> m_platform;
+
+ pid_t m_uiThreadId = 0;
+
Evas_Object *m_image = nullptr;
Evas_GL_Context *m_context = nullptr;
Evas_GL_Surface *m_surface = nullptr;
Evas_GL_Config *m_config = nullptr;
Evas_GL *m_gl = nullptr;
Evas_GL_API *m_api = nullptr;
+ Ecore_Timer *m_renderRequestTimer = nullptr;
bool m_isInitialized = false;
bool m_publicTransitEnabled = false;
std::string m_language = "en";
std::string m_providerKey = "";
bool m_isProviderKeySet = false;
+ bool m_dirty = false;
int m_x = 0;
int m_y = 0;