skia2/gm/imagesource2.cpp
Brian Salomon 9fa47cc1c6 Make class members that are static constexpr also be inline.
This is in prep for compiling with -std=c++14 and -Wno-c++17-extensions
when building with clang. Chrome has encountered problems with
third_party headers that are included both in Skia and other Chrome
sources that produce different code based on whether preprocessor macros
indicate a C++14 or C++17 compilation.

In C++17 they are already inline implicitly. When compiling with C++14
we can get linker errors unless they're explicitly inlined or defined
outside the class. With -Wno-c++17-extensions we can explicitly inline
them in the C++14 build because the warning that would be generated
about using a C++17 language extension is suppressed.

We cannot do this in public headers because we support compiling with
C++14 without suppressing the C++17 language extension warnings.

Bug: chromium:1257145
Change-Id: Iaf5f4c62a398f98dd4ca9b7dfb86f2d5cab21d66
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/457498
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2021-10-11 16:22:59 +00:00

104 lines
3.4 KiB
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
#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"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkImageFilters.h"
namespace skiagm {
// This GM reproduces the issue in crbug.com/472795. The SkImageSource image
// is shifted for high quality mode between cpu and gpu.
class ImageSourceGM : public GM {
public:
ImageSourceGM(const char* suffix, const SkSamplingOptions& sampling)
: fSuffix(suffix), fSampling(sampling) {
this->setBGColor(0xFFFFFFFF);
}
protected:
SkString onShortName() override {
SkString name("imagesrc2_");
name.append(fSuffix);
return name;
}
SkISize onISize() override { return SkISize::Make(256, 256); }
// Create an image with high frequency vertical stripes
void onOnceBeforeDraw() override {
constexpr SkPMColor gColors[] = {
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,
};
auto surface(SkSurface::MakeRasterN32Premul(kImageSize, kImageSize));
SkCanvas* canvas = surface->getCanvas();
int curColor = 0;
for (int x = 0; x < kImageSize; x += 3) {
SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(0),
SkIntToScalar(3), SkIntToScalar(kImageSize));
SkPaint p;
p.setColor(gColors[curColor]);
canvas->drawRect(r, p);
curColor = (curColor+1) % SK_ARRAY_COUNT(gColors);
}
fImage = surface->makeImageSnapshot();
}
void onDraw(SkCanvas* canvas) override {
const SkRect srcRect = SkRect::MakeLTRB(0, 0,
SkIntToScalar(kImageSize),
SkIntToScalar(kImageSize));
const SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f);
SkPaint p;
p.setImageFilter(SkImageFilters::Image(fImage, srcRect, dstRect, fSampling));
canvas->saveLayer(nullptr, &p);
canvas->restore();
}
private:
inline static constexpr int kImageSize = 503;
SkString fSuffix;
SkSamplingOptions fSampling;
sk_sp<SkImage> fImage;
using INHERITED = GM;
};
//////////////////////////////////////////////////////////////////////////////
DEF_GM(return new ImageSourceGM("none", SkSamplingOptions());)
DEF_GM(return new ImageSourceGM("low", SkSamplingOptions(SkFilterMode::kLinear));)
DEF_GM(return new ImageSourceGM("med", SkSamplingOptions(SkFilterMode::kLinear,
SkMipmapMode::kLinear));)
DEF_GM(return new ImageSourceGM("high", SkSamplingOptions({1/3.0f, 1/3.0f}));)
} // namespace skiagm