| 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 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
| 10 | 10 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 108 } |
| 109 | 109 |
| 110 protected: | 110 protected: |
| 111 float fTextSize; | 111 float fTextSize; |
| 112 | 112 |
| 113 SkScalar getScale() SK_OVERRIDE { | 113 SkScalar getScale() SK_OVERRIDE { |
| 114 return 32.f/fTextSize; | 114 return 32.f/fTextSize; |
| 115 } | 115 } |
| 116 | 116 |
| 117 void makeBitmap() SK_OVERRIDE { | 117 void makeBitmap() SK_OVERRIDE { |
| 118 fBM.setConfig(SkBitmap::kARGB_8888_Config, int(fTextSize * 8), int(fTe
xtSize * 6)); | 118 fBM.allocN32Pixels(int(fTextSize * 8), int(fTextSize * 6)); |
| 119 fBM.allocPixels(); | |
| 120 SkCanvas canvas(fBM); | 119 SkCanvas canvas(fBM); |
| 121 canvas.drawColor(SK_ColorWHITE); | 120 canvas.drawColor(SK_ColorWHITE); |
| 122 | 121 |
| 123 SkPaint paint; | 122 SkPaint paint; |
| 124 paint.setAntiAlias(true); | 123 paint.setAntiAlias(true); |
| 125 paint.setSubpixelText(true); | 124 paint.setSubpixelText(true); |
| 126 paint.setTextSize(fTextSize); | 125 paint.setTextSize(fTextSize); |
| 127 | 126 |
| 128 setTypeface(&paint, "Times", SkTypeface::kNormal); | 127 setTypeface(&paint, "Times", SkTypeface::kNormal); |
| 129 canvas.drawText("Hamburgefons", 12, fTextSize/2, 1.2f*fTextSize, paint
); | 128 canvas.drawText("Hamburgefons", 12, fTextSize/2, 1.2f*fTextSize, paint
); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 148 | 147 |
| 149 protected: | 148 protected: |
| 150 int fSize; | 149 int fSize; |
| 151 int fNumChecks; | 150 int fNumChecks; |
| 152 | 151 |
| 153 SkScalar getScale() SK_OVERRIDE { | 152 SkScalar getScale() SK_OVERRIDE { |
| 154 return 192.f/fSize; | 153 return 192.f/fSize; |
| 155 } | 154 } |
| 156 | 155 |
| 157 void makeBitmap() SK_OVERRIDE { | 156 void makeBitmap() SK_OVERRIDE { |
| 158 fBM.setConfig(SkBitmap::kARGB_8888_Config, fSize, fSize); | 157 fBM.allocN32Pixels(fSize, fSize); |
| 159 fBM.allocPixels(); | |
| 160 SkAutoLockPixels lock(fBM); | |
| 161 for (int y = 0; y < fSize; y ++) { | 158 for (int y = 0; y < fSize; y ++) { |
| 162 for (int x = 0; x < fSize; x ++) { | 159 for (int x = 0; x < fSize; x ++) { |
| 163 SkPMColor* s = fBM.getAddr32(x, y); | 160 SkPMColor* s = fBM.getAddr32(x, y); |
| 164 int cx = (x * fNumChecks) / fSize; | 161 int cx = (x * fNumChecks) / fSize; |
| 165 int cy = (y * fNumChecks) / fSize; | 162 int cy = (y * fNumChecks) / fSize; |
| 166 if ((cx+cy)%2) { | 163 if ((cx+cy)%2) { |
| 167 *s = 0xFFFFFFFF; | 164 *s = 0xFFFFFFFF; |
| 168 } else { | 165 } else { |
| 169 *s = 0xFF000000; | 166 *s = 0xFF000000; |
| 170 } | 167 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 200 SkFILEStream stream(path.c_str()); | 197 SkFILEStream stream(path.c_str()); |
| 201 if (stream.isValid()) { | 198 if (stream.isValid()) { |
| 202 codec = SkImageDecoder::Factory(&stream); | 199 codec = SkImageDecoder::Factory(&stream); |
| 203 } | 200 } |
| 204 if (codec) { | 201 if (codec) { |
| 205 stream.rewind(); | 202 stream.rewind(); |
| 206 codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, | 203 codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, |
| 207 SkImageDecoder::kDecodePixels_Mode); | 204 SkImageDecoder::kDecodePixels_Mode); |
| 208 SkDELETE(codec); | 205 SkDELETE(codec); |
| 209 } else { | 206 } else { |
| 210 fBM.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | 207 fBM.allocN32Pixels(1, 1); |
| 211 fBM.allocPixels(); | |
| 212 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad | 208 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad |
| 213 } | 209 } |
| 214 fSize = fBM.height(); | 210 fSize = fBM.height(); |
| 215 } | 211 } |
| 216 private: | 212 private: |
| 217 typedef FilterBitmapGM INHERITED; | 213 typedef FilterBitmapGM INHERITED; |
| 218 }; | 214 }; |
| 219 | 215 |
| 220 ////////////////////////////////////////////////////////////////////////////// | 216 ////////////////////////////////////////////////////////////////////////////// |
| 221 | 217 |
| 222 DEF_GM( return new FilterBitmapTextGM(3); ) | 218 DEF_GM( return new FilterBitmapTextGM(3); ) |
| 223 DEF_GM( return new FilterBitmapTextGM(7); ) | 219 DEF_GM( return new FilterBitmapTextGM(7); ) |
| 224 DEF_GM( return new FilterBitmapTextGM(10); ) | 220 DEF_GM( return new FilterBitmapTextGM(10); ) |
| 225 DEF_GM( return new FilterBitmapCheckerboardGM(4,4); ) | 221 DEF_GM( return new FilterBitmapCheckerboardGM(4,4); ) |
| 226 DEF_GM( return new FilterBitmapCheckerboardGM(32,32); ) | 222 DEF_GM( return new FilterBitmapCheckerboardGM(32,32); ) |
| 227 DEF_GM( return new FilterBitmapCheckerboardGM(32,8); ) | 223 DEF_GM( return new FilterBitmapCheckerboardGM(32,8); ) |
| 228 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); ) | 224 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); ) |
| 229 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); ) | 225 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); ) |
| 230 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); ) | 226 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); ) |
| 231 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); ) | 227 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); ) |
| 232 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); ) | 228 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); ) |
| 233 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); ) | 229 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); ) |
| 234 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); ) | 230 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); ) |
| 235 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); ) | 231 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); ) |
| OLD | NEW |