void onDraw(SkCanvas* canvas) override {
GrRenderTarget* target = canvas->internal_private_accessTopLayerRenderTarget();
GrContext* ctx = canvas->getGrContext();
- GrDrawContext* drawContext = ctx ? ctx->drawContext() : nullptr;
+ SkAutoTUnref<GrDrawContext> drawContext(ctx ? ctx->drawContext() : nullptr);
if (drawContext && target) {
SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S));
static const int stride = 2 * S;
SkASSERT(fp);
paint.addColorFragmentProcessor(fp)->unref();
- GrDrawContext* drawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(context->drawContext());
if (drawContext) {
drawContext->drawNonAARectToRect(dst->asRenderTarget(), clip, paint, SkMatrix::I(),
dstRect, srcRect);
return false;
}
- GrDrawContext* drawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(context->drawContext());
if (drawContext) {
GrPaint grPaint;
grPaint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
paint.setCoverageSetOpXPFactory(SkRegion::kDifference_Op);
}
- GrDrawContext* drawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(context->drawContext());
if (!drawContext) {
return false;
}
matrix.setTranslate(-SkIntToScalar(colorBounds.x()),
-SkIntToScalar(colorBounds.y()));
- GrDrawContext* drawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(context->drawContext());
if (!drawContext) {
return false;
}
return nullptr;
}
- GrDrawContext* srcDrawContext = nullptr;
+ SkAutoTUnref<GrDrawContext> srcDrawContext;
for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
GrPaint paint;
scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
i < scaleFactorY ? 0.5f : 1.0f);
- GrDrawContext* dstDrawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext());
if (!dstDrawContext) {
return nullptr;
}
dstDrawContext->drawNonAARectToRect(dstTexture->asRenderTarget(), clip, paint,
SkMatrix::I(), dstRect, srcRect);
- srcDrawContext = dstDrawContext;
+ srcDrawContext.swap(&dstDrawContext);
srcRect = dstRect;
srcTexture = dstTexture;
SkTSwap(dstTexture, tempTexture);
SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY));
SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
- GrDrawContext* dstDrawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext());
if (!dstDrawContext) {
return nullptr;
}
convolve_gaussian_2d(dstDrawContext, dstTexture->asRenderTarget(), clip, srcRect, dstRect,
srcTexture, radiusX, radiusY, sigmaX, sigmaY, cropToRect, srcIRect);
- srcDrawContext = dstDrawContext;
+ srcDrawContext.swap(&dstDrawContext);
srcRect = dstRect;
srcTexture = dstTexture;
SkTSwap(dstTexture, tempTexture);
if (scaleFactorX > 1) {
// TODO: if we pass in the source draw context we don't need this here
if (!srcDrawContext) {
- srcDrawContext = context->drawContext();
+ srcDrawContext.reset(context->drawContext());
if (!srcDrawContext) {
return nullptr;
}
}
SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
- GrDrawContext* dstDrawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext());
if (!dstDrawContext) {
return nullptr;
}
srcTexture, Gr1DKernelEffect::kX_Direction, radiusX, sigmaX,
cropToRect);
- srcDrawContext = dstDrawContext;
+ srcDrawContext.swap(&dstDrawContext);
srcTexture = dstTexture;
srcRect = dstRect;
SkTSwap(dstTexture, tempTexture);
if (scaleFactorY > 1 || sigmaX > 0.0f) {
// TODO: if we pass in the source draw context we don't need this here
if (!srcDrawContext) {
- srcDrawContext = context->drawContext();
+ srcDrawContext.reset(context->drawContext());
if (!srcDrawContext) {
return nullptr;
}
SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
- GrDrawContext* dstDrawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext());
if (!dstDrawContext) {
return nullptr;
}
dstRect, srcTexture, Gr1DKernelEffect::kY_Direction, radiusY, sigmaY,
cropToRect);
- srcDrawContext = dstDrawContext;
+ srcDrawContext.swap(&dstDrawContext);
srcTexture = dstTexture;
srcRect = dstRect;
SkTSwap(dstTexture, tempTexture);
SkRect dstRect(srcRect);
scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY);
- GrDrawContext* dstDrawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext());
if (!dstDrawContext) {
return nullptr;
}
dstDrawContext->drawNonAARectToRect(dstTexture->asRenderTarget(), clip, paint,
SkMatrix::I(), dstRect, srcRect);
- srcDrawContext = dstDrawContext;
+ srcDrawContext.swap(&dstDrawContext);
srcRect = dstRect;
srcTexture = dstTexture;
SkTSwap(dstTexture, tempTexture);
SkRect bottom = SkRect::MakeXYWH(1, dstRect.height() - 1, dstRect.width() - 2, 1);
SkRect bottomRight = SkRect::MakeXYWH(dstRect.width() - 1, dstRect.height() - 1, 1, 1);
- GrDrawContext* drawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(context->drawContext());
if (!drawContext) {
return false;
}
if (nullptr == scratch) {
return false;
}
- GrDrawContext* dstDrawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext());
if (!dstDrawContext) {
return false;
}
if (nullptr == scratch) {
return false;
}
- GrDrawContext* dstDrawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext());
if (!dstDrawContext) {
return false;
}
paint.addColorFragmentProcessor(foregroundDomain.get());
paint.addColorFragmentProcessor(xferProcessor)->unref();
- GrDrawContext* drawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(context->drawContext());
if (!drawContext) {
return false;
}
SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height());
- GrDrawContext* drawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(context->drawContext());
if (!drawContext) {
return nullptr;
}
new GrDrawContext(fContext, fDrawTarget, props);
}
- return fDrawContext[props.pixelGeometry()][props.isUseDeviceIndependentFonts()];
+ // For now, everyone gets a faux creation ref
+ return SkRef(fDrawContext[props.pixelGeometry()][props.isUseDeviceIndependentFonts()]);
}
////////////////////////////////////////////////////////////////////////////////
}
SkMatrix matrix;
matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top));
- GrDrawContext* drawContext = this->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(this->drawContext());
if (!drawContext) {
return false;
}
if (fp) {
paint.addColorFragmentProcessor(fp);
SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
- GrDrawContext* drawContext = this->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(this->drawContext());
drawContext->drawRect(temp->asRenderTarget(), GrClip::WideOpen(), paint,
SkMatrix::I(), rect, nullptr);
surfaceToRead.reset(SkRef(temp.get()));
return;
}
- GrDrawContext* drawContext = this->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(this->drawContext());
if (!drawContext) {
return;
}
SkASSERT(0 == fPictureHash.count());
- GrDrawContext* drawContext = fContext->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(fContext->drawContext());
if (drawContext) {
drawContext->discard(fAtlas->getTexture()->asRenderTarget());
void GrRenderTarget::discard() {
// go through context so that all necessary flushing occurs
GrContext* context = this->getContext();
- GrDrawContext* drawContext = context ? context->drawContext() : nullptr;
+ if (!context) {
+ return;
+ }
+
+ SkAutoTUnref<GrDrawContext> drawContext(context->drawContext());
if (!drawContext) {
return;
}
fLegacyBitmap.setInfo(info);
fLegacyBitmap.setPixelRef(pr)->unref();
- fDrawContext.reset(SkRef(fContext->drawContext(&this->surfaceProps())));
+ fDrawContext.reset(fContext->drawContext(&this->surfaceProps()));
}
GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::Budgeted budgeted,
SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget);
fLegacyBitmap.setPixelRef(pr)->unref();
- fDrawContext.reset(SkRef(fRenderTarget->getContext()->drawContext(&this->surfaceProps())));
+ fDrawContext.reset(fRenderTarget->getContext()->drawContext(&this->surfaceProps()));
}
///////////////////////////////////////////////////////////////////////////////
SkRect rect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(rtDesc.fHeight));
SkRect localRect = SkRect::MakeWH(1.f, 1.f);
- GrDrawContext* drawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(context->drawContext());
if (!drawContext) {
return nullptr;
}
SkRect r = SkRect::MakeWH(SkIntToScalar(yuvInfo.fSize[0].fWidth),
SkIntToScalar(yuvInfo.fSize[0].fHeight));
- GrDrawContext* drawContext = ctx->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext());
if (!drawContext) {
return nullptr;
}
paint1.addColorFragmentProcessor(pmToUPM1);
- GrDrawContext* readDrawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> readDrawContext(context->drawContext());
if (!readDrawContext) {
failed = true;
break;
paint2.addColorFragmentProcessor(upmToPM);
- GrDrawContext* tempDrawContext = context->drawContext();
+ SkAutoTUnref<GrDrawContext> tempDrawContext(context->drawContext());
if (!tempDrawContext) {
failed = true;
break;
paint3.addColorFragmentProcessor(pmToUPM2);
- readDrawContext = context->drawContext();
+ readDrawContext.reset(context->drawContext());
if (!readDrawContext) {
failed = true;
break;
const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth),
SkIntToScalar(dstDesc.fHeight));
- GrDrawContext* drawContext = ctx->drawContext();
+ SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext());
+ if (!drawContext) {
+ return nullptr;
+ }
+
drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMatrix::I(), rect);
ctx->flushSurfaceWrites(dst);
return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueID,