| 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 | 9 |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkPaint.h" | 11 #include "SkPaint.h" |
| 12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
| 13 #include "SkTextBlob.h" | 13 #include "SkTextBlob.h" |
| 14 #include "SkFontMgr.h" | 14 #include "SkFontMgr.h" |
| 15 #include "SkGraphics.h" | 15 #include "SkGraphics.h" |
| 16 #include "SkSurface.h" | 16 #include "SkSurface.h" |
| 17 #include "SkTypeface.h" | 17 #include "SkTypeface.h" |
| 18 #include "../src/fonts/SkRandomScalerContext.h" | 18 #include "../src/fonts/SkRandomScalerContext.h" |
| 19 | 19 |
| 20 #ifdef SK_BUILD_FOR_WIN | 20 #ifdef SK_BUILD_FOR_WIN |
| 21 #include "SkTypeface_win.h" | 21 #include "SkTypeface_win.h" |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 #include "Test.h" | 24 #include "Test.h" |
| 25 | 25 |
| 26 #if SK_SUPPORT_GPU | 26 #if SK_SUPPORT_GPU |
| 27 #include "GrContextFactory.h" | 27 #include "GrContext.h" |
| 28 #include "GrTest.h" | 28 #include "GrTest.h" |
| 29 | 29 |
| 30 struct TextBlobWrapper { | 30 struct TextBlobWrapper { |
| 31 // This class assumes it 'owns' the textblob it wraps, and thus does not nee
d to take a ref | 31 // This class assumes it 'owns' the textblob it wraps, and thus does not nee
d to take a ref |
| 32 explicit TextBlobWrapper(const SkTextBlob* blob) : fBlob(blob) {} | 32 explicit TextBlobWrapper(const SkTextBlob* blob) : fBlob(blob) {} |
| 33 TextBlobWrapper(const TextBlobWrapper& blob) : fBlob(SkRef(blob.fBlob.get())
) {} | 33 TextBlobWrapper(const TextBlobWrapper& blob) : fBlob(SkRef(blob.fBlob.get())
) {} |
| 34 | 34 |
| 35 SkAutoTUnref<const SkTextBlob> fBlob; | 35 SkAutoTUnref<const SkTextBlob> fBlob; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 static void draw(SkCanvas* canvas, int redraw, const SkTArray<TextBlobWrapper>&
blobs) { | 38 static void draw(SkCanvas* canvas, int redraw, const SkTArray<TextBlobWrapper>&
blobs) { |
| 39 int yOffset = 0; | 39 int yOffset = 0; |
| 40 for (int r = 0; r < redraw; r++) { | 40 for (int r = 0; r < redraw; r++) { |
| 41 for (int i = 0; i < blobs.count(); i++) { | 41 for (int i = 0; i < blobs.count(); i++) { |
| 42 const SkTextBlob* blob = blobs[i].fBlob.get(); | 42 const SkTextBlob* blob = blobs[i].fBlob.get(); |
| 43 const SkRect& bounds = blob->bounds(); | 43 const SkRect& bounds = blob->bounds(); |
| 44 yOffset += SkScalarCeilToInt(bounds.height()); | 44 yOffset += SkScalarCeilToInt(bounds.height()); |
| 45 SkPaint paint; | 45 SkPaint paint; |
| 46 canvas->drawTextBlob(blob, 0, SkIntToScalar(yOffset), paint); | 46 canvas->drawTextBlob(blob, 0, SkIntToScalar(yOffset), paint); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 static const int kWidth = 1024; | 51 static const int kWidth = 1024; |
| 52 static const int kHeight = 768; | 52 static const int kHeight = 768; |
| 53 | 53 |
| 54 // This test hammers the GPU textblobcache and font atlas | 54 // This test hammers the GPU textblobcache and font atlas |
| 55 static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContextFactory
* factory, | 55 static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContext* conte
xt, |
| 56 int maxTotalText, int maxGlyphID, int maxFamil
ies, bool normal, | 56 int maxTotalText, int maxGlyphID, int maxFamil
ies, bool normal, |
| 57 bool stressTest) { | 57 bool stressTest) { |
| 58 // setup surface | 58 // setup surface |
| 59 uint32_t flags = 0; | 59 uint32_t flags = 0; |
| 60 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); | 60 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 61 | 61 |
| 62 // We don't typically actually draw with this unittest | |
| 63 GrContext* ctx = factory->get(GrContextFactory::kNull_GLContextType); | |
| 64 | |
| 65 // configure our context for maximum stressing of cache and atlas | 62 // configure our context for maximum stressing of cache and atlas |
| 66 if (stressTest) { | 63 if (stressTest) { |
| 67 GrTest::SetupAlwaysEvictAtlas(ctx); | 64 GrTest::SetupAlwaysEvictAtlas(context); |
| 68 ctx->setTextBlobCacheLimit_ForTesting(0); | 65 context->setTextBlobCacheLimit_ForTesting(0); |
| 69 } | 66 } |
| 70 | 67 |
| 71 SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPre
mul_SkAlphaType); | 68 SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPre
mul_SkAlphaType); |
| 72 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::k
No_Budgeted, info, | 69 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, SkSurfac
e::kNo_Budgeted, info, |
| 73 0, &props)); | 70 0, &props)); |
| 74 REPORTER_ASSERT(reporter, surface); | 71 REPORTER_ASSERT(reporter, surface); |
| 75 if (!surface) { | 72 if (!surface) { |
| 76 return; | 73 return; |
| 77 } | 74 } |
| 78 | 75 |
| 79 SkCanvas* canvas = surface->getCanvas(); | 76 SkCanvas* canvas = surface->getCanvas(); |
| 80 | 77 |
| 81 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | 78 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| 82 | 79 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 return; | 139 return; |
| 143 } | 140 } |
| 144 | 141 |
| 145 SkCanvas* canvasNoLCD = surfaceNoLCD->getCanvas(); | 142 SkCanvas* canvasNoLCD = surfaceNoLCD->getCanvas(); |
| 146 | 143 |
| 147 // test redraw | 144 // test redraw |
| 148 draw(canvas, 2, blobs); | 145 draw(canvas, 2, blobs); |
| 149 draw(canvasNoLCD, 2, blobs); | 146 draw(canvasNoLCD, 2, blobs); |
| 150 | 147 |
| 151 // test draw after free | 148 // test draw after free |
| 152 ctx->freeGpuResources(); | 149 context->freeGpuResources(); |
| 153 draw(canvas, 1, blobs); | 150 draw(canvas, 1, blobs); |
| 154 | 151 |
| 155 ctx->freeGpuResources(); | 152 context->freeGpuResources(); |
| 156 draw(canvasNoLCD, 1, blobs); | 153 draw(canvasNoLCD, 1, blobs); |
| 157 | 154 |
| 158 // test draw after abandon | 155 // test draw after abandon |
| 159 ctx->abandonContext(); | 156 context->abandonContext(); |
| 160 draw(canvas, 1, blobs); | 157 draw(canvas, 1, blobs); |
| 161 } | 158 } |
| 162 | 159 |
| 163 DEF_GPUTEST(TextBlobCache, reporter, factory) { | 160 DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobCache, reporter, context) { |
| 164 text_blob_cache_inner(reporter, factory, 1024, 256, 30, true, false); | 161 text_blob_cache_inner(reporter, context, 1024, 256, 30, true, false); |
| 165 } | 162 } |
| 166 | 163 |
| 167 DEF_GPUTEST(TextBlobStressCache, reporter, factory) { | 164 DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobStressCache, reporter, context) { |
| 168 text_blob_cache_inner(reporter, factory, 256, 256, 10, true, true); | 165 text_blob_cache_inner(reporter, context, 256, 256, 10, true, true); |
| 169 } | 166 } |
| 170 | 167 |
| 171 DEF_GPUTEST(TextBlobAbnormal, reporter, factory) { | 168 DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobAbnormal, reporter, context) { |
| 172 text_blob_cache_inner(reporter, factory, 256, 256, 10, false, false); | 169 text_blob_cache_inner(reporter, context, 256, 256, 10, false, false); |
| 173 } | 170 } |
| 174 | 171 |
| 175 DEF_GPUTEST(TextBlobStressAbnormal, reporter, factory) { | 172 DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobStressAbnormal, reporter, context) { |
| 176 text_blob_cache_inner(reporter, factory, 256, 256, 10, false, true); | 173 text_blob_cache_inner(reporter, context, 256, 256, 10, false, true); |
| 177 } | 174 } |
| 178 #endif | 175 #endif |
| OLD | NEW |