aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects/SkLightingImageFilter.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-02-08 12:49:00 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-02-08 12:49:16 +0000
commit696b29346e85307a05af47768d358161eba3f6bd (patch)
tree2b488b37e0240e0176c539ad4efd4e25ca5bbd7d /src/effects/SkLightingImageFilter.cpp
parent9852dc027f77c20640796d6988b0efcd42aa0b73 (diff)
Revert "Remove asTextureRef from SkSpecialImage & update effects accordingly"
This reverts commit e88cf6b7aa5deaeaa9dab18ada7d9d11e1e4be12. Reason for revert: See if breaking DEPS roll Original change's description: > Remove asTextureRef from SkSpecialImage & update effects accordingly > > This CL also renames SkSpecialImage::asTextureProxy to asTextureProxyRef > > Change-Id: I5ed8e475bb9688453b825ae4500ed0e8d324b5ac > Reviewed-on: https://skia-review.googlesource.com/7995 > Reviewed-by: Brian Salomon <bsalomon@google.com> > Commit-Queue: Robert Phillips <robertphillips@google.com> > TBR=bsalomon@google.com,robertphillips@google.com,reviews@skia.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: I227cbd5fcaf7e2f86e858331d9ec7ff7a5f203ca Reviewed-on: https://skia-review.googlesource.com/8184 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/effects/SkLightingImageFilter.cpp')
-rw-r--r--src/effects/SkLightingImageFilter.cpp139
1 files changed, 61 insertions, 78 deletions
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index fefb2ff077..92057f0802 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -365,15 +365,15 @@ protected:
const SkIRect& bounds,
const SkMatrix& matrix,
const OutputProperties& outputProperties) const;
- virtual sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrContext*, sk_sp<GrTextureProxy>,
+ virtual sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*,
const SkMatrix&,
const SkIRect* srcBounds,
BoundaryMode boundaryMode) const = 0;
#endif
private:
#if SK_SUPPORT_GPU
- void drawRect(GrContext*, GrRenderTargetContext*,
- sk_sp<GrTextureProxy> srcProxy,
+ void drawRect(GrRenderTargetContext* renderTargetContext,
+ GrTexture* src,
const SkMatrix& matrix,
const GrClip& clip,
const SkRect& dstRect,
@@ -385,9 +385,8 @@ private:
};
#if SK_SUPPORT_GPU
-void SkLightingImageFilterInternal::drawRect(GrContext* context,
- GrRenderTargetContext* renderTargetContext,
- sk_sp<GrTextureProxy> srcProxy,
+void SkLightingImageFilterInternal::drawRect(GrRenderTargetContext* renderTargetContext,
+ GrTexture* src,
const SkMatrix& matrix,
const GrClip& clip,
const SkRect& dstRect,
@@ -397,8 +396,7 @@ void SkLightingImageFilterInternal::drawRect(GrContext* context,
SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()));
GrPaint paint;
paint.setGammaCorrect(renderTargetContext->isGammaCorrect());
- sk_sp<GrFragmentProcessor> fp(this->makeFragmentProcessor(context, std::move(srcProxy),
- matrix, srcBounds,
+ sk_sp<GrFragmentProcessor> fp(this->makeFragmentProcessor(src, matrix, srcBounds,
boundaryMode));
paint.addColorFragmentProcessor(std::move(fp));
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
@@ -416,8 +414,8 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(
GrContext* context = source->getContext();
- sk_sp<GrTextureProxy> inputProxy(input->asTextureProxyRef(context));
- SkASSERT(inputProxy);
+ sk_sp<GrTexture> inputTexture(input->asTextureRef(context));
+ SkASSERT(inputTexture);
sk_sp<GrRenderTargetContext> renderTargetContext(context->makeDeferredRenderTargetContext(
SkBackingFit::kApprox, offsetBounds.width(), offsetBounds.height(),
@@ -445,23 +443,23 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(
SkRect bottomRight = SkRect::MakeXYWH(dstRect.width() - 1, dstRect.height() - 1, 1, 1);
const SkIRect* pSrcBounds = inputBounds.contains(offsetBounds) ? nullptr : &inputBounds;
- this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, topLeft,
+ this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, topLeft,
kTopLeft_BoundaryMode, pSrcBounds, offsetBounds);
- this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, top,
+ this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, top,
kTop_BoundaryMode, pSrcBounds, offsetBounds);
- this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, topRight,
+ this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, topRight,
kTopRight_BoundaryMode, pSrcBounds, offsetBounds);
- this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, left,
+ this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, left,
kLeft_BoundaryMode, pSrcBounds, offsetBounds);
- this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, interior,
+ this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, interior,
kInterior_BoundaryMode, pSrcBounds, offsetBounds);
- this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, right,
+ this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, right,
kRight_BoundaryMode, pSrcBounds, offsetBounds);
- this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, bottomLeft,
+ this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, bottomLeft,
kBottomLeft_BoundaryMode, pSrcBounds, offsetBounds);
- this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, bottom,
+ this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, bottom,
kBottom_BoundaryMode, pSrcBounds, offsetBounds);
- this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, bottomRight,
+ this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, bottomRight,
kBottomRight_BoundaryMode, pSrcBounds, offsetBounds);
return SkSpecialImage::MakeDeferredFromGpu(
@@ -495,8 +493,8 @@ protected:
SkIPoint* offset) const override;
#if SK_SUPPORT_GPU
- sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrContext*, sk_sp<GrTextureProxy>,
- const SkMatrix&, const SkIRect* bounds,
+ sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*, const SkMatrix&,
+ const SkIRect* bounds,
BoundaryMode) const override;
#endif
@@ -531,8 +529,8 @@ protected:
SkIPoint* offset) const override;
#if SK_SUPPORT_GPU
- sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrContext*, sk_sp<GrTextureProxy>,
- const SkMatrix&, const SkIRect* bounds,
+ sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*, const SkMatrix&,
+ const SkIRect* bounds,
BoundaryMode) const override;
#endif
@@ -547,8 +545,7 @@ private:
class GrLightingEffect : public GrSingleTextureEffect {
public:
- GrLightingEffect(GrContext*, sk_sp<GrTextureProxy>,
- const SkImageFilterLight* light, SkScalar surfaceScale,
+ GrLightingEffect(GrTexture* texture, const SkImageFilterLight* light, SkScalar surfaceScale,
const SkMatrix& matrix, BoundaryMode boundaryMode, const SkIRect* srcBounds);
~GrLightingEffect() override;
@@ -578,8 +575,7 @@ private:
class GrDiffuseLightingEffect : public GrLightingEffect {
public:
- static sk_sp<GrFragmentProcessor> Make(GrContext* context,
- sk_sp<GrTextureProxy> proxy,
+ static sk_sp<GrFragmentProcessor> Make(GrTexture* texture,
const SkImageFilterLight* light,
SkScalar surfaceScale,
const SkMatrix& matrix,
@@ -587,8 +583,8 @@ public:
BoundaryMode boundaryMode,
const SkIRect* srcBounds) {
return sk_sp<GrFragmentProcessor>(
- new GrDiffuseLightingEffect(context, std::move(proxy), light,
- surfaceScale, matrix, kd, boundaryMode, srcBounds));
+ new GrDiffuseLightingEffect(texture, light, surfaceScale, matrix, kd, boundaryMode,
+ srcBounds));
}
const char* name() const override { return "DiffuseLighting"; }
@@ -602,7 +598,7 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override;
- GrDiffuseLightingEffect(GrContext*, sk_sp<GrTextureProxy>,
+ GrDiffuseLightingEffect(GrTexture* texture,
const SkImageFilterLight* light,
SkScalar surfaceScale,
const SkMatrix& matrix,
@@ -611,15 +607,13 @@ private:
const SkIRect* srcBounds);
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
- SkScalar fKD;
-
typedef GrLightingEffect INHERITED;
+ SkScalar fKD;
};
class GrSpecularLightingEffect : public GrLightingEffect {
public:
- static sk_sp<GrFragmentProcessor> Make(GrContext* context,
- sk_sp<GrTextureProxy> proxy,
+ static sk_sp<GrFragmentProcessor> Make(GrTexture* texture,
const SkImageFilterLight* light,
SkScalar surfaceScale,
const SkMatrix& matrix,
@@ -628,8 +622,7 @@ public:
BoundaryMode boundaryMode,
const SkIRect* srcBounds) {
return sk_sp<GrFragmentProcessor>(
- new GrSpecularLightingEffect(context, std::move(proxy),
- light, surfaceScale, matrix, ks, shininess,
+ new GrSpecularLightingEffect(texture, light, surfaceScale, matrix, ks, shininess,
boundaryMode, srcBounds));
}
@@ -645,7 +638,7 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override;
- GrSpecularLightingEffect(GrContext*, sk_sp<GrTextureProxy>,
+ GrSpecularLightingEffect(GrTexture* texture,
const SkImageFilterLight* light,
SkScalar surfaceScale,
const SkMatrix& matrix,
@@ -655,10 +648,9 @@ private:
const SkIRect* srcBounds);
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
+ typedef GrLightingEffect INHERITED;
SkScalar fKS;
SkScalar fShininess;
-
- typedef GrLightingEffect INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
@@ -1356,14 +1348,12 @@ void SkDiffuseLightingImageFilter::toString(SkString* str) const {
#if SK_SUPPORT_GPU
sk_sp<GrFragmentProcessor> SkDiffuseLightingImageFilter::makeFragmentProcessor(
- GrContext* context,
- sk_sp<GrTextureProxy> proxy,
+ GrTexture* texture,
const SkMatrix& matrix,
const SkIRect* srcBounds,
BoundaryMode boundaryMode) const {
SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255));
- return GrDiffuseLightingEffect::Make(context, std::move(proxy),
- this->light(), scale, matrix, this->kd(),
+ return GrDiffuseLightingEffect::Make(texture, this->light(), scale, matrix, this->kd(),
boundaryMode, srcBounds);
}
#endif
@@ -1523,14 +1513,12 @@ void SkSpecularLightingImageFilter::toString(SkString* str) const {
#if SK_SUPPORT_GPU
sk_sp<GrFragmentProcessor> SkSpecularLightingImageFilter::makeFragmentProcessor(
- GrContext* context,
- sk_sp<GrTextureProxy> proxy,
+ GrTexture* texture,
const SkMatrix& matrix,
const SkIRect* srcBounds,
BoundaryMode boundaryMode) const {
SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255));
- return GrSpecularLightingEffect::Make(context, std::move(proxy), this->light(),
- scale, matrix, this->ks(),
+ return GrSpecularLightingEffect::Make(texture, this->light(), scale, matrix, this->ks(),
this->shininess(), boundaryMode, srcBounds);
}
#endif
@@ -1703,30 +1691,29 @@ private:
///////////////////////////////////////////////////////////////////////////////
-static GrTextureDomain create_domain(GrTextureProxy* proxy, const SkIRect* srcBounds,
+static GrTextureDomain create_domain(GrTexture* texture, const SkIRect* srcBounds,
GrTextureDomain::Mode mode) {
if (srcBounds) {
SkRect texelDomain = GrTextureDomain::MakeTexelDomainForMode(*srcBounds, mode);
- return GrTextureDomain(proxy, texelDomain, mode);
+ return GrTextureDomain(texture, texelDomain, mode);
} else {
return GrTextureDomain::IgnoredDomain();
}
}
-GrLightingEffect::GrLightingEffect(GrContext* context,
- sk_sp<GrTextureProxy> proxy,
+GrLightingEffect::GrLightingEffect(GrTexture* texture,
const SkImageFilterLight* light,
SkScalar surfaceScale,
const SkMatrix& matrix,
BoundaryMode boundaryMode,
const SkIRect* srcBounds)
// Perhaps this could advertise the opaque or modulating optimizations?
- : INHERITED(context, kNone_OptimizationFlags, proxy, nullptr, SkMatrix::I())
+ : INHERITED(texture, nullptr, SkMatrix::I(), kNone_OptimizationFlags)
, fLight(light)
, fSurfaceScale(surfaceScale)
, fFilterMatrix(matrix)
, fBoundaryMode(boundaryMode)
- , fDomain(create_domain(proxy.get(), srcBounds, GrTextureDomain::kDecal_Mode)) {
+ , fDomain(create_domain(texture, srcBounds, GrTextureDomain::kDecal_Mode)) {
fLight->ref();
if (light->requiresFragmentPosition()) {
this->setWillReadFragmentPosition();
@@ -1746,16 +1733,14 @@ bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
///////////////////////////////////////////////////////////////////////////////
-GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrContext* context,
- sk_sp<GrTextureProxy> proxy,
+GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture,
const SkImageFilterLight* light,
SkScalar surfaceScale,
const SkMatrix& matrix,
SkScalar kd,
BoundaryMode boundaryMode,
const SkIRect* srcBounds)
- : INHERITED(context, std::move(proxy), light, surfaceScale, matrix,
- boundaryMode, srcBounds), fKD(kd) {
+ : INHERITED(texture, light, surfaceScale, matrix, boundaryMode, srcBounds), fKD(kd) {
this->initClassID<GrDiffuseLightingEffect>();
}
@@ -1777,9 +1762,9 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect);
#if GR_TEST_UTILS
sk_sp<GrFragmentProcessor> GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d) {
- int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
- : GrProcessorUnitTest::kAlphaTextureIdx;
- sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
+ int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
+ GrProcessorUnitTest::kAlphaTextureIdx;
+ GrTexture* tex = d->fTextures[texIdx];
SkScalar surfaceScale = d->fRandom->nextSScalar1();
SkScalar kd = d->fRandom->nextUScalar1();
sk_sp<SkImageFilterLight> light(create_random_light(d->fRandom));
@@ -1787,14 +1772,13 @@ sk_sp<GrFragmentProcessor> GrDiffuseLightingEffect::TestCreate(GrProcessorTestDa
for (int i = 0; i < 9; i++) {
matrix[i] = d->fRandom->nextUScalar1();
}
- SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, proxy->width()),
- d->fRandom->nextRangeU(0, proxy->height()),
- d->fRandom->nextRangeU(0, proxy->width()),
- d->fRandom->nextRangeU(0, proxy->height()));
+ SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, tex->width()),
+ d->fRandom->nextRangeU(0, tex->height()),
+ d->fRandom->nextRangeU(0, tex->width()),
+ d->fRandom->nextRangeU(0, tex->height()));
BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundaryModeCount);
- return GrDiffuseLightingEffect::Make(d->context(),
- std::move(proxy), light.get(), surfaceScale,
- matrix, kd, mode, &srcBounds);
+ return GrDiffuseLightingEffect::Make(tex, light.get(), surfaceScale, matrix, kd, mode,
+ &srcBounds);
}
#endif
@@ -1964,8 +1948,7 @@ void GrGLDiffuseLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman,
///////////////////////////////////////////////////////////////////////////////
-GrSpecularLightingEffect::GrSpecularLightingEffect(GrContext* context,
- sk_sp<GrTextureProxy> proxy,
+GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture,
const SkImageFilterLight* light,
SkScalar surfaceScale,
const SkMatrix& matrix,
@@ -1973,7 +1956,7 @@ GrSpecularLightingEffect::GrSpecularLightingEffect(GrContext* context,
SkScalar shininess,
BoundaryMode boundaryMode,
const SkIRect* srcBounds)
- : INHERITED(context, std::move(proxy), light, surfaceScale, matrix, boundaryMode, srcBounds)
+ : INHERITED(texture, light, surfaceScale, matrix, boundaryMode, srcBounds)
, fKS(ks)
, fShininess(shininess) {
this->initClassID<GrSpecularLightingEffect>();
@@ -1999,9 +1982,9 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect);
#if GR_TEST_UTILS
sk_sp<GrFragmentProcessor> GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d) {
- int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
- : GrProcessorUnitTest::kAlphaTextureIdx;
- sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
+ int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
+ GrProcessorUnitTest::kAlphaTextureIdx;
+ GrTexture* tex = d->fTextures[texIdx];
SkScalar surfaceScale = d->fRandom->nextSScalar1();
SkScalar ks = d->fRandom->nextUScalar1();
SkScalar shininess = d->fRandom->nextUScalar1();
@@ -2011,11 +1994,11 @@ sk_sp<GrFragmentProcessor> GrSpecularLightingEffect::TestCreate(GrProcessorTestD
matrix[i] = d->fRandom->nextUScalar1();
}
BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundaryModeCount);
- SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, proxy->width()),
- d->fRandom->nextRangeU(0, proxy->height()),
- d->fRandom->nextRangeU(0, proxy->width()),
- d->fRandom->nextRangeU(0, proxy->height()));
- return GrSpecularLightingEffect::Make(d->context(), std::move(proxy),
+ SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, tex->width()),
+ d->fRandom->nextRangeU(0, tex->height()),
+ d->fRandom->nextRangeU(0, tex->width()),
+ d->fRandom->nextRangeU(0, tex->height()));
+ return GrSpecularLightingEffect::Make(d->fTextures[GrProcessorUnitTest::kAlphaTextureIdx],
light.get(), surfaceScale, matrix, ks, shininess, mode,
&srcBounds);
}