bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +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 | */ |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkBitmap.h" |
| 10 | #include "include/core/SkBlurTypes.h" |
| 11 | #include "include/core/SkCanvas.h" |
| 12 | #include "include/core/SkColor.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 13 | #include "include/core/SkFont.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/core/SkImage.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 15 | #include "include/core/SkImageInfo.h" |
| 16 | #include "include/core/SkMaskFilter.h" |
| 17 | #include "include/core/SkMatrix.h" |
| 18 | #include "include/core/SkPaint.h" |
| 19 | #include "include/core/SkPoint.h" |
| 20 | #include "include/core/SkRect.h" |
| 21 | #include "include/core/SkRefCnt.h" |
| 22 | #include "include/core/SkScalar.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "include/core/SkShader.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 24 | #include "include/core/SkSize.h" |
| 25 | #include "include/core/SkString.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 26 | #include "include/core/SkSurface.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 27 | #include "include/core/SkTileMode.h" |
| 28 | #include "include/core/SkTypeface.h" |
| 29 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 30 | #include "include/effects/SkGradientShader.h" |
Adlai Holler | 872a32c | 2020-07-10 14:33:22 -0400 | [diff] [blame] | 31 | #include "include/gpu/GrDirectContext.h" |
Kevin Lubick | 1b3aa8b | 2023-01-19 14:03:31 -0500 | [diff] [blame] | 32 | #include "src/base/SkMathPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 33 | #include "src/core/SkBlurMask.h" |
Kevin Lubick | 9b02837 | 2023-10-05 15:04:54 -0400 | [diff] [blame] | 34 | #include "tools/GpuToolUtils.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 35 | #include "tools/ToolUtils.h" |
Kevin Lubick | e836c3a | 2023-10-20 06:55:35 -0400 | [diff] [blame] | 36 | #include "tools/fonts/FontToolUtils.h" |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 37 | |
bsalomon@google.com | 7d30a21 | 2012-04-25 15:52:27 +0000 | [diff] [blame] | 38 | static SkBitmap make_chessbm(int w, int h) { |
| 39 | SkBitmap bm; |
reed@google.com | eb9a46c | 2014-01-25 16:46:20 +0000 | [diff] [blame] | 40 | bm.allocN32Pixels(w, h); |
bsalomon@google.com | 7d30a21 | 2012-04-25 15:52:27 +0000 | [diff] [blame] | 41 | |
| 42 | for (int y = 0; y < bm.height(); y++) { |
| 43 | uint32_t* p = bm.getAddr32(0, y); |
| 44 | for (int x = 0; x < bm.width(); x++) { |
| 45 | p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK; |
| 46 | } |
| 47 | } |
Mike Reed | d396cd5 | 2021-01-23 21:14:47 -0500 | [diff] [blame] | 48 | bm.setImmutable(); |
bsalomon@google.com | 7d30a21 | 2012-04-25 15:52:27 +0000 | [diff] [blame] | 49 | return bm; |
| 50 | } |
| 51 | |
bsalomon | 7cf36cc | 2016-07-14 09:33:42 -0700 | [diff] [blame] | 52 | // Creates a bitmap and a matching image. |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 53 | static sk_sp<SkImage> makebm(SkCanvas* origCanvas, SkBitmap* resultBM, int w, int h) { |
robertphillips | 24eb7a8 | 2015-09-24 08:47:49 -0700 | [diff] [blame] | 54 | SkImageInfo info = SkImageInfo::MakeN32Premul(w, h); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 55 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 56 | auto surface(ToolUtils::makeSurface(origCanvas, info)); |
robertphillips | 24eb7a8 | 2015-09-24 08:47:49 -0700 | [diff] [blame] | 57 | SkCanvas* canvas = surface->getCanvas(); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 58 | |
robertphillips | 24eb7a8 | 2015-09-24 08:47:49 -0700 | [diff] [blame] | 59 | canvas->clear(SK_ColorTRANSPARENT); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 60 | |
| 61 | SkScalar wScalar = SkIntToScalar(w); |
| 62 | SkScalar hScalar = SkIntToScalar(h); |
| 63 | |
| 64 | SkPoint pt = { wScalar / 2, hScalar / 2 }; |
| 65 | |
Brian Osman | 116b33e | 2020-02-05 13:34:09 -0500 | [diff] [blame] | 66 | SkScalar radius = 4 * std::max(wScalar, hScalar); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 67 | |
| 68 | SkColor colors[] = { SK_ColorRED, SK_ColorYELLOW, |
| 69 | SK_ColorGREEN, SK_ColorMAGENTA, |
| 70 | SK_ColorBLUE, SK_ColorCYAN, |
| 71 | SK_ColorRED}; |
| 72 | |
| 73 | SkScalar pos[] = {0, |
| 74 | SK_Scalar1 / 6, |
| 75 | 2 * SK_Scalar1 / 6, |
| 76 | 3 * SK_Scalar1 / 6, |
| 77 | 4 * SK_Scalar1 / 6, |
| 78 | 5 * SK_Scalar1 / 6, |
| 79 | SK_Scalar1}; |
| 80 | |
| 81 | SkPaint paint; |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 82 | SkRect rect = SkRect::MakeWH(wScalar, hScalar); |
| 83 | SkMatrix mat = SkMatrix::I(); |
| 84 | for (int i = 0; i < 4; ++i) { |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 85 | paint.setShader(SkGradientShader::MakeRadial( |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 86 | pt, radius, |
| 87 | colors, pos, |
Herb Derby | c37b386 | 2022-06-21 09:49:17 -0400 | [diff] [blame] | 88 | std::size(colors), |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 89 | SkTileMode::kRepeat, |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 90 | 0, &mat)); |
robertphillips | 24eb7a8 | 2015-09-24 08:47:49 -0700 | [diff] [blame] | 91 | canvas->drawRect(rect, paint); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 92 | rect.inset(wScalar / 8, hScalar / 8); |
| 93 | mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4); |
| 94 | } |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 95 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 96 | auto image = surface->makeImageSnapshot(); |
robertphillips | 24eb7a8 | 2015-09-24 08:47:49 -0700 | [diff] [blame] | 97 | |
| 98 | SkBitmap tempBM; |
| 99 | |
Cary Clark | 4f5a79c | 2018-02-07 15:51:00 -0500 | [diff] [blame] | 100 | image->asLegacyBitmap(&tempBM); |
robertphillips | 24eb7a8 | 2015-09-24 08:47:49 -0700 | [diff] [blame] | 101 | |
| 102 | // Let backends know we won't change this, so they don't have to deep copy it defensively. |
| 103 | tempBM.setImmutable(); |
| 104 | *resultBM = tempBM; |
| 105 | |
| 106 | return image; |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 109 | static void bitmapproc(SkCanvas* canvas, sk_sp<SkImage> image, |
| 110 | const SkBitmap&, const SkIRect& srcR, |
Mike Reed | d396cd5 | 2021-01-23 21:14:47 -0500 | [diff] [blame] | 111 | const SkRect& dstR, const SkSamplingOptions& sampling, |
| 112 | const SkPaint* paint) { |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 113 | canvas->drawImageRect(image, SkRect::Make(srcR), dstR, sampling, paint, |
Mike Reed | d396cd5 | 2021-01-23 21:14:47 -0500 | [diff] [blame] | 114 | SkCanvas::kStrict_SrcRectConstraint); |
fmalita | ab83da7 | 2016-08-26 13:04:14 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 117 | static void bitmapsubsetproc(SkCanvas* canvas, sk_sp<SkImage> image, |
| 118 | const SkBitmap& bm, const SkIRect& srcR, |
Mike Reed | d396cd5 | 2021-01-23 21:14:47 -0500 | [diff] [blame] | 119 | const SkRect& dstR, const SkSamplingOptions& sampling, |
| 120 | const SkPaint* paint) { |
fmalita | ab83da7 | 2016-08-26 13:04:14 -0700 | [diff] [blame] | 121 | if (!bm.bounds().contains(srcR)) { |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 122 | bitmapproc(canvas, std::move(image), bm, srcR, dstR, sampling, paint); |
fmalita | ab83da7 | 2016-08-26 13:04:14 -0700 | [diff] [blame] | 123 | return; |
| 124 | } |
| 125 | |
| 126 | SkBitmap subset; |
| 127 | if (bm.extractSubset(&subset, srcR)) { |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 128 | sk_sp<SkImage> subsetImg = ToolUtils::MakeTextureImage(canvas, subset.asImage()); |
| 129 | canvas->drawImageRect(subsetImg, dstR, sampling, paint); |
fmalita | ab83da7 | 2016-08-26 13:04:14 -0700 | [diff] [blame] | 130 | } |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 131 | } |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 132 | |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 133 | static void imageproc(SkCanvas* canvas, sk_sp<SkImage> image, const SkBitmap&, const SkIRect& srcR, |
Mike Reed | d396cd5 | 2021-01-23 21:14:47 -0500 | [diff] [blame] | 134 | const SkRect& dstR, const SkSamplingOptions& sampling, const SkPaint* paint) { |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 135 | sk_sp<SkImage> tmp = ToolUtils::MakeTextureImage(canvas, std::move(image)); |
| 136 | canvas->drawImageRect(tmp, SkRect::Make(srcR), dstR, sampling, paint, |
Mike Reed | d396cd5 | 2021-01-23 21:14:47 -0500 | [diff] [blame] | 137 | SkCanvas::kStrict_SrcRectConstraint); |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 140 | static void imagesubsetproc(SkCanvas* canvas, sk_sp<SkImage> image, const SkBitmap& bm, |
Mike Reed | d396cd5 | 2021-01-23 21:14:47 -0500 | [diff] [blame] | 141 | const SkIRect& srcR, const SkRect& dstR, |
| 142 | const SkSamplingOptions& sampling, const SkPaint* paint) { |
Kevin Lubick | 77472bf | 2023-03-24 07:11:17 -0400 | [diff] [blame] | 143 | SkASSERT_RELEASE(image); |
fmalita | ab83da7 | 2016-08-26 13:04:14 -0700 | [diff] [blame] | 144 | if (!image->bounds().contains(srcR)) { |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 145 | imageproc(canvas, std::move(image), bm, srcR, dstR, sampling, paint); |
fmalita | ab83da7 | 2016-08-26 13:04:14 -0700 | [diff] [blame] | 146 | return; |
| 147 | } |
| 148 | |
Adlai Holler | 872a32c | 2020-07-10 14:33:22 -0400 | [diff] [blame] | 149 | auto direct = GrAsDirectContext(canvas->recordingContext()); |
Kevin Lubick | 14d319b | 2023-04-27 15:43:07 -0400 | [diff] [blame] | 150 | if (sk_sp<SkImage> subset = image->makeSubset(direct, srcR)) { |
Mike Reed | d396cd5 | 2021-01-23 21:14:47 -0500 | [diff] [blame] | 151 | canvas->drawImageRect(subset, dstR, sampling, paint); |
Robert Phillips | 01f3be4 | 2023-06-16 13:22:18 -0400 | [diff] [blame] | 152 | return; |
fmalita | ab83da7 | 2016-08-26 13:04:14 -0700 | [diff] [blame] | 153 | } |
Kevin Lubick | 0f7b44e | 2023-02-28 09:13:11 -0500 | [diff] [blame] | 154 | #if defined(SK_GRAPHITE) |
Kevin Lubick | 14d319b | 2023-04-27 15:43:07 -0400 | [diff] [blame] | 155 | if (sk_sp<SkImage> subset = image->makeSubset(canvas->recorder(), srcR, {})) { |
Robert Phillips | 6f8ecbe | 2023-01-13 15:43:40 -0500 | [diff] [blame] | 156 | canvas->drawImageRect(subset, dstR, sampling, paint); |
| 157 | } |
| 158 | #endif |
fmalita | ab83da7 | 2016-08-26 13:04:14 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 161 | typedef void DrawRectRectProc(SkCanvas*, sk_sp<SkImage>, const SkBitmap&, |
| 162 | const SkIRect& srcR, const SkRect& dstR, |
Mike Reed | d396cd5 | 2021-01-23 21:14:47 -0500 | [diff] [blame] | 163 | const SkSamplingOptions&, const SkPaint*); |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 164 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 165 | constexpr int gSize = 1024; |
| 166 | constexpr int gBmpSize = 2048; |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 167 | |
| 168 | class DrawBitmapRectGM : public skiagm::GM { |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 169 | public: |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 170 | DrawBitmapRectGM(DrawRectRectProc proc, const char suffix[]) : fProc(proc) { |
| 171 | fName.set("drawbitmaprect"); |
| 172 | if (suffix) { |
| 173 | fName.append(suffix); |
| 174 | } |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 175 | } |
| 176 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 177 | DrawRectRectProc* fProc; |
| 178 | SkBitmap fLargeBitmap; |
| 179 | sk_sp<SkImage> fImage; |
| 180 | SkString fName; |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 181 | |
| 182 | protected: |
Leandro Lovisolo | 24fa211 | 2023-08-15 19:05:17 +0000 | [diff] [blame] | 183 | SkString getName() const override { return fName; } |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 184 | |
Leandro Lovisolo | 8f02388 | 2023-08-15 21:13:52 +0000 | [diff] [blame] | 185 | SkISize getISize() override { return SkISize::Make(gSize, gSize); } |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 186 | |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 187 | DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override { |
Robert Phillips | 4a3ebc2 | 2020-07-10 11:27:43 -0400 | [diff] [blame] | 188 | if (!fImage || !fImage->isValid(canvas->recordingContext())) { |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 189 | fImage = ToolUtils::MakeTextureImage(canvas, |
| 190 | makebm(canvas, &fLargeBitmap, gBmpSize, gBmpSize)); |
| 191 | if (!fImage) { |
| 192 | *errorMsg = "Image creation failed"; |
| 193 | return DrawResult::kSkip; |
| 194 | } |
robertphillips | 24eb7a8 | 2015-09-24 08:47:49 -0700 | [diff] [blame] | 195 | } |
| 196 | |
vandebo@chromium.org | 663515b | 2012-01-05 18:45:27 +0000 | [diff] [blame] | 197 | SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)}; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 198 | const int kMaxSrcRectSize = 1 << (SkNextLog2(gBmpSize) + 2); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 199 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 200 | const int kPadX = 30; |
| 201 | const int kPadY = 40; |
John Stiles | acf7164 | 2021-08-12 22:33:57 -0400 | [diff] [blame] | 202 | SkPaint alphaPaint; |
| 203 | alphaPaint.setAlphaf(0.125f); |
| 204 | canvas->drawImageRect(fImage, SkRect::MakeIWH(gSize, gSize), SkSamplingOptions(), |
| 205 | &alphaPaint); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 206 | canvas->translate(SK_Scalar1 * kPadX / 2, |
| 207 | SK_Scalar1 * kPadY / 2); |
| 208 | SkPaint blackPaint; |
| 209 | SkScalar titleHeight = SK_Scalar1 * 24; |
| 210 | blackPaint.setColor(SK_ColorBLACK); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 211 | blackPaint.setAntiAlias(true); |
Mike Reed | c4745d6 | 2019-01-07 09:31:58 -0500 | [diff] [blame] | 212 | |
Kevin Lubick | e836c3a | 2023-10-20 06:55:35 -0400 | [diff] [blame] | 213 | SkFont font(ToolUtils::DefaultPortableTypeface(), titleHeight); |
Mike Reed | c4745d6 | 2019-01-07 09:31:58 -0500 | [diff] [blame] | 214 | |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 215 | SkString title; |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 216 | title.printf("Bitmap size: %d x %d", gBmpSize, gBmpSize); |
Mike Reed | c4745d6 | 2019-01-07 09:31:58 -0500 | [diff] [blame] | 217 | canvas->drawString(title, 0, titleHeight, font, blackPaint); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 218 | |
| 219 | canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight); |
| 220 | int rowCount = 0; |
| 221 | canvas->save(); |
| 222 | for (int w = 1; w <= kMaxSrcRectSize; w *= 4) { |
| 223 | for (int h = 1; h <= kMaxSrcRectSize; h *= 4) { |
| 224 | |
reed | f803da1 | 2015-01-23 05:58:07 -0800 | [diff] [blame] | 225 | SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSize - h) / 2, w, h); |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 226 | fProc(canvas, fImage, fLargeBitmap, srcRect, dstRect, SkSamplingOptions(), |
Mike Reed | d396cd5 | 2021-01-23 21:14:47 -0500 | [diff] [blame] | 227 | nullptr); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 228 | |
| 229 | SkString label; |
| 230 | label.appendf("%d x %d", w, h); |
| 231 | blackPaint.setAntiAlias(true); |
| 232 | blackPaint.setStyle(SkPaint::kFill_Style); |
Mike Reed | c4745d6 | 2019-01-07 09:31:58 -0500 | [diff] [blame] | 233 | font.setSize(SK_Scalar1 * 10); |
| 234 | SkScalar baseline = dstRect.height() + font.getSize() + SK_Scalar1 * 3; |
| 235 | canvas->drawString(label, 0, baseline, font, blackPaint); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 236 | blackPaint.setStyle(SkPaint::kStroke_Style); |
| 237 | blackPaint.setStrokeWidth(SK_Scalar1); |
| 238 | blackPaint.setAntiAlias(false); |
| 239 | canvas->drawRect(dstRect, blackPaint); |
| 240 | |
| 241 | canvas->translate(dstRect.width() + SK_Scalar1 * kPadX, 0); |
| 242 | ++rowCount; |
| 243 | if ((dstRect.width() + kPadX) * rowCount > gSize) { |
| 244 | canvas->restore(); |
| 245 | canvas->translate(0, dstRect.height() + SK_Scalar1 * kPadY); |
| 246 | canvas->save(); |
| 247 | rowCount = 0; |
| 248 | } |
| 249 | } |
| 250 | } |
bsalomon@google.com | 7d30a21 | 2012-04-25 15:52:27 +0000 | [diff] [blame] | 251 | |
| 252 | { |
| 253 | // test the following code path: |
| 254 | // SkGpuDevice::drawPath() -> SkGpuDevice::drawWithMaskFilter() |
| 255 | SkIRect srcRect; |
John Stiles | acf7164 | 2021-08-12 22:33:57 -0400 | [diff] [blame] | 256 | SkPaint maskPaint; |
Mike Reed | d396cd5 | 2021-01-23 21:14:47 -0500 | [diff] [blame] | 257 | SkBitmap bm = make_chessbm(5, 5); |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 258 | sk_sp<SkImage> img = ToolUtils::MakeTextureImage(canvas, bm.asImage()); |
bsalomon@google.com | 7d30a21 | 2012-04-25 15:52:27 +0000 | [diff] [blame] | 259 | |
| 260 | srcRect.setXYWH(1, 1, 3, 3); |
John Stiles | acf7164 | 2021-08-12 22:33:57 -0400 | [diff] [blame] | 261 | maskPaint.setMaskFilter(SkMaskFilter::MakeBlur( |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 262 | kNormal_SkBlurStyle, |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 263 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)))); |
fmalita | ab83da7 | 2016-08-26 13:04:14 -0700 | [diff] [blame] | 264 | |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 265 | fProc(canvas, img, bm, srcRect, dstRect, |
John Stiles | acf7164 | 2021-08-12 22:33:57 -0400 | [diff] [blame] | 266 | SkSamplingOptions(SkFilterMode::kLinear), &maskPaint); |
bsalomon@google.com | 7d30a21 | 2012-04-25 15:52:27 +0000 | [diff] [blame] | 267 | } |
Robert Phillips | 0fb10ab | 2022-04-20 14:57:03 -0400 | [diff] [blame] | 268 | |
| 269 | return DrawResult::kOk; |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 273 | using INHERITED = skiagm::GM; |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 274 | }; |
| 275 | |
fmalita | ab83da7 | 2016-08-26 13:04:14 -0700 | [diff] [blame] | 276 | DEF_GM( return new DrawBitmapRectGM(bitmapproc , nullptr); ) |
| 277 | DEF_GM( return new DrawBitmapRectGM(bitmapsubsetproc, "-subset"); ) |
| 278 | DEF_GM( return new DrawBitmapRectGM(imageproc , "-imagerect"); ) |
| 279 | DEF_GM( return new DrawBitmapRectGM(imagesubsetproc , "-imagerect-subset"); ) |