Add SkColorSpace to GrDrawContext

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2164363002

Review-Url: https://codereview.chromium.org/2164363002
This commit is contained in:
brianosman 2016-07-21 13:28:36 -07:00 committed by Commit bot
parent 8602ede5fd
commit dfe4f2e4fe
48 changed files with 169 additions and 89 deletions

View File

@ -36,7 +36,7 @@ protected:
SkSurface* createSurface() override {
SkSurfaceProps props(INHERITED::getSurfaceProps());
if (kGPU_DeviceType == fType) {
return SkSurface::MakeRenderTargetDirect(fRenderTarget, &props).release();
return SkSurface::MakeRenderTargetDirect(fRenderTarget, nullptr, &props).release();
}
static const SkImageInfo info = SkImageInfo::MakeN32Premul(
SkScalarRoundToInt(this->width()), SkScalarRoundToInt(this->height()));

View File

@ -82,7 +82,7 @@ public:
/**
* Return a new surface using the specified render target.
*/
static sk_sp<SkSurface> MakeRenderTargetDirect(GrRenderTarget*,
static sk_sp<SkSurface> MakeRenderTargetDirect(GrRenderTarget*, sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* = nullptr);
/**
@ -92,7 +92,7 @@ public:
* SkSurface.
*/
static sk_sp<SkSurface> MakeFromBackendTexture(GrContext*, const GrBackendTextureDesc&,
const SkSurfaceProps*);
sk_sp<SkColorSpace>, const SkSurfaceProps*);
/**
* Used to wrap a pre-existing 3D API rendering target as a SkSurface. Skia will not assume
@ -101,6 +101,7 @@ public:
*/
static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext*,
const GrBackendRenderTargetDesc&,
sk_sp<SkColorSpace>,
const SkSurfaceProps*);
/**
@ -112,7 +113,28 @@ public:
* SkSurface.
*/
static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(
GrContext*, const GrBackendTextureDesc&, const SkSurfaceProps*);
GrContext*, const GrBackendTextureDesc&, sk_sp<SkColorSpace>, const SkSurfaceProps*);
/**
* Legacy versions of the above factories, without color space support. These create "legacy"
* surfaces that operate without gamma correction or color management.
*/
static sk_sp<SkSurface> MakeFromBackendTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
const SkSurfaceProps* props) {
return MakeFromBackendTexture(ctx, desc, nullptr, props);
}
static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext* ctx,
const GrBackendRenderTargetDesc& desc,
const SkSurfaceProps* props) {
return MakeFromBackendRenderTarget(ctx, desc, nullptr, props);
}
static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(
GrContext* ctx, const GrBackendTextureDesc& desc, const SkSurfaceProps* props) {
return MakeFromBackendTextureAsRenderTarget(ctx, desc, nullptr, props);
}
/**
* Return a new surface whose contents will be drawn to an offscreen
@ -149,7 +171,7 @@ public:
return NewRaster(SkImageInfo::MakeN32Premul(width, height), props);
}
static SkSurface* NewRenderTargetDirect(GrRenderTarget* rt, const SkSurfaceProps* props) {
return MakeRenderTargetDirect(rt, props).release();
return MakeRenderTargetDirect(rt, nullptr, props).release();
}
static SkSurface* NewRenderTargetDirect(GrRenderTarget* target) {
return NewRenderTargetDirect(target, NULL);

View File

@ -189,7 +189,8 @@ public:
*
* @return a draw context
*/
sk_sp<GrDrawContext> drawContext(sk_sp<GrRenderTarget> rt, const SkSurfaceProps* = nullptr);
sk_sp<GrDrawContext> drawContext(sk_sp<GrRenderTarget> rt, sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* = nullptr);
/**
* Create both a GrRenderTarget and a matching GrDrawContext to wrap it.
@ -199,6 +200,7 @@ public:
sk_sp<GrDrawContext> newDrawContext(SkBackingFit fit,
int width, int height,
GrPixelConfig config,
sk_sp<SkColorSpace> colorSpace,
int sampleCnt = 0,
GrSurfaceOrigin origin = kDefault_GrSurfaceOrigin,
const SkSurfaceProps* surfaceProps = nullptr,

View File

@ -272,6 +272,7 @@ public:
int numColorSamples() const { return fRenderTarget->numColorSamples(); }
bool isGammaCorrect() const { return fSurfaceProps.isGammaCorrect(); }
const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
SkColorSpace* getColorSpace() const { return fColorSpace.get(); }
bool wasAbandoned() const;
@ -288,7 +289,7 @@ public:
GrAuditTrail* auditTrail() { return fAuditTrail; }
protected:
GrDrawContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTarget>,
GrDrawContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTarget>, sk_sp<SkColorSpace>,
const SkSurfaceProps* surfaceProps, GrAuditTrail*, GrSingleOwner*);
GrDrawingManager* drawingManager() { return fDrawingManager; }
@ -362,6 +363,7 @@ private:
GrContext* fContext;
GrInstancedPipelineInfo fInstancedPipelineInfo;
sk_sp<SkColorSpace> fColorSpace;
SkSurfaceProps fSurfaceProps;
GrAuditTrail* fAuditTrail;

View File

@ -297,7 +297,9 @@ public:
return SkSurface::MakeRenderTarget(fCurContext, SkBudgeted::kNo, win->info(),
fMSAASampleCount, &props).release();
} else {
return SkSurface::MakeRenderTargetDirect(fCurRenderTarget, &props).release();
return SkSurface::MakeRenderTargetDirect(fCurRenderTarget,
sk_ref_sp(win->info().colorSpace()),
&props).release();
}
}
#endif

View File

@ -283,7 +283,8 @@ sk_sp<SkSpecialImage> SkImageFilter::DrawWithFP(GrContext* context,
sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kApprox,
bounds.width(), bounds.height(),
kRGBA_8888_GrPixelConfig));
kRGBA_8888_GrPixelConfig,
std::move(colorSpace)));
if (!drawContext) {
return nullptr;
}
@ -294,9 +295,9 @@ sk_sp<SkSpecialImage> SkImageFilter::DrawWithFP(GrContext* context,
GrFixedClip clip(dstIRect);
drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect);
// TODO: Get the colorSpace from the drawContext (once it has one)
return SkSpecialImage::MakeFromGpu(dstIRect, kNeedNewImageUniqueID_SpecialImage,
drawContext->asTexture(), std::move(colorSpace));
drawContext->asTexture(),
sk_ref_sp(drawContext->getColorSpace()));
}
#endif

View File

@ -391,7 +391,7 @@ public:
return SkSpecialSurface::MakeRenderTarget(fTexture->getContext(),
info.width(), info.height(),
config);
config, sk_ref_sp(info.colorSpace()));
}
sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override {

View File

@ -155,13 +155,15 @@ private:
sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context,
int width, int height,
GrPixelConfig config) {
GrPixelConfig config,
sk_sp<SkColorSpace> colorSpace) {
if (!context) {
return nullptr;
}
sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kApprox,
width, height, config));
width, height, config,
std::move(colorSpace)));
if (!drawContext) {
return nullptr;
}

View File

@ -57,7 +57,8 @@ public:
*/
static sk_sp<SkSpecialSurface> MakeRenderTarget(GrContext*,
int width, int height,
GrPixelConfig config);
GrPixelConfig config,
sk_sp<SkColorSpace> colorSpace);
#endif
/**

View File

@ -104,7 +104,7 @@ sk_sp<GrTexture> SkAlphaThresholdFilterImpl::createMaskTexture(GrContext* contex
sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kApprox,
bounds.width(), bounds.height(),
config));
config, nullptr));
if (!drawContext) {
return nullptr;
}

View File

@ -121,13 +121,14 @@ sk_sp<SkSpecialImage> SkBlurImageFilter::onFilterImage(SkSpecialImage* source,
inputBounds.offset(-inputOffset);
dstBounds.offset(-inputOffset);
sk_sp<GrDrawContext> drawContext(SkGpuBlurUtils::GaussianBlur(
context,
inputTexture.get(),
source->props().isGammaCorrect(),
dstBounds,
&inputBounds,
sigma.x(),
sigma.y()));
context,
inputTexture.get(),
sk_ref_sp(source->getColorSpace()),
source->props().isGammaCorrect(),
dstBounds,
&inputBounds,
sigma.x(),
sigma.y()));
if (!drawContext) {
return nullptr;
}

View File

@ -1248,7 +1248,7 @@ bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src,
static const bool kIsGammaCorrect = false;
bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle);
sk_sp<GrDrawContext> drawContext(SkGpuBlurUtils::GaussianBlur(context, src,
kIsGammaCorrect,
nullptr, kIsGammaCorrect,
clipRect, nullptr,
xformedSigma, xformedSigma));
if (!drawContext) {

View File

@ -335,9 +335,9 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou
SkMatrix matrix;
matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colorBounds.y()));
sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kApprox,
bounds.width(), bounds.height(),
kSkia8888_GrPixelConfig));
sk_sp<GrDrawContext> drawContext(
context->newDrawContext(SkBackingFit::kApprox, bounds.width(), bounds.height(),
kSkia8888_GrPixelConfig, sk_ref_sp(source->getColorSpace())));
if (!drawContext) {
return nullptr;
}
@ -346,11 +346,10 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou
offset->fX = bounds.left();
offset->fY = bounds.top();
// TODO: Get the colorSpace from the drawContext (once it has one)
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()),
kNeedNewImageUniqueID_SpecialImage,
drawContext->asTexture(),
sk_ref_sp(source->getColorSpace()));
sk_ref_sp(drawContext->getColorSpace()));
}
#endif

View File

@ -182,6 +182,7 @@ namespace SkGpuBlurUtils {
sk_sp<GrDrawContext> GaussianBlur(GrContext* context,
GrTexture* origSrc,
sk_sp<SkColorSpace> colorSpace,
bool gammaCorrect,
const SkIRect& dstBounds,
const SkIRect* srcBounds,
@ -230,7 +231,7 @@ sk_sp<GrDrawContext> GaussianBlur(GrContext* context,
SkSurfaceProps::kLegacyFontHost_InitType);
sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(SkBackingFit::kApprox,
width, height, config,
width, height, config, colorSpace,
0, kDefault_GrSurfaceOrigin,
&props));
if (!dstDrawContext) {
@ -251,7 +252,7 @@ sk_sp<GrDrawContext> GaussianBlur(GrContext* context,
}
sk_sp<GrDrawContext> tmpDrawContext(context->newDrawContext(SkBackingFit::kApprox,
width, height, config,
width, height, config, colorSpace,
0, kDefault_GrSurfaceOrigin,
&props));
if (!tmpDrawContext) {

View File

@ -23,6 +23,7 @@ namespace SkGpuBlurUtils {
* Note: one of sigmaX and sigmaY should be non-zero!
* @param context The GPU context
* @param srcTexture The source texture to be blurred.
* @param colorSpace Color space of the source (used for the drawContext result, too).
* @param gammaCorrect Should blur be gamma-correct (sRGB to linear, etc...)
* @param dstBounds The destination bounds, relative to the source texture.
* @param srcBounds The source bounds, relative to the source texture. If non-null,
@ -33,6 +34,7 @@ namespace SkGpuBlurUtils {
*/
sk_sp<GrDrawContext> GaussianBlur(GrContext* context,
GrTexture* srcTexture,
sk_sp<SkColorSpace> colorSpace,
bool gammaCorrect,
const SkIRect& dstBounds,
const SkIRect* srcBounds,

View File

@ -411,7 +411,8 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(SkSpecialIma
sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kApprox,
offsetBounds.width(),
offsetBounds.height(),
kRGBA_8888_GrPixelConfig));
kRGBA_8888_GrPixelConfig,
sk_ref_sp(source->getColorSpace())));
if (!drawContext) {
return nullptr;
}
@ -453,11 +454,10 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(SkSpecialIma
this->drawRect(drawContext.get(), inputTexture.get(), matrix, clip, bottomRight,
kBottomRight_BoundaryMode, pSrcBounds, offsetBounds);
// TODO: Get the colorSpace from the drawContext (once it has one)
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(offsetBounds.width(), offsetBounds.height()),
kNeedNewImageUniqueID_SpecialImage,
drawContext->asTexture(),
sk_ref_sp(source->getColorSpace()));
sk_ref_sp(drawContext->getColorSpace()));
}
#endif

View File

@ -474,6 +474,7 @@ static sk_sp<SkSpecialImage> apply_morphology(GrContext* context,
SkISize radius) {
sk_sp<GrTexture> srcTexture(input->asTextureRef(context));
SkASSERT(srcTexture);
sk_sp<SkColorSpace> colorSpace = sk_ref_sp(input->getColorSpace());
// setup new clip
const GrFixedClip clip(SkIRect::MakeWH(srcTexture->width(), srcTexture->height()));
@ -486,7 +487,8 @@ static sk_sp<SkSpecialImage> apply_morphology(GrContext* context,
if (radius.fWidth > 0) {
sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(SkBackingFit::kApprox,
rect.width(), rect.height(),
kSkia8888_GrPixelConfig));
kSkia8888_GrPixelConfig,
colorSpace));
if (!dstDrawContext) {
return nullptr;
}
@ -507,7 +509,8 @@ static sk_sp<SkSpecialImage> apply_morphology(GrContext* context,
if (radius.fHeight > 0) {
sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(SkBackingFit::kApprox,
rect.width(), rect.height(),
kSkia8888_GrPixelConfig));
kSkia8888_GrPixelConfig,
colorSpace));
if (!dstDrawContext) {
return nullptr;
}
@ -519,10 +522,9 @@ static sk_sp<SkSpecialImage> apply_morphology(GrContext* context,
srcTexture = dstDrawContext->asTexture();
}
// TODO: Get the colorSpace from the drawContext (once it has one)
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height()),
kNeedNewImageUniqueID_SpecialImage,
std::move(srcTexture), sk_ref_sp(input->getColorSpace()),
std::move(srcTexture), std::move(colorSpace),
&input->props());
}
#endif

View File

@ -243,7 +243,8 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter::filterImageGPU(SkSpecialImage* sour
sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kApprox,
bounds.width(), bounds.height(),
kSkia8888_GrPixelConfig));
kSkia8888_GrPixelConfig,
sk_ref_sp(source->getColorSpace())));
if (!drawContext) {
return nullptr;
}
@ -252,11 +253,10 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter::filterImageGPU(SkSpecialImage* sour
matrix.setTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
drawContext->drawRect(GrNoClip(), paint, matrix, SkRect::Make(bounds));
// TODO: Get the colorSpace from the drawContext (once it has one)
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()),
kNeedNewImageUniqueID_SpecialImage,
drawContext->asTexture(),
sk_ref_sp(source->getColorSpace()));
sk_ref_sp(drawContext->getColorSpace()));
}
#endif

View File

@ -113,6 +113,7 @@ static sk_sp<GrTexture> create_mask_GPU(GrContext* context,
maskRect.width(),
maskRect.height(),
config,
nullptr,
sampleCnt));
if (!drawContext) {
return nullptr;

View File

@ -474,7 +474,7 @@ sk_sp<GrTexture> GrClipMaskManager::CreateAlphaClipMask(GrContext* context,
sk_sp<GrDrawContext> dc(context->newDrawContext(SkBackingFit::kApprox,
clipSpaceIBounds.width(),
clipSpaceIBounds.height(),
config));
config, nullptr));
if (!dc) {
return nullptr;
}

View File

@ -357,7 +357,10 @@ bool GrContext::writeSurfacePixels(GrSurface* surface,
}
SkMatrix matrix;
matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top));
sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(renderTarget)));
// TODO: Need to decide the semantics of this function for color spaces. Do we support
// conversion from a passed-in color space? For now, specifying nullptr means that this
// path will do no conversion, so it will match the behavior of the non-draw path.
sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(renderTarget), nullptr));
if (!drawContext) {
return false;
}
@ -444,10 +447,14 @@ bool GrContext::readSurfacePixels(GrSurface* src,
tempDrawInfo.fTempSurfaceFit= SkBackingFit::kApprox;
}
}
// TODO: Need to decide the semantics of this function for color spaces. Do we support
// conversion to a passed-in color space? For now, specifying nullptr means that this
// path will do no conversion, so it will match the behavior of the non-draw path.
sk_sp<GrDrawContext> tempDC = this->newDrawContext(tempDrawInfo.fTempSurfaceFit,
tempDrawInfo.fTempSurfaceDesc.fWidth,
tempDrawInfo.fTempSurfaceDesc.fHeight,
tempDrawInfo.fTempSurfaceDesc.fConfig,
nullptr,
tempDrawInfo.fTempSurfaceDesc.fSampleCnt,
tempDrawInfo.fTempSurfaceDesc.fOrigin);
if (tempDC) {
@ -534,7 +541,8 @@ bool GrContext::applyGamma(GrRenderTarget* dst, GrTexture* src, SkScalar gamma){
SkSurfaceProps props(SkSurfaceProps::kGammaCorrect_Flag,
SkSurfaceProps::kLegacyFontHost_InitType);
sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst), &props));
// TODO: Supply color space?
sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst), nullptr, &props));
if (!drawContext) {
return false;
}
@ -596,7 +604,7 @@ bool GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe
src->flushWrites();
return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint);
}
sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst->asRenderTarget())));
sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst->asRenderTarget()), nullptr));
if (!drawContext) {
return false;
}
@ -636,14 +644,16 @@ int GrContext::getRecommendedSampleCount(GrPixelConfig config,
sk_sp<GrDrawContext> GrContext::drawContext(sk_sp<GrRenderTarget> rt,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps) {
ASSERT_SINGLE_OWNER
return fDrawingManager->drawContext(std::move(rt), surfaceProps);
return fDrawingManager->drawContext(std::move(rt), std::move(colorSpace), surfaceProps);
}
sk_sp<GrDrawContext> GrContext::newDrawContext(SkBackingFit fit,
int width, int height,
GrPixelConfig config,
sk_sp<SkColorSpace> colorSpace,
int sampleCnt,
GrSurfaceOrigin origin,
const SkSurfaceProps* surfaceProps,
@ -667,7 +677,7 @@ sk_sp<GrDrawContext> GrContext::newDrawContext(SkBackingFit fit,
}
sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTarget()),
surfaceProps));
std::move(colorSpace), surfaceProps));
if (!drawContext) {
return nullptr;
}

View File

@ -69,6 +69,7 @@ bool GrDrawContext::wasAbandoned() const {
GrDrawContext::GrDrawContext(GrContext* context,
GrDrawingManager* drawingMgr,
sk_sp<GrRenderTarget> rt,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps,
GrAuditTrail* auditTrail,
GrSingleOwner* singleOwner)
@ -77,6 +78,7 @@ GrDrawContext::GrDrawContext(GrContext* context,
, fDrawTarget(SkSafeRef(fRenderTarget->getLastDrawTarget()))
, fContext(context)
, fInstancedPipelineInfo(fRenderTarget.get())
, fColorSpace(std::move(colorSpace))
, fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps))
, fAuditTrail(auditTrail)
#ifdef SK_DEBUG

View File

@ -175,6 +175,7 @@ GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawP
}
sk_sp<GrDrawContext> GrDrawingManager::drawContext(sk_sp<GrRenderTarget> rt,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps) {
if (this->wasAbandoned()) {
return nullptr;
@ -191,13 +192,14 @@ sk_sp<GrDrawContext> GrDrawingManager::drawContext(sk_sp<GrRenderTarget> rt,
GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt.get());
if (sb) {
return sk_sp<GrDrawContext>(new GrPathRenderingDrawContext(
fContext, this, std::move(rt),
surfaceProps,
fContext, this, std::move(rt),
std::move(colorSpace), surfaceProps,
fContext->getAuditTrail(), fSingleOwner));
}
}
return sk_sp<GrDrawContext>(new GrDrawContext(fContext, this, std::move(rt), surfaceProps,
return sk_sp<GrDrawContext>(new GrDrawContext(fContext, this, std::move(rt),
std::move(colorSpace), surfaceProps,
fContext->getAuditTrail(),
fSingleOwner));
}

View File

@ -31,7 +31,8 @@ public:
bool wasAbandoned() const { return fAbandoned; }
void freeGpuResources();
sk_sp<GrDrawContext> drawContext(sk_sp<GrRenderTarget> rt, const SkSurfaceProps*);
sk_sp<GrDrawContext> drawContext(sk_sp<GrRenderTarget> rt, sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps*);
// The caller automatically gets a ref on the returned drawTarget. It must
// be balanced by an unref call.

View File

@ -27,9 +27,9 @@ public:
SkDrawFilter*, const SkIRect& clipBounds) override;
protected:
GrPathRenderingDrawContext(GrContext* ctx, GrDrawingManager* mgr, sk_sp<GrRenderTarget> rt,
const SkSurfaceProps* surfaceProps, GrAuditTrail* at,
GrSingleOwner* so)
: INHERITED(ctx, mgr, std::move(rt), surfaceProps, at, so) {}
sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* surfaceProps,
GrAuditTrail* at, GrSingleOwner* so)
: INHERITED(ctx, mgr, std::move(rt), std::move(colorSpace), surfaceProps, at, so) {}
private:
SkAutoTDelete<GrStencilAndCoverTextContext> fStencilAndCoverTextContext;

View File

@ -29,7 +29,7 @@ void GrRenderTarget::discard() {
return;
}
sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(this)));
sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(this), nullptr));
if (!drawContext) {
return;
}

View File

@ -61,7 +61,7 @@ static GrTexture* copy_on_gpu(GrTexture* inputTexture, const SkIRect* subset,
}
sk_sp<GrDrawContext> copyDC = context->newDrawContext(SkBackingFit::kExact, copyParams.fWidth,
copyParams.fHeight, config);
copyParams.fHeight, config, nullptr);
if (!copyDC) {
return nullptr;
}

View File

@ -71,14 +71,14 @@ bool GrTextureToYUVPlanes(GrTexture* texture, const SkISize sizes[3], void* cons
if (sizes[0] == sizes[1] && sizes[1] == sizes[2]) {
yuvDrawContext = context->newDrawContext(SkBackingFit::kApprox,
sizes[0].fWidth, sizes[0].fHeight,
kRGBA_8888_GrPixelConfig);
kRGBA_8888_GrPixelConfig, nullptr);
if (!yuvDrawContext) {
return false;
}
} else {
yDrawContext = context->newDrawContext(SkBackingFit::kApprox,
sizes[0].fWidth, sizes[0].fHeight,
singleChannelPixelConfig);
singleChannelPixelConfig, nullptr);
if (!yDrawContext) {
return false;
}
@ -86,17 +86,17 @@ bool GrTextureToYUVPlanes(GrTexture* texture, const SkISize sizes[3], void* cons
// TODO: Add support for GL_RG when available.
uvDrawContext = context->newDrawContext(SkBackingFit::kApprox,
sizes[1].fWidth, sizes[1].fHeight,
kRGBA_8888_GrPixelConfig);
kRGBA_8888_GrPixelConfig, nullptr);
if (!uvDrawContext) {
return false;
}
} else {
uDrawContext = context->newDrawContext(SkBackingFit::kApprox,
sizes[1].fWidth, sizes[1].fHeight,
singleChannelPixelConfig);
singleChannelPixelConfig, nullptr);
vDrawContext = context->newDrawContext(SkBackingFit::kApprox,
sizes[2].fWidth, sizes[2].fHeight,
singleChannelPixelConfig);
singleChannelPixelConfig, nullptr);
if (!uDrawContext || !vDrawContext) {
return false;
}

View File

@ -113,9 +113,11 @@ sk_sp<GrTexture> GrYUVProvider::refAsTexture(GrContext* ctx,
}
}
// We never want to perform color-space conversion during the decode
sk_sp<GrDrawContext> drawContext(ctx->newDrawContext(SkBackingFit::kExact,
desc.fWidth, desc.fHeight,
desc.fConfig, desc.fSampleCnt));
desc.fConfig, nullptr,
desc.fSampleCnt));
if (!drawContext) {
return nullptr;
}

View File

@ -126,8 +126,8 @@ bool SkGpuDevice::CheckAlphaTypeAndGetFlags(
return true;
}
sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTarget> rt, const SkSurfaceProps* props,
InitContents init) {
sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTarget> rt, sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props, InitContents init) {
if (!rt || rt->wasDestroyed() || !rt->getContext()) {
return nullptr;
}
@ -141,7 +141,8 @@ sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTarget> rt, const SkSurfacePr
GrContext* context = rt->getContext();
sk_sp<GrDrawContext> drawContext(context->drawContext(std::move(rt), props));
sk_sp<GrDrawContext> drawContext(context->drawContext(std::move(rt), std::move(colorSpace),
props));
return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), width, height, flags));
}
@ -223,7 +224,7 @@ sk_sp<GrDrawContext> SkGpuDevice::CreateDrawContext(GrContext* context,
return context->newDrawContext(SkBackingFit::kExact, // Why exact?
origInfo.width(), origInfo.height(),
config, sampleCount,
config, sk_ref_sp(cs), sampleCount,
kDefault_GrSurfaceOrigin, surfaceProps, budgeted);
}
@ -1842,6 +1843,7 @@ SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint
sk_sp<GrDrawContext> dc(fContext->newDrawContext(fit,
cinfo.fInfo.width(), cinfo.fInfo.height(),
fDrawContext->config(),
sk_ref_sp(fDrawContext->getColorSpace()),
fDrawContext->desc().fSampleCnt,
kDefault_GrSurfaceOrigin,
&props));

View File

@ -42,7 +42,8 @@ public:
* MakeFromBackendTexture, MakeFromBackendRenderTarget,
* and MakeFromBackendTextureAsRenderTarget. Only the first is worrisome.
*/
static sk_sp<SkGpuDevice> Make(sk_sp<GrRenderTarget> target,
static sk_sp<SkGpuDevice> Make(sk_sp<GrRenderTarget> target,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps*,
InitContents);

View File

@ -174,9 +174,9 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
}
sk_sp<GrDrawContext> readDC(context->newDrawContext(SkBackingFit::kExact, kSize, kSize,
kConfig));
kConfig, nullptr));
sk_sp<GrDrawContext> tempDC(context->newDrawContext(SkBackingFit::kExact, kSize, kSize,
kConfig));
kConfig, nullptr));
if (!readDC || !tempDC) {
return;
}

View File

@ -245,6 +245,7 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac
sk_sp<GrDrawContext> drawContext(ctx->newDrawContext(SkBackingFit::kExact,
width, height,
kRGBA_8888_GrPixelConfig,
std::move(imageColorSpace),
0,
origin));
if (!drawContext) {
@ -262,7 +263,7 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac
ctx->flushSurfaceWrites(drawContext->accessRenderTarget());
return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID,
kOpaque_SkAlphaType, drawContext->asTexture().get(),
std::move(imageColorSpace), budgeted);
sk_ref_sp(drawContext->getColorSpace()), budgeted);
}
sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace,

View File

@ -223,7 +223,8 @@ void SkSurface::prepareForExternalIO() {
#if !SK_SUPPORT_GPU
sk_sp<SkSurface> SkSurface::MakeRenderTargetDirect(GrRenderTarget*, const SkSurfaceProps*) {
sk_sp<SkSurface> SkSurface::MakeRenderTargetDirect(GrRenderTarget*, sk_sp<SkColorSpace>,
const SkSurfaceProps*) {
return nullptr;
}
@ -233,18 +234,19 @@ sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext*, SkBudgeted, const SkIma
}
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTextureDesc&,
const SkSurfaceProps*) {
sk_sp<SkColorSpace>, const SkSurfaceProps*) {
return nullptr;
}
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext*,
const GrBackendRenderTargetDesc&,
sk_sp<SkColorSpace>,
const SkSurfaceProps*) {
return nullptr;
}
sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext*, const GrBackendTextureDesc&,
const SkSurfaceProps*) {
sk_sp<SkColorSpace>, const SkSurfaceProps*) {
return nullptr;
}

View File

@ -132,9 +132,11 @@ void SkSurface_Gpu::onPrepareForExternalIO() {
///////////////////////////////////////////////////////////////////////////////
sk_sp<SkSurface> SkSurface::MakeRenderTargetDirect(GrRenderTarget* target,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props) {
sk_sp<SkGpuDevice> device(
SkGpuDevice::Make(sk_ref_sp(target), props, SkGpuDevice::kUninit_InitContents));
SkGpuDevice::Make(sk_ref_sp(target), std::move(colorSpace), props,
SkGpuDevice::kUninit_InitContents));
if (!device) {
return nullptr;
}
@ -154,6 +156,7 @@ sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* ctx, SkBudgeted budgeted
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context,
const GrBackendTextureDesc& desc,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props) {
if (nullptr == context) {
return nullptr;
@ -166,7 +169,8 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context,
if (!surface) {
return nullptr;
}
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(sk_ref_sp(surface->asRenderTarget()), props,
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(sk_ref_sp(surface->asRenderTarget()),
std::move(colorSpace), props,
SkGpuDevice::kUninit_InitContents));
if (!device) {
return nullptr;
@ -176,6 +180,7 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context,
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
const GrBackendRenderTargetDesc& desc,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props) {
if (!context) {
return nullptr;
@ -184,7 +189,7 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
if (!rt) {
return nullptr;
}
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(rt), props,
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(rt), std::move(colorSpace), props,
SkGpuDevice::kUninit_InitContents));
if (!device) {
return nullptr;
@ -194,6 +199,7 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context,
const GrBackendTextureDesc& desc,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props) {
if (!context) {
return nullptr;
@ -202,7 +208,7 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* cont
if (!rt) {
return nullptr;
}
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(rt), props,
sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(rt), std::move(colorSpace), props,
SkGpuDevice::kUninit_InitContents));
if (!device) {
return nullptr;

View File

@ -45,7 +45,7 @@ static bool reset_dc(sk_sp<GrDrawContext>* dc, GrContext* context, int w, int h)
}
context->freeGpuResources();
*dc = context->newDrawContext(SkBackingFit::kExact, w, h, kRGBA_8888_GrPixelConfig);
*dc = context->newDrawContext(SkBackingFit::kExact, w, h, kRGBA_8888_GrPixelConfig, nullptr);
SkASSERT((*dc)->accessRenderTarget()->getUniqueID() != oldID);

View File

@ -66,6 +66,7 @@ DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(AADistanceFieldPathRenderer, reporter, ctxInfo)
sk_sp<GrDrawContext> drawContext(ctxInfo.grContext()->newDrawContext(SkBackingFit::kApprox,
800, 800,
kSkia8888_GrPixelConfig,
nullptr,
0,
kTopLeft_GrSurfaceOrigin));
if (!drawContext) {

View File

@ -158,6 +158,7 @@ static sk_sp<GrDrawContext> random_draw_context(GrContext* context,
kRenderTargetWidth,
kRenderTargetHeight,
kRGBA_8888_GrPixelConfig,
nullptr,
sampleCnt,
origin));
return drawContext;
@ -345,7 +346,8 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) {
sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kExact,
kRenderTargetWidth,
kRenderTargetHeight,
kRGBA_8888_GrPixelConfig));
kRGBA_8888_GrPixelConfig,
nullptr));
if (!drawContext) {
SkDebugf("Could not allocate a drawContext");
return false;

View File

@ -367,7 +367,7 @@ static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context,
if (context) {
return SkSpecialSurface::MakeRenderTarget(context,
widthHeight, widthHeight,
kSkia8888_GrPixelConfig);
kSkia8888_GrPixelConfig, nullptr);
} else
#endif
{

View File

@ -105,7 +105,8 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kApprox,
1, 1, kRGBA_8888_GrPixelConfig));
1, 1, kRGBA_8888_GrPixelConfig,
nullptr));
if (!drawContext) {
ERRORF(reporter, "Could not create draw context.");
return;

View File

@ -397,7 +397,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Gpu, reporter, ctxInfo) {
desc.fOrigin = origin;
SkAutoTUnref<GrTexture> surfaceTexture(
ctxInfo.grContext()->textureProvider()->createTexture(desc, SkBudgeted::kNo));
auto surface(SkSurface::MakeRenderTargetDirect(surfaceTexture->asRenderTarget()));
auto surface(SkSurface::MakeRenderTargetDirect(surfaceTexture->asRenderTarget(), nullptr));
desc.fFlags = kNone_GrSurfaceFlags;
test_readpixels(reporter, surface, kLast_BitmapInit);
}

View File

@ -93,7 +93,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
// Now try writing on the single channel texture (if we could create as a RT).
if (texture->asRenderTarget()) {
sk_sp<SkSurface> surf(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget()));
sk_sp<SkSurface> surf(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget(),
nullptr));
SkCanvas* canvas = surf->getCanvas();
SkPaint paint;

View File

@ -90,7 +90,8 @@ static void test_clear(skiatest::Reporter* reporter, GrContext* context,
GrTexture* rectangleTexture) {
if (rectangleTexture->asRenderTarget()) {
sk_sp<GrDrawContext> dc(
context->drawContext(sk_ref_sp(rectangleTexture->asRenderTarget())));
context->drawContext(sk_ref_sp(rectangleTexture->asRenderTarget()),
nullptr));
if (!dc) {
ERRORF(reporter, "Could not get GrDrawContext for rectangle texture.");
return;

View File

@ -123,12 +123,17 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SRGBMipMaps, reporter, ctxInfo) {
SkSurfaceProps l32Props(SkSurfaceProps::kLegacyFontHost_InitType);
SkSurfaceProps s32Props(SkSurfaceProps::kGammaCorrect_Flag,
SkSurfaceProps::kLegacyFontHost_InitType);
sk_sp<SkColorSpace> srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
sk_sp<GrDrawContext> l32DrawContext = context->newDrawContext(SkBackingFit::kExact, rtS, rtS,
kSkia8888_GrPixelConfig, 0,
kSkia8888_GrPixelConfig,
nullptr,
0,
kDefault_GrSurfaceOrigin,
&l32Props);
sk_sp<GrDrawContext> s32DrawContext = context->newDrawContext(SkBackingFit::kExact, rtS, rtS,
kSkiaGamma8888_GrPixelConfig, 0,
kSkiaGamma8888_GrPixelConfig,
std::move(srgbColorSpace),
0,
kDefault_GrSurfaceOrigin,
&s32Props);

View File

@ -81,7 +81,8 @@ DEF_TEST(SpecialSurface_Raster2, reporter) {
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, ctxInfo) {
sk_sp<SkSpecialSurface> surf(SkSpecialSurface::MakeRenderTarget(ctxInfo.grContext(),
kSmallerSize, kSmallerSize,
kSkia8888_GrPixelConfig));
kSkia8888_GrPixelConfig,
nullptr));
test_surface(surf, reporter, 0);
}

View File

@ -337,7 +337,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, ctxInfo) {
desc.fTextureHandle = textureObject;
GrTexture* texture = context->textureProvider()->wrapBackendTexture(desc);
{
auto surface(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget()));
auto surface(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget(), nullptr));
test_unique_image_snap(reporter, surface.get(), true, imageBackingStore,
surfaceBackingStore);
}

View File

@ -257,6 +257,7 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(TessellatingPathRendererTests, reporter, ctxInfo) {
sk_sp<GrDrawContext> drawContext(ctxInfo.grContext()->newDrawContext(SkBackingFit::kApprox,
800, 800,
kSkia8888_GrPixelConfig,
nullptr,
0,
kTopLeft_GrSurfaceOrigin));
if (!drawContext) {

View File

@ -416,7 +416,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WritePixels_Gpu, reporter, ctxInfo) {
desc.fOrigin = origin;
SkAutoTUnref<GrTexture> texture(
ctxInfo.grContext()->textureProvider()->createTexture(desc, SkBudgeted::kNo));
auto surface(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget()));
auto surface(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget(), nullptr));
test_write_pixels(reporter, surface.get());
}
}