RoundRectClippingAnimation.cpp revision 5abc1fb1d4c3956f27948cb68e601675c8fea85c
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 22class RoundRectClippingAnimation : public TestScene { 23public: 24 int mSpacing, mSize; 25 26 RoundRectClippingAnimation(int spacing, int size) 27 : mSpacing(spacing), mSize(size) {} 28 29 std::vector< sp<RenderNode> > cards; 30 void createContent(int width, int height, Canvas& canvas) override { 31 canvas.drawColor(0xFFFFFFFF, SkXfermode::kSrcOver_Mode); 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, SkXfermode::kSrcOver_Mode); 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 } 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 63static TestScene::Registrar _RoundRectClippingGpu(TestScene::Info{ 64 "roundRectClipping-gpu", 65 "A bunch of RenderNodes with round rect clipping outlines that's GPU limited.", 66 [](const TestScene::Options&) -> test::TestScene* { 67 return new RoundRectClippingAnimation(dp(40), dp(200)); 68 } 69}); 70 71static TestScene::Registrar _RoundRectClippingCpu(TestScene::Info{ 72 "roundRectClipping-cpu", 73 "A bunch of RenderNodes with round rect clipping outlines that's CPU limited.", 74 [](const TestScene::Options&) -> test::TestScene* { 75 return new RoundRectClippingAnimation(dp(20), dp(20)); 76 } 77}); 78