1 /* 2 * Copyright (C) 2017 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 <SkBlendMode.h> 20 21 class ShadowShaderAnimation; 22 23 static TestScene::Registrar _ShadowShader(TestScene::Info{ 24 "shadowshader", 25 "A set of overlapping shadowed areas with simple tessellation useful for" 26 " benchmarking shadow shader performance.", 27 TestScene::simpleCreateScene<ShadowShaderAnimation>}); 28 29 class ShadowShaderAnimation : public TestScene { 30 public: 31 std::vector<sp<RenderNode> > cards; createContent(int width,int height,Canvas & canvas)32 void createContent(int width, int height, Canvas& canvas) override { 33 canvas.drawColor(0xFFFFFFFF, SkBlendMode::kSrcOver); 34 canvas.enableZ(true); 35 36 int outset = 50; 37 for (int i = 0; i < 10; i++) { 38 sp<RenderNode> card = 39 createCard(outset, outset, width - (outset * 2), height - (outset * 2)); 40 canvas.drawRenderNode(card.get()); 41 cards.push_back(card); 42 } 43 44 canvas.enableZ(false); 45 } doFrame(int frameNr)46 void doFrame(int frameNr) override { 47 int curFrame = frameNr % 10; 48 for (size_t ci = 0; ci < cards.size(); ci++) { 49 cards[ci]->mutateStagingProperties().setTranslationX(curFrame); 50 cards[ci]->mutateStagingProperties().setTranslationY(curFrame); 51 cards[ci]->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); 52 } 53 } 54 55 private: createCard(int x,int y,int width,int height)56 sp<RenderNode> createCard(int x, int y, int width, int height) { 57 return TestUtils::createNode(x, y, x + width, y + height, 58 [width, height](RenderProperties& props, Canvas& canvas) { 59 props.setElevation(1000); 60 61 // Set 0 radius, no clipping, so shadow is easy to compute. 62 // Slightly transparent outline 63 // to signal contents aren't opaque (not necessary though, 64 // as elevation is so high, no 65 // inner content to cut out) 66 props.mutableOutline().setRoundRect(0, 0, width, height, 0, 67 0.99f); 68 props.mutableOutline().setShouldClip(false); 69 70 // don't draw anything to card's canvas - we just want the 71 // shadow 72 }); 73 } 74 }; 75