blob: e7ba471ee807195c25e5c6c2d5f8101a56de0756 [file] [log] [blame]
John Reckb5eeb182020-12-09 13:45:39 -05001/*
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
25using namespace android;
26using namespace android::uirenderer;
27
28void BM_CanvasOpBuffer_alloc(benchmark::State& benchState) {
29 while (benchState.KeepRunning()) {
30 auto displayList = new CanvasOpBuffer();
31 benchmark::DoNotOptimize(displayList);
32 delete displayList;
33 }
34}
35BENCHMARK(BM_CanvasOpBuffer_alloc);
36
37void 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}
49BENCHMARK(BM_CanvasOpBuffer_record_saverestore);
50
51void 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}
63BENCHMARK(BM_CanvasOpBuffer_record_saverestoreWithReuse);
64
65void 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,
Mike Reed7994a312021-01-28 18:06:26 -050088 SkFilterMode::kNearest,
John Reckb5eeb182020-12-09 13:45:39 -050089 SkPaint{}
90 });
91 canvas.restore();
92 }
93 benchmark::DoNotOptimize(&canvas);
94 canvas.finish();
95 }
96}
97BENCHMARK(BM_CanvasOpBuffer_record_simpleBitmapView);