2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "SkImageSource.h"
11 #include "SkSurface.h"
15 // This GM reproduces the issue in crbug.com/472795. The SkImageSource image
16 // is shifted for high quality mode between cpu and gpu.
17 class ImageSourceGM : public GM {
19 ImageSourceGM(const char* suffix, SkFilterQuality filter) : fSuffix(suffix), fFilter(filter) {
20 this->setBGColor(0xFFFFFFFF);
24 SkString onShortName() override {
25 SkString name("imagesrc2_");
30 SkISize onISize() override { return SkISize::Make(256, 256); }
32 // Create an image with high frequency vertical stripes
33 void onOnceBeforeDraw() override {
34 constexpr SkPMColor gColors[] = {
35 SK_ColorRED, SK_ColorGRAY,
36 SK_ColorGREEN, SK_ColorGRAY,
37 SK_ColorBLUE, SK_ColorGRAY,
38 SK_ColorCYAN, SK_ColorGRAY,
39 SK_ColorMAGENTA, SK_ColorGRAY,
40 SK_ColorYELLOW, SK_ColorGRAY,
41 SK_ColorWHITE, SK_ColorGRAY,
44 auto surface(SkSurface::MakeRasterN32Premul(kImageSize, kImageSize));
45 SkCanvas* canvas = surface->getCanvas();
49 for (int x = 0; x < kImageSize; x += 3) {
50 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(0),
51 SkIntToScalar(3), SkIntToScalar(kImageSize));
53 p.setColor(gColors[curColor]);
54 canvas->drawRect(r, p);
56 curColor = (curColor+1) % SK_ARRAY_COUNT(gColors);
59 fImage = surface->makeImageSnapshot();
62 void onDraw(SkCanvas* canvas) override {
63 const SkRect srcRect = SkRect::MakeLTRB(0, 0,
64 SkIntToScalar(kImageSize),
65 SkIntToScalar(kImageSize));
66 const SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f);
69 p.setImageFilter(SkImageSource::Make(fImage, srcRect, dstRect, fFilter));
71 canvas->saveLayer(nullptr, &p);
76 static constexpr int kImageSize = 503;
79 SkFilterQuality fFilter;
80 sk_sp<SkImage> fImage;
85 //////////////////////////////////////////////////////////////////////////////
87 DEF_GM(return new ImageSourceGM("none", kNone_SkFilterQuality);)
88 DEF_GM(return new ImageSourceGM("low", kLow_SkFilterQuality);)
89 DEF_GM(return new ImageSourceGM("med", kMedium_SkFilterQuality);)
90 DEF_GM(return new ImageSourceGM("high", kHigh_SkFilterQuality);)