| 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 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 23 uint32_t onGetFlags() const SK_OVERRIDE { |
| 24 return kSkipTiled_Flag; | 24 return kSkipTiled_Flag; |
| 25 } | 25 } |
| 26 | 26 |
| 27 virtual SkString onShortName() SK_OVERRIDE { | 27 SkString onShortName() SK_OVERRIDE { |
| 28 return SkString("lighting"); | 28 return SkString("lighting"); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void make_bitmap() { | 31 void make_bitmap() { |
| 32 fBitmap.allocN32Pixels(100, 100); | 32 fBitmap.allocN32Pixels(100, 100); |
| 33 SkCanvas canvas(fBitmap); | 33 SkCanvas canvas(fBitmap); |
| 34 canvas.clear(0x00000000); | 34 canvas.clear(0x00000000); |
| 35 SkPaint paint; | 35 SkPaint paint; |
| 36 paint.setAntiAlias(true); | 36 paint.setAntiAlias(true); |
| 37 sk_tool_utils::set_portable_typeface(&paint); | 37 sk_tool_utils::set_portable_typeface(&paint); |
| 38 paint.setColor(0xFFFFFFFF); | 38 paint.setColor(0xFFFFFFFF); |
| 39 paint.setTextSize(SkIntToScalar(96)); | 39 paint.setTextSize(SkIntToScalar(96)); |
| 40 const char* str = "e"; | 40 const char* str = "e"; |
| 41 canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); | 41 canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); |
| 42 } | 42 } |
| 43 | 43 |
| 44 virtual SkISize onISize() SK_OVERRIDE { | 44 SkISize onISize() SK_OVERRIDE { |
| 45 return SkISize::Make(WIDTH, HEIGHT); | 45 return SkISize::Make(WIDTH, HEIGHT); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y)
{ | 48 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y)
{ |
| 49 canvas->save(); | 49 canvas->save(); |
| 50 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 50 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 51 canvas->clipRect(SkRect::MakeWH( | 51 canvas->clipRect(SkRect::MakeWH( |
| 52 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); | 52 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); |
| 53 canvas->drawBitmap(fBitmap, 0, 0, &paint); | 53 canvas->drawBitmap(fBitmap, 0, 0, &paint); |
| 54 canvas->restore(); | 54 canvas->restore(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 57 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 58 if (!fInitialized) { | 58 if (!fInitialized) { |
| 59 make_bitmap(); | 59 make_bitmap(); |
| 60 fInitialized = true; | 60 fInitialized = true; |
| 61 } | 61 } |
| 62 canvas->clear(0xFF101010); | 62 canvas->clear(0xFF101010); |
| 63 SkPaint checkPaint; | 63 SkPaint checkPaint; |
| 64 checkPaint.setColor(0xFF202020); | 64 checkPaint.setColor(0xFF202020); |
| 65 for (int y = 0; y < HEIGHT; y += 16) { | 65 for (int y = 0; y < HEIGHT; y += 16) { |
| 66 for (int x = 0; x < WIDTH; x += 16) { | 66 for (int x = 0; x < WIDTH; x += 16) { |
| 67 canvas->save(); | 67 canvas->save(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 SkBitmap fBitmap; | 122 SkBitmap fBitmap; |
| 123 bool fInitialized; | 123 bool fInitialized; |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 ////////////////////////////////////////////////////////////////////////////// | 126 ////////////////////////////////////////////////////////////////////////////// |
| 127 | 127 |
| 128 static GM* MyFactory(void*) { return new ImageLightingGM; } | 128 static GM* MyFactory(void*) { return new ImageLightingGM; } |
| 129 static GMRegistry reg(MyFactory); | 129 static GMRegistry reg(MyFactory); |
| 130 | 130 |
| 131 } | 131 } |
| OLD | NEW |