OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkLightingImageFilter.h" | 9 #include "SkLightingImageFilter.h" |
10 | 10 |
11 #define WIDTH 330 | 11 #define WIDTH 330 |
12 #define HEIGHT 440 | 12 #define HEIGHT 440 |
13 | 13 |
14 namespace skiagm { | 14 namespace skiagm { |
15 | 15 |
16 class ImageLightingGM : public GM { | 16 class ImageLightingGM : public GM { |
17 public: | 17 public: |
18 ImageLightingGM() : fInitialized(false) { | 18 ImageLightingGM() : fInitialized(false) { |
19 this->setBGColor(0xFF000000); | 19 this->setBGColor(0xFF000000); |
20 } | 20 } |
21 | 21 |
22 protected: | 22 protected: |
23 | 23 |
24 SkString onShortName() SK_OVERRIDE { | 24 SkString onShortName() override { |
25 return SkString("lighting"); | 25 return SkString("lighting"); |
26 } | 26 } |
27 | 27 |
28 void make_bitmap() { | 28 void make_bitmap() { |
29 fBitmap.allocN32Pixels(100, 100); | 29 fBitmap.allocN32Pixels(100, 100); |
30 SkCanvas canvas(fBitmap); | 30 SkCanvas canvas(fBitmap); |
31 canvas.clear(0x00000000); | 31 canvas.clear(0x00000000); |
32 SkPaint paint; | 32 SkPaint paint; |
33 paint.setAntiAlias(true); | 33 paint.setAntiAlias(true); |
34 sk_tool_utils::set_portable_typeface(&paint); | 34 sk_tool_utils::set_portable_typeface(&paint); |
35 paint.setColor(0xFFFFFFFF); | 35 paint.setColor(0xFFFFFFFF); |
36 paint.setTextSize(SkIntToScalar(96)); | 36 paint.setTextSize(SkIntToScalar(96)); |
37 const char* str = "e"; | 37 const char* str = "e"; |
38 canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); | 38 canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); |
39 } | 39 } |
40 | 40 |
41 SkISize onISize() SK_OVERRIDE { | 41 SkISize onISize() override { |
42 return SkISize::Make(WIDTH, HEIGHT); | 42 return SkISize::Make(WIDTH, HEIGHT); |
43 } | 43 } |
44 | 44 |
45 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y)
{ | 45 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y)
{ |
46 canvas->save(); | 46 canvas->save(); |
47 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 47 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
48 canvas->clipRect(SkRect::MakeWH( | 48 canvas->clipRect(SkRect::MakeWH( |
49 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); | 49 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); |
50 canvas->drawBitmap(fBitmap, 0, 0, &paint); | 50 canvas->drawBitmap(fBitmap, 0, 0, &paint); |
51 canvas->restore(); | 51 canvas->restore(); |
52 } | 52 } |
53 | 53 |
54 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 54 void onDraw(SkCanvas* canvas) override { |
55 if (!fInitialized) { | 55 if (!fInitialized) { |
56 make_bitmap(); | 56 make_bitmap(); |
57 fInitialized = true; | 57 fInitialized = true; |
58 } | 58 } |
59 canvas->clear(0xFF101010); | 59 canvas->clear(0xFF101010); |
60 SkPaint checkPaint; | 60 SkPaint checkPaint; |
61 checkPaint.setColor(0xFF202020); | 61 checkPaint.setColor(0xFF202020); |
62 for (int y = 0; y < HEIGHT; y += 16) { | 62 for (int y = 0; y < HEIGHT; y += 16) { |
63 for (int x = 0; x < WIDTH; x += 16) { | 63 for (int x = 0; x < WIDTH; x += 16) { |
64 canvas->save(); | 64 canvas->save(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 SkBitmap fBitmap; | 119 SkBitmap fBitmap; |
120 bool fInitialized; | 120 bool fInitialized; |
121 }; | 121 }; |
122 | 122 |
123 ////////////////////////////////////////////////////////////////////////////// | 123 ////////////////////////////////////////////////////////////////////////////// |
124 | 124 |
125 static GM* MyFactory(void*) { return new ImageLightingGM; } | 125 static GM* MyFactory(void*) { return new ImageLightingGM; } |
126 static GMRegistry reg(MyFactory); | 126 static GMRegistry reg(MyFactory); |
127 | 127 |
128 } | 128 } |
OLD | NEW |