Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Copyright (C) 2016 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 "tests/common/TestListViewSceneBase.h"
19 #include "hwui/Paint.h"
20 #include <SkGradientShader.h>
21
22 class ListOfFadedTextAnimation;
23
24 static TestScene::Registrar _ListOfFadedTextAnimation(TestScene::Info{
25 "fadingedges",
26 "A mock ListView of scrolling text with faded edge. Doesn't re-bind/re-record views"
27 "as they are recycled, so won't upload much content (either glyphs, or bitmaps).",
28 TestScene::simpleCreateScene<ListOfFadedTextAnimation>});
29
30 class ListOfFadedTextAnimation : public TestListViewSceneBase {
31 void createListItem(RenderProperties& props, Canvas& canvas, int id, int itemWidth,
32 int itemHeight) override {
33 canvas.drawColor(Color::White, SkBlendMode::kSrcOver);
34 int length = dp(100);
35 canvas.saveLayer(0, 0, length, itemHeight, nullptr);
36 Paint textPaint;
37 textPaint.getSkFont().setSize(dp(20));
38 textPaint.setAntiAlias(true);
39 TestUtils::drawUtf8ToCanvas(&canvas, "not that long long text", textPaint, dp(10), dp(30));
40
41 SkPoint pts[2];
42 pts[0].set(0, 0);
43 pts[1].set(0, 1);
44
45 SkColor colors[2] = {Color::Black, Color::Transparent};
46 sk_sp<SkShader> s(
47 SkGradientShader::MakeLinear(pts, colors, NULL, 2, SkTileMode::kClamp));
48
49 SkMatrix matrix;
50 matrix.setScale(1, length);
51 matrix.postRotate(-90);
52 Paint fadingPaint;
53 fadingPaint.setShader(s->makeWithLocalMatrix(matrix));
54 fadingPaint.setBlendMode(SkBlendMode::kDstOut);
55 canvas.drawRect(0, 0, length, itemHeight, fadingPaint);
56 canvas.restore();
57 }
58 };