diff options
Diffstat (limited to 'libs/hwui/tests')
-rw-r--r-- | libs/hwui/tests/common/TestUtils.cpp | 38 | ||||
-rw-r--r-- | libs/hwui/tests/common/TestUtils.h | 4 | ||||
-rw-r--r-- | libs/hwui/tests/unit/TextDropShadowCacheTests.cpp | 28 |
3 files changed, 44 insertions, 26 deletions
diff --git a/libs/hwui/tests/common/TestUtils.cpp b/libs/hwui/tests/common/TestUtils.cpp index 5ed7aa464026..3440d03b4fc5 100644 --- a/libs/hwui/tests/common/TestUtils.cpp +++ b/libs/hwui/tests/common/TestUtils.cpp @@ -58,27 +58,22 @@ sp<DeferredLayerUpdater> TestUtils::createTextureLayerUpdater( return layerUpdater; } -void TestUtils::drawTextToCanvas(TestCanvas* canvas, const char* text, - const SkPaint& paint, float x, float y) { - // drawing text requires GlyphID TextEncoding (which JNI layer would have done) - LOG_ALWAYS_FATAL_IF(paint.getTextEncoding() != SkPaint::kGlyphID_TextEncoding, - "must use glyph encoding"); +void TestUtils::layoutTextUnscaled(const SkPaint& paint, const char* text, + std::vector<glyph_t>* outGlyphs, std::vector<float>* outPositions, + float* outTotalAdvance, Rect* outBounds) { + Rect bounds; + float totalAdvance = 0; SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); SkAutoGlyphCacheNoGamma autoCache(paint, &surfaceProps, &SkMatrix::I()); - - float totalAdvance = 0; - std::vector<glyph_t> glyphs; - std::vector<float> positions; - Rect bounds; while (*text != '\0') { SkUnichar unichar = SkUTF8_NextUnichar(&text); glyph_t glyph = autoCache.getCache()->unicharToGlyph(unichar); autoCache.getCache()->unicharToGlyph(unichar); // push glyph and its relative position - glyphs.push_back(glyph); - positions.push_back(totalAdvance); - positions.push_back(0); + outGlyphs->push_back(glyph); + outPositions->push_back(totalAdvance); + outPositions->push_back(0); // compute bounds SkGlyph skGlyph = autoCache.getCache()->getUnicharMetrics(unichar); @@ -91,6 +86,23 @@ void TestUtils::drawTextToCanvas(TestCanvas* canvas, const char* text, paint.getTextWidths(&glyph, sizeof(glyph), &skWidth, NULL); totalAdvance += skWidth; } + *outBounds = bounds; + *outTotalAdvance = totalAdvance; +} + +void TestUtils::drawTextToCanvas(TestCanvas* canvas, const char* text, + const SkPaint& paint, float x, float y) { + // drawing text requires GlyphID TextEncoding (which JNI layer would have done) + LOG_ALWAYS_FATAL_IF(paint.getTextEncoding() != SkPaint::kGlyphID_TextEncoding, + "must use glyph encoding"); + SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); + SkAutoGlyphCacheNoGamma autoCache(paint, &surfaceProps, &SkMatrix::I()); + + std::vector<glyph_t> glyphs; + std::vector<float> positions; + float totalAdvance; + Rect bounds; + layoutTextUnscaled(paint, text, &glyphs, &positions, &totalAdvance, &bounds); // apply alignment via x parameter (which JNI layer would have done) if (paint.getTextAlign() == SkPaint::kCenter_Align) { diff --git a/libs/hwui/tests/common/TestUtils.h b/libs/hwui/tests/common/TestUtils.h index ae0814241055..6f237059dd33 100644 --- a/libs/hwui/tests/common/TestUtils.h +++ b/libs/hwui/tests/common/TestUtils.h @@ -205,6 +205,10 @@ public: static SkColor interpolateColor(float fraction, SkColor start, SkColor end); + static void layoutTextUnscaled(const SkPaint& paint, const char* text, + std::vector<glyph_t>* outGlyphs, std::vector<float>* outPositions, + float* outTotalAdvance, Rect* outBounds); + static void drawTextToCanvas(TestCanvas* canvas, const char* text, const SkPaint& paint, float x, float y); diff --git a/libs/hwui/tests/unit/TextDropShadowCacheTests.cpp b/libs/hwui/tests/unit/TextDropShadowCacheTests.cpp index c54f2c365ee2..0d26df203f02 100644 --- a/libs/hwui/tests/unit/TextDropShadowCacheTests.cpp +++ b/libs/hwui/tests/unit/TextDropShadowCacheTests.cpp @@ -21,29 +21,31 @@ #include "utils/Blur.h" #include "tests/common/TestUtils.h" -#include <SkBlurDrawLooper.h> #include <SkPaint.h> using namespace android; using namespace android::uirenderer; RENDERTHREAD_TEST(TextDropShadowCache, addRemove) { + SkPaint paint; + paint.setTextSize(20); + GammaFontRenderer gammaFontRenderer; FontRenderer& fontRenderer = gammaFontRenderer.getFontRenderer(); - TextDropShadowCache cache(5000); + fontRenderer.setFont(&paint, SkMatrix::I()); + TextDropShadowCache cache(MB(5)); cache.setFontRenderer(fontRenderer); - SkPaint paint; - paint.setLooper(SkBlurDrawLooper::Create((SkColor)0xFFFFFFFF, - Blur::convertRadiusToSigma(10), 10, 10))->unref(); - std::string msg("This is a test"); - std::unique_ptr<float[]> positions(new float[msg.length()]); - for (size_t i = 0; i < msg.length(); i++) { - positions[i] = i * 10.0f; - } - fontRenderer.setFont(&paint, SkMatrix::I()); - ShadowTexture* texture = cache.get(&paint, msg.c_str(), msg.length(), - 10.0f, positions.get()); + std::vector<glyph_t> glyphs; + std::vector<float> positions; + float totalAdvance; + uirenderer::Rect bounds; + TestUtils::layoutTextUnscaled(paint, "This is a test", + &glyphs, &positions, &totalAdvance, &bounds); + EXPECT_TRUE(bounds.contains(5, -10, 100, 0)) << "Expect input to be nontrivially sized"; + + ShadowTexture* texture = cache.get(&paint, glyphs.data(), glyphs.size(), 10, positions.data()); + ASSERT_TRUE(texture); ASSERT_FALSE(texture->cleanup); ASSERT_EQ((uint32_t) texture->objectSize(), cache.getSize()); |