aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Scroggo <Scroggo@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-21 16:01:26 +0000
committerGravatar Scroggo <Scroggo@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-21 16:01:26 +0000
commit62b65b0913566381db468277de07e5dd2a9237ca (patch)
treed5bfc75e09a389922f96b79d759bbfbcf3d861a9
parentfd0ffcf486a239d65b586bd638e5aaca907244de (diff)
SampleApp fixes.
On Android, delete gWindow before calling application_term, avoiding a crash each time the app closes. Also make sure the screen is redrawn when resuming. On Linux, delete gWindow to avoid memory leak. In general, allow moving from sample 0 to the last sample. Reviewed at http://codereview.appspot.com/4639060 git-svn-id: http://skia.googlecode.com/svn/trunk@1661 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--android_sample/SampleApp/jni/sample-jni.cpp12
-rw-r--r--android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java11
-rw-r--r--android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java9
-rw-r--r--samplecode/SampleApp.cpp10
-rw-r--r--samplecode/SampleApp.h1
-rw-r--r--unix_test_app/main.cpp1
6 files changed, 37 insertions, 7 deletions
diff --git a/android_sample/SampleApp/jni/sample-jni.cpp b/android_sample/SampleApp/jni/sample-jni.cpp
index a82256c31d..ffda03d796 100644
--- a/android_sample/SampleApp/jni/sample-jni.cpp
+++ b/android_sample/SampleApp/jni/sample-jni.cpp
@@ -173,6 +173,8 @@ JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_serviceQueueTimer(
JNIEnv* env, jobject thiz);
JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_saveToPdf(
JNIEnv* env, jobject thiz);
+JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_postInval(
+ JNIEnv* env, jobject thiz);
};
JNIEXPORT bool JNICALL Java_com_skia_sampleapp_SampleApp_handleKeyDown(
@@ -251,6 +253,8 @@ JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_init(JNIEnv* env,
JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_term(JNIEnv* env,
jobject thiz)
{
+ delete gWindow;
+ gWindow = NULL;
application_term();
if (gWindowGlue.m_obj) {
env->DeleteWeakGlobalRef(gWindowGlue.m_obj);
@@ -260,8 +264,6 @@ JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_term(JNIEnv* env,
env->DeleteWeakGlobalRef(gActivityGlue.m_obj);
gActivityGlue.m_obj = NULL;
}
- delete gWindow;
- gWindow = NULL;
}
@@ -373,3 +375,9 @@ JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_saveToPdf(
{
gWindow->saveToPdf();
}
+
+JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_postInval(
+ JNIEnv* env, jobject thiz)
+{
+ gWindow->postInvalDelay();
+}
diff --git a/android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java b/android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java
index bdd9f2b5e6..03a6d71553 100644
--- a/android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java
+++ b/android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java
@@ -63,6 +63,16 @@ public class SampleApp extends Activity
}
@Override
+ protected void onResume () {
+ super.onResume();
+ int width = mView.getWidth();
+ int height = mView.getHeight();
+ if (width > 0 && height > 0) {
+ mView.postInval();
+ }
+ }
+
+ @Override
public void onDestroy() {
mView.queueEvent(new Runnable() {
@Override
@@ -260,6 +270,7 @@ public class SampleApp extends Activity
native void processSkEvent();
native void serviceQueueTimer();
native void saveToPdf();
+ native void postInval();
static {
System.loadLibrary("skia-sample");
diff --git a/android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java b/android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java
index ab4e5c0d64..56f7c12ac6 100644
--- a/android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java
+++ b/android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java
@@ -42,6 +42,15 @@ public class SampleView extends GLSurfaceView {
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
+ public void postInval() {
+ queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ mApp.postInval();
+ }
+ });
+ }
+
// Called by JNI
@SuppressWarnings("unused")
private void queueSkEvent() {
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 2d5d0ca9c9..9c2b7d1344 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -53,9 +53,9 @@ extern SkView* create_overview(int, const SkViewFactory[]);
///////////////
static const char view_inval_msg[] = "view-inval-msg";
-static void postInvalDelay(SkEventSinkID sinkID) {
+void SampleWindow::postInvalDelay() {
SkEvent* evt = new SkEvent(view_inval_msg);
- evt->post(sinkID, 1);
+ evt->post(this->getSinkID(), 1);
}
static bool isInvalEvent(const SkEvent& evt) {
@@ -844,7 +844,7 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
if (fMeasureFPS && fMeasureFPS_Time) {
fMeasureFPS_Time = SkTime::GetMSecs() - fMeasureFPS_Time;
this->updateTitle();
- postInvalDelay(this->getSinkID());
+ this->postInvalDelay();
}
// if ((fScrollTestX | fScrollTestY) != 0)
@@ -928,7 +928,7 @@ void SampleWindow::changeZoomLevel(float delta) {
}
bool SampleWindow::previousSample() {
- fCurrIndex = (fCurrIndex - 1) % fSamples.count();
+ fCurrIndex = (fCurrIndex - 1 + fSamples.count()) % fSamples.count();
this->loadView(fSamples[fCurrIndex]());
return true;
}
@@ -1428,7 +1428,7 @@ void SampleWindow::onSizeChange() {
#ifdef ANDROID
// FIXME: The first draw after a size change does not work on Android, so
// we post an invalidate.
- postInvalDelay(this->getSinkID());
+ this->postInvalDelay();
#endif
this->updateTitle(); // to refresh our config
}
diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h
index a58c68873e..4d16121d04 100644
--- a/samplecode/SampleApp.h
+++ b/samplecode/SampleApp.h
@@ -61,6 +61,7 @@ public:
bool handleTouch(int ownerId, float x, float y,
SkView::Click::State state);
void saveToPdf();
+ void postInvalDelay();
protected:
virtual void onDraw(SkCanvas* canvas);
diff --git a/unix_test_app/main.cpp b/unix_test_app/main.cpp
index 5be93bc479..9dafb3c902 100644
--- a/unix_test_app/main.cpp
+++ b/unix_test_app/main.cpp
@@ -25,6 +25,7 @@ int main(){
gWindow->loop();
+ delete gWindow;
application_term();
return 0;
}