aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-04-28 09:55:15 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-28 09:55:15 -0700
commitd4c741e3d0e0fa633399691c47f76b6c7841ee83 (patch)
tree3a242889fa24e3e209df4e0ec76049fbdde61721 /src/effects
parent23bd7e9273438863149ed58c089e9bf457e9892d (diff)
Refactor drawContext/RenderTarget creation
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/SkAlphaThresholdFilter.cpp22
-rw-r--r--src/effects/SkDisplacementMapEffect.cpp17
-rw-r--r--src/effects/SkLightingImageFilter.cpp18
-rw-r--r--src/effects/SkMorphologyImageFilter.cpp41
-rw-r--r--src/effects/SkXfermodeImageFilter.cpp20
5 files changed, 37 insertions, 81 deletions
diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp
index bfbcfd21f8..cec45ba911 100644
--- a/src/effects/SkAlphaThresholdFilter.cpp
+++ b/src/effects/SkAlphaThresholdFilter.cpp
@@ -95,24 +95,16 @@ SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(const SkRegion& region,
sk_sp<GrTexture> SkAlphaThresholdFilterImpl::createMaskTexture(GrContext* context,
const SkMatrix& inMatrix,
const SkIRect& bounds) const {
- GrSurfaceDesc maskDesc;
+ GrPixelConfig config;
if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
- maskDesc.fConfig = kAlpha_8_GrPixelConfig;
+ config = kAlpha_8_GrPixelConfig;
} else {
- maskDesc.fConfig = kRGBA_8888_GrPixelConfig;
- }
- maskDesc.fFlags = kRenderTarget_GrSurfaceFlag;
- // Add one pixel of border to ensure that clamp mode will be all zeros
- // the outside.
- maskDesc.fWidth = bounds.width();
- maskDesc.fHeight = bounds.height();
- sk_sp<GrTexture> maskTexture(context->textureProvider()->createApproxTexture(maskDesc));
- if (!maskTexture) {
- return nullptr;
+ config = kRGBA_8888_GrPixelConfig;
}
- sk_sp<GrDrawContext> drawContext(
- context->drawContext(sk_ref_sp(maskTexture->asRenderTarget())));
+ sk_sp<GrDrawContext> drawContext(context->newDrawContext(GrContext::kLoose_BackingFit,
+ bounds.width(), bounds.height(),
+ config));
if (!drawContext) {
return nullptr;
}
@@ -129,7 +121,7 @@ sk_sp<GrTexture> SkAlphaThresholdFilterImpl::createMaskTexture(GrContext* contex
iter.next();
}
- return maskTexture;
+ return drawContext->asTexture();
}
#endif
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index 797bd972dd..cf9e2c3c9f 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -317,17 +317,6 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou
return nullptr;
}
- GrSurfaceDesc desc;
- desc.fFlags = kRenderTarget_GrSurfaceFlag;
- desc.fWidth = bounds.width();
- desc.fHeight = bounds.height();
- desc.fConfig = kSkia8888_GrPixelConfig;
-
- sk_sp<GrTexture> dst(context->textureProvider()->createApproxTexture(desc));
- if (!dst) {
- return nullptr;
- }
-
GrPaint paint;
SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displTexture.get());
offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displOffset.fX),
@@ -346,7 +335,9 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou
SkMatrix matrix;
matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colorBounds.y()));
- sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(dst->asRenderTarget())));
+ sk_sp<GrDrawContext> drawContext(context->newDrawContext(GrContext::kLoose_BackingFit,
+ bounds.width(), bounds.height(),
+ kSkia8888_GrPixelConfig));
if (!drawContext) {
return nullptr;
}
@@ -357,7 +348,7 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou
offset->fY = bounds.top();
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()),
kNeedNewImageUniqueID_SpecialImage,
- std::move(dst));
+ drawContext->asTexture());
}
#endif
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 7223ae5a1e..6efb0f6c4e 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -407,18 +407,10 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(SkSpecialIma
sk_sp<GrTexture> inputTexture(input->asTextureRef(context));
SkASSERT(inputTexture);
- GrSurfaceDesc desc;
- desc.fFlags = kRenderTarget_GrSurfaceFlag,
- desc.fWidth = offsetBounds.width();
- desc.fHeight = offsetBounds.height();
- desc.fConfig = kRGBA_8888_GrPixelConfig;
-
- sk_sp<GrTexture> dst(context->textureProvider()->createApproxTexture(desc));
- if (!dst) {
- return nullptr;
- }
-
- sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(dst->asRenderTarget())));
+ sk_sp<GrDrawContext> drawContext(context->newDrawContext(GrContext::kLoose_BackingFit,
+ offsetBounds.width(),
+ offsetBounds.height(),
+ kRGBA_8888_GrPixelConfig));
if (!drawContext) {
return nullptr;
}
@@ -462,7 +454,7 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(SkSpecialIma
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(offsetBounds.width(), offsetBounds.height()),
kNeedNewImageUniqueID_SpecialImage,
- std::move(dst));
+ drawContext->asTexture());
}
#endif
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index 9e87fe04a4..2a0f078c05 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -478,26 +478,18 @@ static sk_sp<SkSpecialImage> apply_morphology(GrContext* context,
SkASSERT(srcTexture);
// setup new clip
- GrClip clip(SkRect::MakeWH(SkIntToScalar(srcTexture->width()),
- SkIntToScalar(srcTexture->height())));
-
- SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height());
- GrSurfaceDesc desc;
- desc.fFlags = kRenderTarget_GrSurfaceFlag;
- desc.fWidth = rect.width();
- desc.fHeight = rect.height();
- desc.fConfig = kSkia8888_GrPixelConfig;
+ const GrClip clip(SkRect::MakeWH(SkIntToScalar(srcTexture->width()),
+ SkIntToScalar(srcTexture->height())));
+
+ const SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height());
SkIRect srcRect = rect;
SkASSERT(radius.width() > 0 || radius.height() > 0);
if (radius.fWidth > 0) {
- GrTexture* scratch = context->textureProvider()->createApproxTexture(desc);
- if (!scratch) {
- return nullptr;
- }
- sk_sp<GrDrawContext> dstDrawContext(
- context->drawContext(sk_ref_sp(scratch->asRenderTarget())));
+ sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(GrContext::kLoose_BackingFit,
+ rect.width(), rect.height(),
+ kSkia8888_GrPixelConfig));
if (!dstDrawContext) {
return nullptr;
}
@@ -507,21 +499,18 @@ static sk_sp<SkSpecialImage> apply_morphology(GrContext* context,
Gr1DKernelEffect::kX_Direction);
SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom,
dstRect.width(), radius.fHeight);
- GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphType ?
- SK_ColorWHITE :
- SK_ColorTRANSPARENT;
+ GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphType
+ ? SK_ColorWHITE
+ : SK_ColorTRANSPARENT;
dstDrawContext->clear(&clearRect, clearColor, false);
- srcTexture.reset(scratch);
+ srcTexture = dstDrawContext->asTexture();
srcRect = dstRect;
}
if (radius.fHeight > 0) {
- GrTexture* scratch = context->textureProvider()->createApproxTexture(desc);
- if (!scratch) {
- return nullptr;
- }
- sk_sp<GrDrawContext> dstDrawContext(
- context->drawContext(sk_ref_sp(scratch->asRenderTarget())));
+ sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(GrContext::kLoose_BackingFit,
+ rect.width(), rect.height(),
+ kSkia8888_GrPixelConfig));
if (!dstDrawContext) {
return nullptr;
}
@@ -530,7 +519,7 @@ static sk_sp<SkSpecialImage> apply_morphology(GrContext* context,
srcRect, dstRect, radius.fHeight, morphType,
Gr1DKernelEffect::kY_Direction);
- srcTexture.reset(scratch);
+ srcTexture = dstDrawContext->asTexture();
}
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height()),
diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp
index b1ac1c32e0..b1e19bbec3 100644
--- a/src/effects/SkXfermodeImageFilter.cpp
+++ b/src/effects/SkXfermodeImageFilter.cpp
@@ -176,16 +176,6 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter::filterImageGPU(SkSpecialImage* sour
foregroundTex = foreground->asTextureRef(context);
}
- GrSurfaceDesc desc;
- desc.fFlags = kRenderTarget_GrSurfaceFlag;
- desc.fWidth = bounds.width();
- desc.fHeight = bounds.height();
- desc.fConfig = kSkia8888_GrPixelConfig;
- sk_sp<GrTexture> dst(context->textureProvider()->createApproxTexture(desc));
- if (!dst) {
- return nullptr;
- }
-
GrPaint paint;
// SRGBTODO: AllowSRGBInputs?
SkAutoTUnref<const GrFragmentProcessor> bgFP;
@@ -236,11 +226,11 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter::filterImageGPU(SkSpecialImage* sour
mode.reset(new SkProcCoeffXfermode(rec, SkXfermode::kSrcOver_Mode));
}
- SkAutoTUnref<const GrFragmentProcessor> xferFP(mode->getFragmentProcessorForImageFilter(bgFP));
+ sk_sp<const GrFragmentProcessor> xferFP(mode->getFragmentProcessorForImageFilter(bgFP));
// A null 'xferFP' here means kSrc_Mode was used in which case we can just proceed
if (xferFP) {
- paint.addColorFragmentProcessor(xferFP);
+ paint.addColorFragmentProcessor(xferFP.get());
}
} else {
paint.addColorFragmentProcessor(bgFP);
@@ -248,7 +238,9 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter::filterImageGPU(SkSpecialImage* sour
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
- sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(dst->asRenderTarget())));
+ sk_sp<GrDrawContext> drawContext(context->newDrawContext(GrContext::kLoose_BackingFit,
+ bounds.width(), bounds.height(),
+ kSkia8888_GrPixelConfig));
if (!drawContext) {
return nullptr;
}
@@ -259,7 +251,7 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter::filterImageGPU(SkSpecialImage* sour
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()),
kNeedNewImageUniqueID_SpecialImage,
- std::move(dst));
+ drawContext->asTexture());
}
#endif