Merge "Add Outline/RenderNode perf tests"

This commit is contained in:
Chris Craik
2016-12-12 21:15:05 +00:00
committed by Android (Google) Code Review
2 changed files with 109 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.graphics.perftests;
import android.graphics.Outline;
import android.perftests.utils.BenchmarkState;
import android.perftests.utils.PerfStatusReporter;
import android.support.test.filters.LargeTest;
import android.view.RenderNode;
import org.junit.Rule;
import org.junit.Test;
@LargeTest
public class OutlinePerfTest {
@Rule
public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
@Test
public void testSetEmpty() {
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
Outline outline = new Outline();
while (state.keepRunning()) {
outline.setEmpty();
}
}
@Test
public void testSetRoundRect() {
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
Outline outline = new Outline();
while (state.keepRunning()) {
outline.setRoundRect(50, 50, 150, 150, 5);
}
}
}

View File

@@ -16,14 +16,18 @@
package android.graphics.perftests;
import android.graphics.Outline;
import android.perftests.utils.BenchmarkState;
import android.perftests.utils.PerfStatusReporter;
import android.support.test.filters.LargeTest;
import android.view.DisplayListCanvas;
import android.view.RenderNode;
import org.junit.Rule;
import org.junit.Test;
import java.util.ArrayList;
@LargeTest
public class RenderNodePerfTest {
@Rule
@@ -65,4 +69,58 @@ public class RenderNodePerfTest {
node.isValid();
}
}
@Test
public void testStartEnd() {
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
RenderNode node = RenderNode.create("LinearLayout", null);
while (state.keepRunning()) {
DisplayListCanvas canvas = node.start(100, 100);
node.end(canvas);
}
}
@Test
public void testStartEndDeepHierarchy() {
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
RenderNode[] nodes = new RenderNode[30];
DisplayListCanvas[] canvases = new DisplayListCanvas[nodes.length];
for (int i = 0; i < nodes.length; i++) {
nodes[i] = RenderNode.create("LinearLayout", null);
}
while (state.keepRunning()) {
for (int i = 0; i < nodes.length; i++) {
canvases[i] = nodes[i].start(100, 100);
}
for (int i = nodes.length - 1; i >= 0; i--) {
nodes[i].end(canvases[i]);
}
}
}
@Test
public void testHasIdentityMatrix() {
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
RenderNode node = RenderNode.create("LinearLayout", null);
while (state.keepRunning()) {
node.hasIdentityMatrix();
}
}
@Test
public void testSetOutline() {
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
RenderNode node = RenderNode.create("LinearLayout", null);
Outline a = new Outline();
a.setRoundRect(0, 0, 100, 100, 10);
Outline b = new Outline();
b.setRect(50, 50, 150, 150);
b.setAlpha(0.5f);
while (state.keepRunning()) {
node.setOutline(a);
node.setOutline(b);
}
}
}