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

Side by Side Diff: samplecode/SampleText.cpp

Issue 393063002: remove dead code from sample (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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 | no next file » | 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"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
57 nn = SkIntToScalar((unsigned int)n); 57 nn = SkIntToScalar((unsigned int)n);
58 mm = m; 58 mm = m;
59 } 59 }
60 60
61 SkDEBUGCODE(size_t length2 =) paint.breakText(text, length, width, &mm); 61 SkDEBUGCODE(size_t length2 =) paint.breakText(text, length, width, &mm);
62 SkASSERT(length2 == length); 62 SkASSERT(length2 == length);
63 SkASSERT(mm == width); 63 SkASSERT(mm == width);
64 } 64 }
65 65
66 static SkRandom gRand;
67
68 class SkPowerMode : public SkXfermode {
69 public:
70 SkPowerMode(SkScalar exponent) { this->init(exponent); }
71
72 virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
73 const SkAlpha aa[]) const SK_OVERRIDE;
74
75 typedef SkFlattenable* (*Factory)(SkReadBuffer&);
76
77 SK_TO_STRING_OVERRIDE()
78 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPowerMode)
79
80 private:
81 SkScalar fExp; // user's value
82 uint8_t fTable[256]; // cache
83
84 void init(SkScalar exponent);
85 SkPowerMode(SkReadBuffer& b) : INHERITED(b) {
86 // read the exponent
87 this->init(SkFixedToScalar(b.readFixed()));
88 }
89 virtual void flatten(SkWriteBuffer& b) const SK_OVERRIDE {
90 this->INHERITED::flatten(b);
91 b.writeFixed(SkScalarToFixed(fExp));
92 }
93
94 typedef SkXfermode INHERITED;
95 };
96
97 void SkPowerMode::init(SkScalar e) {
98 fExp = e;
99 float ee = SkScalarToFloat(e);
100
101 printf("------ %g\n", ee);
102 for (int i = 0; i < 256; i++) {
103 float x = i / 255.f;
104 // printf(" %d %g", i, x);
105 x = powf(x, ee);
106 // printf(" %g", x);
107 int xx = SkScalarRoundToInt(x * 255);
108 // printf(" %d\n", xx);
109 fTable[i] = SkToU8(xx);
110 }
111 }
112
113 void SkPowerMode::xfer16(uint16_t dst[], const SkPMColor src[], int count,
114 const SkAlpha aa[]) const {
115 for (int i = 0; i < count; i++) {
116 SkPMColor c = src[i];
117 int r = SkGetPackedR32(c);
118 int g = SkGetPackedG32(c);
119 int b = SkGetPackedB32(c);
120 r = fTable[r];
121 g = fTable[g];
122 b = fTable[b];
123 dst[i] = SkPack888ToRGB16(r, g, b);
124 }
125 }
126
127 #ifndef SK_IGNORE_TO_STRING
128 void SkPowerMode::toString(SkString* str) const {
129 str->append("SkPowerMode: exponent ");
130 str->appendScalar(fExp);
131 }
132 #endif
133
134 static const struct { 66 static const struct {
135 const char* fName; 67 const char* fName;
136 uint32_t fFlags; 68 uint32_t fFlags;
137 bool fFlushCache; 69 bool fFlushCache;
138 } gHints[] = { 70 } gHints[] = {
139 { "Linear", SkPaint::kLinearText_Flag, false }, 71 { "Linear", SkPaint::kLinearText_Flag, false },
140 { "Normal", 0, true }, 72 { "Normal", 0, true },
141 { "Subpixel", SkPaint::kSubpixelText_Flag, true } 73 { "Subpixel", SkPaint::kSubpixelText_Flag, true }
142 }; 74 };
143 75
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 int fHints; 201 int fHints;
270 SkScalar fClickX; 202 SkScalar fClickX;
271 203
272 typedef SampleView INHERITED; 204 typedef SampleView INHERITED;
273 }; 205 };
274 206
275 ////////////////////////////////////////////////////////////////////////////// 207 //////////////////////////////////////////////////////////////////////////////
276 208
277 static SkView* MyFactory() { return new TextSpeedView; } 209 static SkView* MyFactory() { return new TextSpeedView; }
278 static SkViewRegister reg(MyFactory); 210 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698