blob: bd5169391e3d38f49d2b278a3a71cd7420c0e7de [file] [log] [blame]
John Reck82f5e0c2015-10-22 17:07:45 -07001/*
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 "Matrix.h"
20#include "Rect.h"
21#include "Vector.h"
22#include "VertexBuffer.h"
23#include "TessellationCache.h"
24#include "microbench/MicroBench.h"
25
26#include <SkPath.h>
27
28#include <memory>
29
30using namespace android;
31using namespace android::uirenderer;
32
33struct ShadowTestData {
34 Matrix4 drawTransform;
35 Rect localClip;
36 Matrix4 casterTransformXY;
37 Matrix4 casterTransformZ;
38 Vector3 lightCenter;
39 float lightRadius;
40};
41
42void createShadowTestData(ShadowTestData* out) {
43 static float SAMPLE_DRAW_TRANSFORM[] = {
44 1, 0, 0, 0,
45 0, 1, 0, 0,
46 0, 0, 1, 0,
47 0, 0, 0, 1,
48 };
49 static float SAMPLE_CASTERXY[] = {
50 1, 0, 0, 0,
51 0, 1, 0, 0,
52 0, 0, 1, 0,
53 32, 32, 0, 1,
54 };
55 static float SAMPLE_CASTERZ[] = {
56 1, 0, 0, 0,
57 0, 1, 0, 0,
58 0, 0, 1, 0,
59 32, 32, 32, 1,
60 };
61 static Rect SAMPLE_CLIP(0, 0, 1536, 2048);
62 static Vector3 SAMPLE_LIGHT_CENTER{768, -400, 1600};
63 static float SAMPLE_LIGHT_RADIUS = 1600;
64
65 out->drawTransform.load(SAMPLE_DRAW_TRANSFORM);
66 out->localClip = SAMPLE_CLIP;
67 out->casterTransformXY.load(SAMPLE_CASTERXY);
68 out->casterTransformZ.load(SAMPLE_CASTERZ);
69 out->lightCenter = SAMPLE_LIGHT_CENTER;
70 out->lightRadius = SAMPLE_LIGHT_RADIUS;
71}
72
73static inline void tessellateShadows(ShadowTestData& testData, bool opaque,
74 const SkPath& shape, VertexBuffer* ambient, VertexBuffer* spot) {
75 tessellateShadows(&testData.drawTransform, &testData.localClip,
76 opaque, &shape, &testData.casterTransformXY,
77 &testData.casterTransformZ, testData.lightCenter,
78 testData.lightRadius, *ambient, *spot);
79}
80
81BENCHMARK_NO_ARG(BM_TessellateShadows_roundrect_opaque);
82void BM_TessellateShadows_roundrect_opaque::Run(int iters) {
83 ShadowTestData shadowData;
84 createShadowTestData(&shadowData);
85 SkPath path;
86 path.reset();
87 path.addRoundRect(SkRect::MakeLTRB(0, 0, 100, 100), 5, 5);
88
89 StartBenchmarkTiming();
90 for (int i = 0; i < iters; i++) {
91 std::unique_ptr<VertexBuffer> ambient(new VertexBuffer);
92 std::unique_ptr<VertexBuffer> spot(new VertexBuffer);
93 tessellateShadows(shadowData, true, path, ambient.get(), spot.get());
94 MicroBench::DoNotOptimize(ambient.get());
95 MicroBench::DoNotOptimize(spot.get());
96 }
97 StopBenchmarkTiming();
98}
99
100BENCHMARK_NO_ARG(BM_TessellateShadows_roundrect_translucent);
101void BM_TessellateShadows_roundrect_translucent::Run(int iters) {
102 ShadowTestData shadowData;
103 createShadowTestData(&shadowData);
104 SkPath path;
105 path.reset();
106 path.addRoundRect(SkRect::MakeLTRB(0, 0, 100, 100), 5, 5);
107
108 StartBenchmarkTiming();
109 for (int i = 0; i < iters; i++) {
110 std::unique_ptr<VertexBuffer> ambient(new VertexBuffer);
111 std::unique_ptr<VertexBuffer> spot(new VertexBuffer);
112 tessellateShadows(shadowData, false, path, ambient.get(), spot.get());
113 MicroBench::DoNotOptimize(ambient.get());
114 MicroBench::DoNotOptimize(spot.get());
115 }
116 StopBenchmarkTiming();
117}