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