Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2014 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "gm.h" | |
| 9 #include "SkCanvas.h" | |
| 10 #include "SkColorFilter.h" | |
| 11 #include "SkGradientShader.h" | |
| 12 | |
| 13 static SkShader* make_shader(const SkRect& bounds) { | |
| 14 const SkPoint pts[] = { | |
| 15 { bounds.left(), bounds.top() }, | |
| 16 { bounds.right(), bounds.bottom() }, | |
| 17 }; | |
| 18 const SkColor colors[] = { | |
| 19 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorBLACK, | |
| 20 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, | |
| 21 }; | |
| 22 return SkGradientShader::CreateLinear(pts, | |
| 23 colors, NULL, SK_ARRAY_COUNT(colors), | |
| 24 SkShader::kClamp_TileMode); | |
| 25 } | |
| 26 | |
| 27 typedef void (*InstallPaint)(SkPaint*, uint32_t, uint32_t); | |
| 28 | |
| 29 static void install_nothing(SkPaint* paint, uint32_t, uint32_t) { | |
| 30 paint->setColorFilter(NULL); | |
| 31 } | |
| 32 | |
| 33 static void install_lighting(SkPaint* paint, uint32_t mul, uint32_t add) { | |
| 34 paint->setColorFilter(SkColorFilter::CreateLightingFilter(mul, add))->unref( ); | |
| 35 } | |
| 36 | |
| 37 class ColorFiltersGM : public skiagm::GM { | |
| 38 public: | |
| 39 ColorFiltersGM() { | |
| 40 fName.set("lightingcolorfilter"); | |
|
tfarina
2014/02/06 16:31:33
is this equivalent to:
ColorFiltersGM() : fName("
| |
| 41 } | |
| 42 | |
| 43 protected: | |
| 44 virtual SkString onShortName() { | |
| 45 return fName; | |
| 46 } | |
| 47 | |
| 48 virtual SkISize onISize() { | |
| 49 return SkISize::Make(640, 480); | |
| 50 } | |
| 51 | |
| 52 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | |
| 53 SkPaint paint; | |
| 54 SkRect r; | |
| 55 r.setWH(600, 50); | |
| 56 paint.setShader(make_shader(r))->unref(); | |
| 57 | |
| 58 const struct { | |
| 59 InstallPaint fProc; | |
| 60 uint32_t fData0, fData1; | |
| 61 } rec[] = { | |
| 62 { install_nothing, 0, 0 }, | |
| 63 { install_lighting, 0xFF0000, 0 }, | |
| 64 { install_lighting, 0x00FF00, 0 }, | |
| 65 { install_lighting, 0x0000FF, 0 }, | |
| 66 { install_lighting, 0x000000, 0xFF0000 }, | |
| 67 { install_lighting, 0x000000, 0x00FF00 }, | |
| 68 { install_lighting, 0x000000, 0x0000FF }, | |
| 69 }; | |
| 70 | |
| 71 canvas->translate(10, 10); | |
| 72 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { | |
| 73 rec[i].fProc(&paint, rec[i].fData0, rec[i].fData1); | |
| 74 canvas->drawRect(r, paint); | |
| 75 canvas->translate(0, r.height() + 10); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 private: | |
| 80 SkString fName; | |
| 81 typedef GM INHERITED; | |
| 82 }; | |
| 83 | |
| 84 | |
| 85 ////////////////////////////////////////////////////////////////////////////// | |
| 86 | |
| 87 DEF_GM( return SkNEW(ColorFiltersGM); ) | |
| 88 | |
| OLD | NEW |