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

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
void onOnceBeforeDraw () override
 
DrawResult onDraw (SkCanvas *canvas, SkString *errorMsg) override
 
bool onAnimate (double nanos) 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
 
- 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
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 249 of file blurrect.cpp.

Member Function Documentation

◆ getISize()

SkISize skiagm::BlurRectCompareGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 253 of file blurrect.cpp.

253{ return {900, 1220}; }

◆ getName()

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

Implements skiagm::GM.

Definition at line 251 of file blurrect.cpp.

251{ return SkString("blurrect_compare"); }

◆ onAnimate()

bool skiagm::BlurRectCompareGM::onAnimate ( double  nanos)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 330 of file blurrect.cpp.

330 {
331 fSigmaAnimationBoost = TimeUtils::SineWave(nanos, 5, 2.5f, 0.f, 2.f);
332 fRecalcMasksForAnimation = true;
333 return true;
334 }
static float SineWave(double time, float periodInSecs, float phaseInSecs, float min, float max)
Definition: TimeUtils.h:48

◆ onDraw()

DrawResult skiagm::BlurRectCompareGM::onDraw ( SkCanvas canvas,
SkString errorMsg 
)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 257 of file blurrect.cpp.

257 {
258 if (canvas->imageInfo().colorType() == kUnknown_SkColorType ||
259 (canvas->recordingContext() && !canvas->recordingContext()->asDirectContext())) {
260 *errorMsg = "Not supported when recording, relies on canvas->makeSurface()";
261 return DrawResult::kSkip;
262 }
263 int32_t ctxID = canvas->recordingContext() ? canvas->recordingContext()->priv().contextID()
264 : 0;
265 if (fRecalcMasksForAnimation || !fActualMasks[0][0][0] || ctxID != fLastContextUniqueID) {
266 if (fRecalcMasksForAnimation) {
267 // Sigma is changing so references must also be recalculated.
268 this->prepareReferenceMasks();
269 }
270 this->prepareActualMasks(canvas);
271 this->prepareMaskDifferences(canvas);
272 fLastContextUniqueID = ctxID;
273 fRecalcMasksForAnimation = false;
274 }
275 canvas->clear(SK_ColorBLACK);
276 static constexpr float kMargin = 30;
277 float totalW = 0;
278 for (auto w : kSizes) {
279 totalW += w + kMargin;
280 }
281 canvas->translate(kMargin, kMargin);
282 for (int mode = 0; mode < 3; ++mode) {
283 canvas->save();
284 for (size_t sigmaIdx = 0; sigmaIdx < kNumSigmas; ++sigmaIdx) {
285 auto sigma = kSigmas[sigmaIdx] + fSigmaAnimationBoost;
286 for (size_t heightIdx = 0; heightIdx < kNumSizes; ++heightIdx) {
287 auto h = kSizes[heightIdx];
288 canvas->save();
289 for (size_t widthIdx = 0; widthIdx < kNumSizes; ++widthIdx) {
290 auto w = kSizes[widthIdx];
292 paint.setColor(SK_ColorWHITE);
293 SkImage* img;
294 switch (mode) {
295 case 0:
296 img = fReferenceMasks[sigmaIdx][heightIdx][widthIdx].get();
297 break;
298 case 1:
299 img = fActualMasks[sigmaIdx][heightIdx][widthIdx].get();
300 break;
301 case 2:
302 img = fMaskDifferences[sigmaIdx][heightIdx][widthIdx].get();
303 // The error images are opaque, use kPlus so they are additive if
304 // the overlap between test cases.
305 paint.setBlendMode(SkBlendMode::kPlus);
306 break;
307 }
308 auto pad = PadForSigma(sigma);
309 canvas->drawImage(img, -pad, -pad, SkSamplingOptions(), &paint);
310#if 0 // Uncomment to hairline stroke around blurred rect in red on top of the blur result.
311 // The rect is defined at integer coords. We inset by 1/2 pixel so our stroke lies on top
312 // of the edge pixels.
314 stroke.setColor(SK_ColorRED);
315 stroke.setStrokeWidth(0.f);
317 canvas->drawRect(SkRect::MakeWH(w, h).makeInset(0.5, 0.5), stroke);
318#endif
319 canvas->translate(w + kMargin, 0.f);
320 }
321 canvas->restore();
322 canvas->translate(0, h + kMargin);
323 }
324 }
325 canvas->restore();
326 canvas->translate(totalW + 2 * kMargin, 0);
327 }
328 return DrawResult::kOk;
329 }
@ kPlus
r = min(s + d, 1)
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
constexpr int kMargin
Definition: aaxfermodes.cpp:31
uint32_t contextID() const
virtual GrDirectContext * asDirectContext()
GrRecordingContextPriv priv()
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
void clear(SkColor color)
Definition: SkCanvas.h:1199
int save()
Definition: SkCanvas.cpp:447
SkImageInfo imageInfo() const
Definition: SkCanvas.cpp:1206
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
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 mode
Definition: switches.h:228
SkSamplingOptions(SkFilterMode::kLinear))
SkScalar w
SkScalar h
SkColorType colorType() const
Definition: SkImageInfo.h:373
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ onOnceBeforeDraw()

void skiagm::BlurRectCompareGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 255 of file blurrect.cpp.

255{ this->prepareReferenceMasks(); }

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