OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkView.h" | 9 #include "SkView.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
12 #include "SkPath.h" | 12 #include "SkPath.h" |
13 #include "SkRegion.h" | 13 #include "SkRegion.h" |
14 #include "SkShader.h" | 14 #include "SkShader.h" |
15 #include "SkUtils.h" | 15 #include "SkUtils.h" |
16 #include "Sk1DPathEffect.h" | 16 #include "Sk1DPathEffect.h" |
17 #include "SkCornerPathEffect.h" | 17 #include "SkCornerPathEffect.h" |
18 #include "SkPathMeasure.h" | 18 #include "SkPathMeasure.h" |
19 #include "SkRandom.h" | 19 #include "SkRandom.h" |
20 #include "SkColorPriv.h" | 20 #include "SkColorPriv.h" |
21 #include "SkColorFilter.h" | 21 #include "SkColorFilter.h" |
22 #include "SkDither.h" | 22 #include "SkDither.h" |
| 23 #include "sk_tool_utils.h" |
23 | 24 |
24 static void make_bm(SkBitmap* bm) { | 25 static void make_bm(SkBitmap* bm) { |
25 const SkPMColor colors[] = { | 26 const SkPMColor colors[] = { |
26 SkPreMultiplyColor(SK_ColorRED), SkPreMultiplyColor(SK_ColorGREEN), | 27 SkPreMultiplyColor(SK_ColorRED), SkPreMultiplyColor(SK_ColorGREEN), |
27 SkPreMultiplyColor(SK_ColorBLUE), SkPreMultiplyColor(SK_ColorWHITE) | 28 SkPreMultiplyColor(SK_ColorBLUE), SkPreMultiplyColor(SK_ColorWHITE) |
28 }; | 29 }; |
29 SkColorTable* ctable = new SkColorTable(colors, 4); | 30 SkColorTable* ctable = new SkColorTable(colors, 4); |
30 bm->allocPixels(SkImageInfo::Make(2, 2, kIndex_8_SkColorType, | 31 bm->allocPixels(SkImageInfo::Make(2, 2, kIndex_8_SkColorType, |
31 kOpaque_SkAlphaType), | 32 kOpaque_SkAlphaType), |
32 NULL, ctable); | 33 NULL, ctable); |
(...skipping 12 matching lines...) Expand all Loading... |
45 } | 46 } |
46 | 47 |
47 static SkScalar draw_set(SkCanvas* c, const SkBitmap& bm, SkScalar x, SkPaint* p
) { | 48 static SkScalar draw_set(SkCanvas* c, const SkBitmap& bm, SkScalar x, SkPaint* p
) { |
48 x += draw_bm(c, bm, x, 0, p); | 49 x += draw_bm(c, bm, x, 0, p); |
49 p->setFilterLevel(SkPaint::kLow_FilterLevel); | 50 p->setFilterLevel(SkPaint::kLow_FilterLevel); |
50 x += draw_bm(c, bm, x, 0, p); | 51 x += draw_bm(c, bm, x, 0, p); |
51 p->setDither(true); | 52 p->setDither(true); |
52 return x + draw_bm(c, bm, x, 0, p); | 53 return x + draw_bm(c, bm, x, 0, p); |
53 } | 54 } |
54 | 55 |
55 static const char* gConfigNames[] = { | |
56 "unknown config", | |
57 "A8", | |
58 "Index8", | |
59 "565", | |
60 "4444", | |
61 "8888" | |
62 }; | |
63 | |
64 static SkScalar draw_row(SkCanvas* canvas, const SkBitmap& bm) { | 56 static SkScalar draw_row(SkCanvas* canvas, const SkBitmap& bm) { |
65 SkAutoCanvasRestore acr(canvas, true); | 57 SkAutoCanvasRestore acr(canvas, true); |
66 | 58 |
67 SkPaint paint; | 59 SkPaint paint; |
68 SkScalar x = 0; | 60 SkScalar x = 0; |
69 const int scale = 32; | 61 const int scale = 32; |
70 | 62 |
71 paint.setAntiAlias(true); | 63 paint.setAntiAlias(true); |
72 const char* name = gConfigNames[bm.config()]; | 64 const char* name = sk_tool_utils::colortype_name(bm.colorType()); |
73 canvas->drawText(name, strlen(name), x, SkIntToScalar(bm.height())*scale*5/8
, | 65 canvas->drawText(name, strlen(name), x, SkIntToScalar(bm.height())*scale*5/8
, |
74 paint); | 66 paint); |
75 canvas->translate(SkIntToScalar(48), 0); | 67 canvas->translate(SkIntToScalar(48), 0); |
76 | 68 |
77 canvas->scale(SkIntToScalar(scale), SkIntToScalar(scale)); | 69 canvas->scale(SkIntToScalar(scale), SkIntToScalar(scale)); |
78 | 70 |
79 x += draw_set(canvas, bm, 0, &paint); | 71 x += draw_set(canvas, bm, 0, &paint); |
80 paint.reset(); | 72 paint.reset(); |
81 paint.setAlpha(0x80); | 73 paint.setAlpha(0x80); |
82 draw_set(canvas, bm, x, &paint); | 74 draw_set(canvas, bm, x, &paint); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 113 } |
122 | 114 |
123 private: | 115 private: |
124 typedef SampleView INHERITED; | 116 typedef SampleView INHERITED; |
125 }; | 117 }; |
126 | 118 |
127 ////////////////////////////////////////////////////////////////////////////// | 119 ////////////////////////////////////////////////////////////////////////////// |
128 | 120 |
129 static SkView* MyFactory() { return new FilterView; } | 121 static SkView* MyFactory() { return new FilterView; } |
130 static SkViewRegister reg(MyFactory); | 122 static SkViewRegister reg(MyFactory); |
OLD | NEW |