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
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(
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);
env->DeleteWeakGlobalRef(gActivityGlue.m_obj);
gActivityGlue.m_obj = NULL;
}
- delete gWindow;
- gWindow = NULL;
}
{
gWindow->saveToPdf();
}
+
+JNIEXPORT void JNICALL Java_com_skia_sampleapp_SampleApp_postInval(
+ JNIEnv* env, jobject thiz)
+{
+ gWindow->postInvalDelay();
+}
}
@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
native void processSkEvent();
native void serviceQueueTimer();
native void saveToPdf();
+ native void postInval();
static {
System.loadLibrary("skia-sample");
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() {
///////////////
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) {
if (fMeasureFPS && fMeasureFPS_Time) {
fMeasureFPS_Time = SkTime::GetMSecs() - fMeasureFPS_Time;
this->updateTitle();
- postInvalDelay(this->getSinkID());
+ this->postInvalDelay();
}
// if ((fScrollTestX | fScrollTestY) != 0)
}
bool SampleWindow::previousSample() {
- fCurrIndex = (fCurrIndex - 1) % fSamples.count();
+ fCurrIndex = (fCurrIndex - 1 + fSamples.count()) % fSamples.count();
this->loadView(fSamples[fCurrIndex]());
return true;
}
#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
}
bool handleTouch(int ownerId, float x, float y,
SkView::Click::State state);
void saveToPdf();
+ void postInvalDelay();
protected:
virtual void onDraw(SkCanvas* canvas);
gWindow->loop();
+ delete gWindow;
application_term();
return 0;
}