DisplayListCanvasBench.cpp revision 5e00c7ce063116c11315639f0035aca8ad73e8cc
1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include <benchmark/benchmark.h> 18 19#include "DisplayList.h" 20#include "RecordingCanvas.h" 21#include "tests/common/TestUtils.h" 22 23using namespace android; 24using namespace android::uirenderer; 25 26typedef RecordingCanvas TestCanvas; 27 28void BM_DisplayList_alloc(benchmark::State& benchState) { 29 while (benchState.KeepRunning()) { 30 auto displayList = new DisplayList(); 31 benchmark::DoNotOptimize(displayList); 32 delete displayList; 33 } 34} 35BENCHMARK(BM_DisplayList_alloc); 36 37void BM_DisplayList_alloc_theoretical(benchmark::State& benchState) { 38 while (benchState.KeepRunning()) { 39 auto displayList = new char[sizeof(DisplayList)]; 40 benchmark::DoNotOptimize(displayList); 41 delete[] displayList; 42 } 43} 44BENCHMARK(BM_DisplayList_alloc_theoretical); 45 46void BM_DisplayListCanvas_record_empty(benchmark::State& benchState) { 47 TestCanvas canvas(100, 100); 48 delete canvas.finishRecording(); 49 50 while (benchState.KeepRunning()) { 51 canvas.resetRecording(100, 100); 52 benchmark::DoNotOptimize(&canvas); 53 delete canvas.finishRecording(); 54 } 55} 56BENCHMARK(BM_DisplayListCanvas_record_empty); 57 58void BM_DisplayListCanvas_record_saverestore(benchmark::State& benchState) { 59 TestCanvas canvas(100, 100); 60 delete canvas.finishRecording(); 61 62 while (benchState.KeepRunning()) { 63 canvas.resetRecording(100, 100); 64 canvas.save(SaveFlags::MatrixClip); 65 canvas.save(SaveFlags::MatrixClip); 66 benchmark::DoNotOptimize(&canvas); 67 canvas.restore(); 68 canvas.restore(); 69 delete canvas.finishRecording(); 70 } 71} 72BENCHMARK(BM_DisplayListCanvas_record_saverestore); 73 74void BM_DisplayListCanvas_record_translate(benchmark::State& benchState) { 75 TestCanvas canvas(100, 100); 76 delete canvas.finishRecording(); 77 78 while (benchState.KeepRunning()) { 79 canvas.resetRecording(100, 100); 80 canvas.scale(10, 10); 81 benchmark::DoNotOptimize(&canvas); 82 delete canvas.finishRecording(); 83 } 84} 85BENCHMARK(BM_DisplayListCanvas_record_translate); 86 87/** 88 * Simulate a simple view drawing a background, overlapped by an image. 89 * 90 * Note that the recording commands are intentionally not perfectly efficient, as the 91 * View system frequently produces unneeded save/restores. 92 */ 93void BM_DisplayListCanvas_record_simpleBitmapView(benchmark::State& benchState) { 94 TestCanvas canvas(100, 100); 95 delete canvas.finishRecording(); 96 97 SkPaint rectPaint; 98 SkBitmap iconBitmap = TestUtils::createSkBitmap(80, 80); 99 100 while (benchState.KeepRunning()) { 101 canvas.resetRecording(100, 100); 102 { 103 canvas.save(SaveFlags::MatrixClip); 104 canvas.drawRect(0, 0, 100, 100, rectPaint); 105 canvas.restore(); 106 } 107 { 108 canvas.save(SaveFlags::MatrixClip); 109 canvas.translate(10, 10); 110 canvas.drawBitmap(iconBitmap, 0, 0, nullptr); 111 canvas.restore(); 112 } 113 benchmark::DoNotOptimize(&canvas); 114 delete canvas.finishRecording(); 115 } 116} 117BENCHMARK(BM_DisplayListCanvas_record_simpleBitmapView); 118 119class NullClient: public CanvasStateClient { 120 void onViewportInitialized() override {} 121 void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) {} 122 GLuint getTargetFbo() const override { return 0; } 123}; 124 125void BM_CanvasState_saverestore(benchmark::State& benchState) { 126 NullClient client; 127 CanvasState state(client); 128 state.initializeSaveStack(100, 100, 0, 0, 100, 100, Vector3()); 129 130 while (benchState.KeepRunning()) { 131 state.save(SaveFlags::MatrixClip); 132 state.save(SaveFlags::MatrixClip); 133 benchmark::DoNotOptimize(&state); 134 state.restore(); 135 state.restore(); 136 } 137} 138BENCHMARK(BM_CanvasState_saverestore); 139 140void BM_CanvasState_init(benchmark::State& benchState) { 141 NullClient client; 142 CanvasState state(client); 143 state.initializeSaveStack(100, 100, 0, 0, 100, 100, Vector3()); 144 145 while (benchState.KeepRunning()) { 146 state.initializeSaveStack(100, 100, 0, 0, 100, 100, Vector3()); 147 benchmark::DoNotOptimize(&state); 148 } 149} 150BENCHMARK(BM_CanvasState_init); 151 152void BM_CanvasState_translate(benchmark::State& benchState) { 153 NullClient client; 154 CanvasState state(client); 155 state.initializeSaveStack(100, 100, 0, 0, 100, 100, Vector3()); 156 157 while (benchState.KeepRunning()) { 158 state.translate(5, 5, 0); 159 benchmark::DoNotOptimize(&state); 160 state.translate(-5, -5, 0); 161 } 162} 163BENCHMARK(BM_CanvasState_translate); 164 165void BM_DisplayListCanvas_basicViewGroupDraw(benchmark::State& benchState) { 166 sp<RenderNode> child = TestUtils::createNode(50, 50, 100, 100, 167 [](auto& props, auto& canvas) { 168 canvas.drawColor(0xFFFFFFFF, SkXfermode::kSrcOver_Mode); 169 }); 170 171 TestCanvas canvas(100, 100); 172 delete canvas.finishRecording(); 173 174 while (benchState.KeepRunning()) { 175 canvas.resetRecording(200, 200); 176 canvas.setHighContrastText(false); 177 canvas.translate(0, 0); // mScrollX, mScrollY 178 179 // Clip to padding 180 // Can expect ~25% of views to have clip to padding with a non-null padding 181 int clipRestoreCount = canvas.save(SaveFlags::MatrixClip); 182 canvas.clipRect(1, 1, 199, 199, SkRegion::kIntersect_Op); 183 184 canvas.insertReorderBarrier(true); 185 186 // Draw child loop 187 for (int i = 0; i < benchState.range_x(); i++) { 188 canvas.drawRenderNode(child.get()); 189 } 190 191 canvas.insertReorderBarrier(false); 192 canvas.restoreToCount(clipRestoreCount); 193 194 delete canvas.finishRecording(); 195 } 196} 197BENCHMARK(BM_DisplayListCanvas_basicViewGroupDraw)->Arg(1)->Arg(5)->Arg(10); 198