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