Home | History | Annotate | Download | only in unit
      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 
     31 RENDERTHREAD_TEST(FontRenderer, renderDropShadow) {
     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;
     43     TestUtils::layoutTextUnscaled(paint, "This is a test",
     44             &glyphs, &positions, &totalAdvance, &bounds);
     45 
     46     for (int radius : {28, 20, 2}) {
     47         auto result = fontRenderer.renderDropShadow(&paint, glyphs.data(), glyphs.size(),
     48                 radius, positions.data());
     49         ASSERT_NE(nullptr, result.image);
     50         EXPECT_FALSE(isZero(result.image, result.width * result.height));
     51         EXPECT_LE(bounds.getWidth() + radius * 2, (int) result.width);
     52         EXPECT_LE(bounds.getHeight() + radius * 2, (int) result.height);
     53         delete result.image;
     54     }
     55 }
     56