From c7e6aa6df955469d8aafcd5e51f59e57d3693a81 Mon Sep 17 00:00:00 2001 From: ExMix Date: Tue, 10 Sep 2013 13:06:04 +0300 Subject: [PATCH] review fixes --- android/YoPme/jni/Framework.cpp | 64 ++++++++++--------- android/YoPme/jni/Framework.hpp | 9 ++- android/YoPme/jni/MapRenderer.cpp | 16 ++++- .../mapswithme/yopme/BackscreenActivity.java | 22 ++++--- .../com/mapswithme/yopme/map/MapRenderer.java | 2 + map/framework.cpp | 8 +++ map/framework.hpp | 1 + map/navigator.cpp | 5 -- map/navigator.hpp | 2 - yopme_desktop/yopme_desktop.pro | 8 +-- 10 files changed, 81 insertions(+), 56 deletions(-) diff --git a/android/YoPme/jni/Framework.cpp b/android/YoPme/jni/Framework.cpp index d84ef5f0fe..77d86fbfdc 100644 --- a/android/YoPme/jni/Framework.cpp +++ b/android/YoPme/jni/Framework.cpp @@ -2,20 +2,43 @@ #include "Stubs.hpp" -#include "../../../base/logging.hpp" -#include "../../../platform/platform.hpp" -#include "../../../geometry/any_rect2d.hpp" #include "../../../map/events.hpp" #include "../../../map/navigator.hpp" #include "../../../map/yopme_render_policy.hpp" +#include "../../../platform/platform.hpp" +#include "../../../geometry/any_rect2d.hpp" +#include "../../../base/logging.hpp" #include namespace yopme { + static EmptyVideoTimer s_timer; Framework::Framework(int width, int height) + : m_width(width) + , m_height(height) + { + LOG(LDEBUG, ("Framework Constructor")); + // TODO move this in some method like ExternalStorageConnected + m_framework.AddLocalMaps(); + LOG(LDEBUG, ("Local maps addeded")); + } + + Framework::~Framework() + { + m_framework.PrepareToShutdown(); + } + + void Framework::ShowRect(double lat, double lon, double zoom) + { + m_framework.ShowRect(lat, lon, zoom); + InitRenderPolicy(); + RenderMap(); + TeardownRenderPolicy(); + } + + void Framework::InitRenderPolicy() { - m_timer.reset(new EmptyVideoTimer()); shared_ptr primaryRC(new RenderContext()); graphics::ResourceManager::Params rmParams; rmParams.m_rtFormat = graphics::Data8Bpp; @@ -25,49 +48,30 @@ namespace yopme RenderPolicy::Params rpParams; - rpParams.m_videoTimer = m_timer.get(); + rpParams.m_videoTimer = &s_timer; rpParams.m_useDefaultFB = true; rpParams.m_rmParams = rmParams; rpParams.m_primaryRC = primaryRC; rpParams.m_density = graphics::EDensityXHDPI; rpParams.m_skinName = "basic.skn"; - rpParams.m_screenWidth = width; - rpParams.m_screenHeight = height; + rpParams.m_screenWidth = m_width; + rpParams.m_screenHeight = m_height; try { - RenderPolicy * policy = new ::YopmeRP(rpParams); - m_framework.SetRenderPolicy(policy); - // TODO move this in some method like ExternalStorageConnected - m_framework.AddLocalMaps(); + m_framework.SetRenderPolicy(new ::YopmeRP(rpParams)); } catch(RootException & e) { LOG(LERROR, (e.what())); } - m_framework.OnSize(width, height); + m_framework.OnSize(m_width, m_height); } - Framework::~Framework() + void Framework::TeardownRenderPolicy() { - m_framework.PrepareToShutdown(); - } - - void Framework::ConfigureNavigator(double lat, double lon, double zoom) - { - Navigator & navigator = m_framework.GetNavigator(); - ScalesProcessor const & scales = navigator.GetScaleProcessor(); - m2::RectD rect = scales.GetRectForDrawScale(zoom, m2::PointD(lon, lat)); - - m2::PointD leftBottom = rect.LeftBottom(); - m2::PointD rightTop = rect.RightTop(); - m2::RectD pixelRect = m2::RectD(MercatorBounds::LonToX(leftBottom.x), - MercatorBounds::LatToY(leftBottom.y), - MercatorBounds::LonToX(rightTop.x), - MercatorBounds::LatToY(rightTop.y)); - - navigator.SetFromRect(m2::AnyRectD(pixelRect)); + m_framework.SetRenderPolicy(0); } void Framework::RenderMap() diff --git a/android/YoPme/jni/Framework.hpp b/android/YoPme/jni/Framework.hpp index 257fe4fad3..d9deecd4bd 100644 --- a/android/YoPme/jni/Framework.hpp +++ b/android/YoPme/jni/Framework.hpp @@ -13,11 +13,16 @@ namespace yopme Framework(int width, int height); ~Framework(); - void ConfigureNavigator(double lat, double lon, double zoom); + void ShowRect(double lat, double lon, double zoom); + + private: + void InitRenderPolicy(); + void TeardownRenderPolicy(); void RenderMap(); private: ::Framework m_framework; - shared_ptr m_timer; + int m_width; + int m_height; }; } diff --git a/android/YoPme/jni/MapRenderer.cpp b/android/YoPme/jni/MapRenderer.cpp index 449513dc5c..c2c7d11f4c 100644 --- a/android/YoPme/jni/MapRenderer.cpp +++ b/android/YoPme/jni/MapRenderer.cpp @@ -3,7 +3,12 @@ #include "Framework.hpp" #include "../../../base/logging.hpp" +#include "../../../std/shared_ptr.hpp" +namespace +{ + static shared_ptr s_framework; +} // @TODO refactor and remove that void InitNVEvent(JavaVM * jvm) {} @@ -11,12 +16,17 @@ void InitNVEvent(JavaVM * jvm) {} extern "C" { +JNIEXPORT void JNICALL +Java_com_mapswithme_yopme_map_MapRenderer_nativeCreateFramework(JNIEnv * env, jobject obj, int width, int height) +{ + s_framework.reset(new yopme::Framework(width, height)); +} + JNIEXPORT void JNICALL Java_com_mapswithme_yopme_map_MapRenderer_nativeRenderMap(JNIEnv * env, jobject obj, double lat, double lon, double zoom) { - yopme::Framework f(360, 640); - f.ConfigureNavigator(lat, lon, zoom); - f.RenderMap(); + ASSERT(s_framework != NULL, ()); + s_framework->ShowRect(lat, lon, zoom); } } // extern "C" diff --git a/android/YoPme/src/com/mapswithme/yopme/BackscreenActivity.java b/android/YoPme/src/com/mapswithme/yopme/BackscreenActivity.java index e0323edde1..7196ed604c 100644 --- a/android/YoPme/src/com/mapswithme/yopme/BackscreenActivity.java +++ b/android/YoPme/src/com/mapswithme/yopme/BackscreenActivity.java @@ -61,10 +61,6 @@ public class BackscreenActivity extends BSActivity protected void onBSCreate() { super.onBSCreate(); - - final Resources res = getResources(); - mMapDataProvider = new MapRenderer((int) res.getDimension(R.dimen.yota_width), - (int)res.getDimension(R.dimen.yota_height)); final String extStoragePath = getDataStoragePath(); final String extTmpPath = getTempPath(); @@ -74,6 +70,12 @@ public class BackscreenActivity extends BSActivity new File(extTmpPath).mkdirs(); nativeInitPlatform(getApkPath(), extStoragePath, extTmpPath, "", true); + + /// !!! Create MapRenderer ONLY AFTER platform init !!! + //final Resources res = getResources(); + //mMapDataProvider = new MapRenderer((int) res.getDimension(R.dimen.yota_width), + // (int)res.getDimension(R.dimen.yota_height)); + mMapDataProvider = MapRenderer.GetRenderer(); setUpView(); } @@ -233,8 +235,7 @@ public class BackscreenActivity extends BSActivity { if (mLocation == null) return; - data = mMapDataProvider.getMyPositionData(mLocation.getLatitude(), - mLocation.getLongitude(), mZoomLevel); + data = mMapDataProvider.getMyPositionData(mLocation.getLatitude(), mLocation.getLongitude(), mZoomLevel); } else if (mMode == Mode.POI) data = mMapDataProvider.getPOIData(mPoint, mZoomLevel); @@ -248,8 +249,9 @@ public class BackscreenActivity extends BSActivity public static void startInMode(Context context, Mode mode, MWMPoint point) { - final Intent i = new Intent(context, BackscreenActivity.class).putExtra(EXTRA_MODE, mode).putExtra(EXTRA_POINT, - point); + final Intent i = new Intent(context, BackscreenActivity.class) + .putExtra(EXTRA_MODE, mode) + .putExtra(EXTRA_POINT, point); context.startService(i); } @@ -302,6 +304,6 @@ public class BackscreenActivity extends BSActivity } private native void nativeInitPlatform(String apkPath, String storagePath, - String tmpPath, String obbGooglePath, - boolean isPro); + String tmpPath, String obbGooglePath, + boolean isPro); } diff --git a/android/YoPme/src/com/mapswithme/yopme/map/MapRenderer.java b/android/YoPme/src/com/mapswithme/yopme/map/MapRenderer.java index a7bf46e89c..9e126d51ad 100644 --- a/android/YoPme/src/com/mapswithme/yopme/map/MapRenderer.java +++ b/android/YoPme/src/com/mapswithme/yopme/map/MapRenderer.java @@ -13,6 +13,7 @@ public class MapRenderer implements MapDataProvider { mPixelBuffer = new PixelBuffer(width, height); mPixelBuffer.init(); + nativeCreateFramework(width, height); } public void terminate() @@ -57,5 +58,6 @@ public class MapRenderer implements MapDataProvider } } + private native void nativeCreateFramework(int width, int height); private native void nativeRenderMap(double lat, double lon, double zoom); } diff --git a/map/framework.cpp b/map/framework.cpp index 38e1642dee..07d573f9c4 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -877,6 +877,14 @@ bool Framework::CheckMinMaxVisibleScale(m2::RectD & rect, int maxScale/* = -1*/) return false; } +void Framework::ShowRect(double lat, double lon, double zoom) +{ + m2::RectD rect = m_scales.GetRectForDrawScale(zoom, + m2::PointD(MercatorBounds::LonToX(lon), + MercatorBounds::LatToY(lat))); + ShowRectEx(rect); +} + void Framework::ShowRect(m2::RectD const & r) { m2::AnyRectD rect(r); diff --git a/map/framework.hpp b/map/framework.hpp index 9dbf98f2b6..8ed54d7fe2 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -374,6 +374,7 @@ private: void ShowRectFixed(m2::AnyRectD const & rect); public: + void ShowRect(double lat, double lon, double zoom); /// Set navigator viewport by rect as-is. void ShowRect(m2::RectD const & rect); /// - Use navigator rotate angle. diff --git a/map/navigator.cpp b/map/navigator.cpp index 65fdff0117..75698f0f9a 100644 --- a/map/navigator.cpp +++ b/map/navigator.cpp @@ -327,11 +327,6 @@ m2::PointD Navigator::ShiftPoint(m2::PointD const & pt) const return pt + m2::PointD(pxRect.minX(), pxRect.minY()); } -ScalesProcessor const & Navigator::GetScaleProcessor() const -{ - return m_scales; -} - void Navigator::StartDrag(m2::PointD const & pt, double /*timeInSec*/) { m_StartPt1 = m_LastPt1 = pt; diff --git a/map/navigator.hpp b/map/navigator.hpp index a7ba896e86..bbb2030092 100644 --- a/map/navigator.hpp +++ b/map/navigator.hpp @@ -66,8 +66,6 @@ public: /// so we should take it into an account m2::PointD ShiftPoint(m2::PointD const & pt) const; - ScalesProcessor const & GetScaleProcessor() const; - private: ScalesProcessor const & m_scales; diff --git a/yopme_desktop/yopme_desktop.pro b/yopme_desktop/yopme_desktop.pro index 47573b00f5..c3073d16a9 100644 --- a/yopme_desktop/yopme_desktop.pro +++ b/yopme_desktop/yopme_desktop.pro @@ -53,11 +53,11 @@ macx-* { QMAKE_BUNDLE_DATA += OTHER_RES CLASSIFICATOR_RES SKIN_RES FONT_RES MWM_RES } -SOURCES += main.cpp\ - mainwindow.cpp \ - glwidget.cpp +SOURCES += main.cpp \ + mainwindow.cpp \ + glwidget.cpp \ HEADERS += mainwindow.hpp \ - glwidget.hpp + glwidget.hpp \ FORMS += mainwindow.ui