Debian Codegraph @

libs/hwui/tests/common/scenes/SaveLayerAnimation.cpp

raw symbols SCIP
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 SaveLayerAnimation;
20
21 static TestScene::Registrar _SaveLayer(TestScene::Info{
22 "savelayer",
23 "A nested pair of clipped saveLayer operations. "
24 "Tests the clipped saveLayer codepath. Draws content into offscreen buffers and back "
25 "again.",
26 TestScene::simpleCreateScene<SaveLayerAnimation>});
27
28 class SaveLayerAnimation : public TestScene {
29 public:
30 sp<RenderNode> card;
31 void createContent(int width, int height, Canvas& canvas) override {
32 canvas.drawColor(Color::White, SkBlendMode::kSrcOver); // background
33
34 card = TestUtils::createNode(0, 0, 400, 800, [](RenderProperties& props, Canvas& canvas) {
35 // nested clipped saveLayers
36 canvas.saveLayerAlpha(0, 0, 400, 400, 200);
37 canvas.drawColor(Color::Green_700, SkBlendMode::kSrcOver);
38 canvas.clipRect(50, 50, 350, 350, SkClipOp::kIntersect);
39 canvas.saveLayerAlpha(100, 100, 300, 300, 128);
40 canvas.drawColor(Color::Blue_500, SkBlendMode::kSrcOver);
41 canvas.restore();
42 canvas.restore();
43
44 // single unclipped saveLayer
45 canvas.save(SaveFlags::MatrixClip);
46 canvas.translate(0, 400);
47 int unclippedSaveLayer = canvas.saveUnclippedLayer(100, 100, 300, 300);
48 Paint paint;
49 paint.setAntiAlias(true);
50 paint.setColor(Color::Green_700);
51 canvas.drawCircle(200, 200, 200, paint);
52 Paint alphaPaint;
53 alphaPaint.setAlpha(128);
54 canvas.restoreUnclippedLayer(unclippedSaveLayer, alphaPaint);
55 canvas.restore();
56 });
57
58 canvas.drawRenderNode(card.get());
59 }
60 void doFrame(int frameNr) override {
61 int curFrame = frameNr % 150;
62 card->mutateStagingProperties().setTranslationX(curFrame);
63 card->mutateStagingProperties().setTranslationY(curFrame);
64 card->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y);
65 }
66 };