From 397876c838fdf796194e8ff9a36a29b056593d26 Mon Sep 17 00:00:00 2001 From: vng Date: Sat, 2 Jul 2011 01:12:33 +0300 Subject: [PATCH] [Android] - Add rendering routine; - Add more framework routine; - Add logging; --- android/jni/Android.mk | 2 + android/jni/framework.cpp | 49 +++++++++-- android/jni/framework.h | 6 +- android/jni/jni_helper.cpp | 5 +- android/jni/jni_string.cpp | 13 ++- android/jni/logging.cpp | 13 ++- android/jni/logging.h | 2 + android/jni/main_native.cpp | 14 ++- android/jni/platform.cpp | 5 ++ android/jni/rendering.cpp | 85 +++++++++++++++++++ android/jni/rendering.h | 13 +++ .../src/com/mapswithme/maps/MainGLView.java | 7 +- 12 files changed, 200 insertions(+), 14 deletions(-) create mode 100644 android/jni/rendering.cpp create mode 100644 android/jni/rendering.h diff --git a/android/jni/Android.mk b/android/jni/Android.mk index eee9e00d76..6ba1b03ed6 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -13,6 +13,7 @@ LOCAL_HEADER_FILES := \ logging.h \ platform.h \ framework.h \ + rendering.h \ LOCAL_SRC_FILES := \ main_native.cpp \ @@ -22,6 +23,7 @@ LOCAL_SRC_FILES := \ framework.cpp \ logging.cpp \ temp_stubs.cpp \ + rendering.cpp \ LOCAL_LDLIBS := -llog -lGLESv1_CM \ -lwords -lmap -lstorage -lversion -lsearch -lindexer -lyg -lplatform \ diff --git a/android/jni/framework.cpp b/android/jni/framework.cpp index 89a03872c1..87322ba7c2 100644 --- a/android/jni/framework.cpp +++ b/android/jni/framework.cpp @@ -1,7 +1,8 @@ #include "framework.h" #include "jni_helper.h" +#include "rendering.h" -#include "../../map/drawer_yg.hpp" +#include "../../base/logging.hpp" void AndroidFramework::ViewHandle::invalidateImpl() @@ -27,9 +28,47 @@ void AndroidFramework::SetParentView(JNIEnv * env, jobject view) m_parentView = view; } -void AndroidFramework::Init() +void AndroidFramework::InitRenderer() { - //initializeGL(); - //m_view->setDrawer(new DrawerYG()); - //m_view->setRenderContext(); + LOG(LDEBUG, ("AF::InitRenderer 1")); + shared_ptr pRC = CreateRenderContext(); + + LOG(LDEBUG, ("AF::InitRenderer 2")); + shared_ptr pRM = CreateResourceManager(); + + LOG(LDEBUG, ("AF::InitRenderer 3")); + m_view->setRenderContext(pRC); + m_view->setDrawer(CreateDrawer(pRM)); + + LOG(LDEBUG, ("AF::InitRenderer 4")); + m_work.initializeGL(pRC, pRM); + + LOG(LDEBUG, ("AF::InitRenderer 5")); +} + +void AndroidFramework::Resize(int w, int h) +{ + LOG(LDEBUG, ("AF::Resize 1")); + m_view->drawer()->onSize(w, h); + LOG(LDEBUG, ("AF::Resize 2")); +} + +void AndroidFramework::DrawFrame() +{ + LOG(LDEBUG, ("AF::DrawFrame 1")); + shared_ptr p = m_view->drawer(); + + LOG(LDEBUG, ("AF::DrawFrame 2")); + p->beginFrame(); + + LOG(LDEBUG, ("AF::DrawFrame 3")); + p->clear(); + + LOG(LDEBUG, ("AF::DrawFrame 4")); + p->screen()->drawRectangle(m2::RectD(100, 100, 200, 200), yg::Color(255, 0, 0, 255), yg::maxDepth); + + LOG(LDEBUG, ("AF::DrawFrame 5")); + p->endFrame(); + + LOG(LDEBUG, ("AF::DrawFrame 6")); } diff --git a/android/jni/framework.h b/android/jni/framework.h index f7c0f1fe23..4918393da9 100644 --- a/android/jni/framework.h +++ b/android/jni/framework.h @@ -35,5 +35,9 @@ public: void SetParentView(JNIEnv * env, jobject view); - void Init(); + void InitRenderer(); + + void Resize(int w, int h); + + void DrawFrame(); }; diff --git a/android/jni/jni_helper.cpp b/android/jni/jni_helper.cpp index eed7e77d16..a2c253e1c8 100644 --- a/android/jni/jni_helper.cpp +++ b/android/jni/jni_helper.cpp @@ -1,6 +1,6 @@ #include "jni_helper.h" -#include +#include "../../base/assert.hpp" namespace jni { @@ -11,9 +11,10 @@ namespace jni { jmethodID GetJavaMethodID(JNIEnv * env, jobject obj, char const * fn, char const * sig) { + ASSERT ( env != 0 && obj != 0, () ); jclass cls = env->GetObjectClass(obj); jmethodID mid = env->GetMethodID(cls, fn, sig); - assert(mid != 0); + ASSERT ( mid != 0, () ); return mid; } diff --git a/android/jni/jni_string.cpp b/android/jni/jni_string.cpp index e6b7a3b3a9..6d2f9c1c3b 100644 --- a/android/jni/jni_string.cpp +++ b/android/jni/jni_string.cpp @@ -1,7 +1,10 @@ #include "jni_string.h" -namespace jni { +#include "../../base/string_utils.hpp" + +namespace jni +{ String::String(JNIEnv * env, jstring s) : m_env(env), m_s(s) { @@ -15,8 +18,12 @@ namespace jni { string String::ToString() const { - /// @todo - return std::string(); + size_t const sz = m_env->GetStringLength(m_s); + + string res; + utf8::unchecked::utf16to8(m_ret, m_ret + sz, back_inserter(res)); + + return res; } string ToString(JNIEnv * env, jstring s) diff --git a/android/jni/logging.cpp b/android/jni/logging.cpp index 682bf42849..715fbb4046 100644 --- a/android/jni/logging.cpp +++ b/android/jni/logging.cpp @@ -19,7 +19,13 @@ void AndroidLogMessage(LogLevel l, SrcPoint const & src, string const & s) case LCRITICAL: pr = ANDROID_LOG_FATAL; break; } - __android_log_print(pr, "mapswithme", s.c_str()); + string const out = debug_print(src) + " " + s; + __android_log_print(pr, "MapsWithMe_JNI", out.c_str()); +} + +void AndroidAssertMessage(SrcPoint const & src, string const & s) +{ + AndroidLogMessage(LERROR, src, s); } void InitSystemLog() @@ -27,4 +33,9 @@ void InitSystemLog() SetLogMessageFn(&AndroidLogMessage); } +void InitAssertLog() +{ + OnAssertFailed = &AndroidAssertMessage; +} + } diff --git a/android/jni/logging.h b/android/jni/logging.h index fe1187cdd9..213b17345f 100644 --- a/android/jni/logging.h +++ b/android/jni/logging.h @@ -1,8 +1,10 @@ #pragma once #include "../../base/logging.hpp" +#include "../../base/assert.hpp" namespace jni { void InitSystemLog(); + void InitAssertLog(); } diff --git a/android/jni/main_native.cpp b/android/jni/main_native.cpp index d67e5dd2ce..3e68b7f9d4 100644 --- a/android/jni/main_native.cpp +++ b/android/jni/main_native.cpp @@ -6,7 +6,7 @@ #include -AndroidFramework * g_work; +AndroidFramework * g_work = 0; extern "C" { @@ -18,10 +18,15 @@ extern "C" Java_com_mapswithme_maps_MWMActivity_nativeInit(JNIEnv * env, jobject thiz, jstring path) { jni::InitSystemLog(); + jni::InitAssertLog(); + LOG(LDEBUG, ("MWMActivity::Init 1")); GetAndroidPlatform().Initialize(env, thiz, path); + LOG(LDEBUG, ("MWMActivity::Init 2")); //g_work = new AndroidFramework(); + + LOG(LDEBUG, ("MWMActivity::Init 3")); } /////////////////////////////////////////////////////////////////////////////////// @@ -31,6 +36,7 @@ extern "C" JNIEXPORT void JNICALL Java_com_mapswithme_maps_MainGLView_nativeInit(JNIEnv * env, jobject thiz) { + //ASSERT ( g_work, () ); //g_work->SetParentView(env, thiz); } @@ -53,15 +59,21 @@ extern "C" JNIEXPORT void JNICALL Java_com_mapswithme_maps_MainRenderer_nativeInit(JNIEnv * env, jobject thiz) { + //ASSERT ( g_work, () ); + //g_work->InitRenderer(); } JNIEXPORT void JNICALL Java_com_mapswithme_maps_MainRenderer_nativeResize(JNIEnv * env, jobject thiz, jint w, jint h) { + //ASSERT ( g_work, () ); + //g_work->Resize(w, h); } JNIEXPORT void JNICALL Java_com_mapswithme_maps_MainRenderer_nativeDraw(JNIEnv * env, jobject thiz) { + //ASSERT ( g_work, () ); + //g_work->DrawFrame(); } } diff --git a/android/jni/platform.cpp b/android/jni/platform.cpp index 8a02860c37..85c3c29424 100644 --- a/android/jni/platform.cpp +++ b/android/jni/platform.cpp @@ -1,10 +1,15 @@ #include "platform.h" #include "jni_string.h" +#include "../../base/logging.hpp" + void AndroidPlatform::Initialize(JNIEnv * env, jobject activity, jstring path) { m_writableDir = m_resourcesDir = jni::ToString(env, path); + + LOG(LDEBUG, ("Resource path = ", m_resourcesDir)); + LOG(LDEBUG, ("Writable path = ", m_writableDir)); } int AndroidPlatform::CpuCores() const diff --git a/android/jni/rendering.cpp b/android/jni/rendering.cpp new file mode 100644 index 0000000000..94646b8833 --- /dev/null +++ b/android/jni/rendering.cpp @@ -0,0 +1,85 @@ +#include "rendering.h" + +#include "../../yg/framebuffer.hpp" +#include "../../yg/internal/opengl.hpp" + +#include "../../platform/platform.hpp" + +#include "../../base/math.hpp" + + +shared_ptr CreateResourceManager() +{ + int bigVBSize = pow(2, ceil(log(15000 * sizeof(yg::gl::Vertex)))); + int bigIBSize = pow(2, ceil(log(30000 * sizeof(unsigned short)))); + + int smallVBSize = pow(2, ceil(log(1500 * sizeof(yg::gl::Vertex)))); + int smallIBSize = pow(2, ceil(log(3000 * sizeof(unsigned short)))); + + int blitVBSize = pow(2, ceil(log(10 * sizeof(yg::gl::AuxVertex)))); + int blitIBSize = pow(2, ceil(log(10 * sizeof(unsigned short)))); + + Platform & pl = GetPlatform(); + yg::ResourceManager * pRM = new yg::ResourceManager( + bigVBSize, bigIBSize, 4, + smallVBSize, smallIBSize, 10, + blitVBSize, blitIBSize, 10, + 512, 256, 6, + 512, 256, 4, + pl.ReadPathForFile("unicode_blocks.txt").c_str(), + pl.ReadPathForFile("fonts_whitelist.txt").c_str(), + pl.ReadPathForFile("fonts_blacklist.txt").c_str(), + 1 * 1024 * 1024, + 500 * 1024, + yg::Rt8Bpp, + !yg::gl::g_isBufferObjectsSupported, + !pl.IsMultiSampled()); + + Platform::FilesList fonts; + pl.GetFontNames(fonts); + pRM->addFonts(fonts); + + return make_shared_ptr(pRM); +} + +shared_ptr CreateDrawer(shared_ptr pRM) +{ + Platform & pl = GetPlatform(); + + DrawerYG::params_t p; + p.m_resourceManager = pRM; + p.m_isMultiSampled = pl.IsMultiSampled(); + p.m_frameBuffer.reset(new yg::gl::FrameBuffer()); + p.m_glyphCacheID = 1; + + return make_shared_ptr(new DrawerYG(pl.SkinName(), p)); +} + +namespace +{ + class AndroidRenderContext : public yg::gl::RenderContext + { + public: + AndroidRenderContext() + { + } + + virtual void makeCurrent() + { + } + + virtual shared_ptr createShared() + { + return make_shared_ptr(new AndroidRenderContext()); + } + + virtual void endThreadDrawing() + { + } + }; +} + +shared_ptr CreateRenderContext() +{ + return make_shared_ptr(new AndroidRenderContext()); +} diff --git a/android/jni/rendering.h b/android/jni/rendering.h new file mode 100644 index 0000000000..2cf4619a31 --- /dev/null +++ b/android/jni/rendering.h @@ -0,0 +1,13 @@ +#pragma once + +#include "../../map/drawer_yg.hpp" + +#include "../../yg/rendercontext.hpp" +#include "../../yg/resource_manager.hpp" + + +shared_ptr CreateResourceManager(); + +shared_ptr CreateRenderContext(); + +shared_ptr CreateDrawer(shared_ptr pRM); diff --git a/android/src/com/mapswithme/maps/MainGLView.java b/android/src/com/mapswithme/maps/MainGLView.java index 602cb52193..09c007165b 100644 --- a/android/src/com/mapswithme/maps/MainGLView.java +++ b/android/src/com/mapswithme/maps/MainGLView.java @@ -7,7 +7,7 @@ import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.opengl.GLSurfaceView; -//import android.util.Log; +import android.util.Log; import android.view.MotionEvent; public class MainGLView extends GLSurfaceView @@ -49,21 +49,26 @@ public class MainGLView extends GLSurfaceView class MainRenderer implements GLSurfaceView.Renderer { + private static String TAG = "MainGLView.MainRenderer"; + @Override public void onDrawFrame(GL10 gl) { + Log.i(TAG, "onDrawFrame"); nativeDraw(); } @Override public void onSurfaceChanged(GL10 gl, int w, int h) { + Log.i(TAG, "onSurfaceChanged"); nativeResize(w, h); } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { + Log.i(TAG, "onSurfaceCreated"); nativeInit(); }