Smaller fragment from "Reduce dependence on GrSurface's origin field"
TBR=bsalomon@google.com
Change-Id: I996226ffaf84ca357740a6da9bb80a3b8febb379
Reviewed-on: https://skia-review.googlesource.com/25745
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/effects/GrCircleBlurFragmentProcessor.cpp b/src/effects/GrCircleBlurFragmentProcessor.cpp
index 135b00e..fb12afb 100644
--- a/src/effects/GrCircleBlurFragmentProcessor.cpp
+++ b/src/effects/GrCircleBlurFragmentProcessor.cpp
@@ -178,6 +178,7 @@
if (!blurProfile) {
static constexpr int kProfileTextureWidth = 512;
GrSurfaceDesc texDesc;
+ texDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
texDesc.fWidth = kProfileTextureWidth;
texDesc.fHeight = 1;
texDesc.fConfig = kAlpha_8_GrPixelConfig;
@@ -197,6 +198,7 @@
return nullptr;
}
+ SkASSERT(blurProfile->origin() == kTopLeft_GrSurfaceOrigin);
resourceProvider->assignUniqueKeyToProxy(key, blurProfile.get());
}
diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp
index d85160e..eac70c9 100644
--- a/src/effects/SkBlurMaskFilter.cpp
+++ b/src/effects/SkBlurMaskFilter.cpp
@@ -942,15 +942,8 @@
sk_sp<GrTextureProxy> GrRectBlurEffect::CreateBlurProfileTexture(
GrResourceProvider* resourceProvider,
float sigma) {
- GrSurfaceDesc texDesc;
-
unsigned int profileSize = SkScalarCeilToInt(6*sigma);
- texDesc.fWidth = profileSize;
- texDesc.fHeight = 1;
- texDesc.fConfig = kAlpha_8_GrPixelConfig;
- texDesc.fIsMipMapped = false;
-
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 1);
@@ -959,6 +952,13 @@
sk_sp<GrTextureProxy> blurProfile(resourceProvider->findProxyByUniqueKey(key));
if (!blurProfile) {
+ GrSurfaceDesc texDesc;
+ texDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
+ texDesc.fWidth = profileSize;
+ texDesc.fHeight = 1;
+ texDesc.fConfig = kAlpha_8_GrPixelConfig;
+ texDesc.fIsMipMapped = false;
+
std::unique_ptr<uint8_t[]> profile(SkBlurMask::ComputeBlurProfile(sigma));
blurProfile = GrSurfaceProxy::MakeDeferred(resourceProvider,
@@ -967,6 +967,7 @@
return nullptr;
}
+ SkASSERT(blurProfile->origin() == kTopLeft_GrSurfaceOrigin);
resourceProvider->assignUniqueKeyToProxy(key, blurProfile.get());
}
@@ -1154,6 +1155,7 @@
if (!mask) {
return nullptr;
}
+ SkASSERT(mask->origin() == kBottomLeft_GrSurfaceOrigin);
context->resourceProvider()->assignUniqueKeyToProxy(key, mask.get());
}
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index 90756a7..06e7e68 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -597,14 +597,15 @@
void GrGLDisplacementMapEffect::onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& proc) {
const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMapEffect>();
- GrTexture* colorTex = displacementMap.textureSampler(1).peekTexture();
+ GrSurfaceProxy* proxy = displacementMap.textureSampler(1).proxy();
+ GrTexture* colorTex = proxy->priv().peekTexture();
SkScalar scaleX = displacementMap.scale().fX / colorTex->width();
SkScalar scaleY = displacementMap.scale().fY / colorTex->height();
pdman.set2f(fScaleUni, SkScalarToFloat(scaleX),
- colorTex->origin() == kTopLeft_GrSurfaceOrigin ?
+ proxy->origin() == kTopLeft_GrSurfaceOrigin ?
SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY));
- fGLDomain.setData(pdman, displacementMap.domain(), colorTex);
+ fGLDomain.setData(pdman, displacementMap.domain(), proxy);
if (SkToBool(displacementMap.colorSpaceXform())) {
fColorSpaceHelper.setData(pdman, displacementMap.colorSpaceXform());
}
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 7b72fcd..58064ce 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -1899,14 +1899,15 @@
fLight = lighting.light()->createGLLight();
}
- GrTexture* texture = lighting.textureSampler(0).peekTexture();
+ GrTextureProxy* proxy = lighting.textureSampler(0).proxy();
+ GrTexture* texture = proxy->priv().peekTexture();
- float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f;
+ float ySign = proxy->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f;
pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->height());
pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale());
sk_sp<SkImageFilterLight> transformedLight(
lighting.light()->transform(lighting.filterMatrix()));
- fDomain.setData(pdman, lighting.domain(), texture);
+ fDomain.setData(pdman, lighting.domain(), proxy);
fLight->setData(pdman, transformedLight.get());
}
diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp
index 90e0a5c..b2c6714 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -202,14 +202,15 @@
const GrFragmentProcessor& effect) {
const GrMagnifierEffect& zoom = effect.cast<GrMagnifierEffect>();
- GrTexture* tex = zoom.textureSampler(0).peekTexture();
+ GrSurfaceProxy* proxy = zoom.textureSampler(0).proxy();
+ GrTexture* tex = proxy->priv().peekTexture();
SkScalar invW = 1.0f / tex->width();
SkScalar invH = 1.0f / tex->height();
{
SkScalar y = zoom.srcRect().y() * invH;
- if (tex->origin() != kTopLeft_GrSurfaceOrigin) {
+ if (proxy->origin() != kTopLeft_GrSurfaceOrigin) {
y = 1.0f - (zoom.srcRect().height() / zoom.bounds().height()) - y;
}
@@ -221,7 +222,7 @@
{
SkScalar y = zoom.bounds().y() * invH;
- if (tex->origin() != kTopLeft_GrSurfaceOrigin) {
+ if (proxy->origin() != kTopLeft_GrSurfaceOrigin) {
y = 1.0f - zoom.bounds().height() * invH;
}
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index a148bb3..2cc224d 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -293,7 +293,8 @@
void GrGLMorphologyEffect::onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& proc) {
const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>();
- GrTexture& texture = *m.textureSampler(0).peekTexture();
+ GrSurfaceProxy* proxy = m.textureSampler(0).proxy();
+ GrTexture& texture = *proxy->priv().peekTexture();
float pixelSize = 0.0f;
switch (m.direction()) {
@@ -311,7 +312,7 @@
if (m.useRange()) {
const float* range = m.range();
if (Gr1DKernelEffect::kY_Direction == m.direction() &&
- texture.origin() == kBottomLeft_GrSurfaceOrigin) {
+ proxy->origin() == kBottomLeft_GrSurfaceOrigin) {
pdman.set2f(fRangeUni, 1.0f - (range[1]*pixelSize), 1.0f - (range[0]*pixelSize));
} else {
pdman.set2f(fRangeUni, range[0] * pixelSize, range[1] * pixelSize);
diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp
index 6d8072f..f7441bc 100644
--- a/src/gpu/effects/GrBicubicEffect.cpp
+++ b/src/gpu/effects/GrBicubicEffect.cpp
@@ -120,13 +120,14 @@
void GrGLBicubicEffect::onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& processor) {
const GrBicubicEffect& bicubicEffect = processor.cast<GrBicubicEffect>();
- GrTexture* texture = processor.textureSampler(0).peekTexture();
+ GrSurfaceProxy* proxy = processor.textureSampler(0).proxy();
+ GrTexture* texture = proxy->priv().peekTexture();
float imageIncrement[2];
imageIncrement[0] = 1.0f / texture->width();
imageIncrement[1] = 1.0f / texture->height();
pdman.set2fv(fImageIncrementUni, 1, imageIncrement);
- fDomain.setData(pdman, bicubicEffect.domain(), texture);
+ fDomain.setData(pdman, bicubicEffect.domain(), proxy);
if (SkToBool(bicubicEffect.colorSpaceXform())) {
fColorSpaceHelper.setData(pdman, bicubicEffect.colorSpaceXform());
}
diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp
index e4989de..e8d0477 100644
--- a/src/gpu/effects/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/GrConfigConversionEffect.cpp
@@ -133,6 +133,7 @@
return false;
}
GrSurfaceDesc desc;
+ desc.fOrigin = kTopLeft_GrSurfaceOrigin;
desc.fWidth = kSize;
desc.fHeight = kSize;
desc.fConfig = kConfig;
diff --git a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
index 4d1a99d..1ab9b78 100644
--- a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
+++ b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
@@ -121,10 +121,11 @@
const GrFragmentProcessor& processor) {
const GrGaussianConvolutionFragmentProcessor& conv =
processor.cast<GrGaussianConvolutionFragmentProcessor>();
- GrTexture& texture = *conv.textureSampler(0).peekTexture();
+ GrSurfaceProxy* proxy = conv.textureSampler(0).proxy();
+ GrTexture& texture = *proxy->priv().peekTexture();
float imageIncrement[2] = {0};
- float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
+ float ySign = proxy->origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
switch (conv.direction()) {
case Gr1DKernelEffect::kX_Direction:
imageIncrement[0] = 1.0f / texture.width();
@@ -149,7 +150,7 @@
pdman.set2f(fBoundsUni, inv * bounds[0], inv * bounds[1]);
} else {
SkScalar inv = SkScalarInvert(SkIntToScalar(texture.height()));
- if (texture.origin() != kTopLeft_GrSurfaceOrigin) {
+ if (proxy->origin() != kTopLeft_GrSurfaceOrigin) {
pdman.set2f(fBoundsUni, 1.0f - (inv * bounds[1]), 1.0f - (inv * bounds[0]));
} else {
pdman.set2f(fBoundsUni, inv * bounds[1], inv * bounds[0]);
diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.cpp b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
index bc1537c..abfe5b3 100644
--- a/src/gpu/effects/GrMatrixConvolutionEffect.cpp
+++ b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
@@ -131,10 +131,11 @@
void GrGLMatrixConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& processor) {
const GrMatrixConvolutionEffect& conv = processor.cast<GrMatrixConvolutionEffect>();
- GrTexture* texture = conv.textureSampler(0).peekTexture();
+ GrSurfaceProxy* proxy = conv.textureSampler(0).proxy();
+ GrTexture* texture = proxy->priv().peekTexture();
float imageIncrement[2];
- float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
+ float ySign = proxy->origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
imageIncrement[0] = 1.0f / texture->width();
imageIncrement[1] = ySign / texture->height();
pdman.set2fv(fImageIncrementUni, 1, imageIncrement);
@@ -145,7 +146,7 @@
pdman.set4fv(fKernelUni, arrayCount, conv.kernel());
pdman.set1f(fGainUni, conv.gain());
pdman.set1f(fBiasUni, conv.bias());
- fDomain.setData(pdman, conv.domain(), texture);
+ fDomain.setData(pdman, conv.domain(), proxy);
}
GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(sk_sp<GrTextureProxy> proxy,
diff --git a/src/gpu/effects/GrTextureDomain.cpp b/src/gpu/effects/GrTextureDomain.cpp
index a8ce0ab..f2b7858 100644
--- a/src/gpu/effects/GrTextureDomain.cpp
+++ b/src/gpu/effects/GrTextureDomain.cpp
@@ -161,7 +161,8 @@
void GrTextureDomain::GLDomain::setData(const GrGLSLProgramDataManager& pdman,
const GrTextureDomain& textureDomain,
- GrTexture* tex) {
+ GrSurfaceProxy* proxy) {
+ GrTexture* tex = proxy->priv().peekTexture();
SkASSERT(textureDomain.mode() == fMode);
if (kIgnore_Mode != textureDomain.mode()) {
SkScalar wInv = SK_Scalar1 / tex->width();
@@ -180,7 +181,7 @@
SkASSERT(values[3] >= 0.0f && values[3] <= 1.0f);
// vertical flip if necessary
- if (kBottomLeft_GrSurfaceOrigin == tex->origin()) {
+ if (kBottomLeft_GrSurfaceOrigin == proxy->origin()) {
values[1] = 1.0f - values[1];
values[3] = 1.0f - values[3];
// The top and bottom were just flipped, so correct the ordering
@@ -270,9 +271,9 @@
const GrFragmentProcessor& fp) override {
const GrTextureDomainEffect& tde = fp.cast<GrTextureDomainEffect>();
const GrTextureDomain& domain = tde.fTextureDomain;
- GrTexture* texture = tde.textureSampler(0).peekTexture();
+ GrSurfaceProxy* proxy = tde.textureSampler(0).proxy();
- fGLDomain.setData(pdman, domain, texture);
+ fGLDomain.setData(pdman, domain, proxy);
if (SkToBool(tde.colorSpaceXform())) {
fColorSpaceHelper.setData(pdman, tde.colorSpaceXform());
}
@@ -372,16 +373,17 @@
const GrFragmentProcessor& fp) override {
const GrDeviceSpaceTextureDecalFragmentProcessor& dstdfp =
fp.cast<GrDeviceSpaceTextureDecalFragmentProcessor>();
- GrTexture* texture = dstdfp.textureSampler(0).peekTexture();
+ GrSurfaceProxy* proxy = dstdfp.textureSampler(0).proxy();
+ GrTexture* texture = proxy->priv().peekTexture();
- fGLDomain.setData(pdman, dstdfp.fTextureDomain, texture);
+ fGLDomain.setData(pdman, dstdfp.fTextureDomain, proxy);
float iw = 1.f / texture->width();
float ih = 1.f / texture->height();
float scaleAndTransData[4] = {
iw, ih,
-dstdfp.fDeviceSpaceOffset.fX * iw, -dstdfp.fDeviceSpaceOffset.fY * ih
};
- if (texture->origin() == kBottomLeft_GrSurfaceOrigin) {
+ if (proxy->origin() == kBottomLeft_GrSurfaceOrigin) {
scaleAndTransData[1] = -scaleAndTransData[1];
scaleAndTransData[3] = 1 - scaleAndTransData[3];
}
diff --git a/src/gpu/effects/GrTextureDomain.h b/src/gpu/effects/GrTextureDomain.h
index cbc55ec..8be1a2b 100644
--- a/src/gpu/effects/GrTextureDomain.h
+++ b/src/gpu/effects/GrTextureDomain.h
@@ -115,8 +115,7 @@
* texture domain. The rectangle is automatically adjusted to account for the texture's
* origin.
*/
- void setData(const GrGLSLProgramDataManager& pdman, const GrTextureDomain& textureDomain,
- GrTexture* texure);
+ void setData(const GrGLSLProgramDataManager&, const GrTextureDomain&, GrSurfaceProxy*);
enum {
kDomainKeyBits = 2, // See DomainKey().