Optimize cinematic rendering for integrated Android TVs
This commit is contained in:
parent
dc5908cb3b
commit
1f69422354
15 changed files with 366 additions and 153 deletions
|
|
@ -3,4 +3,5 @@
|
|||
<application android:label="Luma wake regression tests" />
|
||||
<instrumentation android:name=".WakeRegressionInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
|
||||
<instrumentation android:name="tv.luma.launcher.UpdaterInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
|
||||
<instrumentation android:name=".PerformanceInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
|
||||
</manifest>
|
||||
|
|
|
|||
102
tests/device/PerformanceInstrumentation.java
Normal file
102
tests/device/PerformanceInstrumentation.java
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
package tv.luma.launcher.tests;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Instrumentation;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
/** Same-signature on-device A/B rendering benchmark; never shipped with Luma. */
|
||||
public final class PerformanceInstrumentation extends Instrumentation {
|
||||
private Object field(Object o, String name) throws Exception {
|
||||
Field f = o.getClass().getDeclaredField(name);
|
||||
f.setAccessible(true);
|
||||
return f.get(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle args) {
|
||||
super.onCreate(args);
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
Bundle result = new Bundle();
|
||||
try {
|
||||
Activity activity =
|
||||
startActivitySync(
|
||||
new Intent(Intent.ACTION_MAIN)
|
||||
.setComponent(
|
||||
new ComponentName("tv.luma.launcher", "tv.luma.launcher.MainActivity"))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
Thread.sleep(4000);
|
||||
View scene = (View) field(activity, "scene");
|
||||
Map<?, ?> tiles = (Map<?, ?>) field(activity, "tiles");
|
||||
View[] items = tiles.values().toArray(new View[0]);
|
||||
java.util.List<Long> times =
|
||||
java.util.Collections.synchronizedList(new java.util.ArrayList<>());
|
||||
android.os.HandlerThread listener = new android.os.HandlerThread("frame-metrics");
|
||||
listener.start();
|
||||
activity
|
||||
.getWindow()
|
||||
.addOnFrameMetricsAvailableListener(
|
||||
(w, f, d) -> times.add(f.getMetric(android.view.FrameMetrics.TOTAL_DURATION)),
|
||||
new android.os.Handler(listener.getLooper()));
|
||||
StringBuilder report = new StringBuilder();
|
||||
for (int mode = 0; mode < 3; mode++) {
|
||||
final int variant = mode;
|
||||
runOnMainSync(
|
||||
() -> {
|
||||
scene.setVisibility(variant == 1 ? View.INVISIBLE : View.VISIBLE);
|
||||
if (variant == 2)
|
||||
for (View item : items) {
|
||||
try {
|
||||
((View) field(item, "art")).setOutlineProvider(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
Thread.sleep(700);
|
||||
times.clear();
|
||||
for (int i = 0; i < 36; i++) {
|
||||
View target = items[(i % 12 < 6 ? i % 6 : 11 - i % 12) % Math.min(items.length, 6)];
|
||||
runOnMainSync(target::requestFocus);
|
||||
Thread.sleep(350);
|
||||
}
|
||||
java.util.List<Long> sample;
|
||||
synchronized (times) {
|
||||
sample = new java.util.ArrayList<>(times);
|
||||
}
|
||||
java.util.Collections.sort(sample);
|
||||
report.append("Variant=").append(mode).append(" frames=").append(sample.size());
|
||||
if (!sample.isEmpty())
|
||||
report
|
||||
.append(" medianMs=")
|
||||
.append(sample.get(sample.size() / 2) / 1e6)
|
||||
.append(" p90Ms=")
|
||||
.append(sample.get((int) (sample.size() * .9)) / 1e6)
|
||||
.append(" over16ms=")
|
||||
.append(sample.stream().filter(t -> t > 16666667).count());
|
||||
report.append('\n');
|
||||
try (java.io.FileWriter out =
|
||||
new java.io.FileWriter(
|
||||
new java.io.File(
|
||||
getTargetContext().getExternalFilesDir(null), "performance.txt"))) {
|
||||
out.write(report.toString());
|
||||
}
|
||||
}
|
||||
listener.quitSafely();
|
||||
result.putString(
|
||||
"stream", report.toString() + "PASS: background and shadow A/B benchmark completed\n");
|
||||
finish(Activity.RESULT_OK, result);
|
||||
} catch (Exception e) {
|
||||
result.putString("stream", e.toString());
|
||||
finish(Activity.RESULT_CANCELED, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,14 @@ public final class WakeRegressionInstrumentation extends Instrumentation {
|
|||
Bitmap image = (Bitmap) field(field(tile, "art"), "bitmap");
|
||||
if (image == null || image.isRecycled()) return false;
|
||||
}
|
||||
Bitmap wallpaper = (Bitmap) field(field(activity, "scene"), "wallpaper");
|
||||
Object scene = field(activity, "scene");
|
||||
Bitmap wallpaper = (Bitmap) field(scene, "wallpaper");
|
||||
Bitmap frame = (Bitmap) field(scene, "frame");
|
||||
if (frame == null || frame.isRecycled() || frame.getWidth() > 960 || frame.getHeight() > 540)
|
||||
return false;
|
||||
// A decoded source alone must not conceal a missing or blank composed background.
|
||||
if (frame.getPixel(frame.getWidth() * 3 / 4, frame.getHeight() / 4)
|
||||
== frame.getPixel(frame.getWidth() / 4, frame.getHeight() * 3 / 4)) return false;
|
||||
return wallpaper != null && !wallpaper.isRecycled();
|
||||
}
|
||||
|
||||
|
|
@ -177,6 +184,45 @@ public final class WakeRegressionInstrumentation extends Instrumentation {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
runOnMainSync(
|
||||
() -> {
|
||||
callActivityOnPause(activity);
|
||||
callActivityOnStop(activity);
|
||||
try {
|
||||
Object scene = field(activity, "scene");
|
||||
for (String name : new String[] {"wallpaper", "mediaArt", "frame", "previousFrame"})
|
||||
if (field(scene, name) != null)
|
||||
throw new AssertionError("background retained " + name);
|
||||
if (!((ThreadPoolExecutor) field(scene, "renderer")).getQueue().isEmpty())
|
||||
throw new AssertionError("background work retained after stop");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
callActivityOnRestart(activity);
|
||||
callActivityOnStart(activity);
|
||||
callActivityOnResume(activity);
|
||||
});
|
||||
awaitImages("composed background restores after all cached textures are released");
|
||||
runOnMainSync(
|
||||
() -> {
|
||||
try {
|
||||
java.lang.reflect.Method start = activity.getClass().getDeclaredMethod("startSaver");
|
||||
start.setAccessible(true);
|
||||
start.invoke(activity);
|
||||
Object scene = field(activity, "scene");
|
||||
if ((boolean) field(scene, "active"))
|
||||
throw new AssertionError("scene active under saver");
|
||||
java.lang.reflect.Method stop =
|
||||
activity.getClass().getDeclaredMethod("stopSaver", boolean.class);
|
||||
stop.setAccessible(true);
|
||||
stop.invoke(activity, true);
|
||||
if (!(boolean) field(scene, "active"))
|
||||
throw new AssertionError("scene paused after saver");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
awaitImages("screensaver dismissal resumes background rendering");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
runOnMainSync(
|
||||
() -> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue