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 17 matching lines...) Expand all Loading... |
28 SkPaint paint; | 28 SkPaint paint; |
29 | 29 |
30 SkAutoCanvasRestore acr(canvas, true); | 30 SkAutoCanvasRestore acr(canvas, true); |
31 | 31 |
32 canvas->drawBitmapMatrix(bm, mat, &paint); | 32 canvas->drawBitmapMatrix(bm, mat, &paint); |
33 | 33 |
34 paint.setFilterBitmap(true); | 34 paint.setFilterBitmap(true); |
35 canvas->translate(dx, 0); | 35 canvas->translate(dx, 0); |
36 canvas->drawBitmapMatrix(bm, mat, &paint); | 36 canvas->drawBitmapMatrix(bm, mat, &paint); |
37 | 37 |
38 paint.setFlags(paint.getFlags() | SkPaint::kBicubicFilterBitmap_Flag); | 38 paint.setFlags(paint.getFlags() | SkPaint::kHighQualityFilterBitmap_Flag); |
39 canvas->translate(dx, 0); | 39 canvas->translate(dx, 0); |
40 canvas->drawBitmapMatrix(bm, mat, &paint); | 40 canvas->drawBitmapMatrix(bm, mat, &paint); |
41 } | 41 } |
42 | 42 |
43 class FilterBitmapGM : public skiagm::GM { | 43 class FilterBitmapGM : public skiagm::GM { |
44 void onOnceBeforeDraw() { | 44 void onOnceBeforeDraw() { |
45 | 45 |
46 make_bitmap(); | 46 make_bitmap(); |
47 | 47 |
48 SkScalar cx = SkScalarHalf(fBM.width()); | 48 SkScalar cx = SkScalarHalf(fBM.width()); |
49 SkScalar cy = SkScalarHalf(fBM.height()); | 49 SkScalar cy = SkScalarHalf(fBM.height()); |
50 SkScalar scale = get_scale(); | 50 SkScalar scale = get_scale(); |
51 | 51 |
52 | 52 |
53 fMatrix[0].setScale(scale, scale); | 53 fMatrix[0].setScale(scale, scale); |
54 fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(scale, scale); | 54 fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(scale, scale); |
55 } | 55 } |
56 | 56 |
57 public: | 57 public: |
58 SkBitmap fBM; | 58 SkBitmap fBM; |
59 SkMatrix fMatrix[2]; | 59 SkMatrix fMatrix[2]; |
60 SkString fName; | 60 SkString fName; |
61 | 61 |
62 FilterBitmapGM() | 62 FilterBitmapGM() |
63 { | 63 { |
64 this->setBGColor(0xFFDDDDDD); | 64 this->setBGColor(0xFFDDDDDD); |
65 } | 65 } |
66 | 66 |
67 void setName( const char name[] ) { | 67 void setName(const char name[]) { |
68 fName.set(name); | 68 fName.set(name); |
69 } | 69 } |
70 | 70 |
71 protected: | 71 protected: |
72 virtual SkString onShortName() SK_OVERRIDE { | 72 virtual SkString onShortName() SK_OVERRIDE { |
73 return fName; | 73 return fName; |
74 } | 74 } |
75 | 75 |
76 virtual SkISize onISize() SK_OVERRIDE { | 76 virtual SkISize onISize() SK_OVERRIDE { |
77 return SkISize::Make(920, 480); | 77 return SkISize::Make(920, 480); |
(...skipping 14 matching lines...) Expand all Loading... |
92 canvas->translate(0, size.fHeight); | 92 canvas->translate(0, size.fHeight); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 private: | 96 private: |
97 typedef skiagm::GM INHERITED; | 97 typedef skiagm::GM INHERITED; |
98 }; | 98 }; |
99 | 99 |
100 class FilterBitmapTextGM: public FilterBitmapGM { | 100 class FilterBitmapTextGM: public FilterBitmapGM { |
101 public: | 101 public: |
102 FilterBitmapTextGM( float textSize ) | 102 FilterBitmapTextGM(float textSize) |
103 : fTextSize( textSize ) | 103 : fTextSize(textSize) |
104 { | 104 { |
105 char name[1024]; | 105 char name[1024]; |
106 sprintf( name, "filterbitmap_text_%.2fpt", fTextSize ); | 106 sprintf(name, "filterbitmap_text_%.2fpt", fTextSize); |
107 setName( name ); | 107 setName(name); |
108 } | 108 } |
109 | 109 |
110 protected: | 110 protected: |
111 float fTextSize; | 111 float fTextSize; |
112 | 112 |
113 SkScalar get_scale() SK_OVERRIDE { | 113 SkScalar get_scale() SK_OVERRIDE { |
114 return 32.f/fTextSize; | 114 return 32.f/fTextSize; |
115 } | 115 } |
116 | 116 |
117 void make_bitmap() SK_OVERRIDE { | 117 void make_bitmap() SK_OVERRIDE { |
(...skipping 15 matching lines...) Expand all Loading... |
133 canvas.drawText("Hamburgefons", 12, fTextSize/2, 3.6f*fTextSize, paint
); | 133 canvas.drawText("Hamburgefons", 12, fTextSize/2, 3.6f*fTextSize, paint
); |
134 setTypeface(&paint, "Times", SkTypeface::kBoldItalic); | 134 setTypeface(&paint, "Times", SkTypeface::kBoldItalic); |
135 canvas.drawText("Hamburgefons", 12, fTextSize/2, 4.8f*fTextSize, paint
); | 135 canvas.drawText("Hamburgefons", 12, fTextSize/2, 4.8f*fTextSize, paint
); |
136 } | 136 } |
137 private: | 137 private: |
138 typedef FilterBitmapGM INHERITED; | 138 typedef FilterBitmapGM INHERITED; |
139 }; | 139 }; |
140 | 140 |
141 class FilterBitmapCheckerboardGM: public FilterBitmapGM { | 141 class FilterBitmapCheckerboardGM: public FilterBitmapGM { |
142 public: | 142 public: |
143 FilterBitmapCheckerboardGM( int size, int num_checks ) | 143 FilterBitmapCheckerboardGM(int size, int num_checks) |
144 : fSize( size ), fNumChecks( num_checks ) | 144 : fSize(size), fNumChecks(num_checks) |
145 { | 145 { |
146 char name[1024]; | 146 char name[1024]; |
147 sprintf( name, "filterbitmap_checkerboard_%d_%d", fSize, fNumChecks
); | 147 sprintf(name, "filterbitmap_checkerboard_%d_%d", fSize, fNumChecks); |
148 setName( name ); | 148 setName(name); |
149 } | 149 } |
150 | 150 |
151 protected: | 151 protected: |
152 int fSize; | 152 int fSize; |
153 int fNumChecks; | 153 int fNumChecks; |
154 | 154 |
155 SkScalar get_scale() SK_OVERRIDE { | 155 SkScalar get_scale() SK_OVERRIDE { |
156 return 192.f/fSize; | 156 return 192.f/fSize; |
157 } | 157 } |
158 | 158 |
(...skipping 13 matching lines...) Expand all Loading... |
172 } | 172 } |
173 } | 173 } |
174 } | 174 } |
175 } | 175 } |
176 private: | 176 private: |
177 typedef FilterBitmapGM INHERITED; | 177 typedef FilterBitmapGM INHERITED; |
178 }; | 178 }; |
179 | 179 |
180 class FilterBitmapImageGM: public FilterBitmapGM { | 180 class FilterBitmapImageGM: public FilterBitmapGM { |
181 public: | 181 public: |
182 FilterBitmapImageGM( const char filename[] ) | 182 FilterBitmapImageGM(const char filename[]) |
183 : fFilename( filename ) | 183 : fFilename(filename) |
184 { | 184 { |
185 char name[1024]; | 185 char name[1024]; |
186 sprintf( name, "filterbitmap_image_%s", filename ); | 186 sprintf(name, "filterbitmap_image_%s", filename); |
187 setName( name ); | 187 setName(name); |
188 } | 188 } |
189 | 189 |
190 protected: | 190 protected: |
191 SkString fFilename; | 191 SkString fFilename; |
192 int fSize; | 192 int fSize; |
193 | 193 |
194 SkScalar get_scale() SK_OVERRIDE { | 194 SkScalar get_scale() SK_OVERRIDE { |
195 return 192.f/fSize; | 195 return 192.f/fSize; |
196 } | 196 } |
197 | 197 |
198 void make_bitmap() SK_OVERRIDE { | 198 void make_bitmap() SK_OVERRIDE { |
199 SkString path(skiagm::GM::gResourcePath); | 199 SkString path(skiagm::GM::gResourcePath); |
200 path.append( "/" ); | 200 path.append("/"); |
201 path.append(fFilename); | 201 path.append(fFilename); |
202 | 202 |
203 SkImageDecoder *codec = NULL; | 203 SkImageDecoder *codec = NULL; |
204 SkFILEStream stream(path.c_str()); | 204 SkFILEStream stream(path.c_str()); |
205 if (stream.isValid()) { | 205 if (stream.isValid()) { |
206 codec = SkImageDecoder::Factory(&stream); | 206 codec = SkImageDecoder::Factory(&stream); |
207 } | 207 } |
208 if (codec) { | 208 if (codec) { |
209 stream.rewind(); | 209 stream.rewind(); |
210 codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, | 210 codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, |
(...skipping 19 matching lines...) Expand all Loading... |
230 DEF_GM( return new FilterBitmapCheckerboardGM(32,32); ) | 230 DEF_GM( return new FilterBitmapCheckerboardGM(32,32); ) |
231 DEF_GM( return new FilterBitmapCheckerboardGM(32,8); ) | 231 DEF_GM( return new FilterBitmapCheckerboardGM(32,8); ) |
232 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); ) | 232 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); ) |
233 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); ) | 233 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); ) |
234 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); ) | 234 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); ) |
235 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); ) | 235 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); ) |
236 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); ) | 236 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); ) |
237 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); ) | 237 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); ) |
238 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); ) | 238 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); ) |
239 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); ) | 239 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); ) |
OLD | NEW |