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 "Checkerboard.h" |
| 9 #include "SkBitmapSource.h" |
| 10 #include "SkDisplacementMapEffect.h" |
8 #include "gm.h" | 11 #include "gm.h" |
9 #include "SkDisplacementMapEffect.h" | |
10 #include "SkBitmapSource.h" | |
11 | 12 |
12 namespace skiagm { | 13 namespace skiagm { |
13 | 14 |
14 class DisplacementMapGM : public GM { | 15 class DisplacementMapGM : public GM { |
15 public: | 16 public: |
16 DisplacementMapGM() : fInitialized(false) { | 17 DisplacementMapGM() : fInitialized(false) { |
17 this->setBGColor(0xFF000000); | 18 this->setBGColor(0xFF000000); |
18 } | 19 } |
19 | 20 |
20 protected: | 21 protected: |
(...skipping 19 matching lines...) Expand all Loading... |
40 sk_tool_utils::set_portable_typeface(&paint); | 41 sk_tool_utils::set_portable_typeface(&paint); |
41 paint.setColor(0xFF884422); | 42 paint.setColor(0xFF884422); |
42 paint.setTextSize(SkIntToScalar(96)); | 43 paint.setTextSize(SkIntToScalar(96)); |
43 const char* str = "g"; | 44 const char* str = "g"; |
44 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55),
paint); | 45 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55),
paint); |
45 } | 46 } |
46 | 47 |
47 void make_checkerboard(SkBitmap* bitmap, int w, int h) { | 48 void make_checkerboard(SkBitmap* bitmap, int w, int h) { |
48 bitmap->allocN32Pixels(w, h); | 49 bitmap->allocN32Pixels(w, h); |
49 SkCanvas canvas(*bitmap); | 50 SkCanvas canvas(*bitmap); |
50 canvas.clear(0x00000000); | 51 sk_tools::DrawCheckerboard(&canvas, 0xFF244484, 0xFF804020, 8); |
51 SkPaint darkPaint; | |
52 darkPaint.setColor(0xFF804020); | |
53 SkPaint lightPaint; | |
54 lightPaint.setColor(0xFF244484); | |
55 for (int y = 0; y < h; y += 16) { | |
56 for (int x = 0; x < w; x += 16) { | |
57 canvas.save(); | |
58 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); | |
59 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); | |
60 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); | |
61 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); | |
62 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | |
63 canvas.restore(); | |
64 } | |
65 } | |
66 } | 52 } |
67 | 53 |
68 virtual SkISize onISize() { | 54 virtual SkISize onISize() { |
69 return SkISize::Make(500, 500); | 55 return SkISize::Make(500, 500); |
70 } | 56 } |
71 | 57 |
72 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint)
{ | 58 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint)
{ |
73 canvas->save(); | 59 canvas->save(); |
74 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 60 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
75 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()), SkIntToS
calar(fBitmap.height()))); | 61 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()), SkIntToS
calar(fBitmap.height()))); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 SkBitmap fBitmap, fCheckerboard, fSmall, fLarge, fLargeW, fLargeH; | 207 SkBitmap fBitmap, fCheckerboard, fSmall, fLarge, fLargeW, fLargeH; |
222 bool fInitialized; | 208 bool fInitialized; |
223 }; | 209 }; |
224 | 210 |
225 ////////////////////////////////////////////////////////////////////////////// | 211 ////////////////////////////////////////////////////////////////////////////// |
226 | 212 |
227 static GM* MyFactory(void*) { return new DisplacementMapGM; } | 213 static GM* MyFactory(void*) { return new DisplacementMapGM; } |
228 static GMRegistry reg(MyFactory); | 214 static GMRegistry reg(MyFactory); |
229 | 215 |
230 } | 216 } |
OLD | NEW |