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