| 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 #include "SkOffsetImageFilter.h" | 10 #include "SkOffsetImageFilter.h" |
| 11 #include "SkPoint3.h" | 11 #include "SkPoint3.h" |
| 12 | 12 |
| 13 #define WIDTH 330 | 13 #define WIDTH 330 |
| 14 #define HEIGHT 660 | 14 #define HEIGHT 660 |
| 15 | 15 |
| 16 namespace skiagm { | 16 namespace skiagm { |
| 17 | 17 |
| 18 class ImageLightingGM : public GM { | 18 class ImageLightingGM : public GM { |
| 19 public: | 19 public: |
| 20 ImageLightingGM() : fInitialized(false) { | 20 ImageLightingGM() { |
| 21 this->setBGColor(0xFF000000); | 21 this->setBGColor(0xFF000000); |
| 22 } | 22 } |
| 23 | 23 |
| 24 protected: | 24 protected: |
| 25 | 25 |
| 26 SkString onShortName() override { | 26 SkString onShortName() override { |
| 27 return SkString("lighting"); | 27 return SkString("lighting"); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void make_bitmap() { | |
| 31 fBitmap.allocN32Pixels(100, 100); | |
| 32 SkCanvas canvas(fBitmap); | |
| 33 canvas.clear(0x00000000); | |
| 34 SkPaint paint; | |
| 35 paint.setAntiAlias(true); | |
| 36 sk_tool_utils::set_portable_typeface(&paint); | |
| 37 paint.setColor(0xFFFFFFFF); | |
| 38 paint.setTextSize(SkIntToScalar(96)); | |
| 39 const char* str = "e"; | |
| 40 canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); | |
| 41 } | |
| 42 | |
| 43 SkISize onISize() override { | 30 SkISize onISize() override { |
| 44 return SkISize::Make(WIDTH, HEIGHT); | 31 return SkISize::Make(WIDTH, HEIGHT); |
| 45 } | 32 } |
| 46 | 33 |
| 47 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y)
{ | 34 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y)
{ |
| 48 canvas->save(); | 35 canvas->save(); |
| 49 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 36 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 50 canvas->clipRect(SkRect::MakeWH( | 37 canvas->clipRect(SkRect::MakeWH( |
| 51 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); | 38 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); |
| 52 canvas->drawBitmap(fBitmap, 0, 0, &paint); | 39 canvas->drawBitmap(fBitmap, 0, 0, &paint); |
| 53 canvas->restore(); | 40 canvas->restore(); |
| 54 } | 41 } |
| 55 | 42 |
| 43 void onOnceBeforeDraw() override { |
| 44 fBitmap = sk_tool_utils::create_string_bitmap(100, 100, 0xFFFFFFFF, 20,
70, 96, "e"); |
| 45 } |
| 46 |
| 56 void onDraw(SkCanvas* canvas) override { | 47 void onDraw(SkCanvas* canvas) override { |
| 57 if (!fInitialized) { | |
| 58 make_bitmap(); | |
| 59 fInitialized = true; | |
| 60 } | |
| 61 canvas->clear(sk_tool_utils::color_to_565(0xFF101010)); | 48 canvas->clear(sk_tool_utils::color_to_565(0xFF101010)); |
| 62 SkPaint checkPaint; | 49 SkPaint checkPaint; |
| 63 checkPaint.setColor(sk_tool_utils::color_to_565(0xFF202020)); | 50 checkPaint.setColor(sk_tool_utils::color_to_565(0xFF202020)); |
| 64 for (int y = 0; y < HEIGHT; y += 16) { | 51 for (int y = 0; y < HEIGHT; y += 16) { |
| 65 for (int x = 0; x < WIDTH; x += 16) { | 52 for (int x = 0; x < WIDTH; x += 16) { |
| 66 canvas->save(); | 53 canvas->save(); |
| 67 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 54 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 68 canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), checkPaint); | 55 canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), checkPaint); |
| 69 canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), checkPaint); | 56 canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), checkPaint); |
| 70 canvas->restore(); | 57 canvas->restore(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 sh
ininess, | 143 sh
ininess, |
| 157 in
put, | 144 in
put, |
| 158 cr
))->unref(); | 145 cr
))->unref(); |
| 159 drawClippedBitmap(canvas, paint, 220, y); | 146 drawClippedBitmap(canvas, paint, 220, y); |
| 160 | 147 |
| 161 y += 110; | 148 y += 110; |
| 162 } | 149 } |
| 163 } | 150 } |
| 164 | 151 |
| 165 private: | 152 private: |
| 153 SkBitmap fBitmap; |
| 154 |
| 166 typedef GM INHERITED; | 155 typedef GM INHERITED; |
| 167 SkBitmap fBitmap; | |
| 168 bool fInitialized; | |
| 169 }; | 156 }; |
| 170 | 157 |
| 171 ////////////////////////////////////////////////////////////////////////////// | 158 ////////////////////////////////////////////////////////////////////////////// |
| 172 | 159 |
| 173 DEF_GM(return new ImageLightingGM;) | 160 DEF_GM(return new ImageLightingGM;) |
| 174 } | 161 } |
| OLD | NEW |