Flutter Engine
The Flutter Engine
Classes | Enumerations | Functions | Variables
GrOvalOpFactory.cpp File Reference
#include "src/gpu/ganesh/ops/GrOvalOpFactory.h"
#include "include/core/SkStrokeRec.h"
#include "include/private/base/SkFloatingPoint.h"
#include "src/core/SkMatrixPriv.h"
#include "src/core/SkRRectPriv.h"
#include "src/gpu/BufferWriter.h"
#include "src/gpu/KeyBuilder.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrDrawOpTest.h"
#include "src/gpu/ganesh/GrGeometryProcessor.h"
#include "src/gpu/ganesh/GrOpFlushState.h"
#include "src/gpu/ganesh/GrProcessor.h"
#include "src/gpu/ganesh/GrProcessorUnitTest.h"
#include "src/gpu/ganesh/GrProgramInfo.h"
#include "src/gpu/ganesh/GrResourceProvider.h"
#include "src/gpu/ganesh/GrShaderCaps.h"
#include "src/gpu/ganesh/GrStyle.h"
#include "src/gpu/ganesh/glsl/GrGLSLFragmentShaderBuilder.h"
#include "src/gpu/ganesh/glsl/GrGLSLProgramDataManager.h"
#include "src/gpu/ganesh/glsl/GrGLSLUniformHandler.h"
#include "src/gpu/ganesh/glsl/GrGLSLVarying.h"
#include "src/gpu/ganesh/glsl/GrGLSLVertexGeoBuilder.h"
#include "src/gpu/ganesh/ops/GrMeshDrawOp.h"
#include "src/gpu/ganesh/ops/GrSimpleMeshDrawOpHelper.h"
#include <utility>

Go to the source code of this file.

Classes

class  CircleGeometryProcessor
 
class  ButtCapDashedCircleGeometryProcessor
 
class  EllipseGeometryProcessor
 
class  DIEllipseGeometryProcessor
 
class  CircleOp
 
struct  CircleOp::ArcParams
 
class  ButtCapDashedCircleOp
 
class  EllipseOp
 
class  DIEllipseOp
 
class  CircularRRectOp
 
class  EllipticalRRectOp
 

Enumerations

enum class  DIEllipseStyle { kStroke = 0 , kHairline , kFill }
 
enum  RRectType { kFill_RRectType , kStroke_RRectType , kOverstroke_RRectType }
 

Functions

static int circle_type_to_vert_count (bool stroked)
 
static int circle_type_to_index_count (bool stroked)
 
static const uint16_t * circle_type_to_indices (bool stroked)
 
static int rrect_type_to_vert_count (RRectType type)
 
static int rrect_type_to_index_count (RRectType type)
 
static const uint16_t * rrect_type_to_indices (RRectType type)
 
 SKGPU_DECLARE_STATIC_UNIQUE_KEY (gStrokeRRectOnlyIndexBufferKey)
 
 SKGPU_DECLARE_STATIC_UNIQUE_KEY (gRRectOnlyIndexBufferKey)
 
static sk_sp< const GrBufferget_rrect_index_buffer (RRectType type, GrResourceProvider *resourceProvider)
 
GrOp::Owner make_rrect_op (GrRecordingContext *context, GrPaint &&paint, const SkMatrix &viewMatrix, const SkRRect &rrect, const SkStrokeRec &stroke)
 

Variables

static const uint16_t gFillCircleIndices []
 
static const uint16_t gStrokeCircleIndices []
 
static constexpr SkScalar kOctOffset = 0.41421356237f
 
static constexpr SkPoint kOctagonOuter []
 
static constexpr SkScalar kCosPi8 = 0.923579533f
 
static constexpr SkScalar kSinPi8 = 0.382683432f
 
static constexpr SkPoint kOctagonInner []
 
static const int kIndicesPerFillCircle = std::size(gFillCircleIndices)
 
static const int kIndicesPerStrokeCircle = std::size(gStrokeCircleIndices)
 
static const int kVertsPerStrokeCircle = 16
 
static const int kVertsPerFillCircle = 9
 
static const uint16_t gOverstrokeRRectIndices []
 
static const uint16_t * gStandardRRectIndices = gOverstrokeRRectIndices + 6 * 4
 
static const int kIndicesPerOverstrokeRRect = std::size(gOverstrokeRRectIndices) - 6
 
static const int kIndicesPerFillRRect = kIndicesPerOverstrokeRRect - 6 * 4 + 6
 
static const int kIndicesPerStrokeRRect = kIndicesPerFillRRect - 6
 
static const int kVertsPerStandardRRect = 16
 
static const int kVertsPerOverstrokeRRect = 24
 
static const int kNumRRectsInIndexBuffer = 256
 

Enumeration Type Documentation

◆ DIEllipseStyle

enum class DIEllipseStyle
strong

The output of this effect is a modulation of the input color and coverage for an ellipse, specified as a 2D offset from center for both the outer and inner paths (if stroked). The implict equation used is for a unit circle (x^2 + y^2 - 1 = 0) and the edge corrected by using differentials.

The result is device-independent and can be used with any affine matrix.

Enumerator
kStroke 
kHairline 
kFill 

Definition at line 729 of file GrOvalOpFactory.cpp.

729{ kStroke = 0, kHairline, kFill };
@ kStroke
strokes boundary of shapes
@ kFill
fills interior of shapes

◆ RRectType

enum RRectType
Enumerator
kFill_RRectType 
kStroke_RRectType 
kOverstroke_RRectType 

Definition at line 2461 of file GrOvalOpFactory.cpp.

2461 {
2465};
@ kOverstroke_RRectType
@ kFill_RRectType
@ kStroke_RRectType

Function Documentation

◆ circle_type_to_index_count()

static int circle_type_to_index_count ( bool  stroked)
static

Definition at line 975 of file GrOvalOpFactory.cpp.

975 {
977}
static const int kIndicesPerStrokeCircle
static const int kIndicesPerFillCircle

◆ circle_type_to_indices()

static const uint16_t * circle_type_to_indices ( bool  stroked)
static

Definition at line 979 of file GrOvalOpFactory.cpp.

979 {
980 return stroked ? gStrokeCircleIndices : gFillCircleIndices;
981}
static const uint16_t gStrokeCircleIndices[]
static const uint16_t gFillCircleIndices[]

◆ circle_type_to_vert_count()

static int circle_type_to_vert_count ( bool  stroked)
static

Definition at line 971 of file GrOvalOpFactory.cpp.

971 {
973}
static const int kVertsPerFillCircle
static const int kVertsPerStrokeCircle

◆ get_rrect_index_buffer()

static sk_sp< const GrBuffer > get_rrect_index_buffer ( RRectType  type,
GrResourceProvider resourceProvider 
)
static

Definition at line 2858 of file GrOvalOpFactory.cpp.

2859 {
2860 SKGPU_DEFINE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey);
2861 SKGPU_DEFINE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey);
2862 switch (type) {
2863 case kFill_RRectType:
2864 return resourceProvider->findOrCreatePatternedIndexBuffer(
2866 kVertsPerStandardRRect, gRRectOnlyIndexBufferKey);
2867 case kStroke_RRectType:
2868 return resourceProvider->findOrCreatePatternedIndexBuffer(
2870 kVertsPerStandardRRect, gStrokeRRectOnlyIndexBufferKey);
2871 default:
2872 SkASSERT(false);
2873 return nullptr;
2874 }
2875}
static const int kVertsPerStandardRRect
static const uint16_t * gStandardRRectIndices
static const int kIndicesPerFillRRect
static const int kNumRRectsInIndexBuffer
static const int kIndicesPerStrokeRRect
#define SKGPU_DEFINE_STATIC_UNIQUE_KEY(name)
Definition: ResourceKey.h:324
#define SkASSERT(cond)
Definition: SkAssert.h:116
GLenum type
sk_sp< const GrGpuBuffer > findOrCreatePatternedIndexBuffer(const uint16_t *pattern, int patternSize, int reps, int vertCount, const skgpu::UniqueKey &key)

◆ make_rrect_op()

GrOp::Owner make_rrect_op ( GrRecordingContext context,
GrPaint &&  paint,
const SkMatrix viewMatrix,
const SkRRect rrect,
const SkStrokeRec stroke 
)

Definition at line 3226 of file GrOvalOpFactory.cpp.

3230 {
3231 SkASSERT(viewMatrix.rectStaysRect());
3233 SkASSERT(!rrect.isOval());
3234
3235 // RRect ops only handle simple, but not too simple, rrects.
3236 // Do any matrix crunching before we reset the draw state for device coords.
3237 const SkRect& rrectBounds = rrect.getBounds();
3238 SkRect bounds;
3239 viewMatrix.mapRect(&bounds, rrectBounds);
3240
3242 SkScalar xRadius = SkScalarAbs(viewMatrix[SkMatrix::kMScaleX] * radii.fX +
3243 viewMatrix[SkMatrix::kMSkewY] * radii.fY);
3244 SkScalar yRadius = SkScalarAbs(viewMatrix[SkMatrix::kMSkewX] * radii.fX +
3245 viewMatrix[SkMatrix::kMScaleY] * radii.fY);
3246
3247 SkStrokeRec::Style style = stroke.getStyle();
3248
3249 // Do (potentially) anisotropic mapping of stroke. Use -1s to indicate fill-only draws.
3250 SkVector scaledStroke = {-1, -1};
3251 SkScalar strokeWidth = stroke.getWidth();
3252
3253 bool isStrokeOnly =
3255 bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style;
3256
3257 if (hasStroke) {
3258 if (SkStrokeRec::kHairline_Style == style) {
3259 scaledStroke.set(1, 1);
3260 } else {
3261 scaledStroke.fX = SkScalarAbs(
3262 strokeWidth * (viewMatrix[SkMatrix::kMScaleX] + viewMatrix[SkMatrix::kMSkewY]));
3263 scaledStroke.fY = SkScalarAbs(
3264 strokeWidth * (viewMatrix[SkMatrix::kMSkewX] + viewMatrix[SkMatrix::kMScaleY]));
3265 }
3266
3267 // if half of strokewidth is greater than radius, we don't handle that right now
3268 if ((SK_ScalarHalf * scaledStroke.fX > xRadius ||
3269 SK_ScalarHalf * scaledStroke.fY > yRadius)) {
3270 return nullptr;
3271 }
3272 }
3273
3274 // The matrix may have a rotation by an odd multiple of 90 degrees.
3275 if (viewMatrix.getScaleX() == 0) {
3276 std::swap(xRadius, yRadius);
3277 std::swap(scaledStroke.fX, scaledStroke.fY);
3278 }
3279
3280 // The way the effect interpolates the offset-to-ellipse/circle-center attribute only works on
3281 // the interior of the rrect if the radii are >= 0.5. Otherwise, the inner rect of the nine-
3282 // patch will have fractional coverage. This only matters when the interior is actually filled.
3283 // We could consider falling back to rect rendering here, since a tiny radius is
3284 // indistinguishable from a square corner.
3285 if (!isStrokeOnly && (SK_ScalarHalf > xRadius || SK_ScalarHalf > yRadius)) {
3286 return nullptr;
3287 }
3288
3289 // if the corners are circles, use the circle renderer
3290 return EllipticalRRectOp::Make(context, std::move(paint), viewMatrix, bounds,
3291 xRadius, yRadius, scaledStroke, isStrokeOnly);
3292}
static const int strokeWidth
Definition: BlurTest.cpp:60
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
#define SK_ScalarHalf
Definition: SkScalar.h:19
#define SkScalarAbs(x)
Definition: SkScalar.h:39
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 constexpr int kMScaleX
horizontal scale factor
Definition: SkMatrix.h:353
bool rectStaysRect() const
Definition: SkMatrix.h:271
SkScalar getScaleX() const
Definition: SkMatrix.h:415
static constexpr int kMSkewY
vertical skew factor
Definition: SkMatrix.h:356
static constexpr int kMScaleY
vertical scale factor
Definition: SkMatrix.h:357
static constexpr int kMSkewX
horizontal skew factor
Definition: SkMatrix.h:354
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkMatrix.cpp:1141
static SkVector GetSimpleRadii(const SkRRect &rr)
Definition: SkRRectPriv.h:22
bool isOval() const
Definition: SkRRect.h:85
const SkRect & getBounds() const
Definition: SkRRect.h:279
bool isSimple() const
Definition: SkRRect.h:86
@ kStrokeAndFill_Style
Definition: SkStrokeRec.h:36
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
Optional< SkRect > bounds
Definition: SkRecords.h:189
SkRRect rrect
Definition: SkRecords.h:232
float fX
x-axis value
Definition: SkPoint_impl.h:164
void set(float x, float y)
Definition: SkPoint_impl.h:200
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ rrect_type_to_index_count()

static int rrect_type_to_index_count ( RRectType  type)
static

Definition at line 2478 of file GrOvalOpFactory.cpp.

2478 {
2479 switch (type) {
2480 case kFill_RRectType:
2481 return kIndicesPerFillRRect;
2482 case kStroke_RRectType:
2486 }
2487 SK_ABORT("Invalid type");
2488}
static const int kIndicesPerOverstrokeRRect
#define SK_ABORT(message,...)
Definition: SkAssert.h:70

◆ rrect_type_to_indices()

static const uint16_t * rrect_type_to_indices ( RRectType  type)
static

Definition at line 2490 of file GrOvalOpFactory.cpp.

2490 {
2491 switch (type) {
2492 case kFill_RRectType:
2493 case kStroke_RRectType:
2494 return gStandardRRectIndices;
2497 }
2498 SK_ABORT("Invalid type");
2499}
static const uint16_t gOverstrokeRRectIndices[]

◆ rrect_type_to_vert_count()

static int rrect_type_to_vert_count ( RRectType  type)
static

Definition at line 2467 of file GrOvalOpFactory.cpp.

2467 {
2468 switch (type) {
2469 case kFill_RRectType:
2470 case kStroke_RRectType:
2474 }
2475 SK_ABORT("Invalid type");
2476}
static const int kVertsPerOverstrokeRRect

◆ SKGPU_DECLARE_STATIC_UNIQUE_KEY() [1/2]

SKGPU_DECLARE_STATIC_UNIQUE_KEY ( gRRectOnlyIndexBufferKey  )

◆ SKGPU_DECLARE_STATIC_UNIQUE_KEY() [2/2]

SKGPU_DECLARE_STATIC_UNIQUE_KEY ( gStrokeRRectOnlyIndexBufferKey  )

Variable Documentation

◆ gFillCircleIndices

const uint16_t gFillCircleIndices[]
static
Initial value:
= {
0, 1, 8, 1, 2, 8,
2, 3, 8, 3, 4, 8,
4, 5, 8, 5, 6, 8,
6, 7, 8, 7, 0, 8
}

Definition at line 913 of file GrOvalOpFactory.cpp.

◆ gOverstrokeRRectIndices

const uint16_t gOverstrokeRRectIndices[]
static
Initial value:
= {
16, 17, 19, 16, 19, 18,
19, 17, 23, 19, 23, 21,
21, 23, 22, 21, 22, 20,
22, 16, 18, 22, 18, 20,
0, 1, 5, 0, 5, 4,
2, 3, 7, 2, 7, 6,
8, 9, 13, 8, 13, 12,
10, 11, 15, 10, 15, 14,
1, 2, 6, 1, 6, 5,
4, 5, 9, 4, 9, 8,
6, 7, 11, 6, 11, 10,
9, 10, 14, 9, 14, 13,
5, 6, 10, 5, 10, 9,
}

Definition at line 2422 of file GrOvalOpFactory.cpp.

◆ gStandardRRectIndices

const uint16_t* gStandardRRectIndices = gOverstrokeRRectIndices + 6 * 4
static

Definition at line 2450 of file GrOvalOpFactory.cpp.

◆ gStrokeCircleIndices

const uint16_t gStrokeCircleIndices[]
static
Initial value:
= {
0, 1, 9, 0, 9, 8,
1, 2, 10, 1, 10, 9,
2, 3, 11, 2, 11, 10,
3, 4, 12, 3, 12, 11,
4, 5, 13, 4, 13, 12,
5, 6, 14, 5, 14, 13,
6, 7, 15, 6, 15, 14,
7, 0, 8, 7, 8, 15,
}

Definition at line 924 of file GrOvalOpFactory.cpp.

◆ kCosPi8

constexpr SkScalar kCosPi8 = 0.923579533f
staticconstexpr

Definition at line 953 of file GrOvalOpFactory.cpp.

◆ kIndicesPerFillCircle

const int kIndicesPerFillCircle = std::size(gFillCircleIndices)
static

Definition at line 966 of file GrOvalOpFactory.cpp.

◆ kIndicesPerFillRRect

const int kIndicesPerFillRRect = kIndicesPerOverstrokeRRect - 6 * 4 + 6
static

Definition at line 2455 of file GrOvalOpFactory.cpp.

◆ kIndicesPerOverstrokeRRect

const int kIndicesPerOverstrokeRRect = std::size(gOverstrokeRRectIndices) - 6
static

Definition at line 2453 of file GrOvalOpFactory.cpp.

◆ kIndicesPerStrokeCircle

const int kIndicesPerStrokeCircle = std::size(gStrokeCircleIndices)
static

Definition at line 967 of file GrOvalOpFactory.cpp.

◆ kIndicesPerStrokeRRect

const int kIndicesPerStrokeRRect = kIndicesPerFillRRect - 6
static

Definition at line 2457 of file GrOvalOpFactory.cpp.

◆ kNumRRectsInIndexBuffer

const int kNumRRectsInIndexBuffer = 256
static

Definition at line 2854 of file GrOvalOpFactory.cpp.

◆ kOctagonInner

constexpr SkPoint kOctagonInner[]
staticconstexpr
Initial value:
= {
}
static constexpr SkScalar kCosPi8
static constexpr SkScalar kSinPi8
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173

Definition at line 955 of file GrOvalOpFactory.cpp.

◆ kOctagonOuter

constexpr SkPoint kOctagonOuter[]
staticconstexpr
Initial value:

Definition at line 941 of file GrOvalOpFactory.cpp.

◆ kOctOffset

constexpr SkScalar kOctOffset = 0.41421356237f
staticconstexpr

Definition at line 940 of file GrOvalOpFactory.cpp.

◆ kSinPi8

constexpr SkScalar kSinPi8 = 0.382683432f
staticconstexpr

Definition at line 954 of file GrOvalOpFactory.cpp.

◆ kVertsPerFillCircle

const int kVertsPerFillCircle = 9
static

Definition at line 969 of file GrOvalOpFactory.cpp.

◆ kVertsPerOverstrokeRRect

const int kVertsPerOverstrokeRRect = 24
static

Definition at line 2459 of file GrOvalOpFactory.cpp.

◆ kVertsPerStandardRRect

const int kVertsPerStandardRRect = 16
static

Definition at line 2458 of file GrOvalOpFactory.cpp.

◆ kVertsPerStrokeCircle

const int kVertsPerStrokeCircle = 16
static

Definition at line 968 of file GrOvalOpFactory.cpp.