blob: ecaaf487e4f830ad03a5f99814f5fba2885a2cbf [file] [log] [blame]
sergeyv06a62f62016-06-16 14:52:20 -07001/*
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"
Mike Reedf6d86ac2019-01-18 14:13:23 -050019#include "hwui/Paint.h"
sergeyv06a62f62016-06-16 14:52:20 -070020#include <SkGradientShader.h>
21
22class ListOfFadedTextAnimation;
23
24static TestScene::Registrar _ListOfFadedTextAnimation(TestScene::Info{
John Reck1bcacfd2017-11-03 10:12:19 -070025 "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>});
sergeyv06a62f62016-06-16 14:52:20 -070029
30class ListOfFadedTextAnimation : public TestListViewSceneBase {
John Reck1bcacfd2017-11-03 10:12:19 -070031 void createListItem(RenderProperties& props, Canvas& canvas, int id, int itemWidth,
32 int itemHeight) override {
Mike Reed260ab722016-10-07 15:59:20 -040033 canvas.drawColor(Color::White, SkBlendMode::kSrcOver);
sergeyv06a62f62016-06-16 14:52:20 -070034 int length = dp(100);
35 canvas.saveLayer(0, 0, length, itemHeight, nullptr, SaveFlags::HasAlphaLayer);
Mike Reedf6d86ac2019-01-18 14:13:23 -050036 Paint textPaint;
37 textPaint.getSkFont().setSize(dp(20));
sergeyv06a62f62016-06-16 14:52:20 -070038 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};
John Reck1bcacfd2017-11-03 10:12:19 -070046 sk_sp<SkShader> s(
47 SkGradientShader::MakeLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode));
sergeyv06a62f62016-06-16 14:52:20 -070048
49 SkMatrix matrix;
50 matrix.setScale(1, length);
51 matrix.postRotate(-90);
52 SkPaint fadingPaint;
Mike Reed260ab722016-10-07 15:59:20 -040053 fadingPaint.setShader(s->makeWithLocalMatrix(matrix));
54 fadingPaint.setBlendMode(SkBlendMode::kDstOut);
sergeyv06a62f62016-06-16 14:52:20 -070055 canvas.drawRect(0, 0, length, itemHeight, fadingPaint);
56 canvas.restore();
57 }
58};