本文整理汇总了C++中sk_sp类的典型用法代码示例。如果您正苦于以下问题:C++ sk_sp类的具体用法?C++ sk_sp怎么用?C++ sk_sp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了sk_sp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onDraw
void onDraw(SkCanvas* canvas) override {
canvas->translate(20, 20);
const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) {
sk_sp<SkImage> image(gProcs[i](canvas->getGrContext(), fPicture.get(), info));
if (image) {
this->testImage(canvas, image.get());
}
canvas->translate(120, 0);
}
}
示例2: initPathEffect
void GrStyle::initPathEffect(sk_sp<SkPathEffect> pe) {
SkASSERT(!fPathEffect);
SkASSERT(SkPathEffect::kNone_DashType == fDashInfo.fType);
SkASSERT(0 == fDashInfo.fIntervals.count());
if (!pe) {
return;
}
SkPathEffect::DashInfo info;
if (SkPathEffect::kDash_DashType == pe->asADash(&info)) {
SkStrokeRec::Style recStyle = fStrokeRec.getStyle();
if (recStyle != SkStrokeRec::kFill_Style && recStyle != SkStrokeRec::kStrokeAndFill_Style) {
fDashInfo.fType = SkPathEffect::kDash_DashType;
fDashInfo.fIntervals.reset(info.fCount);
fDashInfo.fPhase = info.fPhase;
info.fIntervals = fDashInfo.fIntervals.get();
pe->asADash(&info);
fPathEffect = std::move(pe);
}
} else {
fPathEffect = std::move(pe);
}
}
示例3: SkASSERT
std::unique_ptr<GrDrawOp> GrDrawVerticesOp::Make(GrPaint&& paint,
sk_sp<SkVertices> vertices,
const SkMatrix& viewMatrix,
GrAAType aaType,
bool gammaCorrect,
sk_sp<GrColorSpaceXform> colorSpaceXform,
GrPrimitiveType* overridePrimType) {
SkASSERT(vertices);
GrPrimitiveType primType = overridePrimType ? *overridePrimType
: SkVertexModeToGrPrimitiveType(vertices->mode());
return Helper::FactoryHelper<GrDrawVerticesOp>(std::move(paint), std::move(vertices), primType,
aaType, gammaCorrect, std::move(colorSpaceXform),
viewMatrix);
}
示例4: SkDEBUGFAIL
sk_sp<GrTextureContext> GrDrawingManager::makeTextureContext(sk_sp<GrSurfaceProxy> sProxy,
sk_sp<SkColorSpace> colorSpace) {
if (this->wasAbandoned() || !sProxy->asTextureProxy()) {
return nullptr;
}
// SkSurface catches bad color space usage at creation. This check handles anything that slips
// by, including internal usage.
if (!SkSurface_Gpu::Valid(fContext, sProxy->config(), colorSpace.get())) {
SkDEBUGFAIL("Invalid config and colorspace combination");
return nullptr;
}
// GrTextureRenderTargets should always be using a GrRenderTargetContext
SkASSERT(!sProxy->asRenderTargetProxy());
sk_sp<GrTextureProxy> textureProxy(sk_ref_sp(sProxy->asTextureProxy()));
return sk_sp<GrTextureContext>(new GrTextureContext(fContext, this, std::move(textureProxy),
std::move(colorSpace),
fContext->contextPriv().getAuditTrail(),
fSingleOwner));
}
示例5: sk_ref_sp
sk_sp<SkImage> SkImage::makeColorSpace(sk_sp<SkColorSpace> target,
SkTransferFunctionBehavior premulBehavior) const {
SkColorSpaceTransferFn fn;
if (!target || !target->isNumericalTransferFn(&fn)) {
return nullptr;
}
// No need to create a new image if:
// (1) The color spaces are equal.
// (2) The color type is kAlpha8.
if (SkColorSpace::Equals(this->colorSpace(), target.get()) ||
kAlpha_8_SkColorType == as_IB(this)->onImageInfo().colorType()) {
return sk_ref_sp(const_cast<SkImage*>(this));
}
SkColorType targetColorType = kN32_SkColorType;
if (SkTransferFunctionBehavior::kRespect == premulBehavior && target->gammaIsLinear()) {
targetColorType = kRGBA_F16_SkColorType;
}
// TODO: We might consider making this a deferred conversion?
return as_IB(this)->onMakeColorSpace(std::move(target), targetColorType, premulBehavior);
}
示例6: SkASSERT
void GrResourceIOProcessor::TextureSampler::reset(GrResourceProvider* resourceProvider,
sk_sp<GrTextureProxy> proxy,
GrSamplerParams::FilterMode filterMode,
SkShader::TileMode tileXAndY,
GrShaderFlags visibility) {
// For now, end the deferral at this time. Once all the TextureSamplers are swapped over
// to taking a GrSurfaceProxy just use the IORefs on the proxy
GrTexture* texture = proxy->instantiate(resourceProvider);
SkASSERT(texture);
fTexture.set(SkRef(texture), kRead_GrIOType);
filterMode = SkTMin(filterMode, texture->texturePriv().highestFilterMode());
fParams.reset(tileXAndY, filterMode);
fVisibility = visibility;
}
示例7: FuzzImageFilterDeserialize
void FuzzImageFilterDeserialize(sk_sp<SkData> bytes) {
const int BitmapSize = 24;
SkBitmap bitmap;
bitmap.allocN32Pixels(BitmapSize, BitmapSize);
SkCanvas canvas(bitmap);
canvas.clear(0x00000000);
auto flattenable = SkImageFilter::Deserialize(bytes->data(), bytes->size());
if (flattenable != nullptr) {
// Let's see if using the filters can cause any trouble...
SkPaint paint;
paint.setImageFilter(flattenable);
canvas.save();
canvas.clipRect(SkRect::MakeXYWH(
0, 0, SkIntToScalar(BitmapSize), SkIntToScalar(BitmapSize)));
// This call shouldn't crash or cause ASAN to flag any memory issues
// If nothing bad happens within this call, everything is fine
canvas.drawBitmap(bitmap, 0, 0, &paint);
canvas.restore();
}
}
示例8: test_surface
// Exercise the public API of SkSpecialSurface (e.g., getCanvas, newImageSnapshot)
static void test_surface(const sk_sp<SkSpecialSurface>& surf,
skiatest::Reporter* reporter,
int offset) {
const SkIRect surfSubset = TestingSpecialSurfaceAccess::Subset(surf.get());
REPORTER_ASSERT(reporter, offset == surfSubset.fLeft);
REPORTER_ASSERT(reporter, offset == surfSubset.fTop);
REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.width());
REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.height());
SkCanvas* canvas = surf->getCanvas();
SkASSERT_RELEASE(canvas);
canvas->clear(SK_ColorRED);
sk_sp<SkSpecialImage> img(surf->makeImageSnapshot());
REPORTER_ASSERT(reporter, img);
const SkIRect imgSubset = img->subset();
REPORTER_ASSERT(reporter, surfSubset == imgSubset);
// the canvas was invalidated by the newImageSnapshot call
REPORTER_ASSERT(reporter, !surf->getCanvas());
}
示例9: AttachStroke
sk_sp<sksg::PaintNode> AttachStroke(const Json::Value& jstroke, AttachContext* ctx,
sk_sp<sksg::PaintNode> stroke_node) {
SkASSERT(jstroke.isObject());
if (!stroke_node)
return nullptr;
stroke_node->setStyle(SkPaint::kStroke_Style);
auto width_attached = BindProperty<ScalarValue>(jstroke["w"], &ctx->fAnimators,
[stroke_node](const ScalarValue& w) {
stroke_node->setStrokeWidth(w);
});
if (!width_attached)
return nullptr;
stroke_node->setStrokeMiter(ParseDefault(jstroke["ml"], 4.0f));
static constexpr SkPaint::Join gJoins[] = {
SkPaint::kMiter_Join,
SkPaint::kRound_Join,
SkPaint::kBevel_Join,
};
stroke_node->setStrokeJoin(gJoins[SkTPin<int>(ParseDefault(jstroke["lj"], 1) - 1,
0, SK_ARRAY_COUNT(gJoins) - 1)]);
static constexpr SkPaint::Cap gCaps[] = {
SkPaint::kButt_Cap,
SkPaint::kRound_Cap,
SkPaint::kSquare_Cap,
};
stroke_node->setStrokeCap(gCaps[SkTPin<int>(ParseDefault(jstroke["lc"], 1) - 1,
0, SK_ARRAY_COUNT(gCaps) - 1)]);
return stroke_node;
}
示例10: proc
sk_sp<SkPixelRef> SkMallocPixelRef::MakeWithProc(const SkImageInfo& info,
size_t rowBytes,
sk_sp<SkColorTable> ctable,
void* addr,
SkMallocPixelRef::ReleaseProc proc,
void* context) {
if (!is_valid(info, ctable.get())) {
if (proc) {
proc(addr, context);
}
return nullptr;
}
return sk_sp<SkPixelRef>(new SkMallocPixelRef(info, addr, rowBytes, std::move(ctable),
proc, context));
}
示例11: SkASSERT
sk_sp<GrTextureProxy> GrTextureProducer::CopyOnGpu(GrContext* context,
sk_sp<GrTextureProxy> inputProxy,
const CopyParams& copyParams,
bool dstWillRequireMipMaps) {
SkASSERT(context);
const SkRect dstRect = SkRect::MakeIWH(copyParams.fWidth, copyParams.fHeight);
GrMipMapped mipMapped = dstWillRequireMipMaps ? GrMipMapped::kYes : GrMipMapped::kNo;
SkRect localRect = SkRect::MakeWH(inputProxy->width(), inputProxy->height());
bool needsDomain = false;
bool resizing = false;
if (copyParams.fFilter != GrSamplerState::Filter::kNearest) {
bool resizing = localRect.width() != dstRect.width() ||
localRect.height() != dstRect.height();
needsDomain = resizing && !GrProxyProvider::IsFunctionallyExact(inputProxy.get());
}
if (copyParams.fFilter == GrSamplerState::Filter::kNearest && !needsDomain && !resizing &&
dstWillRequireMipMaps) {
sk_sp<GrTextureProxy> proxy = GrCopyBaseMipMapToTextureProxy(context, inputProxy.get());
if (proxy) {
return proxy;
}
}
sk_sp<GrRenderTargetContext> copyRTC =
context->contextPriv().makeDeferredRenderTargetContextWithFallback(
SkBackingFit::kExact, dstRect.width(), dstRect.height(), inputProxy->config(),
nullptr, 1, mipMapped, inputProxy->origin());
if (!copyRTC) {
return nullptr;
}
GrPaint paint;
if (needsDomain) {
const SkRect domain = localRect.makeInset(0.5f, 0.5f);
// This would cause us to read values from outside the subset. Surely, the caller knows
// better!
SkASSERT(copyParams.fFilter != GrSamplerState::Filter::kMipMap);
paint.addColorFragmentProcessor(
GrTextureDomainEffect::Make(std::move(inputProxy), SkMatrix::I(), domain,
GrTextureDomain::kClamp_Mode, copyParams.fFilter));
} else {
GrSamplerState samplerState(GrSamplerState::WrapMode::kClamp, copyParams.fFilter);
paint.addColorTextureProcessor(std::move(inputProxy), SkMatrix::I(), samplerState);
}
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
copyRTC->fillRectToRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), dstRect,
localRect);
return copyRTC->asTextureProxyRef();
}
示例12: SkSpecialSurface_Gpu
SkSpecialSurface_Gpu(GrContext* context, sk_sp<GrRenderTargetContext> renderTargetContext,
int width, int height, const SkIRect& subset)
: INHERITED(subset, &renderTargetContext->surfaceProps())
, fRenderTargetContext(std::move(renderTargetContext)) {
sk_sp<SkBaseDevice> device(SkGpuDevice::Make(context, fRenderTargetContext, width, height,
SkGpuDevice::kUninit_InitContents));
if (!device) {
return;
}
fCanvas.reset(new SkCanvas(device));
fCanvas->clipRect(SkRect::Make(subset));
#ifdef SK_IS_BOT
fCanvas->clear(SK_ColorRED); // catch any imageFilter sloppiness
#endif
}
示例13: gradCheck
void gradCheck(skiatest::Reporter* reporter, const sk_sp<SkShader>& shader,
SkShader::GradientInfo* info,
SkShader::GradientType gt) const {
SkAutoTMalloc<SkColor> colorStorage(fColorCount);
SkAutoTMalloc<SkScalar> posStorage(fColorCount);
info->fColorCount = fColorCount;
info->fColors = colorStorage;
info->fColorOffsets = posStorage.get();
REPORTER_ASSERT(reporter, shader->asAGradient(info) == gt);
REPORTER_ASSERT(reporter, info->fColorCount == fColorCount);
REPORTER_ASSERT(reporter,
!memcmp(info->fColors, fColors, fColorCount * sizeof(SkColor)));
REPORTER_ASSERT(reporter,
!memcmp(info->fColorOffsets, fPos, fColorCount * sizeof(SkScalar)));
REPORTER_ASSERT(reporter, fTileMode == (SkTileMode)info->fTileMode);
}
示例14: test_dont_find_if_diff_key
// If either id is different or the clip or the matrix are different the
// cached image won't be found. Even if it is caching the same bitmap.
static void test_dont_find_if_diff_key(skiatest::Reporter* reporter,
const sk_sp<SkSpecialImage>& image,
const sk_sp<SkSpecialImage>& subset) {
static const size_t kCacheSize = 1000000;
SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kCacheSize));
SkIRect clip1 = SkIRect::MakeWH(100, 100);
SkIRect clip2 = SkIRect::MakeWH(200, 200);
SkImageFilter::Cache::Key key0(0, SkMatrix::I(), clip1, image->uniqueID(), image->subset());
SkImageFilter::Cache::Key key1(1, SkMatrix::I(), clip1, image->uniqueID(), image->subset());
SkImageFilter::Cache::Key key2(0, SkMatrix::MakeTrans(5, 5), clip1,
image->uniqueID(), image->subset());
SkImageFilter::Cache::Key key3(0, SkMatrix::I(), clip2, image->uniqueID(), image->subset());
SkImageFilter::Cache::Key key4(0, SkMatrix::I(), clip1, subset->uniqueID(), subset->subset());
SkIPoint offset = SkIPoint::Make(3, 4);
cache->set(key0, image.get(), offset);
SkIPoint foundOffset;
REPORTER_ASSERT(reporter, !cache->get(key1, &foundOffset));
REPORTER_ASSERT(reporter, !cache->get(key2, &foundOffset));
REPORTER_ASSERT(reporter, !cache->get(key3, &foundOffset));
REPORTER_ASSERT(reporter, !cache->get(key4, &foundOffset));
}
示例15: SkASSERT
std::unique_ptr<GrDrawOp> GrDrawVerticesOp::Make(GrRecordingContext* context,
GrPaint&& paint,
sk_sp<SkVertices> vertices,
const SkVertices::Bone bones[],
int boneCount,
const SkMatrix& viewMatrix,
GrAAType aaType,
sk_sp<GrColorSpaceXform> colorSpaceXform,
GrPrimitiveType* overridePrimType) {
SkASSERT(vertices);
GrPrimitiveType primType = overridePrimType ? *overridePrimType
: SkVertexModeToGrPrimitiveType(vertices->mode());
return GrSimpleMeshDrawOpHelper::FactoryHelper<DrawVerticesOp>(context, std::move(paint),
std::move(vertices),
bones, boneCount,
primType, aaType,
std::move(colorSpaceXform),
viewMatrix);
}