Add View->FP helper to SkImage_Base, use instead of GrTextureAdjuster.

Remove now-unused functionality from GrTextureProducer/Adjuster.

Bug: skia:11877
Change-Id: I34225397e730db36c6dc3e8c4815e41a147acb1d
Cq-Include-Trybots: luci.skia.skia.primary:Test-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Release-All-PreAbandonGpuContext
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402638
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Brian Salomon 2021-04-29 16:38:26 -04:00 committed by Skia Commit-Bot
parent 3934647d22
commit e74638b83f
9 changed files with 110 additions and 259 deletions

View File

@ -77,23 +77,3 @@ GrSurfaceProxyView GrTextureAdjuster::onView(GrMipmapped mipMapped) {
SkASSERT(copy.asTextureProxy()); SkASSERT(copy.asTextureProxy());
return copy; return copy;
} }
std::unique_ptr<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor(
const SkMatrix& textureMatrix,
const SkRect* subset,
const SkRect* domain,
GrSamplerState samplerState) {
return this->createFragmentProcessorForView(
this->view(samplerState.mipmapped()), textureMatrix, subset, domain, samplerState);
}
std::unique_ptr<GrFragmentProcessor> GrTextureAdjuster::createBicubicFragmentProcessor(
const SkMatrix& textureMatrix,
const SkRect* subset,
const SkRect* domain,
GrSamplerState::WrapMode wrapX,
GrSamplerState::WrapMode wrapY,
SkImage::CubicResampler kernel) {
return this->createBicubicFragmentProcessorForView(
this->view(GrMipmapped::kNo), textureMatrix, subset, domain, wrapX, wrapY, kernel);
}

View File

@ -23,19 +23,6 @@ public:
GrTextureAdjuster(GrRecordingContext*, GrSurfaceProxyView, const GrColorInfo&, GrTextureAdjuster(GrRecordingContext*, GrSurfaceProxyView, const GrColorInfo&,
uint32_t uniqueID); uint32_t uniqueID);
std::unique_ptr<GrFragmentProcessor> createFragmentProcessor(const SkMatrix& textureMatrix,
const SkRect* subset,
const SkRect* domain,
GrSamplerState) override;
std::unique_ptr<GrFragmentProcessor> createBicubicFragmentProcessor(
const SkMatrix& textureMatrix,
const SkRect* subset,
const SkRect* domain,
GrSamplerState::WrapMode wrapX,
GrSamplerState::WrapMode wrapY,
SkImage::CubicResampler) override;
private: private:
GrSurfaceProxyView onView(GrMipmapped) override; GrSurfaceProxyView onView(GrMipmapped) override;

View File

@ -20,71 +20,6 @@
#include "src/gpu/effects/GrBicubicEffect.h" #include "src/gpu/effects/GrBicubicEffect.h"
#include "src/gpu/effects/GrTextureEffect.h" #include "src/gpu/effects/GrTextureEffect.h"
std::unique_ptr<GrFragmentProcessor> GrTextureProducer::createFragmentProcessorForView(
GrSurfaceProxyView view,
const SkMatrix& textureMatrix,
const SkRect* subset,
const SkRect* domain,
GrSamplerState samplerState) {
if (!view) {
return nullptr;
}
SkRect tempSubset;
if (!subset && !view.proxy()->isFullyLazy() && !view.proxy()->isFunctionallyExact()) {
tempSubset = view.proxy()->getBoundsRect();
subset = &tempSubset;
}
const auto& caps = *fContext->priv().caps();
if (subset) {
if (domain) {
return GrTextureEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix,
samplerState, *subset, *domain, caps);
} else {
return GrTextureEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix,
samplerState, *subset, caps);
}
} else {
return GrTextureEffect::Make(std::move(view), this->alphaType(), textureMatrix,
samplerState, caps);
}
}
std::unique_ptr<GrFragmentProcessor> GrTextureProducer::createBicubicFragmentProcessorForView(
GrSurfaceProxyView view,
const SkMatrix& textureMatrix,
const SkRect* subset,
const SkRect* domain,
GrSamplerState::WrapMode wrapX,
GrSamplerState::WrapMode wrapY,
SkImage::CubicResampler kernel) {
if (!view) {
return nullptr;
}
SkRect tempSubset;
if (!subset && !view.proxy()->isFullyLazy() && !view.proxy()->isFunctionallyExact()) {
tempSubset = view.proxy()->getBoundsRect();
subset = &tempSubset;
}
const auto& caps = *fContext->priv().caps();
static constexpr auto kDir = GrBicubicEffect::Direction::kXY;
if (subset) {
if (domain) {
return GrBicubicEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix,
wrapX, wrapY, *subset, *domain, kernel, kDir, caps);
} else {
return GrBicubicEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix,
wrapX, wrapY, *subset, kernel, kDir, caps);
}
} else {
return GrBicubicEffect::Make(std::move(view), this->alphaType(), textureMatrix, wrapX,
wrapY, kernel, kDir, caps);
}
}
GrSurfaceProxyView GrTextureProducer::view(GrMipmapped mipMapped) { GrSurfaceProxyView GrTextureProducer::view(GrMipmapped mipMapped) {
const GrCaps* caps = this->context()->priv().caps(); const GrCaps* caps = this->context()->priv().caps();
// Sanitize the MIP map request. // Sanitize the MIP map request.

View File

@ -34,53 +34,6 @@ class GrTextureProducer : public SkNoncopyable {
public: public:
virtual ~GrTextureProducer() = default; virtual ~GrTextureProducer() = default;
/**
* Helper for creating a fragment processor to sample the texture with a given filtering mode.
* Attempts to avoid unnecessary copies (e.g. for planar sources or subsets) by generating more
* complex shader code.
*
* @param textureMatrix Matrix used to access the texture. It is applied to
* the local coords. The post-transformed coords should
* be in texel units (rather than normalized) with
* respect to this Producer's bounds (width()/height()).
* @param subset If not null, a subset of the texture to restrict
* sampling to. The wrap modes apply to this subset.
* @param domain If not null, a known limit on the texture coordinates
* that will be accessed. Applies after textureMatrix.
* @param sampler Sampler state. Wrap modes applies to subset if not
* null, otherwise to the entire source.
**/
virtual std::unique_ptr<GrFragmentProcessor> createFragmentProcessor(
const SkMatrix& textureMatrix,
const SkRect* subset,
const SkRect* domain,
GrSamplerState sampler) = 0;
/**
* Similar createFragmentProcessor but produces a fragment processor that does bicubic
* interpolation of the source. Attempts to avoid unnecessary copies (e.g. for planar sources or
* subsets) by generating more complex shader code.
*
* @param textureMatrix Matrix used to access the texture. It is applied to
* the local coords. The post-transformed coords should
* be in texel units (rather than normalized) with
* respect to this Producer's bounds (width()/height()).
* @param subset If not null, a subset of the texture to restrict
* sampling to. The wrap modes apply to this subset.
* @param domain If not null, a known limit on the texture coordinates
* that will be accessed. Applies after textureMatrix.
* @param wrapX Wrap mode on x axis. Applied to subset if not null,
* otherwise to the entire source.
* @param wrapY Wrap mode on y axis. Applied to subset if not null,
* otherwise to the entire source.
*/
virtual std::unique_ptr<GrFragmentProcessor> createBicubicFragmentProcessor(
const SkMatrix& textureMatrix,
const SkRect* subset,
const SkRect* domain,
GrSamplerState::WrapMode wrapX,
GrSamplerState::WrapMode wrapY,
SkImage::CubicResampler kernel) = 0;
/** /**
* Returns a texture view, possibly with MIP maps. The request for MIP maps may not be honored * Returns a texture view, possibly with MIP maps. The request for MIP maps may not be honored
@ -89,38 +42,15 @@ public:
*/ */
GrSurfaceProxyView view(GrMipmapped); GrSurfaceProxyView view(GrMipmapped);
const GrColorInfo& colorInfo() const { return fImageInfo.colorInfo(); }
int width() const { return fImageInfo.width(); } int width() const { return fImageInfo.width(); }
int height() const { return fImageInfo.height(); } int height() const { return fImageInfo.height(); }
SkISize dimensions() const { return fImageInfo.dimensions(); } SkISize dimensions() const { return fImageInfo.dimensions(); }
GrColorType colorType() const { return fImageInfo.colorType(); } GrColorType colorType() const { return fImageInfo.colorType(); }
SkAlphaType alphaType() const { return fImageInfo.alphaType(); }
SkColorSpace* colorSpace() const { return fImageInfo.colorSpace(); }
bool isAlphaOnly() const { return GrColorTypeIsAlphaOnly(fImageInfo.colorType()); }
/* Is it a planar image consisting of multiple textures that may have different resolutions? */
virtual bool isPlanar() const { return false; }
protected: protected:
GrTextureProducer(GrRecordingContext* context, const GrImageInfo& imageInfo) GrTextureProducer(GrRecordingContext* context, const GrImageInfo& imageInfo)
: fContext(context), fImageInfo(imageInfo) {} : fContext(context), fImageInfo(imageInfo) {}
// Helper for making a texture effect from a single proxy view.
std::unique_ptr<GrFragmentProcessor> createFragmentProcessorForView(
GrSurfaceProxyView view,
const SkMatrix& textureMatrix,
const SkRect* subset,
const SkRect* domain,
GrSamplerState sampler);
// Helper for making a bicubic effect from a single proxy view.
std::unique_ptr<GrFragmentProcessor> createBicubicFragmentProcessorForView(
GrSurfaceProxyView view,
const SkMatrix& textureMatrix,
const SkRect* subset,
const SkRect* domain,
GrSamplerState::WrapMode wrapX,
GrSamplerState::WrapMode wrapY,
SkImage::CubicResampler kernel);
GrRecordingContext* context() const { return fContext; } GrRecordingContext* context() const { return fContext; }

View File

@ -36,6 +36,8 @@
#include "src/gpu/GrImageContextPriv.h" #include "src/gpu/GrImageContextPriv.h"
#include "src/gpu/GrRecordingContextPriv.h" #include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/SkGr.h" #include "src/gpu/SkGr.h"
#include "src/gpu/effects/GrBicubicEffect.h"
#include "src/gpu/effects/GrTextureEffect.h"
#include "src/image/SkImage_Gpu.h" #include "src/image/SkImage_Gpu.h"
#endif #endif
#include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrBackendSurface.h"
@ -337,6 +339,79 @@ std::unique_ptr<GrFragmentProcessor> SkImage_Base::asFragmentProcessor(
} }
return this->onAsFragmentProcessor(rContext, sampling, tileModes, m, subset, domain); return this->onAsFragmentProcessor(rContext, sampling, tileModes, m, subset, domain);
} }
std::unique_ptr<GrFragmentProcessor> SkImage_Base::MakeFragmentProcessorFromView(
GrRecordingContext* rContext,
GrSurfaceProxyView view,
SkAlphaType at,
SkSamplingOptions sampling,
const SkTileMode tileModes[2],
const SkMatrix& m,
const SkRect* subset,
const SkRect* domain) {
if (!view) {
return nullptr;
}
const GrCaps& caps = *rContext->priv().caps();
auto wmx = SkTileModeToWrapMode(tileModes[0]);
auto wmy = SkTileModeToWrapMode(tileModes[1]);
if (sampling.useCubic) {
if (subset) {
if (domain) {
return GrBicubicEffect::MakeSubset(std::move(view),
at,
m,
wmx,
wmy,
*subset,
*domain,
sampling.cubic,
GrBicubicEffect::Direction::kXY,
*rContext->priv().caps());
}
return GrBicubicEffect::MakeSubset(std::move(view),
at,
m,
wmx,
wmy,
*subset,
sampling.cubic,
GrBicubicEffect::Direction::kXY,
*rContext->priv().caps());
}
return GrBicubicEffect::Make(std::move(view),
at,
m,
wmx,
wmy,
sampling.cubic,
GrBicubicEffect::Direction::kXY,
*rContext->priv().caps());
}
if (view.proxy()->asTextureProxy()->mipmapped() == GrMipmapped::kNo) {
sampling = SkSamplingOptions(sampling.filter);
}
GrSamplerState sampler(wmx, wmy, sampling.filter, sampling.mipmap);
if (subset) {
if (domain) {
return GrTextureEffect::MakeSubset(std::move(view),
at,
m,
sampler,
*subset,
*domain,
caps);
}
return GrTextureEffect::MakeSubset(std::move(view),
at,
m,
sampler,
*subset,
caps);
} else {
return GrTextureEffect::Make(std::move(view), at, m, sampler, caps);
}
}
#endif #endif
GrBackendTexture SkImage_Base::onGetBackendTexture(bool flushPendingGrContextIO, GrBackendTexture SkImage_Base::onGetBackendTexture(bool flushPendingGrContextIO,

View File

@ -173,6 +173,15 @@ protected:
GrSurfaceProxyView src, GrSurfaceProxyView src,
GrMipmapped, GrMipmapped,
GrImageTexGenPolicy); GrImageTexGenPolicy);
static std::unique_ptr<GrFragmentProcessor> MakeFragmentProcessorFromView(GrRecordingContext*,
GrSurfaceProxyView,
SkAlphaType,
SkSamplingOptions,
const SkTileMode[2],
const SkMatrix&,
const SkRect* subset,
const SkRect* domain);
#endif #endif
private: private:

View File

@ -854,19 +854,15 @@ std::unique_ptr<GrFragmentProcessor> SkImage_Gpu::onAsFragmentProcessor(
if (!fContext->priv().matches(rContext)) { if (!fContext->priv().matches(rContext)) {
return {}; return {};
} }
GrSurfaceProxyView view = this->makeView(rContext); auto mm = sampling.mipmap == SkMipmapMode::kNone ? GrMipmapped::kNo : GrMipmapped::kYes;
GrColorType ct = SkColorTypeAndFormatToGrColorType(rContext->priv().caps(), return MakeFragmentProcessorFromView(rContext,
this->colorType(), std::get<0>(this->asView(rContext, mm)),
view.proxy()->backendFormat()); this->alphaType(),
GrColorInfo colorInfo(ct, this->alphaType(), this->refColorSpace()); sampling,
GrTextureAdjuster adjuster(rContext, std::move(view), colorInfo, this->uniqueID()); tileModes,
auto wmx = SkTileModeToWrapMode(tileModes[0]); m,
auto wmy = SkTileModeToWrapMode(tileModes[1]); subset,
if (sampling.useCubic) { domain);
return adjuster.createBicubicFragmentProcessor(m, subset, domain, wmx, wmy, sampling.cubic);
}
GrSamplerState sampler(wmx, wmy, sampling.filter, sampling.mipmap);
return adjuster.createFragmentProcessor(m, subset, domain, sampler);
} }
GrSurfaceProxyView SkImage_Gpu::makeView(GrRecordingContext* rContext) const { GrSurfaceProxyView SkImage_Gpu::makeView(GrRecordingContext* rContext) const {

View File

@ -264,23 +264,15 @@ std::unique_ptr<GrFragmentProcessor> SkImage_Lazy::onAsFragmentProcessor(
const SkRect* domain) const { const SkRect* domain) const {
// TODO: If the CPU data is extracted as planes return a FP that reconstructs the image from // TODO: If the CPU data is extracted as planes return a FP that reconstructs the image from
// the planes. // the planes.
auto wmx = SkTileModeToWrapMode(tileModes[0]);
auto wmy = SkTileModeToWrapMode(tileModes[1]);
auto mm = sampling.mipmap == SkMipmapMode::kNone ? GrMipmapped::kNo : GrMipmapped::kYes; auto mm = sampling.mipmap == SkMipmapMode::kNone ? GrMipmapped::kNo : GrMipmapped::kYes;
auto [view, ct] = this->asView(rContext, mm); return MakeFragmentProcessorFromView(rContext,
if (!view) { std::get<0>(this->asView(rContext, mm)),
return nullptr; this->alphaType(),
} sampling,
GrColorInfo info = this->imageInfo().colorInfo(); tileModes,
info = info.makeColorType(ct); m,
// We pass the invalid unique ID here because our above call to asView() should have already subset,
// made and cached a mipmapped texture if mipmapping was called for. domain);
GrTextureAdjuster adjuster(rContext, std::move(view), std::move(info), SK_InvalidUniqueID);
if (sampling.useCubic) {
return adjuster.createBicubicFragmentProcessor(m, subset, domain, wmx, wmy, sampling.cubic);
}
GrSamplerState sampler(wmx, wmy, sampling.filter, sampling.mipmap);
return adjuster.createFragmentProcessor(m, subset, domain, sampler);
} }
GrSurfaceProxyView SkImage_Lazy::textureProxyViewFromPlanes(GrRecordingContext* ctx, GrSurfaceProxyView SkImage_Lazy::textureProxyViewFromPlanes(GrRecordingContext* ctx,

View File

@ -440,73 +440,20 @@ std::tuple<GrSurfaceProxyView, GrColorType> SkImage_Raster::onAsView(
} }
std::unique_ptr<GrFragmentProcessor> SkImage_Raster::onAsFragmentProcessor( std::unique_ptr<GrFragmentProcessor> SkImage_Raster::onAsFragmentProcessor(
GrRecordingContext* context, GrRecordingContext* rContext,
SkSamplingOptions sampling, SkSamplingOptions sampling,
const SkTileMode tileModes[2], const SkTileMode tileModes[2],
const SkMatrix& m, const SkMatrix& m,
const SkRect* subset, const SkRect* subset,
const SkRect* domain) const { const SkRect* domain) const {
auto mm = sampling.mipmap == SkMipmapMode::kNone ? GrMipmapped::kNo : GrMipmapped::kYes; auto mm = sampling.mipmap == SkMipmapMode::kNone ? GrMipmapped::kNo : GrMipmapped::kYes;
auto [view, ct] = this->asView(context, mm); return MakeFragmentProcessorFromView(rContext,
if (!view) { std::get<0>(this->asView(rContext, mm)),
return nullptr; this->alphaType(),
} sampling,
const GrCaps& caps = *context->priv().caps(); tileModes,
auto wmx = SkTileModeToWrapMode(tileModes[0]); m,
auto wmy = SkTileModeToWrapMode(tileModes[1]); subset,
if (sampling.useCubic) { domain);
if (subset) {
if (domain) {
return GrBicubicEffect::MakeSubset(std::move(view),
this->alphaType(),
m,
wmx,
wmy,
*subset,
*domain,
sampling.cubic,
GrBicubicEffect::Direction::kXY,
*context->priv().caps());
}
return GrBicubicEffect::MakeSubset(std::move(view),
this->alphaType(),
m,
wmx,
wmy,
*subset,
sampling.cubic,
GrBicubicEffect::Direction::kXY,
*context->priv().caps());
}
return GrBicubicEffect::Make(std::move(view),
this->alphaType(),
m,
wmx,
wmy,
sampling.cubic,
GrBicubicEffect::Direction::kXY,
*context->priv().caps());
}
GrSamplerState sampler(wmx, wmy, sampling.filter, sampling.mipmap);
if (subset) {
if (domain) {
return GrTextureEffect::MakeSubset(std::move(view),
this->alphaType(),
m,
sampler,
*subset,
*domain,
caps);
}
return GrTextureEffect::MakeSubset(std::move(view),
this->alphaType(),
m,
sampler,
*subset,
caps);
} else {
return GrTextureEffect::Make(std::move(view), this->alphaType(), m, sampler, caps);
}
} }
#endif #endif