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 #include <SkBlendMode.h> 20 21 class ClippingAnimation; 22 23 static TestScene::Registrar _RectGrid(TestScene::Info{ 24 "clip", 25 "Complex clip cases" 26 "Low CPU/GPU load.", 27 TestScene::simpleCreateScene<ClippingAnimation>}); 28 29 class ClippingAnimation : public TestScene { 30 public: 31 sp<RenderNode> card; createContent(int width,int height,Canvas & canvas)32 void createContent(int width, int height, Canvas& canvas) override { 33 canvas.drawColor(Color::White, SkBlendMode::kSrcOver); 34 card = TestUtils::createNode(0, 0, 200, 400, [](RenderProperties& props, Canvas& canvas) { 35 canvas.save(SaveFlags::MatrixClip); 36 { 37 canvas.clipRect(0, 0, 200, 200, SkClipOp::kIntersect); 38 canvas.translate(100, 100); 39 canvas.rotate(45); 40 canvas.translate(-100, -100); 41 canvas.clipRect(0, 0, 200, 200, SkClipOp::kIntersect); 42 canvas.drawColor(Color::Blue_500, SkBlendMode::kSrcOver); 43 } 44 canvas.restore(); 45 46 canvas.save(SaveFlags::MatrixClip); 47 { 48 SkPath clipCircle; 49 clipCircle.addCircle(100, 300, 100); 50 canvas.clipPath(&clipCircle, SkClipOp::kIntersect); 51 canvas.drawColor(Color::Red_500, SkBlendMode::kSrcOver); 52 } 53 canvas.restore(); 54 55 // put on a layer, to test stencil attachment 56 props.mutateLayerProperties().setType(LayerType::RenderLayer); 57 props.setAlpha(0.9f); 58 }); 59 canvas.drawRenderNode(card.get()); 60 } doFrame(int frameNr)61 void doFrame(int frameNr) override { 62 int curFrame = frameNr % 150; 63 card->mutateStagingProperties().setTranslationX(curFrame); 64 card->mutateStagingProperties().setTranslationY(curFrame); 65 card->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); 66 } 67 }; 68