Chris Craik | f3754a8 | 2016-04-19 18:13:21 -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 <gtest/gtest.h> |
| 18 | |
| 19 | #include "GammaFontRenderer.h" |
| 20 | #include "tests/common/TestUtils.h" |
| 21 | |
| 22 | using namespace android::uirenderer; |
| 23 | |
| 24 | static bool isZero(uint8_t* data, int size) { |
| 25 | for (int i = 0; i < size; i++) { |
| 26 | if (data[i]) return false; |
| 27 | } |
| 28 | return true; |
| 29 | } |
| 30 | |
John Reck | 915883b | 2017-05-03 10:27:20 -0700 | [diff] [blame] | 31 | RENDERTHREAD_OPENGL_PIPELINE_TEST(FontRenderer, renderDropShadow) { |
Chris Craik | f3754a8 | 2016-04-19 18:13:21 -0700 | [diff] [blame] | 32 | SkPaint paint; |
| 33 | paint.setTextSize(10); |
| 34 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 35 | GammaFontRenderer gammaFontRenderer; |
| 36 | FontRenderer& fontRenderer = gammaFontRenderer.getFontRenderer(); |
| 37 | fontRenderer.setFont(&paint, SkMatrix::I()); |
| 38 | |
| 39 | std::vector<glyph_t> glyphs; |
| 40 | std::vector<float> positions; |
| 41 | float totalAdvance; |
| 42 | Rect bounds; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 43 | TestUtils::layoutTextUnscaled(paint, "This is a test", &glyphs, &positions, &totalAdvance, |
| 44 | &bounds); |
Chris Craik | f3754a8 | 2016-04-19 18:13:21 -0700 | [diff] [blame] | 45 | |
| 46 | for (int radius : {28, 20, 2}) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 47 | auto result = fontRenderer.renderDropShadow(&paint, glyphs.data(), glyphs.size(), radius, |
| 48 | positions.data()); |
Chris Craik | f3754a8 | 2016-04-19 18:13:21 -0700 | [diff] [blame] | 49 | ASSERT_NE(nullptr, result.image); |
| 50 | EXPECT_FALSE(isZero(result.image, result.width * result.height)); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 51 | EXPECT_LE(bounds.getWidth() + radius * 2, (int)result.width); |
| 52 | EXPECT_LE(bounds.getHeight() + radius * 2, (int)result.height); |
Chris Craik | f3754a8 | 2016-04-19 18:13:21 -0700 | [diff] [blame] | 53 | delete result.image; |
| 54 | } |
| 55 | } |