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