From: Varun Date: Sun, 31 Jul 2016 14:44:57 +0000 (-0400) Subject: Foundation for multiple map instance support X-Git-Tag: submit/tizen_3.0/20161108.012559~38 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=13900614699987a75029700a90bb76df4866a740;p=platform%2Fcore%2Flocation%2Fmaps-plugin-mapzen.git Foundation for multiple map instance support - Updates core tangram rendering code and respective changes in the plugin code Change-Id: I3143dc2f71c0be6311b407c32e5ca1b73c10e17e --- diff --git a/lib/arm/libtangram.so b/lib/arm/libtangram.so index 5863d57..4ee6542 100755 Binary files a/lib/arm/libtangram.so and b/lib/arm/libtangram.so differ diff --git a/lib/i586/libtangram.so b/lib/i586/libtangram.so index f8d7cb4..d2db1f1 100755 Binary files a/lib/i586/libtangram.so and b/lib/i586/libtangram.so differ diff --git a/src/mapzen/tangram/ease.h b/src/mapzen/tangram/ease.h index 4e1f705..ed9cb81 100644 --- a/src/mapzen/tangram/ease.h +++ b/src/mapzen/tangram/ease.h @@ -1,5 +1,6 @@ #pragma once +#include "tangram.h" #include #include @@ -7,13 +8,6 @@ namespace Tangram { using EaseCb = std::function; -enum class EaseType : char { - linear = 0, - cubic, - quint, - sine, -}; - template T ease(T _start, T _end, float _t, EaseType _e) { float f = _t; diff --git a/src/mapzen/tangram/tangram.h b/src/mapzen/tangram/tangram.h index 9f37b68..af000ca 100644 --- a/src/mapzen/tangram/tangram.h +++ b/src/mapzen/tangram/tangram.h @@ -1,146 +1,191 @@ #pragma once #include "properties.h" -#include "ease.h" +#include #include -#include #include - -/* Tangram API - * - * Primary interface for controlling and managing the lifecycle of a Tangram - * map surface - */ +#include namespace Tangram { class DataSource; -// Create resources and initialize the map view using the scene file at the -// given resource path -void initialize(const char* _scenePath); +struct TouchItem { + std::shared_ptr properties; + float position[2]; + float distance; +}; + +struct SceneUpdate { + std::string keys; + std::string value; +}; + +enum class EaseType : char { + linear = 0, + cubic, + quint, + sine, +}; + +class Map { + +public: + + // Create an empty map object. To display a map, call either loadScene() or loadSceneAsync(). + Map(); + ~Map(); + + // Load the scene at the given absolute file path asynchronously + void loadSceneAsync(const char* _scenePath, bool _useScenePosition = false, + std::function _platformCallback = {}, void *_cbData = nullptr); + + // Load the scene at the given absolute file path synchronously + void loadScene(const char* _scenePath, bool _useScenePosition = false); + + // Request an update to the scene configuration; the path is a series of yaml keys + // separated by a '.' and the value is a string of yaml to replace the current value + // at the given path in the scene + void queueSceneUpdate(const char* _path, const char* _value); + + // Apply all previously requested scene updates + void applySceneUpdates(); + + // Initialize graphics resources; OpenGL context must be created prior to calling this + void setupGL(); -// Load the scene at the given absolute file path asynchronously -void loadSceneAsync(const char* _scenePath, bool _useScenePosition = false, - std::function _platformCallback = {}, void *_cbData = nullptr); -// Load the scene at the given absolute file path synchronously -void loadScene(const char* _scenePath, bool _useScenePosition = false); + // Resize the map view to a new width and height (in pixels) + void resize(int _newWidth, int _newHeight); -// Request an update to the scene configuration; the path is a series of yaml keys -// separated by a '.' and the value is a string of yaml to replace the current value -// at the given path in the scene -void queueSceneUpdate(const char* _path, const char* _value); + // Update the map state with the time interval since the last update, returns + // true when the current view is completely loaded (all tiles are available and + // no animation in progress) + bool update(float _dt); -// Apply all previously requested scene updates -void applySceneUpdates(); + // Render a new frame of the map view (if needed) + void render(); -// Initialize graphics resources; OpenGL context must be created prior to calling this -void setupGL(); + // Gets the viewport height in physical pixels (framebuffer size) + int getViewportHeight(); -// Resize the map view to a new width and height (in pixels) -void resize(int _newWidth, int _newHeight); + // Gets the viewport width in physical pixels (framebuffer size) + int getViewportWidth(); -// Update the map state with the time interval since the last update, returns -// true when the current view is completely loaded (all tiles are available and -// no animation in progress) -bool update(float _dt); + // Set the ratio of hardware pixels to logical pixels (defaults to 1.0) + void setPixelScale(float _pixelsPerPoint); -// Render a new frame of the map view (if needed) -void render(); + // Gets the pixel scale + float getPixelScale(); -// Set the position of the map view in degrees longitude and latitude; if duration -// (in seconds) is provided, position eases to the set value over the duration; -// calling either version of the setter overrides all previous calls -void setPosition(double _lon, double _lat); -void setPosition(double _lon, double _lat, float _duration, EaseType _e = EaseType::quint); + // Capture a snapshot of the current frame and store it in the allocated _data + // _data is expected to be of size getViewportHeight() * getViewportWidth() + // Pixel data is stored starting from the lower left corner of the viewport + // Each pixel(x, y) would be located at _data[y * getViewportWidth() + x] + // Each unsigned int corresponds to an RGBA pixel value + void captureSnapshot(unsigned int* _data); -// Set the values of the arguments to the position of the map view in degrees -// longitude and latitude -void getPosition(double& _lon, double& _lat); + // Set the position of the map view in degrees longitude and latitude; if duration + // (in seconds) is provided, position eases to the set value over the duration; + // calling either version of the setter overrides all previous calls + void setPosition(double _lon, double _lat); + void setPositionEased(double _lon, double _lat, float _duration, EaseType _e = EaseType::quint); -// Set the fractional zoom level of the view; if duration (in seconds) is provided, -// zoom eases to the set value over the duration; calling either version of the setter -// overrides all previous calls -void setZoom(float _z); -void setZoom(float _z, float _duration, EaseType _e = EaseType::quint); + // Set the values of the arguments to the position of the map view in degrees + // longitude and latitude + void getPosition(double& _lon, double& _lat); -// Get the fractional zoom level of the view -float getZoom(); + // Set the fractional zoom level of the view; if duration (in seconds) is provided, + // zoom eases to the set value over the duration; calling either version of the setter + // overrides all previous calls + void setZoom(float _z); + void setZoomEased(float _z, float _duration, EaseType _e = EaseType::quint); -// Set the counter-clockwise rotation of the view in radians; 0 corresponds to -// North pointing up; if duration (in seconds) is provided, rotation eases to the -// the set value over the duration; calling either version of the setter overrides -// all previous calls -void setRotation(float _radians); -void setRotation(float _radians, float _duration, EaseType _e = EaseType::quint); + // Get the fractional zoom level of the view + float getZoom(); -// Get the counter-clockwise rotation of the view in radians; 0 corresponds to -// North pointing up -float getRotation(); + // Set the counter-clockwise rotation of the view in radians; 0 corresponds to + // North pointing up; if duration (in seconds) is provided, rotation eases to the + // the set value over the duration; calling either version of the setter overrides + // all previous calls + void setRotation(float _radians); + void setRotationEased(float _radians, float _duration, EaseType _e = EaseType::quint); -// Set the tilt angle of the view in radians; 0 corresponds to straight down; -// if duration (in seconds) is provided, tilt eases to the set value over the -// duration; calling either version of the setter overrides all previous calls -void setTilt(float _radians); -void setTilt(float _radians, float _duration, EaseType _e = EaseType::quint); + // Get the counter-clockwise rotation of the view in radians; 0 corresponds to + // North pointing up + float getRotation(); -// Get the tilt angle of the view in radians; 0 corresponds to straight down -float getTilt(); + // Set the tilt angle of the view in radians; 0 corresponds to straight down; + // if duration (in seconds) is provided, tilt eases to the set value over the + // duration; calling either version of the setter overrides all previous calls + void setTilt(float _radians); + void setTiltEased(float _radians, float _duration, EaseType _e = EaseType::quint); -// Given coordinates in screen space (x right, y down), set the output longitude and -// latitude to the geographic location corresponding to that point; returns false if -// no geographic position corresponds to the screen location, otherwise returns true -bool screenPositionToLngLat(double _x, double _y, double* _lng, double* _lat); + // Get the tilt angle of the view in radians; 0 corresponds to straight down + float getTilt(); -// Given longitude and latitude coordinates, set the output coordinates to the -// corresponding point in screen space (x right, y down); returns false if the -// point is not visible on the screen, otherwise returns true -bool lngLatToScreenPosition(double _lng, double _lat, double* _x, double* _y); + // Set the camera type (0 = perspective, 1 = isometric, 2 = flat) + void setCameraType(int _type); -// Set the ratio of hardware pixels to logical pixels (defaults to 1.0) -void setPixelScale(float _pixelsPerPoint); + // Get the camera type (0 = perspective, 1 = isometric, 2 = flat) + int getCameraType(); -// Set the camera type (0 = perspective, 1 = isometric, 2 = flat) -void setCameraType(int _type); + // Given coordinates in screen space (x right, y down), set the output longitude and + // latitude to the geographic location corresponding to that point; returns false if + // no geographic position corresponds to the screen location, otherwise returns true + bool screenPositionToLngLat(double _x, double _y, double* _lng, double* _lat); -// Get the camera type (0 = perspective, 1 = isometric, 2 = flat) -int getCameraType(); + // Given longitude and latitude coordinates, set the output coordinates to the + // corresponding point in screen space (x right, y down); returns false if the + // point is not visible on the screen, otherwise returns true + bool lngLatToScreenPosition(double _lng, double _lat, double* _x, double* _y); -// Add a data source for adding drawable map data, which will be styled -// according to the scene file using the provided data source name; -void addDataSource(std::shared_ptr _source); + // Add a data source for adding drawable map data, which will be styled + // according to the scene file using the provided data source name; + void addDataSource(std::shared_ptr _source); -// Remove a data source from the map; returns true if the source was found -// and removed, otherwise returns false. -bool removeDataSource(DataSource& _source); + // Remove a data source from the map; returns true if the source was found + // and removed, otherwise returns false. + bool removeDataSource(DataSource& _source); -void clearDataSource(DataSource& _source, bool _data, bool _tiles); + void clearDataSource(DataSource& _source, bool _data, bool _tiles); -// Respond to a tap at the given screen coordinates (x right, y down) -void handleTapGesture(float _posX, float _posY); + // Respond to a tap at the given screen coordinates (x right, y down) + void handleTapGesture(float _posX, float _posY); -// Respond to a double tap at the given screen coordinates (x right, y down) -void handleDoubleTapGesture(float _posX, float _posY); + // Respond to a double tap at the given screen coordinates (x right, y down) + void handleDoubleTapGesture(float _posX, float _posY); -// Respond to a drag with the given displacement in screen coordinates (x right, y down) -void handlePanGesture(float _startX, float _startY, float _endX, float _endY); + // Respond to a drag with the given displacement in screen coordinates (x right, y down) + void handlePanGesture(float _startX, float _startY, float _endX, float _endY); -// Respond to a fling from the given position with the given velocity in screen coordinates -void handleFlingGesture(float _posX, float _posY, float _velocityX, float _velocityY); + // Respond to a fling from the given position with the given velocity in screen coordinates + void handleFlingGesture(float _posX, float _posY, float _velocityX, float _velocityY); -// Respond to a pinch at the given position in screen coordinates with the given -// incremental scale -void handlePinchGesture(float _posX, float _posY, float _scale, float _velocity); + // Respond to a pinch at the given position in screen coordinates with the given + // incremental scale + void handlePinchGesture(float _posX, float _posY, float _scale, float _velocity); -// Respond to a rotation gesture with the given incremental rotation in radians -void handleRotateGesture(float _posX, float _posY, float _rotation); + // Respond to a rotation gesture with the given incremental rotation in radians + void handleRotateGesture(float _posX, float _posY, float _rotation); -// Respond to a two-finger shove with the given distance in screen coordinates -void handleShoveGesture(float _distance); + // Respond to a two-finger shove with the given distance in screen coordinates + void handleShoveGesture(float _distance); -// Set whether the OpenGL state will be cached between subsequent frames; this improves rendering -// efficiency, but can cause errors if your application code makes OpenGL calls (false by default) -void useCachedGlState(bool _use); + // Set whether the OpenGL state will be cached between subsequent frames; this improves rendering + // efficiency, but can cause errors if your application code makes OpenGL calls (false by default) + void useCachedGlState(bool _use); + + const std::vector& pickFeaturesAt(float _x, float _y); + + // Run this task asynchronously to Tangram's main update loop. + void runAsyncTask(std::function _task); + +private: + + class Impl; + std::unique_ptr impl; + +}; enum DebugFlags { freeze_tiles = 0, // While on, the set of tiles currently being drawn will not update to match the view @@ -162,37 +207,5 @@ bool getDebugFlag(DebugFlags _flag); // Toggle the boolean state of a debug feature (see debug.h) void toggleDebugFlag(DebugFlags _flag); -// Run this task on Tangram's main update loop. -void runOnMainLoop(std::function _task); - -// Run this task asynchronously to Tangram's main update loop. -void runAsyncTask(std::function _task); - -// Gets the viewport height in physical pixels (framebuffer size) -int getViewportHeight(); - -// Gets the viewport width in physical pixels (framebuffer size) -int getViewportWidth(); - -// Gets the pixel scale -float getPixelScale(); - -// Capture a snapshot of the current frame and store it in the allocated _data -// _data is expected to be of size getViewportHeight() * getViewportWidth() -// Pixel data is stored starting from the lower left corner of the viewport -// Each pixel(x, y) would be located at _data[y * getViewportWidth() + x] -// Each unsigned int corresponds to an RGBA pixel value -void captureSnapshot(unsigned int* _data); - -struct TouchItem { - std::shared_ptr properties; - float position[2]; - float distance; -}; - -const std::vector& pickFeaturesAt(float _x, float _y); - -float frameTime(); - } diff --git a/src/mapzen/tangram_view.cpp b/src/mapzen/tangram_view.cpp index e027ec7..13c74c1 100644 --- a/src/mapzen/tangram_view.cpp +++ b/src/mapzen/tangram_view.cpp @@ -98,18 +98,19 @@ mapzen_error_e TangramView::create(maps_view_h view, maps_plugin_map_view_ready_ }); m_readyCb = callback; + // TODO: What to do for multiple instances setEvasGlAPI(m_api); initUrlRequests(); // Set up the tangram map. - Tangram::initialize(NORMAL_SCENE_FILE_PATH); - Tangram::loadScene(NORMAL_SCENE_FILE_PATH); + m_map = new Tangram::Map(); + m_map->loadScene(NORMAL_SCENE_FILE_PATH); // Make the GL context current and perform GL setup. evas_gl_make_current(m_gl, m_surface, m_context); - Tangram::setupGL(); - Tangram::resize(m_w, m_h); + m_map->setupGL(); + m_map->resize(m_w, m_h); readyMapCb((void*)view); m_isInitialized = true; @@ -191,6 +192,11 @@ mapzen_error_e TangramView::destroy(maps_view_h view) evas_gl_config_free(m_config); } + if (m_map) { + delete m_map; + m_map = nullptr; + } + return MAPZEN_ERROR_NONE; } @@ -219,18 +225,18 @@ mapzen_error_e TangramView::render(maps_view_h view, const maps_coordinates_h co m_w = w; m_h = h; evas_gl_make_current(m_gl, m_surface, m_context); - Tangram::resize(m_w, m_h); + m_map->resize(m_w, m_h); setupOpenGlSurface(view); } if (m_zoom != zoom) { m_zoom = zoom; - Tangram::setZoom(zoom); + m_map->setZoom(zoom); } if (m_angle != angle) { m_angle = angle; - Tangram::setRotation(degrees_to_radians(angle)); + m_map->setRotation(degrees_to_radians(angle)); } double lng = 0, lat = 0; @@ -240,7 +246,7 @@ mapzen_error_e TangramView::render(maps_view_h view, const maps_coordinates_h co if (m_lng != lng || m_lat != lat) { m_lng = lng; m_lat = lat; - Tangram::setPosition(m_lng, m_lat); + m_map->setPosition(m_lng, m_lat); } requestRender(); @@ -268,8 +274,8 @@ mapzen_error_e TangramView::moveCenter(maps_view_h view, int delta_x, int delta_ double x = 0.5 * m_w + (double)delta_x; double y = 0.5 * m_h + (double)delta_y; double lng, lat = 0.0; - Tangram::screenPositionToLngLat(x, y, &lng, &lat); - Tangram::setPosition(lng, lat); + m_map->screenPositionToLngLat(x, y, &lng, &lat); + m_map->setPosition(lng, lat); MAPS_LOGD("Moved with delta x: %d, y: %d to coordinates lon: %f, lat: %f", delta_x, delta_y, lng, lat); @@ -287,7 +293,7 @@ mapzen_error_e TangramView::getCenter(maps_view_h view, maps_coordinates_h *cent } double longitude = 0, latitude = 0; - Tangram::getPosition(longitude, latitude); + m_map->getPosition(longitude, latitude); longitude = wrap_longitude(longitude); latitude = wrap_latitude(latitude); @@ -322,7 +328,7 @@ mapzen_error_e TangramView::convertScreenToGeolocation(maps_view_h view, int x, } double longitude = (double)x, latitude = (double)y; - Tangram::screenPositionToLngLat(x, y, &longitude, &latitude); + m_map->screenPositionToLngLat(x, y, &longitude, &latitude); longitude = wrap_longitude(longitude); latitude = wrap_latitude(latitude); @@ -351,7 +357,7 @@ mapzen_error_e TangramView::convertGeolocationToScreen(maps_view_h view, const m maps_coordinates_get_longitude(coord, &lng); double screenx, screeny; - Tangram::lngLatToScreenPosition(lng, lat, &screenx, &screeny); + m_map->lngLatToScreenPosition(lng, lat, &screenx, &screeny); *x = (int)screenx; *y = (int)screeny; @@ -401,7 +407,7 @@ mapzen_error_e TangramView::captureSnapshot(maps_view_h view, void **data, int * return MAPZEN_ERROR_OUT_OF_MEMORY; } - Tangram::captureSnapshot(pixels); + m_map->captureSnapshot(pixels); for (int i = 0; i < m_h; ++i) { memcpy((unsigned int*)*data + m_w * i, pixels + m_w * (m_h - i - 1), m_w); @@ -452,7 +458,7 @@ void TangramView::setMapType(maps_view_h view) return; } m_viewType = newViewType; - Tangram::loadScene(newSceneFile); + m_map->loadScene(newSceneFile); } } @@ -477,10 +483,14 @@ void TangramView::pixelGetCb(void *data, Evas_Object *obj) evas_gl_make_current(tv->m_gl, tv->m_surface, tv->m_context); tv->m_api->glViewport(0, 0, tv->m_w, tv->m_h); - Tangram::update(0); - Tangram::render(); + if (tv->m_map) { + tv->m_map->update(0); + tv->m_map->render(); + MAPS_LOGD("pixelGetCb called on TangramView"); + } else { + MAPS_LOGD("tv->m_map is null, in pixelGelCb"); + } - MAPS_LOGD("pixelGetCb called on TangramView"); } void TangramView::renderingCb(void *data) { diff --git a/src/mapzen/tangram_view.hpp b/src/mapzen/tangram_view.hpp index 6cf5123..424ec21 100644 --- a/src/mapzen/tangram_view.hpp +++ b/src/mapzen/tangram_view.hpp @@ -25,6 +25,10 @@ #include #include "mapzen_types.h" +namespace Tangram { + class Map; +} + class TangramView { public: @@ -54,6 +58,7 @@ private: private: + Tangram::Map *m_map = nullptr; Evas_Object *m_image = nullptr; Evas_GL_Context *m_context = nullptr; Evas_GL_Surface *m_surface = nullptr;