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 "TextDropShadowCache.h"
     21 #include "tests/common/TestUtils.h"
     22 #include "utils/Blur.h"
     23 
     24 #include <SkPaint.h>
     25 
     26 using namespace android;
     27 using namespace android::uirenderer;
     28 
     29 RENDERTHREAD_OPENGL_PIPELINE_TEST(TextDropShadowCache, addRemove) {
     30     SkPaint paint;
     31     paint.setTextSize(20);
     32     paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
     33 
     34     GammaFontRenderer gammaFontRenderer;
     35     FontRenderer& fontRenderer = gammaFontRenderer.getFontRenderer();
     36     fontRenderer.setFont(&paint, SkMatrix::I());
     37     TextDropShadowCache cache(MB(5));
     38     cache.setFontRenderer(fontRenderer);
     39 
     40     std::vector<glyph_t> glyphs;
     41     std::vector<float> positions;
     42     float totalAdvance;
     43     uirenderer::Rect bounds;
     44     TestUtils::layoutTextUnscaled(paint, "This is a test", &glyphs, &positions, &totalAdvance,
     45                                   &bounds);
     46     EXPECT_TRUE(bounds.contains(5, -10, 100, 0)) << "Expect input to be nontrivially sized";
     47 
     48     ShadowTexture* texture = cache.get(&paint, glyphs.data(), glyphs.size(), 10, positions.data());
     49 
     50     ASSERT_TRUE(texture);
     51     ASSERT_FALSE(texture->cleanup);
     52     ASSERT_EQ((uint32_t)texture->objectSize(), cache.getSize());
     53     ASSERT_TRUE(cache.getSize());
     54     cache.clear();
     55     ASSERT_EQ(cache.getSize(), 0u);
     56 }
     57