Migrate GrSurfaceContext readPixels to take direct context
After this lands we'll proceed up the stack and add the direct
context requirement to the public API and SkImage.
Bug: skia:104662
Change-Id: I4b2d779a7fcd65eec68e631757821ac8e136ddba
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309044
Commit-Queue: Adlai Holler <adlai@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp
index 5e51da4..8a0a0d4 100644
--- a/src/gpu/GrSurfaceContext.cpp
+++ b/src/gpu/GrSurfaceContext.cpp
@@ -132,14 +132,14 @@
}
#endif
-bool GrSurfaceContext::readPixels(const GrImageInfo& origDstInfo, void* dst, size_t rowBytes,
- SkIPoint pt, GrDirectContext* direct) {
+bool GrSurfaceContext::readPixels(GrDirectContext* dContext, const GrImageInfo& origDstInfo,
+ void* dst, size_t rowBytes, SkIPoint pt) {
ASSERT_SINGLE_OWNER
RETURN_FALSE_IF_ABANDONED
SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::readPixels");
- if (!direct && !(direct = fContext->asDirectContext())) {
+ if (!dContext) {
return false;
}
@@ -165,7 +165,7 @@
}
// MDB TODO: delay this instantiation until later in the method
- if (!srcProxy->instantiate(direct->priv().resourceProvider())) {
+ if (!srcProxy->instantiate(dContext->priv().resourceProvider())) {
return false;
}
@@ -183,7 +183,7 @@
needColorConversion = flags.linearize || flags.gamut_transform || flags.encode,
premul = flags.premul;
- const GrCaps* caps = direct->priv().caps();
+ const GrCaps* caps = dContext->priv().caps();
bool srcIsCompressed = caps->isFormatCompressed(srcSurface->backendFormat());
// This is the getImageData equivalent to the canvas2D putImageData fast path. We probably don't
// care so much about getImageData performance. However, in order to ensure putImageData/
@@ -200,7 +200,7 @@
(srcColorType == GrColorType::kRGBA_8888 ||
srcColorType == GrColorType::kBGRA_8888) &&
defaultRGBAFormat.isValid() &&
- direct->priv().validPMUPMConversionExists();
+ dContext->priv().validPMUPMConversionExists();
auto readFlag = caps->surfaceSupportsReadPixels(srcSurface);
if (readFlag == GrCaps::SurfaceReadPixelsSupport::kUnsupported) {
@@ -213,7 +213,7 @@
sk_sp<SkColorSpace> cs = canvas2DFastPath ? nullptr : this->colorInfo().refColorSpace();
auto tempCtx = GrRenderTargetContext::Make(
- direct, colorType, std::move(cs), SkBackingFit::kApprox, dstInfo.dimensions(),
+ dContext, colorType, std::move(cs), SkBackingFit::kApprox, dstInfo.dimensions(),
1, GrMipmapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
if (!tempCtx) {
return false;
@@ -221,7 +221,7 @@
std::unique_ptr<GrFragmentProcessor> fp;
if (canvas2DFastPath) {
- fp = direct->priv().createPMToUPMEffect(
+ fp = dContext->priv().createPMToUPMEffect(
GrTextureEffect::Make(this->readSurfaceView(), this->colorInfo().alphaType()));
if (dstInfo.colorType() == GrColorType::kBGRA_8888) {
fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), GrSwizzle::BGRA());
@@ -246,7 +246,7 @@
SkRect::MakeWH(dstInfo.width(), dstInfo.height()),
SkRect::MakeXYWH(pt.fX, pt.fY, dstInfo.width(), dstInfo.height()));
- return tempCtx->readPixels(dstInfo, dst, rowBytes, {0, 0}, direct);
+ return tempCtx->readPixels(dContext, dstInfo, dst, rowBytes, {0, 0});
}
bool flip = this->origin() == kBottomLeft_GrSurfaceOrigin;
@@ -276,11 +276,11 @@
pt.fY = flip ? srcSurface->height() - pt.fY - dstInfo.height() : pt.fY;
}
- direct->priv().flushSurface(srcProxy);
- direct->submit();
- if (!direct->priv().getGpu()->readPixels(srcSurface, pt.fX, pt.fY, dstInfo.width(),
- dstInfo.height(), this->colorInfo().colorType(),
- supportedRead.fColorType, readDst, readRB)) {
+ dContext->priv().flushSurface(srcProxy);
+ dContext->submit();
+ if (!dContext->priv().getGpu()->readPixels(srcSurface, pt.fX, pt.fY, dstInfo.width(),
+ dstInfo.height(), this->colorInfo().colorType(),
+ supportedRead.fColorType, readDst, readRB)) {
return false;
}
@@ -290,14 +290,14 @@
return true;
}
-bool GrSurfaceContext::writePixels(const GrImageInfo& origSrcInfo, const void* src, size_t rowBytes,
- SkIPoint pt, GrDirectContext* direct) {
+bool GrSurfaceContext::writePixels(GrDirectContext* dContext, const GrImageInfo& origSrcInfo,
+ const void* src, size_t rowBytes, SkIPoint pt) {
ASSERT_SINGLE_OWNER
RETURN_FALSE_IF_ABANDONED
SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::writePixels");
- if (!direct && !(direct = fContext->asDirectContext())) {
+ if (!dContext) {
return false;
}
@@ -326,7 +326,7 @@
return false;
}
- if (!dstProxy->instantiate(direct->priv().resourceProvider())) {
+ if (!dstProxy->instantiate(dContext->priv().resourceProvider())) {
return false;
}
@@ -344,7 +344,7 @@
needColorConversion = flags.linearize || flags.gamut_transform || flags.encode,
premul = flags.premul;
- const GrCaps* caps = direct->priv().caps();
+ const GrCaps* caps = dContext->priv().caps();
auto rgbaDefaultFormat = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
GrRenderable::kNo);
@@ -359,7 +359,7 @@
(dstColorType == GrColorType::kRGBA_8888 ||
dstColorType == GrColorType::kBGRA_8888) &&
rgbaDefaultFormat.isValid() &&
- direct->priv().validPMUPMConversionExists();
+ dContext->priv().validPMUPMConversionExists();
if (!caps->surfaceSupportsWritePixels(dstSurface) || canvas2DFastPath) {
GrColorType colorType;
@@ -388,14 +388,14 @@
// targets we will use top left and otherwise we will make the origins match.
GrSurfaceOrigin tempOrigin =
this->asRenderTargetContext() ? kTopLeft_GrSurfaceOrigin : this->origin();
- auto tempProxy = direct->priv().proxyProvider()->createProxy(
+ auto tempProxy = dContext->priv().proxyProvider()->createProxy(
format, srcInfo.dimensions(), GrRenderable::kNo, 1, GrMipmapped::kNo,
SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
if (!tempProxy) {
return false;
}
GrSurfaceProxyView tempView(tempProxy, tempOrigin, tempReadSwizzle);
- GrSurfaceContext tempCtx(direct, tempView, colorType, alphaType,
+ GrSurfaceContext tempCtx(dContext, tempView, colorType, alphaType,
this->colorInfo().refColorSpace());
// In the fast path we always write the srcData to the temp context as though it were RGBA.
@@ -405,14 +405,14 @@
if (canvas2DFastPath) {
srcInfo = srcInfo.makeColorType(GrColorType::kRGBA_8888);
}
- if (!tempCtx.writePixels(srcInfo, src, rowBytes, {0, 0}, direct)) {
+ if (!tempCtx.writePixels(dContext, srcInfo, src, rowBytes, {0, 0})) {
return false;
}
if (this->asRenderTargetContext()) {
std::unique_ptr<GrFragmentProcessor> fp;
if (canvas2DFastPath) {
- fp = direct->priv().createUPMToPMEffect(
+ fp = dContext->priv().createUPMToPMEffect(
GrTextureEffect::Make(std::move(tempView), alphaType));
// Important: check the original src color type here!
if (origSrcInfo.colorType() == GrColorType::kBGRA_8888) {
@@ -471,42 +471,41 @@
// giving the drawing manager the chance of skipping the flush (i.e., by passing in the
// destination proxy)
// TODO: should this policy decision just be moved into the drawing manager?
- direct->priv().flushSurface(caps->preferVRAMUseOverFlushes() ? dstProxy : nullptr);
+ dContext->priv().flushSurface(caps->preferVRAMUseOverFlushes() ? dstProxy : nullptr);
- return direct->priv().getGpu()->writePixels(dstSurface, pt.fX, pt.fY, srcInfo.width(),
- srcInfo.height(), this->colorInfo().colorType(),
- srcColorType, src, rowBytes);
+ return dContext->priv().getGpu()->writePixels(dstSurface, pt.fX, pt.fY, srcInfo.width(),
+ srcInfo.height(), this->colorInfo().colorType(),
+ srcColorType, src, rowBytes);
}
-void GrSurfaceContext::asyncRescaleAndReadPixels(const SkImageInfo& info,
+void GrSurfaceContext::asyncRescaleAndReadPixels(GrDirectContext* dContext,
+ const SkImageInfo& info,
const SkIRect& srcRect,
RescaleGamma rescaleGamma,
SkFilterQuality rescaleQuality,
ReadPixelsCallback callback,
- ReadPixelsContext context) {
- auto direct = fContext->asDirectContext();
-
+ ReadPixelsContext callbackContext) {
// We implement this by rendering and we don't currently support rendering kUnpremul.
if (info.alphaType() == kUnpremul_SkAlphaType) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
- if (!direct) {
- callback(context, nullptr);
+ if (!dContext) {
+ callback(callbackContext, nullptr);
return;
}
auto rt = this->asRenderTargetProxy();
if (rt && rt->wrapsVkSecondaryCB()) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
if (rt && rt->framebufferOnly()) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
auto dstCT = SkColorTypeToGrColorType(info.colorType());
if (dstCT == GrColorType::kUnknown) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
bool needsRescale = srcRect.width() != info.width() || srcRect.height() != info.height();
@@ -521,7 +520,7 @@
backendFormatOfFinalContext, dstCT);
// Fail if we can't read from the source surface's color type.
if (readInfo.fColorType == GrColorType::kUnknown) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
// Fail if read color type does not have all of dstCT's color channels and those missing color
@@ -530,7 +529,7 @@
uint32_t legalReadChannels = GrColorTypeChannelFlags(readInfo.fColorType);
uint32_t srcChannels = GrColorTypeChannelFlags(this->colorInfo().colorType());
if ((~legalReadChannels & dstChannels) & srcChannels) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
@@ -541,7 +540,7 @@
tempRTC = this->rescale(info, kTopLeft_GrSurfaceOrigin, srcRect, rescaleGamma,
rescaleQuality);
if (!tempRTC) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
SkASSERT(SkColorSpace::Equals(tempRTC->colorInfo().colorSpace(), info.colorSpace()));
@@ -562,18 +561,18 @@
GrSurfaceProxyView::Copy(fContext, texProxyView, GrMipmapped::kNo, srcRect,
SkBackingFit::kApprox, SkBudgeted::kNo);
if (!texProxyView) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
SkASSERT(texProxyView.asTextureProxy());
srcRectToDraw = SkRect::MakeWH(srcRect.width(), srcRect.height());
}
- tempRTC = GrRenderTargetContext::Make(direct, this->colorInfo().colorType(),
+ tempRTC = GrRenderTargetContext::Make(dContext, this->colorInfo().colorType(),
info.refColorSpace(), SkBackingFit::kApprox,
srcRect.size(), 1, GrMipmapped::kNo,
GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
if (!tempRTC) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
tempRTC->drawTexture(nullptr,
@@ -594,8 +593,8 @@
}
}
auto rtc = tempRTC ? tempRTC.get() : this;
- return rtc->asyncReadPixels(SkIRect::MakeXYWH(x, y, info.width(), info.height()),
- info.colorType(), callback, context);
+ return rtc->asyncReadPixels(dContext, SkIRect::MakeXYWH(x, y, info.width(), info.height()),
+ info.colorType(), callback, callbackContext);
}
class GrSurfaceContext::AsyncReadResult : public SkImage::AsyncReadResult {
@@ -664,21 +663,20 @@
uint32_t fInboxID;
};
-void GrSurfaceContext::asyncReadPixels(const SkIRect& rect,
+void GrSurfaceContext::asyncReadPixels(GrDirectContext* dContext,
+ const SkIRect& rect,
SkColorType colorType,
ReadPixelsCallback callback,
- ReadPixelsContext context) {
+ ReadPixelsContext callbackContext) {
SkASSERT(rect.fLeft >= 0 && rect.fRight <= this->width());
SkASSERT(rect.fTop >= 0 && rect.fBottom <= this->height());
- if (this->asSurfaceProxy()->isProtected() == GrProtected::kYes) {
- callback(context, nullptr);
+ if (!dContext || this->asSurfaceProxy()->isProtected() == GrProtected::kYes) {
+ callback(callbackContext, nullptr);
return;
}
- auto directContext = fContext->asDirectContext();
- SkASSERT(directContext);
- auto mappedBufferManager = directContext->priv().clientMappedBufferManager();
+ auto mappedBufferManager = dContext->priv().clientMappedBufferManager();
auto transferResult = this->transferPixels(SkColorTypeToGrColorType(colorType), rect);
@@ -690,11 +688,12 @@
SkPixmap pm(ii, data.get(), ii.minRowBytes());
result->addCpuPlane(std::move(data), pm.rowBytes());
- if (!this->readPixels(ii, pm.writable_addr(), pm.rowBytes(), {rect.fLeft, rect.fTop})) {
- callback(context, nullptr);
+ SkIPoint pt{rect.fLeft, rect.fTop};
+ if (!this->readPixels(dContext, ii, pm.writable_addr(), pm.rowBytes(), pt)) {
+ callback(callbackContext, nullptr);
return;
}
- callback(context, std::move(result));
+ callback(callbackContext, std::move(result));
return;
}
@@ -710,7 +709,7 @@
// explicit flush from the caller. We'd have to have a way to defer attaching the finish
// callback to GrGpu until after the next flush that flushes our op list, though.
auto* finishContext = new FinishContext{callback,
- context,
+ callbackContext,
rect.size(),
colorType,
mappedBufferManager,
@@ -732,35 +731,35 @@
this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo, nullptr);
}
-void GrSurfaceContext::asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
+void GrSurfaceContext::asyncRescaleAndReadPixelsYUV420(GrDirectContext* dContext,
+ SkYUVColorSpace yuvColorSpace,
sk_sp<SkColorSpace> dstColorSpace,
const SkIRect& srcRect,
SkISize dstSize,
RescaleGamma rescaleGamma,
SkFilterQuality rescaleQuality,
ReadPixelsCallback callback,
- ReadPixelsContext context) {
+ ReadPixelsContext callbackContext) {
SkASSERT(srcRect.fLeft >= 0 && srcRect.fRight <= this->width());
SkASSERT(srcRect.fTop >= 0 && srcRect.fBottom <= this->height());
SkASSERT(!dstSize.isZero());
SkASSERT((dstSize.width() % 2 == 0) && (dstSize.height() % 2 == 0));
- auto direct = fContext->asDirectContext();
- if (!direct) {
- callback(context, nullptr);
+ if (!dContext) {
+ callback(callbackContext, nullptr);
return;
}
auto rt = this->asRenderTargetProxy();
if (rt && rt->wrapsVkSecondaryCB()) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
if (rt && rt->framebufferOnly()) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
if (this->asSurfaceProxy()->isProtected() == GrProtected::kYes) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
int x = srcRect.fLeft;
@@ -775,7 +774,7 @@
auto tempRTC = this->rescale(info, kTopLeft_GrSurfaceOrigin, srcRect, rescaleGamma,
rescaleQuality);
if (!tempRTC) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
SkASSERT(SkColorSpace::Equals(tempRTC->colorInfo().colorSpace(), info.colorSpace()));
@@ -789,7 +788,7 @@
srcRect, SkBackingFit::kApprox, SkBudgeted::kYes);
if (!srcView) {
// If we can't get a texture copy of the contents then give up.
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
SkASSERT(srcView.asTextureProxy());
@@ -802,10 +801,10 @@
if (xform) {
SkRect srcRectToDraw = SkRect::MakeXYWH(x, y, srcRect.width(), srcRect.height());
auto tempRTC = GrRenderTargetContext::Make(
- direct, this->colorInfo().colorType(), dstColorSpace, SkBackingFit::kApprox,
+ dContext, this->colorInfo().colorType(), dstColorSpace, SkBackingFit::kApprox,
dstSize, 1, GrMipmapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
if (!tempRTC) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
tempRTC->drawTexture(nullptr,
@@ -829,18 +828,18 @@
}
auto yRTC = GrRenderTargetContext::MakeWithFallback(
- direct, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, dstSize, 1,
+ dContext, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, dstSize, 1,
GrMipmapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
int halfW = dstSize.width() /2;
int halfH = dstSize.height()/2;
auto uRTC = GrRenderTargetContext::MakeWithFallback(
- direct, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, {halfW, halfH}, 1,
- GrMipmapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
+ dContext, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, {halfW, halfH},
+ 1, GrMipmapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
auto vRTC = GrRenderTargetContext::MakeWithFallback(
- direct, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, {halfW, halfH}, 1,
- GrMipmapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
+ dContext, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, {halfW, halfH},
+ 1, GrMipmapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
if (!yRTC || !uRTC || !vRTC) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
@@ -874,7 +873,7 @@
yTransfer = yRTC->transferPixels(GrColorType::kAlpha_8,
SkIRect::MakeWH(yRTC->width(), yRTC->height()));
if (!yTransfer.fTransferBuffer) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
}
@@ -899,7 +898,7 @@
uTransfer = uRTC->transferPixels(GrColorType::kAlpha_8,
SkIRect::MakeWH(uRTC->width(), uRTC->height()));
if (!uTransfer.fTransferBuffer) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
}
@@ -923,7 +922,7 @@
vTransfer = vRTC->transferPixels(GrColorType::kAlpha_8,
SkIRect::MakeWH(vRTC->width(), vRTC->height()));
if (!vTransfer.fTransferBuffer) {
- callback(context, nullptr);
+ callback(callbackContext, nullptr);
return;
}
}
@@ -936,17 +935,17 @@
std::unique_ptr<char[]> y(new char[yRB * yInfo.height()]);
std::unique_ptr<char[]> u(new char[uvRB*uvInfo.height()]);
std::unique_ptr<char[]> v(new char[uvRB*uvInfo.height()]);
- if (!yRTC->readPixels(yInfo, y.get(), yRB, {0, 0}, direct) ||
- !uRTC->readPixels(uvInfo, u.get(), uvRB, {0, 0}, direct) ||
- !vRTC->readPixels(uvInfo, v.get(), uvRB, {0, 0}, direct)) {
- callback(context, nullptr);
+ if (!yRTC->readPixels(dContext, yInfo, y.get(), yRB, {0, 0}) ||
+ !uRTC->readPixels(dContext, uvInfo, u.get(), uvRB, {0, 0}) ||
+ !vRTC->readPixels(dContext, uvInfo, v.get(), uvRB, {0, 0})) {
+ callback(callbackContext, nullptr);
return;
}
- auto result = std::make_unique<AsyncReadResult>(direct->priv().contextID());
+ auto result = std::make_unique<AsyncReadResult>(dContext->priv().contextID());
result->addCpuPlane(std::move(y), yRB );
result->addCpuPlane(std::move(u), uvRB);
result->addCpuPlane(std::move(v), uvRB);
- callback(context, std::move(result));
+ callback(callbackContext, std::move(result));
return;
}
@@ -963,8 +962,8 @@
// explicit flush from the caller. We'd have to have a way to defer attaching the finish
// callback to GrGpu until after the next flush that flushes our op list, though.
auto* finishContext = new FinishContext{callback,
- context,
- direct->priv().clientMappedBufferManager(),
+ callbackContext,
+ dContext->priv().clientMappedBufferManager(),
dstSize,
std::move(yTransfer),
std::move(uTransfer),
diff --git a/src/gpu/GrSurfaceContext.h b/src/gpu/GrSurfaceContext.h
index 4645630..6a6ef4f 100644
--- a/src/gpu/GrSurfaceContext.h
+++ b/src/gpu/GrSurfaceContext.h
@@ -75,30 +75,35 @@
/**
* Reads a rectangle of pixels from the render target context.
+ * @param dContext The direct context to use
* @param dstInfo image info for the destination
* @param dst destination pixels for the read
* @param rowBytes bytes in a row of 'dst'
* @param srcPt offset w/in the surface context from which to read
- * @param direct The direct context to use. If null will use our GrRecordingContext if it
* is a GrDirectContext and fail otherwise.
*/
- bool readPixels(const GrImageInfo& dstInfo, void* dst, size_t rowBytes, SkIPoint srcPt,
- GrDirectContext* direct = nullptr);
+ bool readPixels(GrDirectContext* dContext,
+ const GrImageInfo& dstInfo,
+ void* dst,
+ size_t rowBytes,
+ SkIPoint srcPt);
using ReadPixelsCallback = SkImage::ReadPixelsCallback;
using ReadPixelsContext = SkImage::ReadPixelsContext;
using RescaleGamma = SkImage::RescaleGamma;
// GPU implementation for SkImage:: and SkSurface::asyncRescaleAndReadPixels.
- void asyncRescaleAndReadPixels(const SkImageInfo& info,
+ void asyncRescaleAndReadPixels(GrDirectContext*,
+ const SkImageInfo& info,
const SkIRect& srcRect,
RescaleGamma rescaleGamma,
SkFilterQuality rescaleQuality,
ReadPixelsCallback callback,
- ReadPixelsContext context);
+ ReadPixelsContext callbackContext);
// GPU implementation for SkImage:: and SkSurface::asyncRescaleAndReadPixelsYUV420.
- void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
+ void asyncRescaleAndReadPixelsYUV420(GrDirectContext*,
+ SkYUVColorSpace yuvColorSpace,
sk_sp<SkColorSpace> dstColorSpace,
const SkIRect& srcRect,
SkISize dstSize,
@@ -110,15 +115,17 @@
/**
* Writes a rectangle of pixels [srcInfo, srcBuffer, srcRowbytes] into the
* renderTargetContext at the specified position.
+ * @param dContext The direct context to use
* @param srcInfo image info for the source pixels
* @param src source for the write
* @param rowBytes bytes in a row of 'src'
* @param dstPt offset w/in the surface context at which to write
- * @param direct The direct context to use. If null will use our GrRecordingContext if it
- * is a GrDirectContext and fail otherwise.
*/
- bool writePixels(const GrImageInfo& srcInfo, const void* src, size_t rowBytes, SkIPoint dstPt,
- GrDirectContext* direct = nullptr);
+ bool writePixels(GrDirectContext* dContext,
+ const GrImageInfo& srcInfo,
+ const void* src,
+ size_t rowBytes,
+ SkIPoint dstPt);
GrSurfaceProxy* asSurfaceProxy() { return fReadView.proxy(); }
const GrSurfaceProxy* asSurfaceProxy() const { return fReadView.proxy(); }
@@ -204,10 +211,11 @@
PixelTransferResult transferPixels(GrColorType colorType, const SkIRect& rect);
// The async read step of asyncRescaleAndReadPixels()
- void asyncReadPixels(const SkIRect& rect,
- SkColorType colorType,
- ReadPixelsCallback callback,
- ReadPixelsContext context);
+ void asyncReadPixels(GrDirectContext*,
+ const SkIRect& srcRect,
+ SkColorType,
+ ReadPixelsCallback,
+ ReadPixelsContext);
private:
friend class GrSurfaceProxy; // for copy
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index c316910..9a86673 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -183,21 +183,26 @@
bool SkGpuDevice::onReadPixels(const SkPixmap& pm, int x, int y) {
ASSERT_SINGLE_OWNER
- if (!SkImageInfoValidConversion(pm.info(), this->imageInfo())) {
+ // Context TODO: Elevate direct context requirement to public API
+ auto dContext = fContext->asDirectContext();
+ if (!dContext || !SkImageInfoValidConversion(pm.info(), this->imageInfo())) {
return false;
}
- return fRenderTargetContext->readPixels(pm.info(), pm.writable_addr(), pm.rowBytes(), {x, y});
+ return fRenderTargetContext->readPixels(dContext, pm.info(), pm.writable_addr(), pm.rowBytes(),
+ {x, y});
}
bool SkGpuDevice::onWritePixels(const SkPixmap& pm, int x, int y) {
ASSERT_SINGLE_OWNER
- if (!SkImageInfoValidConversion(this->imageInfo(), pm.info())) {
+ // Context TODO: Elevate direct context requirement to public API
+ auto dContext = fContext->asDirectContext();
+ if (!dContext || !SkImageInfoValidConversion(this->imageInfo(), pm.info())) {
return false;
}
- return fRenderTargetContext->writePixels(pm.info(), pm.addr(), pm.rowBytes(), {x, y});
+ return fRenderTargetContext->writePixels(dContext, pm.info(), pm.addr(), pm.rowBytes(), {x, y});
}
bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) {
diff --git a/src/gpu/effects/generated/GrConfigConversionEffect.cpp b/src/gpu/effects/generated/GrConfigConversionEffect.cpp
index 4e38451..5f1a8b7 100644
--- a/src/gpu/effects/generated/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/generated/GrConfigConversionEffect.cpp
@@ -81,7 +81,7 @@
}
#endif
-bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* context) {
+bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* dContext) {
static constexpr int kSize = 256;
static constexpr GrColorType kColorType = GrColorType::kRGBA_8888;
SkAutoTMalloc<uint32_t> data(kSize * kSize * 3);
@@ -107,9 +107,9 @@
const SkImageInfo ii =
SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
- auto readRTC = GrRenderTargetContext::Make(context, kColorType, nullptr, SkBackingFit::kExact,
+ auto readRTC = GrRenderTargetContext::Make(dContext, kColorType, nullptr, SkBackingFit::kExact,
{kSize, kSize});
- auto tempRTC = GrRenderTargetContext::Make(context, kColorType, nullptr, SkBackingFit::kExact,
+ auto tempRTC = GrRenderTargetContext::Make(dContext, kColorType, nullptr, SkBackingFit::kExact,
{kSize, kSize});
if (!readRTC || !readRTC->asTextureProxy() || !tempRTC) {
return false;
@@ -125,7 +125,7 @@
bitmap.installPixels(ii, srcData, 4 * kSize);
bitmap.setImmutable();
- GrBitmapTextureMaker maker(context, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
+ GrBitmapTextureMaker maker(dContext, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
auto dataView = maker.view(GrMipmapped::kNo);
if (!dataView) {
return false;
@@ -144,7 +144,7 @@
paint1.setPorterDuffXPFactory(SkBlendMode::kSrc);
readRTC->fillRectToRect(nullptr, std::move(paint1), GrAA::kNo, SkMatrix::I(), kRect, kRect);
- if (!readRTC->readPixels(ii, firstRead, 0, {0, 0})) {
+ if (!readRTC->readPixels(dContext, ii, firstRead, 0, {0, 0})) {
return false;
}
@@ -168,7 +168,7 @@
readRTC->fillRectToRect(nullptr, std::move(paint3), GrAA::kNo, SkMatrix::I(), kRect, kRect);
- if (!readRTC->readPixels(ii, secondRead, 0, {0, 0})) {
+ if (!readRTC->readPixels(dContext, ii, secondRead, 0, {0, 0})) {
return false;
}
diff --git a/src/gpu/text/GrAtlasManager.cpp b/src/gpu/text/GrAtlasManager.cpp
index e50c6ea..1272953 100644
--- a/src/gpu/text/GrAtlasManager.cpp
+++ b/src/gpu/text/GrAtlasManager.cpp
@@ -219,27 +219,26 @@
* Write the contents of the surface proxy to a PNG. Returns true if successful.
* @param filename Full path to desired file
*/
-static bool save_pixels(GrDirectContext* context, GrSurfaceProxyView view, GrColorType colorType,
+static bool save_pixels(GrDirectContext* dContext, GrSurfaceProxyView view, GrColorType colorType,
const char* filename) {
if (!view.proxy()) {
return false;
}
- SkImageInfo ii =
- SkImageInfo::Make(view.proxy()->dimensions(), kRGBA_8888_SkColorType,
- kPremul_SkAlphaType);
+ auto ii = SkImageInfo::Make(view.proxy()->dimensions(), kRGBA_8888_SkColorType,
+ kPremul_SkAlphaType);
SkBitmap bm;
if (!bm.tryAllocPixels(ii)) {
return false;
}
- auto sContext = GrSurfaceContext::Make(context, std::move(view), colorType,
+ auto sContext = GrSurfaceContext::Make(dContext, std::move(view), colorType,
kUnknown_SkAlphaType, nullptr);
if (!sContext || !sContext->asTextureProxy()) {
return false;
}
- bool result = sContext->readPixels(ii, bm.getPixels(), bm.rowBytes(), {0, 0});
+ bool result = sContext->readPixels(dContext, ii, bm.getPixels(), bm.rowBytes(), {0, 0});
if (!result) {
SkDebugf("------ failed to read pixels for %s\n", filename);
return false;
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 532ffa4..18dc428 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -126,14 +126,21 @@
SkFilterQuality rescaleQuality,
ReadPixelsCallback callback,
ReadPixelsContext context) {
+ auto dContext = fContext->asDirectContext();
+ if (!dContext) {
+ // DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
+ callback(context, nullptr);
+ return;
+ }
GrColorType ct = SkColorTypeToGrColorType(this->colorType());
- auto ctx = GrSurfaceContext::Make(fContext.get(), fView, ct, this->alphaType(),
+ auto ctx = GrSurfaceContext::Make(dContext, fView, ct, this->alphaType(),
this->refColorSpace());
if (!ctx) {
callback(context, nullptr);
return;
}
- ctx->asyncRescaleAndReadPixels(info, srcRect, rescaleGamma, rescaleQuality, callback, context);
+ ctx->asyncRescaleAndReadPixels(dContext, info, srcRect, rescaleGamma, rescaleQuality,
+ callback, context);
}
void SkImage_Gpu::onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
@@ -144,14 +151,21 @@
SkFilterQuality rescaleQuality,
ReadPixelsCallback callback,
ReadPixelsContext context) {
+ auto dContext = fContext->asDirectContext();
+ if (!dContext) {
+ // DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
+ callback(context, nullptr);
+ return;
+ }
GrColorType ct = SkColorTypeToGrColorType(this->colorType());
- auto ctx = GrSurfaceContext::Make(fContext.get(), fView, ct, this->alphaType(),
+ auto ctx = GrSurfaceContext::Make(dContext, fView, ct, this->alphaType(),
this->refColorSpace());
if (!ctx) {
callback(context, nullptr);
return;
}
- ctx->asyncRescaleAndReadPixelsYUV420(yuvColorSpace,
+ ctx->asyncRescaleAndReadPixelsYUV420(dContext,
+ yuvColorSpace,
std::move(dstColorSpace),
srcRect,
dstSize,
@@ -665,13 +679,13 @@
return nullptr;
}
- auto direct = GrAsDirectContext(context);
- if (!direct) {
+ auto dContext = GrAsDirectContext(context);
+ if (!dContext) {
SkDebugf("Direct context required\n");
return nullptr;
}
- GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(direct,
+ GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(dContext,
hardwareBuffer,
bufferDesc.format,
true);
@@ -685,7 +699,7 @@
GrAHardwareBufferUtils::TexImageCtx deleteImageCtx = nullptr;
GrBackendTexture backendTexture =
- GrAHardwareBufferUtils::MakeBackendTexture(direct, hardwareBuffer,
+ GrAHardwareBufferUtils::MakeBackendTexture(dContext, hardwareBuffer,
bufferDesc.width, bufferDesc.height,
&deleteImageProc, &updateImageProc,
&deleteImageCtx, false, backendFormat, true);
@@ -702,7 +716,7 @@
GrColorType grColorType = SkColorTypeToGrColorType(colorType);
- GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
+ GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
if (!proxyProvider) {
return nullptr;
}
@@ -717,26 +731,26 @@
sk_sp<SkColorSpace> cs = pixmap.refColorSpace();
SkAlphaType at = pixmap.alphaType();
- GrSwizzle swizzle = direct->priv().caps()->getReadSwizzle(backendFormat, grColorType);
+ GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(backendFormat, grColorType);
GrSurfaceProxyView view(std::move(proxy), surfaceOrigin, swizzle);
- sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(direct), kNeedNewImageUniqueID, view,
+ sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(dContext), kNeedNewImageUniqueID, view,
colorType, at, cs);
if (!image) {
return nullptr;
}
- GrDrawingManager* drawingManager = direct->priv().drawingManager();
+ GrDrawingManager* drawingManager = dContext->priv().drawingManager();
if (!drawingManager) {
return nullptr;
}
- GrSurfaceContext surfaceContext(direct, std::move(view),
+ GrSurfaceContext surfaceContext(dContext, std::move(view),
SkColorTypeToGrColorType(pixmap.colorType()),
pixmap.alphaType(), cs);
SkImageInfo srcInfo = SkImageInfo::Make(bufferDesc.width, bufferDesc.height, colorType, at,
std::move(cs));
- surfaceContext.writePixels(srcInfo, pixmap.addr(0, 0), pixmap.rowBytes(), {0, 0});
+ surfaceContext.writePixels(dContext, srcInfo, pixmap.addr(0, 0), pixmap.rowBytes(), {0, 0});
GrSurfaceProxy* p[1] = {surfaceContext.asSurfaceProxy()};
drawingManager->flush(p, 1, SkSurface::BackendSurfaceAccess::kNoAccess, {}, nullptr);
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index 8d545d4..95c4897 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -86,8 +86,8 @@
//////////////////////////////////////////////////////////////////////////////////////////////////
bool SkImage_GpuBase::getROPixels(SkBitmap* dst, CachingHint chint) const {
- auto direct = fContext->asDirectContext();
- if (!direct) {
+ auto dContext = fContext->asDirectContext();
+ if (!dContext) {
// DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
return false;
}
@@ -112,18 +112,19 @@
}
}
- const GrSurfaceProxyView* view = this->view(direct);
+ const GrSurfaceProxyView* view = this->view(dContext);
SkASSERT(view);
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(
fContext->priv().caps(), this->colorType(), view->proxy()->backendFormat());
- auto sContext = GrSurfaceContext::Make(direct, *view, grColorType, this->alphaType(),
+ auto sContext = GrSurfaceContext::Make(dContext, *view, grColorType, this->alphaType(),
this->refColorSpace());
if (!sContext) {
return false;
}
- if (!sContext->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), {0, 0})) {
+ if (!sContext->readPixels(dContext, pmap.info(), pmap.writable_addr(), pmap.rowBytes(),
+ {0, 0})) {
return false;
}
@@ -157,8 +158,8 @@
bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
int srcX, int srcY, CachingHint) const {
- auto direct = fContext->asDirectContext();
- if (!direct) {
+ auto dContext = fContext->asDirectContext();
+ if (!dContext) {
// DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
return false;
}
@@ -167,18 +168,18 @@
return false;
}
- const GrSurfaceProxyView* view = this->view(direct);
+ const GrSurfaceProxyView* view = this->view(dContext);
SkASSERT(view);
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(
- fContext->priv().caps(), this->colorType(), view->proxy()->backendFormat());
+ dContext->priv().caps(), this->colorType(), view->proxy()->backendFormat());
- auto sContext = GrSurfaceContext::Make(direct, *view, grColorType, this->alphaType(),
+ auto sContext = GrSurfaceContext::Make(dContext, *view, grColorType, this->alphaType(),
this->refColorSpace());
if (!sContext) {
return false;
}
- return sContext->readPixels(dstInfo, dstPixels, dstRB, {srcX, srcY});
+ return sContext->readPixels(dContext, dstInfo, dstPixels, dstRB, {srcX, srcY});
}
GrSurfaceProxyView SkImage_GpuBase::refView(GrRecordingContext* context,
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 2a36fc0..f95ff0e 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -148,7 +148,13 @@
ReadPixelsCallback callback,
ReadPixelsContext context) {
auto* rtc = this->fDevice->accessRenderTargetContext();
- rtc->asyncRescaleAndReadPixels(info, srcRect, rescaleGamma, rescaleQuality, callback, context);
+ // Context TODO: Elevate direct context requirement to public API.
+ auto dContext = rtc->priv().recordingContext()->asDirectContext();
+ if (!dContext) {
+ return;
+ }
+ rtc->asyncRescaleAndReadPixels(dContext, info, srcRect, rescaleGamma, rescaleQuality,
+ callback, context);
}
void SkSurface_Gpu::onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
@@ -160,7 +166,13 @@
ReadPixelsCallback callback,
ReadPixelsContext context) {
auto* rtc = this->fDevice->accessRenderTargetContext();
- rtc->asyncRescaleAndReadPixelsYUV420(yuvColorSpace,
+ // Context TODO: Elevate direct context requirement to public API.
+ auto dContext = rtc->priv().recordingContext()->asDirectContext();
+ if (!dContext) {
+ return;
+ }
+ rtc->asyncRescaleAndReadPixelsYUV420(dContext,
+ yuvColorSpace,
std::move(dstColorSpace),
srcRect,
dstSize,