TextDropShadowCacheTests.cpp revision c3127a78b996a540cd002e5a87861e8a2adeb336
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 <SkBlurDrawLooper.h> 25#include <SkPaint.h> 26 27using namespace android; 28using namespace android::uirenderer; 29 30RENDERTHREAD_TEST(TextDropShadowCache, addRemove) { 31 GammaFontRenderer gammaFontRenderer; 32 FontRenderer& fontRenderer = gammaFontRenderer.getFontRenderer(); 33 TextDropShadowCache cache(5000); 34 cache.setFontRenderer(fontRenderer); 35 36 SkPaint paint; 37 paint.setLooper(SkBlurDrawLooper::Create((SkColor)0xFFFFFFFF, 38 Blur::convertRadiusToSigma(10), 10, 10))->unref(); 39 std::string msg("This is a test"); 40 std::unique_ptr<float[]> positions(new float[msg.length()]); 41 for (size_t i = 0; i < msg.length(); i++) { 42 positions[i] = i * 10.0f; 43 } 44 fontRenderer.setFont(&paint, SkMatrix::I()); 45 ShadowTexture* texture = cache.get(&paint, msg.c_str(), msg.length(), 46 10.0f, positions.get()); 47 ASSERT_TRUE(texture); 48 ASSERT_FALSE(texture->cleanup); 49 ASSERT_EQ((uint32_t) texture->objectSize(), cache.getSize()); 50 ASSERT_TRUE(cache.getSize()); 51 cache.clear(); 52 ASSERT_EQ(cache.getSize(), 0u); 53} 54