OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 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 "SkLumaXfermode.h" |
| 11 |
| 12 static void show_scene(SkCanvas* canvas, SkXfermode* mode, const char* label) { |
| 13 SkPaint paint; |
| 14 paint.setAntiAlias(true); |
| 15 SkRect r, c, bounds = { 10, 10, 110, 110 }; |
| 16 |
| 17 c = bounds; |
| 18 c.fRight = bounds.centerX(); |
| 19 r = bounds; |
| 20 r.fBottom = bounds.centerY(); |
| 21 canvas->drawRect(r, paint); |
| 22 |
| 23 SkScalar tw = paint.measureText(label, strlen(label)); |
| 24 canvas->drawText(label, strlen(label), bounds.centerX() - tw / 2, |
| 25 bounds.bottom() + 15, paint); |
| 26 |
| 27 canvas->saveLayer(&bounds, NULL); |
| 28 |
| 29 r = bounds; |
| 30 r.inset(20, 0); |
| 31 paint.setColor(0x80FFFF00); |
| 32 canvas->drawOval(r, paint); |
| 33 canvas->save(); |
| 34 canvas->clipRect(c); |
| 35 paint.setColor(0xFFFFFF00); |
| 36 canvas->drawOval(r, paint); |
| 37 canvas->restore(); |
| 38 |
| 39 SkPaint xferPaint; |
| 40 xferPaint.setXfermode(mode); |
| 41 canvas->saveLayer(&bounds, &xferPaint); |
| 42 |
| 43 r = bounds; |
| 44 r.inset(0, 20); |
| 45 paint.setColor(0x8080FF00); |
| 46 canvas->drawOval(r, paint); |
| 47 canvas->save(); |
| 48 canvas->clipRect(c); |
| 49 paint.setColor(0xFF80FF00); |
| 50 canvas->drawOval(r, paint); |
| 51 canvas->restore(); |
| 52 |
| 53 canvas->restore(); |
| 54 canvas->restore(); |
| 55 } |
| 56 |
| 57 class LumaXfermodeGM : public skiagm::GM { |
| 58 public: |
| 59 LumaXfermodeGM() {} |
| 60 |
| 61 protected: |
| 62 virtual SkString onShortName() SK_OVERRIDE { |
| 63 return SkString("lumamode"); |
| 64 } |
| 65 |
| 66 virtual SkISize onISize() SK_OVERRIDE { |
| 67 return SkISize::Make(450, 140); |
| 68 } |
| 69 |
| 70 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 71 show_scene(canvas, NULL, "SrcOver"); |
| 72 canvas->translate(150, 0); |
| 73 SkAutoTUnref<SkXfermode> src_in(SkLumaMaskXfermode::Create(SkXfermode::k
SrcIn_Mode)); |
| 74 show_scene(canvas, src_in.get(), "SrcInLuma"); |
| 75 canvas->translate(150, 0); |
| 76 SkAutoTUnref<SkXfermode> dst_in(SkLumaMaskXfermode::Create(SkXfermode::k
DstIn_Mode)); |
| 77 show_scene(canvas, dst_in.get(), "DstInLuma"); |
| 78 } |
| 79 |
| 80 private: |
| 81 typedef skiagm::GM INHERITED; |
| 82 }; |
| 83 |
| 84 ////////////////////////////////////////////////////////////////////////////// |
| 85 |
| 86 DEF_GM( return SkNEW(LumaXfermodeGM); ) |
OLD | NEW |