blob: c78f131ce2cef0427ced2fb3069195b6caab009f [file] [log] [blame]
Chris Craikf3754a82016-04-19 18:13:21 -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 <gtest/gtest.h>
18
19#include "GammaFontRenderer.h"
20#include "tests/common/TestUtils.h"
21
22using namespace android::uirenderer;
23
24static 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 Reck915883b2017-05-03 10:27:20 -070031RENDERTHREAD_OPENGL_PIPELINE_TEST(FontRenderer, renderDropShadow) {
Chris Craikf3754a82016-04-19 18:13:21 -070032 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 Reck1bcacfd2017-11-03 10:12:19 -070043 TestUtils::layoutTextUnscaled(paint, "This is a test", &glyphs, &positions, &totalAdvance,
44 &bounds);
Chris Craikf3754a82016-04-19 18:13:21 -070045
46 for (int radius : {28, 20, 2}) {
John Reck1bcacfd2017-11-03 10:12:19 -070047 auto result = fontRenderer.renderDropShadow(&paint, glyphs.data(), glyphs.size(), radius,
48 positions.data());
Chris Craikf3754a82016-04-19 18:13:21 -070049 ASSERT_NE(nullptr, result.image);
50 EXPECT_FALSE(isZero(result.image, result.width * result.height));
John Reck1bcacfd2017-11-03 10:12:19 -070051 EXPECT_LE(bounds.getWidth() + radius * 2, (int)result.width);
52 EXPECT_LE(bounds.getHeight() + radius * 2, (int)result.height);
Chris Craikf3754a82016-04-19 18:13:21 -070053 delete result.image;
54 }
55}