OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 | 10 |
11 #include "SkTypeface.h" | 11 #include "SkTypeface.h" |
12 #include "SkImageDecoder.h" | 12 #include "SkImageDecoder.h" |
13 #include "SkStream.h" | 13 #include "SkStream.h" |
14 #include "SkPaint.h" | |
14 | 15 |
15 static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style sty le) { | 16 static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style sty le) { |
16 SkSafeUnref(paint->setTypeface(SkTypeface::CreateFromName(name, style))); | 17 SkSafeUnref(paint->setTypeface(SkTypeface::CreateFromName(name, style))); |
17 } | 18 } |
18 | 19 |
19 class DownsampleBitmapGM : public skiagm::GM { | 20 class DownsampleBitmapGM : public skiagm::GM { |
20 | 21 |
21 public: | 22 public: |
22 SkBitmap fBM; | 23 SkBitmap fBM; |
23 SkString fName; | 24 SkString fName; |
24 bool fBitmapMade; | 25 bool fBitmapMade; |
26 SkPaint::FilterLevel fFilterLevel; | |
25 | 27 |
26 DownsampleBitmapGM() | 28 DownsampleBitmapGM(SkPaint::FilterLevel filterLevel) |
29 : fFilterLevel(filterLevel) | |
27 { | 30 { |
28 this->setBGColor(0xFFDDDDDD); | 31 this->setBGColor(0xFFDDDDDD); |
29 fBitmapMade = false; | 32 fBitmapMade = false; |
30 } | 33 } |
31 | 34 |
32 void setName(const char name[]) { | 35 void setName(const char name[]) { |
33 fName.set(name); | 36 fName.set(name); |
34 } | 37 } |
38 | |
39 const char *filterLevelToString() { | |
40 switch(fFilterLevel) { | |
reed1
2013/07/25 17:35:48
could use a table here. there is a common way skia
| |
41 case SkPaint::kNone_FilterLevel: | |
bsalomon
2013/07/25 14:31:11
nit indent within a case (the return statements)
| |
42 return "none"; | |
43 case SkPaint::kLow_FilterLevel: | |
44 return "low"; | |
45 case SkPaint::kMedium_FilterLevel: | |
46 return "medium"; | |
47 case SkPaint::kHigh_FilterLevel: | |
48 return "high"; | |
49 default: | |
50 return "unknown"; | |
51 } | |
52 } | |
35 | 53 |
36 protected: | 54 protected: |
37 virtual SkString onShortName() SK_OVERRIDE { | 55 virtual SkString onShortName() SK_OVERRIDE { |
38 return fName; | 56 return fName; |
39 } | 57 } |
40 | 58 |
41 virtual SkISize onISize() SK_OVERRIDE { | 59 virtual SkISize onISize() SK_OVERRIDE { |
42 make_bitmap_wrapper(); | 60 make_bitmap_wrapper(); |
43 return SkISize::Make(4 * fBM.width(), fBM.height()); | 61 return SkISize::Make(4 * fBM.width(), fBM.height()); |
44 } | 62 } |
(...skipping 12 matching lines...) Expand all Loading... | |
57 | 75 |
58 int curX = 0; | 76 int curX = 0; |
59 int curWidth; | 77 int curWidth; |
60 float curScale = 1; | 78 float curScale = 1; |
61 do { | 79 do { |
62 | 80 |
63 SkMatrix matrix; | 81 SkMatrix matrix; |
64 matrix.setScale( curScale, curScale ); | 82 matrix.setScale( curScale, curScale ); |
65 | 83 |
66 SkPaint paint; | 84 SkPaint paint; |
67 paint.setFilterLevel(SkPaint::kHigh_FilterLevel); | 85 paint.setFilterLevel(fFilterLevel); |
68 | 86 |
69 canvas->save(); | 87 canvas->save(); |
70 canvas->translate( (SkScalar) curX, 0.f ); | 88 canvas->translate( (SkScalar) curX, 0.f ); |
71 canvas->drawBitmapMatrix( fBM, matrix, &paint ); | 89 canvas->drawBitmapMatrix( fBM, matrix, &paint ); |
72 canvas->restore(); | 90 canvas->restore(); |
73 | 91 |
74 curWidth = (int) (fBM.width() * curScale + 2); | 92 curWidth = (int) (fBM.width() * curScale + 2); |
75 curX += curWidth; | 93 curX += curWidth; |
76 curScale *= 0.75f; | 94 curScale *= 0.75f; |
77 } while (curWidth >= 2 && curX < 4*fBM.width()); | 95 } while (curWidth >= 2 && curX < 4*fBM.width()); |
78 } | 96 } |
79 | 97 |
80 private: | 98 private: |
81 typedef skiagm::GM INHERITED; | 99 typedef skiagm::GM INHERITED; |
82 }; | 100 }; |
83 | 101 |
84 class DownsampleBitmapTextGM: public DownsampleBitmapGM { | 102 class DownsampleBitmapTextGM: public DownsampleBitmapGM { |
85 public: | 103 public: |
86 DownsampleBitmapTextGM(float textSize) | 104 DownsampleBitmapTextGM(float textSize, SkPaint::FilterLevel filterLevel) |
87 : fTextSize(textSize) | 105 : INHERITED(filterLevel), fTextSize(textSize) |
88 { | 106 { |
89 char name[1024]; | 107 char name[1024]; |
reed1
2013/07/25 17:35:48
SkString has printf, just for this sort of usage.
| |
90 sprintf(name, "downsamplebitmap_text_%.2fpt", fTextSize); | 108 sprintf(name, "downsamplebitmap_text_%s_%.2fpt", this->filterLevelTo String(), fTextSize); |
91 setName(name); | 109 setName(name); |
92 } | 110 } |
93 | 111 |
94 protected: | 112 protected: |
95 float fTextSize; | 113 float fTextSize; |
96 | 114 |
97 virtual void make_bitmap() SK_OVERRIDE { | 115 virtual void make_bitmap() SK_OVERRIDE { |
98 fBM.setConfig(SkBitmap::kARGB_8888_Config, int(fTextSize * 8), int(fTe xtSize * 6)); | 116 fBM.setConfig(SkBitmap::kARGB_8888_Config, int(fTextSize * 8), int(fTe xtSize * 6)); |
99 fBM.allocPixels(); | 117 fBM.allocPixels(); |
100 SkCanvas canvas(fBM); | 118 SkCanvas canvas(fBM); |
(...skipping 12 matching lines...) Expand all Loading... | |
113 canvas.drawText("Hamburgefons", 12, fTextSize/2, 3.6f*fTextSize, paint ); | 131 canvas.drawText("Hamburgefons", 12, fTextSize/2, 3.6f*fTextSize, paint ); |
114 setTypeface(&paint, "Times", SkTypeface::kBoldItalic); | 132 setTypeface(&paint, "Times", SkTypeface::kBoldItalic); |
115 canvas.drawText("Hamburgefons", 12, fTextSize/2, 4.8f*fTextSize, paint ); | 133 canvas.drawText("Hamburgefons", 12, fTextSize/2, 4.8f*fTextSize, paint ); |
116 } | 134 } |
117 private: | 135 private: |
118 typedef DownsampleBitmapGM INHERITED; | 136 typedef DownsampleBitmapGM INHERITED; |
119 }; | 137 }; |
120 | 138 |
121 class DownsampleBitmapCheckerboardGM: public DownsampleBitmapGM { | 139 class DownsampleBitmapCheckerboardGM: public DownsampleBitmapGM { |
122 public: | 140 public: |
123 DownsampleBitmapCheckerboardGM(int size, int numChecks) | 141 DownsampleBitmapCheckerboardGM(int size, int numChecks, SkPaint::FilterLev el filterLevel) |
124 : fSize(size), fNumChecks(numChecks) | 142 : INHERITED(filterLevel), fSize(size), fNumChecks(numChecks) |
125 { | 143 { |
126 char name[1024]; | 144 char name[1024]; |
127 sprintf(name, "downsamplebitmap_checkerboard_%d_%d", fSize, fNumChec ks); | 145 sprintf(name, "downsamplebitmap_checkerboard_%s_%d_%d", this->filter LevelToString(), fSize, fNumChecks); |
128 setName(name); | 146 setName(name); |
129 } | 147 } |
130 | 148 |
131 protected: | 149 protected: |
132 int fSize; | 150 int fSize; |
133 int fNumChecks; | 151 int fNumChecks; |
134 | 152 |
135 virtual void make_bitmap() SK_OVERRIDE { | 153 virtual void make_bitmap() SK_OVERRIDE { |
136 fBM.setConfig(SkBitmap::kARGB_8888_Config, fSize, fSize); | 154 fBM.setConfig(SkBitmap::kARGB_8888_Config, fSize, fSize); |
137 fBM.allocPixels(); | 155 fBM.allocPixels(); |
(...skipping 10 matching lines...) Expand all Loading... | |
148 } | 166 } |
149 } | 167 } |
150 } | 168 } |
151 } | 169 } |
152 private: | 170 private: |
153 typedef DownsampleBitmapGM INHERITED; | 171 typedef DownsampleBitmapGM INHERITED; |
154 }; | 172 }; |
155 | 173 |
156 class DownsampleBitmapImageGM: public DownsampleBitmapGM { | 174 class DownsampleBitmapImageGM: public DownsampleBitmapGM { |
157 public: | 175 public: |
158 DownsampleBitmapImageGM(const char filename[]) | 176 DownsampleBitmapImageGM(const char filename[], SkPaint::FilterLevel filter Level) |
159 : fFilename(filename) | 177 : INHERITED(filterLevel), fFilename(filename) |
160 { | 178 { |
161 char name[1024]; | 179 char name[1024]; |
162 sprintf(name, "downsamplebitmap_image_%s", filename); | 180 sprintf(name, "downsamplebitmap_image_%s_%s", this->filterLevelToStr ing(), filename); |
163 setName(name); | 181 setName(name); |
164 } | 182 } |
165 | 183 |
166 protected: | 184 protected: |
167 SkString fFilename; | 185 SkString fFilename; |
168 int fSize; | 186 int fSize; |
169 | 187 |
170 virtual void make_bitmap() SK_OVERRIDE { | 188 virtual void make_bitmap() SK_OVERRIDE { |
171 SkString path(skiagm::GM::gResourcePath); | 189 SkString path(skiagm::GM::gResourcePath); |
172 path.append("/"); | 190 path.append("/"); |
(...skipping 15 matching lines...) Expand all Loading... | |
188 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad | 206 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad |
189 } | 207 } |
190 fSize = fBM.height(); | 208 fSize = fBM.height(); |
191 } | 209 } |
192 private: | 210 private: |
193 typedef DownsampleBitmapGM INHERITED; | 211 typedef DownsampleBitmapGM INHERITED; |
194 }; | 212 }; |
195 | 213 |
196 ////////////////////////////////////////////////////////////////////////////// | 214 ////////////////////////////////////////////////////////////////////////////// |
197 | 215 |
198 DEF_GM( return new DownsampleBitmapTextGM(72); ) | 216 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kHigh_FilterLevel); ) |
199 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256); ) | 217 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kHigh_Filter Level); ) |
200 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png"); ) | 218 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kHigh_Fi lterLevel); ) |
219 | |
220 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kMedium_FilterLevel); ) | |
221 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kMedium_Filt erLevel); ) | |
222 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kMedium_ FilterLevel); ) | |
223 | |
224 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kLow_FilterLevel); ) | |
225 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kLow_FilterL evel); ) | |
226 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kLow_Fil terLevel); ) | |
227 | |
228 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kNone_FilterLevel); ) | |
229 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kNone_Filter Level); ) | |
230 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kNone_Fi lterLevel); ) | |
OLD | NEW |