Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
CircularRRectOp Class Referencefinal
Inheritance diagram for CircularRRectOp:
GrMeshDrawOp GrDrawOp GrOp SkNoncopyable

Public Member Functions

 CircularRRectOp (GrProcessorSet *processorSet, const SkPMColor4f &color, const SkMatrix &viewMatrix, const SkRect &devRect, float devRadius, float devStrokeWidth, bool strokeOnly)
 
const char * name () const override
 
void visitProxies (const GrVisitProxyFunc &func) const override
 
GrProcessorSet::Analysis finalize (const GrCaps &caps, const GrAppliedClip *clip, GrClampType clampType) override
 
FixedFunctionFlags fixedFunctionFlags () const override
 
- Public Member Functions inherited from GrDrawOp
 GrDrawOp (uint32_t classID)
 
virtual bool usesMSAA () const
 
virtual ClipResult clipToShape (skgpu::ganesh::SurfaceDrawContext *, SkClipOp, const SkMatrix &, const GrShape &, GrAA)
 
virtual bool usesStencil () const
 
- Public Member Functions inherited from GrOp
virtual ~GrOp ()=default
 
CombineResult combineIfPossible (GrOp *that, SkArenaAlloc *alloc, const GrCaps &caps)
 
const SkRectbounds () const
 
void setClippedBounds (const SkRect &clippedBounds)
 
bool hasAABloat () const
 
bool hasZeroArea () const
 
void operator delete (void *p)
 
template<typename T >
const Tcast () const
 
template<typename T >
Tcast ()
 
uint32_t classID () const
 
uint32_t uniqueID () const
 
void prePrepare (GrRecordingContext *context, const GrSurfaceProxyView &dstView, GrAppliedClip *clip, const GrDstProxyView &dstProxyView, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp)
 
void prepare (GrOpFlushState *state)
 
void execute (GrOpFlushState *state, const SkRect &chainBounds)
 
void chainConcat (GrOp::Owner)
 
bool isChainHead () const
 
bool isChainTail () const
 
GrOpnextInChain () const
 
GrOpprevInChain () const
 
GrOp::Owner cutChain ()
 
void setBounds (const SkRect &newBounds, HasAABloat aabloat, IsHairline zeroArea)
 
void setTransformedBounds (const SkRect &srcBounds, const SkMatrix &m, HasAABloat aabloat, IsHairline zeroArea)
 
void makeFullScreen (GrSurfaceProxy *proxy)
 

Static Public Member Functions

static DEFINE_OP_CLASS_ID GrOp::Owner Make (GrRecordingContext *context, GrPaint &&paint, const SkMatrix &viewMatrix, const SkRect &devRect, float devRadius, float devStrokeWidth, bool strokeOnly)
 
- Static Public Member Functions inherited from GrMeshDrawOp
static bool CanUpgradeAAOnMerge (GrAAType aa1, GrAAType aa2)
 
- Static Public Member Functions inherited from GrOp
template<typename Op , typename... Args>
static Owner Make (GrRecordingContext *context, Args &&... args)
 
template<typename Op , typename... Args>
static Owner MakeWithProcessorSet (GrRecordingContext *context, const SkPMColor4f &color, GrPaint &&paint, Args &&... args)
 
template<typename Op , typename... Args>
static Owner MakeWithExtraMemory (GrRecordingContext *context, size_t extraSize, Args &&... args)
 
static uint32_t GenOpClassID ()
 

Private Member Functions

GrProgramInfoprogramInfo () override
 
void onCreateProgramInfo (const GrCaps *caps, SkArenaAlloc *arena, const GrSurfaceProxyView &writeView, bool usesMSAASurface, GrAppliedClip &&appliedClip, const GrDstProxyView &dstProxyView, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp) override
 
void onPrepareDraws (GrMeshDrawTarget *target) override
 
void onExecute (GrOpFlushState *flushState, const SkRect &chainBounds) override
 
CombineResult onCombineIfPossible (GrOp *t, SkArenaAlloc *, const GrCaps &caps) override
 

Additional Inherited Members

- Public Types inherited from GrDrawOp
enum class  ClipResult { kFail , kClippedGeometrically , kClippedInShader , kClippedOut }
 
- Public Types inherited from GrOp
enum class  CombineResult { kMerged , kMayChain , kCannotCombine }
 
enum class  HasAABloat : bool { kNo = false , kYes = true }
 
enum class  IsHairline : bool { kNo = false , kYes = true }
 
using Owner = std::unique_ptr< GrOp >
 
- Protected Types inherited from GrDrawOp
enum class  FixedFunctionFlags : uint32_t { kNone = 0x0 , kUsesHWAA = 0x1 , kUsesStencil = 0x2 }
 
- Protected Member Functions inherited from GrMeshDrawOp
 GrMeshDrawOp (uint32_t classID)
 
void createProgramInfo (const GrCaps *caps, SkArenaAlloc *arena, const GrSurfaceProxyView &writeView, bool usesMSAASurface, GrAppliedClip &&appliedClip, const GrDstProxyView &dstProxyView, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp)
 
void createProgramInfo (GrMeshDrawTarget *)
 
virtual void onPrePrepareDraws (GrRecordingContext *, const GrSurfaceProxyView &writeView, GrAppliedClip *, const GrDstProxyView &, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp)
 
- Protected Member Functions inherited from GrDrawOp
 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS (FixedFunctionFlags)
 
- Static Protected Member Functions inherited from GrMeshDrawOp
static bool CombinedQuadCountWillOverflow (GrAAType aaType, bool willBeUpgradedToAA, int combinedQuadCount)
 

Detailed Description

Definition at line 2512 of file GrOvalOpFactory.cpp.

Constructor & Destructor Documentation

◆ CircularRRectOp()

CircularRRectOp::CircularRRectOp ( GrProcessorSet processorSet,
const SkPMColor4f color,
const SkMatrix viewMatrix,
const SkRect devRect,
float  devRadius,
float  devStrokeWidth,
bool  strokeOnly 
)
inline

Definition at line 2532 of file GrOvalOpFactory.cpp.

2535 : INHERITED(ClassID())
2536 , fViewMatrixIfUsingLocalCoords(viewMatrix)
2537 , fHelper(processorSet, GrAAType::kCoverage) {
2538 SkRect bounds = devRect;
2539 SkASSERT(!(devStrokeWidth <= 0 && strokeOnly));
2540 SkScalar innerRadius = 0.0f;
2541 SkScalar outerRadius = devRadius;
2542 SkScalar halfWidth = 0;
2544 if (devStrokeWidth > 0) {
2545 if (SkScalarNearlyZero(devStrokeWidth)) {
2546 halfWidth = SK_ScalarHalf;
2547 } else {
2548 halfWidth = SkScalarHalf(devStrokeWidth);
2549 }
2550
2551 if (strokeOnly) {
2552 // Outset stroke by 1/4 pixel
2553 devStrokeWidth += 0.25f;
2554 // If stroke is greater than width or height, this is still a fill
2555 // Otherwise we compute stroke params
2556 if (devStrokeWidth <= devRect.width() && devStrokeWidth <= devRect.height()) {
2557 innerRadius = devRadius - halfWidth;
2558 type = (innerRadius >= 0) ? kStroke_RRectType : kOverstroke_RRectType;
2559 }
2560 }
2561 outerRadius += halfWidth;
2562 bounds.outset(halfWidth, halfWidth);
2563 }
2564
2565 // The radii are outset for two reasons. First, it allows the shader to simply perform
2566 // simpler computation because the computed alpha is zero, rather than 50%, at the radius.
2567 // Second, the outer radius is used to compute the verts of the bounding box that is
2568 // rendered and the outset ensures the box will cover all partially covered by the rrect
2569 // corners.
2570 outerRadius += SK_ScalarHalf;
2571 innerRadius -= SK_ScalarHalf;
2572
2574
2575 // Expand the rect for aa to generate correct vertices.
2577
2578 fRRects.emplace_back(RRect{color, innerRadius, outerRadius, bounds, type});
2579 fVertCount = rrect_type_to_vert_count(type);
2580 fIndexCount = rrect_type_to_index_count(type);
2581 fAllFill = (kFill_RRectType == type);
2582 }
static int rrect_type_to_vert_count(RRectType type)
static int rrect_type_to_index_count(RRectType type)
@ kOverstroke_RRectType
@ kFill_RRectType
@ kStroke_RRectType
SkColor4f color
#define SkASSERT(cond)
Definition SkAssert.h:116
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:101
#define SkScalarHalf(a)
Definition SkScalar.h:75
#define SK_ScalarHalf
Definition SkScalar.h:19
const SkRect & bounds() const
Definition GrOp.h:122
void setBounds(const SkRect &newBounds, HasAABloat aabloat, IsHairline zeroArea)
Definition GrOp.h:279
T & emplace_back(Args &&... args)
Definition SkTArray.h:243
float SkScalar
Definition extension.cpp:12
void outset(float dx, float dy)
Definition SkRect.h:1077
constexpr float height() const
Definition SkRect.h:769
constexpr float width() const
Definition SkRect.h:762

Member Function Documentation

◆ finalize()

GrProcessorSet::Analysis CircularRRectOp::finalize ( const GrCaps ,
const GrAppliedClip ,
GrClampType   
)
inlineoverridevirtual

This is called after the GrAppliedClip has been computed and just prior to recording the op or combining it with a previously recorded op. The op should convert any proxies or resources it owns to "pending io" status so that resource allocation can be more optimal. Additionally, at this time the op must report whether a copy of the destination (or destination texture itself) needs to be provided to the GrXferProcessor when this op executes.

Implements GrDrawOp.

Definition at line 2594 of file GrOvalOpFactory.cpp.

2595 {
2596 SkPMColor4f* color = &fRRects.front().fColor;
2597 return fHelper.finalizeProcessors(caps, clip, clampType,
2599 &fWideColor);
2600 }
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition SkPath.cpp:3824
GrProcessorSet::Analysis finalizeProcessors(const GrCaps &caps, const GrAppliedClip *clip, GrClampType clampType, GrProcessorAnalysisCoverage geometryCoverage, GrProcessorAnalysisColor *geometryColor)

◆ fixedFunctionFlags()

FixedFunctionFlags CircularRRectOp::fixedFunctionFlags ( ) const
inlineoverridevirtual

Reimplemented from GrDrawOp.

Definition at line 2602 of file GrOvalOpFactory.cpp.

2602{ return fHelper.fixedFunctionFlags(); }
GrDrawOp::FixedFunctionFlags fixedFunctionFlags() const

◆ Make()

static DEFINE_OP_CLASS_ID GrOp::Owner CircularRRectOp::Make ( GrRecordingContext context,
GrPaint &&  paint,
const SkMatrix viewMatrix,
const SkRect devRect,
float  devRadius,
float  devStrokeWidth,
bool  strokeOnly 
)
inlinestatic

Definition at line 2521 of file GrOvalOpFactory.cpp.

2527 {
2528 return Helper::FactoryHelper<CircularRRectOp>(context, std::move(paint), viewMatrix,
2529 devRect, devRadius,
2530 devStrokeWidth, strokeOnly);
2531 }
const Paint & paint

◆ name()

const char * CircularRRectOp::name ( ) const
inlineoverridevirtual

Implements GrOp.

Definition at line 2584 of file GrOvalOpFactory.cpp.

2584{ return "CircularRRectOp"; }

◆ onCombineIfPossible()

CombineResult CircularRRectOp::onCombineIfPossible ( GrOp t,
SkArenaAlloc ,
const GrCaps caps 
)
inlineoverrideprivatevirtual

Reimplemented from GrOp.

Definition at line 2789 of file GrOvalOpFactory.cpp.

2789 {
2790 CircularRRectOp* that = t->cast<CircularRRectOp>();
2791
2792 // can only represent 65535 unique vertices with 16-bit indices
2793 if (fVertCount + that->fVertCount > 65536) {
2795 }
2796
2797 if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
2799 }
2800
2801 if (fHelper.usesLocalCoords() &&
2802 !SkMatrixPriv::CheapEqual(fViewMatrixIfUsingLocalCoords,
2803 that->fViewMatrixIfUsingLocalCoords)) {
2805 }
2806
2807 fRRects.push_back_n(that->fRRects.size(), that->fRRects.begin());
2808 fVertCount += that->fVertCount;
2809 fIndexCount += that->fIndexCount;
2810 fAllFill = fAllFill && that->fAllFill;
2811 fWideColor = fWideColor || that->fWideColor;
2813 }
const T & cast() const
Definition GrOp.h:148
bool isCompatible(const GrSimpleMeshDrawOpHelper &that, const GrCaps &, const SkRect &thisBounds, const SkRect &thatBounds, bool ignoreAAType=false) const
static bool CheapEqual(const SkMatrix &a, const SkMatrix &b)
T * push_back_n(int n)
Definition SkTArray.h:262
int size() const
Definition SkTArray.h:416

◆ onCreateProgramInfo()

void CircularRRectOp::onCreateProgramInfo ( const GrCaps caps,
SkArenaAlloc arena,
const GrSurfaceProxyView writeView,
bool  usesMSAASurface,
GrAppliedClip &&  appliedClip,
const GrDstProxyView dstProxyView,
GrXferBarrierFlags  renderPassXferBarriers,
GrLoadOp  colorLoadOp 
)
inlineoverrideprivatevirtual

Implements GrMeshDrawOp.

Definition at line 2657 of file GrOvalOpFactory.cpp.

2664 {
2665 SkASSERT(!usesMSAASurface);
2666
2667 // Invert the view matrix as a local matrix (if any other processors require coords).
2668 SkMatrix localMatrix;
2669 if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) {
2670 return;
2671 }
2672
2674 false, false, false, false,
2675 fWideColor, localMatrix);
2676
2677 fProgramInfo = fHelper.createProgramInfo(caps, arena, writeView, usesMSAASurface,
2678 std::move(appliedClip), dstProxyView, gp,
2680 renderPassXferBarriers, colorLoadOp);
2681 }
static GrGeometryProcessor * Make(SkArenaAlloc *arena, bool stroke, bool clipPlane, bool isectPlane, bool unionPlane, bool roundCaps, bool wideColor, const SkMatrix &localMatrix)
GrProgramInfo * createProgramInfo(const GrCaps *, SkArenaAlloc *, const GrSurfaceProxyView &writeView, bool usesMSAASurface, GrAppliedClip &&, const GrDstProxyView &, GrGeometryProcessor *, GrPrimitiveType, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp)
bool invert(SkMatrix *inverse) const
Definition SkMatrix.h:1206

◆ onExecute()

void CircularRRectOp::onExecute ( GrOpFlushState flushState,
const SkRect chainBounds 
)
inlineoverrideprivatevirtual

Implements GrOp.

Definition at line 2779 of file GrOvalOpFactory.cpp.

2779 {
2780 if (!fProgramInfo || !fMesh) {
2781 return;
2782 }
2783
2784 flushState->bindPipelineAndScissorClip(*fProgramInfo, chainBounds);
2785 flushState->bindTextures(fProgramInfo->geomProc(), nullptr, fProgramInfo->pipeline());
2786 flushState->drawMesh(*fMesh);
2787 }
void drawMesh(const GrSimpleMesh &mesh)
void bindPipelineAndScissorClip(const GrProgramInfo &programInfo, const SkRect &drawBounds)
void bindTextures(const GrGeometryProcessor &geomProc, const GrSurfaceProxy &singleGeomProcTexture, const GrPipeline &pipeline)
const GrPipeline & pipeline() const
const GrGeometryProcessor & geomProc() const

◆ onPrepareDraws()

void CircularRRectOp::onPrepareDraws ( GrMeshDrawTarget target)
inlineoverrideprivatevirtual

Implements GrMeshDrawOp.

Definition at line 2683 of file GrOvalOpFactory.cpp.

2683 {
2684 if (!fProgramInfo) {
2685 this->createProgramInfo(target);
2686 if (!fProgramInfo) {
2687 return;
2688 }
2689 }
2690
2691 sk_sp<const GrBuffer> vertexBuffer;
2692 int firstVertex;
2693
2694 VertexWriter verts = target->makeVertexWriter(fProgramInfo->geomProc().vertexStride(),
2695 fVertCount, &vertexBuffer, &firstVertex);
2696 if (!verts) {
2697 SkDebugf("Could not allocate vertices\n");
2698 return;
2699 }
2700
2701 sk_sp<const GrBuffer> indexBuffer;
2702 int firstIndex = 0;
2703 uint16_t* indices = target->makeIndexSpace(fIndexCount, &indexBuffer, &firstIndex);
2704 if (!indices) {
2705 SkDebugf("Could not allocate indices\n");
2706 return;
2707 }
2708
2709 int currStartVertex = 0;
2710 for (const auto& rrect : fRRects) {
2711 VertexColor color(rrect.fColor, fWideColor);
2712 SkScalar outerRadius = rrect.fOuterRadius;
2713 const SkRect& bounds = rrect.fDevBounds;
2714
2715 SkScalar yCoords[4] = {bounds.fTop, bounds.fTop + outerRadius,
2716 bounds.fBottom - outerRadius, bounds.fBottom};
2717
2718 SkScalar yOuterRadii[4] = {-1, 0, 0, 1};
2719 // The inner radius in the vertex data must be specified in normalized space.
2720 // For fills, specifying -1/outerRadius guarantees an alpha of 1.0 at the inner radius.
2721 SkScalar innerRadius = rrect.fType != kFill_RRectType
2722 ? rrect.fInnerRadius / rrect.fOuterRadius
2723 : -1.0f / rrect.fOuterRadius;
2724 for (int i = 0; i < 4; ++i) {
2725 verts << bounds.fLeft << yCoords[i]
2726 << color
2727 << -1.0f << yOuterRadii[i]
2728 << outerRadius << innerRadius;
2729
2730 verts << (bounds.fLeft + outerRadius) << yCoords[i]
2731 << color
2732 << 0.0f << yOuterRadii[i]
2733 << outerRadius << innerRadius;
2734
2735 verts << (bounds.fRight - outerRadius) << yCoords[i]
2736 << color
2737 << 0.0f << yOuterRadii[i]
2738 << outerRadius << innerRadius;
2739
2740 verts << bounds.fRight << yCoords[i]
2741 << color
2742 << 1.0f << yOuterRadii[i]
2743 << outerRadius << innerRadius;
2744 }
2745 // Add the additional vertices for overstroked rrects.
2746 // Effectively this is an additional stroked rrect, with its
2747 // outer radius = outerRadius - innerRadius, and inner radius = 0.
2748 // This will give us correct AA in the center and the correct
2749 // distance to the outer edge.
2750 //
2751 // Also, the outer offset is a constant vector pointing to the right, which
2752 // guarantees that the distance value along the outer rectangle is constant.
2753 if (kOverstroke_RRectType == rrect.fType) {
2754 SkASSERT(rrect.fInnerRadius <= 0.0f);
2755
2756 SkScalar overstrokeOuterRadius = outerRadius - rrect.fInnerRadius;
2757 // this is the normalized distance from the outer rectangle of this
2758 // geometry to the outer edge
2759 SkScalar maxOffset = -rrect.fInnerRadius / overstrokeOuterRadius;
2760
2761 FillInOverstrokeVerts(verts, bounds, outerRadius, overstrokeOuterRadius, maxOffset,
2762 overstrokeOuterRadius, 0.0f, color);
2763 }
2764
2765 const uint16_t* primIndices = rrect_type_to_indices(rrect.fType);
2766 const int primIndexCount = rrect_type_to_index_count(rrect.fType);
2767 for (int i = 0; i < primIndexCount; ++i) {
2768 *indices++ = primIndices[i] + currStartVertex;
2769 }
2770
2771 currStartVertex += rrect_type_to_vert_count(rrect.fType);
2772 }
2773
2774 fMesh = target->allocMesh();
2775 fMesh->setIndexed(std::move(indexBuffer), fIndexCount, firstIndex, 0, fVertCount - 1,
2776 GrPrimitiveRestart::kNo, std::move(vertexBuffer), firstVertex);
2777 }
static const uint16_t * rrect_type_to_indices(RRectType type)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
void createProgramInfo(const GrCaps *caps, SkArenaAlloc *arena, const GrSurfaceProxyView &writeView, bool usesMSAASurface, GrAppliedClip &&appliedClip, const GrDstProxyView &dstProxyView, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp)
uint32_t * target
SkRRect rrect
Definition SkRecords.h:232
void setIndexed(sk_sp< const GrBuffer > indexBuffer, int indexCount, int baseIndex, uint16_t minIndexValue, uint16_t maxIndexValue, GrPrimitiveRestart, sk_sp< const GrBuffer > vertexBuffer, int baseVertex)
SkScalar fBottom
larger y-axis bounds
Definition extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition extension.cpp:16
SkScalar fTop
smaller y-axis bounds
Definition extension.cpp:15

◆ programInfo()

GrProgramInfo * CircularRRectOp::programInfo ( )
inlineoverrideprivatevirtual

Implements GrMeshDrawOp.

Definition at line 2655 of file GrOvalOpFactory.cpp.

2655{ return fProgramInfo; }

◆ visitProxies()

void CircularRRectOp::visitProxies ( const GrVisitProxyFunc func) const
inlineoverridevirtual

Reimplemented from GrOp.

Definition at line 2586 of file GrOvalOpFactory.cpp.

2586 {
2587 if (fProgramInfo) {
2588 fProgramInfo->visitFPProxies(func);
2589 } else {
2590 fHelper.visitProxies(func);
2591 }
2592 }
void visitFPProxies(const GrVisitProxyFunc &func) const
void visitProxies(const GrVisitProxyFunc &func) const

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