aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/TextBlobCacheTest.cpp
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2015-07-31 11:45:22 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-31 11:45:22 -0700
commit65e96b4eb94c1b692f7decc18915cff77c5f1ab3 (patch)
tree71c1644d22637202b918c91f7d93af912ab2eeaa /tests/TextBlobCacheTest.cpp
parent88c7b988ba7792e51e741567426069cd9cc852dd (diff)
Modifying TextBlobCacheTest to use SkRandomScalerContext
Diffstat (limited to 'tests/TextBlobCacheTest.cpp')
-rw-r--r--tests/TextBlobCacheTest.cpp48
1 files changed, 34 insertions, 14 deletions
diff --git a/tests/TextBlobCacheTest.cpp b/tests/TextBlobCacheTest.cpp
index 3cbc8a35ad..60a6a8a24b 100644
--- a/tests/TextBlobCacheTest.cpp
+++ b/tests/TextBlobCacheTest.cpp
@@ -14,6 +14,7 @@
#include "SkGraphics.h"
#include "SkSurface.h"
#include "SkTypeface.h"
+#include "../src/fonts/SkRandomScalerContext.h"
#ifdef SK_BUILD_FOR_WIN
#include "SkTypeface_win.h"
@@ -45,21 +46,18 @@ static void draw(SkCanvas* canvas, int redraw, const SkTArray<TextBlobWrapper>&
}
}
-// limit this just so we don't take too long to draw
-#define MAX_TOTAL_TEXT 4096
-#define MAX_CHAR 256
-#define MAX_FAMILIES 30
-
static const int kWidth = 1024;
static const int kHeight = 768;
// This test hammers the GPU textblobcache and font atlas
-DEF_GPUTEST(TextBlobCache, reporter, factory) {
+static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContextFactory* factory,
+ int maxTotalText, int maxGlyphID, int maxFamilies, bool normal) {
// setup surface
uint32_t flags = 0;
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
- GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType);
+ // We don't typically actually draw with this unittest
+ GrContext* ctx = factory->get(GrContextFactory::kNull_GLContextType);
SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPremul_SkAlphaType);
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info,
0, &props));
@@ -72,12 +70,12 @@ DEF_GPUTEST(TextBlobCache, reporter, factory) {
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- int count = SkMin32(fm->countFamilies(), MAX_FAMILIES);
+ int count = SkMin32(fm->countFamilies(), maxFamilies);
// make a ton of text
- uint16_t text[MAX_TOTAL_TEXT];
- for (int i = 0; i < MAX_TOTAL_TEXT; i++) {
- text[i] = i % MAX_CHAR;
+ SkAutoTArray<uint16_t> text(maxTotalText);
+ for (int i = 0; i < maxTotalText; i++) {
+ text[i] = i % maxGlyphID;
}
// generate textblobs
@@ -94,7 +92,14 @@ DEF_GPUTEST(TextBlobCache, reporter, factory) {
SkFontStyle fs;
set->getStyle(j, &fs, NULL);
- SkSafeUnref(paint.setTypeface(set->createTypeface(j)));
+ // We use a typeface which randomy returns unexpected mask formats to fuzz
+ SkAutoTUnref<SkTypeface> orig(set->createTypeface(j));
+ if (normal) {
+ paint.setTypeface(orig);
+ } else {
+ SkAutoTUnref<SkTypeface> typeface(SkNEW_ARGS(SkRandomTypeface, (orig, paint, true)));
+ paint.setTypeface(typeface);
+ }
SkTextBlobBuilder builder;
for (int aa = 0; aa < 2; aa++) {
@@ -103,11 +108,14 @@ DEF_GPUTEST(TextBlobCache, reporter, factory) {
paint.setAntiAlias(SkToBool(aa));
paint.setSubpixelText(SkToBool(subpixel));
paint.setLCDRenderText(SkToBool(lcd));
+ if (!SkToBool(lcd)) {
+ paint.setTextSize(160);
+ }
const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(paint,
- MAX_TOTAL_TEXT,
+ maxTotalText,
0, 0,
NULL);
- memcpy(run.glyphs, text, MAX_TOTAL_TEXT * sizeof(uint16_t));
+ memcpy(run.glyphs, text.get(), maxTotalText * sizeof(uint16_t));
}
}
}
@@ -141,4 +149,16 @@ DEF_GPUTEST(TextBlobCache, reporter, factory) {
ctx->abandonContext();
draw(canvas, 1, blobs);
}
+
+DEF_GPUTEST(TextBlobCache, reporter, factory) {
+ text_blob_cache_inner(reporter, factory, 4096, 256, 30, true);
+}
+
+DEF_GPUTEST(TextBlobAbnormal, reporter, factory) {
+#ifdef SK_BUILD_FOR_ANDROID
+ text_blob_cache_inner(reporter, factory, 32, 32, 1, false);
+#else
+ text_blob_cache_inner(reporter, factory, 256, 256, 1, false);
+#endif
+}
#endif