2013-07-25 21:34:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkBlurTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkColor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImage.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkImageInfo.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkMaskFilter.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/core/SkTileMode.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "include/gpu/GrContextOptions.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/private/SkTDArray.h"
|
|
|
|
#include "src/core/SkBlurMask.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
|
2020-05-15 13:52:29 +00:00
|
|
|
/** Creates an image with two one-pixel wide borders around a checkerboard. The checkerboard is 2x2
|
|
|
|
checks where each check has as many pixels as is necessary to fill the interior. It returns
|
|
|
|
the image and a src rect that bounds the checkerboard portion. */
|
2021-01-23 23:10:39 +00:00
|
|
|
std::tuple<sk_sp<SkImage>, SkRect> make_ringed_image(int width, int height) {
|
2020-05-15 13:52:29 +00:00
|
|
|
|
|
|
|
// These are kRGBA_8888_SkColorType values.
|
|
|
|
static constexpr uint32_t kOuterRingColor = 0xFFFF0000,
|
|
|
|
kInnerRingColor = 0xFF0000FF,
|
|
|
|
kCheckColor1 = 0xFF000000,
|
|
|
|
kCheckColor2 = 0xFFFFFFFF;
|
2015-11-02 20:33:21 +00:00
|
|
|
|
2013-11-08 15:09:22 +00:00
|
|
|
SkASSERT(0 == width % 2 && 0 == height % 2);
|
2015-11-09 18:06:06 +00:00
|
|
|
SkASSERT(width >= 6 && height >= 6);
|
2013-11-09 07:02:23 +00:00
|
|
|
|
2020-05-15 13:52:29 +00:00
|
|
|
SkImageInfo info = SkImageInfo::Make(width, height, kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
2015-11-09 18:06:06 +00:00
|
|
|
size_t rowBytes = SkAlign4(info.minRowBytes());
|
2020-05-15 13:52:29 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(info, rowBytes);
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2020-05-15 13:52:29 +00:00
|
|
|
uint32_t* scanline = bitmap.getAddr32(0, 0);
|
2013-07-25 21:34:00 +00:00
|
|
|
for (int x = 0; x < width; ++x) {
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline[x] = kOuterRingColor;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline = bitmap.getAddr32(0, 1);
|
|
|
|
scanline[0] = kOuterRingColor;
|
2013-11-08 15:09:22 +00:00
|
|
|
for (int x = 1; x < width - 1; ++x) {
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline[x] = kInnerRingColor;
|
2013-11-08 15:09:22 +00:00
|
|
|
}
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline[width - 1] = kOuterRingColor;
|
2015-11-09 18:06:06 +00:00
|
|
|
|
|
|
|
for (int y = 2; y < height / 2; ++y) {
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline = bitmap.getAddr32(0, y);
|
|
|
|
scanline[0] = kOuterRingColor;
|
|
|
|
scanline[1] = kInnerRingColor;
|
2015-11-09 18:06:06 +00:00
|
|
|
for (int x = 2; x < width / 2; ++x) {
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline[x] = kCheckColor1;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
2015-11-09 18:06:06 +00:00
|
|
|
for (int x = width / 2; x < width - 2; ++x) {
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline[x] = kCheckColor2;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline[width - 2] = kInnerRingColor;
|
|
|
|
scanline[width - 1] = kOuterRingColor;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 18:06:06 +00:00
|
|
|
for (int y = height / 2; y < height - 2; ++y) {
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline = bitmap.getAddr32(0, y);
|
|
|
|
scanline[0] = kOuterRingColor;
|
|
|
|
scanline[1] = kInnerRingColor;
|
2015-11-09 18:06:06 +00:00
|
|
|
for (int x = 2; x < width / 2; ++x) {
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline[x] = kCheckColor2;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
2015-11-09 18:06:06 +00:00
|
|
|
for (int x = width / 2; x < width - 2; ++x) {
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline[x] = kCheckColor1;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline[width - 2] = kInnerRingColor;
|
|
|
|
scanline[width - 1] = kOuterRingColor;
|
2013-11-08 15:09:22 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline = bitmap.getAddr32(0, height - 2);
|
|
|
|
scanline[0] = kOuterRingColor;
|
2013-11-08 15:09:22 +00:00
|
|
|
for (int x = 1; x < width - 1; ++x) {
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline[x] = kInnerRingColor;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline[width - 1] = kOuterRingColor;
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline = bitmap.getAddr32(0, height - 1);
|
2013-07-25 21:34:00 +00:00
|
|
|
for (int x = 0; x < width; ++x) {
|
2020-05-15 13:52:29 +00:00
|
|
|
scanline[x] = kOuterRingColor;
|
2015-11-09 18:06:06 +00:00
|
|
|
}
|
2020-05-15 13:52:29 +00:00
|
|
|
bitmap.setImmutable();
|
2021-01-23 23:10:39 +00:00
|
|
|
return {bitmap.asImage(), SkRect::Make({2, 2, width - 2, height - 2})};
|
2015-10-23 18:13:01 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 13:52:29 +00:00
|
|
|
/**
|
2020-05-18 20:40:59 +00:00
|
|
|
* These GMs exercise the behavior of the drawImageRect and its SrcRectConstraint parameter. They
|
|
|
|
* tests various matrices, filter qualities, and interaction with mask filters. They also exercise
|
2020-05-15 13:52:29 +00:00
|
|
|
* the tiling image draws of SkGpuDevice by overriding the maximum texture size of the GrContext.
|
|
|
|
*/
|
2020-05-18 20:40:59 +00:00
|
|
|
class SrcRectConstraintGM : public skiagm::GM {
|
2013-07-25 21:34:00 +00:00
|
|
|
public:
|
2020-05-26 14:38:24 +00:00
|
|
|
SrcRectConstraintGM(const char* shortName, SkCanvas::SrcRectConstraint constraint, bool batch)
|
|
|
|
: fShortName(shortName)
|
|
|
|
, fConstraint(constraint)
|
2021-01-29 19:42:38 +00:00
|
|
|
, fBatch(batch) {
|
|
|
|
// Make sure GPU SkSurfaces can be created for this GM.
|
|
|
|
SkASSERT(this->onISize().width() <= kMaxTextureSize &&
|
|
|
|
this->onISize().height() <= kMaxTextureSize);
|
|
|
|
}
|
2013-07-25 21:34:00 +00:00
|
|
|
|
|
|
|
protected:
|
2020-05-26 14:38:24 +00:00
|
|
|
SkString onShortName() override { return fShortName; }
|
|
|
|
SkISize onISize() override { return SkISize::Make(800, 1000); }
|
|
|
|
|
2021-01-23 23:10:39 +00:00
|
|
|
void drawImage(SkCanvas* canvas, sk_sp<SkImage> image, SkRect srcRect, SkRect dstRect,
|
|
|
|
const SkSamplingOptions& sampling, SkPaint* paint) {
|
2020-05-26 14:38:24 +00:00
|
|
|
if (fBatch) {
|
|
|
|
SkCanvas::ImageSetEntry imageSetEntry[1];
|
|
|
|
imageSetEntry[0].fImage = image;
|
2021-01-23 23:10:39 +00:00
|
|
|
imageSetEntry[0].fSrcRect = srcRect;
|
2020-05-26 14:38:24 +00:00
|
|
|
imageSetEntry[0].fDstRect = dstRect;
|
|
|
|
imageSetEntry[0].fAAFlags = paint->isAntiAlias() ? SkCanvas::kAll_QuadAAFlags
|
|
|
|
: SkCanvas::kNone_QuadAAFlags;
|
|
|
|
canvas->experimental_DrawEdgeAAImageSet(imageSetEntry, SK_ARRAY_COUNT(imageSetEntry),
|
|
|
|
/*dstClips=*/nullptr,
|
|
|
|
/*preViewMatrices=*/nullptr,
|
2021-01-23 23:10:39 +00:00
|
|
|
sampling, paint, fConstraint);
|
2020-05-26 14:38:24 +00:00
|
|
|
} else {
|
2021-01-23 23:10:39 +00:00
|
|
|
canvas->drawImageRect(image.get(), srcRect, dstRect, sampling, paint, fConstraint);
|
2020-05-18 20:40:59 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-11-09 18:06:06 +00:00
|
|
|
// Draw the area of interest of the small image
|
2021-01-23 23:10:39 +00:00
|
|
|
void drawCase1(SkCanvas* canvas, int transX, int transY, bool aa,
|
|
|
|
const SkSamplingOptions& sampling) {
|
2015-07-14 17:54:12 +00:00
|
|
|
SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
|
|
|
|
SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
|
2013-07-26 07:00:58 +00:00
|
|
|
|
2013-08-20 12:09:32 +00:00
|
|
|
SkPaint paint;
|
2015-10-23 18:13:01 +00:00
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setAntiAlias(aa);
|
2013-08-20 12:09:32 +00:00
|
|
|
|
2021-01-23 23:10:39 +00:00
|
|
|
drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint);
|
2013-08-20 12:09:32 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 18:06:06 +00:00
|
|
|
// Draw the area of interest of the large image
|
2021-01-23 23:10:39 +00:00
|
|
|
void drawCase2(SkCanvas* canvas, int transX, int transY, bool aa,
|
|
|
|
const SkSamplingOptions& sampling) {
|
2015-07-14 17:54:12 +00:00
|
|
|
SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
|
|
|
|
SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
|
2013-07-25 21:34:00 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
2015-10-23 18:13:01 +00:00
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setAntiAlias(aa);
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2021-01-23 23:10:39 +00:00
|
|
|
drawImage(canvas, fBigImage, fBigSrcRect, dst, sampling, &paint);
|
2013-08-20 12:09:32 +00:00
|
|
|
}
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2015-11-09 18:06:06 +00:00
|
|
|
// Draw upper-left 1/4 of the area of interest of the large image
|
2021-01-23 23:10:39 +00:00
|
|
|
void drawCase3(SkCanvas* canvas, int transX, int transY, bool aa,
|
|
|
|
const SkSamplingOptions& sampling) {
|
|
|
|
SkRect src = SkRect::MakeXYWH(fBigSrcRect.fLeft,
|
|
|
|
fBigSrcRect.fTop,
|
|
|
|
fBigSrcRect.width()/2,
|
|
|
|
fBigSrcRect.height()/2);
|
2015-07-14 17:54:12 +00:00
|
|
|
SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
|
|
|
|
SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2013-08-20 12:09:32 +00:00
|
|
|
SkPaint paint;
|
2015-10-23 18:13:01 +00:00
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setAntiAlias(aa);
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2021-01-23 23:10:39 +00:00
|
|
|
drawImage(canvas, fBigImage, src, dst, sampling, &paint);
|
2013-08-20 12:09:32 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 18:06:06 +00:00
|
|
|
// Draw the area of interest of the small image with a normal blur
|
2021-01-23 23:10:39 +00:00
|
|
|
void drawCase4(SkCanvas* canvas, int transX, int transY, bool aa,
|
|
|
|
const SkSamplingOptions& sampling) {
|
2015-07-14 17:54:12 +00:00
|
|
|
SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
|
|
|
|
SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
|
2013-08-20 16:51:20 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle,
|
2016-04-04 17:02:58 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(3)));
|
2015-10-23 18:13:01 +00:00
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setAntiAlias(aa);
|
2013-08-20 16:51:20 +00:00
|
|
|
|
2021-01-23 23:10:39 +00:00
|
|
|
drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint);
|
2013-08-20 16:51:20 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 18:06:06 +00:00
|
|
|
// Draw the area of interest of the small image with a outer blur
|
2021-01-23 23:10:39 +00:00
|
|
|
void drawCase5(SkCanvas* canvas, int transX, int transY, bool aa,
|
|
|
|
const SkSamplingOptions& sampling) {
|
2015-11-04 12:36:12 +00:00
|
|
|
SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
|
|
|
|
SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
|
|
|
|
|
|
|
|
SkPaint paint;
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kOuter_SkBlurStyle,
|
2016-04-04 17:02:58 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(7)));
|
2015-11-04 12:36:12 +00:00
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setAntiAlias(aa);
|
|
|
|
|
2021-01-23 23:10:39 +00:00
|
|
|
drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint);
|
2015-11-04 12:36:12 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 21:50:17 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2021-01-29 19:42:38 +00:00
|
|
|
std::tie(fBigImage, fBigSrcRect) = make_ringed_image(2*kMaxTextureSize, 2*kMaxTextureSize);
|
2020-05-15 13:52:29 +00:00
|
|
|
std::tie(fSmallImage, fSmallSrcRect) = make_ringed_image(kSmallSize, kSmallSize);
|
2016-07-13 21:50:17 +00:00
|
|
|
}
|
2015-11-09 18:06:06 +00:00
|
|
|
|
2016-07-13 21:50:17 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-08-20 12:09:32 +00:00
|
|
|
canvas->clear(SK_ColorGRAY);
|
2020-06-01 14:38:31 +00:00
|
|
|
std::vector<SkMatrix> matrices;
|
2015-10-23 18:13:01 +00:00
|
|
|
// Draw with identity
|
2020-06-01 14:38:31 +00:00
|
|
|
matrices.push_back(SkMatrix::I());
|
2015-10-23 18:13:01 +00:00
|
|
|
|
|
|
|
// Draw with rotation and scale down in x, up in y.
|
|
|
|
SkMatrix m;
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkScalar kBottom = SkIntToScalar(kRow4Y + kBlockSize + kBlockSpacing);
|
2015-10-23 18:13:01 +00:00
|
|
|
m.setTranslate(0, kBottom);
|
|
|
|
m.preRotate(15.f, 0, kBottom + kBlockSpacing);
|
|
|
|
m.preScale(0.71f, 1.22f);
|
2020-06-01 14:38:31 +00:00
|
|
|
matrices.push_back(m);
|
2015-10-23 18:13:01 +00:00
|
|
|
|
|
|
|
// Align the next set with the middle of the previous in y, translated to the right in x.
|
2020-06-01 14:38:31 +00:00
|
|
|
SkPoint corners[] = {{0, 0}, {0, kBottom}, {kWidth, kBottom}, {kWidth, 0}};
|
|
|
|
matrices.back().mapPoints(corners, 4);
|
2021-08-13 02:33:57 +00:00
|
|
|
m.setTranslate(std::max({corners[0].fX, corners[1].fX, corners[2].fX, corners[3].fX}),
|
|
|
|
(corners[0].fY + corners[1].fY + corners[2].fY + corners[3].fY) / 4);
|
2015-10-23 18:13:01 +00:00
|
|
|
m.preScale(0.2f, 0.2f);
|
2020-06-01 14:38:31 +00:00
|
|
|
matrices.push_back(m);
|
2015-10-23 18:13:01 +00:00
|
|
|
|
2021-01-23 23:10:39 +00:00
|
|
|
const SkSamplingOptions none(SkFilterMode::kNearest);
|
|
|
|
const SkSamplingOptions low(SkFilterMode::kLinear);
|
2021-02-05 17:55:38 +00:00
|
|
|
const SkSamplingOptions high(SkCubicResampler::Mitchell());
|
2021-01-23 23:10:39 +00:00
|
|
|
|
2015-10-23 18:13:01 +00:00
|
|
|
SkScalar maxX = 0;
|
2020-06-01 14:38:31 +00:00
|
|
|
for (bool antiAlias : {false, true}) {
|
2013-11-22 20:34:59 +00:00
|
|
|
canvas->save();
|
2015-10-23 18:13:01 +00:00
|
|
|
canvas->translate(maxX, 0);
|
2020-06-01 14:38:31 +00:00
|
|
|
for (const SkMatrix& matrix : matrices) {
|
2015-10-23 18:13:01 +00:00
|
|
|
canvas->save();
|
2020-06-01 14:38:31 +00:00
|
|
|
canvas->concat(matrix);
|
2015-10-23 18:13:01 +00:00
|
|
|
|
2020-05-18 20:40:59 +00:00
|
|
|
// First draw a column with no filtering
|
2021-01-23 23:10:39 +00:00
|
|
|
this->drawCase1(canvas, kCol0X, kRow0Y, antiAlias, none);
|
|
|
|
this->drawCase2(canvas, kCol0X, kRow1Y, antiAlias, none);
|
|
|
|
this->drawCase3(canvas, kCol0X, kRow2Y, antiAlias, none);
|
|
|
|
this->drawCase4(canvas, kCol0X, kRow3Y, antiAlias, none);
|
|
|
|
this->drawCase5(canvas, kCol0X, kRow4Y, antiAlias, none);
|
2020-05-18 20:40:59 +00:00
|
|
|
|
|
|
|
// Then draw a column with low filtering
|
2021-01-23 23:10:39 +00:00
|
|
|
this->drawCase1(canvas, kCol1X, kRow0Y, antiAlias, low);
|
|
|
|
this->drawCase2(canvas, kCol1X, kRow1Y, antiAlias, low);
|
|
|
|
this->drawCase3(canvas, kCol1X, kRow2Y, antiAlias, low);
|
|
|
|
this->drawCase4(canvas, kCol1X, kRow3Y, antiAlias, low);
|
|
|
|
this->drawCase5(canvas, kCol1X, kRow4Y, antiAlias, low);
|
2020-05-18 20:40:59 +00:00
|
|
|
|
2020-05-19 14:22:03 +00:00
|
|
|
// Then draw a column with high filtering. Skip it if in kStrict mode and MIP
|
|
|
|
// mapping will be used. On GPU we allow bleeding at non-base levels because
|
|
|
|
// building a new MIP chain for the subset is expensive.
|
|
|
|
SkScalar scales[2];
|
2020-06-01 14:38:31 +00:00
|
|
|
SkAssertResult(matrix.getMinMaxScales(scales));
|
2020-05-19 14:22:03 +00:00
|
|
|
if (fConstraint != SkCanvas::kStrict_SrcRectConstraint || scales[0] >= 1.f) {
|
2021-01-23 23:10:39 +00:00
|
|
|
this->drawCase1(canvas, kCol2X, kRow0Y, antiAlias, high);
|
|
|
|
this->drawCase2(canvas, kCol2X, kRow1Y, antiAlias, high);
|
|
|
|
this->drawCase3(canvas, kCol2X, kRow2Y, antiAlias, high);
|
|
|
|
this->drawCase4(canvas, kCol2X, kRow3Y, antiAlias, high);
|
|
|
|
this->drawCase5(canvas, kCol2X, kRow4Y, antiAlias, high);
|
2020-05-19 14:22:03 +00:00
|
|
|
}
|
2015-10-23 18:13:01 +00:00
|
|
|
|
2020-06-01 14:38:31 +00:00
|
|
|
SkPoint innerCorners[] = {{0, 0}, {0, kBottom}, {kWidth, kBottom}, {kWidth, 0}};
|
|
|
|
matrix.mapPoints(innerCorners, 4);
|
|
|
|
SkScalar x = kBlockSize + std::max({innerCorners[0].fX, innerCorners[1].fX,
|
|
|
|
innerCorners[2].fX, innerCorners[3].fX});
|
2020-02-07 15:36:46 +00:00
|
|
|
maxX = std::max(maxX, x);
|
2015-10-23 18:13:01 +00:00
|
|
|
canvas->restore();
|
2013-11-22 20:34:59 +00:00
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
}
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
|
|
|
|
2015-05-27 20:23:23 +00:00
|
|
|
void modifyGrContextOptions(GrContextOptions* options) override {
|
2021-01-29 19:42:38 +00:00
|
|
|
options->fMaxTextureSizeOverride = kMaxTextureSize;
|
2015-05-27 20:23:23 +00:00
|
|
|
}
|
|
|
|
|
2013-07-25 21:34:00 +00:00
|
|
|
private:
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int kBlockSize = 70;
|
|
|
|
static constexpr int kBlockSpacing = 12;
|
|
|
|
|
|
|
|
static constexpr int kCol0X = kBlockSpacing;
|
|
|
|
static constexpr int kCol1X = 2*kBlockSpacing + kBlockSize;
|
|
|
|
static constexpr int kCol2X = 3*kBlockSpacing + 2*kBlockSize;
|
2020-05-18 20:40:59 +00:00
|
|
|
static constexpr int kWidth = 4*kBlockSpacing + 3*kBlockSize;
|
2016-09-01 18:24:54 +00:00
|
|
|
|
|
|
|
static constexpr int kRow0Y = kBlockSpacing;
|
|
|
|
static constexpr int kRow1Y = 2*kBlockSpacing + kBlockSize;
|
|
|
|
static constexpr int kRow2Y = 3*kBlockSpacing + 2*kBlockSize;
|
|
|
|
static constexpr int kRow3Y = 4*kBlockSpacing + 3*kBlockSize;
|
|
|
|
static constexpr int kRow4Y = 5*kBlockSpacing + 4*kBlockSize;
|
|
|
|
|
|
|
|
static constexpr int kSmallSize = 6;
|
2021-01-29 19:42:38 +00:00
|
|
|
// This must be at least as large as the GM width and height so that a surface can be made.
|
|
|
|
static constexpr int kMaxTextureSize = 1000;
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2020-05-26 14:38:24 +00:00
|
|
|
SkString fShortName;
|
2020-05-15 13:52:29 +00:00
|
|
|
sk_sp<SkImage> fBigImage;
|
|
|
|
sk_sp<SkImage> fSmallImage;
|
2021-01-23 23:10:39 +00:00
|
|
|
SkRect fBigSrcRect;
|
|
|
|
SkRect fSmallSrcRect;
|
2020-05-18 20:40:59 +00:00
|
|
|
SkCanvas::SrcRectConstraint fConstraint;
|
2020-05-26 14:38:24 +00:00
|
|
|
bool fBatch = false;
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2013-07-25 21:34:00 +00:00
|
|
|
};
|
|
|
|
|
2020-05-26 14:38:24 +00:00
|
|
|
DEF_GM(return new SrcRectConstraintGM("strict_constraint_no_red_allowed",
|
|
|
|
SkCanvas::kStrict_SrcRectConstraint,
|
|
|
|
/*batch=*/false););
|
|
|
|
DEF_GM(return new SrcRectConstraintGM("strict_constraint_batch_no_red_allowed",
|
|
|
|
SkCanvas::kStrict_SrcRectConstraint,
|
|
|
|
/*batch=*/true););
|
|
|
|
DEF_GM(return new SrcRectConstraintGM("fast_constraint_red_is_allowed",
|
|
|
|
SkCanvas::kFast_SrcRectConstraint,
|
|
|
|
/*batch=*/false););
|
2016-07-25 15:11:58 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Construct an image and return the inner "src" rect. Build the image such that the interior is
|
|
|
|
// blue, with a margin of blue (2px) but then an outer margin of red.
|
|
|
|
//
|
|
|
|
// Show that kFast_SrcRectConstraint sees even the red margin (due to mipmapping) when the image
|
|
|
|
// is scaled down far enough.
|
|
|
|
//
|
|
|
|
static sk_sp<SkImage> make_image(SkCanvas* canvas, SkRect* srcR) {
|
2016-07-26 15:26:46 +00:00
|
|
|
// Intentially making the size a power of 2 to avoid the noise from how different GPUs will
|
|
|
|
// produce different mipmap filtering when we have an odd sized texture.
|
|
|
|
const int N = 10 + 2 + 8 + 2 + 10;
|
2016-07-25 15:11:58 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(N, N);
|
2019-03-20 16:12:10 +00:00
|
|
|
auto surface = ToolUtils::makeSurface(canvas, info);
|
2016-07-25 15:11:58 +00:00
|
|
|
SkCanvas* c = surface->getCanvas();
|
|
|
|
SkRect r = SkRect::MakeIWH(info.width(), info.height());
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
c->drawRect(r, paint);
|
2016-07-26 15:26:46 +00:00
|
|
|
r.inset(10, 10);
|
2016-07-25 15:11:58 +00:00
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
c->drawRect(r, paint);
|
|
|
|
|
|
|
|
*srcR = r.makeInset(2, 2);
|
|
|
|
return surface->makeImageSnapshot();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_SIMPLE_GM(bleed_downscale, canvas, 360, 240) {
|
|
|
|
SkRect src;
|
|
|
|
sk_sp<SkImage> img = make_image(canvas, &src);
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
canvas->translate(10, 10);
|
|
|
|
|
|
|
|
const SkCanvas::SrcRectConstraint constraints[] = {
|
|
|
|
SkCanvas::kStrict_SrcRectConstraint, SkCanvas::kFast_SrcRectConstraint
|
|
|
|
};
|
2021-01-24 02:14:47 +00:00
|
|
|
const SkSamplingOptions samplings[] = {
|
|
|
|
SkSamplingOptions(SkFilterMode::kNearest),
|
|
|
|
SkSamplingOptions(SkFilterMode::kLinear),
|
|
|
|
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear),
|
2016-07-25 15:11:58 +00:00
|
|
|
};
|
|
|
|
for (auto constraint : constraints) {
|
|
|
|
canvas->save();
|
2021-01-24 02:14:47 +00:00
|
|
|
for (auto sampling : samplings) {
|
2019-03-20 16:12:10 +00:00
|
|
|
auto surf = ToolUtils::makeSurface(canvas, SkImageInfo::MakeN32Premul(1, 1));
|
2021-01-24 02:14:47 +00:00
|
|
|
surf->getCanvas()->drawImageRect(img, src, SkRect::MakeWH(1, 1), sampling,
|
|
|
|
nullptr, constraint);
|
2016-07-25 15:11:58 +00:00
|
|
|
// now blow up the 1 pixel result
|
2021-01-24 02:14:47 +00:00
|
|
|
canvas->drawImageRect(surf->makeImageSnapshot(), SkRect::MakeWH(100, 100),
|
|
|
|
SkSamplingOptions());
|
2016-07-25 15:11:58 +00:00
|
|
|
canvas->translate(120, 0);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, 120);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|