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

Public Types

enum  Type {
  kBW_Draw_Type , kAA_Draw_Type , kBW_Clip_Type , kAA_Clip_Type ,
  kEffect_Type
}
 
- 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

 RRectGM (Type type)
 
- 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

void onOnceBeforeDraw () override
 
SkString getName () const override
 
SkISize getISize () override
 
DrawResult onDraw (SkCanvas *canvas, SkString *errorMsg) override
 
void setUpRRects ()
 
- 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

- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 40 of file rrects.cpp.

Member Enumeration Documentation

◆ Type

Enumerator
kBW_Draw_Type 
kAA_Draw_Type 
kBW_Clip_Type 
kAA_Clip_Type 
kEffect_Type 

Definition at line 42 of file rrects.cpp.

Constructor & Destructor Documentation

◆ RRectGM()

skiagm::RRectGM::RRectGM ( Type  type)
inline

Definition at line 49 of file rrects.cpp.

49: fType(type) { }
GLenum type

Member Function Documentation

◆ getISize()

SkISize skiagm::RRectGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 80 of file rrects.cpp.

80{ return SkISize::Make(kImageWidth, kImageHeight); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

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

Implements skiagm::GM.

Definition at line 58 of file rrects.cpp.

58 {
59 SkString name("rrect");
60 switch (fType) {
61 case kBW_Draw_Type:
62 name.append("_draw_bw");
63 break;
64 case kAA_Draw_Type:
65 name.append("_draw_aa");
66 break;
67 case kBW_Clip_Type:
68 name.append("_clip_bw");
69 break;
70 case kAA_Clip_Type:
71 name.append("_clip_aa");
72 break;
73 case kEffect_Type:
74 name.append("_effect");
75 break;
76 }
77 return name;
78 }
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 82 of file rrects.cpp.

82 {
84
85 auto rContext = canvas->recordingContext();
86 if (kEffect_Type == fType && (!sdc || !rContext)) {
88 return DrawResult::kSkip;
89 }
90
92 if (kAA_Draw_Type == fType) {
93 paint.setAntiAlias(true);
94 }
95
96 if (fType == kBW_Clip_Type || fType == kAA_Clip_Type) {
97 // Add a gradient to the paint to ensure local coords are respected.
98 SkPoint pts[3] = {{0, 0}, {1.5f, 1}};
100 paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2,
102 }
103
104#ifdef SK_DEBUG
105 const SkRect kMaxImageBound = SkRect::MakeWH(SkIntToScalar(kImageWidth),
106 SkIntToScalar(kImageHeight));
107#endif
108
109 int lastEdgeType = (kEffect_Type == fType) ? (int) GrClipEdgeType::kLast: 0;
110
111 int y = 1;
112 for (int et = 0; et <= lastEdgeType; ++et) {
113 int x = 1;
114 for (int curRRect = 0; curRRect < kNumRRects; ++curRRect) {
115 bool drew = true;
116#ifdef SK_DEBUG
117 if (curRRect != kNumRRects - 1) { // skip last rrect, which is large but clipped
118 SkRect imageSpaceBounds = fRRects[curRRect].getBounds();
119 imageSpaceBounds.offset(SkIntToScalar(x), SkIntToScalar(y));
120 SkASSERT(kMaxImageBound.contains(imageSpaceBounds));
121 }
122#endif
123 canvas->save();
125
126 SkRRect rrect = fRRects[curRRect];
127 if (curRRect == kNumRRects - 1) {
128 canvas->clipRect({0, 0, kTileX - 2, kTileY - 2});
129 canvas->translate(-0.14f * rrect.rect().width(),
130 -0.14f * rrect.rect().height());
131 }
132 if (kEffect_Type == fType) {
133 fRRects[curRRect].transform(canvas->getLocalToDeviceAs3x3(), &rrect);
134
135 GrClipEdgeType edgeType = (GrClipEdgeType) et;
136 const auto& caps = *rContext->priv().caps()->shaderCaps();
137 auto [success, fp] = GrRRectEffect::Make(/*inputFP=*/nullptr,
138 edgeType, rrect, caps);
139 if (success) {
140 GrPaint grPaint;
142 grPaint.setCoverageFragmentProcessor(std::move(fp));
143 grPaint.setColor4f({ 0, 0, 0, 1.f });
144
146 bounds.intersect(SkRect::MakeXYWH(x, y, kTileX - 2, kTileY - 2));
147 if (et >= (int) GrClipEdgeType::kInverseFillBW) {
148 bounds.outset(2.f, 2.f);
149 }
150
152 rContext, std::move(grPaint), SkMatrix::I(), bounds));
153 } else {
154 drew = false;
155 }
156 } else if (fType == kBW_Clip_Type || fType == kAA_Clip_Type) {
157 bool aaClip = (kAA_Clip_Type == fType);
158 canvas->clipRRect(rrect, aaClip);
159 canvas->setMatrix(SkMatrix::Scale(kImageWidth, kImageHeight));
160 canvas->drawRect(SkRect::MakeWH(1, 1), paint);
161 } else {
162 canvas->drawRRect(rrect, paint);
163 }
164
165 canvas->restore();
166 if (drew) {
167 x = x + kTileX;
168 if (x > kImageWidth) {
169 x = 1;
170 y += kTileY;
171 }
172 }
173 }
174 if (x != 1) {
175 y += kTileY;
176 }
177 }
178 return DrawResult::kOk;
179 }
GrClipEdgeType
Definition: GrTypesPriv.h:361
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void setXPFactory(const GrXPFactory *xpFactory)
Definition: GrPaint.h:53
void setColor4f(const SkPMColor4f &color)
Definition: GrPaint.h:50
void setCoverageFragmentProcessor(std::unique_ptr< GrFragmentProcessor > fp)
Definition: GrPaint.h:75
static const GrXPFactory * Get(SkBlendMode blendMode)
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
SkMatrix getLocalToDeviceAs3x3() const
Definition: SkCanvas.h:2222
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
Definition: SkCanvas.cpp:1705
int save()
Definition: SkCanvas.cpp:447
void setMatrix(const SkM44 &matrix)
Definition: SkCanvas.cpp:1349
void clipRRect(const SkRRect &rrect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1439
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)
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
const SkRect & rect() const
Definition: SkRRect.h:264
bool transform(const SkMatrix &matrix, SkRRect *dst) const
Definition: SkRRect.cpp:436
const SkRect & getBounds() const
Definition: SkRRect.h:279
static GrOp::Owner MakeNonAARect(GrRecordingContext *, GrPaint &&, const SkMatrix &view, const SkRect &, const GrUserStencilSettings *=nullptr)
Definition: FillRectOp.cpp:480
static constexpr char kErrorMsg_DrawSkippedGpuOnly[]
Definition: gm.h:127
const Paint & paint
Definition: color_source.cc:38
double y
double x
GrFPResult Make(std::unique_ptr< GrFragmentProcessor >, GrClipEdgeType, const SkRRect &, const GrShaderCaps &)
Optional< SkRect > bounds
Definition: SkRecords.h:189
SkRRect rrect
Definition: SkRecords.h:232
PODArray< SkColor > colors
Definition: SkRecords.h:276
const uint32_t fp
SurfaceDrawContext * TopDeviceSurfaceDrawContext(const SkCanvas *canvas)
Definition: GrCanvas.cpp:20
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
bool contains(SkScalar x, SkScalar y) const
Definition: extension.cpp:19
void offset(float dx, float dy)
Definition: SkRect.h:1016
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ onOnceBeforeDraw()

void skiagm::RRectGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 53 of file rrects.cpp.

53 {
54 this->setBGColor(0xFFDDDDDD);
55 this->setUpRRects();
56 }
void setBGColor(SkColor)
Definition: gm.cpp:159
void setUpRRects()
Definition: rrects.cpp:181

◆ setUpRRects()

void skiagm::RRectGM::setUpRRects ( )
inlineprotected

Definition at line 181 of file rrects.cpp.

181 {
182 // each RRect must fit in a 0x0 -> (kTileX-2)x(kTileY-2) block. These will be tiled across
183 // the screen in kTileX x kTileY tiles. The extra empty pixels on each side are for AA.
184
185 // simple cases
186 fRRects[0].setRect(SkRect::MakeWH(kTileX-2, kTileY-2));
187 fRRects[1].setOval(SkRect::MakeWH(kTileX-2, kTileY-2));
188 fRRects[2].setRectXY(SkRect::MakeWH(kTileX-2, kTileY-2), 10, 10);
189 fRRects[3].setRectXY(SkRect::MakeWH(kTileX-2, kTileY-2), 10, 5);
190 // small circular corners are an interesting test case for gpu clipping
191 fRRects[4].setRectXY(SkRect::MakeWH(kTileX-2, kTileY-2), 1, 1);
192 fRRects[5].setRectXY(SkRect::MakeWH(kTileX-2, kTileY-2), 0.5f, 0.5f);
193 fRRects[6].setRectXY(SkRect::MakeWH(kTileX-2, kTileY-2), 0.2f, 0.2f);
194
195 // The first complex case needs special handling since it is a square
196 fRRects[kNumSimpleCases].setRectRadii(SkRect::MakeWH(kTileY-2, kTileY-2), gRadii[0]);
197 for (size_t i = 1; i < std::size(gRadii); ++i) {
198 fRRects[kNumSimpleCases+i].setRectRadii(SkRect::MakeWH(kTileX-2, kTileY-2), gRadii[i]);
199 }
200 // The last case is larger than kTileX-2 x kTileY-2 but will be drawn at an offset
201 // into a clip rect that respects the tile size and highlights the rrect's corner curve.
202 fRRects[kNumRRects - 1].setRectXY({9.f, 9.f, 1699.f, 1699.f}, 843.749f, 843.75f);
203 }
void setOval(const SkRect &oval)
Definition: SkRRect.cpp:30
void setRectRadii(const SkRect &rect, const SkVector radii[4])
Definition: SkRRect.cpp:189
void setRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition: SkRRect.cpp:52
void setRect(const SkRect &rect)
Definition: SkRRect.h:126
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

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