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 "hwui/Paint.h"
21 #include "canvas/CanvasOpBuffer.h"
22 #include "canvas/CanvasFrontend.h"
23 #include "tests/common/TestUtils.h"
24
25 using namespace android;
26 using namespace android::uirenderer;
27
BM_CanvasOpBuffer_alloc(benchmark::State & benchState)28 void BM_CanvasOpBuffer_alloc(benchmark::State& benchState) {
29 while (benchState.KeepRunning()) {
30 auto displayList = new CanvasOpBuffer();
31 benchmark::DoNotOptimize(displayList);
32 delete displayList;
33 }
34 }
35 BENCHMARK(BM_CanvasOpBuffer_alloc);
36
BM_CanvasOpBuffer_record_saverestore(benchmark::State & benchState)37 void BM_CanvasOpBuffer_record_saverestore(benchmark::State& benchState) {
38 CanvasFrontend<CanvasOpBuffer> canvas(100, 100);
39 while (benchState.KeepRunning()) {
40 canvas.reset(100, 100);
41 canvas.save(SaveFlags::MatrixClip);
42 canvas.save(SaveFlags::MatrixClip);
43 benchmark::DoNotOptimize(&canvas);
44 canvas.restore();
45 canvas.restore();
46 canvas.finish();
47 }
48 }
49 BENCHMARK(BM_CanvasOpBuffer_record_saverestore);
50
BM_CanvasOpBuffer_record_saverestoreWithReuse(benchmark::State & benchState)51 void BM_CanvasOpBuffer_record_saverestoreWithReuse(benchmark::State& benchState) {
52 CanvasFrontend<CanvasOpBuffer> canvas(100, 100);
53
54 while (benchState.KeepRunning()) {
55 canvas.reset(100, 100);
56 canvas.save(SaveFlags::MatrixClip);
57 canvas.save(SaveFlags::MatrixClip);
58 benchmark::DoNotOptimize(&canvas);
59 canvas.restore();
60 canvas.restore();
61 }
62 }
63 BENCHMARK(BM_CanvasOpBuffer_record_saverestoreWithReuse);
64
BM_CanvasOpBuffer_record_simpleBitmapView(benchmark::State & benchState)65 void BM_CanvasOpBuffer_record_simpleBitmapView(benchmark::State& benchState) {
66 CanvasFrontend<CanvasOpBuffer> canvas(100, 100);
67
68 Paint rectPaint;
69 sk_sp<Bitmap> iconBitmap(TestUtils::createBitmap(80, 80));
70
71 while (benchState.KeepRunning()) {
72 canvas.reset(100, 100);
73 {
74 canvas.save(SaveFlags::MatrixClip);
75 canvas.draw(CanvasOp<CanvasOpType::DrawRect> {
76 .rect = SkRect::MakeWH(100, 100),
77 .paint = rectPaint,
78 });
79 canvas.restore();
80 }
81 {
82 canvas.save(SaveFlags::MatrixClip);
83 canvas.translate(10, 10);
84 canvas.draw(CanvasOp<CanvasOpType::DrawImage> {
85 iconBitmap,
86 0,
87 0,
88 SkFilterMode::kNearest,
89 SkPaint{}
90 });
91 canvas.restore();
92 }
93 benchmark::DoNotOptimize(&canvas);
94 canvas.finish();
95 }
96 }
97 BENCHMARK(BM_CanvasOpBuffer_record_simpleBitmapView);
98