1c3127a78b996a540cd002e5a87861e8a2adeb336John Reck/*
2c3127a78b996a540cd002e5a87861e8a2adeb336John Reck * Copyright (C) 2016 The Android Open Source Project
3c3127a78b996a540cd002e5a87861e8a2adeb336John Reck *
4c3127a78b996a540cd002e5a87861e8a2adeb336John Reck * Licensed under the Apache License, Version 2.0 (the "License");
5c3127a78b996a540cd002e5a87861e8a2adeb336John Reck * you may not use this file except in compliance with the License.
6c3127a78b996a540cd002e5a87861e8a2adeb336John Reck * You may obtain a copy of the License at
7c3127a78b996a540cd002e5a87861e8a2adeb336John Reck *
8c3127a78b996a540cd002e5a87861e8a2adeb336John Reck *      http://www.apache.org/licenses/LICENSE-2.0
9c3127a78b996a540cd002e5a87861e8a2adeb336John Reck *
10c3127a78b996a540cd002e5a87861e8a2adeb336John Reck * Unless required by applicable law or agreed to in writing, software
11c3127a78b996a540cd002e5a87861e8a2adeb336John Reck * distributed under the License is distributed on an "AS IS" BASIS,
12c3127a78b996a540cd002e5a87861e8a2adeb336John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c3127a78b996a540cd002e5a87861e8a2adeb336John Reck * See the License for the specific language governing permissions and
14c3127a78b996a540cd002e5a87861e8a2adeb336John Reck * limitations under the License.
15c3127a78b996a540cd002e5a87861e8a2adeb336John Reck */
16c3127a78b996a540cd002e5a87861e8a2adeb336John Reck
17c3127a78b996a540cd002e5a87861e8a2adeb336John Reck#include <gtest/gtest.h>
18c3127a78b996a540cd002e5a87861e8a2adeb336John Reck
19c3127a78b996a540cd002e5a87861e8a2adeb336John Reck#include "GammaFontRenderer.h"
20c3127a78b996a540cd002e5a87861e8a2adeb336John Reck#include "TextDropShadowCache.h"
21c3127a78b996a540cd002e5a87861e8a2adeb336John Reck#include "utils/Blur.h"
22c3127a78b996a540cd002e5a87861e8a2adeb336John Reck#include "tests/common/TestUtils.h"
23c3127a78b996a540cd002e5a87861e8a2adeb336John Reck
24c3127a78b996a540cd002e5a87861e8a2adeb336John Reck#include <SkPaint.h>
25c3127a78b996a540cd002e5a87861e8a2adeb336John Reck
26c3127a78b996a540cd002e5a87861e8a2adeb336John Reckusing namespace android;
27c3127a78b996a540cd002e5a87861e8a2adeb336John Reckusing namespace android::uirenderer;
28c3127a78b996a540cd002e5a87861e8a2adeb336John Reck
29c3127a78b996a540cd002e5a87861e8a2adeb336John ReckRENDERTHREAD_TEST(TextDropShadowCache, addRemove) {
30e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    SkPaint paint;
31e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    paint.setTextSize(20);
32e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik
33c3127a78b996a540cd002e5a87861e8a2adeb336John Reck    GammaFontRenderer gammaFontRenderer;
34c3127a78b996a540cd002e5a87861e8a2adeb336John Reck    FontRenderer& fontRenderer = gammaFontRenderer.getFontRenderer();
35e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    fontRenderer.setFont(&paint, SkMatrix::I());
36e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    TextDropShadowCache cache(MB(5));
37c3127a78b996a540cd002e5a87861e8a2adeb336John Reck    cache.setFontRenderer(fontRenderer);
38c3127a78b996a540cd002e5a87861e8a2adeb336John Reck
39e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    std::vector<glyph_t> glyphs;
40e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    std::vector<float> positions;
41e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    float totalAdvance;
42e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    uirenderer::Rect bounds;
43e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    TestUtils::layoutTextUnscaled(paint, "This is a test",
44e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik            &glyphs, &positions, &totalAdvance, &bounds);
45e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    EXPECT_TRUE(bounds.contains(5, -10, 100, 0)) << "Expect input to be nontrivially sized";
46e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik
47e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    ShadowTexture* texture = cache.get(&paint, glyphs.data(), glyphs.size(), 10, positions.data());
48e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik
49c3127a78b996a540cd002e5a87861e8a2adeb336John Reck    ASSERT_TRUE(texture);
50c3127a78b996a540cd002e5a87861e8a2adeb336John Reck    ASSERT_FALSE(texture->cleanup);
51c3127a78b996a540cd002e5a87861e8a2adeb336John Reck    ASSERT_EQ((uint32_t) texture->objectSize(), cache.getSize());
52c3127a78b996a540cd002e5a87861e8a2adeb336John Reck    ASSERT_TRUE(cache.getSize());
53c3127a78b996a540cd002e5a87861e8a2adeb336John Reck    cache.clear();
54c3127a78b996a540cd002e5a87861e8a2adeb336John Reck    ASSERT_EQ(cache.getSize(), 0u);
55c3127a78b996a540cd002e5a87861e8a2adeb336John Reck}
56