Add UiBench jank and macrobench tests for saveLayer performance
Create 2 jank tests and 1 macrobench that measure saveLayer performance: - Fling a ListView, which has a vertical fading edge. - Draw a canvas with 20 saveLayer/restore interleaved with other drawText and drawRect ops. Test: built and ran UiBench jank and macrobench tests. Change-Id: I5a50feb7431d597c92c7a49031505d41f397d175
This commit is contained in:
72
libs/hwui/tests/common/scenes/SaveLayer2Animation.cpp
Normal file
72
libs/hwui/tests/common/scenes/SaveLayer2Animation.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.
|
||||
*/
|
||||
|
||||
#include "TestSceneBase.h"
|
||||
#include <string>
|
||||
#include <hwui/Paint.h>
|
||||
#include <minikin/Layout.h>
|
||||
|
||||
class SaveLayer2Animation;
|
||||
|
||||
static TestScene::Registrar _SaveLayer(TestScene::Info{
|
||||
"savelayer2",
|
||||
"Interleaving 20 drawText/drawRect ops with saveLayer"
|
||||
"Tests the clipped saveLayer performance and FBO switching overhead.",
|
||||
TestScene::simpleCreateScene<SaveLayer2Animation>
|
||||
});
|
||||
|
||||
class SaveLayer2Animation : public TestScene {
|
||||
public:
|
||||
Paint mBluePaint;
|
||||
Paint mGreenPaint;
|
||||
|
||||
void createContent(int width, int height, Canvas& canvas) override {
|
||||
canvas.drawColor(SkColorSetARGB(255, 255, 0, 0), SkBlendMode::kSrcOver);
|
||||
SkIRect bounds = SkIRect::MakeWH(width, height);
|
||||
int regions = 20;
|
||||
int smallRectHeight = (bounds.height()/regions);
|
||||
int padding = smallRectHeight / 4;
|
||||
int top = bounds.fTop;
|
||||
|
||||
mBluePaint.setColor(SkColorSetARGB(255, 0, 0, 255));
|
||||
mBluePaint.setTextSize(padding);
|
||||
mGreenPaint.setColor(SkColorSetARGB(255, 0, 255, 0));
|
||||
mGreenPaint.setTextSize(padding);
|
||||
|
||||
//interleave drawText and drawRect with saveLayer ops
|
||||
for (int i = 0; i < regions; i++, top += smallRectHeight) {
|
||||
canvas.saveLayer(bounds.fLeft, top, bounds.fRight, top + padding,
|
||||
&mBluePaint, SaveFlags::ClipToLayer | SaveFlags::MatrixClip);
|
||||
canvas.drawColor(SkColorSetARGB(255, 255, 255, 0), SkBlendMode::kSrcOver);
|
||||
std::string stri = std::to_string(i);
|
||||
std::string offscreen = "offscreen line " + stri;
|
||||
std::unique_ptr<uint16_t[]> offtext = TestUtils::asciiToUtf16(offscreen.c_str());
|
||||
canvas.drawText(offtext.get(), 0, offscreen.length(), offscreen.length(),
|
||||
bounds.fLeft, top + padding, minikin::kBidi_Force_LTR, mBluePaint, nullptr);
|
||||
canvas.restore();
|
||||
|
||||
canvas.drawRect(bounds.fLeft, top + padding, bounds.fRight,
|
||||
top + smallRectHeight - padding, mBluePaint);
|
||||
std::string onscreen = "onscreen line " + stri;
|
||||
std::unique_ptr<uint16_t[]> ontext = TestUtils::asciiToUtf16(onscreen.c_str());
|
||||
canvas.drawText(ontext.get(), 0, onscreen.length(), onscreen.length(), bounds.fLeft,
|
||||
top + smallRectHeight - padding, minikin::kBidi_Force_LTR, mGreenPaint,
|
||||
nullptr);
|
||||
}
|
||||
}
|
||||
void doFrame(int frameNr) override {
|
||||
}
|
||||
};
|
||||
@@ -99,6 +99,22 @@
|
||||
<category android:name="com.android.test.uibench.TEST" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".FadingEdgeListActivity"
|
||||
android:label="General/Fading Edge ListView" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="com.android.test.uibench.TEST" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".SaveLayerInterleaveActivity"
|
||||
android:label="General/SaveLayer Animation" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="com.android.test.uibench.TEST" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ClippedListActivity"
|
||||
android:label="General/Clipped ListView"
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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 com.android.test.uibench;
|
||||
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListAdapter;
|
||||
|
||||
import com.android.test.uibench.listview.CompatListActivity;
|
||||
import com.android.test.uibench.listview.FadingEdgeListFragment;
|
||||
|
||||
public class FadingEdgeListActivity extends CompatListActivity {
|
||||
|
||||
@Override
|
||||
protected ListAdapter createListAdapter() {
|
||||
return new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
|
||||
TextUtils.buildSimpleStringList(40));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListFragment createListFragment() {
|
||||
return (ListFragment)new FadingEdgeListFragment();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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 com.android.test.uibench;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
/**
|
||||
* Test Canvas.saveLayer performance by interleaving drawText/drawRect with saveLayer.
|
||||
* This test will be used to measure if drawing interleaved layers at the beginning of a frame will
|
||||
* decrease FBO switching overhead (this is a future optimization in SkiaGL rendering pipeline).
|
||||
*/
|
||||
public class SaveLayerInterleaveActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setBackgroundDrawable(new Drawable() {
|
||||
private final Paint mBluePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
private final Paint mGreenPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
return PixelFormat.OPAQUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter colorFilter) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
canvas.drawColor(Color.RED);
|
||||
|
||||
Rect bounds = getBounds();
|
||||
int regions = 20;
|
||||
int smallRectHeight = (bounds.height()/regions);
|
||||
int padding = smallRectHeight / 4;
|
||||
int top = bounds.top;
|
||||
mBluePaint.setColor(Color.BLUE);
|
||||
mBluePaint.setTextSize(padding);
|
||||
mGreenPaint.setColor(Color.GREEN);
|
||||
mGreenPaint.setTextSize(padding);
|
||||
|
||||
//interleave drawText and drawRect with saveLayer ops
|
||||
for (int i = 0; i < regions; i++, top += smallRectHeight) {
|
||||
canvas.saveLayer(bounds.left, top, bounds.right, top + padding,
|
||||
mBluePaint);
|
||||
canvas.drawColor(Color.YELLOW);
|
||||
canvas.drawText("offscreen line "+ i, bounds.left, top + padding,
|
||||
mBluePaint);
|
||||
canvas.restore();
|
||||
|
||||
Rect partX = new Rect(bounds.left, top + padding,
|
||||
bounds.right,top + smallRectHeight - padding);
|
||||
canvas.drawRect(partX, mBluePaint);
|
||||
canvas.drawText("onscreen line "+ i, bounds.left,
|
||||
top + smallRectHeight - padding, mGreenPaint);
|
||||
}
|
||||
|
||||
invalidateSelf();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -29,11 +29,15 @@ public abstract class CompatListActivity extends AppCompatActivity {
|
||||
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
if (fm.findFragmentById(android.R.id.content) == null) {
|
||||
ListFragment listFragment = new ListFragment();
|
||||
ListFragment listFragment = createListFragment();
|
||||
listFragment.setListAdapter(createListAdapter());
|
||||
fm.beginTransaction().add(android.R.id.content, listFragment).commit();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract ListAdapter createListAdapter();
|
||||
|
||||
protected ListFragment createListFragment() {
|
||||
return new ListFragment();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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 com.android.test.uibench.listview;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class FadingEdgeListFragment extends ListFragment {
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
ListView listView = getListView();
|
||||
listView.setVerticalFadingEdgeEnabled(true);
|
||||
listView.setFadingEdgeLength(500);
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user