aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrTextureProducer.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-03-27 11:08:16 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-27 16:31:02 +0000
commit3798c86f6885f0b47fb2e659a43b48a4468a97ef (patch)
tree8670d4adcc7889af63b4168256f0325aa78aa3bd /src/gpu/GrTextureProducer.cpp
parent465748c246dde8c131effdfa69aed82ef7a48af8 (diff)
Remove GrFragmentProcessor-derived class' GrTexture-based ctors
Split out into: https://skia-review.googlesource.com/c/8881/ (Switch GrTextureStripAtlas over to GrTextureProxies) https://skia-review.googlesource.com/c/8942/ (Wrap cached GrTextures in GrTextureProxies (e.g., blur profiles, nine-patch blurs, etc.)) https://skia-review.googlesource.com/c/8997/ (Clean up/remove unused GrFragmentProcessor-derived ctors) https://skia-review.googlesource.com/c/9191/ (Switch SkImageGenerator over to generating GrTextureProxies) https://skia-review.googlesource.com/c/9448/ (Switch GrYUVProvider over to GrTextureProxies) https://skia-review.googlesource.com/c/9559/ (Preparatory Proxification) https://skia-review.googlesource.com/c/9626/ (Consolidate Proxy caching code in GrResourceProvider) https://skia-review.googlesource.com/c/9683/ (More pre-emptive proxification) https://skia-review.googlesource.com/c/9917/ (Make experimental Perlin noise shader take texture proxies) https://skia-review.googlesource.com/c/9961/ (rename makeCopyForTextureParams to isACopyNeededForTextureParams) https://skia-review.googlesource.com/c/9945/ (Make SkImageCacherator be deferred) https://skia-review.googlesource.com/c/10180/ (Add new proxy-based DetermineDomainMode w/ test) Change-Id: Ia33389d92360e542a9d2bf395948deb04d017465 Reviewed-on: https://skia-review.googlesource.com/8823 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu/GrTextureProducer.cpp')
-rw-r--r--src/gpu/GrTextureProducer.cpp219
1 files changed, 5 insertions, 214 deletions
diff --git a/src/gpu/GrTextureProducer.cpp b/src/gpu/GrTextureProducer.cpp
index a8390ee9bc..d226c3feb6 100644
--- a/src/gpu/GrTextureProducer.cpp
+++ b/src/gpu/GrTextureProducer.cpp
@@ -16,56 +16,6 @@
#include "effects/GrSimpleTextureEffect.h"
#include "effects/GrTextureDomain.h"
-GrTexture* GrTextureProducer::CopyOnGpu(GrTexture* inputTexture, const SkIRect* subset,
- const CopyParams& copyParams) {
- SkASSERT(!subset || !subset->isEmpty());
- GrContext* context = inputTexture->getContext();
- SkASSERT(context);
-
- GrPixelConfig config = GrMakePixelConfigUncompressed(inputTexture->config());
-
- sk_sp<GrRenderTargetContext> copyRTC = context->makeRenderTargetContextWithFallback(
- SkBackingFit::kExact, copyParams.fWidth, copyParams.fHeight, config, nullptr);
- if (!copyRTC) {
- return nullptr;
- }
-
- GrPaint paint;
- paint.setGammaCorrect(true);
-
- if (copyParams.fFilter != GrSamplerParams::kNone_FilterMode && subset &&
- (subset->width() != copyParams.fWidth || subset->height() != copyParams.fHeight)) {
- SkRect domain;
- domain.fLeft = subset->fLeft + 0.5f;
- domain.fTop = subset->fTop + 0.5f;
- domain.fRight = subset->fRight - 0.5f;
- domain.fBottom = subset->fBottom - 0.5f;
- // This would cause us to read values from outside the subset. Surely, the caller knows
- // better!
- SkASSERT(copyParams.fFilter != GrSamplerParams::kMipMap_FilterMode);
- paint.addColorFragmentProcessor(
- GrTextureDomainEffect::Make(inputTexture, nullptr, SkMatrix::I(), domain,
- GrTextureDomain::kClamp_Mode,
- copyParams.fFilter));
- } else {
- GrSamplerParams params(SkShader::kClamp_TileMode, copyParams.fFilter);
- paint.addColorTextureProcessor(inputTexture, nullptr, SkMatrix::I(), params);
- }
- paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
-
- SkRect localRect;
- if (subset) {
- localRect = SkRect::Make(*subset);
- } else {
- localRect = SkRect::MakeWH(inputTexture->width(), inputTexture->height());
- }
-
- SkRect dstRect = SkRect::MakeIWH(copyParams.fWidth, copyParams.fHeight);
- copyRTC->fillRectToRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), dstRect,
- localRect);
- return copyRTC->asTexture().release();
-}
-
sk_sp<GrTextureProxy> GrTextureProducer::CopyOnGpu(GrContext* context,
sk_sp<GrTextureProxy> inputProxy,
const SkIRect* subset,
@@ -128,145 +78,17 @@ sk_sp<GrTextureProxy> GrTextureProducer::CopyOnGpu(GrContext* context,
/** 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. We can *never* allow
- * filtering to cause bleed of pixels outside this rectangle.
- * - The second rectangle is the constraint rectangle, which is known to be contained by the
- * content area. The filterConstraint specifies whether we are allowed to bleed across this
- * rect.
+ * - 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,
- int texW, int texH,
- const SkIRect* textureContentArea,
- const GrSamplerParams::FilterMode* filterModeOrNullForBicubic,
- SkRect* domainRect) {
-
- SkASSERT(SkRect::MakeIWH(texW, texH).contains(constraintRect));
- // We only expect a content area rect if there is some non-content area.
- SkASSERT(!textureContentArea ||
- (!textureContentArea->contains(SkIRect::MakeWH(texW, texH)) &&
- SkRect::Make(*textureContentArea).contains(constraintRect)));
-
- SkRect textureBounds = SkRect::MakeIWH(texW, texH);
- // If the src rectangle contains the whole texture then no need for a domain.
- if (constraintRect.contains(textureBounds)) {
- 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
- // texture, and we aren't going to generate sample coords outside the constraint rect then we
- // don't need a domain.
- if (!restrictFilterToRect && !textureContentArea && 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 GrSamplerParams::kNone_FilterMode:
- if (coordsLimitedToConstraintRect) {
- return kNoDomain_DomainMode;
- } else {
- filterHalfWidth = 0.f;
- }
- break;
- case GrSamplerParams::kBilerp_FilterMode:
- filterHalfWidth = .5f;
- break;
- case GrSamplerParams::kMipMap_FilterMode:
- if (restrictFilterToRect || textureContentArea) {
- // 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 (textureContentArea) {
- // If we got here then: there is a textureContentArea, 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 content area.
- // We will only set the sides that are required.
-
- domainRect->setLargest();
- 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 (textureContentArea->fLeft > 0 &&
- textureContentArea->fLeft + filterHalfWidth > constraintRect.fLeft) {
- domainRect->fLeft = textureContentArea->fLeft + kDomainInset;
- needContentAreaConstraint = true;
- }
- if (textureContentArea->fTop > 0 &&
- textureContentArea->fTop + filterHalfWidth > constraintRect.fTop) {
- domainRect->fTop = textureContentArea->fTop + kDomainInset;
- needContentAreaConstraint = true;
- }
- if (textureContentArea->fRight < texW &&
- textureContentArea->fRight - filterHalfWidth < constraintRect.fRight) {
- domainRect->fRight = textureContentArea->fRight - kDomainInset;
- needContentAreaConstraint = true;
- }
- if (textureContentArea->fBottom < texH &&
- textureContentArea->fBottom - filterHalfWidth < constraintRect.fBottom) {
- domainRect->fBottom = textureContentArea->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.
- if (textureContentArea->fLeft != 0) {
- domainRect->fLeft = textureContentArea->fLeft + kDomainInset;
- }
- if (textureContentArea->fTop != 0) {
- domainRect->fTop = textureContentArea->fTop + kDomainInset;
- }
- if (textureContentArea->fRight != texW) {
- domainRect->fRight = textureContentArea->fRight - kDomainInset;
- }
- if (textureContentArea->fBottom != texH) {
- domainRect->fBottom = textureContentArea->fBottom - kDomainInset;
- }
- }
- } else {
- return kNoDomain_DomainMode;
- }
-
- if (domainRect->fLeft > domainRect->fRight) {
- domainRect->fLeft = domainRect->fRight = SkScalarAve(domainRect->fLeft, domainRect->fRight);
- }
- if (domainRect->fTop > domainRect->fBottom) {
- domainRect->fTop = domainRect->fBottom = SkScalarAve(domainRect->fTop, domainRect->fBottom);
- }
- return kDomain_DomainMode;
-}
-
-GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode(
const SkRect& constraintRect,
FilterConstraint filterConstraint,
bool coordsLimitedToConstraintRect,
@@ -402,37 +224,6 @@ GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode(
}
sk_sp<GrFragmentProcessor> GrTextureProducer::CreateFragmentProcessorForDomainAndFilter(
- GrTexture* texture,
- sk_sp<GrColorSpaceXform> colorSpaceXform,
- const SkMatrix& textureMatrix,
- DomainMode domainMode,
- const SkRect& domain,
- const GrSamplerParams::FilterMode* filterOrNullForBicubic) {
- SkASSERT(kTightCopy_DomainMode != domainMode);
- if (filterOrNullForBicubic) {
- if (kDomain_DomainMode == domainMode) {
- return GrTextureDomainEffect::Make(texture, std::move(colorSpaceXform), textureMatrix,
- domain, GrTextureDomain::kClamp_Mode,
- *filterOrNullForBicubic);
- } else {
- GrSamplerParams params(SkShader::kClamp_TileMode, *filterOrNullForBicubic);
- return GrSimpleTextureEffect::Make(texture, std::move(colorSpaceXform), textureMatrix,
- params);
- }
- } else {
- if (kDomain_DomainMode == domainMode) {
- return GrBicubicEffect::Make(texture, std::move(colorSpaceXform), textureMatrix,
- domain);
- } else {
- static const SkShader::TileMode kClampClamp[] =
- { SkShader::kClamp_TileMode, SkShader::kClamp_TileMode };
- return GrBicubicEffect::Make(texture, std::move(colorSpaceXform), textureMatrix,
- kClampClamp);
- }
- }
-}
-
-sk_sp<GrFragmentProcessor> GrTextureProducer::CreateFragmentProcessorForDomainAndFilter(
GrResourceProvider* resourceProvider,
sk_sp<GrTextureProxy> proxy,
sk_sp<GrColorSpaceXform> colorSpaceXform,