commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "include/core/SkBitmap.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkCanvas.h" |
| 11 | #include "include/core/SkClipOp.h" |
| 12 | #include "include/core/SkColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkFont.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 14 | #include "include/core/SkFontTypes.h" |
| 15 | #include "include/core/SkMatrix.h" |
| 16 | #include "include/core/SkPaint.h" |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 17 | #include "include/core/SkPathBuilder.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 18 | #include "include/core/SkPoint.h" |
| 19 | #include "include/core/SkRect.h" |
| 20 | #include "include/core/SkScalar.h" |
| 21 | #include "include/core/SkShader.h" |
| 22 | #include "include/core/SkSize.h" |
| 23 | #include "include/core/SkString.h" |
| 24 | #include "include/core/SkTileMode.h" |
| 25 | #include "include/core/SkTypeface.h" |
| 26 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "include/effects/SkGradientShader.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 28 | #include "tools/ToolUtils.h" |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 29 | |
Mike Reed | 607a382 | 2021-01-24 19:49:21 -0500 | [diff] [blame] | 30 | static sk_sp<SkImage> make_img(int w, int h) { |
| 31 | auto surf = SkSurface::MakeRaster(SkImageInfo::MakeN32(w, h, kOpaque_SkAlphaType)); |
| 32 | auto canvas = surf->getCanvas(); |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 33 | |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 34 | SkScalar wScalar = SkIntToScalar(w); |
| 35 | SkScalar hScalar = SkIntToScalar(h); |
| 36 | |
| 37 | SkPoint pt = { wScalar / 2, hScalar / 2 }; |
| 38 | |
Brian Osman | 116b33e | 2020-02-05 13:34:09 -0500 | [diff] [blame] | 39 | SkScalar radius = 3 * std::max(wScalar, hScalar); |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 40 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 41 | SkColor colors[] = {SK_ColorDKGRAY, |
| 42 | ToolUtils::color_to_565(0xFF222255), |
| 43 | ToolUtils::color_to_565(0xFF331133), |
| 44 | ToolUtils::color_to_565(0xFF884422), |
| 45 | ToolUtils::color_to_565(0xFF000022), |
| 46 | SK_ColorWHITE, |
| 47 | ToolUtils::color_to_565(0xFFAABBCC)}; |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 48 | |
| 49 | SkScalar pos[] = {0, |
| 50 | SK_Scalar1 / 6, |
| 51 | 2 * SK_Scalar1 / 6, |
| 52 | 3 * SK_Scalar1 / 6, |
| 53 | 4 * SK_Scalar1 / 6, |
| 54 | 5 * SK_Scalar1 / 6, |
| 55 | SK_Scalar1}; |
| 56 | |
| 57 | SkPaint paint; |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 58 | SkRect rect = SkRect::MakeWH(wScalar, hScalar); |
| 59 | SkMatrix mat = SkMatrix::I(); |
| 60 | for (int i = 0; i < 4; ++i) { |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 61 | paint.setShader(SkGradientShader::MakeRadial( |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 62 | pt, radius, |
| 63 | colors, pos, |
| 64 | SK_ARRAY_COUNT(colors), |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 65 | SkTileMode::kRepeat, |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 66 | 0, &mat)); |
Mike Reed | 607a382 | 2021-01-24 19:49:21 -0500 | [diff] [blame] | 67 | canvas->drawRect(rect, paint); |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 68 | rect.inset(wScalar / 8, hScalar / 8); |
| 69 | mat.preTranslate(6 * wScalar, 6 * hScalar); |
| 70 | mat.postScale(SK_Scalar1 / 3, SK_Scalar1 / 3); |
| 71 | } |
| 72 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 73 | SkFont font(ToolUtils::create_portable_typeface(), wScalar / 2.2f); |
Mike Reed | 4de2f1f | 2019-01-05 16:35:13 -0500 | [diff] [blame] | 74 | |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 75 | paint.setShader(nullptr); |
Mike Klein | d46dce3 | 2018-08-16 10:17:03 -0400 | [diff] [blame] | 76 | paint.setColor(SK_ColorLTGRAY); |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 77 | constexpr char kTxt[] = "Skia"; |
Mike Reed | 4de2f1f | 2019-01-05 16:35:13 -0500 | [diff] [blame] | 78 | SkPoint texPos = { wScalar / 17, hScalar / 2 + font.getSize() / 2.5f }; |
Mike Reed | 607a382 | 2021-01-24 19:49:21 -0500 | [diff] [blame] | 79 | canvas->drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8, |
| 80 | texPos.fX, texPos.fY, font, paint); |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 81 | paint.setColor(SK_ColorBLACK); |
| 82 | paint.setStyle(SkPaint::kStroke_Style); |
| 83 | paint.setStrokeWidth(SK_Scalar1); |
Mike Reed | 607a382 | 2021-01-24 19:49:21 -0500 | [diff] [blame] | 84 | canvas->drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8, |
| 85 | texPos.fX, texPos.fY, font, paint); |
| 86 | return surf->makeImageSnapshot(); |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | namespace skiagm { |
| 90 | /** |
| 91 | * This GM tests convex polygon clips. |
| 92 | */ |
| 93 | class ConvexPolyClip : public GM { |
| 94 | public: |
| 95 | ConvexPolyClip() { |
| 96 | this->setBGColor(0xFFFFFFFF); |
| 97 | } |
| 98 | |
| 99 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 100 | SkString onShortName() override { |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 101 | return SkString("convex_poly_clip"); |
| 102 | } |
| 103 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 104 | SkISize onISize() override { |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 105 | // When benchmarking the saveLayer set of draws is skipped. |
| 106 | int w = 435; |
| 107 | if (kBench_Mode != this->getMode()) { |
| 108 | w *= 2; |
| 109 | } |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 110 | return SkISize::Make(w, 540); |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 111 | } |
| 112 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 113 | void onOnceBeforeDraw() override { |
Michael Ludwig | b23630c | 2021-08-10 12:27:25 -0400 | [diff] [blame] | 114 | // On < c++17, emplace_back() returns a void :( |
| 115 | auto emplace_back = [](std::vector<Clip>& clips) -> Clip& { |
| 116 | clips.emplace_back(); |
| 117 | return clips.back(); |
| 118 | }; |
| 119 | |
| 120 | emplace_back(fClips).setPath(SkPath::Polygon({ |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 121 | { 5.f, 5.f}, |
| 122 | {100.f, 20.f}, |
| 123 | { 15.f, 100.f}, |
| 124 | }, false)); |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 125 | |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 126 | SkPathBuilder hexagon; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 127 | constexpr SkScalar kRadius = 45.f; |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 128 | const SkPoint center = { kRadius, kRadius }; |
| 129 | for (int i = 0; i < 6; ++i) { |
| 130 | SkScalar angle = 2 * SK_ScalarPI * i / 6; |
Brian Osman | 4428f2c | 2019-04-02 10:59:28 -0400 | [diff] [blame] | 131 | SkPoint point = { SkScalarCos(angle), SkScalarSin(angle) }; |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 132 | point.scale(kRadius); |
| 133 | point = center + point; |
| 134 | if (0 == i) { |
| 135 | hexagon.moveTo(point); |
| 136 | } else { |
| 137 | hexagon.lineTo(point); |
| 138 | } |
| 139 | } |
Michael Ludwig | b23630c | 2021-08-10 12:27:25 -0400 | [diff] [blame] | 140 | emplace_back(fClips).setPath(hexagon.snapshot()); |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 141 | |
| 142 | SkMatrix scaleM; |
| 143 | scaleM.setScale(1.1f, 0.4f, kRadius, kRadius); |
Michael Ludwig | b23630c | 2021-08-10 12:27:25 -0400 | [diff] [blame] | 144 | emplace_back(fClips).setPath(hexagon.detach().makeTransform(scaleM)); |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 145 | |
Michael Ludwig | b23630c | 2021-08-10 12:27:25 -0400 | [diff] [blame] | 146 | emplace_back(fClips).setRect(SkRect::MakeXYWH(8.3f, 11.6f, 78.2f, 72.6f)); |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 147 | |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 148 | SkRect rect = SkRect::MakeLTRB(10.f, 12.f, 80.f, 86.f); |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 149 | SkMatrix rotM; |
| 150 | rotM.setRotate(23.f, rect.centerX(), rect.centerY()); |
Michael Ludwig | b23630c | 2021-08-10 12:27:25 -0400 | [diff] [blame] | 151 | emplace_back(fClips).setPath(SkPath::Rect(rect).makeTransform(rotM)); |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 152 | |
Mike Reed | 607a382 | 2021-01-24 19:49:21 -0500 | [diff] [blame] | 153 | fImg = make_img(100, 100); |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 154 | } |
| 155 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 156 | void onDraw(SkCanvas* canvas) override { |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 157 | SkScalar y = 0; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 158 | constexpr SkScalar kMargin = 10.f; |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 159 | |
| 160 | SkPaint bgPaint; |
| 161 | bgPaint.setAlpha(0x15); |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 162 | SkISize size = canvas->getBaseLayerSize(); |
Mike Reed | 607a382 | 2021-01-24 19:49:21 -0500 | [diff] [blame] | 163 | canvas->drawImageRect(fImg, SkRect::MakeIWH(size.fWidth, size.fHeight), |
| 164 | SkSamplingOptions(), &bgPaint); |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 165 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 166 | constexpr char kTxt[] = "Clip Me!"; |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 167 | SkFont font(ToolUtils::create_portable_typeface(), 23); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 168 | SkScalar textW = font.measureText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8); |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 169 | SkPaint txtPaint; |
Mike Klein | d46dce3 | 2018-08-16 10:17:03 -0400 | [diff] [blame] | 170 | txtPaint.setColor(SK_ColorDKGRAY); |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 171 | |
| 172 | SkScalar startX = 0; |
| 173 | int testLayers = kBench_Mode != this->getMode(); |
| 174 | for (int doLayer = 0; doLayer <= testLayers; ++doLayer) { |
Michael Ludwig | b23630c | 2021-08-10 12:27:25 -0400 | [diff] [blame] | 175 | for (const Clip& clip : fClips) { |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 176 | SkScalar x = startX; |
| 177 | for (int aa = 0; aa < 2; ++aa) { |
| 178 | if (doLayer) { |
| 179 | SkRect bounds; |
Michael Ludwig | b23630c | 2021-08-10 12:27:25 -0400 | [diff] [blame] | 180 | clip.getBounds(&bounds); |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 181 | bounds.outset(2, 2); |
| 182 | bounds.offset(x, y); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 183 | canvas->saveLayer(&bounds, nullptr); |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 184 | } else { |
| 185 | canvas->save(); |
| 186 | } |
| 187 | canvas->translate(x, y); |
Michael Ludwig | b23630c | 2021-08-10 12:27:25 -0400 | [diff] [blame] | 188 | clip.setOnCanvas(canvas, SkClipOp::kIntersect, SkToBool(aa)); |
Mike Reed | 607a382 | 2021-01-24 19:49:21 -0500 | [diff] [blame] | 189 | canvas->drawImage(fImg, 0, 0); |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 190 | canvas->restore(); |
Mike Reed | 607a382 | 2021-01-24 19:49:21 -0500 | [diff] [blame] | 191 | x += fImg->width() + kMargin; |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 192 | } |
| 193 | for (int aa = 0; aa < 2; ++aa) { |
| 194 | |
| 195 | SkPaint clipOutlinePaint; |
| 196 | clipOutlinePaint.setAntiAlias(true); |
| 197 | clipOutlinePaint.setColor(0x50505050); |
| 198 | clipOutlinePaint.setStyle(SkPaint::kStroke_Style); |
| 199 | clipOutlinePaint.setStrokeWidth(0); |
| 200 | |
| 201 | if (doLayer) { |
| 202 | SkRect bounds; |
Michael Ludwig | b23630c | 2021-08-10 12:27:25 -0400 | [diff] [blame] | 203 | clip.getBounds(&bounds); |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 204 | bounds.outset(2, 2); |
| 205 | bounds.offset(x, y); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 206 | canvas->saveLayer(&bounds, nullptr); |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 207 | } else { |
| 208 | canvas->save(); |
| 209 | } |
| 210 | canvas->translate(x, y); |
Michael Ludwig | b23630c | 2021-08-10 12:27:25 -0400 | [diff] [blame] | 211 | SkPath closedClipPath = clip.asClosedPath(); |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 212 | canvas->drawPath(closedClipPath, clipOutlinePaint); |
Michael Ludwig | b23630c | 2021-08-10 12:27:25 -0400 | [diff] [blame] | 213 | clip.setOnCanvas(canvas, SkClipOp::kIntersect, SkToBool(aa)); |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 214 | canvas->scale(1.f, 1.8f); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 215 | canvas->drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8, |
Mike Reed | 2e6db18 | 2018-12-15 13:45:33 -0500 | [diff] [blame] | 216 | 0, 1.5f * font.getSize(), font, txtPaint); |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 217 | canvas->restore(); |
| 218 | x += textW + 2 * kMargin; |
| 219 | } |
Mike Reed | 607a382 | 2021-01-24 19:49:21 -0500 | [diff] [blame] | 220 | y += fImg->height() + kMargin; |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 221 | } |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 222 | y = 0; |
Mike Reed | 607a382 | 2021-01-24 19:49:21 -0500 | [diff] [blame] | 223 | startX += 2 * fImg->width() + SkScalarCeilToInt(2 * textW) + 6 * kMargin; |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 227 | bool runAsBench() const override { return true; } |
mtklein | cf5d9c9 | 2015-01-23 10:31:45 -0800 | [diff] [blame] | 228 | |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 229 | private: |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 230 | class Clip { |
| 231 | public: |
| 232 | enum ClipType { |
| 233 | kNone_ClipType, |
| 234 | kPath_ClipType, |
| 235 | kRect_ClipType |
| 236 | }; |
| 237 | |
| 238 | Clip () : fClipType(kNone_ClipType) {} |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 239 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 240 | void setOnCanvas(SkCanvas* canvas, SkClipOp op, bool aa) const { |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 241 | switch (fClipType) { |
| 242 | case kPath_ClipType: |
Mike Reed | d849a75 | 2020-09-08 20:47:09 -0400 | [diff] [blame] | 243 | canvas->clipPath(fPathBuilder.snapshot(), op, aa); |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 244 | break; |
| 245 | case kRect_ClipType: |
| 246 | canvas->clipRect(fRect, op, aa); |
| 247 | break; |
| 248 | case kNone_ClipType: |
| 249 | SkDEBUGFAIL("Uninitialized Clip."); |
| 250 | break; |
| 251 | } |
| 252 | } |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 253 | |
Mike Reed | d849a75 | 2020-09-08 20:47:09 -0400 | [diff] [blame] | 254 | SkPath asClosedPath() const { |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 255 | switch (fClipType) { |
| 256 | case kPath_ClipType: |
Mike Reed | d849a75 | 2020-09-08 20:47:09 -0400 | [diff] [blame] | 257 | return SkPathBuilder(fPathBuilder).close().detach(); |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 258 | break; |
| 259 | case kRect_ClipType: |
Mike Reed | d849a75 | 2020-09-08 20:47:09 -0400 | [diff] [blame] | 260 | return SkPath::Rect(fRect); |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 261 | case kNone_ClipType: |
| 262 | SkDEBUGFAIL("Uninitialized Clip."); |
| 263 | break; |
| 264 | } |
Mike Reed | d849a75 | 2020-09-08 20:47:09 -0400 | [diff] [blame] | 265 | return SkPath(); |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 266 | } |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 267 | |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 268 | void setPath(const SkPath& path) { |
| 269 | fClipType = kPath_ClipType; |
Mike Reed | d849a75 | 2020-09-08 20:47:09 -0400 | [diff] [blame] | 270 | fPathBuilder = path; |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 271 | } |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 272 | |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 273 | void setRect(const SkRect& rect) { |
| 274 | fClipType = kRect_ClipType; |
| 275 | fRect = rect; |
Mike Reed | d849a75 | 2020-09-08 20:47:09 -0400 | [diff] [blame] | 276 | fPathBuilder.reset(); |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 277 | } |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 278 | |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 279 | ClipType getType() const { return fClipType; } |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 280 | |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 281 | void getBounds(SkRect* bounds) const { |
| 282 | switch (fClipType) { |
| 283 | case kPath_ClipType: |
Mike Reed | d849a75 | 2020-09-08 20:47:09 -0400 | [diff] [blame] | 284 | *bounds = fPathBuilder.computeBounds(); |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 285 | break; |
| 286 | case kRect_ClipType: |
| 287 | *bounds = fRect; |
| 288 | break; |
| 289 | case kNone_ClipType: |
| 290 | SkDEBUGFAIL("Uninitialized Clip."); |
| 291 | break; |
| 292 | } |
| 293 | } |
| 294 | |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 295 | private: |
| 296 | ClipType fClipType; |
Mike Reed | d849a75 | 2020-09-08 20:47:09 -0400 | [diff] [blame] | 297 | SkPathBuilder fPathBuilder; |
commit-bot@chromium.org | b511be5 | 2014-02-04 15:09:16 +0000 | [diff] [blame] | 298 | SkRect fRect; |
| 299 | }; |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 300 | |
Michael Ludwig | b23630c | 2021-08-10 12:27:25 -0400 | [diff] [blame] | 301 | std::vector<Clip> fClips; |
| 302 | sk_sp<SkImage> fImg;; |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 303 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 304 | using INHERITED = GM; |
commit-bot@chromium.org | a343c84 | 2014-01-31 14:48:58 +0000 | [diff] [blame] | 305 | }; |
| 306 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 307 | DEF_GM(return new ConvexPolyClip;) |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 308 | } // namespace skiagm |