本文整理汇总了C++中SkRect::makeInset方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRect::makeInset方法的具体用法?C++ SkRect::makeInset怎么用?C++ SkRect::makeInset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRect
的用法示例。
在下文中一共展示了SkRect::makeInset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onDraw
void onDraw(SkCanvas* canvas) override {
SkPaint blurPaint;
SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(5.0f, 5.0f));
blurPaint.setImageFilter(blur);
const SkScalar tile_size = SkIntToScalar(128);
SkRect bounds;
if (!canvas->getClipBounds(&bounds)) {
bounds.setEmpty();
}
int ts = SkScalarCeilToInt(tile_size);
SkImageInfo info = SkImageInfo::MakeN32Premul(ts, ts);
SkAutoTUnref<SkSurface> tileSurface(canvas->newSurface(info));
if (!tileSurface.get()) {
tileSurface.reset(SkSurface::NewRaster(info));
}
SkCanvas* tileCanvas = tileSurface->getCanvas();
for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tile_size) {
for (SkScalar x = bounds.left(); x < bounds.right(); x += tile_size) {
tileCanvas->save();
tileCanvas->clear(0);
tileCanvas->translate(-x, -y);
SkRect rect = SkRect::MakeWH(WIDTH, HEIGHT);
tileCanvas->saveLayer(&rect, &blurPaint);
SkRRect rrect = SkRRect::MakeRectXY(rect.makeInset(20, 20), 25, 25);
tileCanvas->clipRRect(rrect, SkRegion::kDifference_Op, true);
SkPaint paint;
tileCanvas->drawRect(rect, paint);
tileCanvas->restore();
tileCanvas->restore();
canvas->drawImage(tileSurface->makeImageSnapshot().get(), x, y);
}
}
}
示例2: samplerState
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();
}
示例3: onDraw
void onDraw(int loops, SkCanvas* canvas) override {
SkPaint paint;
static const SkScalar kX = 0;
static const SkScalar kY = 0;
const SkRect bmpRect = SkRect::MakeXYWH(kX, kY,
SkIntToScalar(fCheckerboard.width()),
SkIntToScalar(fCheckerboard.height()));
const SkImageFilter::CropRect cropRect =
SkImageFilter::CropRect(bmpRect.makeInset(10.f, 10.f));
const SkImageFilter::CropRect* crop = fIsCropped ? &cropRect : nullptr;
paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY, nullptr, crop))->unref();
for (int i = 0; i < loops; i++) {
canvas->drawBitmap(fCheckerboard, kX, kY, &paint);
}
}
示例4: onDraw
void onDraw(int loops, SkCanvas* canvas) override {
SkPaint paint;
static const SkScalar kX = 0;
static const SkScalar kY = 0;
const SkRect bmpRect = SkRect::MakeXYWH(kX, kY,
SkIntToScalar(fCheckerboard.width()),
SkIntToScalar(fCheckerboard.height()));
const SkImageFilter::CropRect cropRect(bmpRect.makeInset(10.f, 10.f));
const SkImageFilter::CropRect cropRectLarge(bmpRect);
SkAutoTUnref<SkImageFilter> noOpCropped(SkOffsetImageFilter::Create(0, 0, nullptr,
&cropRect));
SkImageFilter* input = fIsExpanded ? noOpCropped.get() : nullptr;
const SkImageFilter::CropRect* crop =
fIsExpanded ? &cropRectLarge : fIsCropped ? &cropRect : nullptr;
SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(fSigmaX, fSigmaY, input, crop));
paint.setImageFilter(blur);
for (int i = 0; i < loops; i++) {
canvas->drawBitmap(fCheckerboard, kX, kY, &paint);
}
}
示例5: DetermineDomainMode
/** Determines whether a texture domain is necessary and if so what domain to use. There are two
* rectangles to consider:
* - The first is the content area specified by the texture adjuster (i.e., textureContentArea).
* We can *never* allow filtering to cause bleed of pixels outside this rectangle.
* - The second rectangle is the constraint rectangle (i.e., constraintRect), which is known to
* be contained by the content area. The filterConstraint specifies whether we are allowed to
* bleed across this rect.
*
* We want to avoid using a domain if possible. We consider the above rectangles, the filter type,
* and whether the coords generated by the draw would all fall within the constraint rect. If the
* latter is true we only need to consider whether the filter would extend beyond the rects.
*/
GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode(
const SkRect& constraintRect,
FilterConstraint filterConstraint,
bool coordsLimitedToConstraintRect,
GrTextureProxy* proxy,
const GrSamplerState::Filter* filterModeOrNullForBicubic,
SkRect* domainRect) {
const SkIRect proxyBounds = SkIRect::MakeWH(proxy->width(), proxy->height());
SkASSERT(proxyBounds.contains(constraintRect));
const bool proxyIsExact = GrProxyProvider::IsFunctionallyExact(proxy);
// If the constraint rectangle contains the whole proxy then no need for a domain.
if (constraintRect.contains(proxyBounds) && proxyIsExact) {
return kNoDomain_DomainMode;
}
bool restrictFilterToRect = (filterConstraint == GrTextureProducer::kYes_FilterConstraint);
// If we can filter outside the constraint rect, and there is no non-content area of the
// proxy, and we aren't going to generate sample coords outside the constraint rect then we
// don't need a domain.
if (!restrictFilterToRect && proxyIsExact && coordsLimitedToConstraintRect) {
return kNoDomain_DomainMode;
}
// Get the domain inset based on sampling mode (or bail if mipped)
SkScalar filterHalfWidth = 0.f;
if (filterModeOrNullForBicubic) {
switch (*filterModeOrNullForBicubic) {
case GrSamplerState::Filter::kNearest:
if (coordsLimitedToConstraintRect) {
return kNoDomain_DomainMode;
} else {
filterHalfWidth = 0.f;
}
break;
case GrSamplerState::Filter::kBilerp:
filterHalfWidth = .5f;
break;
case GrSamplerState::Filter::kMipMap:
if (restrictFilterToRect || !proxyIsExact) {
// No domain can save us here.
return kTightCopy_DomainMode;
}
return kNoDomain_DomainMode;
}
} else {
// bicubic does nearest filtering internally.
filterHalfWidth = 1.5f;
}
// Both bilerp and bicubic use bilinear filtering and so need to be clamped to the center
// of the edge texel. Pinning to the texel center has no impact on nearest mode and MIP-maps
static const SkScalar kDomainInset = 0.5f;
// Figure out the limits of pixels we're allowed to sample from.
// Unless we know the amount of outset and the texture matrix we have to conservatively enforce
// the domain.
if (restrictFilterToRect) {
*domainRect = constraintRect.makeInset(kDomainInset, kDomainInset);
} else if (!proxyIsExact) {
// If we got here then: proxy is not exact, the coords are limited to the
// constraint rect, and we're allowed to filter across the constraint rect boundary. So
// we check whether the filter would reach across the edge of the proxy.
// We will only set the sides that are required.
*domainRect = SkRectPriv::MakeLargest();
if (coordsLimitedToConstraintRect) {
// We may be able to use the fact that the texture coords are limited to the constraint
// rect in order to avoid having to add a domain.
bool needContentAreaConstraint = false;
if (proxyBounds.fRight - filterHalfWidth < constraintRect.fRight) {
domainRect->fRight = proxyBounds.fRight - kDomainInset;
needContentAreaConstraint = true;
}
if (proxyBounds.fBottom - filterHalfWidth < constraintRect.fBottom) {
domainRect->fBottom = proxyBounds.fBottom - kDomainInset;
needContentAreaConstraint = true;
}
if (!needContentAreaConstraint) {
return kNoDomain_DomainMode;
}
} else {
// Our sample coords for the texture are allowed to be outside the constraintRect so we
// don't consider it when computing the domain.
domainRect->fRight = proxyBounds.fRight - kDomainInset;
//.........这里部分代码省略.........