Add SkColorSpace to GrDrawContext
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2164363002
Review-Url: https://codereview.chromium.org/2164363002
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index 3ad225b..f6d6fc2 100644
--- a/src/gpu/GrBlurUtils.cpp
+++ b/src/gpu/GrBlurUtils.cpp
@@ -113,6 +113,7 @@
maskRect.width(),
maskRect.height(),
config,
+ nullptr,
sampleCnt));
if (!drawContext) {
return nullptr;
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index 77d5ea1..6e2a303 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -474,7 +474,7 @@
sk_sp<GrDrawContext> dc(context->newDrawContext(SkBackingFit::kApprox,
clipSpaceIBounds.width(),
clipSpaceIBounds.height(),
- config));
+ config, nullptr));
if (!dc) {
return nullptr;
}
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 4cb90c6..6bb3ea6 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -357,7 +357,10 @@
}
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 @@
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 @@
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 @@
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 @@
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> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTarget()),
- surfaceProps));
+ std::move(colorSpace), surfaceProps));
if (!drawContext) {
return nullptr;
}
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index 52f7fc0..9a647c0 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -69,6 +69,7 @@
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 @@
, fDrawTarget(SkSafeRef(fRenderTarget->getLastDrawTarget()))
, fContext(context)
, fInstancedPipelineInfo(fRenderTarget.get())
+ , fColorSpace(std::move(colorSpace))
, fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps))
, fAuditTrail(auditTrail)
#ifdef SK_DEBUG
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index 75ee0db..5dc07dd 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -175,6 +175,7 @@
}
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 @@
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));
}
diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h
index fa644b5..d777242 100644
--- a/src/gpu/GrDrawingManager.h
+++ b/src/gpu/GrDrawingManager.h
@@ -31,7 +31,8 @@
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.
diff --git a/src/gpu/GrPathRenderingDrawContext.h b/src/gpu/GrPathRenderingDrawContext.h
index 5d1893c..5c1a968 100644
--- a/src/gpu/GrPathRenderingDrawContext.h
+++ b/src/gpu/GrPathRenderingDrawContext.h
@@ -27,9 +27,9 @@
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;
diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp
index 6a9d489..9eba180 100644
--- a/src/gpu/GrRenderTarget.cpp
+++ b/src/gpu/GrRenderTarget.cpp
@@ -29,7 +29,7 @@
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;
}
diff --git a/src/gpu/GrTextureParamsAdjuster.cpp b/src/gpu/GrTextureParamsAdjuster.cpp
index fe81bea..e077fee 100644
--- a/src/gpu/GrTextureParamsAdjuster.cpp
+++ b/src/gpu/GrTextureParamsAdjuster.cpp
@@ -61,7 +61,7 @@
}
sk_sp<GrDrawContext> copyDC = context->newDrawContext(SkBackingFit::kExact, copyParams.fWidth,
- copyParams.fHeight, config);
+ copyParams.fHeight, config, nullptr);
if (!copyDC) {
return nullptr;
}
diff --git a/src/gpu/GrTextureToYUVPlanes.cpp b/src/gpu/GrTextureToYUVPlanes.cpp
index da98547..25a79e4 100644
--- a/src/gpu/GrTextureToYUVPlanes.cpp
+++ b/src/gpu/GrTextureToYUVPlanes.cpp
@@ -71,14 +71,14 @@
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 @@
// 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;
}
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp
index c35f57a..e9b2ef5 100644
--- a/src/gpu/GrYUVProvider.cpp
+++ b/src/gpu/GrYUVProvider.cpp
@@ -113,9 +113,11 @@
}
}
+ // 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;
}
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 2b4c084..20e5afe 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -126,8 +126,8 @@
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 @@
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 @@
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 @@
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));
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index d341b39..8111759 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -42,7 +42,8 @@
* 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);
diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp
index 5294492..f41e154 100644
--- a/src/gpu/effects/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/GrConfigConversionEffect.cpp
@@ -174,9 +174,9 @@
}
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;
}