tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
| 11 | #include "SkPath.h" |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 12 | #include "SkMakeUnique.h" |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 13 | |
reed | 02f9ed7 | 2016-09-06 09:06:18 -0700 | [diff] [blame] | 14 | static void do_draw(SkCanvas* canvas, const SkRect& r) { |
| 15 | SkPaint paint; |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 16 | paint.setBlendMode(SkBlendMode::kSrc); |
reed | 02f9ed7 | 2016-09-06 09:06:18 -0700 | [diff] [blame] | 17 | paint.setColor(0x800000FF); |
| 18 | canvas->drawRect(r, paint); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Exercise kDontClipToLayer_Legacy_SaveLayerFlag flag, which does not limit the clip to the |
| 23 | * layer's bounds. Thus when a draw occurs, it can (depending on "where" it is) draw into the layer |
| 24 | * and/or draw onto the surrounding portions of the canvas, or both. |
| 25 | * |
| 26 | * This GM has a 100x100 rectangle (r), which its going to draw. However first it creates a layer |
| 27 | * with this flag covering 1/2 of the rectangle (upper half). Then it draws the rect in SRC mode. |
| 28 | * |
| 29 | * The portion of the draw that intersects the layer should see the SRC draw, apply it to the layer |
| 30 | * and then during restore, it will SRC_OVER that layer onto the canvas (SRC_OVER since the layer |
| 31 | * has no paint, so it gets the default xfermode during restore). |
| 32 | * |
reed | 28d1ce5 | 2016-09-06 14:57:00 -0700 | [diff] [blame] | 33 | * Note: when we talk about drawing directly into the "canvas", in fact we are drawing into an |
| 34 | * "outer" layer we created (filled with red). This is a testing detail, so that our final |
| 35 | * output image is itself opaque, otherwise we make it harder to view the GM as a PNG. |
reed | 02f9ed7 | 2016-09-06 09:06:18 -0700 | [diff] [blame] | 36 | * |
reed | 28d1ce5 | 2016-09-06 14:57:00 -0700 | [diff] [blame] | 37 | * The portion of the draw below the layer draws directly into the canvas. Since it is in SRC mode, |
| 38 | * it will write 0x80 to the canvas' alpha, overwriting the "red", which then gets blended with |
| 39 | * the GM's white background. |
| 40 | * |
| 41 | * The portion in the layer, will end up SRC_OVERing the 0x80 layer pixels onto the canvas' red |
| 42 | * pixels, making magenta. |
| 43 | * |
| 44 | * Thus the expected result is the upper half to be magenta 0xFF7F0080, and the lower half to be |
| 45 | * light blue 0xFF7F7FFF. |
reed | 02f9ed7 | 2016-09-06 09:06:18 -0700 | [diff] [blame] | 46 | */ |
| 47 | DEF_SIMPLE_GM(dont_clip_to_layer, canvas, 120, 120) { |
reed | 28d1ce5 | 2016-09-06 14:57:00 -0700 | [diff] [blame] | 48 | const SkRect r { 10, 10, 110, 110 }; |
| 49 | |
| 50 | // Wrap the entire test inside a red layer, so we don't punch the actual gm's alpha with |
| 51 | // kSrc_Mode, which makes it hard to view (we like our GMs to have opaque pixels). |
| 52 | canvas->saveLayer(&r, nullptr); |
| 53 | canvas->drawColor(SK_ColorRED); |
| 54 | |
Mike Reed | 8a8937c | 2017-02-14 10:12:34 -0500 | [diff] [blame] | 55 | SkRect r0 = { 20, 20, 100, 55 }; |
| 56 | SkRect r1 = { 20, 65, 100, 100 }; |
reed | 02f9ed7 | 2016-09-06 09:06:18 -0700 | [diff] [blame] | 57 | |
| 58 | SkCanvas::SaveLayerRec rec; |
| 59 | rec.fPaint = nullptr; |
| 60 | rec.fBounds = &r0; |
| 61 | rec.fBackdrop = nullptr; |
| 62 | rec.fSaveLayerFlags = 1 << 31;//SkCanvas::kDontClipToLayer_Legacy_SaveLayerFlag; |
| 63 | canvas->saveLayer(rec); |
Mike Reed | 8a8937c | 2017-02-14 10:12:34 -0500 | [diff] [blame] | 64 | rec.fBounds = &r1; |
| 65 | canvas->saveLayer(rec); |
reed | 02f9ed7 | 2016-09-06 09:06:18 -0700 | [diff] [blame] | 66 | do_draw(canvas, r); |
| 67 | canvas->restore(); |
reed | 28d1ce5 | 2016-09-06 14:57:00 -0700 | [diff] [blame] | 68 | |
| 69 | canvas->restore(); // red-layer |
reed | 02f9ed7 | 2016-09-06 09:06:18 -0700 | [diff] [blame] | 70 | } |
| 71 | |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 72 | /** Draw a 2px border around the target, then red behind the target; |
| 73 | set the clip to match the target, then draw >> the target in blue. |
| 74 | */ |
| 75 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 76 | static void draw(SkCanvas* canvas, SkRect& target, int x, int y) { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 77 | SkPaint borderPaint; |
| 78 | borderPaint.setColor(SkColorSetRGB(0x0, 0xDD, 0x0)); |
| 79 | borderPaint.setAntiAlias(true); |
| 80 | SkPaint backgroundPaint; |
| 81 | backgroundPaint.setColor(SkColorSetRGB(0xDD, 0x0, 0x0)); |
| 82 | backgroundPaint.setAntiAlias(true); |
| 83 | SkPaint foregroundPaint; |
| 84 | foregroundPaint.setColor(SkColorSetRGB(0x0, 0x0, 0xDD)); |
| 85 | foregroundPaint.setAntiAlias(true); |
| 86 | |
| 87 | canvas->save(); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 88 | canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 89 | target.inset(SkIntToScalar(-2), SkIntToScalar(-2)); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 90 | canvas->drawRect(target, borderPaint); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 91 | target.inset(SkIntToScalar(2), SkIntToScalar(2)); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 92 | canvas->drawRect(target, backgroundPaint); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 93 | canvas->clipRect(target, true); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 94 | target.inset(SkIntToScalar(-4), SkIntToScalar(-4)); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 95 | canvas->drawRect(target, foregroundPaint); |
| 96 | canvas->restore(); |
| 97 | } |
| 98 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 99 | static void draw_square(SkCanvas* canvas, int x, int y) { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 100 | SkRect target (SkRect::MakeWH(10 * SK_Scalar1, 10 * SK_Scalar1)); |
| 101 | draw(canvas, target, x, y); |
| 102 | } |
| 103 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 104 | static void draw_column(SkCanvas* canvas, int x, int y) { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 105 | SkRect target (SkRect::MakeWH(1 * SK_Scalar1, 10 * SK_Scalar1)); |
| 106 | draw(canvas, target, x, y); |
| 107 | } |
| 108 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 109 | static void draw_bar(SkCanvas* canvas, int x, int y) { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 110 | SkRect target (SkRect::MakeWH(10 * SK_Scalar1, 1 * SK_Scalar1)); |
| 111 | draw(canvas, target, x, y); |
| 112 | } |
| 113 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 114 | static void draw_rect_tests(SkCanvas* canvas) { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 115 | draw_square(canvas, 10, 10); |
| 116 | draw_column(canvas, 30, 10); |
| 117 | draw_bar(canvas, 10, 30); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | Test a set of clipping problems discovered while writing blitAntiRect, |
| 122 | and test all the code paths through the clipping blitters. |
| 123 | Each region should show as a blue center surrounded by a 2px green |
| 124 | border, with no red. |
| 125 | */ |
| 126 | |
reed@google.com | ff26b7e | 2013-05-23 17:04:19 +0000 | [diff] [blame] | 127 | class AAClipGM : public skiagm::GM { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 128 | public: |
| 129 | AAClipGM() { |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 130 | |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 134 | SkString onShortName() override { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 135 | return SkString("aaclip"); |
| 136 | } |
| 137 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 138 | SkISize onISize() override { |
commit-bot@chromium.org | 5d0b150 | 2014-04-14 15:02:19 +0000 | [diff] [blame] | 139 | return SkISize::Make(240, 120); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 140 | } |
| 141 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 142 | void onDraw(SkCanvas* canvas) override { |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 143 | // Initial pixel-boundary-aligned draw |
| 144 | draw_rect_tests(canvas); |
| 145 | |
| 146 | // Repeat 4x with .2, .4, .6, .8 px offsets |
| 147 | canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 148 | canvas->translate(SkIntToScalar(50), 0); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 149 | draw_rect_tests(canvas); |
| 150 | |
| 151 | canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 152 | canvas->translate(SkIntToScalar(50), 0); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 153 | draw_rect_tests(canvas); |
| 154 | |
| 155 | canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 156 | canvas->translate(SkIntToScalar(50), 0); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 157 | draw_rect_tests(canvas); |
| 158 | |
| 159 | canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); |
tomhudson@google.com | abfa8d1 | 2011-12-28 19:40:48 +0000 | [diff] [blame] | 160 | canvas->translate(SkIntToScalar(50), 0); |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 161 | draw_rect_tests(canvas); |
| 162 | } |
| 163 | |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 164 | private: |
reed@google.com | ff26b7e | 2013-05-23 17:04:19 +0000 | [diff] [blame] | 165 | typedef skiagm::GM INHERITED; |
tomhudson@google.com | ef279d3 | 2011-12-21 14:27:14 +0000 | [diff] [blame] | 166 | }; |
| 167 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 168 | DEF_GM(return new AAClipGM;) |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 169 | |
| 170 | ///////////////////////////////////////////////////////////////////////// |
| 171 | |
| 172 | #ifdef SK_BUILD_FOR_MAC |
| 173 | |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 174 | static std::unique_ptr<SkCanvas> make_canvas(const SkBitmap& bm) { |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 175 | const SkImageInfo& info = bm.info(); |
| 176 | if (info.bytesPerPixel() == 4) { |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 177 | return SkCanvas::MakeRasterDirectN32(info.width(), info.height(), |
| 178 | (SkPMColor*)bm.getPixels(), |
| 179 | bm.rowBytes()); |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 180 | } else { |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 181 | return skstd::make_unique<SkCanvas>(bm); |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
| 185 | #include "SkCGUtils.h" |
| 186 | static void test_image(SkCanvas* canvas, const SkImageInfo& info) { |
| 187 | SkBitmap bm; |
| 188 | bm.allocPixels(info); |
| 189 | |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 190 | if (info.isOpaque()) { |
| 191 | bm.eraseColor(SK_ColorGREEN); |
| 192 | } else { |
| 193 | bm.eraseColor(0); |
| 194 | } |
skia.committer@gmail.com | ede0c5c | 2014-04-23 03:04:11 +0000 | [diff] [blame] | 195 | |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 196 | SkPaint paint; |
| 197 | paint.setAntiAlias(true); |
| 198 | paint.setColor(SK_ColorBLUE); |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 199 | make_canvas(bm)->drawCircle(50, 50, 49, paint); |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 200 | canvas->drawBitmap(bm, 10, 10); |
skia.committer@gmail.com | ede0c5c | 2014-04-23 03:04:11 +0000 | [diff] [blame] | 201 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 202 | CGImageRef image = SkCreateCGImageRefWithColorspace(bm, nullptr); |
skia.committer@gmail.com | ede0c5c | 2014-04-23 03:04:11 +0000 | [diff] [blame] | 203 | |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 204 | SkBitmap bm2; |
| 205 | SkCreateBitmapFromCGImage(&bm2, image); |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 206 | canvas->drawBitmap(bm2, 10, 120); |
Mike Reed | 463c848 | 2016-12-21 12:01:12 -0500 | [diff] [blame] | 207 | canvas->drawImage(SkMakeImageFromCGImage(image), 10, 120 + bm2.height() + 10); |
| 208 | |
| 209 | CGImageRelease(image); |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | class CGImageGM : public skiagm::GM { |
| 213 | public: |
| 214 | CGImageGM() {} |
skia.committer@gmail.com | ede0c5c | 2014-04-23 03:04:11 +0000 | [diff] [blame] | 215 | |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 216 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 217 | SkString onShortName() override { |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 218 | return SkString("cgimage"); |
| 219 | } |
skia.committer@gmail.com | ede0c5c | 2014-04-23 03:04:11 +0000 | [diff] [blame] | 220 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 221 | SkISize onISize() override { |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 222 | return SkISize::Make(800, 250); |
| 223 | } |
skia.committer@gmail.com | ede0c5c | 2014-04-23 03:04:11 +0000 | [diff] [blame] | 224 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 225 | void onDraw(SkCanvas* canvas) override { |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 226 | const struct { |
| 227 | SkColorType fCT; |
| 228 | SkAlphaType fAT; |
| 229 | } rec[] = { |
| 230 | { kRGB_565_SkColorType, kOpaque_SkAlphaType }, |
| 231 | |
| 232 | { kRGBA_8888_SkColorType, kPremul_SkAlphaType }, |
| 233 | { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType }, |
| 234 | { kRGBA_8888_SkColorType, kOpaque_SkAlphaType }, |
| 235 | |
| 236 | { kBGRA_8888_SkColorType, kPremul_SkAlphaType }, |
| 237 | { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType }, |
| 238 | { kBGRA_8888_SkColorType, kOpaque_SkAlphaType }, |
| 239 | }; |
skia.committer@gmail.com | ede0c5c | 2014-04-23 03:04:11 +0000 | [diff] [blame] | 240 | |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 241 | for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { |
| 242 | SkImageInfo info = SkImageInfo::Make(100, 100, rec[i].fCT, rec[i].fAT); |
| 243 | test_image(canvas, info); |
| 244 | canvas->translate(info.width() + 10, 0); |
| 245 | } |
| 246 | } |
skia.committer@gmail.com | ede0c5c | 2014-04-23 03:04:11 +0000 | [diff] [blame] | 247 | |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 248 | private: |
| 249 | typedef skiagm::GM INHERITED; |
| 250 | }; |
Mike Reed | 463c848 | 2016-12-21 12:01:12 -0500 | [diff] [blame] | 251 | //DEF_GM( return new CGImageGM; ) |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 252 | #endif |
reed | 8f76cb9 | 2015-04-22 17:38:23 -0700 | [diff] [blame] | 253 | |
| 254 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 255 | |
halcanary | 6950de6 | 2015-11-07 05:29:00 -0800 | [diff] [blame] | 256 | // https://bug.skia.org/3716 |
reed | 8f76cb9 | 2015-04-22 17:38:23 -0700 | [diff] [blame] | 257 | class ClipCubicGM : public skiagm::GM { |
| 258 | const SkScalar W = 100; |
| 259 | const SkScalar H = 240; |
| 260 | |
| 261 | SkPath fVPath, fHPath; |
| 262 | public: |
| 263 | ClipCubicGM() { |
| 264 | fVPath.moveTo(W, 0); |
| 265 | fVPath.cubicTo(W, H-10, 0, 10, 0, H); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 266 | |
reed | 8f76cb9 | 2015-04-22 17:38:23 -0700 | [diff] [blame] | 267 | SkMatrix pivot; |
| 268 | pivot.setRotate(90, W/2, H/2); |
| 269 | fVPath.transform(pivot, &fHPath); |
| 270 | } |
| 271 | |
| 272 | protected: |
| 273 | SkString onShortName() override { |
| 274 | return SkString("clipcubic"); |
| 275 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 276 | |
reed | 8f76cb9 | 2015-04-22 17:38:23 -0700 | [diff] [blame] | 277 | SkISize onISize() override { |
| 278 | return SkISize::Make(400, 410); |
| 279 | } |
| 280 | |
| 281 | void doDraw(SkCanvas* canvas, const SkPath& path) { |
| 282 | SkPaint paint; |
| 283 | paint.setAntiAlias(true); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 284 | |
caryclark | 1259601 | 2015-07-29 05:27:47 -0700 | [diff] [blame] | 285 | paint.setColor(sk_tool_utils::color_to_565(0xFFCCCCCC)); |
reed | 8f76cb9 | 2015-04-22 17:38:23 -0700 | [diff] [blame] | 286 | canvas->drawPath(path, paint); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 287 | |
reed | 8f76cb9 | 2015-04-22 17:38:23 -0700 | [diff] [blame] | 288 | paint.setColor(SK_ColorRED); |
| 289 | paint.setStyle(SkPaint::kStroke_Style); |
| 290 | canvas->drawPath(path, paint); |
| 291 | } |
| 292 | |
| 293 | void drawAndClip(SkCanvas* canvas, const SkPath& path, SkScalar dx, SkScalar dy) { |
| 294 | SkAutoCanvasRestore acr(canvas, true); |
| 295 | |
| 296 | SkRect r = SkRect::MakeXYWH(0, H/4, W, H/2); |
| 297 | SkPaint paint; |
caryclark | 1259601 | 2015-07-29 05:27:47 -0700 | [diff] [blame] | 298 | paint.setColor(sk_tool_utils::color_to_565(0xFF8888FF)); |
reed | 8f76cb9 | 2015-04-22 17:38:23 -0700 | [diff] [blame] | 299 | |
| 300 | canvas->drawRect(r, paint); |
| 301 | this->doDraw(canvas, path); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 302 | |
reed | 8f76cb9 | 2015-04-22 17:38:23 -0700 | [diff] [blame] | 303 | canvas->translate(dx, dy); |
| 304 | |
| 305 | canvas->drawRect(r, paint); |
| 306 | canvas->clipRect(r); |
| 307 | this->doDraw(canvas, path); |
| 308 | } |
| 309 | |
| 310 | void onDraw(SkCanvas* canvas) override { |
| 311 | canvas->translate(80, 10); |
| 312 | this->drawAndClip(canvas, fVPath, 200, 0); |
| 313 | canvas->translate(0, 200); |
| 314 | this->drawAndClip(canvas, fHPath, 200, 0); |
| 315 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 316 | |
reed | 8f76cb9 | 2015-04-22 17:38:23 -0700 | [diff] [blame] | 317 | private: |
| 318 | typedef skiagm::GM INHERITED; |
| 319 | }; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 320 | DEF_GM(return new ClipCubicGM;) |