本文整理汇总了C++中SkTLazy::init方法的典型用法代码示例。如果您正苦于以下问题:C++ SkTLazy::init方法的具体用法?C++ SkTLazy::init怎么用?C++ SkTLazy::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkTLazy
的用法示例。
在下文中一共展示了SkTLazy::init方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onPrepareDraws
void onPrepareDraws(Target* target) const override {
SkMatrix invert;
if (fUsesLocalCoords && !fViewMatrix.invert(&invert)) {
SkDebugf("Could not invert viewmatrix\n");
return;
}
// Setup GrGeometryProcessors
SkAutoTUnref<GrPLSGeometryProcessor> triangleProcessor(
PLSAATriangleEffect::Create(invert, fUsesLocalCoords));
SkAutoTUnref<GrPLSGeometryProcessor> quadProcessor(
PLSQuadEdgeEffect::Create(invert, fUsesLocalCoords));
GrResourceProvider* rp = target->resourceProvider();
SkRect bounds;
this->bounds().roundOut(&bounds);
triangleProcessor->setBounds(bounds);
quadProcessor->setBounds(bounds);
// We use the fact that SkPath::transform path does subdivision based on
// perspective. Otherwise, we apply the view matrix when copying to the
// segment representation.
const SkMatrix* viewMatrix = &fViewMatrix;
// We avoid initializing the path unless we have to
const SkPath* pathPtr = &fPath;
SkTLazy<SkPath> tmpPath;
if (viewMatrix->hasPerspective()) {
SkPath* tmpPathPtr = tmpPath.init(*pathPtr);
tmpPathPtr->setIsVolatile(true);
tmpPathPtr->transform(*viewMatrix);
viewMatrix = &SkMatrix::I();
pathPtr = tmpPathPtr;
}
GrMesh mesh;
PLSVertices triVertices;
PLSVertices quadVertices;
if (!get_geometry(*pathPtr, *viewMatrix, triVertices, quadVertices, rp, bounds)) {
return;
}
if (triVertices.count()) {
const GrBuffer* triVertexBuffer;
int firstTriVertex;
size_t triStride = triangleProcessor->getVertexStride();
PLSVertex* triVerts = reinterpret_cast<PLSVertex*>(target->makeVertexSpace(
triStride, triVertices.count(), &triVertexBuffer, &firstTriVertex));
if (!triVerts) {
SkDebugf("Could not allocate vertices\n");
return;
}
for (int i = 0; i < triVertices.count(); ++i) {
triVerts[i] = triVertices[i];
}
mesh.init(kTriangles_GrPrimitiveType, triVertexBuffer, firstTriVertex,
triVertices.count());
target->draw(triangleProcessor, mesh);
}
if (quadVertices.count()) {
const GrBuffer* quadVertexBuffer;
int firstQuadVertex;
size_t quadStride = quadProcessor->getVertexStride();
PLSVertex* quadVerts = reinterpret_cast<PLSVertex*>(target->makeVertexSpace(
quadStride, quadVertices.count(), &quadVertexBuffer, &firstQuadVertex));
if (!quadVerts) {
SkDebugf("Could not allocate vertices\n");
return;
}
for (int i = 0; i < quadVertices.count(); ++i) {
quadVerts[i] = quadVertices[i];
}
mesh.init(kTriangles_GrPrimitiveType, quadVertexBuffer, firstQuadVertex,
quadVertices.count());
target->draw(quadProcessor, mesh);
}
SkAutoTUnref<GrGeometryProcessor> finishProcessor(
PLSFinishEffect::Create(fColor,
pathPtr->getFillType() ==
SkPath::FillType::kEvenOdd_FillType,
invert,
fUsesLocalCoords));
const GrBuffer* rectVertexBuffer;
size_t finishStride = finishProcessor->getVertexStride();
int firstRectVertex;
static const int kRectVertexCount = 6;
SkPoint* rectVerts = reinterpret_cast<SkPoint*>(target->makeVertexSpace(
finishStride, kRectVertexCount, &rectVertexBuffer, &firstRectVertex));
if (!rectVerts) {
SkDebugf("Could not allocate vertices\n");
return;
}
rectVerts[0] = { bounds.fLeft, bounds.fTop };
rectVerts[1] = { bounds.fLeft, bounds.fBottom };
rectVerts[2] = { bounds.fRight, bounds.fBottom };
rectVerts[3] = { bounds.fLeft, bounds.fTop };
//.........这里部分代码省略.........
示例2: onPrepareDraws
void onPrepareDraws(Target* target) const override {
#ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS
if (this->linesOnly()) {
this->prepareLinesOnlyDraws(target);
return;
}
#endif
int instanceCount = fGeoData.count();
SkMatrix invert;
if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) {
SkDebugf("Could not invert viewmatrix\n");
return;
}
// Setup GrGeometryProcessor
sk_sp<GrGeometryProcessor> quadProcessor(
QuadEdgeEffect::Make(this->color(), invert, this->usesLocalCoords()));
// TODO generate all segments for all paths and use one vertex buffer
for (int i = 0; i < instanceCount; i++) {
const Geometry& args = fGeoData[i];
// We use the fact that SkPath::transform path does subdivision based on
// perspective. Otherwise, we apply the view matrix when copying to the
// segment representation.
const SkMatrix* viewMatrix = &args.fViewMatrix;
// We avoid initializing the path unless we have to
const SkPath* pathPtr = &args.fPath;
SkTLazy<SkPath> tmpPath;
if (viewMatrix->hasPerspective()) {
SkPath* tmpPathPtr = tmpPath.init(*pathPtr);
tmpPathPtr->setIsVolatile(true);
tmpPathPtr->transform(*viewMatrix);
viewMatrix = &SkMatrix::I();
pathPtr = tmpPathPtr;
}
int vertexCount;
int indexCount;
enum {
kPreallocSegmentCnt = 512 / sizeof(Segment),
kPreallocDrawCnt = 4,
};
SkSTArray<kPreallocSegmentCnt, Segment, true> segments;
SkPoint fanPt;
if (!get_segments(*pathPtr, *viewMatrix, &segments, &fanPt, &vertexCount,
&indexCount)) {
continue;
}
const GrBuffer* vertexBuffer;
int firstVertex;
size_t vertexStride = quadProcessor->getVertexStride();
QuadVertex* verts = reinterpret_cast<QuadVertex*>(target->makeVertexSpace(
vertexStride, vertexCount, &vertexBuffer, &firstVertex));
if (!verts) {
SkDebugf("Could not allocate vertices\n");
return;
}
const GrBuffer* indexBuffer;
int firstIndex;
uint16_t *idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex);
if (!idxs) {
SkDebugf("Could not allocate indices\n");
return;
}
SkSTArray<kPreallocDrawCnt, Draw, true> draws;
create_vertices(segments, fanPt, &draws, verts, idxs);
GrMesh mesh;
for (int j = 0; j < draws.count(); ++j) {
const Draw& draw = draws[j];
mesh.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer,
firstVertex, firstIndex, draw.fVertexCnt, draw.fIndexCnt);
target->draw(quadProcessor.get(), mesh);
firstVertex += draw.fVertexCnt;
firstIndex += draw.fIndexCnt;
}
}
}
示例3: tmpStroke
GrGLPath::GrGLPath(GrGLGpu* gpu, const SkPath& origSkPath, const GrStrokeInfo& origStroke)
: INHERITED(gpu, origSkPath, origStroke),
fPathID(gpu->glPathRendering()->genPaths(1)) {
if (origSkPath.isEmpty()) {
InitPathObjectEmptyPath(gpu, fPathID);
fShouldStroke = false;
fShouldFill = false;
} else {
const SkPath* skPath = &origSkPath;
SkTLazy<SkPath> tmpPath;
const GrStrokeInfo* stroke = &origStroke;
GrStrokeInfo tmpStroke(SkStrokeRec::kFill_InitStyle);
if (stroke->isDashed()) {
// Skia stroking and NVPR stroking differ with respect to dashing
// pattern.
// Convert a dashing to either a stroke or a fill.
if (stroke->applyDashToPath(tmpPath.init(), &tmpStroke, *skPath)) {
skPath = tmpPath.get();
stroke = &tmpStroke;
}
}
bool didInit = false;
if (stroke->needToApply() && stroke->getCap() != SkPaint::kButt_Cap) {
// Skia stroking and NVPR stroking differ with respect to stroking
// end caps of empty subpaths.
// Convert stroke to fill if path contains empty subpaths.
didInit = InitPathObjectPathDataCheckingDegenerates(gpu, fPathID, *skPath);
if (!didInit) {
if (!tmpPath.isValid()) {
tmpPath.init();
}
SkAssertResult(stroke->applyToPath(tmpPath.get(), *skPath));
skPath = tmpPath.get();
tmpStroke.setFillStyle();
stroke = &tmpStroke;
}
}
if (!didInit) {
InitPathObjectPathData(gpu, fPathID, *skPath);
}
fShouldStroke = stroke->needToApply();
fShouldFill = stroke->isFillStyle() ||
stroke->getStyle() == SkStrokeRec::kStrokeAndFill_Style;
fFillType = convert_skpath_filltype(skPath->getFillType());
fBounds = skPath->getBounds();
if (fShouldStroke) {
InitPathObjectStroke(gpu, fPathID, *stroke);
// FIXME: try to account for stroking, without rasterizing the stroke.
fBounds.outset(stroke->getWidth(), stroke->getWidth());
}
}
this->registerWithCache();
}
示例4: draw_path_with_mask_filter
static void draw_path_with_mask_filter(GrContext* context,
GrDrawContext* drawContext,
const GrClip& clip,
GrPaint* paint,
const SkMatrix& viewMatrix,
const SkMaskFilter* maskFilter,
const GrStyle& style,
const SkPath* path,
bool pathIsMutable) {
SkASSERT(maskFilter);
SkIRect clipBounds;
clip.getConservativeBounds(drawContext->width(), drawContext->height(), &clipBounds);
SkTLazy<SkPath> tmpPath;
SkStrokeRec::InitStyle fillOrHairline;
// We just fully apply the style here.
if (style.applies()) {
SkScalar scale = GrStyle::MatrixToScaleFactor(viewMatrix);
if (0 == scale || !style.applyToPath(tmpPath.init(), &fillOrHairline, *path, scale)) {
return;
}
pathIsMutable = true;
path = tmpPath.get();
} else if (style.isSimpleHairline()) {
fillOrHairline = SkStrokeRec::kHairline_InitStyle;
} else {
SkASSERT(style.isSimpleFill());
fillOrHairline = SkStrokeRec::kFill_InitStyle;
}
// transform the path into device space
if (!viewMatrix.isIdentity()) {
SkPath* result;
if (pathIsMutable) {
result = const_cast<SkPath*>(path);
} else {
if (!tmpPath.isValid()) {
tmpPath.init();
}
result = tmpPath.get();
}
path->transform(viewMatrix, result);
path = result;
result->setIsVolatile(true);
pathIsMutable = true;
}
SkRect maskRect;
if (maskFilter->canFilterMaskGPU(SkRRect::MakeRect(path->getBounds()),
clipBounds,
viewMatrix,
&maskRect)) {
// This mask will ultimately be drawn as a non-AA rect (see draw_mask).
// Non-AA rects have a bad habit of snapping arbitrarily. Integerize here
// so the mask draws in a reproducible manner.
SkIRect finalIRect;
maskRect.roundOut(&finalIRect);
if (clip_bounds_quick_reject(clipBounds, finalIRect)) {
// clipped out
return;
}
if (maskFilter->directFilterMaskGPU(context->textureProvider(),
drawContext,
paint,
clip,
viewMatrix,
SkStrokeRec(fillOrHairline),
*path)) {
// the mask filter was able to draw itself directly, so there's nothing
// left to do.
return;
}
sk_sp<GrTexture> mask(create_mask_GPU(context,
finalIRect,
*path,
fillOrHairline,
paint->isAntiAlias(),
drawContext->numColorSamples()));
if (mask) {
GrTexture* filtered;
if (maskFilter->filterMaskGPU(mask.get(), viewMatrix, finalIRect, &filtered)) {
// filterMaskGPU gives us ownership of a ref to the result
SkAutoTUnref<GrTexture> atu(filtered);
if (draw_mask(drawContext, clip, viewMatrix, finalIRect, paint, filtered)) {
// This path is completely drawn
return;
}
}
}
}
sw_draw_with_mask_filter(drawContext, context->textureProvider(),
clip, viewMatrix, *path,
maskFilter, clipBounds, paint, fillOrHairline);
}