| 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 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 DownsampleBitmapTextGM(float textSize, SkPaint::FilterLevel filterLevel) | 92 DownsampleBitmapTextGM(float textSize, SkPaint::FilterLevel filterLevel) |
| 93 : INHERITED(filterLevel), fTextSize(textSize) | 93 : INHERITED(filterLevel), fTextSize(textSize) |
| 94 { | 94 { |
| 95 fName.printf("downsamplebitmap_text_%s_%.2fpt", this->filterLevelToS
tring(), fTextSize); | 95 fName.printf("downsamplebitmap_text_%s_%.2fpt", this->filterLevelToS
tring(), fTextSize); |
| 96 } | 96 } |
| 97 | 97 |
| 98 protected: | 98 protected: |
| 99 float fTextSize; | 99 float fTextSize; |
| 100 | 100 |
| 101 virtual void make_bitmap() SK_OVERRIDE { | 101 virtual void make_bitmap() SK_OVERRIDE { |
| 102 fBM.setConfig(SkBitmap::kARGB_8888_Config, int(fTextSize * 8), int(fTe
xtSize * 6)); | 102 fBM.allocN32Pixels(int(fTextSize * 8), int(fTextSize * 6)); |
| 103 fBM.allocPixels(); | |
| 104 SkCanvas canvas(fBM); | 103 SkCanvas canvas(fBM); |
| 105 canvas.drawColor(SK_ColorWHITE); | 104 canvas.drawColor(SK_ColorWHITE); |
| 106 | 105 |
| 107 SkPaint paint; | 106 SkPaint paint; |
| 108 paint.setAntiAlias(true); | 107 paint.setAntiAlias(true); |
| 109 paint.setSubpixelText(true); | 108 paint.setSubpixelText(true); |
| 110 paint.setTextSize(fTextSize); | 109 paint.setTextSize(fTextSize); |
| 111 | 110 |
| 112 setTypeface(&paint, "Times", SkTypeface::kNormal); | 111 setTypeface(&paint, "Times", SkTypeface::kNormal); |
| 113 canvas.drawText("Hamburgefons", 12, fTextSize/2, 1.2f*fTextSize, paint
); | 112 canvas.drawText("Hamburgefons", 12, fTextSize/2, 1.2f*fTextSize, paint
); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 128 : INHERITED(filterLevel), fSize(size), fNumChecks(numChecks) | 127 : INHERITED(filterLevel), fSize(size), fNumChecks(numChecks) |
| 129 { | 128 { |
| 130 fName.printf("downsamplebitmap_checkerboard_%s_%d_%d", this->filterL
evelToString(), fSize, fNumChecks); | 129 fName.printf("downsamplebitmap_checkerboard_%s_%d_%d", this->filterL
evelToString(), fSize, fNumChecks); |
| 131 } | 130 } |
| 132 | 131 |
| 133 protected: | 132 protected: |
| 134 int fSize; | 133 int fSize; |
| 135 int fNumChecks; | 134 int fNumChecks; |
| 136 | 135 |
| 137 virtual void make_bitmap() SK_OVERRIDE { | 136 virtual void make_bitmap() SK_OVERRIDE { |
| 138 fBM.setConfig(SkBitmap::kARGB_8888_Config, fSize, fSize); | 137 fBM.allocN32Pixels(fSize, fSize); |
| 139 fBM.allocPixels(); | |
| 140 SkAutoLockPixels lock(fBM); | |
| 141 for (int y = 0; y < fSize; ++y) { | 138 for (int y = 0; y < fSize; ++y) { |
| 142 for (int x = 0; x < fSize; ++x) { | 139 for (int x = 0; x < fSize; ++x) { |
| 143 SkPMColor* s = fBM.getAddr32(x, y); | 140 SkPMColor* s = fBM.getAddr32(x, y); |
| 144 int cx = (x * fNumChecks) / fSize; | 141 int cx = (x * fNumChecks) / fSize; |
| 145 int cy = (y * fNumChecks) / fSize; | 142 int cy = (y * fNumChecks) / fSize; |
| 146 if ((cx+cy)%2) { | 143 if ((cx+cy)%2) { |
| 147 *s = 0xFFFFFFFF; | 144 *s = 0xFFFFFFFF; |
| 148 } else { | 145 } else { |
| 149 *s = 0xFF000000; | 146 *s = 0xFF000000; |
| 150 } | 147 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 176 SkFILEStream stream(path.c_str()); | 173 SkFILEStream stream(path.c_str()); |
| 177 if (stream.isValid()) { | 174 if (stream.isValid()) { |
| 178 codec = SkImageDecoder::Factory(&stream); | 175 codec = SkImageDecoder::Factory(&stream); |
| 179 } | 176 } |
| 180 if (codec) { | 177 if (codec) { |
| 181 stream.rewind(); | 178 stream.rewind(); |
| 182 codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, | 179 codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, |
| 183 SkImageDecoder::kDecodePixels_Mode); | 180 SkImageDecoder::kDecodePixels_Mode); |
| 184 SkDELETE(codec); | 181 SkDELETE(codec); |
| 185 } else { | 182 } else { |
| 186 fBM.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | 183 fBM.allocN32Pixels(1, 1); |
| 187 fBM.allocPixels(); | |
| 188 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad | 184 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad |
| 189 } | 185 } |
| 190 fSize = fBM.height(); | 186 fSize = fBM.height(); |
| 191 } | 187 } |
| 192 private: | 188 private: |
| 193 typedef DownsampleBitmapGM INHERITED; | 189 typedef DownsampleBitmapGM INHERITED; |
| 194 }; | 190 }; |
| 195 | 191 |
| 196 ////////////////////////////////////////////////////////////////////////////// | 192 ////////////////////////////////////////////////////////////////////////////// |
| 197 | 193 |
| 198 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kHigh_FilterLevel); ) | 194 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kHigh_FilterLevel); ) |
| 199 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kHigh_Filter
Level); ) | 195 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kHigh_Filter
Level); ) |
| 200 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kHigh_Fi
lterLevel); ) | 196 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kHigh_Fi
lterLevel); ) |
| 201 | 197 |
| 202 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kMedium_FilterLevel); ) | 198 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kMedium_FilterLevel); ) |
| 203 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kMedium_Filt
erLevel); ) | 199 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kMedium_Filt
erLevel); ) |
| 204 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kMedium_
FilterLevel); ) | 200 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kMedium_
FilterLevel); ) |
| 205 | 201 |
| 206 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kLow_FilterLevel); ) | 202 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kLow_FilterLevel); ) |
| 207 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kLow_FilterL
evel); ) | 203 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kLow_FilterL
evel); ) |
| 208 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kLow_Fil
terLevel); ) | 204 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kLow_Fil
terLevel); ) |
| 209 | 205 |
| 210 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kNone_FilterLevel); ) | 206 DEF_GM( return new DownsampleBitmapTextGM(72, SkPaint::kNone_FilterLevel); ) |
| 211 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kNone_Filter
Level); ) | 207 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, SkPaint::kNone_Filter
Level); ) |
| 212 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kNone_Fi
lterLevel); ) | 208 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", SkPaint::kNone_Fi
lterLevel); ) |
| OLD | NEW |