blob: 0d87776e083ef375150b7c08190d4349d5c092d9 [file] [log] [blame]
Chris Craikc7fa8432015-12-09 11:17:28 -08001/*
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#include "utils/Color.h"
19
20#include <cstdio>
21
22class ShapeAnimation;
23
John Reck1bcacfd2017-11-03 10:12:19 -070024static TestScene::Registrar _Shapes(TestScene::Info{"shapes", "A grid of shape drawing test cases.",
25 TestScene::simpleCreateScene<ShapeAnimation>});
Chris Craikc7fa8432015-12-09 11:17:28 -080026
27class ShapeAnimation : public TestScene {
28public:
29 sp<RenderNode> card;
Stan Iliev06152cd2016-07-27 17:55:43 -040030 void createContent(int width, int height, Canvas& canvas) override {
John Reck1bcacfd2017-11-03 10:12:19 -070031 card = TestUtils::createNode(
32 0, 0, width, height, [width](RenderProperties& props, Canvas& canvas) {
33 std::function<void(Canvas&, float, const SkPaint&)> ops[] = {
34 [](Canvas& canvas, float size, const SkPaint& paint) {
35 canvas.drawArc(0, 0, size, size, 50, 189, true, paint);
36 },
37 [](Canvas& canvas, float size, const SkPaint& paint) {
38 canvas.drawOval(0, 0, size, size, paint);
39 },
40 [](Canvas& canvas, float size, const SkPaint& paint) {
41 SkPath diamondPath;
42 diamondPath.moveTo(size / 2, 0);
43 diamondPath.lineTo(size, size / 2);
44 diamondPath.lineTo(size / 2, size);
45 diamondPath.lineTo(0, size / 2);
46 diamondPath.close();
47 canvas.drawPath(diamondPath, paint);
48 },
49 [](Canvas& canvas, float size, const SkPaint& paint) {
50 float data[] = {0, 0, size, size, 0, size, size, 0};
51 canvas.drawLines(data, sizeof(data) / sizeof(float), paint);
52 },
53 [](Canvas& canvas, float size, const SkPaint& paint) {
54 float data[] = {0, 0, size, size, 0, size, size, 0};
55 canvas.drawPoints(data, sizeof(data) / sizeof(float), paint);
56 },
57 [](Canvas& canvas, float size, const SkPaint& paint) {
58 canvas.drawRect(0, 0, size, size, paint);
59 },
60 [](Canvas& canvas, float size, const SkPaint& paint) {
61 float rad = size / 4;
62 canvas.drawRoundRect(0, 0, size, size, rad, rad, paint);
63 }};
64 float cellSpace = dp(4);
65 float cellSize = floorf(width / 7 - cellSpace);
Chris Craikc7fa8432015-12-09 11:17:28 -080066
John Reck1bcacfd2017-11-03 10:12:19 -070067 // each combination of strokeWidth + style gets a column
68 int outerCount = canvas.save(SaveFlags::MatrixClip);
69 SkPaint paint;
70 paint.setAntiAlias(true);
71 SkPaint::Style styles[] = {SkPaint::kStroke_Style, SkPaint::kFill_Style,
72 SkPaint::kStrokeAndFill_Style};
73 for (auto style : styles) {
74 paint.setStyle(style);
75 for (auto strokeWidth : {0.0f, 0.5f, 8.0f}) {
76 paint.setStrokeWidth(strokeWidth);
77 // fill column with each op
78 int middleCount = canvas.save(SaveFlags::MatrixClip);
79 for (auto op : ops) {
80 int innerCount = canvas.save(SaveFlags::MatrixClip);
81 canvas.clipRect(0, 0, cellSize, cellSize, SkClipOp::kIntersect);
82 canvas.drawColor(Color::White, SkBlendMode::kSrcOver);
83 op(canvas, cellSize, paint);
84 canvas.restoreToCount(innerCount);
85 canvas.translate(cellSize + cellSpace, 0);
86 }
87 canvas.restoreToCount(middleCount);
88 canvas.translate(0, cellSize + cellSpace);
89 }
Chris Craikc7fa8432015-12-09 11:17:28 -080090 }
John Reck1bcacfd2017-11-03 10:12:19 -070091 canvas.restoreToCount(outerCount);
92 });
Mike Reed260ab722016-10-07 15:59:20 -040093 canvas.drawColor(Color::Grey_500, SkBlendMode::kSrcOver);
Chris Craikc7fa8432015-12-09 11:17:28 -080094 canvas.drawRenderNode(card.get());
95 }
96
97 void doFrame(int frameNr) override {
98 card->mutateStagingProperties().setTranslationY(frameNr % 150);
99 card->setPropertyFieldsDirty(RenderNode::Y);
100 }
101};