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

Side by Side Diff: samplecode/SampleText.cpp

Issue 280233002: remove unused Kernel33MaskFilter (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add fix in experimental Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « samplecode/SamplePoints.cpp ('k') | samplecode/SampleXfermodesBlur.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 2011 Google Inc. 2 * Copyright 2011 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 "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkWriteBuffer.h" 12 #include "SkWriteBuffer.h"
13 #include "SkGradientShader.h" 13 #include "SkGradientShader.h"
14 #include "SkGraphics.h" 14 #include "SkGraphics.h"
15 #include "SkImageDecoder.h" 15 #include "SkImageDecoder.h"
16 #include "SkKernel33MaskFilter.h"
17 #include "SkPath.h" 16 #include "SkPath.h"
18 #include "SkRandom.h" 17 #include "SkRandom.h"
19 #include "SkRegion.h" 18 #include "SkRegion.h"
20 #include "SkShader.h" 19 #include "SkShader.h"
21 #include "SkUtils.h" 20 #include "SkUtils.h"
22 #include "SkColorPriv.h" 21 #include "SkColorPriv.h"
23 #include "SkColorFilter.h" 22 #include "SkColorFilter.h"
24 #include "SkTime.h" 23 #include "SkTime.h"
25 #include "SkTypeface.h" 24 #include "SkTypeface.h"
26 #include "SkXfermode.h" 25 #include "SkXfermode.h"
27 26
28 #include "SkStream.h" 27 #include "SkStream.h"
29 #include "SkXMLParser.h" 28 #include "SkXMLParser.h"
30 29
31 class ReduceNoise : public SkKernel33ProcMaskFilter {
32 public:
33 ReduceNoise(int percent256) : SkKernel33ProcMaskFilter(percent256) {}
34 virtual uint8_t computeValue(uint8_t* const* srcRows) const {
35 int c = srcRows[1][1];
36 int min = 255, max = 0;
37 for (int i = 0; i < 3; i++)
38 for (int j = 0; j < 3; j++)
39 if (i != 1 || j != 1)
40 {
41 int v = srcRows[i][j];
42 if (max < v)
43 max = v;
44 if (min > v)
45 min = v;
46 }
47 if (c > max) c = max;
48 // if (c < min) c = min;
49 return c;
50 }
51
52 #ifndef SK_IGNORE_TO_STRING
53 virtual void toString(SkString* str) const SK_OVERRIDE {
54 str->append("ReduceNoise: (");
55 this->INHERITED::toString(str);
56 str->append(")");
57 }
58 #endif
59
60 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(ReduceNoise)
61
62 private:
63 ReduceNoise(SkReadBuffer& rb) : SkKernel33ProcMaskFilter(rb) {}
64
65 typedef SkKernel33ProcMaskFilter INHERITED;
66 };
67
68 class Darken : public SkKernel33ProcMaskFilter {
69 public:
70 Darken(int percent256) : SkKernel33ProcMaskFilter(percent256) {}
71 virtual uint8_t computeValue(uint8_t* const* srcRows) const {
72 int c = srcRows[1][1];
73 float f = c / 255.f;
74
75 if (c >= 0) {
76 f = sqrtf(f);
77 } else {
78 f *= f;
79 }
80 SkASSERT(f >= 0 && f <= 1);
81 return (int)(f * 255);
82 }
83
84 #ifndef SK_IGNORE_TO_STRING
85 virtual void toString(SkString* str) const SK_OVERRIDE {
86 str->append("Darken: (");
87 this->INHERITED::toString(str);
88 str->append(")");
89 }
90 #endif
91
92 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Darken)
93
94 private:
95 Darken(SkReadBuffer& rb) : SkKernel33ProcMaskFilter(rb) {}
96
97 typedef SkKernel33ProcMaskFilter INHERITED;
98 };
99
100 static SkMaskFilter* makemf() { return new Darken(0x30); }
101
102 static void test_breakText() { 30 static void test_breakText() {
103 SkPaint paint; 31 SkPaint paint;
104 const char* text = "sdfkljAKLDFJKEWkldfjlk#$%&sdfs.dsj"; 32 const char* text = "sdfkljAKLDFJKEWkldfjlk#$%&sdfs.dsj";
105 size_t length = strlen(text); 33 size_t length = strlen(text);
106 SkScalar width = paint.measureText(text, length); 34 SkScalar width = paint.measureText(text, length);
107 35
108 SkScalar mm = 0; 36 SkScalar mm = 0;
109 SkScalar nn = 0; 37 SkScalar nn = 0;
110 for (SkScalar w = 0; w <= width; w += SK_Scalar1) { 38 for (SkScalar w = 0; w <= width; w += SK_Scalar1) {
111 SkScalar m; 39 SkScalar m;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 static const struct { 134 static const struct {
207 const char* fName; 135 const char* fName;
208 uint32_t fFlags; 136 uint32_t fFlags;
209 bool fFlushCache; 137 bool fFlushCache;
210 } gHints[] = { 138 } gHints[] = {
211 { "Linear", SkPaint::kLinearText_Flag, false }, 139 { "Linear", SkPaint::kLinearText_Flag, false },
212 { "Normal", 0, true }, 140 { "Normal", 0, true },
213 { "Subpixel", SkPaint::kSubpixelText_Flag, true } 141 { "Subpixel", SkPaint::kSubpixelText_Flag, true }
214 }; 142 };
215 143
216 static void DrawTheText(SkCanvas* canvas, const char text[], size_t length, 144 static void DrawTheText(SkCanvas* canvas, const char text[], size_t length, SkSc alar x, SkScalar y,
217 SkScalar x, SkScalar y, const SkPaint& paint, 145 const SkPaint& paint, SkScalar clickX) {
218 SkScalar clickX, SkMaskFilter* mf) {
219 SkPaint p(paint); 146 SkPaint p(paint);
220 147
221 #if 0 148 #if 0
222 canvas->drawText(text, length, x, y, paint); 149 canvas->drawText(text, length, x, y, paint);
223 #else 150 #else
224 { 151 {
225 SkPoint pts[1000]; 152 SkPoint pts[1000];
226 SkScalar xpos = x; 153 SkScalar xpos = x;
227 SkASSERT(length <= SK_ARRAY_COUNT(pts)); 154 SkASSERT(length <= SK_ARRAY_COUNT(pts));
228 for (size_t i = 0; i < length; i++) { 155 for (size_t i = 0; i < length; i++) {
229 pts[i].set(xpos, y), xpos += paint.getTextSize(); 156 pts[i].set(xpos, y), xpos += paint.getTextSize();
230 } 157 }
231 canvas->drawPosText(text, length, pts, paint); 158 canvas->drawPosText(text, length, pts, paint);
232 } 159 }
233 #endif 160 #endif
234 161
235 p.setSubpixelText(true); 162 p.setSubpixelText(true);
236 x += SkIntToScalar(180); 163 x += SkIntToScalar(180);
237 canvas->drawText(text, length, x, y, p); 164 canvas->drawText(text, length, x, y, p);
238 165
239 #ifdef SK_DEBUG 166 #ifdef SK_DEBUG
240 if (true) { 167 if (true) {
241 // p.setMaskFilter(mf);
242 p.setSubpixelText(false); 168 p.setSubpixelText(false);
243 p.setLinearText(true); 169 p.setLinearText(true);
244 x += SkIntToScalar(180); 170 x += SkIntToScalar(180);
245 canvas->drawText(text, length, x, y, p); 171 canvas->drawText(text, length, x, y, p);
246 } 172 }
247 #endif 173 #endif
248 } 174 }
249 175
250 class TextSpeedView : public SampleView { 176 class TextSpeedView : public SampleView {
251 public: 177 public:
252 TextSpeedView() { 178 TextSpeedView() {
253 fMF = makemf();
254
255 fHints = 0; 179 fHints = 0;
256 fClickX = 0; 180 fClickX = 0;
257 181
258 test_breakText(); 182 test_breakText();
259 } 183 }
260 184
261 virtual ~TextSpeedView() {
262 SkSafeUnref(fMF);
263 }
264
265 protected: 185 protected:
266 // overrides from SkEventSink 186 // overrides from SkEventSink
267 virtual bool onQuery(SkEvent* evt) { 187 virtual bool onQuery(SkEvent* evt) {
268 if (SampleCode::TitleQ(*evt)) { 188 if (SampleCode::TitleQ(*evt)) {
269 SampleCode::TitleR(evt, "Text"); 189 SampleCode::TitleR(evt, "Text");
270 return true; 190 return true;
271 } 191 }
272 return this->INHERITED::onQuery(evt); 192 return this->INHERITED::onQuery(evt);
273 } 193 }
274 194
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 239
320 const char* text = "Hamburgefons"; 240 const char* text = "Hamburgefons";
321 size_t length = strlen(text); 241 size_t length = strlen(text);
322 242
323 SkScalar y = SkIntToScalar(0); 243 SkScalar y = SkIntToScalar(0);
324 for (int i = 9; i <= 24; i++) { 244 for (int i = 9; i <= 24; i++) {
325 paint.setTextSize(SkIntToScalar(i) /*+ (gRand.nextU() & 0xFFFF)*/); 245 paint.setTextSize(SkIntToScalar(i) /*+ (gRand.nextU() & 0xFFFF)*/);
326 for (SkScalar dx = 0; dx <= SkIntToScalar(3)/4; 246 for (SkScalar dx = 0; dx <= SkIntToScalar(3)/4;
327 dx += SkIntToScalar(1) /* /4 */) { 247 dx += SkIntToScalar(1) /* /4 */) {
328 y += paint.getFontSpacing(); 248 y += paint.getFontSpacing();
329 DrawTheText(canvas, text, length, SkIntToScalar(20) + dx, y, 249 DrawTheText(canvas, text, length, SkIntToScalar(20) + dx, y, pai nt, fClickX);
330 paint, fClickX, fMF);
331 } 250 }
332 } 251 }
333 if (gHints[index].fFlushCache) { 252 if (gHints[index].fFlushCache) {
334 // SkGraphics::SetFontCacheUsed(0); 253 // SkGraphics::SetFontCacheUsed(0);
335 } 254 }
336 } 255 }
337 256
338 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, 257 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
339 unsigned modi) SK_OVERRIDE { 258 unsigned modi) SK_OVERRIDE {
340 fClickX = x; 259 fClickX = x;
341 this->inval(NULL); 260 this->inval(NULL);
342 return this->INHERITED::onFindClickHandler(x, y, modi); 261 return this->INHERITED::onFindClickHandler(x, y, modi);
343 } 262 }
344 263
345 virtual bool onClick(Click* click) { 264 virtual bool onClick(Click* click) {
346 return this->INHERITED::onClick(click); 265 return this->INHERITED::onClick(click);
347 } 266 }
348 267
349 private: 268 private:
350 int fHints; 269 int fHints;
351 SkScalar fClickX; 270 SkScalar fClickX;
352 SkMaskFilter* fMF;
353 271
354 typedef SampleView INHERITED; 272 typedef SampleView INHERITED;
355 }; 273 };
356 274
357 ////////////////////////////////////////////////////////////////////////////// 275 //////////////////////////////////////////////////////////////////////////////
358 276
359 static SkView* MyFactory() { return new TextSpeedView; } 277 static SkView* MyFactory() { return new TextSpeedView; }
360 static SkViewRegister reg(MyFactory); 278 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SamplePoints.cpp ('k') | samplecode/SampleXfermodesBlur.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698