Refactor drawContext/RenderTarget creation
authorrobertphillips <robertphillips@google.com>
Thu, 28 Apr 2016 16:55:15 +0000 (09:55 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 28 Apr 2016 16:55:15 +0000 (09:55 -0700)
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1914883002

Committed: https://skia.googlesource.com/skia/+/2f1c42e8448bbbadeb3df1c626faa90aa33f8907

Review-Url: https://codereview.chromium.org/1914883002

13 files changed:
include/gpu/GrContext.h
src/core/SkImageFilter.cpp
src/effects/SkAlphaThresholdFilter.cpp
src/effects/SkDisplacementMapEffect.cpp
src/effects/SkLightingImageFilter.cpp
src/effects/SkMorphologyImageFilter.cpp
src/effects/SkXfermodeImageFilter.cpp
src/gpu/GrBlurUtils.cpp
src/gpu/GrContext.cpp
src/image/SkImage_Gpu.cpp
tests/ClearTest.cpp
tests/ClipBoundsTest.cpp
tests/PrimitiveProcessorTest.cpp

index 087d821beb1f06285b9bdff0211786cd14898bb1..cb407aa5bfa16db1d2c3e7800e0c2c237e7b2804 100644 (file)
@@ -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.
 
index ed6d14ac147b7464814f18188168c689712faf90..d0042527e48c29381c0a93fc94e1d98981d5fe31 100644 (file)
@@ -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
 
index bfbcfd21f8b959e8acfeeab9fc0c0e41a032457c..cec45ba9114243cb9ba768ee9b7585226e216604 100644 (file)
@@ -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
 
index 797bd972dd9850f979991127bf42cc2eb21392f0..cf9e2c3c9f9a77531b4ea751f87797e008146df0 100644 (file)
@@ -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
 
index 7223ae5a1e4a3d7cddd2e05a4b7698dc732046f4..6efb0f6c4e1a33f0fdaf7e5c6cc1e663c3588241 100644 (file)
@@ -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
 
index 9e87fe04a41a4c00dbc41898277e0b7d7460e69f..2a0f078c053fd6ed0cc13577668090b7415a6c1c 100644 (file)
@@ -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()),
index b1ac1c32e08ac9c20bc8eed444f350f3056080eb..b1e19bbec3e207e82db9617473baa8f8e02fde5a 100644 (file)
@@ -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
index 6827c83421b532941d9a68ddfefca4f183be827d..f95bdfff02ffa45325e85db2a8ca4479170a688e 100644 (file)
@@ -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)) {
index 5ebb2e95fbf62c478db804e0e1254827a37e5689..a186bd87bc101f1cf9107ccc1903172adf354622 100644 (file)
@@ -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();
index a66a623638ad7a3d8a5c4fb53ac7a4d94a77104a..eea7e2c04074e191eee77d1e022348c338f92757 100644 (file)
@@ -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) {
index 1065d940ba84350a626f9f7b38fca1e353f11aa5..7a533ba19c45a4788a5501a8276f7f7a92c28ec6 100644 (file)
@@ -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;
     }
index abdd3f44fa1e4e3b1d36fda9bdf2aa5fd6c28779..5660afdc27aa2cdb00b422509230113d3cbb1792 100644 (file)
@@ -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);
 
index 6d4ede1ce9246e725daaa718452c35b70a33af4e..b1157a33a9e3c24aec044338d8b7ec5260e8a8d1 100644 (file)
@@ -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);