blob: 9f599100200ea329438f10078693574e0aa52884 [file] [log] [blame]
Chris Craik00911812017-02-03 13:53:23 -08001/*
2 * Copyright (C) 2017 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 "TestSceneBase.h"
18
19class ShadowShaderAnimation;
20
21static TestScene::Registrar _ShadowShader(TestScene::Info{
John Reck1bcacfd2017-11-03 10:12:19 -070022 "shadowshader",
23 "A set of overlapping shadowed areas with simple tessellation useful for"
24 " benchmarking shadow shader performance.",
25 TestScene::simpleCreateScene<ShadowShaderAnimation>});
Chris Craik00911812017-02-03 13:53:23 -080026
27class ShadowShaderAnimation : public TestScene {
28public:
John Reck1bcacfd2017-11-03 10:12:19 -070029 std::vector<sp<RenderNode> > cards;
Chris Craik00911812017-02-03 13:53:23 -080030 void createContent(int width, int height, Canvas& canvas) override {
31 canvas.drawColor(0xFFFFFFFF, SkBlendMode::kSrcOver);
32 canvas.insertReorderBarrier(true);
33
34 int outset = 50;
35 for (int i = 0; i < 10; i++) {
John Reck1bcacfd2017-11-03 10:12:19 -070036 sp<RenderNode> card =
37 createCard(outset, outset, width - (outset * 2), height - (outset * 2));
Chris Craik00911812017-02-03 13:53:23 -080038 canvas.drawRenderNode(card.get());
39 cards.push_back(card);
40 }
41
42 canvas.insertReorderBarrier(false);
43 }
44 void doFrame(int frameNr) override {
45 int curFrame = frameNr % 10;
46 for (size_t ci = 0; ci < cards.size(); ci++) {
47 cards[ci]->mutateStagingProperties().setTranslationX(curFrame);
48 cards[ci]->mutateStagingProperties().setTranslationY(curFrame);
49 cards[ci]->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y);
50 }
51 }
John Reck1bcacfd2017-11-03 10:12:19 -070052
Chris Craik00911812017-02-03 13:53:23 -080053private:
54 sp<RenderNode> createCard(int x, int y, int width, int height) {
55 return TestUtils::createNode(x, y, x + width, y + height,
John Reck1bcacfd2017-11-03 10:12:19 -070056 [width, height](RenderProperties& props, Canvas& canvas) {
57 props.setElevation(1000);
Chris Craik00911812017-02-03 13:53:23 -080058
John Reck1bcacfd2017-11-03 10:12:19 -070059 // Set 0 radius, no clipping, so shadow is easy to compute.
60 // Slightly transparent outline
61 // to signal contents aren't opaque (not necessary though,
62 // as elevation is so high, no
63 // inner content to cut out)
64 props.mutableOutline().setRoundRect(0, 0, width, height, 0,
65 0.99f);
66 props.mutableOutline().setShouldClip(false);
Chris Craik00911812017-02-03 13:53:23 -080067
John Reck1bcacfd2017-11-03 10:12:19 -070068 // don't draw anything to card's canvas - we just want the
69 // shadow
70 });
Chris Craik00911812017-02-03 13:53:23 -080071 }
72};