diff options
-rw-r--r-- | include/gpu/GrContext.h | 15 | ||||
-rw-r--r-- | src/core/SkImageFilter.cpp | 17 | ||||
-rw-r--r-- | src/effects/SkAlphaThresholdFilter.cpp | 22 | ||||
-rw-r--r-- | src/effects/SkDisplacementMapEffect.cpp | 17 | ||||
-rw-r--r-- | src/effects/SkLightingImageFilter.cpp | 18 | ||||
-rw-r--r-- | src/effects/SkMorphologyImageFilter.cpp | 41 | ||||
-rw-r--r-- | src/effects/SkXfermodeImageFilter.cpp | 20 | ||||
-rw-r--r-- | src/gpu/GrBlurUtils.cpp | 59 | ||||
-rw-r--r-- | src/gpu/GrContext.cpp | 31 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 33 | ||||
-rw-r--r-- | tests/ClearTest.cpp | 40 | ||||
-rw-r--r-- | tests/ClipBoundsTest.cpp | 18 | ||||
-rw-r--r-- | tests/PrimitiveProcessorTest.cpp | 17 |
13 files changed, 149 insertions, 199 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 087d821beb..cb407aa5bf 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -194,6 +194,21 @@ public: */ sk_sp<GrDrawContext> drawContext(sk_sp<GrRenderTarget> rt, const SkSurfaceProps* = nullptr); + enum BackingFit { + kTight_BackingFit, + kLoose_BackingFit + }; + + /** + * Create both a GrRenderTarget and a matching GrDrawContext to wrap it. + * The created GrRenderTarget will always be budgeted. + */ + sk_sp<GrDrawContext> newDrawContext(BackingFit fit, + int width, int height, + GrPixelConfig config, + int sampleCnt = 0, + GrSurfaceOrigin origin = kDefault_GrSurfaceOrigin); + /////////////////////////////////////////////////////////////////////////// // Misc. diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index ed6d14ac14..d0042527e4 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -280,18 +280,9 @@ sk_sp<SkSpecialImage> SkImageFilter::DrawWithFP(GrContext* context, paint.addColorFragmentProcessor(fp.get()); paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); - GrSurfaceDesc desc; - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fWidth = bounds.width(); - desc.fHeight = bounds.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, + bounds.width(), bounds.height(), + kRGBA_8888_GrPixelConfig)); if (!drawContext) { return nullptr; } @@ -303,7 +294,7 @@ sk_sp<SkSpecialImage> SkImageFilter::DrawWithFP(GrContext* context, return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()), kNeedNewImageUniqueID_SpecialImage, - std::move(dst)); + drawContext->asTexture()); } #endif 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 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)) { diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 5ebb2e95fb..a186bd87bc 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -615,6 +615,37 @@ sk_sp<GrDrawContext> GrContext::drawContext(sk_sp<GrRenderTarget> rt, return fDrawingManager->drawContext(std::move(rt), surfaceProps); } +sk_sp<GrDrawContext> GrContext::newDrawContext(BackingFit fit, + int width, int height, + GrPixelConfig config, + int sampleCnt, + GrSurfaceOrigin origin) { + GrSurfaceDesc desc; + desc.fFlags = kRenderTarget_GrSurfaceFlag; + desc.fOrigin = origin; + desc.fWidth = width; + desc.fHeight = height; + desc.fConfig = config; + desc.fSampleCnt = sampleCnt; + + sk_sp<GrTexture> tex; + if (kTight_BackingFit == fit) { + tex.reset(this->textureProvider()->createTexture(desc, SkBudgeted::kYes)); + } else { + tex.reset(this->textureProvider()->createApproxTexture(desc)); + } + if (!tex) { + return nullptr; + } + + sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTarget()))); + if (!drawContext) { + return nullptr; + } + + return drawContext; +} + bool GrContext::abandoned() const { ASSERT_SINGLE_OWNER return fDrawingManager->abandoned(); diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index a66a623638..eea7e2c040 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -249,17 +249,16 @@ sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace return nullptr; } - GrSurfaceDesc dstDesc; + const int width = yuvSizes[0].fWidth; + const int height = yuvSizes[0].fHeight; + // Needs to be a render target in order to draw to it for the yuv->rgb conversion. - dstDesc.fFlags = kRenderTarget_GrSurfaceFlag; - dstDesc.fOrigin = origin; - dstDesc.fWidth = yuvSizes[0].fWidth; - dstDesc.fHeight = yuvSizes[0].fHeight; - dstDesc.fConfig = kRGBA_8888_GrPixelConfig; - dstDesc.fSampleCnt = 0; - - SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(dstDesc, SkBudgeted::kYes)); - if (!dst) { + sk_sp<GrDrawContext> drawContext(ctx->newDrawContext(GrContext::kTight_BackingFit, + width, height, + kRGBA_8888_GrPixelConfig, + 0, + origin)); + if (!drawContext) { return nullptr; } @@ -268,17 +267,13 @@ sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace paint.addColorFragmentProcessor(GrYUVEffect::CreateYUVToRGB(yTex, uTex, vTex, yuvSizes, colorSpace))->unref(); - const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), - SkIntToScalar(dstDesc.fHeight)); - sk_sp<GrDrawContext> drawContext(ctx->drawContext(sk_ref_sp(dst->asRenderTarget()))); - if (!drawContext) { - return nullptr; - } + const SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect); - ctx->flushSurfaceWrites(dst); - return sk_make_sp<SkImage_Gpu>(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueID, - kOpaque_SkAlphaType, dst, budgeted); + ctx->flushSurfaceWrites(drawContext->accessRenderTarget()); + return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID, + kOpaque_SkAlphaType, + drawContext->asTexture().get(), budgeted); } static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) { diff --git a/tests/ClearTest.cpp b/tests/ClearTest.cpp index 1065d940ba..7a533ba19c 100644 --- a/tests/ClearTest.cpp +++ b/tests/ClearTest.cpp @@ -37,31 +37,18 @@ static bool check_rect(GrDrawContext* dc, const SkIRect& rect, uint32_t expected return true; } -// We only really need the DC, but currently the DC doesn't own the RT so we also ref it, but that -// could be dropped when DC is a proper owner of its RT. -static bool reset_dc(sk_sp<GrDrawContext>* dc, SkAutoTUnref<GrSurface>* rtKeepAlive, - GrContext* context, int w, int h) { +static bool reset_dc(sk_sp<GrDrawContext>* dc, GrContext* context, int w, int h) { SkDEBUGCODE(uint32_t oldID = 0;) if (*dc) { SkDEBUGCODE(oldID = (*dc)->accessRenderTarget()->getUniqueID();) - rtKeepAlive->reset(nullptr); dc->reset(nullptr); } context->freeGpuResources(); - GrTextureDesc desc; - desc.fWidth = w; - desc.fHeight = h; - desc.fConfig = kRGBA_8888_GrPixelConfig; - desc.fFlags = kRenderTarget_GrSurfaceFlag; + *dc = context->newDrawContext(GrContext::kTight_BackingFit, w, h, kRGBA_8888_GrPixelConfig); + + SkASSERT((*dc)->accessRenderTarget()->getUniqueID() != oldID); - rtKeepAlive->reset(context->textureProvider()->createTexture(desc, SkBudgeted::kYes)); - if (!(*rtKeepAlive)) { - return false; - } - GrRenderTarget* rt = (*rtKeepAlive)->asRenderTarget(); - SkASSERT(rt->getUniqueID() != oldID); - *dc = context->drawContext(sk_ref_sp(rt)); return *dc != nullptr; } @@ -72,7 +59,6 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { SkIRect fullRect = SkIRect::MakeWH(kW, kH); sk_sp<GrDrawContext> drawContext; - SkAutoTUnref<GrSurface> rtKeepAlive; // A rectangle that is inset by one on all sides and the 1-pixel wide rectangles that surround // it. @@ -96,7 +82,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { static const GrColor kColor1 = 0xABCDEF01; static const GrColor kColor2 = ~kColor1; - if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { + if (!reset_dc(&drawContext, context, kW, kH)) { ERRORF(reporter, "Could not create draw context."); return; } @@ -107,7 +93,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { failX, failY); } - if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { + if (!reset_dc(&drawContext, context, kW, kH)) { ERRORF(reporter, "Could not create draw context."); return; } @@ -119,7 +105,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { failX, failY); } - if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { + if (!reset_dc(&drawContext, context, kW, kH)) { ERRORF(reporter, "Could not create draw context."); return; } @@ -131,7 +117,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { failX, failY); } - if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { + if (!reset_dc(&drawContext, context, kW, kH)) { ERRORF(reporter, "Could not create draw context."); return; } @@ -143,7 +129,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { failX, failY); } - if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { + if (!reset_dc(&drawContext, context, kW, kH)) { ERRORF(reporter, "Could not create draw context."); return; } @@ -155,7 +141,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { failX, failY); } - if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { + if (!reset_dc(&drawContext, context, kW, kH)) { ERRORF(reporter, "Could not create draw context."); return; } @@ -174,7 +160,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { failX, failY); } - if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { + if (!reset_dc(&drawContext, context, kW, kH)) { ERRORF(reporter, "Could not create draw context."); return; } @@ -186,7 +172,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { failX, failY); } - if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { + if (!reset_dc(&drawContext, context, kW, kH)) { ERRORF(reporter, "Could not create draw context."); return; } @@ -214,7 +200,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { failX, failY); } - if (!reset_dc(&drawContext, &rtKeepAlive, context, kW, kH)) { + if (!reset_dc(&drawContext, context, kW, kH)) { ERRORF(reporter, "Could not create draw context."); return; } diff --git a/tests/ClipBoundsTest.cpp b/tests/ClipBoundsTest.cpp index abdd3f44fa..5660afdc27 100644 --- a/tests/ClipBoundsTest.cpp +++ b/tests/ClipBoundsTest.cpp @@ -17,20 +17,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, ctxInfo) { static const int kXSize = 100; static const int kYSize = 100; - GrSurfaceDesc desc; - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fConfig = kAlpha_8_GrPixelConfig; - desc.fWidth = kXSize; - desc.fHeight = kYSize; - - SkAutoTUnref<GrTexture> texture( - ctxInfo.fGrContext->textureProvider()->createTexture(desc, SkBudgeted::kYes, nullptr, 0)); - if (!texture) { - return; - } - - SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize); - SkRect screen = SkRect::Make(intScreen); + const SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize); + const SkRect screen = SkRect::Make(intScreen); SkRect clipRect(screen); clipRect.outset(10, 10); @@ -56,7 +44,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, ctxInfo) { clipData.setClipStack(&stack); SkIRect devGrClipBound; - clipData.getConservativeBounds(texture->width(), texture->height(), + clipData.getConservativeBounds(kXSize, kYSize, &devGrClipBound, &isIntersectionOfRects); diff --git a/tests/PrimitiveProcessorTest.cpp b/tests/PrimitiveProcessorTest.cpp index 6d4ede1ce9..b1157a33a9 100644 --- a/tests/PrimitiveProcessorTest.cpp +++ b/tests/PrimitiveProcessorTest.cpp @@ -103,18 +103,9 @@ private: DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) { GrContext* context = ctxInfo.fGrContext; - GrTextureDesc desc; - desc.fHeight = 1; - desc.fWidth = 1; - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fConfig = kRGBA_8888_GrPixelConfig; - SkAutoTUnref<GrTexture> target(context->textureProvider()->createTexture(desc, - SkBudgeted::kYes)); - if (!target) { - ERRORF(reporter, "Could not create render target."); - return; - } - sk_sp<GrDrawContext> dc(context->drawContext(sk_ref_sp(target->asRenderTarget()))); + + sk_sp<GrDrawContext> dc(context->newDrawContext(GrContext::kLoose_BackingFit, + 1, 1, kRGBA_8888_GrPixelConfig)); if (!dc) { ERRORF(reporter, "Could not create draw context."); return; @@ -132,7 +123,7 @@ DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) { #endif SkAutoTUnref<GrDrawBatch> batch; GrPipelineBuilder pb; - pb.setRenderTarget(target->asRenderTarget()); + pb.setRenderTarget(dc->accessRenderTarget()); // This one should succeed. batch.reset(new Batch(attribCnt)); dc->drawContextPriv().testingOnly_drawBatch(pb, batch); |