OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
11 #include "SkPoint.h" | 11 #include "SkPoint.h" |
12 #include "SkTextBlob.h" | 12 #include "SkTextBlob.h" |
13 #include "SkFontMgr.h" | 13 #include "SkFontMgr.h" |
14 #include "SkGraphics.h" | 14 #include "SkGraphics.h" |
15 #include "SkSurface.h" | 15 #include "SkSurface.h" |
16 #include "SkTypeface.h" | 16 #include "SkTypeface.h" |
| 17 #include "../src/fonts/SkRandomScalerContext.h" |
17 | 18 |
18 #ifdef SK_BUILD_FOR_WIN | 19 #ifdef SK_BUILD_FOR_WIN |
19 #include "SkTypeface_win.h" | 20 #include "SkTypeface_win.h" |
20 #endif | 21 #endif |
21 | 22 |
22 #include "Test.h" | 23 #include "Test.h" |
23 | 24 |
24 #if SK_SUPPORT_GPU | 25 #if SK_SUPPORT_GPU |
25 #include "GrContextFactory.h" | 26 #include "GrContextFactory.h" |
26 | 27 |
(...skipping 11 matching lines...) Expand all Loading... |
38 for (int i = 0; i < blobs.count(); i++) { | 39 for (int i = 0; i < blobs.count(); i++) { |
39 const SkTextBlob* blob = blobs[i].fBlob.get(); | 40 const SkTextBlob* blob = blobs[i].fBlob.get(); |
40 const SkRect& bounds = blob->bounds(); | 41 const SkRect& bounds = blob->bounds(); |
41 yOffset += SkScalarCeilToInt(bounds.height()); | 42 yOffset += SkScalarCeilToInt(bounds.height()); |
42 SkPaint paint; | 43 SkPaint paint; |
43 canvas->drawTextBlob(blob, 0, SkIntToScalar(yOffset), paint); | 44 canvas->drawTextBlob(blob, 0, SkIntToScalar(yOffset), paint); |
44 } | 45 } |
45 } | 46 } |
46 } | 47 } |
47 | 48 |
48 // limit this just so we don't take too long to draw | |
49 #define MAX_TOTAL_TEXT 4096 | |
50 #define MAX_CHAR 256 | |
51 #define MAX_FAMILIES 30 | |
52 | |
53 static const int kWidth = 1024; | 49 static const int kWidth = 1024; |
54 static const int kHeight = 768; | 50 static const int kHeight = 768; |
55 | 51 |
56 // This test hammers the GPU textblobcache and font atlas | 52 // This test hammers the GPU textblobcache and font atlas |
57 DEF_GPUTEST(TextBlobCache, reporter, factory) { | 53 static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContextFactory
* factory, |
| 54 int maxTotalText, int maxGlyphID, int maxFamil
ies, bool normal) { |
58 // setup surface | 55 // setup surface |
59 uint32_t flags = 0; | 56 uint32_t flags = 0; |
60 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); | 57 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
61 | 58 |
62 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType); | 59 // We don't typically actually draw with this unittest |
| 60 GrContext* ctx = factory->get(GrContextFactory::kNull_GLContextType); |
63 SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPre
mul_SkAlphaType); | 61 SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPre
mul_SkAlphaType); |
64 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::k
No_Budgeted, info, | 62 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::k
No_Budgeted, info, |
65 0, &props)); | 63 0, &props)); |
66 REPORTER_ASSERT(reporter, surface); | 64 REPORTER_ASSERT(reporter, surface); |
67 if (!surface) { | 65 if (!surface) { |
68 return; | 66 return; |
69 } | 67 } |
70 | 68 |
71 SkCanvas* canvas = surface->getCanvas(); | 69 SkCanvas* canvas = surface->getCanvas(); |
72 | 70 |
73 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | 71 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
74 | 72 |
75 int count = SkMin32(fm->countFamilies(), MAX_FAMILIES); | 73 int count = SkMin32(fm->countFamilies(), maxFamilies); |
76 | 74 |
77 // make a ton of text | 75 // make a ton of text |
78 uint16_t text[MAX_TOTAL_TEXT]; | 76 SkAutoTArray<uint16_t> text(maxTotalText); |
79 for (int i = 0; i < MAX_TOTAL_TEXT; i++) { | 77 for (int i = 0; i < maxTotalText; i++) { |
80 text[i] = i % MAX_CHAR; | 78 text[i] = i % maxGlyphID; |
81 } | 79 } |
82 | 80 |
83 // generate textblobs | 81 // generate textblobs |
84 SkTArray<TextBlobWrapper> blobs; | 82 SkTArray<TextBlobWrapper> blobs; |
85 for (int i = 0; i < count; i++) { | 83 for (int i = 0; i < count; i++) { |
86 SkPaint paint; | 84 SkPaint paint; |
87 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 85 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
88 paint.setTextSize(48); // draw big glyphs to really stress the atlas | 86 paint.setTextSize(48); // draw big glyphs to really stress the atlas |
89 | 87 |
90 SkString familyName; | 88 SkString familyName; |
91 fm->getFamilyName(i, &familyName); | 89 fm->getFamilyName(i, &familyName); |
92 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); | 90 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); |
93 for (int j = 0; j < set->count(); ++j) { | 91 for (int j = 0; j < set->count(); ++j) { |
94 SkFontStyle fs; | 92 SkFontStyle fs; |
95 set->getStyle(j, &fs, NULL); | 93 set->getStyle(j, &fs, NULL); |
96 | 94 |
97 SkSafeUnref(paint.setTypeface(set->createTypeface(j))); | 95 // We use a typeface which randomy returns unexpected mask formats t
o fuzz |
| 96 SkAutoTUnref<SkTypeface> orig(set->createTypeface(j)); |
| 97 if (normal) { |
| 98 paint.setTypeface(orig); |
| 99 } else { |
| 100 SkAutoTUnref<SkTypeface> typeface(SkNEW_ARGS(SkRandomTypeface, (
orig, paint, true))); |
| 101 paint.setTypeface(typeface); |
| 102 } |
98 | 103 |
99 SkTextBlobBuilder builder; | 104 SkTextBlobBuilder builder; |
100 for (int aa = 0; aa < 2; aa++) { | 105 for (int aa = 0; aa < 2; aa++) { |
101 for (int subpixel = 0; subpixel < 2; subpixel++) { | 106 for (int subpixel = 0; subpixel < 2; subpixel++) { |
102 for (int lcd = 0; lcd < 2; lcd++) { | 107 for (int lcd = 0; lcd < 2; lcd++) { |
103 paint.setAntiAlias(SkToBool(aa)); | 108 paint.setAntiAlias(SkToBool(aa)); |
104 paint.setSubpixelText(SkToBool(subpixel)); | 109 paint.setSubpixelText(SkToBool(subpixel)); |
105 paint.setLCDRenderText(SkToBool(lcd)); | 110 paint.setLCDRenderText(SkToBool(lcd)); |
| 111 if (!SkToBool(lcd)) { |
| 112 paint.setTextSize(160); |
| 113 } |
106 const SkTextBlobBuilder::RunBuffer& run = builder.allocR
un(paint, | 114 const SkTextBlobBuilder::RunBuffer& run = builder.allocR
un(paint, |
107
MAX_TOTAL_TEXT, | 115
maxTotalText, |
108
0, 0, | 116
0, 0, |
109
NULL); | 117
NULL); |
110 memcpy(run.glyphs, text, MAX_TOTAL_TEXT * sizeof(uint16_
t)); | 118 memcpy(run.glyphs, text.get(), maxTotalText * sizeof(uin
t16_t)); |
111 } | 119 } |
112 } | 120 } |
113 } | 121 } |
114 SkNEW_APPEND_TO_TARRAY(&blobs, TextBlobWrapper, (builder.build())); | 122 SkNEW_APPEND_TO_TARRAY(&blobs, TextBlobWrapper, (builder.build())); |
115 } | 123 } |
116 } | 124 } |
117 | 125 |
118 // create surface where LCD is impossible | 126 // create surface where LCD is impossible |
119 info = SkImageInfo::MakeN32Premul(kWidth, kHeight); | 127 info = SkImageInfo::MakeN32Premul(kWidth, kHeight); |
120 SkSurfaceProps propsNoLCD(0, kUnknown_SkPixelGeometry); | 128 SkSurfaceProps propsNoLCD(0, kUnknown_SkPixelGeometry); |
(...skipping 13 matching lines...) Expand all Loading... |
134 ctx->freeGpuResources(); | 142 ctx->freeGpuResources(); |
135 draw(canvas, 1, blobs); | 143 draw(canvas, 1, blobs); |
136 | 144 |
137 ctx->freeGpuResources(); | 145 ctx->freeGpuResources(); |
138 draw(canvasNoLCD, 1, blobs); | 146 draw(canvasNoLCD, 1, blobs); |
139 | 147 |
140 // test draw after abandon | 148 // test draw after abandon |
141 ctx->abandonContext(); | 149 ctx->abandonContext(); |
142 draw(canvas, 1, blobs); | 150 draw(canvas, 1, blobs); |
143 } | 151 } |
| 152 |
| 153 DEF_GPUTEST(TextBlobCache, reporter, factory) { |
| 154 text_blob_cache_inner(reporter, factory, 4096, 256, 30, true); |
| 155 } |
| 156 |
| 157 DEF_GPUTEST(TextBlobAbnormal, reporter, factory) { |
| 158 #ifdef SK_BUILD_FOR_ANDROID |
| 159 text_blob_cache_inner(reporter, factory, 32, 32, 1, false); |
| 160 #else |
| 161 text_blob_cache_inner(reporter, factory, 256, 256, 1, false); |
144 #endif | 162 #endif |
| 163 } |
| 164 #endif |
OLD | NEW |