Flutter Engine
The Flutter Engine
imagesource2.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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 */
7
8#include "gm/gm.h"
14#include "include/core/SkRect.h"
17#include "include/core/SkSize.h"
22
23namespace skiagm {
24
25// This GM reproduces the issue in crbug.com/472795. The SkImageSource image
26// is shifted for high quality mode between cpu and gpu.
27class ImageSourceGM : public GM {
28public:
30 : fSuffix(suffix), fSampling(sampling) {
31 this->setBGColor(0xFFFFFFFF);
32 }
33
34protected:
35 SkString getName() const override {
36 SkString name("imagesrc2_");
37 name.append(fSuffix);
38 return name;
39 }
40
41 SkISize getISize() override { return SkISize::Make(256, 256); }
42
43 // Create an image with high frequency vertical stripes
44 void onOnceBeforeDraw() override {
45 constexpr SkPMColor gColors[] = {
53 };
54
55 auto surface(SkSurfaces::Raster(SkImageInfo::MakeN32Premul(kImageSize, kImageSize)));
56 SkCanvas* canvas = surface->getCanvas();
57
58 int curColor = 0;
59
60 for (int x = 0; x < kImageSize; x += 3) {
62 SkIntToScalar(3), SkIntToScalar(kImageSize));
63 SkPaint p;
64 p.setColor(gColors[curColor]);
65 canvas->drawRect(r, p);
66
67 curColor = (curColor+1) % std::size(gColors);
68 }
69
70 fImage = surface->makeImageSnapshot();
71 }
72
73 void onDraw(SkCanvas* canvas) override {
74 const SkRect srcRect = SkRect::MakeLTRB(0, 0,
75 SkIntToScalar(kImageSize),
76 SkIntToScalar(kImageSize));
77 const SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f);
78
79 SkPaint p;
80 p.setImageFilter(SkImageFilters::Image(fImage, srcRect, dstRect, fSampling));
81
82 canvas->saveLayer(nullptr, &p);
83 canvas->restore();
84 }
85
86private:
87 inline static constexpr int kImageSize = 503;
88
89 SkString fSuffix;
90 SkSamplingOptions fSampling;
91 sk_sp<SkImage> fImage;
92
93 using INHERITED = GM;
94};
95
96//////////////////////////////////////////////////////////////////////////////
97
98DEF_GM(return new ImageSourceGM("none", SkSamplingOptions());)
102DEF_GM(return new ImageSourceGM("high", SkSamplingOptions({1/3.0f, 1/3.0f}));)
103} // namespace skiagm
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
uint32_t SkPMColor
Definition: SkColor.h:205
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SkIntToScalar(x)
Definition: SkScalar.h:57
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
static sk_sp< SkImageFilter > Image(sk_sp< SkImage > image, const SkRect &srcRect, const SkRect &dstRect, const SkSamplingOptions &sampling)
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
void setBGColor(SkColor)
Definition: gm.cpp:159
void onDraw(SkCanvas *canvas) override
SkString getName() const override
void onOnceBeforeDraw() override
ImageSourceGM(const char *suffix, const SkSamplingOptions &sampling)
SkISize getISize() override
VkSurfaceKHR surface
Definition: main.cc:49
double x
SkSamplingOptions sampling
Definition: SkRecords.h:337
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
SkSamplingOptions(SkFilterMode::kLinear))
constexpr SkColor gColors[]
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646