Revert "Migrate GrSurfaceContext readPixels to take direct context"
This reverts commit d169e1915cba8caaddabb22b3672c7cefa91bfa2.
Reason for revert: broke chrome via code generator
Original change's description:
> 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>
TBR=robertphillips@google.com,adlai@google.com
Change-Id: I6126f2dca4bc902c903512ac486e22841cc472e5
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:104662
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309281
Reviewed-by: Adlai Holler <adlai@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp
index 8a0a0d4..5e51da4 100644
--- a/src/gpu/GrSurfaceContext.cpp
+++ b/src/gpu/GrSurfaceContext.cpp
@@ -132,14 +132,14 @@
}
#endif
-bool GrSurfaceContext::readPixels(GrDirectContext* dContext, const GrImageInfo& origDstInfo,
- void* dst, size_t rowBytes, SkIPoint pt) {
+bool GrSurfaceContext::readPixels(const GrImageInfo& origDstInfo, void* dst, size_t rowBytes,
+ SkIPoint pt, GrDirectContext* direct) {
ASSERT_SINGLE_OWNER
RETURN_FALSE_IF_ABANDONED
SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::readPixels");
- if (!dContext) {
+ if (!direct && !(direct = fContext->asDirectContext())) {
return false;
}
@@ -165,7 +165,7 @@
}
// MDB TODO: delay this instantiation until later in the method
- if (!srcProxy->instantiate(dContext->priv().resourceProvider())) {
+ if (!srcProxy->instantiate(direct->priv().resourceProvider())) {
return false;
}
@@ -183,7 +183,7 @@
needColorConversion = flags.linearize || flags.gamut_transform || flags.encode,
premul = flags.premul;
- const GrCaps* caps = dContext->priv().caps();
+ const GrCaps* caps = direct->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() &&
- dContext->priv().validPMUPMConversionExists();
+ direct->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(
- dContext, colorType, std::move(cs), SkBackingFit::kApprox, dstInfo.dimensions(),
+ direct, 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 = dContext->priv().createPMToUPMEffect(
+ fp = direct->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(dContext, dstInfo, dst, rowBytes, {0, 0});
+ return tempCtx->readPixels(dstInfo, dst, rowBytes, {0, 0}, direct);
}
bool flip = this->origin() == kBottomLeft_GrSurfaceOrigin;
@@ -276,11 +276,11 @@
pt.fY = flip ? srcSurface->height() - pt.fY - dstInfo.height() : pt.fY;
}
- 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)) {
+ 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)) {
return false;
}
@@ -290,14 +290,14 @@
return true;
}
-bool GrSurfaceContext::writePixels(GrDirectContext* dContext, const GrImageInfo& origSrcInfo,
- const void* src, size_t rowBytes, SkIPoint pt) {
+bool GrSurfaceContext::writePixels(const GrImageInfo& origSrcInfo, const void* src, size_t rowBytes,
+ SkIPoint pt, GrDirectContext* direct) {
ASSERT_SINGLE_OWNER
RETURN_FALSE_IF_ABANDONED
SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::writePixels");
- if (!dContext) {
+ if (!direct && !(direct = fContext->asDirectContext())) {
return false;
}
@@ -326,7 +326,7 @@
return false;
}
- if (!dstProxy->instantiate(dContext->priv().resourceProvider())) {
+ if (!dstProxy->instantiate(direct->priv().resourceProvider())) {
return false;
}
@@ -344,7 +344,7 @@
needColorConversion = flags.linearize || flags.gamut_transform || flags.encode,
premul = flags.premul;
- const GrCaps* caps = dContext->priv().caps();
+ const GrCaps* caps = direct->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() &&
- dContext->priv().validPMUPMConversionExists();
+ direct->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 = dContext->priv().proxyProvider()->createProxy(
+ auto tempProxy = direct->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(dContext, tempView, colorType, alphaType,
+ GrSurfaceContext tempCtx(direct, 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(dContext, srcInfo, src, rowBytes, {0, 0})) {
+ if (!tempCtx.writePixels(srcInfo, src, rowBytes, {0, 0}, direct)) {
return false;
}
if (this->asRenderTargetContext()) {
std::unique_ptr<GrFragmentProcessor> fp;
if (canvas2DFastPath) {
- fp = dContext->priv().createUPMToPMEffect(
+ fp = direct->priv().createUPMToPMEffect(
GrTextureEffect::Make(std::move(tempView), alphaType));
// Important: check the original src color type here!
if (origSrcInfo.colorType() == GrColorType::kBGRA_8888) {
@@ -471,41 +471,42 @@
// 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?
- dContext->priv().flushSurface(caps->preferVRAMUseOverFlushes() ? dstProxy : nullptr);
+ direct->priv().flushSurface(caps->preferVRAMUseOverFlushes() ? dstProxy : nullptr);
- return dContext->priv().getGpu()->writePixels(dstSurface, pt.fX, pt.fY, srcInfo.width(),
- srcInfo.height(), this->colorInfo().colorType(),
- srcColorType, src, rowBytes);
+ return direct->priv().getGpu()->writePixels(dstSurface, pt.fX, pt.fY, srcInfo.width(),
+ srcInfo.height(), this->colorInfo().colorType(),
+ srcColorType, src, rowBytes);
}
-void GrSurfaceContext::asyncRescaleAndReadPixels(GrDirectContext* dContext,
- const SkImageInfo& info,
+void GrSurfaceContext::asyncRescaleAndReadPixels(const SkImageInfo& info,
const SkIRect& srcRect,
RescaleGamma rescaleGamma,
SkFilterQuality rescaleQuality,
ReadPixelsCallback callback,
- ReadPixelsContext callbackContext) {
+ ReadPixelsContext context) {
+ auto direct = fContext->asDirectContext();
+
// We implement this by rendering and we don't currently support rendering kUnpremul.
if (info.alphaType() == kUnpremul_SkAlphaType) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
- if (!dContext) {
- callback(callbackContext, nullptr);
+ if (!direct) {
+ callback(context, nullptr);
return;
}
auto rt = this->asRenderTargetProxy();
if (rt && rt->wrapsVkSecondaryCB()) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
if (rt && rt->framebufferOnly()) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
auto dstCT = SkColorTypeToGrColorType(info.colorType());
if (dstCT == GrColorType::kUnknown) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
bool needsRescale = srcRect.width() != info.width() || srcRect.height() != info.height();
@@ -520,7 +521,7 @@
backendFormatOfFinalContext, dstCT);
// Fail if we can't read from the source surface's color type.
if (readInfo.fColorType == GrColorType::kUnknown) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
// Fail if read color type does not have all of dstCT's color channels and those missing color
@@ -529,7 +530,7 @@
uint32_t legalReadChannels = GrColorTypeChannelFlags(readInfo.fColorType);
uint32_t srcChannels = GrColorTypeChannelFlags(this->colorInfo().colorType());
if ((~legalReadChannels & dstChannels) & srcChannels) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
@@ -540,7 +541,7 @@
tempRTC = this->rescale(info, kTopLeft_GrSurfaceOrigin, srcRect, rescaleGamma,
rescaleQuality);
if (!tempRTC) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
SkASSERT(SkColorSpace::Equals(tempRTC->colorInfo().colorSpace(), info.colorSpace()));
@@ -561,18 +562,18 @@
GrSurfaceProxyView::Copy(fContext, texProxyView, GrMipmapped::kNo, srcRect,
SkBackingFit::kApprox, SkBudgeted::kNo);
if (!texProxyView) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
SkASSERT(texProxyView.asTextureProxy());
srcRectToDraw = SkRect::MakeWH(srcRect.width(), srcRect.height());
}
- tempRTC = GrRenderTargetContext::Make(dContext, this->colorInfo().colorType(),
+ tempRTC = GrRenderTargetContext::Make(direct, this->colorInfo().colorType(),
info.refColorSpace(), SkBackingFit::kApprox,
srcRect.size(), 1, GrMipmapped::kNo,
GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
if (!tempRTC) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
tempRTC->drawTexture(nullptr,
@@ -593,8 +594,8 @@
}
}
auto rtc = tempRTC ? tempRTC.get() : this;
- return rtc->asyncReadPixels(dContext, SkIRect::MakeXYWH(x, y, info.width(), info.height()),
- info.colorType(), callback, callbackContext);
+ return rtc->asyncReadPixels(SkIRect::MakeXYWH(x, y, info.width(), info.height()),
+ info.colorType(), callback, context);
}
class GrSurfaceContext::AsyncReadResult : public SkImage::AsyncReadResult {
@@ -663,20 +664,21 @@
uint32_t fInboxID;
};
-void GrSurfaceContext::asyncReadPixels(GrDirectContext* dContext,
- const SkIRect& rect,
+void GrSurfaceContext::asyncReadPixels(const SkIRect& rect,
SkColorType colorType,
ReadPixelsCallback callback,
- ReadPixelsContext callbackContext) {
+ ReadPixelsContext context) {
SkASSERT(rect.fLeft >= 0 && rect.fRight <= this->width());
SkASSERT(rect.fTop >= 0 && rect.fBottom <= this->height());
- if (!dContext || this->asSurfaceProxy()->isProtected() == GrProtected::kYes) {
- callback(callbackContext, nullptr);
+ if (this->asSurfaceProxy()->isProtected() == GrProtected::kYes) {
+ callback(context, nullptr);
return;
}
- auto mappedBufferManager = dContext->priv().clientMappedBufferManager();
+ auto directContext = fContext->asDirectContext();
+ SkASSERT(directContext);
+ auto mappedBufferManager = directContext->priv().clientMappedBufferManager();
auto transferResult = this->transferPixels(SkColorTypeToGrColorType(colorType), rect);
@@ -688,12 +690,11 @@
SkPixmap pm(ii, data.get(), ii.minRowBytes());
result->addCpuPlane(std::move(data), pm.rowBytes());
- SkIPoint pt{rect.fLeft, rect.fTop};
- if (!this->readPixels(dContext, ii, pm.writable_addr(), pm.rowBytes(), pt)) {
- callback(callbackContext, nullptr);
+ if (!this->readPixels(ii, pm.writable_addr(), pm.rowBytes(), {rect.fLeft, rect.fTop})) {
+ callback(context, nullptr);
return;
}
- callback(callbackContext, std::move(result));
+ callback(context, std::move(result));
return;
}
@@ -709,7 +710,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,
- callbackContext,
+ context,
rect.size(),
colorType,
mappedBufferManager,
@@ -731,35 +732,35 @@
this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo, nullptr);
}
-void GrSurfaceContext::asyncRescaleAndReadPixelsYUV420(GrDirectContext* dContext,
- SkYUVColorSpace yuvColorSpace,
+void GrSurfaceContext::asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
sk_sp<SkColorSpace> dstColorSpace,
const SkIRect& srcRect,
SkISize dstSize,
RescaleGamma rescaleGamma,
SkFilterQuality rescaleQuality,
ReadPixelsCallback callback,
- ReadPixelsContext callbackContext) {
+ ReadPixelsContext context) {
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));
- if (!dContext) {
- callback(callbackContext, nullptr);
+ auto direct = fContext->asDirectContext();
+ if (!direct) {
+ callback(context, nullptr);
return;
}
auto rt = this->asRenderTargetProxy();
if (rt && rt->wrapsVkSecondaryCB()) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
if (rt && rt->framebufferOnly()) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
if (this->asSurfaceProxy()->isProtected() == GrProtected::kYes) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
int x = srcRect.fLeft;
@@ -774,7 +775,7 @@
auto tempRTC = this->rescale(info, kTopLeft_GrSurfaceOrigin, srcRect, rescaleGamma,
rescaleQuality);
if (!tempRTC) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
SkASSERT(SkColorSpace::Equals(tempRTC->colorInfo().colorSpace(), info.colorSpace()));
@@ -788,7 +789,7 @@
srcRect, SkBackingFit::kApprox, SkBudgeted::kYes);
if (!srcView) {
// If we can't get a texture copy of the contents then give up.
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
SkASSERT(srcView.asTextureProxy());
@@ -801,10 +802,10 @@
if (xform) {
SkRect srcRectToDraw = SkRect::MakeXYWH(x, y, srcRect.width(), srcRect.height());
auto tempRTC = GrRenderTargetContext::Make(
- dContext, this->colorInfo().colorType(), dstColorSpace, SkBackingFit::kApprox,
+ direct, this->colorInfo().colorType(), dstColorSpace, SkBackingFit::kApprox,
dstSize, 1, GrMipmapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
if (!tempRTC) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
tempRTC->drawTexture(nullptr,
@@ -828,18 +829,18 @@
}
auto yRTC = GrRenderTargetContext::MakeWithFallback(
- dContext, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, dstSize, 1,
+ direct, 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(
- dContext, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, {halfW, halfH},
- 1, GrMipmapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
+ direct, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, {halfW, halfH}, 1,
+ GrMipmapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
auto vRTC = GrRenderTargetContext::MakeWithFallback(
- dContext, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, {halfW, halfH},
- 1, GrMipmapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
+ direct, GrColorType::kAlpha_8, dstColorSpace, SkBackingFit::kApprox, {halfW, halfH}, 1,
+ GrMipmapped::kNo, GrProtected::kNo, kTopLeft_GrSurfaceOrigin);
if (!yRTC || !uRTC || !vRTC) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
@@ -873,7 +874,7 @@
yTransfer = yRTC->transferPixels(GrColorType::kAlpha_8,
SkIRect::MakeWH(yRTC->width(), yRTC->height()));
if (!yTransfer.fTransferBuffer) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
}
@@ -898,7 +899,7 @@
uTransfer = uRTC->transferPixels(GrColorType::kAlpha_8,
SkIRect::MakeWH(uRTC->width(), uRTC->height()));
if (!uTransfer.fTransferBuffer) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
}
@@ -922,7 +923,7 @@
vTransfer = vRTC->transferPixels(GrColorType::kAlpha_8,
SkIRect::MakeWH(vRTC->width(), vRTC->height()));
if (!vTransfer.fTransferBuffer) {
- callback(callbackContext, nullptr);
+ callback(context, nullptr);
return;
}
}
@@ -935,17 +936,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(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);
+ 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);
return;
}
- auto result = std::make_unique<AsyncReadResult>(dContext->priv().contextID());
+ auto result = std::make_unique<AsyncReadResult>(direct->priv().contextID());
result->addCpuPlane(std::move(y), yRB );
result->addCpuPlane(std::move(u), uvRB);
result->addCpuPlane(std::move(v), uvRB);
- callback(callbackContext, std::move(result));
+ callback(context, std::move(result));
return;
}
@@ -962,8 +963,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,
- callbackContext,
- dContext->priv().clientMappedBufferManager(),
+ context,
+ direct->priv().clientMappedBufferManager(),
dstSize,
std::move(yTransfer),
std::move(uTransfer),
diff --git a/src/gpu/GrSurfaceContext.h b/src/gpu/GrSurfaceContext.h
index 6a6ef4f..4645630 100644
--- a/src/gpu/GrSurfaceContext.h
+++ b/src/gpu/GrSurfaceContext.h
@@ -75,35 +75,30 @@
/**
* 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(GrDirectContext* dContext,
- const GrImageInfo& dstInfo,
- void* dst,
- size_t rowBytes,
- SkIPoint srcPt);
+ bool readPixels(const GrImageInfo& dstInfo, void* dst, size_t rowBytes, SkIPoint srcPt,
+ GrDirectContext* direct = nullptr);
using ReadPixelsCallback = SkImage::ReadPixelsCallback;
using ReadPixelsContext = SkImage::ReadPixelsContext;
using RescaleGamma = SkImage::RescaleGamma;
// GPU implementation for SkImage:: and SkSurface::asyncRescaleAndReadPixels.
- void asyncRescaleAndReadPixels(GrDirectContext*,
- const SkImageInfo& info,
+ void asyncRescaleAndReadPixels(const SkImageInfo& info,
const SkIRect& srcRect,
RescaleGamma rescaleGamma,
SkFilterQuality rescaleQuality,
ReadPixelsCallback callback,
- ReadPixelsContext callbackContext);
+ ReadPixelsContext context);
// GPU implementation for SkImage:: and SkSurface::asyncRescaleAndReadPixelsYUV420.
- void asyncRescaleAndReadPixelsYUV420(GrDirectContext*,
- SkYUVColorSpace yuvColorSpace,
+ void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
sk_sp<SkColorSpace> dstColorSpace,
const SkIRect& srcRect,
SkISize dstSize,
@@ -115,17 +110,15 @@
/**
* 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(GrDirectContext* dContext,
- const GrImageInfo& srcInfo,
- const void* src,
- size_t rowBytes,
- SkIPoint dstPt);
+ bool writePixels(const GrImageInfo& srcInfo, const void* src, size_t rowBytes, SkIPoint dstPt,
+ GrDirectContext* direct = nullptr);
GrSurfaceProxy* asSurfaceProxy() { return fReadView.proxy(); }
const GrSurfaceProxy* asSurfaceProxy() const { return fReadView.proxy(); }
@@ -211,11 +204,10 @@
PixelTransferResult transferPixels(GrColorType colorType, const SkIRect& rect);
// The async read step of asyncRescaleAndReadPixels()
- void asyncReadPixels(GrDirectContext*,
- const SkIRect& srcRect,
- SkColorType,
- ReadPixelsCallback,
- ReadPixelsContext);
+ void asyncReadPixels(const SkIRect& rect,
+ SkColorType colorType,
+ ReadPixelsCallback callback,
+ ReadPixelsContext context);
private:
friend class GrSurfaceProxy; // for copy
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 9a86673..c316910 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -183,26 +183,21 @@
bool SkGpuDevice::onReadPixels(const SkPixmap& pm, int x, int y) {
ASSERT_SINGLE_OWNER
- // Context TODO: Elevate direct context requirement to public API
- auto dContext = fContext->asDirectContext();
- if (!dContext || !SkImageInfoValidConversion(pm.info(), this->imageInfo())) {
+ if (!SkImageInfoValidConversion(pm.info(), this->imageInfo())) {
return false;
}
- return fRenderTargetContext->readPixels(dContext, pm.info(), pm.writable_addr(), pm.rowBytes(),
- {x, y});
+ return fRenderTargetContext->readPixels(pm.info(), pm.writable_addr(), pm.rowBytes(), {x, y});
}
bool SkGpuDevice::onWritePixels(const SkPixmap& pm, int x, int y) {
ASSERT_SINGLE_OWNER
- // Context TODO: Elevate direct context requirement to public API
- auto dContext = fContext->asDirectContext();
- if (!dContext || !SkImageInfoValidConversion(this->imageInfo(), pm.info())) {
+ if (!SkImageInfoValidConversion(this->imageInfo(), pm.info())) {
return false;
}
- return fRenderTargetContext->writePixels(dContext, pm.info(), pm.addr(), pm.rowBytes(), {x, y});
+ return fRenderTargetContext->writePixels(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 5f1a8b7..4e38451 100644
--- a/src/gpu/effects/generated/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/generated/GrConfigConversionEffect.cpp
@@ -81,7 +81,7 @@
}
#endif
-bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* dContext) {
+bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* context) {
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(dContext, kColorType, nullptr, SkBackingFit::kExact,
+ auto readRTC = GrRenderTargetContext::Make(context, kColorType, nullptr, SkBackingFit::kExact,
{kSize, kSize});
- auto tempRTC = GrRenderTargetContext::Make(dContext, kColorType, nullptr, SkBackingFit::kExact,
+ auto tempRTC = GrRenderTargetContext::Make(context, 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(dContext, bitmap, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
+ GrBitmapTextureMaker maker(context, 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(dContext, ii, firstRead, 0, {0, 0})) {
+ if (!readRTC->readPixels(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(dContext, ii, secondRead, 0, {0, 0})) {
+ if (!readRTC->readPixels(ii, secondRead, 0, {0, 0})) {
return false;
}
diff --git a/src/gpu/text/GrAtlasManager.cpp b/src/gpu/text/GrAtlasManager.cpp
index 1272953..e50c6ea 100644
--- a/src/gpu/text/GrAtlasManager.cpp
+++ b/src/gpu/text/GrAtlasManager.cpp
@@ -219,26 +219,27 @@
* 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* dContext, GrSurfaceProxyView view, GrColorType colorType,
+static bool save_pixels(GrDirectContext* context, GrSurfaceProxyView view, GrColorType colorType,
const char* filename) {
if (!view.proxy()) {
return false;
}
- auto ii = SkImageInfo::Make(view.proxy()->dimensions(), kRGBA_8888_SkColorType,
- kPremul_SkAlphaType);
+ SkImageInfo ii =
+ SkImageInfo::Make(view.proxy()->dimensions(), kRGBA_8888_SkColorType,
+ kPremul_SkAlphaType);
SkBitmap bm;
if (!bm.tryAllocPixels(ii)) {
return false;
}
- auto sContext = GrSurfaceContext::Make(dContext, std::move(view), colorType,
+ auto sContext = GrSurfaceContext::Make(context, std::move(view), colorType,
kUnknown_SkAlphaType, nullptr);
if (!sContext || !sContext->asTextureProxy()) {
return false;
}
- bool result = sContext->readPixels(dContext, ii, bm.getPixels(), bm.rowBytes(), {0, 0});
+ bool result = sContext->readPixels(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 18dc428..532ffa4 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -126,21 +126,14 @@
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(dContext, fView, ct, this->alphaType(),
+ auto ctx = GrSurfaceContext::Make(fContext.get(), fView, ct, this->alphaType(),
this->refColorSpace());
if (!ctx) {
callback(context, nullptr);
return;
}
- ctx->asyncRescaleAndReadPixels(dContext, info, srcRect, rescaleGamma, rescaleQuality,
- callback, context);
+ ctx->asyncRescaleAndReadPixels(info, srcRect, rescaleGamma, rescaleQuality, callback, context);
}
void SkImage_Gpu::onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
@@ -151,21 +144,14 @@
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(dContext, fView, ct, this->alphaType(),
+ auto ctx = GrSurfaceContext::Make(fContext.get(), fView, ct, this->alphaType(),
this->refColorSpace());
if (!ctx) {
callback(context, nullptr);
return;
}
- ctx->asyncRescaleAndReadPixelsYUV420(dContext,
- yuvColorSpace,
+ ctx->asyncRescaleAndReadPixelsYUV420(yuvColorSpace,
std::move(dstColorSpace),
srcRect,
dstSize,
@@ -679,13 +665,13 @@
return nullptr;
}
- auto dContext = GrAsDirectContext(context);
- if (!dContext) {
+ auto direct = GrAsDirectContext(context);
+ if (!direct) {
SkDebugf("Direct context required\n");
return nullptr;
}
- GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(dContext,
+ GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(direct,
hardwareBuffer,
bufferDesc.format,
true);
@@ -699,7 +685,7 @@
GrAHardwareBufferUtils::TexImageCtx deleteImageCtx = nullptr;
GrBackendTexture backendTexture =
- GrAHardwareBufferUtils::MakeBackendTexture(dContext, hardwareBuffer,
+ GrAHardwareBufferUtils::MakeBackendTexture(direct, hardwareBuffer,
bufferDesc.width, bufferDesc.height,
&deleteImageProc, &updateImageProc,
&deleteImageCtx, false, backendFormat, true);
@@ -716,7 +702,7 @@
GrColorType grColorType = SkColorTypeToGrColorType(colorType);
- GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
+ GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
if (!proxyProvider) {
return nullptr;
}
@@ -731,26 +717,26 @@
sk_sp<SkColorSpace> cs = pixmap.refColorSpace();
SkAlphaType at = pixmap.alphaType();
- GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(backendFormat, grColorType);
+ GrSwizzle swizzle = direct->priv().caps()->getReadSwizzle(backendFormat, grColorType);
GrSurfaceProxyView view(std::move(proxy), surfaceOrigin, swizzle);
- sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(dContext), kNeedNewImageUniqueID, view,
+ sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(direct), kNeedNewImageUniqueID, view,
colorType, at, cs);
if (!image) {
return nullptr;
}
- GrDrawingManager* drawingManager = dContext->priv().drawingManager();
+ GrDrawingManager* drawingManager = direct->priv().drawingManager();
if (!drawingManager) {
return nullptr;
}
- GrSurfaceContext surfaceContext(dContext, std::move(view),
+ GrSurfaceContext surfaceContext(direct, std::move(view),
SkColorTypeToGrColorType(pixmap.colorType()),
pixmap.alphaType(), cs);
SkImageInfo srcInfo = SkImageInfo::Make(bufferDesc.width, bufferDesc.height, colorType, at,
std::move(cs));
- surfaceContext.writePixels(dContext, srcInfo, pixmap.addr(0, 0), pixmap.rowBytes(), {0, 0});
+ surfaceContext.writePixels(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 95c4897..8d545d4 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 dContext = fContext->asDirectContext();
- if (!dContext) {
+ auto direct = fContext->asDirectContext();
+ if (!direct) {
// DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
return false;
}
@@ -112,19 +112,18 @@
}
}
- const GrSurfaceProxyView* view = this->view(dContext);
+ const GrSurfaceProxyView* view = this->view(direct);
SkASSERT(view);
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(
fContext->priv().caps(), this->colorType(), view->proxy()->backendFormat());
- auto sContext = GrSurfaceContext::Make(dContext, *view, grColorType, this->alphaType(),
+ auto sContext = GrSurfaceContext::Make(direct, *view, grColorType, this->alphaType(),
this->refColorSpace());
if (!sContext) {
return false;
}
- if (!sContext->readPixels(dContext, pmap.info(), pmap.writable_addr(), pmap.rowBytes(),
- {0, 0})) {
+ if (!sContext->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), {0, 0})) {
return false;
}
@@ -158,8 +157,8 @@
bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
int srcX, int srcY, CachingHint) const {
- auto dContext = fContext->asDirectContext();
- if (!dContext) {
+ auto direct = fContext->asDirectContext();
+ if (!direct) {
// DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
return false;
}
@@ -168,18 +167,18 @@
return false;
}
- const GrSurfaceProxyView* view = this->view(dContext);
+ const GrSurfaceProxyView* view = this->view(direct);
SkASSERT(view);
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(
- dContext->priv().caps(), this->colorType(), view->proxy()->backendFormat());
+ fContext->priv().caps(), this->colorType(), view->proxy()->backendFormat());
- auto sContext = GrSurfaceContext::Make(dContext, *view, grColorType, this->alphaType(),
+ auto sContext = GrSurfaceContext::Make(direct, *view, grColorType, this->alphaType(),
this->refColorSpace());
if (!sContext) {
return false;
}
- return sContext->readPixels(dContext, dstInfo, dstPixels, dstRB, {srcX, srcY});
+ return sContext->readPixels(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 f95ff0e..2a36fc0 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -148,13 +148,7 @@
ReadPixelsCallback callback,
ReadPixelsContext context) {
auto* rtc = this->fDevice->accessRenderTargetContext();
- // 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);
+ rtc->asyncRescaleAndReadPixels(info, srcRect, rescaleGamma, rescaleQuality, callback, context);
}
void SkSurface_Gpu::onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
@@ -166,13 +160,7 @@
ReadPixelsCallback callback,
ReadPixelsContext context) {
auto* rtc = this->fDevice->accessRenderTargetContext();
- // Context TODO: Elevate direct context requirement to public API.
- auto dContext = rtc->priv().recordingContext()->asDirectContext();
- if (!dContext) {
- return;
- }
- rtc->asyncRescaleAndReadPixelsYUV420(dContext,
- yuvColorSpace,
+ rtc->asyncRescaleAndReadPixelsYUV420(yuvColorSpace,
std::move(dstColorSpace),
srcRect,
dstSize,