ClippingAnimation.cpp revision 6e49c9f007c879f05b035c40c0ba543c00f9d0d0
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
19class ClippingAnimation;
20
21static TestScene::Registrar _RectGrid(TestScene::Info{
22    "clip",
23    "Complex clip cases"
24    "Low CPU/GPU load.",
25    TestScene::simpleCreateScene<ClippingAnimation>
26});
27
28class ClippingAnimation : public TestScene {
29public:
30    sp<RenderNode> card;
31    void createContent(int width, int height, Canvas& canvas) override {
32        canvas.drawColor(Color::White, SkBlendMode::kSrcOver);
33        card = TestUtils::createNode(0, 0, 200, 400,
34                [](RenderProperties& props, Canvas& canvas) {
35            canvas.save(SaveFlags::MatrixClip);
36            {
37                canvas.clipRect(0, 0, 200, 200, kIntersect_SkClipOp);
38                canvas.translate(100, 100);
39                canvas.rotate(45);
40                canvas.translate(-100, -100);
41                canvas.clipRect(0, 0, 200, 200, kIntersect_SkClipOp);
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, kIntersect_SkClipOp);
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    }
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