Debian Codegraph @

libs/hwui/tests/common/scenes/RoundRectClippingAnimation.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2016 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
19 #include <vector>
20
21 class RoundRectClippingAnimation : public TestScene {
22 public:
23 int mSpacing, mSize;
24 int mMaxCards;
25
26 RoundRectClippingAnimation(int spacing, int size, int maxCards = INT_MAX)
27 : mSpacing(spacing), mSize(size), mMaxCards(maxCards) {}
28
29 std::vector<sp<RenderNode> > cards;
30 void createContent(int width, int height, Canvas& canvas) override {
31 canvas.drawColor(0xFFFFFFFF, SkBlendMode::kSrcOver);
32 canvas.enableZ(true);
33 int ci = 0;
34 int numCards = 0;
35
36 for (int x = 0; x < width; x += mSpacing) {
37 for (int y = 0; y < height; y += mSpacing) {
38 auto color = BrightColors[ci++ % BrightColorsCount];
39 auto card = TestUtils::createNode(
40 x, y, x + mSize, y + mSize, [&](RenderProperties& props, Canvas& canvas) {
41 canvas.drawColor(color, SkBlendMode::kSrcOver);
42 props.mutableOutline().setRoundRect(0, 0, props.getWidth(),
43 props.getHeight(), mSize * .25, 1);
44 props.mutableOutline().setShouldClip(true);
45 });
46 canvas.drawRenderNode(card.get());
47 cards.push_back(card);
48 ++numCards;
49 if (numCards >= mMaxCards) {
50 break;
51 }
52 }
53 if (numCards >= mMaxCards) {
54 break;
55 }
56 }
57
58 canvas.enableZ(false);
59 }
60 void doFrame(int frameNr) override {
61 int curFrame = frameNr % 50;
62 if (curFrame > 25) curFrame = 50 - curFrame;
63 for (auto& card : cards) {
64 card->mutateStagingProperties().setTranslationX(curFrame);
65 card->mutateStagingProperties().setTranslationY(curFrame);
66 card->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y);
67 }
68 }
69 };
70
71 static TestScene::Registrar _RoundRectClippingGpu(TestScene::Info{
72 "roundRectClipping-gpu",
73 "A bunch of RenderNodes with round rect clipping outlines that's GPU limited.",
74 [](const TestScene::Options&) -> test::TestScene* {
75 return new RoundRectClippingAnimation(dp(40), dp(200));
76 }});
77
78 static TestScene::Registrar _RoundRectClippingCpu(TestScene::Info{
79 "roundRectClipping-cpu",
80 "A bunch of RenderNodes with round rect clipping outlines that's CPU limited.",
81 [](const TestScene::Options&) -> test::TestScene* {
82 return new RoundRectClippingAnimation(dp(20), dp(20));
83 }});
84
85 static TestScene::Registrar _RoundRectClippingGrid(TestScene::Info{
86 "roundRectClipping-grid", "A grid of RenderNodes with round rect clipping outlines.",
87 [](const TestScene::Options&) -> test::TestScene* {
88 return new RoundRectClippingAnimation(dp(100), dp(80));
89 }});
90
91 static TestScene::Registrar _RoundRectClippingSingle(TestScene::Info{
92 "roundRectClipping-single", "A single RenderNodes with round rect clipping outline.",
93 [](const TestScene::Options&) -> test::TestScene* {
94 return new RoundRectClippingAnimation(dp(100), dp(80), 1);
95 }});
96
97 static TestScene::Registrar _RoundRectClippingSingleLarge(TestScene::Info{
98 "roundRectClipping-singlelarge",
99 "A single large RenderNodes with round rect clipping outline.",
100 [](const TestScene::Options&) -> test::TestScene* {
101 return new RoundRectClippingAnimation(dp(100), dp(350), 1);
102 }});