Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
skiagm::MatrixConvolutionGM Class Reference
Inheritance diagram for skiagm::MatrixConvolutionGM:
skiagm::GM

Public Member Functions

 MatrixConvolutionGM (SkColor colorOne, SkColor colorTwo, KernelFixture kernelFixture, const char *nameSuffix)
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
virtual SkISize getISize ()=0
 
virtual SkString getName () const =0
 
virtual bool runAsBench () const
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual bool isBazelOnly () const
 
virtual std::map< std::string, std::string > getGoldKeys () const
 

Protected Member Functions

bool runAsBench () const override
 
SkString getName () const override
 
void makeBitmap ()
 
SkISize getISize () override
 
sk_sp< SkImageFiltermakeFilter (const SkIPoint &kernelOffsetIn, SkTileMode tileMode, bool convolveAlpha)
 
void draw (SkCanvas *canvas, int x, int y, const SkIPoint &kernelOffset, SkTileMode tileMode, bool convolveAlpha, const SkIRect *cropRect=nullptr)
 
void onOnceBeforeDraw () override
 
void onDraw (SkCanvas *canvas) override
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onOnceBeforeDraw ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual void onDraw (SkCanvas *)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Additional Inherited Members

- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 40 of file matrixconvolution.cpp.

Constructor & Destructor Documentation

◆ MatrixConvolutionGM()

skiagm::MatrixConvolutionGM::MatrixConvolutionGM ( SkColor  colorOne,
SkColor  colorTwo,
KernelFixture  kernelFixture,
const char *  nameSuffix 
)
inline

Definition at line 42 of file matrixconvolution.cpp.

43 : fNameSuffix(nameSuffix),
44 fKernelFixture(kernelFixture) {
45 this->setBGColor(0x00000000);
46 fColors[0] = colorOne;
47 fColors[1] = colorTwo;
48 }
void setBGColor(SkColor)
Definition: gm.cpp:159

Member Function Documentation

◆ draw()

void skiagm::MatrixConvolutionGM::draw ( SkCanvas canvas,
int  x,
int  y,
const SkIPoint kernelOffset,
SkTileMode  tileMode,
bool  convolveAlpha,
const SkIRect cropRect = nullptr 
)
inlineprotected

Definition at line 130 of file matrixconvolution.cpp.

132 {
134 auto filter = this->makeFilter(kernelOffset, tileMode, convolveAlpha);
135 if (cropRect) {
136 filter = SkImageFilters::Crop(SkRect::Make(*cropRect), std::move(filter));
137 }
138 paint.setImageFilter(std::move(filter));
139 canvas->save();
141 canvas->drawImage(fImage, 0, 0, {}, &paint);
142 canvas->restore();
143 }
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static sk_sp< SkImageFilter > Crop(const SkRect &rect, SkTileMode tileMode, sk_sp< SkImageFilter > input)
sk_sp< SkImageFilter > makeFilter(const SkIPoint &kernelOffsetIn, SkTileMode tileMode, bool convolveAlpha)
const Paint & paint
Definition: color_source.cc:38
double y
double x
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669

◆ getISize()

SkISize skiagm::MatrixConvolutionGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 70 of file matrixconvolution.cpp.

70{ return SkISize::Make(500, 300); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString skiagm::MatrixConvolutionGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 53 of file matrixconvolution.cpp.

53{ return SkStringPrintf("matrixconvolution%s", fNameSuffix); }
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.

◆ makeBitmap()

void skiagm::MatrixConvolutionGM::makeBitmap ( )
inlineprotected

Definition at line 55 of file matrixconvolution.cpp.

55 {
56 // Draw our bitmap in N32, so legacy devices get "premul" values they understand
59 paint.setColor(0xFFFFFFFF);
60 SkPoint pts[2] = { {0, 0},
61 {0, 80.0f} };
62 SkScalar pos[2] = { 0, 80.0f };
64 pts, fColors, pos, 2, SkTileMode::kClamp));
66 surf->getCanvas()->drawString("e", -10.0f, 80.0f, font, paint);
67 fImage = surf->makeImageSnapshot();
68 }
SkPoint pos
Definition: SkFont.h:35
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
float SkScalar
Definition: extension.cpp:12
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
sk_sp< SkTypeface > DefaultPortableTypeface()
font
Font Metadata and Metrics.
static SkImageInfo MakeN32Premul(int width, int height)

◆ makeFilter()

sk_sp< SkImageFilter > skiagm::MatrixConvolutionGM::makeFilter ( const SkIPoint kernelOffsetIn,
SkTileMode  tileMode,
bool  convolveAlpha 
)
inlineprotected

Definition at line 72 of file matrixconvolution.cpp.

74 {
75 // The kernelOffset is specified in a 0..2 coordinate space.
76 float normalizedXOffset = kernelOffsetIn.fX / 2.0f;
77 float normalizedYOffset = kernelOffsetIn.fY / 2.0f;
78 // Must provide a cropping geometry in order for 'tileMode' to be well defined.
79 SkIRect tileBoundary = fImage->bounds();
80 switch (fKernelFixture) {
82 SkIPoint kernelOffset {SkScalarRoundToInt(2*normalizedXOffset),
83 SkScalarRoundToInt(2*normalizedYOffset)};
84 // All 1s except center value, which is -7 (sum of 1).
85 std::vector<SkScalar> kernel(9, SkIntToScalar(1));
86 kernel[4] = SkIntToScalar(-7);
88 {3,3}, kernel.data(), /* gain= */ 0.3f, /* bias= */ 100.0f,
89 kernelOffset, tileMode, convolveAlpha, nullptr, tileBoundary);
90 }
92 SkIPoint kernelOffset {SkScalarRoundToInt(6*normalizedXOffset),
93 SkScalarRoundToInt(6*normalizedYOffset)};
94 // This ensures the texture fallback path will be taken
95 static_assert(49 > skgpu::kMaxBlurSamples);
96 // All 1s except center value, which is -47 (sum of 1).
97 std::vector<SkScalar> kernel(49, SkIntToScalar(1));
98 kernel[24] = SkIntToScalar(-47);
100 {7,7}, kernel.data(), /* gain= */ 0.3f, /* bias= */ 100.0f,
101 kernelOffset, tileMode, convolveAlpha, nullptr, tileBoundary);
102 }
104 SkIPoint kernelOffset {SkScalarRoundToInt(127*normalizedXOffset), 0};
105 // This ensures the texture fallback path will be taken
106 static_assert(128 > skgpu::kMaxBlurSamples);
107 std::vector<float> kernel(128, 0.0f);
108 kernel[64] = 0.5f;
109 kernel[65] = -0.5f;
111 {128,1}, kernel.data(), /* gain= */ 0.3f, /* bias= */ 100.0f,
112 kernelOffset, tileMode, convolveAlpha, nullptr, tileBoundary);
113 }
115 SkIPoint kernelOffset {0, SkScalarRoundToInt(254*normalizedYOffset)};
116 // This ensures the texture fallback path will be taken
117 static_assert(255 > skgpu::kMaxBlurSamples);
118 std::vector<float> kernel(255, 0.0f);
119 kernel[126] = 0.5f;
120 kernel[128] = -0.5f;
122 {1,255}, kernel.data(), /* gain= */ 0.3f, /* bias= */ 100.0f,
123 kernelOffset, tileMode, convolveAlpha, nullptr, tileBoundary);
124 }
125 default:
126 return nullptr;
127 }
128 }
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:37
static sk_sp< SkImageFilter > MatrixConvolution(const SkISize &kernelSize, const SkScalar kernel[], SkScalar gain, SkScalar bias, const SkIPoint &kernelOffset, SkTileMode tileMode, bool convolveAlpha, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
SkIRect bounds() const
Definition: SkImage.h:303
static constexpr int kMaxBlurSamples
Definition: BlurUtils.h:35
@ kLargest_KernelFixture
int32_t fX
x-axis value
Definition: SkPoint_impl.h:29
int32_t fY
y-axis value
Definition: SkPoint_impl.h:30
Definition: SkRect.h:32

◆ onDraw()

void skiagm::MatrixConvolutionGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 149 of file matrixconvolution.cpp.

149 {
150 canvas->clear(SK_ColorBLACK);
151 SkIPoint kernelOffset = SkIPoint::Make(1, 0);
152 for (int x = 10; x < 310; x += 100) {
153 this->draw(canvas, x, 10, kernelOffset, SkTileMode::kClamp, true);
154 this->draw(canvas, x, 110, kernelOffset, SkTileMode::kDecal, true);
155 this->draw(canvas, x, 210, kernelOffset, SkTileMode::kRepeat, true);
156 kernelOffset.fY++;
157 }
158 kernelOffset.fY = 1;
159 SkIRect smallRect = SkIRect::MakeXYWH(10, 5, 60, 60);
160 this->draw(canvas, 310, 10, kernelOffset, SkTileMode::kClamp, true, &smallRect);
161 this->draw(canvas, 310, 110, kernelOffset, SkTileMode::kDecal, true, &smallRect);
162 this->draw(canvas, 310, 210, kernelOffset, SkTileMode::kRepeat, true, &smallRect);
163
164 this->draw(canvas, 410, 10, kernelOffset, SkTileMode::kClamp, false);
165 this->draw(canvas, 410, 110, kernelOffset, SkTileMode::kDecal, false);
166 this->draw(canvas, 410, 210, kernelOffset, SkTileMode::kRepeat, false);
167 }
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
void clear(SkColor color)
Definition: SkCanvas.h:1199
void draw(SkCanvas *canvas, int x, int y, const SkIPoint &kernelOffset, SkTileMode tileMode, bool convolveAlpha, const SkIRect *cropRect=nullptr)
static constexpr SkIPoint Make(int32_t x, int32_t y)
Definition: SkPoint_impl.h:38
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104

◆ onOnceBeforeDraw()

void skiagm::MatrixConvolutionGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 145 of file matrixconvolution.cpp.

145 {
146 this->makeBitmap();
147 }

◆ runAsBench()

bool skiagm::MatrixConvolutionGM::runAsBench ( ) const
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 51 of file matrixconvolution.cpp.

51{ return true; }

The documentation for this class was generated from the following file: