| OLD | NEW |
| 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 "gm.h" | 8 #include "gm.h" |
| 9 | 9 |
| 10 #include "Resources.h" | 10 #include "Resources.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 setTypeface(&paint, "Times", SkTypeface::kItalic); | 131 setTypeface(&paint, "Times", SkTypeface::kItalic); |
| 132 canvas.drawText("Hamburgefons", 12, fTextSize/2, 3.6f*fTextSize, paint
); | 132 canvas.drawText("Hamburgefons", 12, fTextSize/2, 3.6f*fTextSize, paint
); |
| 133 setTypeface(&paint, "Times", SkTypeface::kBoldItalic); | 133 setTypeface(&paint, "Times", SkTypeface::kBoldItalic); |
| 134 canvas.drawText("Hamburgefons", 12, fTextSize/2, 4.8f*fTextSize, paint
); | 134 canvas.drawText("Hamburgefons", 12, fTextSize/2, 4.8f*fTextSize, paint
); |
| 135 } | 135 } |
| 136 private: | 136 private: |
| 137 typedef FilterBitmapGM INHERITED; | 137 typedef FilterBitmapGM INHERITED; |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 class FilterBitmapCheckerboardGM: public FilterBitmapGM { | 140 class FilterBitmapCheckerboardGM: public FilterBitmapGM { |
| 141 public: | 141 public: |
| 142 FilterBitmapCheckerboardGM(int size, int num_checks) | 142 FilterBitmapCheckerboardGM(int size, int num_checks, bool convertToG8 = fals
e) |
| 143 : fSize(size), fNumChecks(num_checks) | 143 : fSize(size), fNumChecks(num_checks), fConvertToG8(convertToG8) |
| 144 { | 144 { |
| 145 fName.printf("filterbitmap_checkerboard_%d_%d", fSize, fNumChecks); | 145 fName.printf("filterbitmap_checkerboard_%d_%d%s", |
| 146 } | 146 fSize, fNumChecks, convertToG8 ? "_g8" : ""); |
| 147 } |
| 147 | 148 |
| 148 protected: | 149 protected: |
| 149 int fSize; | 150 int fSize; |
| 150 int fNumChecks; | 151 int fNumChecks; |
| 151 | 152 |
| 152 SkScalar getScale() SK_OVERRIDE { | 153 SkScalar getScale() SK_OVERRIDE { |
| 153 return 192.f/fSize; | 154 return 192.f/fSize; |
| 154 } | 155 } |
| 155 | 156 |
| 156 void makeBitmap() SK_OVERRIDE { | 157 void makeBitmap() SK_OVERRIDE { |
| 157 fBM.allocN32Pixels(fSize, fSize); | 158 fBM.allocN32Pixels(fSize, fSize); |
| 158 for (int y = 0; y < fSize; y ++) { | 159 for (int y = 0; y < fSize; y ++) { |
| 159 for (int x = 0; x < fSize; x ++) { | 160 for (int x = 0; x < fSize; x ++) { |
| 160 SkPMColor* s = fBM.getAddr32(x, y); | 161 SkPMColor* s = fBM.getAddr32(x, y); |
| 161 int cx = (x * fNumChecks) / fSize; | 162 int cx = (x * fNumChecks) / fSize; |
| 162 int cy = (y * fNumChecks) / fSize; | 163 int cy = (y * fNumChecks) / fSize; |
| 163 if ((cx+cy)%2) { | 164 if ((cx+cy)%2) { |
| 164 *s = 0xFFFFFFFF; | 165 *s = 0xFFFFFFFF; |
| 165 } else { | 166 } else { |
| 166 *s = 0xFF000000; | 167 *s = 0xFF000000; |
| 167 } | 168 } |
| 168 } | 169 } |
| 169 } | 170 } |
| 171 if (fConvertToG8) { |
| 172 SkBitmap tmp; |
| 173 fBM.copyTo(&tmp, kGray_8_SkColorType); |
| 174 fBM = tmp; |
| 175 } |
| 170 } | 176 } |
| 171 private: | 177 private: |
| 172 typedef FilterBitmapGM INHERITED; | 178 const bool fConvertToG8; |
| 179 typedef FilterBitmapGM INHERITED; |
| 173 }; | 180 }; |
| 174 | 181 |
| 175 class FilterBitmapImageGM: public FilterBitmapGM { | 182 class FilterBitmapImageGM: public FilterBitmapGM { |
| 176 public: | 183 public: |
| 177 FilterBitmapImageGM(const char filename[]) | 184 FilterBitmapImageGM(const char filename[], bool convertToG8 = false) |
| 178 : fFilename(filename) | 185 : fFilename(filename), fConvertToG8(convertToG8) |
| 179 { | 186 { |
| 180 fName.printf("filterbitmap_image_%s", filename); | 187 fName.printf("filterbitmap_image_%s%s", filename, convertToG8 ? "_g8" :
""); |
| 181 } | 188 } |
| 182 | 189 |
| 183 protected: | 190 protected: |
| 184 SkString fFilename; | 191 SkString fFilename; |
| 185 int fSize; | 192 int fSize; |
| 186 | 193 |
| 187 SkScalar getScale() SK_OVERRIDE { | 194 SkScalar getScale() SK_OVERRIDE { |
| 188 return 192.f/fSize; | 195 return 192.f/fSize; |
| 189 } | 196 } |
| 190 | 197 |
| 191 void makeBitmap() SK_OVERRIDE { | 198 void makeBitmap() SK_OVERRIDE { |
| 192 SkImageDecoder* codec = NULL; | 199 SkImageDecoder* codec = NULL; |
| 193 SkString resourcePath = GetResourcePath(fFilename.c_str()); | 200 SkString resourcePath = GetResourcePath(fFilename.c_str()); |
| 194 SkFILEStream stream(resourcePath.c_str()); | 201 SkFILEStream stream(resourcePath.c_str()); |
| 195 if (stream.isValid()) { | 202 if (stream.isValid()) { |
| 196 codec = SkImageDecoder::Factory(&stream); | 203 codec = SkImageDecoder::Factory(&stream); |
| 197 } | 204 } |
| 198 if (codec) { | 205 if (codec) { |
| 199 stream.rewind(); | 206 stream.rewind(); |
| 200 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDe
codePixels_Mode); | 207 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDe
codePixels_Mode); |
| 201 SkDELETE(codec); | 208 SkDELETE(codec); |
| 202 } else { | 209 } else { |
| 203 fBM.allocN32Pixels(1, 1); | 210 fBM.allocN32Pixels(1, 1); |
| 204 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad | 211 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad |
| 205 } | 212 } |
| 206 fSize = fBM.height(); | 213 fSize = fBM.height(); |
| 214 if (fConvertToG8) { |
| 215 SkBitmap tmp; |
| 216 fBM.copyTo(&tmp, kGray_8_SkColorType); |
| 217 fBM = tmp; |
| 218 } |
| 207 } | 219 } |
| 208 private: | 220 private: |
| 209 typedef FilterBitmapGM INHERITED; | 221 const bool fConvertToG8; |
| 222 typedef FilterBitmapGM INHERITED; |
| 210 }; | 223 }; |
| 211 | 224 |
| 212 ////////////////////////////////////////////////////////////////////////////// | 225 ////////////////////////////////////////////////////////////////////////////// |
| 213 | 226 |
| 214 DEF_GM( return new FilterBitmapTextGM(3); ) | 227 DEF_GM( return new FilterBitmapTextGM(3); ) |
| 215 DEF_GM( return new FilterBitmapTextGM(7); ) | 228 DEF_GM( return new FilterBitmapTextGM(7); ) |
| 216 DEF_GM( return new FilterBitmapTextGM(10); ) | 229 DEF_GM( return new FilterBitmapTextGM(10); ) |
| 217 DEF_GM( return new FilterBitmapCheckerboardGM(4,4); ) | 230 DEF_GM( return new FilterBitmapCheckerboardGM(4,4); ) |
| 218 DEF_GM( return new FilterBitmapCheckerboardGM(32,32); ) | 231 DEF_GM( return new FilterBitmapCheckerboardGM(32,32); ) |
| 232 DEF_GM( return new FilterBitmapCheckerboardGM(32,32, true); ) |
| 219 DEF_GM( return new FilterBitmapCheckerboardGM(32,8); ) | 233 DEF_GM( return new FilterBitmapCheckerboardGM(32,8); ) |
| 220 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); ) | 234 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); ) |
| 221 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); ) | 235 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); ) |
| 222 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); ) | 236 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); ) |
| 223 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); ) | 237 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); ) |
| 224 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); ) | 238 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); ) |
| 239 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png", true); ) |
| 225 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); ) | 240 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); ) |
| 226 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); ) | 241 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); ) |
| 227 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); ) | 242 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); ) |
| 228 DEF_GM( return new FilterBitmapImageGM("color_wheel.png"); ) | 243 DEF_GM( return new FilterBitmapImageGM("color_wheel.png"); ) |
| OLD | NEW |