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

Public Member Functions

 SrcRectConstraintGM (const char *shortName, SkCanvas::SrcRectConstraint constraint, bool manual)
 
- 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

SkString getName () const override
 
SkISize getISize () override
 
void drawImage (SkCanvas *canvas, sk_sp< SkImage > image, SkRect srcRect, SkRect dstRect, const SkSamplingOptions &sampling, SkPaint *paint)
 
void drawCase1 (SkCanvas *canvas, int transX, int transY, bool aa, const SkSamplingOptions &sampling)
 
void drawCase2 (SkCanvas *canvas, int transX, int transY, bool aa, const SkSamplingOptions &sampling)
 
void drawCase3 (SkCanvas *canvas, int transX, int transY, bool aa, const SkSamplingOptions &sampling)
 
void drawCase4 (SkCanvas *canvas, int transX, int transY, bool aa, const SkSamplingOptions &sampling)
 
void drawCase5 (SkCanvas *canvas, int transX, int transY, bool aa, const SkSamplingOptions &sampling)
 
void onDraw (SkCanvas *canvas) override
 
void modifyGrContextOptions (GrContextOptions *options) 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

These GMs exercise the behavior of the drawImageRect and its SrcRectConstraint parameter. They tests various matrices, filter qualities, and interaction with mask filters. They also exercise the tiling image draws of SkGpuDevice by overriding the maximum texture size of the GrContext.

Definition at line 118 of file bleed.cpp.

Constructor & Destructor Documentation

◆ SrcRectConstraintGM()

SrcRectConstraintGM::SrcRectConstraintGM ( const char *  shortName,
SkCanvas::SrcRectConstraint  constraint,
bool  manual 
)
inline

Definition at line 120 of file bleed.cpp.

121 : fShortName(shortName)
122 , fConstraint(constraint)
123 , fManual(manual) {
124 // Make sure GPU SkSurfaces can be created for this GM.
125 SkASSERT(this->getISize().width() <= kMaxTextureSize &&
126 this->getISize().height() <= kMaxTextureSize);
127 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkISize getISize() override
Definition: bleed.cpp:131
SkScalar width()
Definition: gm.h:159
SkScalar height()
Definition: gm.h:162

Member Function Documentation

◆ drawCase1()

void SrcRectConstraintGM::drawCase1 ( SkCanvas canvas,
int  transX,
int  transY,
bool  aa,
const SkSamplingOptions sampling 
)
inlineprotected

Definition at line 144 of file bleed.cpp.

145 {
147 SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
148
150 paint.setColor(SK_ColorBLUE);
151 paint.setAntiAlias(aa);
152
153 this->drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint);
154 }
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void drawImage(SkCanvas *canvas, sk_sp< SkImage > image, SkRect srcRect, SkRect dstRect, const SkSamplingOptions &sampling, SkPaint *paint)
Definition: bleed.cpp:133
const Paint & paint
Definition: color_source.cc:38
SkSamplingOptions sampling
Definition: SkRecords.h:337
dst
Definition: cp.py:12
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ drawCase2()

void SrcRectConstraintGM::drawCase2 ( SkCanvas canvas,
int  transX,
int  transY,
bool  aa,
const SkSamplingOptions sampling 
)
inlineprotected

Definition at line 157 of file bleed.cpp.

158 {
160 SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
161
163 paint.setColor(SK_ColorBLUE);
164 paint.setAntiAlias(aa);
165
166 this->drawImage(canvas, fBigImage, fBigSrcRect, dst, sampling, &paint);
167 }

◆ drawCase3()

void SrcRectConstraintGM::drawCase3 ( SkCanvas canvas,
int  transX,
int  transY,
bool  aa,
const SkSamplingOptions sampling 
)
inlineprotected

Definition at line 170 of file bleed.cpp.

171 {
172 SkRect src = SkRect::MakeXYWH(fBigSrcRect.fLeft,
173 fBigSrcRect.fTop,
174 fBigSrcRect.width()/2,
175 fBigSrcRect.height()/2);
177 SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
178
180 paint.setColor(SK_ColorBLUE);
181 paint.setAntiAlias(aa);
182
183 this->drawImage(canvas, fBigImage, src, dst, sampling, &paint);
184 }
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ drawCase4()

void SrcRectConstraintGM::drawCase4 ( SkCanvas canvas,
int  transX,
int  transY,
bool  aa,
const SkSamplingOptions sampling 
)
inlineprotected

Definition at line 187 of file bleed.cpp.

188 {
190 SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
191
195 paint.setColor(SK_ColorBLUE);
196 paint.setAntiAlias(aa);
197
198 this->drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint);
199 }
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
static SkScalar SK_SPI ConvertRadiusToSigma(SkScalar radius)
Definition: SkBlurMask.cpp:39
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)

◆ drawCase5()

void SrcRectConstraintGM::drawCase5 ( SkCanvas canvas,
int  transX,
int  transY,
bool  aa,
const SkSamplingOptions sampling 
)
inlineprotected

Definition at line 202 of file bleed.cpp.

203 {
205 SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
206
210 paint.setColor(SK_ColorBLUE);
211 paint.setAntiAlias(aa);
212
213 this->drawImage(canvas, fSmallImage, fSmallSrcRect, dst, sampling, &paint);
214 }
@ kOuter_SkBlurStyle
nothing inside, fuzzy outside
Definition: SkBlurTypes.h:14

◆ drawImage()

void SrcRectConstraintGM::drawImage ( SkCanvas canvas,
sk_sp< SkImage image,
SkRect  srcRect,
SkRect  dstRect,
const SkSamplingOptions sampling,
SkPaint paint 
)
inlineprotected

Definition at line 133 of file bleed.cpp.

134 {
135 if (fManual) {
136 SkTiledImageUtils::DrawImageRect(canvas, image.get(), srcRect, dstRect,
137 sampling, paint, fConstraint);
138 } else {
139 canvas->drawImageRect(image.get(), srcRect, dstRect, sampling, paint, fConstraint);
140 }
141 }
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
T * get() const
Definition: SkRefCnt.h:303
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SK_API void DrawImageRect(SkCanvas *canvas, const SkImage *image, const SkRect &src, const SkRect &dst, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)

◆ getISize()

SkISize SrcRectConstraintGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 131 of file bleed.cpp.

131{ return SkISize::Make(800, 1000); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString SrcRectConstraintGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 130 of file bleed.cpp.

130{ return fShortName; }

◆ modifyGrContextOptions()

void SrcRectConstraintGM::modifyGrContextOptions ( GrContextOptions options)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 296 of file bleed.cpp.

296 {
297 options->fMaxTextureSizeOverride = kMaxTextureSize;
298 }
const char * options

◆ onDraw()

void SrcRectConstraintGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 216 of file bleed.cpp.

216 {
217 if (!fSmallImage) {
218 std::tie(fBigImage, fBigSrcRect) = make_ringed_image(canvas,
219 2*kMaxTextureSize,
220 2*kMaxTextureSize);
221 std::tie(fSmallImage, fSmallSrcRect) = make_ringed_image(canvas,
222 kSmallSize, kSmallSize);
223 }
224
225 canvas->clear(SK_ColorGRAY);
226 std::vector<SkMatrix> matrices;
227 // Draw with identity
228 matrices.push_back(SkMatrix::I());
229
230 // Draw with rotation and scale down in x, up in y.
231 SkMatrix m;
232 constexpr SkScalar kBottom = SkIntToScalar(kRow4Y + kBlockSize + kBlockSpacing);
233 m.setTranslate(0, kBottom);
234 m.preRotate(15.f, 0, kBottom + kBlockSpacing);
235 m.preScale(0.71f, 1.22f);
236 matrices.push_back(m);
237
238 // Align the next set with the middle of the previous in y, translated to the right in x.
239 SkPoint corners[] = {{0, 0}, {0, kBottom}, {kWidth, kBottom}, {kWidth, 0}};
240 matrices.back().mapPoints(corners, 4);
241 m.setTranslate(std::max({corners[0].fX, corners[1].fX, corners[2].fX, corners[3].fX}),
242 (corners[0].fY + corners[1].fY + corners[2].fY + corners[3].fY) / 4);
243 m.preScale(0.2f, 0.2f);
244 matrices.push_back(m);
245
249
250 SkScalar maxX = 0;
251 for (bool antiAlias : {false, true}) {
252 canvas->save();
253 canvas->translate(maxX, 0);
254 for (const SkMatrix& matrix : matrices) {
255 canvas->save();
256 canvas->concat(matrix);
257
258 // First draw a column with no filtering
259 this->drawCase1(canvas, kCol0X, kRow0Y, antiAlias, none);
260 this->drawCase2(canvas, kCol0X, kRow1Y, antiAlias, none);
261 this->drawCase3(canvas, kCol0X, kRow2Y, antiAlias, none);
262 this->drawCase4(canvas, kCol0X, kRow3Y, antiAlias, none);
263 this->drawCase5(canvas, kCol0X, kRow4Y, antiAlias, none);
264
265 // Then draw a column with low filtering
266 this->drawCase1(canvas, kCol1X, kRow0Y, antiAlias, low);
267 this->drawCase2(canvas, kCol1X, kRow1Y, antiAlias, low);
268 this->drawCase3(canvas, kCol1X, kRow2Y, antiAlias, low);
269 this->drawCase4(canvas, kCol1X, kRow3Y, antiAlias, low);
270 this->drawCase5(canvas, kCol1X, kRow4Y, antiAlias, low);
271
272 // Then draw a column with high filtering. Skip it if in kStrict mode and MIP
273 // mapping will be used. On GPU we allow bleeding at non-base levels because
274 // building a new MIP chain for the subset is expensive.
275 SkScalar scales[2];
276 SkAssertResult(matrix.getMinMaxScales(scales));
277 if (fConstraint != SkCanvas::kStrict_SrcRectConstraint || scales[0] >= 1.f) {
278 this->drawCase1(canvas, kCol2X, kRow0Y, antiAlias, high);
279 this->drawCase2(canvas, kCol2X, kRow1Y, antiAlias, high);
280 this->drawCase3(canvas, kCol2X, kRow2Y, antiAlias, high);
281 this->drawCase4(canvas, kCol2X, kRow3Y, antiAlias, high);
282 this->drawCase5(canvas, kCol2X, kRow4Y, antiAlias, high);
283 }
284
285 SkPoint innerCorners[] = {{0, 0}, {0, kBottom}, {kWidth, kBottom}, {kWidth, 0}};
286 matrix.mapPoints(innerCorners, 4);
287 SkScalar x = kBlockSize + std::max({innerCorners[0].fX, innerCorners[1].fX,
288 innerCorners[2].fX, innerCorners[3].fX});
289 maxX = std::max(maxX, x);
290 canvas->restore();
291 }
292 canvas->restore();
293 }
294 }
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
std::tuple< sk_sp< SkImage >, SkRect > make_ringed_image(SkCanvas *canvas, int width, int height)
Definition: bleed.cpp:42
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
void clear(SkColor color)
Definition: SkCanvas.h:1199
int save()
Definition: SkCanvas.cpp:447
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
void drawCase4(SkCanvas *canvas, int transX, int transY, bool aa, const SkSamplingOptions &sampling)
Definition: bleed.cpp:187
void drawCase5(SkCanvas *canvas, int transX, int transY, bool aa, const SkSamplingOptions &sampling)
Definition: bleed.cpp:202
void drawCase1(SkCanvas *canvas, int transX, int transY, bool aa, const SkSamplingOptions &sampling)
Definition: bleed.cpp:144
void drawCase3(SkCanvas *canvas, int transX, int transY, bool aa, const SkSamplingOptions &sampling)
Definition: bleed.cpp:170
void drawCase2(SkCanvas *canvas, int transX, int transY, bool aa, const SkSamplingOptions &sampling)
Definition: bleed.cpp:157
float SkScalar
Definition: extension.cpp:12
static float max(float r, float g, float b)
Definition: hsl.cpp:49
double x
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
static constexpr SkCubicResampler Mitchell()
float fX
x-axis value
Definition: SkPoint_impl.h:164

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