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