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 
RoundRectClippingAnimation(int spacing,int size)25     RoundRectClippingAnimation(int spacing, int size) : mSpacing(spacing), mSize(size) {}
26 
27     std::vector<sp<RenderNode> > cards;
createContent(int width,int height,Canvas & canvas)28     void createContent(int width, int height, Canvas& canvas) override {
29         canvas.drawColor(0xFFFFFFFF, SkBlendMode::kSrcOver);
30         canvas.enableZ(true);
31         int ci = 0;
32 
33         for (int x = 0; x < width; x += mSpacing) {
34             for (int y = 0; y < height; y += mSpacing) {
35                 auto color = BrightColors[ci++ % BrightColorsCount];
36                 auto card = TestUtils::createNode(
37                         x, y, x + mSize, y + mSize, [&](RenderProperties& props, Canvas& canvas) {
38                             canvas.drawColor(color, SkBlendMode::kSrcOver);
39                             props.mutableOutline().setRoundRect(0, 0, props.getWidth(),
40                                                                 props.getHeight(), mSize * .25, 1);
41                             props.mutableOutline().setShouldClip(true);
42                         });
43                 canvas.drawRenderNode(card.get());
44                 cards.push_back(card);
45             }
46         }
47 
48         canvas.enableZ(false);
49     }
doFrame(int frameNr)50     void doFrame(int frameNr) override {
51         int curFrame = frameNr % 50;
52         if (curFrame > 25) curFrame = 50 - curFrame;
53         for (auto& card : cards) {
54             card->mutateStagingProperties().setTranslationX(curFrame);
55             card->mutateStagingProperties().setTranslationY(curFrame);
56             card->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y);
57         }
58     }
59 };
60 
61 static TestScene::Registrar _RoundRectClippingGpu(TestScene::Info{
62         "roundRectClipping-gpu",
63         "A bunch of RenderNodes with round rect clipping outlines that's GPU limited.",
__anon599878510202(const TestScene::Options&) 64         [](const TestScene::Options&) -> test::TestScene* {
65             return new RoundRectClippingAnimation(dp(40), dp(200));
66         }});
67 
68 static TestScene::Registrar _RoundRectClippingCpu(TestScene::Info{
69         "roundRectClipping-cpu",
70         "A bunch of RenderNodes with round rect clipping outlines that's CPU limited.",
__anon599878510302(const TestScene::Options&) 71         [](const TestScene::Options&) -> test::TestScene* {
72             return new RoundRectClippingAnimation(dp(20), dp(20));
73         }});
74