Consolidate on SkImage_Gpu constructor that takes SkColorInfo.

Also take SkImageInfo in SkImage_GpuBase.

Change-Id: Ie6d71a9a4a3740b9acc0faae72df2796e9a0e567
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/398230
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2021-04-20 16:52:11 -04:00 committed by Skia Commit-Bot
parent af5afed000
commit 9a56eb7063
9 changed files with 93 additions and 94 deletions

View File

@ -138,8 +138,10 @@ static sk_sp<SkImage> make_reference_image(GrDirectContext* context,
return nullptr; return nullptr;
} }
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, std::move(view), return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context),
ii.colorType(), kOpaque_SkAlphaType, nullptr); kNeedNewImageUniqueID,
std::move(view),
ii.colorInfo());
} }
// Here we're converting from a matrix that is intended for UVs to a matrix that is intended // Here we're converting from a matrix that is intended for UVs to a matrix that is intended

View File

@ -324,8 +324,9 @@ static sk_sp<SkImage> wrap_proxy_in_image(GrRecordingContext* context, GrSurface
SkColorType colorType, SkAlphaType alphaType, SkColorType colorType, SkAlphaType alphaType,
sk_sp<SkColorSpace> colorSpace) { sk_sp<SkColorSpace> colorSpace) {
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context),
kNeedNewImageUniqueID, std::move(view), colorType, alphaType, kNeedNewImageUniqueID,
std::move(colorSpace)); std::move(view),
SkColorInfo(colorType, alphaType, std::move(colorSpace)));
} }
class SkSpecialImage_Gpu : public SkSpecialImage_Base { class SkSpecialImage_Gpu : public SkSpecialImage_Base {
@ -360,10 +361,11 @@ public:
// instantiates itself it is going to have to either be okay with having a larger // instantiates itself it is going to have to either be okay with having a larger
// than expected backing texture (unlikely) or the 'fit' of the SurfaceProxy needs // than expected backing texture (unlikely) or the 'fit' of the SurfaceProxy needs
// to be tightened (if it is deferred). // to be tightened (if it is deferred).
sk_sp<SkImage> img = sk_sp<SkImage> img = sk_sp<SkImage>(
sk_sp<SkImage>(new SkImage_Gpu(sk_ref_sp(canvas->recordingContext()), new SkImage_Gpu(sk_ref_sp(canvas->recordingContext()),
this->uniqueID(), fView, this->colorType(), this->uniqueID(),
fAlphaType, fColorSpace)); fView,
SkColorInfo(this->colorType(), fAlphaType, fColorSpace)));
canvas->drawImageRect(img, SkRect::Make(this->subset()), dst, canvas->drawImageRect(img, SkRect::Make(this->subset()), dst,
sampling, paint, SkCanvas::kStrict_SrcRectConstraint); sampling, paint, SkCanvas::kStrict_SrcRectConstraint);

View File

@ -178,9 +178,10 @@ sk_sp<SkImage> GrDirectContextPriv::testingOnly_getFontAtlasImage(GrMaskFormat f
SkColorType colorType = GrColorTypeToSkColorType(GrMaskFormatToColorType(format)); SkColorType colorType = GrColorTypeToSkColorType(GrMaskFormatToColorType(format));
SkASSERT(views[index].proxy()->priv().isExact()); SkASSERT(views[index].proxy()->priv().isExact());
sk_sp<SkImage> image(new SkImage_Gpu(sk_ref_sp(fContext), kNeedNewImageUniqueID, return sk_make_sp<SkImage_Gpu>(sk_ref_sp(fContext),
views[index], colorType, kPremul_SkAlphaType, nullptr)); kNeedNewImageUniqueID,
return image; views[index],
SkColorInfo(colorType, kPremul_SkAlphaType, nullptr));
} }
void GrDirectContextPriv::testingOnly_purgeAllUnlockedResources() { void GrDirectContextPriv::testingOnly_purgeAllUnlockedResources() {

View File

@ -146,15 +146,10 @@ inline GrBackendFormat SkImage_Gpu::ProxyChooser::backendFormat() {
SkImage_Gpu::SkImage_Gpu(sk_sp<GrImageContext> context, SkImage_Gpu::SkImage_Gpu(sk_sp<GrImageContext> context,
uint32_t uniqueID, uint32_t uniqueID,
GrSurfaceProxyView view, GrSurfaceProxyView view,
SkColorType ct, SkColorInfo info)
SkAlphaType at,
sk_sp<SkColorSpace> colorSpace)
: INHERITED(std::move(context), : INHERITED(std::move(context),
view.proxy()->backingStoreDimensions(), SkImageInfo::Make(view.proxy()->backingStoreDimensions(), std::move(info)),
uniqueID, uniqueID)
ct,
at,
std::move(colorSpace))
, fChooser(view.detachProxy()) , fChooser(view.detachProxy())
, fSwizzle(view.swizzle()) , fSwizzle(view.swizzle())
, fOrigin(view.origin()) { , fOrigin(view.origin()) {
@ -172,13 +167,11 @@ SkImage_Gpu::SkImage_Gpu(sk_sp<GrDirectContext> dContext,
sk_sp<GrSurfaceProxy> stableCopy, sk_sp<GrSurfaceProxy> stableCopy,
sk_sp<GrRenderTask> copyTask, sk_sp<GrRenderTask> copyTask,
int volatileSrcTargetCount, int volatileSrcTargetCount,
SkColorInfo colorInfo) SkColorInfo info)
: INHERITED(std::move(dContext), : INHERITED(std::move(dContext),
volatileSrc.proxy()->backingStoreDimensions(), SkImageInfo::Make(volatileSrc.proxy()->backingStoreDimensions(),
kNeedNewImageUniqueID, std::move(info)),
colorInfo.colorType(), kNeedNewImageUniqueID)
colorInfo.alphaType(),
colorInfo.refColorSpace())
, fChooser(std::move(stableCopy), , fChooser(std::move(stableCopy),
volatileSrc.detachProxy(), volatileSrc.detachProxy(),
std::move(copyTask), std::move(copyTask),
@ -297,31 +290,34 @@ size_t SkImage_Gpu::onTextureSize() const { return fChooser.gpuMemorySize(); }
sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(SkColorType targetCT, sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(SkColorType targetCT,
sk_sp<SkColorSpace> targetCS, sk_sp<SkColorSpace> targetCS,
GrDirectContext* direct) const { GrDirectContext* direct) const {
SkColorInfo info(targetCT, this->alphaType(), std::move(targetCS));
if (!fContext->priv().matches(direct)) { if (!fContext->priv().matches(direct)) {
return nullptr; return nullptr;
} }
auto info = this->imageInfo().makeColorType(targetCT).makeColorSpace(targetCS); auto surfaceFillContext = GrSurfaceFillContext::MakeWithFallback(
auto surfaceFillContext = GrSurfaceFillContext::MakeWithFallback(direct, direct,
std::move(info), GrImageInfo(info, this->dimensions()),
SkBackingFit::kExact); SkBackingFit::kExact);
if (!surfaceFillContext) { if (!surfaceFillContext) {
return nullptr; return nullptr;
} }
auto [view, ct] = this->asView(direct, GrMipmapped(this->hasMipmaps())); // We respecify info's CT because we called MakeWithFallback.
auto ct = GrColorTypeToSkColorType(surfaceFillContext->colorInfo().colorType());
info = info.makeColorType(ct);
// Draw this image's texture into the SFC.
auto [view, _] = this->asView(direct, GrMipmapped(this->hasMipmaps()));
auto texFP = GrTextureEffect::Make(std::move(view), this->alphaType()); auto texFP = GrTextureEffect::Make(std::move(view), this->alphaType());
auto colorFP = GrColorSpaceXformEffect::Make(std::move(texFP), auto colorFP = GrColorSpaceXformEffect::Make(std::move(texFP),
this->colorSpace(), this->alphaType(), this->imageInfo().colorInfo(),
targetCS.get(), this->alphaType()); info);
SkASSERT(colorFP);
surfaceFillContext->fillWithFP(std::move(colorFP)); surfaceFillContext->fillWithFP(std::move(colorFP));
SkASSERT(surfaceFillContext->asTextureProxy());
targetCT = GrColorTypeToSkColorType(surfaceFillContext->colorInfo().colorType()); return sk_make_sp<SkImage_Gpu>(sk_ref_sp(direct),
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(direct), kNeedNewImageUniqueID, kNeedNewImageUniqueID,
surfaceFillContext->readSurfaceView(), targetCT, surfaceFillContext->readSurfaceView(),
this->alphaType(), std::move(targetCS)); std::move(info));
} }
sk_sp<SkImage> SkImage_Gpu::onReinterpretColorSpace(sk_sp<SkColorSpace> newCS) const { sk_sp<SkImage> SkImage_Gpu::onReinterpretColorSpace(sk_sp<SkColorSpace> newCS) const {
@ -331,9 +327,7 @@ sk_sp<SkImage> SkImage_Gpu::onReinterpretColorSpace(sk_sp<SkColorSpace> newCS) c
return sk_make_sp<SkImage_Gpu>(fContext, return sk_make_sp<SkImage_Gpu>(fContext,
kNeedNewImageUniqueID, kNeedNewImageUniqueID,
std::move(view), std::move(view),
this->colorType(), this->imageInfo().colorInfo().makeColorSpace(std::move(newCS)));
this->alphaType(),
std::move(newCS));
} }
void SkImage_Gpu::onAsyncRescaleAndReadPixels(const SkImageInfo& info, void SkImage_Gpu::onAsyncRescaleAndReadPixels(const SkImageInfo& info,
@ -397,8 +391,10 @@ void SkImage_Gpu::generatingSurfaceIsDeleted() { fChooser.makeVolatileProxyStabl
static sk_sp<SkImage> new_wrapped_texture_common(GrRecordingContext* rContext, static sk_sp<SkImage> new_wrapped_texture_common(GrRecordingContext* rContext,
const GrBackendTexture& backendTex, const GrBackendTexture& backendTex,
GrColorType colorType, GrSurfaceOrigin origin, GrColorType colorType,
SkAlphaType at, sk_sp<SkColorSpace> colorSpace, GrSurfaceOrigin origin,
SkAlphaType at,
sk_sp<SkColorSpace> colorSpace,
GrWrapOwnership ownership, GrWrapOwnership ownership,
sk_sp<GrRefCntedCallback> releaseHelper) { sk_sp<GrRefCntedCallback> releaseHelper) {
if (!backendTex.isValid() || backendTex.width() <= 0 || backendTex.height() <= 0) { if (!backendTex.isValid() || backendTex.width() <= 0 || backendTex.height() <= 0) {
@ -414,8 +410,11 @@ static sk_sp<SkImage> new_wrapped_texture_common(GrRecordingContext* rContext,
GrSwizzle swizzle = rContext->priv().caps()->getReadSwizzle(proxy->backendFormat(), colorType); GrSwizzle swizzle = rContext->priv().caps()->getReadSwizzle(proxy->backendFormat(), colorType);
GrSurfaceProxyView view(std::move(proxy), origin, swizzle); GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(rContext), kNeedNewImageUniqueID, std::move(view), SkColorInfo info(GrColorTypeToSkColorType(colorType), at, std::move(colorSpace));
GrColorTypeToSkColorType(colorType), at, std::move(colorSpace)); return sk_make_sp<SkImage_Gpu>(sk_ref_sp(rContext),
kNeedNewImageUniqueID,
std::move(view),
std::move(info));
} }
sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrRecordingContext* rContext, sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrRecordingContext* rContext,
@ -448,8 +447,10 @@ sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrRecordingContext* rContext,
SkColorType ct = GrCompressionTypeToSkColorType(type); SkColorType ct = GrCompressionTypeToSkColorType(type);
GrSurfaceProxyView view(std::move(proxy), origin, GrSwizzle::RGBA()); GrSurfaceProxyView view(std::move(proxy), origin, GrSwizzle::RGBA());
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(rContext), kNeedNewImageUniqueID, std::move(view), return sk_make_sp<SkImage_Gpu>(sk_ref_sp(rContext),
ct, at, std::move(cs)); kNeedNewImageUniqueID,
std::move(view),
SkColorInfo(ct, at, std::move(cs)));
} }
sk_sp<SkImage> SkImage::MakeFromTexture(GrRecordingContext* rContext, sk_sp<SkImage> SkImage::MakeFromTexture(GrRecordingContext* rContext,
@ -529,8 +530,10 @@ sk_sp<SkImage> SkImage::MakeTextureFromCompressed(GrDirectContext* direct, sk_sp
SkColorType colorType = GrCompressionTypeToSkColorType(type); SkColorType colorType = GrCompressionTypeToSkColorType(type);
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(direct), kNeedNewImageUniqueID, std::move(view), return sk_make_sp<SkImage_Gpu>(sk_ref_sp(direct),
colorType, kOpaque_SkAlphaType, nullptr); kNeedNewImageUniqueID,
std::move(view),
SkColorInfo(colorType, kOpaque_SkAlphaType, nullptr));
} }
sk_sp<SkImage> SkImage::makeTextureImage(GrDirectContext* dContext, sk_sp<SkImage> SkImage::makeTextureImage(GrDirectContext* dContext,
@ -624,8 +627,10 @@ sk_sp<SkImage> SkImage::MakePromiseTexture(sk_sp<GrContextThreadSafeProxy> threa
GrSwizzle swizzle = threadSafeProxy->priv().caps()->getReadSwizzle(backendFormat, grColorType); GrSwizzle swizzle = threadSafeProxy->priv().caps()->getReadSwizzle(backendFormat, grColorType);
GrSurfaceProxyView view(std::move(proxy), origin, swizzle); GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
sk_sp<GrImageContext> ctx(GrImageContextPriv::MakeForPromiseImage(std::move(threadSafeProxy))); sk_sp<GrImageContext> ctx(GrImageContextPriv::MakeForPromiseImage(std::move(threadSafeProxy)));
return sk_make_sp<SkImage_Gpu>(std::move(ctx), kNeedNewImageUniqueID, std::move(view), return sk_make_sp<SkImage_Gpu>(std::move(ctx),
colorType, alphaType, std::move(colorSpace)); kNeedNewImageUniqueID,
std::move(view),
SkColorInfo(colorType, alphaType, std::move(colorSpace)));
} }
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
@ -747,12 +752,11 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrDirectContext* dContex
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(backendFormat, grColorType); GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(backendFormat, grColorType);
GrSurfaceProxyView framebufferView(std::move(proxy), surfaceOrigin, swizzle); GrSurfaceProxyView framebufferView(std::move(proxy), surfaceOrigin, swizzle);
SkColorInfo colorInfo = pixmap.info().colorInfo().makeColorType(colorType);
sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(dContext), sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(dContext),
kNeedNewImageUniqueID, kNeedNewImageUniqueID,
framebufferView, framebufferView,
colorType, std::move(colorInfo));
pixmap.alphaType(),
pixmap.refColorSpace());
if (!image) { if (!image) {
return nullptr; return nullptr;
} }

View File

@ -23,18 +23,10 @@ class SkBitmap;
class SkImage_Gpu final : public SkImage_GpuBase { class SkImage_Gpu final : public SkImage_GpuBase {
public: public:
SkImage_Gpu(sk_sp<GrImageContext>, uint32_t uniqueID, GrSurfaceProxyView, SkColorType,
SkAlphaType, sk_sp<SkColorSpace>);
SkImage_Gpu(sk_sp<GrImageContext> context, SkImage_Gpu(sk_sp<GrImageContext> context,
uint32_t uniqueID, uint32_t uniqueID,
GrSurfaceProxyView view, GrSurfaceProxyView view,
SkColorInfo info) SkColorInfo info);
: SkImage_Gpu(std::move(context),
uniqueID,
std::move(view),
info.colorType(),
info.alphaType(),
info.refColorSpace()) {}
static sk_sp<SkImage> MakeWithVolatileSrc(sk_sp<GrRecordingContext> rContext, static sk_sp<SkImage> MakeWithVolatileSrc(sk_sp<GrRecordingContext> rContext,
GrSurfaceProxyView volatileSrc, GrSurfaceProxyView volatileSrc,

View File

@ -28,9 +28,8 @@
#include "src/image/SkImage_Gpu.h" #include "src/image/SkImage_Gpu.h"
#include "src/image/SkReadPixelsRec.h" #include "src/image/SkReadPixelsRec.h"
SkImage_GpuBase::SkImage_GpuBase(sk_sp<GrImageContext> context, SkISize size, uint32_t uniqueID, SkImage_GpuBase::SkImage_GpuBase(sk_sp<GrImageContext> context, SkImageInfo info, uint32_t uniqueID)
SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs) : INHERITED(std::move(info), uniqueID)
: INHERITED(SkImageInfo::Make(size, ct, at, std::move(cs)), uniqueID)
, fContext(std::move(context)) {} , fContext(std::move(context)) {}
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -53,8 +53,7 @@ public:
sk_sp<GrRefCntedCallback> releaseHelper); sk_sp<GrRefCntedCallback> releaseHelper);
protected: protected:
SkImage_GpuBase(sk_sp<GrImageContext>, SkISize size, uint32_t uniqueID, SkColorType, SkImage_GpuBase(sk_sp<GrImageContext>, SkImageInfo, uint32_t uniqueID);
SkAlphaType, sk_sp<SkColorSpace>);
sk_sp<GrImageContext> fContext; sk_sp<GrImageContext> fContext;

View File

@ -39,14 +39,16 @@ SkImage_GpuYUVA::SkImage_GpuYUVA(sk_sp<GrImageContext> context,
GrYUVATextureProxies proxies, GrYUVATextureProxies proxies,
sk_sp<SkColorSpace> imageColorSpace) sk_sp<SkColorSpace> imageColorSpace)
: INHERITED(std::move(context), : INHERITED(std::move(context),
proxies.yuvaInfo().dimensions(), SkImageInfo::Make(proxies.yuvaInfo().dimensions(),
uniqueID, kAssumedColorType,
kAssumedColorType, // If an alpha channel is present we always use kPremul. This
// If an alpha channel is present we always use kPremul. This is because, // is because, although the planar data is always un-premul,
// although the planar data is always un-premul, the final interleaved RGB image // the final interleaved RGBA sample produced in the shader
// is/would-be premul. // is premul (and similar if flattened via asView).
proxies.yuvaInfo().hasAlpha() ? kPremul_SkAlphaType : kOpaque_SkAlphaType, proxies.yuvaInfo().hasAlpha() ? kPremul_SkAlphaType
std::move(imageColorSpace)) : kOpaque_SkAlphaType,
std::move(imageColorSpace)),
uniqueID)
, fYUVAProxies(std::move(proxies)) { , fYUVAProxies(std::move(proxies)) {
// The caller should have checked this, just verifying. // The caller should have checked this, just verifying.
SkASSERT(fYUVAProxies.isValid()); SkASSERT(fYUVAProxies.isValid());
@ -57,11 +59,8 @@ SkImage_GpuYUVA::SkImage_GpuYUVA(sk_sp<GrImageContext> context,
const SkImage_GpuYUVA* image, const SkImage_GpuYUVA* image,
sk_sp<SkColorSpace> targetCS) sk_sp<SkColorSpace> targetCS)
: INHERITED(std::move(context), : INHERITED(std::move(context),
image->dimensions(), image->imageInfo().makeColorSpace(std::move(targetCS)),
kNeedNewImageUniqueID, kNeedNewImageUniqueID)
kAssumedColorType,
image->alphaType(),
std::move(targetCS))
, fYUVAProxies(image->fYUVAProxies) , fYUVAProxies(image->fYUVAProxies)
// Since null fFromColorSpace means no GrColorSpaceXform, we turn a null // Since null fFromColorSpace means no GrColorSpaceXform, we turn a null
// image->refColorSpace() into an explicit SRGB. // image->refColorSpace() into an explicit SRGB.

View File

@ -135,16 +135,16 @@ sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(const SkIRect* subset) {
} }
const SkImageInfo info = fDevice->imageInfo(); const SkImageInfo info = fDevice->imageInfo();
sk_sp<SkImage> image; if (!srcView.asTextureProxy()) {
if (srcView.asTextureProxy()) { return nullptr;
// The surfaceDrawContext coming out of SkGpuDevice should always be exact and the
// above copy creates a kExact surfaceContext.
SkASSERT(srcView.proxy()->priv().isExact());
image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(rContext), kNeedNewImageUniqueID,
std::move(srcView), info.colorType(), info.alphaType(),
info.refColorSpace());
} }
return image; // The surfaceDrawContext coming out of SkGpuDevice should always be exact and the
// above copy creates a kExact surfaceContext.
SkASSERT(srcView.proxy()->priv().isExact());
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(rContext),
kNeedNewImageUniqueID,
std::move(srcView),
info.colorInfo());
} }
void SkSurface_Gpu::onWritePixels(const SkPixmap& src, int x, int y) { void SkSurface_Gpu::onWritePixels(const SkPixmap& src, int x, int y) {
@ -303,9 +303,10 @@ void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
const SkImageInfo info = fDevice->imageInfo(); const SkImageInfo info = fDevice->imageInfo();
GrSurfaceProxyView view(std::move(srcProxy), sdc->origin(), sdc->readSwizzle()); GrSurfaceProxyView view(std::move(srcProxy), sdc->origin(), sdc->readSwizzle());
sk_sp<SkImage> image; sk_sp<SkImage> image;
image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(canvasContext), kNeedNewImageUniqueID, image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(canvasContext),
std::move(view), info.colorType(), info.alphaType(), kNeedNewImageUniqueID,
info.refColorSpace()); std::move(view),
info.colorInfo());
canvas->drawImage(image.get(), x, y, sampling, paint); canvas->drawImage(image.get(), x, y, sampling, paint);
return true; return true;
}; };