| 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" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 yOffset += SkScalarCeilToInt(bounds.height()); | 41 yOffset += SkScalarCeilToInt(bounds.height()); |
| 42 SkPaint paint; | 42 SkPaint paint; |
| 43 canvas->drawTextBlob(blob, 0, SkIntToScalar(yOffset), paint); | 43 canvas->drawTextBlob(blob, 0, SkIntToScalar(yOffset), paint); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 // limit this just so we don't take too long to draw | 48 // limit this just so we don't take too long to draw |
| 49 #define MAX_TOTAL_TEXT 4096 | 49 #define MAX_TOTAL_TEXT 4096 |
| 50 #define MAX_CHAR 256 | 50 #define MAX_CHAR 256 |
| 51 #define MAX_FAMILIES 5 | 51 #define MAX_FAMILIES 30 |
| 52 |
| 53 static const int kWidth = 1024; |
| 54 static const int kHeight = 768; |
| 52 | 55 |
| 53 // This test hammers the GPU textblobcache and font atlas | 56 // This test hammers the GPU textblobcache and font atlas |
| 54 DEF_GPUTEST(TextBlobCache, reporter, factory) { | 57 DEF_GPUTEST(TextBlobCache, reporter, factory) { |
| 55 // setup surface | 58 // setup surface |
| 56 uint32_t flags = 0; | 59 uint32_t flags = 0; |
| 57 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); | 60 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 58 | 61 |
| 59 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType); | 62 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType); |
| 60 SkImageInfo info = SkImageInfo::Make(1024, 768, kN32_SkColorType, kPremul_Sk
AlphaType); | 63 SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPre
mul_SkAlphaType); |
| 61 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::k
No_Budgeted, info, | 64 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::k
No_Budgeted, info, |
| 62 0, &props)); | 65 0, &props)); |
| 63 REPORTER_ASSERT(reporter, surface); | 66 REPORTER_ASSERT(reporter, surface); |
| 64 if (!surface) { | 67 if (!surface) { |
| 65 return; | 68 return; |
| 66 } | 69 } |
| 67 | 70 |
| 68 SkCanvas* canvas = surface->getCanvas(); | 71 SkCanvas* canvas = surface->getCanvas(); |
| 69 | 72 |
| 70 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | 73 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| 71 | 74 |
| 72 int count = SkMin32(fm->countFamilies(), MAX_FAMILIES); | 75 int count = SkMin32(fm->countFamilies(), MAX_FAMILIES); |
| 73 | 76 |
| 74 // make a ton of text | 77 // make a ton of text |
| 75 uint16_t text[MAX_TOTAL_TEXT]; | 78 uint16_t text[MAX_TOTAL_TEXT]; |
| 76 for (int i = 0; i < MAX_TOTAL_TEXT; i++) { | 79 for (int i = 0; i < MAX_TOTAL_TEXT; i++) { |
| 77 text[i] = i % MAX_CHAR; | 80 text[i] = i % MAX_CHAR; |
| 78 } | 81 } |
| 79 | 82 |
| 80 // generate textblobs | 83 // generate textblobs |
| 81 SkTArray<TextBlobWrapper> blobs; | 84 SkTArray<TextBlobWrapper> blobs; |
| 82 for (int i = 0; i < count; i++) { | 85 for (int i = 0; i < count; i++) { |
| 83 SkPaint paint; | 86 SkPaint paint; |
| 84 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 87 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 85 paint.setTextSize(256); // draw big glyphs to really stress the atlas | 88 paint.setTextSize(48); // draw big glyphs to really stress the atlas |
| 86 | 89 |
| 87 SkString familyName; | 90 SkString familyName; |
| 88 fm->getFamilyName(i, &familyName); | 91 fm->getFamilyName(i, &familyName); |
| 89 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); | 92 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); |
| 90 for (int j = 0; j < set->count(); ++j) { | 93 for (int j = 0; j < set->count(); ++j) { |
| 91 SkFontStyle fs; | 94 SkFontStyle fs; |
| 92 set->getStyle(j, &fs, NULL); | 95 set->getStyle(j, &fs, NULL); |
| 93 | 96 |
| 94 SkSafeUnref(paint.setTypeface(set->createTypeface(j))); | 97 SkSafeUnref(paint.setTypeface(set->createTypeface(j))); |
| 95 | 98 |
| 96 SkTextBlobBuilder builder; | 99 SkTextBlobBuilder builder; |
| 97 for (int aa = 0; aa < 2; aa++) { | 100 for (int aa = 0; aa < 2; aa++) { |
| 98 for (int subpixel = 0; subpixel < 2; subpixel++) { | 101 for (int subpixel = 0; subpixel < 2; subpixel++) { |
| 99 for (int lcd = 0; lcd < 2; lcd++) { | 102 for (int lcd = 0; lcd < 2; lcd++) { |
| 100 paint.setAntiAlias(SkToBool(aa)); | 103 paint.setAntiAlias(SkToBool(aa)); |
| 101 paint.setSubpixelText(SkToBool(subpixel)); | 104 paint.setSubpixelText(SkToBool(subpixel)); |
| 102 paint.setLCDRenderText(SkToBool(lcd)); | 105 paint.setLCDRenderText(SkToBool(lcd)); |
| 103 const SkTextBlobBuilder::RunBuffer& run = builder.allocR
un(paint, | 106 const SkTextBlobBuilder::RunBuffer& run = builder.allocR
un(paint, |
| 104
MAX_TOTAL_TEXT, | 107
MAX_TOTAL_TEXT, |
| 105
0, 0, | 108
0, 0, |
| 106
NULL); | 109
NULL); |
| 107 memcpy(run.glyphs, text, MAX_TOTAL_TEXT * sizeof(uint16_
t)); | 110 memcpy(run.glyphs, text, MAX_TOTAL_TEXT * sizeof(uint16_
t)); |
| 108 } | 111 } |
| 109 } | 112 } |
| 110 } | 113 } |
| 111 SkNEW_APPEND_TO_TARRAY(&blobs, TextBlobWrapper, (builder.build())); | 114 SkNEW_APPEND_TO_TARRAY(&blobs, TextBlobWrapper, (builder.build())); |
| 112 } | 115 } |
| 113 } | 116 } |
| 114 | 117 |
| 118 // create surface where LCD is impossible |
| 119 info = SkImageInfo::MakeN32Premul(kWidth, kHeight); |
| 120 SkSurfaceProps propsNoLCD(0, kUnknown_SkPixelGeometry); |
| 121 SkAutoTUnref<SkSurface> surfaceNoLCD(canvas->newSurface(info, &propsNoLCD)); |
| 122 REPORTER_ASSERT(reporter, surface); |
| 123 if (!surface) { |
| 124 return; |
| 125 } |
| 126 |
| 127 SkCanvas* canvasNoLCD = surfaceNoLCD->getCanvas(); |
| 128 |
| 115 // test redraw | 129 // test redraw |
| 116 draw(canvas, 2, blobs); | 130 draw(canvas, 2, blobs); |
| 131 draw(canvasNoLCD, 2, blobs); |
| 117 | 132 |
| 118 // test draw after free | 133 // test draw after free |
| 119 ctx->freeGpuResources(); | 134 ctx->freeGpuResources(); |
| 120 draw(canvas, 1, blobs); | 135 draw(canvas, 1, blobs); |
| 121 | 136 |
| 137 ctx->freeGpuResources(); |
| 138 draw(canvasNoLCD, 1, blobs); |
| 139 |
| 122 // test draw after abandon | 140 // test draw after abandon |
| 123 ctx->abandonContext(); | 141 ctx->abandonContext(); |
| 124 draw(canvas, 1, blobs); | 142 draw(canvas, 1, blobs); |
| 125 } | 143 } |
| 126 #endif | 144 #endif |
| OLD | NEW |