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 25 matching lines...) Expand all Loading... |
36 } | 36 } |
37 | 37 |
38 static void draw_row(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat,
SkScalar dx) { | 38 static void draw_row(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat,
SkScalar dx) { |
39 draw_cell(canvas, bm, mat, 0 * dx, kNone_SkFilterQuality); | 39 draw_cell(canvas, bm, mat, 0 * dx, kNone_SkFilterQuality); |
40 draw_cell(canvas, bm, mat, 1 * dx, kLow_SkFilterQuality); | 40 draw_cell(canvas, bm, mat, 1 * dx, kLow_SkFilterQuality); |
41 draw_cell(canvas, bm, mat, 2 * dx, kMedium_SkFilterQuality); | 41 draw_cell(canvas, bm, mat, 2 * dx, kMedium_SkFilterQuality); |
42 draw_cell(canvas, bm, mat, 3 * dx, kHigh_SkFilterQuality); | 42 draw_cell(canvas, bm, mat, 3 * dx, kHigh_SkFilterQuality); |
43 } | 43 } |
44 | 44 |
45 class FilterBitmapGM : public skiagm::GM { | 45 class FilterBitmapGM : public skiagm::GM { |
46 void onOnceBeforeDraw() SK_OVERRIDE { | 46 void onOnceBeforeDraw() override { |
47 | 47 |
48 this->makeBitmap(); | 48 this->makeBitmap(); |
49 | 49 |
50 SkScalar cx = SkScalarHalf(fBM.width()); | 50 SkScalar cx = SkScalarHalf(fBM.width()); |
51 SkScalar cy = SkScalarHalf(fBM.height()); | 51 SkScalar cy = SkScalarHalf(fBM.height()); |
52 SkScalar scale = this->getScale(); | 52 SkScalar scale = this->getScale(); |
53 | 53 |
54 // these two matrices use a scale factor configured by the subclass | 54 // these two matrices use a scale factor configured by the subclass |
55 fMatrix[0].setScale(scale, scale); | 55 fMatrix[0].setScale(scale, scale); |
56 fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(scale, scale); | 56 fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(scale, scale); |
57 | 57 |
58 // up/down scaling mix | 58 // up/down scaling mix |
59 fMatrix[2].setScale(0.7f, 1.05f); | 59 fMatrix[2].setScale(0.7f, 1.05f); |
60 } | 60 } |
61 | 61 |
62 public: | 62 public: |
63 SkBitmap fBM; | 63 SkBitmap fBM; |
64 SkMatrix fMatrix[3]; | 64 SkMatrix fMatrix[3]; |
65 SkString fName; | 65 SkString fName; |
66 | 66 |
67 FilterBitmapGM() | 67 FilterBitmapGM() |
68 { | 68 { |
69 this->setBGColor(0xFFDDDDDD); | 69 this->setBGColor(0xFFDDDDDD); |
70 } | 70 } |
71 | 71 |
72 protected: | 72 protected: |
73 | 73 |
74 SkString onShortName() SK_OVERRIDE { | 74 SkString onShortName() override { |
75 return fName; | 75 return fName; |
76 } | 76 } |
77 | 77 |
78 SkISize onISize() SK_OVERRIDE { | 78 SkISize onISize() override { |
79 return SkISize::Make(1024, 768); | 79 return SkISize::Make(1024, 768); |
80 } | 80 } |
81 | 81 |
82 virtual void makeBitmap() = 0; | 82 virtual void makeBitmap() = 0; |
83 virtual SkScalar getScale() = 0; | 83 virtual SkScalar getScale() = 0; |
84 | 84 |
85 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 85 void onDraw(SkCanvas* canvas) override { |
86 | 86 |
87 canvas->translate(10, 10); | 87 canvas->translate(10, 10); |
88 for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrix); ++i) { | 88 for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrix); ++i) { |
89 SkSize size = computeSize(fBM, fMatrix[i]); | 89 SkSize size = computeSize(fBM, fMatrix[i]); |
90 size.fWidth += 20; | 90 size.fWidth += 20; |
91 size.fHeight += 20; | 91 size.fHeight += 20; |
92 | 92 |
93 draw_row(canvas, fBM, fMatrix[i], size.fWidth); | 93 draw_row(canvas, fBM, fMatrix[i], size.fWidth); |
94 canvas->translate(0, size.fHeight); | 94 canvas->translate(0, size.fHeight); |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 private: | 98 private: |
99 typedef skiagm::GM INHERITED; | 99 typedef skiagm::GM INHERITED; |
100 }; | 100 }; |
101 | 101 |
102 class FilterBitmapTextGM: public FilterBitmapGM { | 102 class FilterBitmapTextGM: public FilterBitmapGM { |
103 public: | 103 public: |
104 FilterBitmapTextGM(float textSize) | 104 FilterBitmapTextGM(float textSize) |
105 : fTextSize(textSize) | 105 : fTextSize(textSize) |
106 { | 106 { |
107 fName.printf("filterbitmap_text_%.2fpt", fTextSize); | 107 fName.printf("filterbitmap_text_%.2fpt", fTextSize); |
108 } | 108 } |
109 | 109 |
110 protected: | 110 protected: |
111 float fTextSize; | 111 float fTextSize; |
112 | 112 |
113 SkScalar getScale() SK_OVERRIDE { | 113 SkScalar getScale() override { |
114 return 32.f/fTextSize; | 114 return 32.f/fTextSize; |
115 } | 115 } |
116 | 116 |
117 void makeBitmap() SK_OVERRIDE { | 117 void makeBitmap() override { |
118 fBM.allocN32Pixels(int(fTextSize * 8), int(fTextSize * 6)); | 118 fBM.allocN32Pixels(int(fTextSize * 8), int(fTextSize * 6)); |
119 SkCanvas canvas(fBM); | 119 SkCanvas canvas(fBM); |
120 canvas.drawColor(SK_ColorWHITE); | 120 canvas.drawColor(SK_ColorWHITE); |
121 | 121 |
122 SkPaint paint; | 122 SkPaint paint; |
123 paint.setAntiAlias(true); | 123 paint.setAntiAlias(true); |
124 paint.setSubpixelText(true); | 124 paint.setSubpixelText(true); |
125 paint.setTextSize(fTextSize); | 125 paint.setTextSize(fTextSize); |
126 | 126 |
127 setTypeface(&paint, "Times", SkTypeface::kNormal); | 127 setTypeface(&paint, "Times", SkTypeface::kNormal); |
(...skipping 15 matching lines...) Expand all Loading... |
143 : fSize(size), fNumChecks(num_checks), fConvertToG8(convertToG8) | 143 : fSize(size), fNumChecks(num_checks), fConvertToG8(convertToG8) |
144 { | 144 { |
145 fName.printf("filterbitmap_checkerboard_%d_%d%s", | 145 fName.printf("filterbitmap_checkerboard_%d_%d%s", |
146 fSize, fNumChecks, convertToG8 ? "_g8" : ""); | 146 fSize, fNumChecks, convertToG8 ? "_g8" : ""); |
147 } | 147 } |
148 | 148 |
149 protected: | 149 protected: |
150 int fSize; | 150 int fSize; |
151 int fNumChecks; | 151 int fNumChecks; |
152 | 152 |
153 SkScalar getScale() SK_OVERRIDE { | 153 SkScalar getScale() override { |
154 return 192.f/fSize; | 154 return 192.f/fSize; |
155 } | 155 } |
156 | 156 |
157 void makeBitmap() SK_OVERRIDE { | 157 void makeBitmap() override { |
158 fBM.allocN32Pixels(fSize, fSize); | 158 fBM.allocN32Pixels(fSize, fSize); |
159 for (int y = 0; y < fSize; y ++) { | 159 for (int y = 0; y < fSize; y ++) { |
160 for (int x = 0; x < fSize; x ++) { | 160 for (int x = 0; x < fSize; x ++) { |
161 SkPMColor* s = fBM.getAddr32(x, y); | 161 SkPMColor* s = fBM.getAddr32(x, y); |
162 int cx = (x * fNumChecks) / fSize; | 162 int cx = (x * fNumChecks) / fSize; |
163 int cy = (y * fNumChecks) / fSize; | 163 int cy = (y * fNumChecks) / fSize; |
164 if ((cx+cy)%2) { | 164 if ((cx+cy)%2) { |
165 *s = 0xFFFFFFFF; | 165 *s = 0xFFFFFFFF; |
166 } else { | 166 } else { |
167 *s = 0xFF000000; | 167 *s = 0xFF000000; |
(...skipping 16 matching lines...) Expand all Loading... |
184 FilterBitmapImageGM(const char filename[], bool convertToG8 = false) | 184 FilterBitmapImageGM(const char filename[], bool convertToG8 = false) |
185 : fFilename(filename), fConvertToG8(convertToG8) | 185 : fFilename(filename), fConvertToG8(convertToG8) |
186 { | 186 { |
187 fName.printf("filterbitmap_image_%s%s", filename, convertToG8 ? "_g8" :
""); | 187 fName.printf("filterbitmap_image_%s%s", filename, convertToG8 ? "_g8" :
""); |
188 } | 188 } |
189 | 189 |
190 protected: | 190 protected: |
191 SkString fFilename; | 191 SkString fFilename; |
192 int fSize; | 192 int fSize; |
193 | 193 |
194 SkScalar getScale() SK_OVERRIDE { | 194 SkScalar getScale() override { |
195 return 192.f/fSize; | 195 return 192.f/fSize; |
196 } | 196 } |
197 | 197 |
198 void makeBitmap() SK_OVERRIDE { | 198 void makeBitmap() override { |
199 SkImageDecoder* codec = NULL; | 199 SkImageDecoder* codec = NULL; |
200 SkString resourcePath = GetResourcePath(fFilename.c_str()); | 200 SkString resourcePath = GetResourcePath(fFilename.c_str()); |
201 SkFILEStream stream(resourcePath.c_str()); | 201 SkFILEStream stream(resourcePath.c_str()); |
202 if (stream.isValid()) { | 202 if (stream.isValid()) { |
203 codec = SkImageDecoder::Factory(&stream); | 203 codec = SkImageDecoder::Factory(&stream); |
204 } | 204 } |
205 if (codec) { | 205 if (codec) { |
206 stream.rewind(); | 206 stream.rewind(); |
207 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDe
codePixels_Mode); | 207 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDe
codePixels_Mode); |
208 SkDELETE(codec); | 208 SkDELETE(codec); |
(...skipping 25 matching lines...) Expand all Loading... |
234 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); ) | 234 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); ) |
235 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); ) | 235 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); ) |
236 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); ) | 236 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); ) |
237 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); ) | 237 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); ) |
238 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); ) | 239 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png", true); ) |
240 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); ) | 240 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); ) |
241 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); ) | 241 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); ) |
242 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); ) | 242 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); ) |
243 DEF_GM( return new FilterBitmapImageGM("color_wheel.png"); ) | 243 DEF_GM( return new FilterBitmapImageGM("color_wheel.png"); ) |
OLD | NEW |