Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | Static Protected Attributes | List of all members
skiagm::BezierConicEffects Class Reference
Inheritance diagram for skiagm::BezierConicEffects:

Public Member Functions

 BezierConicEffects ()
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
DrawResult onDraw (GrRecordingContext *rContext, SkCanvas *canvas, SkString *errorMsg) override
 

Static Protected Attributes

static const int kNumConics = 10
 
static const int kCellWidth = 128
 
static const int kCellHeight = 128
 

Detailed Description

This GM directly exercises effects that draw Bezier curves in the GPU backend.

Definition at line 212 of file beziereffects.cpp.

Constructor & Destructor Documentation

◆ BezierConicEffects()

skiagm::BezierConicEffects::BezierConicEffects ( )
inline

Definition at line 214 of file beziereffects.cpp.

214 {
215 this->setBGColor(0xFFFFFFFF);
216 }

Member Function Documentation

◆ getISize()

SkISize skiagm::BezierConicEffects::getISize ( )
inlineoverrideprotected

Definition at line 225 of file beziereffects.cpp.

static const int kCellHeight
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString skiagm::BezierConicEffects::getName ( ) const
inlineoverrideprotected

Definition at line 223 of file beziereffects.cpp.

223{ return SkString("bezier_conic_effects"); }

◆ onDraw()

DrawResult skiagm::BezierConicEffects::onDraw ( GrRecordingContext rContext,
SkCanvas canvas,
SkString errorMsg 
)
inlineoverrideprotected

Definition at line 227 of file beziereffects.cpp.

227 {
229 if (!sdc) {
230 *errorMsg = kErrorMsg_DrawSkippedGpuOnly;
231 return DrawResult::kSkip;
232 }
233
234 const SkScalar w = kCellWidth, h = kCellHeight;
236
237 const SkPoint baseControlPts[kNumConics][3] = {
238 { { 0.31f * w, 0.01f * h}, { 0.48f * w, 0.74f * h }, { 0.19f * w, 0.33f * h } },
239 { { 0.00f * w, 0.07f * h}, { 0.30f * w, 0.70f * h }, { 0.47f * w, 0.37f * h } },
240 { { 0.15f * w, 0.23f * h}, { 0.49f * w, 0.87f * h }, { 0.85f * w, 0.66f * h } },
241 { { 0.09f * w, 0.15f * h}, { 0.42f * w, 0.33f * h }, { 0.17f * w, 0.38f * h } },
242 { { 0.98f * w, 0.54f * h}, { 0.83f * w, 0.91f * h }, { 0.62f * w, 0.40f * h } },
243 { { 0.96f * w, 0.65f * h}, { 0.03f * w, 0.79f * h }, { 0.24f * w, 0.56f * h } },
244 { { 0.57f * w, 0.12f * h}, { 0.33f * w, 0.67f * h }, { 0.59f * w, 0.33f * h } },
245 { { 0.12f * w, 0.72f * h}, { 0.69f * w, 0.85f * h }, { 0.46f * w, 0.32f * h } },
246 { { 0.27f * w, 0.49f * h}, { 0.41f * w, 0.02f * h }, { 0.11f * w, 0.42f * h } },
247 { { 0.40f * w, 0.13f * h}, { 0.83f * w, 0.30f * h }, { 0.31f * w, 0.68f * h } },
248 };
249 const SkScalar weights[kNumConics] = { 0.62f, 0.01f, 0.95f, 1.48f, 0.37f,
250 0.66f, 0.15f, 0.14f, 0.61f, 1.4f };
251
252 SkPaint ctrlPtPaint;
253 ctrlPtPaint.setColor(SK_ColorRED);
254
255 SkPaint choppedPtPaint;
256 choppedPtPaint.setColor(~ctrlPtPaint.getColor() | 0xFF000000);
257
258 SkPaint polyPaint;
259 polyPaint.setColor(0xffA0A0A0);
260 polyPaint.setStrokeWidth(0);
262
263 SkPaint boundsPaint;
264 boundsPaint.setColor(0xff808080);
265 boundsPaint.setStrokeWidth(0);
266 boundsPaint.setStyle(SkPaint::kStroke_Style);
267
268
269 for (int row = 0; row < kNumConics; ++row) {
270 SkScalar x = 0;
271 SkScalar y = row * h;
272 SkPoint controlPts[] = {
273 {x + baseControlPts[row][0].fX, y + baseControlPts[row][0].fY},
274 {x + baseControlPts[row][1].fX, y + baseControlPts[row][1].fY},
275 {x + baseControlPts[row][2].fX, y + baseControlPts[row][2].fY}
276 };
277
278 for (int i = 0; i < 3; ++i) {
279 canvas->drawCircle(controlPts[i], 6.f, ctrlPtPaint);
280 }
281
282 canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, controlPts, polyPaint);
283
284 SkConic dst[4];
285 SkMatrix klm;
286 int cnt = ChopConic(controlPts, dst, weights[row]);
287 GrPathUtils::getConicKLM(controlPts, weights[row], &klm);
288
289 for (int c = 0; c < cnt; ++c) {
290 SkPoint* pts = dst[c].fPts;
291 for (int i = 0; i < 3; ++i) {
292 canvas->drawCircle(pts[i], 3.f, choppedPtPaint);
293 }
294
296 bounds.setBounds(pts, 3);
297
298 canvas->drawRect(bounds, boundsPaint);
299
301 kOpaqueBlack, klm);
302 sdc->addDrawOp(std::move(op));
303 }
304 }
305
306 return DrawResult::kOk;
307 }
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
std::unique_ptr< GrOp > Owner
Definition: GrOp.h:72
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
Definition: SkCanvas.cpp:1710
@ kPolygon_PointMode
draw the array of points as a open polygon
Definition: SkCanvas.h:1243
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
SkColor getColor() const
Definition: SkPaint.h:225
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
static GrOp::Owner Make(GrRecordingContext *context, const SkRect &rect, const SkPMColor4f &color, const SkMatrix &klm)
float SkScalar
Definition: extension.cpp:12
double y
double x
void getConicKLM(const SkPoint p[3], const SkScalar weight, SkMatrix *klm)
Optional< SkRect > bounds
Definition: SkRecords.h:189
constexpr int kOpaqueBlack
dst
Definition: cp.py:12
SurfaceDrawContext * TopDeviceSurfaceDrawContext(const SkCanvas *canvas)
Definition: GrCanvas.cpp:20
SkScalar w
SkScalar h
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
static SkRGBA4f FromBytes_RGBA(uint32_t color)

Member Data Documentation

◆ kCellHeight

const int skiagm::BezierConicEffects::kCellHeight = 128
staticprotected

Definition at line 221 of file beziereffects.cpp.

◆ kCellWidth

const int skiagm::BezierConicEffects::kCellWidth = 128
staticprotected

Definition at line 220 of file beziereffects.cpp.

◆ kNumConics

const int skiagm::BezierConicEffects::kNumConics = 10
staticprotected

Definition at line 219 of file beziereffects.cpp.


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