Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: gm/textblobrandomfont.cpp

Issue 1264843003: Revert of Add BW masks to random scaler context (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/fonts/SkRandomScalerContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "gm.h" 8 #include "gm.h"
9 9
10 #include "Resources.h" 10 #include "Resources.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 SkAutoTUnref<SkTypeface> orig(sk_tool_utils::create_portable_typeface("s ans-serif", 42 SkAutoTUnref<SkTypeface> orig(sk_tool_utils::create_portable_typeface("s ans-serif",
43 Sk Typeface::kBold)); 43 Sk Typeface::kBold));
44 if (NULL == orig) { 44 if (NULL == orig) {
45 orig.reset(SkTypeface::RefDefault()); 45 orig.reset(SkTypeface::RefDefault());
46 } 46 }
47 SkAutoTUnref<SkTypeface> random(SkNEW_ARGS(SkRandomTypeface, (orig, pain t, false))); 47 SkAutoTUnref<SkTypeface> random(SkNEW_ARGS(SkRandomTypeface, (orig, pain t, false)));
48 paint.setTypeface(random); 48 paint.setTypeface(random);
49 49
50 SkRect bounds; 50 SkRect bounds;
51 paint.measureText(text, strlen(text), &bounds); 51 paint.measureText(text, strlen(text), &bounds);
52
53 SkScalar yOffset = bounds.height();
52 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0); 54 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);
53 55
54 // A8 56 // A8
55 const char* bigtext1 = "The quick brown fox";
56 const char* bigtext2 = "jumps over the lazy dog.";
57 paint.setTextSize(160);
58 paint.setSubpixelText(false); 57 paint.setSubpixelText(false);
59 paint.setLCDRenderText(false); 58 paint.setLCDRenderText(false);
60 paint.measureText(bigtext1, strlen(bigtext1), &bounds); 59 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, yOffset - 32);
61 SkScalar offset = bounds.height();
62 sk_tool_utils::add_to_text_blob(&builder, bigtext1, paint, 0, offset);
63
64 paint.measureText(bigtext2, strlen(bigtext2), &bounds);
65 offset += bounds.height();
66 sk_tool_utils::add_to_text_blob(&builder, bigtext2, paint, 0, offset);
67
68 // color emoji
69 SkAutoTUnref<SkTypeface> origEmoji;
70 sk_tool_utils::emoji_typeface(&origEmoji);
71 if (origEmoji) {
72 const char* emojiText = sk_tool_utils::emoji_sample_text();
73 paint.measureText(emojiText, strlen(emojiText), &bounds);
74 offset += bounds.height();
75 SkAutoTUnref<SkTypeface> randomEmoji(SkNEW_ARGS(SkRandomTypeface, (o rig, paint,
76 f alse)));
77 paint.setTypeface(randomEmoji);
78 sk_tool_utils::add_to_text_blob(&builder, emojiText, paint, 0, offse t);
79 }
80 60
81 // build 61 // build
82 fBlob.reset(builder.build()); 62 fBlob.reset(builder.build());
83 } 63 }
84 64
85 SkString onShortName() override { 65 SkString onShortName() override {
86 return SkString("textblobrandomfont"); 66 return SkString("textblobrandomfont");
87 } 67 }
88 68
89 SkISize onISize() override { 69 SkISize onISize() override {
(...skipping 11 matching lines...) Expand all
101 81
102 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); 82 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
103 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); 83 SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
104 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info, &props)); 84 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info, &props));
105 if (surface) { 85 if (surface) {
106 SkPaint paint; 86 SkPaint paint;
107 paint.setAntiAlias(true); 87 paint.setAntiAlias(true);
108 88
109 SkCanvas* c = surface->getCanvas(); 89 SkCanvas* c = surface->getCanvas();
110 90
111 int stride = SkScalarCeilToInt(fBlob->bounds().height()); 91 int stride = SkScalarCeilToInt(fBlob->bounds().height() / 2) + 10;
112 int yOffset = stride / 8; 92 int yOffset = stride;
113 for (int i = 0; i < 1; i++) { 93 for (int i = 0; i < 10; i++) {
114 // fiddle the canvas to force regen of textblobs 94 // fiddle the canvas to force regen of textblobs
115 canvas->rotate(i % 2 ? 0.0f : -0.05f); 95 canvas->rotate(i % 2 ? 0.0f : -0.05f);
116 canvas->drawTextBlob(fBlob, 10.0f, SkIntToScalar(yOffset), paint ); 96 canvas->drawTextBlob(fBlob, 10.0f, SkIntToScalar(yOffset), paint );
117 yOffset += stride; 97 yOffset += stride;
118 98
119 // This will draw as black boxes 99 // This will draw as black boxes
120 c->drawTextBlob(fBlob, 10, SkIntToScalar(yOffset), paint); 100 c->drawTextBlob(fBlob, 10, SkIntToScalar(yOffset), paint);
121 surface->draw(canvas, 0, 0, nullptr); 101 surface->draw(canvas, 0, 0, nullptr);
122 102
123 // free gpu resources and verify 103 // free gpu resources and verify
124 yOffset += stride; 104 yOffset += stride;
125 canvas->getGrContext()->freeGpuResources(); 105 canvas->getGrContext()->freeGpuResources();
126 canvas->drawTextBlob(fBlob, 10, SkIntToScalar(yOffset), paint); 106 canvas->drawTextBlob(fBlob, 10, SkIntToScalar(yOffset), paint);
127 107
128 yOffset += stride; 108 yOffset += stride;
129 } 109 }
130 110
131 } else { 111 } else {
132 const char* text = "This test requires a surface"; 112 const char* text = "This test requires a surface";
133 size_t len = strlen(text); 113 size_t len = strlen(text);
134 SkPaint paint; 114 SkPaint paint;
135 canvas->drawText(text, len, 10, 100, paint); 115 canvas->drawText(text, len, 10, 100, paint);
136 } 116 }
137 } 117 }
138 118
139 private: 119 private:
140 SkAutoTUnref<const SkTextBlob> fBlob; 120 SkAutoTUnref<const SkTextBlob> fBlob;
141 121
142 static const int kWidth = 2000; 122 static const int kWidth = 1000;
143 static const int kHeight = 1600; 123 static const int kHeight = 1000;
144 124
145 typedef GM INHERITED; 125 typedef GM INHERITED;
146 }; 126 };
147 127
148 ////////////////////////////////////////////////////////////////////////////// 128 //////////////////////////////////////////////////////////////////////////////
149 129
150 DEF_GM( return SkNEW(TextBlobRandomFont); ) 130 DEF_GM( return SkNEW(TextBlobRandomFont); )
151 } 131 }
152 #endif 132 #endif
OLDNEW
« no previous file with comments | « no previous file | src/fonts/SkRandomScalerContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698