2015-04-09 13:47:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 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 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkFilterQuality.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImage.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkImageFilter.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2019-08-02 19:21:23 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2015-04-09 13:47:12 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
2015-09-15 18:26:13 +00:00
|
|
|
// This GM reproduces the issue in crbug.com/472795. The SkImageSource image
|
2015-04-09 13:47:12 +00:00
|
|
|
// is shifted for high quality mode between cpu and gpu.
|
2015-09-15 18:26:13 +00:00
|
|
|
class ImageSourceGM : public GM {
|
2015-04-09 13:47:12 +00:00
|
|
|
public:
|
2015-09-15 18:26:13 +00:00
|
|
|
ImageSourceGM(const char* suffix, SkFilterQuality filter) : fSuffix(suffix), fFilter(filter) {
|
2015-04-09 13:47:12 +00:00
|
|
|
this->setBGColor(0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
2015-09-15 18:26:13 +00:00
|
|
|
SkString name("imagesrc2_");
|
2015-04-09 13:47:12 +00:00
|
|
|
name.append(fSuffix);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override { return SkISize::Make(256, 256); }
|
|
|
|
|
2015-09-15 18:26:13 +00:00
|
|
|
// Create an image with high frequency vertical stripes
|
2015-04-09 13:47:12 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkPMColor gColors[] = {
|
2015-04-09 13:47:12 +00:00
|
|
|
SK_ColorRED, SK_ColorGRAY,
|
|
|
|
SK_ColorGREEN, SK_ColorGRAY,
|
|
|
|
SK_ColorBLUE, SK_ColorGRAY,
|
|
|
|
SK_ColorCYAN, SK_ColorGRAY,
|
|
|
|
SK_ColorMAGENTA, SK_ColorGRAY,
|
|
|
|
SK_ColorYELLOW, SK_ColorGRAY,
|
|
|
|
SK_ColorWHITE, SK_ColorGRAY,
|
|
|
|
};
|
|
|
|
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(SkSurface::MakeRasterN32Premul(kImageSize, kImageSize));
|
2015-09-15 18:26:13 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
2015-04-09 13:47:12 +00:00
|
|
|
|
|
|
|
int curColor = 0;
|
|
|
|
|
|
|
|
for (int x = 0; x < kImageSize; x += 3) {
|
2016-03-29 16:03:52 +00:00
|
|
|
SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(0),
|
2015-04-09 13:47:12 +00:00
|
|
|
SkIntToScalar(3), SkIntToScalar(kImageSize));
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(gColors[curColor]);
|
2015-09-15 18:26:13 +00:00
|
|
|
canvas->drawRect(r, p);
|
2015-04-09 13:47:12 +00:00
|
|
|
|
|
|
|
curColor = (curColor+1) % SK_ARRAY_COUNT(gColors);
|
|
|
|
}
|
2015-09-15 18:26:13 +00:00
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
fImage = surface->makeImageSnapshot();
|
2015-04-09 13:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2016-04-01 16:28:51 +00:00
|
|
|
const SkRect srcRect = SkRect::MakeLTRB(0, 0,
|
|
|
|
SkIntToScalar(kImageSize),
|
|
|
|
SkIntToScalar(kImageSize));
|
|
|
|
const SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f);
|
2015-04-09 13:47:12 +00:00
|
|
|
|
|
|
|
SkPaint p;
|
2019-08-02 19:21:23 +00:00
|
|
|
p.setImageFilter(SkImageFilters::Image(fImage, srcRect, dstRect, fFilter));
|
2015-04-09 13:47:12 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->saveLayer(nullptr, &p);
|
2015-04-09 13:47:12 +00:00
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int kImageSize = 503;
|
2015-04-09 13:47:12 +00:00
|
|
|
|
|
|
|
SkString fSuffix;
|
|
|
|
SkFilterQuality fFilter;
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> fImage;
|
2015-04-09 13:47:12 +00:00
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-09-15 18:26:13 +00:00
|
|
|
DEF_GM(return new ImageSourceGM("none", kNone_SkFilterQuality);)
|
|
|
|
DEF_GM(return new ImageSourceGM("low", kLow_SkFilterQuality);)
|
|
|
|
DEF_GM(return new ImageSourceGM("med", kMedium_SkFilterQuality);)
|
|
|
|
DEF_GM(return new ImageSourceGM("high", kHigh_SkFilterQuality);)
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|