sergeyv | 06a62f6 | 2016-06-16 14:52:20 -0700 | [diff] [blame] | 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" |
Mike Reed | f6d86ac | 2019-01-18 14:13:23 -0500 | [diff] [blame] | 19 | #include "hwui/Paint.h" |
sergeyv | 06a62f6 | 2016-06-16 14:52:20 -0700 | [diff] [blame] | 20 | #include <SkGradientShader.h> |
| 21 | |
| 22 | class ListOfFadedTextAnimation; |
| 23 | |
| 24 | static TestScene::Registrar _ListOfFadedTextAnimation(TestScene::Info{ |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 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>}); |
sergeyv | 06a62f6 | 2016-06-16 14:52:20 -0700 | [diff] [blame] | 29 | |
| 30 | class ListOfFadedTextAnimation : public TestListViewSceneBase { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 31 | void createListItem(RenderProperties& props, Canvas& canvas, int id, int itemWidth, |
| 32 | int itemHeight) override { |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 33 | canvas.drawColor(Color::White, SkBlendMode::kSrcOver); |
sergeyv | 06a62f6 | 2016-06-16 14:52:20 -0700 | [diff] [blame] | 34 | int length = dp(100); |
| 35 | canvas.saveLayer(0, 0, length, itemHeight, nullptr, SaveFlags::HasAlphaLayer); |
Mike Reed | f6d86ac | 2019-01-18 14:13:23 -0500 | [diff] [blame] | 36 | Paint textPaint; |
| 37 | textPaint.getSkFont().setSize(dp(20)); |
sergeyv | 06a62f6 | 2016-06-16 14:52:20 -0700 | [diff] [blame] | 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}; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 46 | sk_sp<SkShader> s( |
| 47 | SkGradientShader::MakeLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode)); |
sergeyv | 06a62f6 | 2016-06-16 14:52:20 -0700 | [diff] [blame] | 48 | |
| 49 | SkMatrix matrix; |
| 50 | matrix.setScale(1, length); |
| 51 | matrix.postRotate(-90); |
| 52 | SkPaint fadingPaint; |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 53 | fadingPaint.setShader(s->makeWithLocalMatrix(matrix)); |
| 54 | fadingPaint.setBlendMode(SkBlendMode::kDstOut); |
sergeyv | 06a62f6 | 2016-06-16 14:52:20 -0700 | [diff] [blame] | 55 | canvas.drawRect(0, 0, length, itemHeight, fadingPaint); |
| 56 | canvas.restore(); |
| 57 | } |
| 58 | }; |