Refactor drawContext/RenderTarget creation
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
This commit is contained in:
parent
23bd7e9273
commit
d4c741e3d0
@ -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.
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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())));
|
||||
const 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 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()),
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
if (!doAA) {
|
||||
// Don't need MSAA if mask isn't AA
|
||||
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;
|
||||
GrPixelConfig config = kRGBA_8888_GrPixelConfig;
|
||||
if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, sampleCnt > 0)) {
|
||||
config = kAlpha_8_GrPixelConfig;
|
||||
}
|
||||
|
||||
GrTexture* mask = context->textureProvider()->createApproxTexture(desc);
|
||||
if (nullptr == mask) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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)) {
|
||||
|
@ -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();
|
||||
|
@ -249,17 +249,16 @@ sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GrSurfaceDesc dstDesc;
|
||||
// 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;
|
||||
const int width = yuvSizes[0].fWidth;
|
||||
const int height = yuvSizes[0].fHeight;
|
||||
|
||||
SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(dstDesc, SkBudgeted::kYes));
|
||||
if (!dst) {
|
||||
// Needs to be a render target in order to draw to it for the yuv->rgb conversion.
|
||||
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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user