38static const int DEFAULT_BUFFER_SIZE = 100;
42static const SkScalar kMaxStrokeWidth = 20.0;
48 const VertexColor&
color,
51 VertexWriter verts{vertData};
52 for (
int i = 0;
i <
tess.numPts(); ++
i) {
54 if (localCoordsMatrix) {
61 for (
int i = 0;
i <
tess.numIndices(); ++
i) {
62 idxs[
i] =
tess.index(
i) + firstIndex;
67 bool tweakAlphaForCoverage,
73 tweakAlphaForCoverage ? Coverage::kAttributeTweakAlpha_Type : Coverage::kAttribute_Type;
75 usesLocalCoords ? LocalCoords::kHasExplicit_Type : LocalCoords::kUnused_Type;
77 wideColor ? Color::kPremulWideColorAttribute_Type : Color::kPremulGrColorAttribute_Type;
82class AAFlatteningConvexPathOp final :
public GrMeshDrawOp {
98 return Helper::FactoryHelper<AAFlatteningConvexPathOp>(context, std::move(
paint),
130 this->setTransformedBounds(
bounds, viewMatrix, HasAABloat::kYes, IsHairline::kNo);
133 const char*
name()
const override {
return "AAFlatteningConvexPathOp"; }
143 FixedFunctionFlags fixedFunctionFlags()
const override {
return fHelper.
fixedFunctionFlags(); }
149 &fPaths.back().fColor, &fWideColor);
153 GrProgramInfo* programInfo()
override {
return fProgramInfo; }
155 void onCreateProgramInfo(
const GrCaps* caps,
158 bool usesMSAASurface,
168 SkDebugf(
"Couldn't create a GrGeometryProcessor\n");
173 std::move(appliedClip), dstProxyView,
175 renderPassXferBarriers, colorLoadOp);
179 int vertexCount,
size_t vertexStride,
void* vertices,
180 int indexCount, uint16_t* indices) {
181 if (vertexCount == 0 || indexCount == 0) {
186 void* verts =
target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer,
189 SkDebugf(
"Could not allocate vertices\n");
192 memcpy(verts, vertices, vertexCount * vertexStride);
196 uint16_t* idxs =
target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex);
198 SkDebugf(
"Could not allocate indices\n");
201 memcpy(idxs, indices, indexCount *
sizeof(uint16_t));
203 mesh->setIndexed(std::move(indexBuffer), indexCount, firstIndex, 0, vertexCount - 1,
210 this->createProgramInfo(
target);
217 int instanceCount = fPaths.size();
219 int64_t vertexCount = 0;
220 int64_t indexCount = 0;
221 int64_t maxVertices = DEFAULT_BUFFER_SIZE;
222 int64_t maxIndices = DEFAULT_BUFFER_SIZE;
223 uint8_t* vertices = (uint8_t*)
sk_malloc_throw(maxVertices * vertexStride);
224 uint16_t* indices = (uint16_t*)
sk_malloc_throw(maxIndices *
sizeof(uint16_t));
225 for (
int i = 0;
i < instanceCount;
i++) {
226 const PathData&
args = fPaths[
i];
234 int currentVertices =
tess.numPts();
235 if (vertexCount + currentVertices >
static_cast<int>(UINT16_MAX)) {
238 this->recordDraw(
target, vertexCount, vertexStride, vertices, indexCount, indices);
242 if (vertexCount + currentVertices > maxVertices) {
243 maxVertices =
std::max(vertexCount + currentVertices, maxVertices * 2);
244 if (maxVertices * vertexStride >
SK_MaxS32) {
249 vertices = (uint8_t*)
sk_realloc_throw(vertices, maxVertices * vertexStride);
251 int currentIndices =
tess.numIndices();
252 if (indexCount + currentIndices > maxIndices) {
253 maxIndices =
std::max(indexCount + currentIndices, maxIndices * 2);
254 if (maxIndices *
sizeof(uint16_t) >
SK_MaxS32) {
259 indices = (uint16_t*)
sk_realloc_throw(indices, maxIndices *
sizeof(uint16_t));
262 const SkMatrix* localCoordsMatrix =
nullptr;
265 if (!
args.fViewMatrix.invert(&ivm)) {
268 localCoordsMatrix = &ivm;
271 extract_verts(
tess, localCoordsMatrix, vertices + vertexStride * vertexCount,
272 VertexColor(
args.fColor, fWideColor), vertexCount, indices + indexCount);
273 vertexCount += currentVertices;
274 indexCount += currentIndices;
277 this->recordDraw(
target, vertexCount, vertexStride, vertices, indexCount, indices);
284 if (!fProgramInfo ||
fMeshes.empty()) {
296 AAFlatteningConvexPathOp* that = t->
cast<AAFlatteningConvexPathOp>();
297 if (!fHelper.
isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
298 return CombineResult::kCannotCombine;
301 fPaths.push_back_n(that->fPaths.size(), that->fPaths.begin());
302 fWideColor |= that->fWideColor;
303 return CombineResult::kMerged;
306#if defined(GR_TEST_UTILS)
307 SkString onDumpInfo()
const override {
309 for (
const auto&
path : fPaths) {
311 "Color: 0x%08x, StrokeWidth: %.2f, Style: %d, Join: %d, "
312 "MiterLimit: %.2f\n",
316 string += fHelper.dumpInfo();
346AALinearizingConvexPathRenderer::onCanDrawPath(
const CanDrawPathArgs&
args)
const {
350 if (!
args.fShape->knownToBeConvex()) {
353 if (
args.fShape->style().pathEffect()) {
356 if (
args.fShape->inverseFilled()) {
359 if (
args.fShape->bounds().width() <= 0 &&
args.fShape->bounds().height() <= 0) {
367 if (!
args.fViewMatrix->isSimilarity()) {
375 !
args.fShape->knownToBeClosed() ||
376 stroke.getJoin() == SkPaint::Join::kRound_Join) {
387 if (
args.fViewMatrix->hasPerspective()) {
393bool AALinearizingConvexPathRenderer::onDrawPath(
const DrawPathArgs&
args) {
395 "AALinearizingConvexPathRenderer::onDrawPath");
402 bool fill =
args.fShape->style().isSimpleFill();
411 args.fSurfaceDrawContext->addDrawOp(
args.fClip, std::move(op));
417#if defined(GR_TEST_UTILS)
419GR_DRAW_OP_TEST_DEFINE(AAFlatteningConvexPathOp) {
420 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
421 const SkPath&
path = GrTest::TestPathConvex(random);
435 if (random->nextBool()) {
440 miterLimit = random->nextRangeF(0.5f, 2.0f);
SkStrokeRec::Style fStyle
static const int strokeWidth
#define GR_AUDIT_TRAIL_AUTO_FRAME(audit_trail, framename)
#define DEFINE_OP_CLASS_ID
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SK_API void sk_free(void *)
static void * sk_malloc_throw(size_t size)
SK_API void * sk_realloc_throw(void *buffer, size_t size)
static constexpr int32_t SK_MaxS32
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
#define INHERITED(method,...)
size_t vertexStride() const
void drawMesh(const GrSimpleMesh &mesh)
void bindPipelineAndScissorClip(const GrProgramInfo &programInfo, const SkRect &drawBounds)
void bindTextures(const GrGeometryProcessor &geomProc, const GrSurfaceProxy &singleGeomProcTexture, const GrPipeline &pipeline)
std::unique_ptr< GrOp > Owner
const GrPipeline & pipeline() const
const GrGeometryProcessor & geomProc() const
void visitFPProxies(const GrVisitProxyFunc &func) const
GrProcessorSet::Analysis finalizeProcessors(const GrCaps &caps, const GrAppliedClip *clip, GrClampType clampType, GrProcessorAnalysisCoverage geometryCoverage, GrProcessorAnalysisColor *geometryColor)
void visitProxies(const GrVisitProxyFunc &func) const
GrDrawOp::FixedFunctionFlags fixedFunctionFlags() const
bool isCompatible(const GrSimpleMeshDrawOpHelperWithStencil &that, const GrCaps &, const SkRect &thisBounds, const SkRect &thatBounds, bool ignoreAAType=false) const
bool usesLocalCoords() const
bool compatibleWithCoverageAsAlpha() const
GrProgramInfo * createProgramInfoWithStencil(const GrCaps *, SkArenaAlloc *, const GrSurfaceProxyView &writeView, bool usesMSAASurface, GrAppliedClip &&, const GrDstProxyView &, GrGeometryProcessor *, GrPrimitiveType, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp)
void mapPoints(SkPoint dst[], const SkPoint src[], int count) const
static const SkMatrix & I()
SkScalar getMaxScale() const
@ kMiter_Join
extends to miter limit
@ kBevel_Join
connects outside edges
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static float max(float r, float g, float b)
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
Optional< SkRect > bounds
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
DEF_SWITCHES_START aot vmservice shared library name
static TessellatorLibtess tess
static SkString join(const CommandLineFlags::StringArray &)
static Conditional< T > If(bool condition, const T &value)