OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 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 "SkImageFilter.h" |
| 10 #include "SkColorMatrixFilter.h" |
| 11 |
| 12 /** |
| 13 * Test drawing a primitive w/ an imagefilter (in this case, just matrix w/ ide
ntity) to see |
| 14 * that we apply the xfermode *after* the image has been created and filtered,
and not during |
| 15 * the creation step (i.e. before it is filtered). |
| 16 * |
| 17 * see skbug.com/3741 |
| 18 */ |
| 19 class ImageFilterXfermodeTestGM : public skiagm::GM { |
| 20 protected: |
| 21 SkString onShortName() override { |
| 22 return SkString("imagefilters_xfermodes"); |
| 23 } |
| 24 |
| 25 SkISize onISize() override { return SkISize::Make(480, 480); } |
| 26 |
| 27 void doDraw(SkCanvas* canvas, SkXfermode::Mode mode, SkImageFilter* imf) { |
| 28 SkPaint paint; |
| 29 paint.setAntiAlias(true); |
| 30 |
| 31 SkRect r0 = SkRect::MakeXYWH(10, 60, 200, 100); |
| 32 SkRect r1 = SkRect::MakeXYWH(60, 10, 100, 200); |
| 33 |
| 34 paint.setColor(SK_ColorRED); |
| 35 canvas->drawOval(r0, paint); |
| 36 |
| 37 paint.setColor(0x800000FF); |
| 38 paint.setImageFilter(imf); |
| 39 paint.setXfermodeMode(mode); |
| 40 canvas->drawOval(r1, paint); |
| 41 } |
| 42 |
| 43 void onDraw(SkCanvas* canvas) override { |
| 44 // just need an imagefilter to trigger the code-path (which creates a tm
p layer) |
| 45 SkAutoTUnref<SkImageFilter> imf(SkImageFilter::CreateMatrixFilter(SkMatr
ix::I(), |
| 46 kNone_
SkFilterQuality)); |
| 47 |
| 48 const SkXfermode::Mode modes[] = { |
| 49 SkXfermode::kSrcATop_Mode, SkXfermode::kDstIn_Mode |
| 50 }; |
| 51 |
| 52 for (size_t i = 0; i < SK_ARRAY_COUNT(modes); ++i) { |
| 53 canvas->save(); |
| 54 this->doDraw(canvas, modes[i], NULL); |
| 55 canvas->translate(250, 0); |
| 56 this->doDraw(canvas, modes[i], imf); |
| 57 canvas->restore(); |
| 58 |
| 59 canvas->translate(0, 250); |
| 60 } |
| 61 } |
| 62 |
| 63 private: |
| 64 typedef GM INHERITED; |
| 65 }; |
| 66 DEF_GM( return new ImageFilterXfermodeTestGM; ) |
| 67 |
OLD | NEW |