summaryrefslogtreecommitdiffstats
path: root/libs/rs/java
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2010-09-28 15:45:45 -0700
committerStephen Hines <srhines@google.com>2010-09-29 16:58:17 -0700
commit01f0ad7c13b8878c2167bff10ea875d7509edca5 (patch)
treea23bced149e474da62c7da992015a5e3163486f9 /libs/rs/java
parent3ebb1ba50c9b98e5303eb21ed6fa488c3f9bd632 (diff)
downloadframeworks_base-01f0ad7c13b8878c2167bff10ea875d7509edca5.zip
frameworks_base-01f0ad7c13b8878c2167bff10ea875d7509edca5.tar.gz
frameworks_base-01f0ad7c13b8878c2167bff10ea875d7509edca5.tar.bz2
Fix clear() operation for rsScriptC.
- This removes a memory leak where some elements were not getting tracked properly (and then triggering an assert when a context is destroyed). - Convert ScriptCState to use a tracked object reference for mScript. - Add a missing clear to FontState. - Clean up synchronization in RSTest so that our graphics context outlives any subtest context. Change-Id: I0d5768c4d2f8810dd1ae2f68b1edd7e150f382fd
Diffstat (limited to 'libs/rs/java')
-rw-r--r--libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java51
-rw-r--r--libs/rs/java/tests/src/com/android/rs/test/RSTestView.java1
-rw-r--r--libs/rs/java/tests/src/com/android/rs/test/UT_fp_mad.java1
-rw-r--r--libs/rs/java/tests/src/com/android/rs/test/UT_primitives.java1
-rw-r--r--libs/rs/java/tests/src/com/android/rs/test/UnitTest.java9
5 files changed, 60 insertions, 3 deletions
diff --git a/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java b/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java
index dbc9133..835dea2 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java
@@ -21,6 +21,8 @@ import android.renderscript.*;
import android.util.Log;
import java.util.ArrayList;
import java.util.ListIterator;
+import java.util.Timer;
+import java.util.TimerTask;
public class RSTestCore {
@@ -42,12 +44,18 @@ public class RSTestCore {
private ArrayList<UnitTest> unitTests;
private ListIterator<UnitTest> test_iter;
private UnitTest activeTest;
+ private boolean stopTesting;
+
+ /* Periodic timer for ensuring future tests get scheduled */
+ private Timer mTimer;
+ public static final int RS_TIMER_PERIOD = 100;
public void init(RenderScriptGL rs, Resources res, int width, int height) {
mRS = rs;
mRes = res;
mWidth = width;
mHeight = height;
+ stopTesting = false;
mScript = new ScriptC_rslist(mRS, mRes, R.raw.rslist, true);
@@ -88,9 +96,17 @@ public class RSTestCore {
test_iter = unitTests.listIterator();
refreshTestResults(); /* Kick off the first test */
+
+ TimerTask pTask = new TimerTask() {
+ public void run() {
+ refreshTestResults();
+ }
+ };
+
+ mTimer = new Timer();
+ mTimer.schedule(pTask, RS_TIMER_PERIOD, RS_TIMER_PERIOD);
}
- static int count = 0;
public void checkAndRunNextTest() {
if (activeTest != null) {
if (!activeTest.isAlive()) {
@@ -104,7 +120,7 @@ public class RSTestCore {
}
}
- if (activeTest == null) {
+ if (!stopTesting && activeTest == null) {
if (test_iter.hasNext()) {
activeTest = test_iter.next();
activeTest.start();
@@ -112,8 +128,14 @@ public class RSTestCore {
* should start running. The message handler in UnitTest.java
* ensures this. */
}
+ else {
+ if (mTimer != null) {
+ mTimer.cancel();
+ mTimer.purge();
+ mTimer = null;
+ }
+ }
}
- count++;
}
public void refreshTestResults() {
@@ -127,6 +149,29 @@ public class RSTestCore {
}
}
+ public void cleanup() {
+ stopTesting = true;
+ UnitTest t = activeTest;
+
+ /* Stop periodic refresh of testing */
+ if (mTimer != null) {
+ mTimer.cancel();
+ mTimer.purge();
+ mTimer = null;
+ }
+
+ /* Wait to exit until we finish the current test */
+ if (t != null) {
+ try {
+ t.join();
+ }
+ catch (InterruptedException e) {
+ }
+ t = null;
+ }
+
+ }
+
public void newTouchPosition(float x, float y, float pressure, int id) {
}
diff --git a/libs/rs/java/tests/src/com/android/rs/test/RSTestView.java b/libs/rs/java/tests/src/com/android/rs/test/RSTestView.java
index ce99c6d..b811d48 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/RSTestView.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/RSTestView.java
@@ -62,6 +62,7 @@ public class RSTestView extends RSSurfaceView {
@Override
protected void onDetachedFromWindow() {
if(mRS != null) {
+ mRender.cleanup();
mRS = null;
destroyRenderScript();
}
diff --git a/libs/rs/java/tests/src/com/android/rs/test/UT_fp_mad.java b/libs/rs/java/tests/src/com/android/rs/test/UT_fp_mad.java
index 8391fb3..9d57e90 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/UT_fp_mad.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/UT_fp_mad.java
@@ -33,6 +33,7 @@ public class UT_fp_mad extends UnitTest {
pRS.mMessageCallback = mRsMessage;
s.invoke_fp_mad_test(0, 0);
pRS.finish();
+ waitForMessage();
pRS.destroy();
}
}
diff --git a/libs/rs/java/tests/src/com/android/rs/test/UT_primitives.java b/libs/rs/java/tests/src/com/android/rs/test/UT_primitives.java
index bef6ec5..fb355dd 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/UT_primitives.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/UT_primitives.java
@@ -33,6 +33,7 @@ public class UT_primitives extends UnitTest {
pRS.mMessageCallback = mRsMessage;
s.invoke_primitives_test(0, 0);
pRS.finish();
+ waitForMessage();
pRS.destroy();
}
}
diff --git a/libs/rs/java/tests/src/com/android/rs/test/UnitTest.java b/libs/rs/java/tests/src/com/android/rs/test/UnitTest.java
index 5eb0d67..c9d88a6 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/UnitTest.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/UnitTest.java
@@ -23,6 +23,7 @@ public class UnitTest extends Thread {
public int result;
private ScriptField_ListAllocs_s.Item mItem;
private RSTestCore mRSTC;
+ private boolean msgHandled;
/* These constants must match those in shared.rsh */
public static final int RS_MSG_TEST_PASSED = 100;
@@ -35,6 +36,7 @@ public class UnitTest extends Thread {
super();
mRSTC = rstc;
name = n;
+ msgHandled = false;
result = initResult;
testID = numTests++;
}
@@ -67,6 +69,7 @@ public class UnitTest extends Thread {
if (mItem != null) {
mItem.result = result;
+ msgHandled = true;
try {
mRSTC.refreshTestResults();
}
@@ -79,6 +82,12 @@ public class UnitTest extends Thread {
}
};
+ public void waitForMessage() {
+ while (!msgHandled) {
+ yield();
+ }
+ }
+
public void setItem(ScriptField_ListAllocs_s.Item item) {
mItem = item;
}