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 | 9 |
10 #include "Resources.h" | 10 #include "Resources.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 } | 33 } |
34 | 34 |
35 const char* filterLevelToString() { | 35 const char* filterLevelToString() { |
36 static const char *filterLevelNames[] = { | 36 static const char *filterLevelNames[] = { |
37 "none", "low", "medium", "high" | 37 "none", "low", "medium", "high" |
38 }; | 38 }; |
39 return filterLevelNames[fFilterLevel]; | 39 return filterLevelNames[fFilterLevel]; |
40 } | 40 } |
41 | 41 |
42 protected: | 42 protected: |
43 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 43 uint32_t onGetFlags() const SK_OVERRIDE { |
44 return kSkipTiled_Flag; | 44 return kSkipTiled_Flag; |
45 } | 45 } |
46 | 46 |
47 virtual SkString onShortName() SK_OVERRIDE { | 47 SkString onShortName() SK_OVERRIDE { |
48 return fName; | 48 return fName; |
49 } | 49 } |
50 | 50 |
51 virtual SkISize onISize() SK_OVERRIDE { | 51 SkISize onISize() SK_OVERRIDE { |
52 make_bitmap_wrapper(); | 52 make_bitmap_wrapper(); |
53 return SkISize::Make(fBM.width(), 4 * fBM.height()); | 53 return SkISize::Make(fBM.width(), 4 * fBM.height()); |
54 } | 54 } |
55 | 55 |
56 void make_bitmap_wrapper() { | 56 void make_bitmap_wrapper() { |
57 if (!fBitmapMade) { | 57 if (!fBitmapMade) { |
58 fBitmapMade = true; | 58 fBitmapMade = true; |
59 make_bitmap(); | 59 make_bitmap(); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 virtual void make_bitmap() = 0; | 63 virtual void make_bitmap() = 0; |
64 | 64 |
65 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 65 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
66 make_bitmap_wrapper(); | 66 make_bitmap_wrapper(); |
67 | 67 |
68 int curY = 0; | 68 int curY = 0; |
69 int curHeight; | 69 int curHeight; |
70 float curScale = 1; | 70 float curScale = 1; |
71 do { | 71 do { |
72 | 72 |
73 SkMatrix matrix; | 73 SkMatrix matrix; |
74 matrix.setScale( curScale, curScale ); | 74 matrix.setScale( curScale, curScale ); |
75 | 75 |
(...skipping 20 matching lines...) Expand all Loading... |
96 public: | 96 public: |
97 DownsampleBitmapTextGM(float textSize, SkPaint::FilterLevel filterLevel) | 97 DownsampleBitmapTextGM(float textSize, SkPaint::FilterLevel filterLevel) |
98 : INHERITED(filterLevel), fTextSize(textSize) | 98 : INHERITED(filterLevel), fTextSize(textSize) |
99 { | 99 { |
100 fName.printf("downsamplebitmap_text_%s_%.2fpt", this->filterLevelToS
tring(), fTextSize); | 100 fName.printf("downsamplebitmap_text_%s_%.2fpt", this->filterLevelToS
tring(), fTextSize); |
101 } | 101 } |
102 | 102 |
103 protected: | 103 protected: |
104 float fTextSize; | 104 float fTextSize; |
105 | 105 |
106 virtual void make_bitmap() SK_OVERRIDE { | 106 void make_bitmap() SK_OVERRIDE { |
107 fBM.allocN32Pixels(int(fTextSize * 8), int(fTextSize * 6)); | 107 fBM.allocN32Pixels(int(fTextSize * 8), int(fTextSize * 6)); |
108 SkCanvas canvas(fBM); | 108 SkCanvas canvas(fBM); |
109 canvas.drawColor(SK_ColorWHITE); | 109 canvas.drawColor(SK_ColorWHITE); |
110 | 110 |
111 SkPaint paint; | 111 SkPaint paint; |
112 paint.setAntiAlias(true); | 112 paint.setAntiAlias(true); |
113 paint.setSubpixelText(true); | 113 paint.setSubpixelText(true); |
114 paint.setTextSize(fTextSize); | 114 paint.setTextSize(fTextSize); |
115 | 115 |
116 setTypeface(&paint, "Times", SkTypeface::kNormal); | 116 setTypeface(&paint, "Times", SkTypeface::kNormal); |
(...skipping 14 matching lines...) Expand all Loading... |
131 DownsampleBitmapCheckerboardGM(int size, int numChecks, SkPaint::FilterLev
el filterLevel) | 131 DownsampleBitmapCheckerboardGM(int size, int numChecks, SkPaint::FilterLev
el filterLevel) |
132 : INHERITED(filterLevel), fSize(size), fNumChecks(numChecks) | 132 : INHERITED(filterLevel), fSize(size), fNumChecks(numChecks) |
133 { | 133 { |
134 fName.printf("downsamplebitmap_checkerboard_%s_%d_%d", this->filterL
evelToString(), fSize, fNumChecks); | 134 fName.printf("downsamplebitmap_checkerboard_%s_%d_%d", this->filterL
evelToString(), fSize, fNumChecks); |
135 } | 135 } |
136 | 136 |
137 protected: | 137 protected: |
138 int fSize; | 138 int fSize; |
139 int fNumChecks; | 139 int fNumChecks; |
140 | 140 |
141 virtual void make_bitmap() SK_OVERRIDE { | 141 void make_bitmap() SK_OVERRIDE { |
142 fBM.allocN32Pixels(fSize, fSize); | 142 fBM.allocN32Pixels(fSize, fSize); |
143 for (int y = 0; y < fSize; ++y) { | 143 for (int y = 0; y < fSize; ++y) { |
144 for (int x = 0; x < fSize; ++x) { | 144 for (int x = 0; x < fSize; ++x) { |
145 SkPMColor* s = fBM.getAddr32(x, y); | 145 SkPMColor* s = fBM.getAddr32(x, y); |
146 int cx = (x * fNumChecks) / fSize; | 146 int cx = (x * fNumChecks) / fSize; |
147 int cy = (y * fNumChecks) / fSize; | 147 int cy = (y * fNumChecks) / fSize; |
148 if ((cx+cy)%2) { | 148 if ((cx+cy)%2) { |
149 *s = 0xFFFFFFFF; | 149 *s = 0xFFFFFFFF; |
150 } else { | 150 } else { |
151 *s = 0xFF000000; | 151 *s = 0xFF000000; |
(...skipping 10 matching lines...) Expand all Loading... |
162 DownsampleBitmapImageGM(const char filename[], SkPaint::FilterLevel filter
Level) | 162 DownsampleBitmapImageGM(const char filename[], SkPaint::FilterLevel filter
Level) |
163 : INHERITED(filterLevel), fFilename(filename) | 163 : INHERITED(filterLevel), fFilename(filename) |
164 { | 164 { |
165 fName.printf("downsamplebitmap_image_%s_%s", this->filterLevelToStri
ng(), filename); | 165 fName.printf("downsamplebitmap_image_%s_%s", this->filterLevelToStri
ng(), filename); |
166 } | 166 } |
167 | 167 |
168 protected: | 168 protected: |
169 SkString fFilename; | 169 SkString fFilename; |
170 int fSize; | 170 int fSize; |
171 | 171 |
172 virtual void make_bitmap() SK_OVERRIDE { | 172 void make_bitmap() SK_OVERRIDE { |
173 SkImageDecoder* codec = NULL; | 173 SkImageDecoder* codec = NULL; |
174 SkString resourcePath = GetResourcePath(fFilename.c_str()); | 174 SkString resourcePath = GetResourcePath(fFilename.c_str()); |
175 SkFILEStream stream(resourcePath.c_str()); | 175 SkFILEStream stream(resourcePath.c_str()); |
176 if (stream.isValid()) { | 176 if (stream.isValid()) { |
177 codec = SkImageDecoder::Factory(&stream); | 177 codec = SkImageDecoder::Factory(&stream); |
178 } | 178 } |
179 if (codec) { | 179 if (codec) { |
180 stream.rewind(); | 180 stream.rewind(); |
181 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDe
codePixels_Mode); | 181 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDe
codePixels_Mode); |
182 SkDELETE(codec); | 182 SkDELETE(codec); |
(...skipping 25 matching lines...) Expand all Loading... |
208 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kLow_FilterL
evel); ) | 208 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kLow_FilterL
evel); ) |
209 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kLow_Fil
terLevel); ) | 209 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kLow_Fil
terLevel); ) |
210 DEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", | 210 DEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", |
211 SkPaint::kLow_FilterLevel); ) | 211 SkPaint::kLow_FilterLevel); ) |
212 | 212 |
213 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kNone_FilterLevel); ) | 213 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kNone_FilterLevel); ) |
214 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kNone_Filter
Level); ) | 214 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kNone_Filter
Level); ) |
215 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kNone_Fi
lterLevel); ) | 215 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kNone_Fi
lterLevel); ) |
216 DEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", | 216 DEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", |
217 SkPaint::kNone_FilterLevel); ) | 217 SkPaint::kNone_FilterLevel); ) |
OLD | NEW |