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

Public Member Functions

 EllipticalRRectOp (GrProcessorSet *processorSet, const SkPMColor4f &color, const SkMatrix &viewMatrix, const SkRect &devRect, float devXRadius, float devYRadius, SkVector devStrokeHalfWidths, 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 devXRadius, float devYRadius, SkVector devStrokeWidths, 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 2877 of file GrOvalOpFactory.cpp.

Constructor & Destructor Documentation

◆ EllipticalRRectOp()

EllipticalRRectOp::EllipticalRRectOp ( GrProcessorSet processorSet,
const SkPMColor4f color,
const SkMatrix viewMatrix,
const SkRect devRect,
float  devXRadius,
float  devYRadius,
SkVector  devStrokeHalfWidths,
bool  strokeOnly 
)
inline

Definition at line 2928 of file GrOvalOpFactory.cpp.

2931 : INHERITED(ClassID())
2932 , fHelper(processorSet, GrAAType::kCoverage)
2933 , fUseScale(false) {
2934 SkScalar innerXRadius = 0.0f;
2935 SkScalar innerYRadius = 0.0f;
2936 SkRect bounds = devRect;
2937 bool stroked = false;
2938 if (devStrokeHalfWidths.fX > 0) {
2939 // this is legit only if scale & translation (which should be the case at the moment)
2940 if (strokeOnly) {
2941 innerXRadius = devXRadius - devStrokeHalfWidths.fX;
2942 innerYRadius = devYRadius - devStrokeHalfWidths.fY;
2943 stroked = (innerXRadius >= 0 && innerYRadius >= 0);
2944 }
2945
2946 devXRadius += devStrokeHalfWidths.fX;
2947 devYRadius += devStrokeHalfWidths.fY;
2948 bounds.outset(devStrokeHalfWidths.fX, devStrokeHalfWidths.fY);
2949 }
2950
2951 fStroked = stroked;
2952 fViewMatrixIfUsingLocalCoords = viewMatrix;
2954 fRRects.emplace_back(
2955 RRect{color, devXRadius, devYRadius, innerXRadius, innerYRadius, bounds});
2956 }
SkColor4f color
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
float fX
x-axis value
float fY
y-axis value
void outset(float dx, float dy)
Definition SkRect.h:1077

Member Function Documentation

◆ finalize()

GrProcessorSet::Analysis EllipticalRRectOp::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 2968 of file GrOvalOpFactory.cpp.

2969 {
2970 fUseScale = !caps.shaderCaps()->fFloatIs32Bits;
2971 SkPMColor4f* color = &fRRects.front().fColor;
2972 return fHelper.finalizeProcessors(caps, clip, clampType,
2974 &fWideColor);
2975 }
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 EllipticalRRectOp::fixedFunctionFlags ( ) const
inlineoverridevirtual

Reimplemented from GrDrawOp.

Definition at line 2977 of file GrOvalOpFactory.cpp.

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

◆ Make()

static DEFINE_OP_CLASS_ID GrOp::Owner EllipticalRRectOp::Make ( GrRecordingContext context,
GrPaint &&  paint,
const SkMatrix viewMatrix,
const SkRect devRect,
float  devXRadius,
float  devYRadius,
SkVector  devStrokeWidths,
bool  strokeOnly 
)
inlinestatic

Definition at line 2886 of file GrOvalOpFactory.cpp.

2893 {
2894 SkASSERT(devXRadius >= 0.5 || strokeOnly);
2895 SkASSERT(devYRadius >= 0.5 || strokeOnly);
2896 SkASSERT((devStrokeWidths.fX > 0) == (devStrokeWidths.fY > 0));
2897 SkASSERT(!(strokeOnly && devStrokeWidths.fX <= 0));
2898 if (devStrokeWidths.fX > 0) {
2899 if (SkScalarNearlyZero(devStrokeWidths.length())) {
2900 devStrokeWidths.set(SK_ScalarHalf, SK_ScalarHalf);
2901 } else {
2902 devStrokeWidths.scale(SK_ScalarHalf);
2903 }
2904
2905 // we only handle thick strokes for near-circular ellipses
2906 if (devStrokeWidths.length() > SK_ScalarHalf &&
2907 (SK_ScalarHalf * devXRadius > devYRadius ||
2908 SK_ScalarHalf * devYRadius > devXRadius)) {
2909 return nullptr;
2910 }
2911
2912 // we don't handle it if curvature of the stroke is less than curvature of the ellipse
2913 if (devStrokeWidths.fX * (devYRadius * devYRadius) <
2914 (devStrokeWidths.fY * devStrokeWidths.fY) * devXRadius) {
2915 return nullptr;
2916 }
2917 if (devStrokeWidths.fY * (devXRadius * devXRadius) <
2918 (devStrokeWidths.fX * devStrokeWidths.fX) * devYRadius) {
2919 return nullptr;
2920 }
2921 }
2922 return Helper::FactoryHelper<EllipticalRRectOp>(context, std::move(paint),
2923 viewMatrix, devRect,
2924 devXRadius, devYRadius, devStrokeWidths,
2925 strokeOnly);
2926 }
#define SkASSERT(cond)
Definition SkAssert.h:116
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:101
#define SK_ScalarHalf
Definition SkScalar.h:19
const Paint & paint
void set(float x, float y)
float length() const
void scale(float scale, SkPoint *dst) const
Definition SkPoint.cpp:17

◆ name()

const char * EllipticalRRectOp::name ( ) const
inlineoverridevirtual

Implements GrOp.

Definition at line 2958 of file GrOvalOpFactory.cpp.

2958{ return "EllipticalRRectOp"; }

◆ onCombineIfPossible()

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

Reimplemented from GrOp.

Definition at line 3113 of file GrOvalOpFactory.cpp.

3113 {
3115
3116 if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
3118 }
3119
3120 if (fStroked != that->fStroked) {
3122 }
3123
3124 if (fHelper.usesLocalCoords() &&
3125 !SkMatrixPriv::CheapEqual(fViewMatrixIfUsingLocalCoords,
3126 that->fViewMatrixIfUsingLocalCoords)) {
3128 }
3129
3130 fRRects.push_back_n(that->fRRects.size(), that->fRRects.begin());
3131 fWideColor = fWideColor || that->fWideColor;
3133 }
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 EllipticalRRectOp::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 2982 of file GrOvalOpFactory.cpp.

2989 {
2990 SkMatrix localMatrix;
2991 if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) {
2992 return;
2993 }
2994
2995 GrGeometryProcessor* gp = EllipseGeometryProcessor::Make(arena, fStroked, fWideColor,
2996 fUseScale, localMatrix);
2997
2998 fProgramInfo = fHelper.createProgramInfo(caps, arena, writeView, usesMSAASurface,
2999 std::move(appliedClip), dstProxyView, gp,
3001 renderPassXferBarriers, colorLoadOp);
3002 }
static GrGeometryProcessor * Make(SkArenaAlloc *arena, bool stroke, bool wideColor, bool useScale, 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 EllipticalRRectOp::onExecute ( GrOpFlushState flushState,
const SkRect chainBounds 
)
inlineoverrideprivatevirtual

Implements GrOp.

Definition at line 3103 of file GrOvalOpFactory.cpp.

3103 {
3104 if (!fProgramInfo || !fMesh) {
3105 return;
3106 }
3107
3108 flushState->bindPipelineAndScissorClip(*fProgramInfo, chainBounds);
3109 flushState->bindTextures(fProgramInfo->geomProc(), nullptr, fProgramInfo->pipeline());
3110 flushState->drawMesh(*fMesh);
3111 }
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 EllipticalRRectOp::onPrepareDraws ( GrMeshDrawTarget target)
inlineoverrideprivatevirtual

Implements GrMeshDrawOp.

Definition at line 3004 of file GrOvalOpFactory.cpp.

3004 {
3005 if (!fProgramInfo) {
3006 this->createProgramInfo(target);
3007 if (!fProgramInfo) {
3008 return;
3009 }
3010 }
3011
3012 // drop out the middle quad if we're stroked
3013 int indicesPerInstance = fStroked ? kIndicesPerStrokeRRect : kIndicesPerFillRRect;
3015 fStroked ? kStroke_RRectType : kFill_RRectType, target->resourceProvider());
3016
3017 if (!indexBuffer) {
3018 SkDebugf("Could not allocate indices\n");
3019 return;
3020 }
3021 PatternHelper helper(target, GrPrimitiveType::kTriangles,
3022 fProgramInfo->geomProc().vertexStride(),
3023 std::move(indexBuffer), kVertsPerStandardRRect, indicesPerInstance,
3024 fRRects.size(), kNumRRectsInIndexBuffer);
3025 VertexWriter verts{helper.vertices()};
3026 if (!verts) {
3027 SkDebugf("Could not allocate vertices\n");
3028 return;
3029 }
3030
3031 for (const auto& rrect : fRRects) {
3032 VertexColor color(rrect.fColor, fWideColor);
3033 // Compute the reciprocals of the radii here to save time in the shader
3034 float reciprocalRadii[4] = {
3035 SkScalarInvert(rrect.fXRadius),
3036 SkScalarInvert(rrect.fYRadius),
3037 // Pinned below, so divide by zero is acceptable
3038 sk_ieee_float_divide(1.0f, rrect.fInnerXRadius),
3039 sk_ieee_float_divide(1.0f, rrect.fInnerYRadius)
3040 };
3041
3042 // If the stroke width is exactly double the radius, the inner radii will be zero.
3043 // Pin to a large value, to avoid infinities in the shader. crbug.com/1139750
3044 reciprocalRadii[2] = std::min(reciprocalRadii[2], 1e6f);
3045 reciprocalRadii[3] = std::min(reciprocalRadii[3], 1e6f);
3046
3047 // On MSAA, bloat enough to guarantee any pixel that might be touched by the rrect has
3048 // full sample coverage.
3049 float aaBloat = target->usesMSAASurface() ? SK_ScalarSqrt2 : .5f;
3050
3051 // Extend out the radii to antialias.
3052 SkScalar xOuterRadius = rrect.fXRadius + aaBloat;
3053 SkScalar yOuterRadius = rrect.fYRadius + aaBloat;
3054
3055 SkScalar xMaxOffset = xOuterRadius;
3056 SkScalar yMaxOffset = yOuterRadius;
3057 if (!fStroked) {
3058 // For filled rrects we map a unit circle in the vertex attributes rather than
3059 // computing an ellipse and modifying that distance, so we normalize to 1.
3060 xMaxOffset /= rrect.fXRadius;
3061 yMaxOffset /= rrect.fYRadius;
3062 }
3063
3064 const SkRect& bounds = rrect.fDevBounds.makeOutset(aaBloat, aaBloat);
3065
3066 SkScalar yCoords[4] = {bounds.fTop, bounds.fTop + yOuterRadius,
3067 bounds.fBottom - yOuterRadius, bounds.fBottom};
3068 SkScalar yOuterOffsets[4] = {yMaxOffset,
3069 SK_ScalarNearlyZero, // we're using inversesqrt() in
3070 // shader, so can't be exactly 0
3071 SK_ScalarNearlyZero, yMaxOffset};
3072
3073 auto maybeScale = VertexWriter::If(fUseScale, std::max(rrect.fXRadius, rrect.fYRadius));
3074 for (int i = 0; i < 4; ++i) {
3075 verts << bounds.fLeft << yCoords[i]
3076 << color
3077 << xMaxOffset << yOuterOffsets[i]
3078 << maybeScale
3079 << reciprocalRadii;
3080
3081 verts << (bounds.fLeft + xOuterRadius) << yCoords[i]
3082 << color
3083 << SK_ScalarNearlyZero << yOuterOffsets[i]
3084 << maybeScale
3085 << reciprocalRadii;
3086
3087 verts << (bounds.fRight - xOuterRadius) << yCoords[i]
3088 << color
3089 << SK_ScalarNearlyZero << yOuterOffsets[i]
3090 << maybeScale
3091 << reciprocalRadii;
3092
3093 verts << bounds.fRight << yCoords[i]
3094 << color
3095 << xMaxOffset << yOuterOffsets[i]
3096 << maybeScale
3097 << reciprocalRadii;
3098 }
3099 }
3100 fMesh = helper.mesh();
3101 }
static const int kVertsPerStandardRRect
static const int kIndicesPerFillRRect
@ kFill_RRectType
@ kStroke_RRectType
static const int kNumRRectsInIndexBuffer
static sk_sp< const GrBuffer > get_rrect_index_buffer(RRectType type, GrResourceProvider *resourceProvider)
static const int kIndicesPerStrokeRRect
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static constexpr float sk_ieee_float_divide(float numer, float denom)
#define SkScalarInvert(x)
Definition SkScalar.h:73
#define SK_ScalarNearlyZero
Definition SkScalar.h:99
#define SK_ScalarSqrt2
Definition SkScalar.h:20
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
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 * EllipticalRRectOp::programInfo ( )
inlineoverrideprivatevirtual

Implements GrMeshDrawOp.

Definition at line 2980 of file GrOvalOpFactory.cpp.

2980{ return fProgramInfo; }

◆ visitProxies()

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

Reimplemented from GrOp.

Definition at line 2960 of file GrOvalOpFactory.cpp.

2960 {
2961 if (fProgramInfo) {
2962 fProgramInfo->visitFPProxies(func);
2963 } else {
2964 fHelper.visitProxies(func);
2965 }
2966 }
void visitFPProxies(const GrVisitProxyFunc &func) const
void visitProxies(const GrVisitProxyFunc &func) const

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