ClippingAnimation.cpp revision e4db79de127cfe961195f52907af8451026eaa20
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, TestCanvas& canvas) override {
32        canvas.drawColor(Color::White, SkXfermode::kSrcOver_Mode);
33        canvas.insertReorderBarrier(true);
34
35        card = TestUtils::createNode(0, 0, 200, 400,
36                [](RenderProperties& props, TestCanvas& canvas) {
37            canvas.save(SkCanvas::kMatrixClip_SaveFlag);
38            {
39                canvas.clipRect(0, 0, 200, 200, SkRegion::kIntersect_Op);
40                canvas.translate(100, 100);
41                canvas.rotate(45);
42                canvas.translate(-100, -100);
43                canvas.clipRect(0, 0, 200, 200, SkRegion::kIntersect_Op);
44                canvas.drawColor(Color::Blue_500, SkXfermode::kSrcOver_Mode);
45            }
46            canvas.restore();
47
48            canvas.save(SkCanvas::kMatrixClip_SaveFlag);
49            {
50                SkPath clipCircle;
51                clipCircle.addCircle(100, 300, 100);
52                canvas.clipPath(&clipCircle, SkRegion::kIntersect_Op);
53                canvas.drawColor(Color::Red_500, SkXfermode::kSrcOver_Mode);
54            }
55            canvas.restore();
56        });
57        canvas.drawRenderNode(card.get());
58
59        canvas.insertReorderBarrier(false);
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