1 /* 2 * Copyright (C) 2015 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 class RectGridAnimation; 21 22 static TestScene::Registrar _RectGrid(TestScene::Info{ 23 "rectgrid", 24 "A dense grid of 1x1 rects that should visually look like a single rect. " 25 "Low CPU/GPU load.", 26 TestScene::simpleCreateScene<RectGridAnimation> 27 }); 28 29 class RectGridAnimation : public TestScene { 30 public: 31 sp<RenderNode> card; createContent(int width,int height,TestCanvas & canvas)32 void createContent(int width, int height, TestCanvas& canvas) override { 33 canvas.drawColor(0xFFFFFFFF, SkXfermode::kSrcOver_Mode); 34 canvas.insertReorderBarrier(true); 35 36 card = TestUtils::createNode(50, 50, 250, 250, 37 [](RenderProperties& props, TestCanvas& canvas) { 38 canvas.drawColor(0xFFFF00FF, SkXfermode::kSrcOver_Mode); 39 40 SkRegion region; 41 for (int xOffset = 0; xOffset < 200; xOffset+=2) { 42 for (int yOffset = 0; yOffset < 200; yOffset+=2) { 43 region.op(xOffset, yOffset, xOffset + 1, yOffset + 1, SkRegion::kUnion_Op); 44 } 45 } 46 47 SkPaint paint; 48 paint.setColor(0xff00ffff); 49 canvas.drawRegion(region, paint); 50 }); 51 canvas.drawRenderNode(card.get()); 52 53 canvas.insertReorderBarrier(false); 54 } doFrame(int frameNr)55 void doFrame(int frameNr) override { 56 int curFrame = frameNr % 150; 57 card->mutateStagingProperties().setTranslationX(curFrame); 58 card->mutateStagingProperties().setTranslationY(curFrame); 59 card->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); 60 } 61 }; 62