Add GrDirectContext arg to SkImage::readPixels
Note: The polarity of the staging flag is inverted from usual because
a G3 dependency with no SkUserConfig.h relies on the legacy API.
Once this lands, we will migrate them and others, then remove the
staging API. The inverted staging flag is kind of nice, actually - I may
use that pattern in the future. It means less total CLs and it's just as
easy to flip the bit on or off during debugging.
Bug: skia:104662
Change-Id: I48cba1eeae3e2e6f79918c6d243e0666e68ec71b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/310656
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp
index d5d334b..b0f0a20 100644
--- a/src/core/SkBitmapCache.cpp
+++ b/src/core/SkBitmapCache.cpp
@@ -286,7 +286,7 @@
const SkMipmap* SkMipmapCache::AddAndRef(const SkImage_Base* image, SkResourceCache* localCache) {
SkBitmap src;
- if (!image->getROPixels(&src)) {
+ if (!image->getROPixels(nullptr, &src)) {
return nullptr;
}
diff --git a/src/core/SkBitmapController.cpp b/src/core/SkBitmapController.cpp
index 4a895cb..d0c7b91 100644
--- a/src/core/SkBitmapController.cpp
+++ b/src/core/SkBitmapController.cpp
@@ -48,7 +48,7 @@
return false;
}
- (void)image->getROPixels(&fResultBitmap);
+ (void)image->getROPixels(nullptr, &fResultBitmap);
return true;
}
@@ -106,7 +106,7 @@
if (this->processHighRequest(image) || this->processMediumRequest(image)) {
SkASSERT(fResultBitmap.getPixels());
} else {
- (void)image->getROPixels(&fResultBitmap);
+ (void)image->getROPixels(nullptr, &fResultBitmap);
}
// fResultBitmap.getPixels() may be null, but our caller knows to check fPixmap.addr()
@@ -124,12 +124,12 @@
auto load_upper_from_base = [&]() {
// only do this once
if (fBaseStorage.getPixels() == nullptr) {
- (void)image->getROPixels(&fBaseStorage);
+ (void)image->getROPixels(nullptr, &fBaseStorage);
fUpper.reset(fBaseStorage.info(), fBaseStorage.getPixels(), fBaseStorage.rowBytes());
}
};
- float level = 0;
+ float level = 0;
if (requestedMode != SkMipmapMode::kNone) {
SkSize scale;
if (!inv.decomposeScale(&scale, nullptr)) {
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 4d94571..c6b60b3 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -422,13 +422,15 @@
}
void SkBitmapDevice::drawImageRect(const SkImage* image,
- const SkRect* src, const SkRect& dst,
- const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) {
+ const SkRect* src, const SkRect& dst,
+ const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) {
SkASSERT(dst.isFinite());
SkASSERT(dst.isSorted());
SkBitmap bitmap;
- if (!as_IB(image)->getROPixels(&bitmap)) {
+ // TODO: Elevate direct context requirement to public API and remove cheat.
+ auto dContext = as_IB(image)->directContext();
+ if (!as_IB(image)->getROPixels(dContext, &bitmap)) {
return;
}
diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp
index 74ed1f0..dbf9d2d 100644
--- a/src/core/SkDeferredDisplayListRecorder.cpp
+++ b/src/core/SkDeferredDisplayListRecorder.cpp
@@ -134,8 +134,6 @@
GrColorType grColorType = SkColorTypeToGrColorType(fCharacterization.colorType());
- sk_sp<SkDeferredDisplayList::LazyProxyData> lazyProxyData = fLazyProxyData;
-
// What we're doing here is we're creating a lazy proxy to back the SkSurface. The lazy
// proxy, when instantiated, will use the GrRenderTarget that backs the SkSurface that the
// DDL is being replayed into.
@@ -158,7 +156,7 @@
GrSwizzle readSwizzle = caps->getReadSwizzle(fCharacterization.backendFormat(), grColorType);
fTargetProxy = proxyProvider->createLazyRenderTargetProxy(
- [lazyProxyData](GrResourceProvider* resourceProvider,
+ [lazyProxyData = fLazyProxyData](GrResourceProvider* resourceProvider,
const GrSurfaceProxy::LazySurfaceDesc&) {
// The proxy backing the destination surface had better have been instantiated
// prior to the this one (i.e., the proxy backing the DLL's surface).
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index fc964c6..c00c4d3 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -183,8 +183,9 @@
const SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul_SkAlphaType);
while (iter.next(&srcR, &dstR, &isFixedColor, &c)) {
- if (isFixedColor || (srcR.width() <= 1.0f && srcR.height() <= 1.0f &&
- image->readPixels(info, &c, 4, srcR.fLeft, srcR.fTop))) {
+ // TODO: support this fast-path for GPU images
+ if (isFixedColor || (srcR.width() <= 1.0f && srcR.height() <= 1.0f &&
+ image->readPixels(nullptr, info, &c, 4, srcR.fLeft, srcR.fTop))) {
// Fast draw with drawRect, if this is a patch containing a single color
// or if this is a patch containing a single pixel.
if (0 != c || !paint.isSrcOver()) {
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index 2d0349f..0a87779 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -167,7 +167,7 @@
// raster to gpu is supported here, but gpu to raster is not
SkBitmap bm;
- if (!image->isTextureBacked() && as_IB(image)->getROPixels(&bm)) {
+ if (as_IB(image)->getROPixels(nullptr, &bm)) {
return MakeFromRaster(subset, bm, props);
}
return nullptr;
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp
index 8a0a0d4..36e6bf2 100644
--- a/src/gpu/GrSurfaceContext.cpp
+++ b/src/gpu/GrSurfaceContext.cpp
@@ -138,8 +138,7 @@
RETURN_FALSE_IF_ABANDONED
SkDEBUGCODE(this->validate();)
GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::readPixels");
-
- if (!dContext) {
+ if (!fContext->priv().matches(dContext)) {
return false;
}
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index bc03a8a..f39da92 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -840,7 +840,7 @@
if (image->isLazyGenerated()) {
GrImageTextureMaker maker(fContext.get(), image, GrImageTexGenPolicy::kDraw);
this->drawProducerLattice(&maker, std::move(iter), dst, paint);
- } else if (as_IB(image)->getROPixels(&bm)) {
+ } else if (as_IB(image)->getROPixels(nullptr, &bm)) {
GrBitmapTextureMaker maker(fContext.get(), bm, GrImageTexGenPolicy::kDraw);
this->drawProducerLattice(&maker, std::move(iter), dst, paint);
}
@@ -893,7 +893,7 @@
if (image->isLazyGenerated()) {
GrImageTextureMaker maker(fContext.get(), image, GrImageTexGenPolicy::kDraw);
this->drawProducerLattice(&maker, std::move(iter), dst, paint);
- } else if (as_IB(image)->getROPixels(&bm)) {
+ } else if (as_IB(image)->getROPixels(nullptr, &bm)) {
GrBitmapTextureMaker maker(fContext.get(), bm, GrImageTexGenPolicy::kDraw);
this->drawProducerLattice(&maker, std::move(iter), dst, paint);
}
diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp
index 93f95ec..0aefd7c 100644
--- a/src/gpu/SkGpuDevice_drawTexture.cpp
+++ b/src/gpu/SkGpuDevice_drawTexture.cpp
@@ -743,7 +743,7 @@
// Extract pixels on the CPU, since we have to split into separate textures before
// sending to the GPU.
SkBitmap bm;
- if (as_IB(image)->getROPixels(&bm)) {
+ if (as_IB(image)->getROPixels(nullptr, &bm)) {
// This is the funnel for all paths that draw tiled bitmaps/images. Log histogram
SK_HISTOGRAM_BOOLEAN("DrawTiled", true);
LogDrawScaleFactor(ctm, srcToDst, paint.getFilterQuality());
@@ -770,7 +770,7 @@
}
SkBitmap bm;
- if (as_IB(image)->getROPixels(&bm)) {
+ if (as_IB(image)->getROPixels(nullptr, &bm)) {
GrBitmapTextureMaker maker(fContext.get(), bm, GrImageTexGenPolicy::kDraw);
draw_texture_producer(fContext.get(), fRenderTargetContext.get(), clip, matrixProvider,
paint, &maker, src, dst, dstClip, srcToDst, aa, aaFlags, constraint,
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index d6ae477..d7ba378 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -50,11 +50,19 @@
return as_IB(this)->onPeekPixels(pm);
}
-bool SkImage::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX,
- int srcY, CachingHint chint) const {
- return as_IB(this)->onReadPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY, chint);
+bool SkImage::readPixels(GrDirectContext* dContext, const SkImageInfo& dstInfo, void* dstPixels,
+ size_t dstRowBytes, int srcX, int srcY, CachingHint chint) const {
+ return as_IB(this)->onReadPixels(dContext, dstInfo, dstPixels, dstRowBytes, srcX, srcY, chint);
}
+#ifndef SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API
+bool SkImage::readPixels(const SkImageInfo& dstInfo, void* dstPixels,
+ size_t dstRowBytes, int srcX, int srcY, CachingHint chint) const {
+ auto dContext = as_IB(this)->directContext();
+ return this->readPixels(dContext, dstInfo, dstPixels, dstRowBytes, srcX, srcY, chint);
+}
+#endif
+
void SkImage::asyncRescaleAndReadPixels(const SkImageInfo& info,
const SkIRect& srcRect,
RescaleGamma rescaleGamma,
@@ -94,15 +102,17 @@
}
bool SkImage::scalePixels(const SkPixmap& dst, SkFilterQuality quality, CachingHint chint) const {
+ // Context TODO: Elevate GrDirectContext requirement to public API.
+ auto dContext = as_IB(this)->directContext();
if (this->width() == dst.width() && this->height() == dst.height()) {
- return this->readPixels(dst, 0, 0, chint);
+ return this->readPixels(dContext, dst, 0, 0, chint);
}
// Idea: If/when SkImageGenerator supports a native-scaling API (where the generator itself
// can scale more efficiently) we should take advantage of it here.
//
SkBitmap bm;
- if (as_IB(this)->getROPixels(&bm, chint)) {
+ if (as_IB(this)->getROPixels(dContext, &bm, chint)) {
SkPixmap pmap;
// Note: By calling the pixmap scaler, we never cache the final result, so the chint
// is (currently) only being applied to the getROPixels. If we get a request to
@@ -149,8 +159,10 @@
}
sk_sp<SkData> SkImage::encodeToData(SkEncodedImageFormat type, int quality) const {
+ // Context TODO: Elevate GrDirectContext requirement to public API.
+ auto dContext = as_IB(this)->directContext();
SkBitmap bm;
- if (as_IB(this)->getROPixels(&bm)) {
+ if (as_IB(this)->getROPixels(dContext, &bm)) {
return SkEncodeBitmap(bm, type, quality);
}
return nullptr;
@@ -276,9 +288,11 @@
src.installPixels(peek);
srcRect = origSrcRect;
} else {
+ // Context TODO: Elevate GrDirectContext requirement to public API.
+ auto dContext = as_IB(this)->directContext();
src.setInfo(this->imageInfo().makeDimensions(origSrcRect.size()));
src.allocPixels();
- if (!this->readPixels(src.pixmap(), origSrcRect.x(), origSrcRect.y())) {
+ if (!this->readPixels(dContext, src.pixmap(), origSrcRect.x(), origSrcRect.y())) {
callback(context, nullptr);
return;
}
@@ -306,10 +320,27 @@
return GrBackendTexture(); // invalid
}
-bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY, CachingHint chint) const {
- return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), srcX, srcY, chint);
+GrDirectContext* SkImage_Base::directContext() const {
+#if SK_SUPPORT_GPU
+ return GrAsDirectContext(this->context());
+#else
+ return nullptr;
+#endif
}
+bool SkImage::readPixels(GrDirectContext* dContext, const SkPixmap& pmap, int srcX, int srcY,
+ CachingHint chint) const {
+ return this->readPixels(dContext, pmap.info(), pmap.writable_addr(), pmap.rowBytes(), srcX,
+ srcY, chint);
+}
+
+#ifndef SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API
+bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY, CachingHint chint) const {
+ auto dContext = as_IB(this)->directContext();
+ return this->readPixels(dContext, pmap, srcX, srcY, chint);
+}
+#endif
+
///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<SkImage> SkImage::MakeFromBitmap(const SkBitmap& bm) {
@@ -321,17 +352,21 @@
}
bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode ) const {
- return as_IB(this)->onAsLegacyBitmap(bitmap);
+ // Context TODO: Elevate GrDirectContext requirement to public API.
+ auto dContext = as_IB(this)->directContext();
+ return as_IB(this)->onAsLegacyBitmap(dContext, bitmap);
}
-bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap) const {
+bool SkImage_Base::onAsLegacyBitmap(GrDirectContext* dContext, SkBitmap* bitmap) const {
// As the base-class, all we can do is make a copy (regardless of mode).
// Subclasses that want to be more optimal should override.
SkImageInfo info = fInfo.makeColorType(kN32_SkColorType).makeColorSpace(nullptr);
if (!bitmap->tryAllocPixels(info)) {
return false;
}
- if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), 0, 0)) {
+
+ if (!this->readPixels(dContext, bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(),
+ 0, 0)) {
bitmap->reset();
return false;
}
@@ -487,9 +522,11 @@
return nullptr;
}
+ // Context TODO: Elevate GrDirectContext requirement to public API.
+ auto dContext = as_IB(this)->directContext();
sk_sp<SkData> data = SkData::MakeUninitialized(size);
pm = {fInfo.makeColorSpace(nullptr), data->writable_data(), fInfo.minRowBytes()};
- if (!this->readPixels(pm, 0, 0, chint)) {
+ if (!this->readPixels(dContext, pm, 0, 0, chint)) {
return nullptr;
}
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index 5f28899..d8ad750 100644
--- a/src/image/SkImage_Base.h
+++ b/src/image/SkImage_Base.h
@@ -40,8 +40,13 @@
virtual const SkBitmap* onPeekBitmap() const { return nullptr; }
- virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
- int srcX, int srcY, CachingHint) const = 0;
+ virtual bool onReadPixels(GrDirectContext*,
+ const SkImageInfo& dstInfo,
+ void* dstPixels,
+ size_t dstRowBytes,
+ int srcX,
+ int srcY,
+ CachingHint) const = 0;
virtual SkMipmap* onPeekMips() const { return nullptr; }
@@ -72,6 +77,9 @@
virtual GrContext* context() const { return nullptr; }
+ /** this->context() try-casted to GrDirectContext. Useful for migrations – avoid otherwise! */
+ GrDirectContext* directContext() const;
+
#if SK_SUPPORT_GPU
virtual GrSemaphoresSubmitted onFlush(GrDirectContext*, const GrFlushInfo&) {
return GrSemaphoresSubmitted::kNo;
@@ -99,13 +107,14 @@
// return a read-only copy of the pixels. We promise to not modify them,
// but only inspect them (or encode them).
- virtual bool getROPixels(SkBitmap*, CachingHint = kAllow_CachingHint) const = 0;
+ virtual bool getROPixels(GrDirectContext*, SkBitmap*,
+ CachingHint = kAllow_CachingHint) const = 0;
virtual sk_sp<SkImage> onMakeSubset(const SkIRect&, GrDirectContext*) const = 0;
virtual sk_sp<SkData> onRefEncoded() const { return nullptr; }
- virtual bool onAsLegacyBitmap(SkBitmap*) const;
+ virtual bool onAsLegacyBitmap(GrDirectContext*, SkBitmap*) const;
// True for picture-backed and codec-backed
virtual bool onIsLazyGenerated() const { return false; }
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index 7461ab4..bf59d5e6 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -85,10 +85,10 @@
//////////////////////////////////////////////////////////////////////////////////////////////////
-bool SkImage_GpuBase::getROPixels(SkBitmap* dst, CachingHint chint) const {
- auto dContext = fContext->asDirectContext();
- if (!dContext) {
- // DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
+bool SkImage_GpuBase::getROPixels(GrDirectContext* dContext,
+ SkBitmap* dst,
+ CachingHint chint) const {
+ if (!fContext->priv().matches(dContext)) {
return false;
}
@@ -156,15 +156,15 @@
this->colorType(), this->alphaType(), this->refColorSpace());
}
-bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
- int srcX, int srcY, CachingHint) const {
- auto dContext = fContext->asDirectContext();
- if (!dContext) {
- // DDL TODO: buffer up the readback so it occurs when the DDL is drawn?
- return false;
- }
-
- if (!SkImageInfoValidConversion(dstInfo, this->imageInfo())) {
+bool SkImage_GpuBase::onReadPixels(GrDirectContext* dContext,
+ const SkImageInfo& dstInfo,
+ void* dstPixels,
+ size_t dstRB,
+ int srcX,
+ int srcY,
+ CachingHint) const {
+ if (!fContext->priv().matches(dContext)
+ || !SkImageInfoValidConversion(dstInfo, this->imageInfo())) {
return false;
}
diff --git a/src/image/SkImage_GpuBase.h b/src/image/SkImage_GpuBase.h
index acf9cdd..5efc46d 100644
--- a/src/image/SkImage_GpuBase.h
+++ b/src/image/SkImage_GpuBase.h
@@ -24,11 +24,16 @@
public:
GrContext* context() const final { return fContext.get(); }
- bool getROPixels(SkBitmap*, CachingHint) const final;
+ bool getROPixels(GrDirectContext*, SkBitmap*, CachingHint) const final;
sk_sp<SkImage> onMakeSubset(const SkIRect& subset, GrDirectContext*) const final;
- bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
- int srcX, int srcY, CachingHint) const override;
+ bool onReadPixels(GrDirectContext *dContext,
+ const SkImageInfo& dstInfo,
+ void* dstPixels,
+ size_t dstRB,
+ int srcX,
+ int srcY,
+ CachingHint) const override;
GrSurfaceProxyView refView(GrRecordingContext*, GrMipmapped) const final;
diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp
index da41d3a..b2dc9fa 100644
--- a/src/image/SkImage_Lazy.cpp
+++ b/src/image/SkImage_Lazy.cpp
@@ -129,7 +129,8 @@
//////////////////////////////////////////////////////////////////////////////////////////////////
-bool SkImage_Lazy::getROPixels(SkBitmap* bitmap, SkImage::CachingHint chint) const {
+bool SkImage_Lazy::getROPixels(GrDirectContext*, SkBitmap* bitmap,
+ SkImage::CachingHint chint) const {
auto check_output_bitmap = [bitmap]() {
SkASSERT(bitmap->isImmutable());
SkASSERT(bitmap->getPixels());
@@ -164,10 +165,15 @@
//////////////////////////////////////////////////////////////////////////////////////////////////
-bool SkImage_Lazy::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
- int srcX, int srcY, CachingHint chint) const {
+bool SkImage_Lazy::onReadPixels(GrDirectContext* dContext,
+ const SkImageInfo& dstInfo,
+ void* dstPixels,
+ size_t dstRB,
+ int srcX,
+ int srcY,
+ CachingHint chint) const {
SkBitmap bm;
- if (this->getROPixels(&bm, chint)) {
+ if (this->getROPixels(dContext, &bm, chint)) {
return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY);
}
return false;
@@ -438,7 +444,7 @@
* 3. Ask the generator to return YUV planes, which the GPU can convert
* 4. Ask the generator to return RGB(A) data, which the GPU can convert
*/
-GrSurfaceProxyView SkImage_Lazy::lockTextureProxyView(GrRecordingContext* ctx,
+GrSurfaceProxyView SkImage_Lazy::lockTextureProxyView(GrRecordingContext* rContext,
GrImageTexGenPolicy texGenPolicy,
GrMipmapped mipMapped) const {
// Values representing the various texture lock paths we can take. Used for logging the path
@@ -459,13 +465,13 @@
GrMakeKeyFromImageID(&key, this->uniqueID(), SkIRect::MakeSize(this->dimensions()));
}
- const GrCaps* caps = ctx->priv().caps();
- GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
+ const GrCaps* caps = rContext->priv().caps();
+ GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
auto installKey = [&](const GrSurfaceProxyView& view) {
SkASSERT(view && view.asTextureProxy());
if (key.isValid()) {
- auto listener = GrMakeUniqueKeyInvalidationListener(&key, ctx->priv().contextID());
+ auto listener = GrMakeUniqueKeyInvalidationListener(&key, rContext->priv().contextID());
this->addUniqueIDListener(std::move(listener));
proxyProvider->assignUniqueKeyToProxy(key, view.asTextureProxy());
}
@@ -488,7 +494,7 @@
// We need a mipped proxy, but we found a cached proxy that wasn't mipped. Thus we
// generate a new mipped surface and copy the original proxy into the base layer. We
// will then let the gpu generate the rest of the mips.
- auto mippedView = GrCopyBaseMipMapToView(ctx, view);
+ auto mippedView = GrCopyBaseMipMapToView(rContext, view);
if (!mippedView) {
// We failed to make a mipped proxy with the base copied into it. This could
// have been from failure to make the proxy or failure to do the copy. Thus we
@@ -505,7 +511,7 @@
// 2. Ask the generator to natively create one.
{
ScopedGenerator generator(fSharedGenerator);
- if (auto view = generator->generateTexture(ctx, this->imageInfo(), {0,0}, mipMapped,
+ if (auto view = generator->generateTexture(rContext, this->imageInfo(), {0,0}, mipMapped,
texGenPolicy)) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath,
kLockTexturePathCount);
@@ -516,13 +522,13 @@
// 3. Ask the generator to return YUV planes, which the GPU can convert. If we will be mipping
// the texture we skip this step so the CPU generate non-planar MIP maps for us.
- if (mipMapped == GrMipmapped::kNo && !ctx->priv().options().fDisableGpuYUVConversion) {
+ if (mipMapped == GrMipmapped::kNo && !rContext->priv().options().fDisableGpuYUVConversion) {
// TODO: Update to create the mipped surface in the textureProxyViewFromPlanes generator and
// draw the base layer directly into the mipped surface.
SkBudgeted budgeted = texGenPolicy == GrImageTexGenPolicy::kNew_Uncached_Unbudgeted
? SkBudgeted::kNo
: SkBudgeted::kYes;
- auto view = this->textureProxyViewFromPlanes(ctx, budgeted);
+ auto view = this->textureProxyViewFromPlanes(rContext, budgeted);
if (view) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath,
kLockTexturePathCount);
@@ -534,13 +540,13 @@
// 4. Ask the generator to return a bitmap, which the GPU can convert.
auto hint = texGenPolicy == GrImageTexGenPolicy::kDraw ? CachingHint::kAllow_CachingHint
: CachingHint::kDisallow_CachingHint;
- if (SkBitmap bitmap; this->getROPixels(&bitmap, hint)) {
+ if (SkBitmap bitmap; this->getROPixels(nullptr, &bitmap, hint)) {
// We always pass uncached here because we will cache it external to the maker based on
// *our* cache policy. We're just using the maker to generate the texture.
auto makerPolicy = texGenPolicy == GrImageTexGenPolicy::kNew_Uncached_Unbudgeted
? GrImageTexGenPolicy::kNew_Uncached_Unbudgeted
: GrImageTexGenPolicy::kNew_Uncached_Budgeted;
- GrBitmapTextureMaker bitmapMaker(ctx, bitmap, makerPolicy);
+ GrBitmapTextureMaker bitmapMaker(rContext, bitmap, makerPolicy);
auto view = bitmapMaker.view(mipMapped);
if (view) {
installKey(view);
diff --git a/src/image/SkImage_Lazy.h b/src/image/SkImage_Lazy.h
index 32bc01e..763d176 100644
--- a/src/image/SkImage_Lazy.h
+++ b/src/image/SkImage_Lazy.h
@@ -37,14 +37,14 @@
SkImage_Lazy(Validator* validator);
- bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY,
+ bool onReadPixels(GrDirectContext*, const SkImageInfo&, void*, size_t, int srcX, int srcY,
CachingHint) const override;
#if SK_SUPPORT_GPU
GrSurfaceProxyView refView(GrRecordingContext*, GrMipmapped) const override;
#endif
sk_sp<SkData> onRefEncoded() const override;
sk_sp<SkImage> onMakeSubset(const SkIRect&, GrDirectContext*) const override;
- bool getROPixels(SkBitmap*, CachingHint) const override;
+ bool getROPixels(GrDirectContext*, SkBitmap*, CachingHint) const override;
bool onIsLazyGenerated() const override { return true; }
sk_sp<SkImage> onMakeColorTypeAndColorSpace(SkColorType, sk_sp<SkColorSpace>,
GrDirectContext*) const override;
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index 8900e02..33d66c4 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -78,7 +78,7 @@
uint32_t id = kNeedNewImageUniqueID);
~SkImage_Raster() override;
- bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY,
+ bool onReadPixels(GrDirectContext*, const SkImageInfo&, void*, size_t, int srcX, int srcY,
CachingHint) const override;
bool onPeekPixels(SkPixmap*) const override;
const SkBitmap* onPeekBitmap() const override { return &fBitmap; }
@@ -87,12 +87,12 @@
GrSurfaceProxyView refView(GrRecordingContext*, GrMipmapped) const override;
#endif
- bool getROPixels(SkBitmap*, CachingHint) const override;
+ bool getROPixels(GrDirectContext*, SkBitmap*, CachingHint) const override;
sk_sp<SkImage> onMakeSubset(const SkIRect&, GrDirectContext*) const override;
SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
- bool onAsLegacyBitmap(SkBitmap*) const override;
+ bool onAsLegacyBitmap(GrDirectContext*, SkBitmap*) const override;
SkImage_Raster(const SkBitmap& bm, bool bitmapMayBeMutable = false)
: INHERITED(bm.info(),
@@ -168,8 +168,13 @@
#endif
}
-bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
- int srcX, int srcY, CachingHint) const {
+bool SkImage_Raster::onReadPixels(GrDirectContext*,
+ const SkImageInfo& dstInfo,
+ void* dstPixels,
+ size_t dstRowBytes,
+ int srcX,
+ int srcY,
+ CachingHint) const {
SkBitmap shallowCopy(fBitmap);
return shallowCopy.readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
}
@@ -178,7 +183,7 @@
return fBitmap.peekPixels(pm);
}
-bool SkImage_Raster::getROPixels(SkBitmap* dst, CachingHint) const {
+bool SkImage_Raster::getROPixels(GrDirectContext*, SkBitmap* dst, CachingHint) const {
*dst = fBitmap;
return true;
}
@@ -367,7 +372,7 @@
return ((const SkImage_Raster*)image)->getPixelRef();
}
-bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap) const {
+bool SkImage_Raster::onAsLegacyBitmap(GrDirectContext*, SkBitmap* bitmap) const {
// When we're a snapshot from a surface, our bitmap may not be marked immutable
// even though logically always we are, but in that case we can't physically share our
// pixelref since the caller might call setImmutable() themselves
@@ -378,7 +383,7 @@
bitmap->setPixelRef(sk_ref_sp(fBitmap.pixelRef()), origin.x(), origin.y());
return true;
}
- return this->INHERITED::onAsLegacyBitmap(bitmap);
+ return this->INHERITED::onAsLegacyBitmap(nullptr, bitmap);
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/image/SkRescaleAndReadPixels.cpp b/src/image/SkRescaleAndReadPixels.cpp
index 0b7ee2e..2c3e4f0 100644
--- a/src/image/SkRescaleAndReadPixels.cpp
+++ b/src/image/SkRescaleAndReadPixels.cpp
@@ -119,7 +119,7 @@
size_t rowBytes = resultInfo.minRowBytes();
std::unique_ptr<char[]> data(new char[resultInfo.height() * rowBytes]);
SkPixmap pm(resultInfo, data.get(), rowBytes);
- if (srcImage->readPixels(pm, srcX, srcY)) {
+ if (srcImage->readPixels(nullptr, pm, srcX, srcY)) {
class Result : public SkImage::AsyncReadResult {
public:
Result(std::unique_ptr<const char[]> data, size_t rowBytes)
diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp
index bee6336..db9bbd1 100644
--- a/src/pdf/SkPDFBitmap.cpp
+++ b/src/pdf/SkPDFBitmap.cpp
@@ -239,7 +239,8 @@
bm.allocPixels(SkImageInfo::Make(w, h, kBGRA_8888_SkColorType, at));
}
}
- if (!image->readPixels(bm.pixmap(), 0, 0)) {
+ // TODO: support GPU images in PDFs
+ if (!image->readPixels(nullptr, bm.pixmap(), 0, 0)) {
bm.eraseColor(SkColorSetARGB(0xFF, 0, 0, 0));
}
return bm;
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 6601802..96d5c72 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -131,7 +131,8 @@
int w = mask->width(), h = mask->height();
SkBitmap greyBitmap;
greyBitmap.allocPixels(SkImageInfo::Make(w, h, kGray_8_SkColorType, kOpaque_SkAlphaType));
- if (!mask->readPixels(SkImageInfo::MakeA8(w, h),
+ // TODO: support gpu images in pdf
+ if (!mask->readPixels(nullptr, SkImageInfo::MakeA8(w, h),
greyBitmap.getPixels(), greyBitmap.rowBytes(), 0, 0)) {
return nullptr;
}
diff --git a/src/pdf/SkPDFUtils.cpp b/src/pdf/SkPDFUtils.cpp
index 306709c..9d1c13a 100644
--- a/src/pdf/SkPDFUtils.cpp
+++ b/src/pdf/SkPDFUtils.cpp
@@ -334,7 +334,8 @@
SkASSERT(img);
SkASSERT(dst);
SkBitmap bitmap;
- if(as_IB(img)->getROPixels(&bitmap)) {
+ // TODO: support GPU images
+ if(as_IB(img)->getROPixels(nullptr, &bitmap)) {
SkASSERT(bitmap.dimensions() == img->dimensions());
SkASSERT(!bitmap.drawsNothing());
*dst = std::move(bitmap);
diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp
index f150f5c..bc8b675 100755
--- a/src/shaders/SkImageShader.cpp
+++ b/src/shaders/SkImageShader.cpp
@@ -362,7 +362,7 @@
} else if (fImage->isLazyGenerated()) {
producer = new (&storage)
GrImageTextureMaker(args.fContext, fImage.get(), GrImageTexGenPolicy::kDraw);
- } else if (as_IB(fImage)->getROPixels(&bm)) {
+ } else if (as_IB(fImage)->getROPixels(nullptr, &bm)) {
producer =
new (&storage) GrBitmapTextureMaker(args.fContext, bm, GrImageTexGenPolicy::kDraw);
} else {
diff --git a/src/svg/SkSVGDevice.cpp b/src/svg/SkSVGDevice.cpp
index 41d0f92..ba26e90 100644
--- a/src/svg/SkSVGDevice.cpp
+++ b/src/svg/SkSVGDevice.cpp
@@ -951,7 +951,8 @@
void SkSVGDevice::drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) {
SkBitmap bm;
- if (!as_IB(image)->getROPixels(&bm)) {
+ // TODO: support gpu images
+ if (!as_IB(image)->getROPixels(nullptr, &bm)) {
return;
}
diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp
index ec4ba68..53047f9 100644
--- a/src/xps/SkXPSDevice.cpp
+++ b/src/xps/SkXPSDevice.cpp
@@ -2009,8 +2009,9 @@
const SkRect& dst,
const SkPaint& paint,
SkCanvas::SrcRectConstraint constraint) {
+ // TODO: support gpu images
SkBitmap bitmap;
- if (!as_IB(image)->getROPixels(&bitmap)) {
+ if (!as_IB(image)->getROPixels(nullptr, &bitmap)) {
return;
}