diff options
author | 2016-04-27 13:34:01 -0700 | |
---|---|---|
committer | 2016-04-27 13:34:01 -0700 | |
commit | 2f1c42e8448bbbadeb3df1c626faa90aa33f8907 (patch) | |
tree | d5fc271e0eb33e4203617ce852ce79d73444e4fd /src/gpu/GrBlurUtils.cpp | |
parent | 4eeccc9de7d2381df85d68e0331a40cddf5989b1 (diff) |
Refactor drawContext/RenderTarget creation
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1914883002
Review-Url: https://codereview.chromium.org/1914883002
Diffstat (limited to 'src/gpu/GrBlurUtils.cpp')
-rw-r--r-- | src/gpu/GrBlurUtils.cpp | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp index 6827c83421..f95bdfff02 100644 --- a/src/gpu/GrBlurUtils.cpp +++ b/src/gpu/GrBlurUtils.cpp @@ -93,38 +93,34 @@ static bool sw_draw_with_mask_filter(GrDrawContext* drawContext, } // Create a mask of 'devPath' and place the result in 'mask'. -static GrTexture* create_mask_GPU(GrContext* context, - SkRect* maskRect, - const SkPath& devPath, - const GrStrokeInfo& strokeInfo, - bool doAA, - int sampleCnt) { +static sk_sp<GrTexture> create_mask_GPU(GrContext* context, + SkRect* maskRect, + const SkPath& devPath, + const GrStrokeInfo& strokeInfo, + bool doAA, + int sampleCnt) { // This mask will ultimately be drawn as a non-AA rect (see draw_mask). // Non-AA rects have a bad habit of snapping arbitrarily. Integerize here // so the mask draws in a reproducible manner. *maskRect = SkRect::Make(maskRect->roundOut()); - GrSurfaceDesc desc; - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fWidth = SkScalarCeilToInt(maskRect->width()); - desc.fHeight = SkScalarCeilToInt(maskRect->height()); - desc.fSampleCnt = doAA ? sampleCnt : 0; - // We actually only need A8, but it often isn't supported as a - // render target so default to RGBA_8888 - desc.fConfig = kRGBA_8888_GrPixelConfig; - - if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, desc.fSampleCnt > 0)) { - desc.fConfig = kAlpha_8_GrPixelConfig; + if (!doAA) { + // Don't need MSAA if mask isn't AA + sampleCnt = 0; } - GrTexture* mask = context->textureProvider()->createApproxTexture(desc); - if (nullptr == mask) { - return nullptr; + // We actually only need A8, but it often isn't supported as a + // render target so default to RGBA_8888 + GrPixelConfig config = kRGBA_8888_GrPixelConfig; + if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, sampleCnt > 0)) { + config = kAlpha_8_GrPixelConfig; } - SkRect clipRect = SkRect::MakeWH(maskRect->width(), maskRect->height()); - - sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(mask->asRenderTarget()))); + sk_sp<GrDrawContext> drawContext(context->newDrawContext(GrContext::kLoose_BackingFit, + SkScalarCeilToInt(maskRect->width()), + SkScalarCeilToInt(maskRect->height()), + config, + sampleCnt)); if (!drawContext) { return nullptr; } @@ -136,6 +132,7 @@ static GrTexture* create_mask_GPU(GrContext* context, tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); // setup new clip + const SkRect clipRect = SkRect::MakeWH(maskRect->width(), maskRect->height()); GrClip clip(clipRect); // Draw the mask into maskTexture with the path's integerized top-left at @@ -143,7 +140,7 @@ static GrTexture* create_mask_GPU(GrContext* context, SkMatrix translate; translate.setTranslate(-maskRect->fLeft, -maskRect->fTop); drawContext->drawPath(clip, tempPaint, translate, devPath, strokeInfo); - return mask; + return drawContext->asTexture();; } static void draw_path_with_mask_filter(GrContext* context, @@ -219,16 +216,16 @@ static void draw_path_with_mask_filter(GrContext* context, return; } - SkAutoTUnref<GrTexture> mask(create_mask_GPU(context, - &maskRect, - *devPathPtr, - strokeInfo, - paint->isAntiAlias(), - drawContext->numColorSamples())); + sk_sp<GrTexture> mask(create_mask_GPU(context, + &maskRect, + *devPathPtr, + strokeInfo, + paint->isAntiAlias(), + drawContext->numColorSamples())); if (mask) { GrTexture* filtered; - if (maskFilter->filterMaskGPU(mask, viewMatrix, maskRect, &filtered, true)) { + if (maskFilter->filterMaskGPU(mask.get(), viewMatrix, maskRect, &filtered, true)) { // filterMaskGPU gives us ownership of a ref to the result SkAutoTUnref<GrTexture> atu(filtered); if (draw_mask(drawContext, clip, viewMatrix, maskRect, paint, filtered)) { |