From 09b6b69ad565ef5cb22ffa9097861884e2722cb0 Mon Sep 17 00:00:00 2001 From: rachytski Date: Sat, 5 Nov 2011 20:48:11 +0400 Subject: [PATCH] [ANDROID] Implemented VideoTimer and correct rendering cycle. --- android/jni/Android.mk | 1 + android/jni/com/mapswithme/maps/Framework.cpp | 16 ++-- .../jni/com/mapswithme/maps/VideoTimer.cpp | 90 +++++++++++++++++++ .../jni/com/mapswithme/maps/VideoTimer.hpp | 41 +++++++++ .../src/com/mapswithme/maps/MainGLView.java | 4 + .../src/com/mapswithme/maps/VideoTimer.java | 59 ++++++++++++ 6 files changed, 205 insertions(+), 6 deletions(-) create mode 100644 android/jni/com/mapswithme/maps/VideoTimer.cpp create mode 100644 android/jni/com/mapswithme/maps/VideoTimer.hpp create mode 100644 android/src/com/mapswithme/maps/VideoTimer.java diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 7a039cae4b..6c1b88e602 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -29,6 +29,7 @@ LOCAL_SRC_FILES := \ com/mapswithme/location/LocationService.cpp \ com/mapswithme/maps/DownloadUI.cpp \ com/mapswithme/maps/Framework.cpp \ + com/mapswithme/maps/VideoTimer.cpp \ com/mapswithme/maps/GesturesProcessor.cpp \ com/mapswithme/maps/MainGLView.cpp \ com/mapswithme/maps/Platform.cpp \ diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index ca5ded20b9..478f89b197 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -6,6 +6,7 @@ */ #include "Framework.hpp" +#include "VideoTimer.hpp" #include "../core/jni_helper.hpp" #include "../core/render_context.hpp" @@ -47,7 +48,7 @@ namespace android ASSERT(g_framework == 0, ()); g_framework = this; - // @TODO refactor storage + // @TODO refactor storage m_storage.ReInitCountries(false); } @@ -86,6 +87,7 @@ namespace android p.m_glyphCacheID = m_rm->guiThreadGlyphCacheID(); p.m_frameBuffer = make_shared_ptr(new yg::gl::FrameBuffer(true)); p.m_skinName = pl.SkinName(); + p.m_useTinyStorage = true; m_drawer = make_shared_ptr(new DrawerYG(p)); } @@ -103,8 +105,8 @@ namespace android Platform & pl = GetPlatform(); m_rm = make_shared_ptr(new yg::ResourceManager( - bigVBSize, bigIBSize, 40, - smallVBSize, smallIBSize, 10, + bigVBSize, bigIBSize, 100, + smallVBSize, smallIBSize, 100, blitVBSize, blitIBSize, 10, 512, 256, 6, 512, 256, 4, @@ -112,9 +114,11 @@ namespace android "fonts_whitelist.txt", "fonts_blacklist.txt", 2 * 1024 * 1024, - 1, + 3, yg::Rt8Bpp, - false)); + true)); + + m_rm->initTinyStorage(300 * sizeof(yg::gl::Vertex), 600 * sizeof(unsigned short), 30); Platform::FilesList fonts; pl.GetFontNames(fonts); @@ -128,7 +132,7 @@ namespace android drule::rules().ForEachRule(make_all_invalid(GetPlatform().CpuCores() + 1)); // temporary workaround - m_work.SetRenderPolicy(shared_ptr(new RenderPolicyST(m_handle, bind(&::Framework::DrawModel, &m_work, _1, _2, _3, _4, _5, false)))); + m_work.SetRenderPolicy(shared_ptr(new PartialRenderPolicy(m_handle, bind(&::Framework::DrawModel, &m_work, _1, _2, _3, _4, _5, false)))); m_rc = make_shared_ptr(new android::RenderContext()); diff --git a/android/jni/com/mapswithme/maps/VideoTimer.cpp b/android/jni/com/mapswithme/maps/VideoTimer.cpp new file mode 100644 index 0000000000..100fa93d00 --- /dev/null +++ b/android/jni/com/mapswithme/maps/VideoTimer.cpp @@ -0,0 +1,90 @@ +/* + * VideoTimer.cpp + * + * Created on: Nov 5, 2011 + * Author: siarheirachytski + */ + +#include "../core/jni_helper.hpp" +#include "VideoTimer.hpp" +#include "../../../../../base/assert.hpp" + +android::VideoTimer * g_timer = 0; + +namespace android +{ + VideoTimer::VideoTimer(JavaVM * javaVM, TFrameFn frameFn) + : m_javaVM(javaVM), ::VideoTimer(frameFn) + { + ASSERT(g_timer == 0, ()); + g_timer = this; + } + + VideoTimer::~VideoTimer() + { + stop(); + g_timer = 0; + } + + void VideoTimer::SetParentObject(jobject videoTimer) + { + m_videoTimer = videoTimer; + } + + void VideoTimer::start() + { + JNIEnv * env; + m_javaVM->AttachCurrentThread(&env, NULL); + env->CallVoidMethod(m_videoTimer, jni::GetJavaMethodID(env, m_videoTimer, "start", "()V")); + m_state = ERunning; + } + + void VideoTimer::resume() + { + JNIEnv * env; + m_javaVM->AttachCurrentThread(&env, NULL); + env->CallVoidMethod(m_videoTimer, jni::GetJavaMethodID(env, m_videoTimer, "resume", "()V")); + m_state = ERunning; + } + + void VideoTimer::pause() + { + JNIEnv * env; + m_javaVM->AttachCurrentThread(&env, NULL); + env->CallVoidMethod(m_videoTimer, jni::GetJavaMethodID(env, m_videoTimer, "pause", "()V")); + m_state = EPaused; + } + + void VideoTimer::stop() + { + JNIEnv * env; + m_javaVM->AttachCurrentThread(&env, NULL); + env->CallVoidMethod(m_videoTimer, jni::GetJavaMethodID(env, m_videoTimer, "stop", "()V")); + m_state = EStopped; + } + + void VideoTimer::perform() + { + m_frameFn(); + } +} + +extern "C" +{ + JNIEXPORT void JNICALL + Java_com_mapswithme_maps_VideoTimer_nativeRun(JNIEnv * env, jobject thiz) + { + ASSERT ( g_timer, ()); + g_timer->perform(); + } + + JNIEXPORT void JNICALL + Java_com_mapswithme_maps_VideoTimer_nativeInit(JNIEnv * env, jobject thiz) + { + ASSERT ( g_timer, ()); + g_timer->SetParentObject(thiz); + } +} + + + diff --git a/android/jni/com/mapswithme/maps/VideoTimer.hpp b/android/jni/com/mapswithme/maps/VideoTimer.hpp new file mode 100644 index 0000000000..56669eeb10 --- /dev/null +++ b/android/jni/com/mapswithme/maps/VideoTimer.hpp @@ -0,0 +1,41 @@ +/* + * VideoTimer.hpp + * + * Created on: Nov 5, 2011 + * Author: siarheirachytski + */ + +#pragma once + +#include +#include "../../../../../platform/video_timer.hpp" + +namespace android +{ + class VideoTimer : public ::VideoTimer + { + private: + JavaVM * m_javaVM; + + jobject m_videoTimer; + + public: + + VideoTimer(JavaVM * jvm, TFrameFn frameFn); + ~VideoTimer(); + + void SetParentObject(jobject videoTimer); + + void start(); + + void stop(); + + void resume(); + + void pause(); + + void perform(); + }; +} + +extern android::VideoTimer * g_timer; diff --git a/android/src/com/mapswithme/maps/MainGLView.java b/android/src/com/mapswithme/maps/MainGLView.java index 9686563161..2441ba503e 100644 --- a/android/src/com/mapswithme/maps/MainGLView.java +++ b/android/src/com/mapswithme/maps/MainGLView.java @@ -1,6 +1,7 @@ package com.mapswithme.maps; import com.mapswithme.maps.GesturesProcessor; +import com.mapswithme.maps.VideoTimer; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; @@ -15,6 +16,7 @@ public class MainGLView extends GLSurfaceView private static String TAG = "MainGLView"; GesturesProcessor m_gestures; + VideoTimer m_timer; public MainGLView(Context context) { @@ -29,6 +31,8 @@ public class MainGLView extends GLSurfaceView // Do native initialization with OpenGL. nativeInit(); + m_timer = new VideoTimer(); + setRenderer(new MainRenderer()); // When renderMode is RENDERMODE_WHEN_DIRTY, the renderer only rendered diff --git a/android/src/com/mapswithme/maps/VideoTimer.java b/android/src/com/mapswithme/maps/VideoTimer.java new file mode 100644 index 0000000000..ee75de76ba --- /dev/null +++ b/android/src/com/mapswithme/maps/VideoTimer.java @@ -0,0 +1,59 @@ +package com.mapswithme.maps; + +import java.util.Timer; +import java.util.TimerTask; + +public class VideoTimer { + + private static String TAG = "VideoTimer"; + + Timer m_timer; + + private native void nativeInit(); + private native void nativeRun(); + + + public class VideoTimerTask extends TimerTask { + + @Override + public void run() { + nativeRun(); + } + } + + VideoTimerTask m_timerTask; + int m_interval; + + public VideoTimer() + { + m_interval = 1000 / 60; + nativeInit(); + } + + void start() + { + m_timerTask = new VideoTimerTask(); + m_timer = new Timer("VideoTimer"); + m_timer.scheduleAtFixedRate(m_timerTask, 0, m_interval); + } + + void resume() + { + m_timerTask = new VideoTimerTask(); + m_timer = new Timer("VideoTimer"); + m_timer.scheduleAtFixedRate(m_timerTask, 0, m_interval); + } + + void pause() + { + m_timer.cancel(); +// m_timer.purge(); + } + + void stop() + { + m_timer.cancel(); +// m_timer.purge(); + } + +}