Home | History | Annotate | Download | only in scenes
      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 #include "TestSceneBase.h"
     18 
     19 class ShadowGridAnimation;
     20 
     21 static TestScene::Registrar _ShadowGrid(TestScene::Info{
     22     "shadowgrid",
     23     "A grid of rounded rects that cast a shadow. Simplified scenario of an "
     24     "Android TV-style launcher interface. High CPU/GPU load.",
     25     TestScene::simpleCreateScene<ShadowGridAnimation>
     26 });
     27 
     28 class ShadowGridAnimation : public TestScene {
     29 public:
     30     std::vector< sp<RenderNode> > cards;
     31     void createContent(int width, int height, TestCanvas& canvas) override {
     32         canvas.drawColor(0xFFFFFFFF, SkXfermode::kSrcOver_Mode);
     33         canvas.insertReorderBarrier(true);
     34 
     35         for (int x = dp(16); x < (width - dp(116)); x += dp(116)) {
     36             for (int y = dp(16); y < (height - dp(116)); y += dp(116)) {
     37                 sp<RenderNode> card = createCard(x, y, dp(100), dp(100));
     38                 canvas.drawRenderNode(card.get());
     39                 cards.push_back(card);
     40             }
     41         }
     42 
     43         canvas.insertReorderBarrier(false);
     44     }
     45     void doFrame(int frameNr) override {
     46         int curFrame = frameNr % 150;
     47         for (size_t ci = 0; ci < cards.size(); ci++) {
     48             cards[ci]->mutateStagingProperties().setTranslationX(curFrame);
     49             cards[ci]->mutateStagingProperties().setTranslationY(curFrame);
     50             cards[ci]->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y);
     51         }
     52     }
     53 private:
     54     sp<RenderNode> createCard(int x, int y, int width, int height) {
     55         return TestUtils::createNode(x, y, x + width, y + height,
     56                 [width, height](RenderProperties& props, TestCanvas& canvas) {
     57             props.setElevation(dp(16));
     58             props.mutableOutline().setRoundRect(0, 0, width, height, dp(6), 1);
     59             props.mutableOutline().setShouldClip(true);
     60             canvas.drawColor(0xFFEEEEEE, SkXfermode::kSrcOver_Mode);
     61         });
     62     }
     63 };
     64