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:
parent
af5afed000
commit
9a56eb7063
@ -138,8 +138,10 @@ static sk_sp<SkImage> make_reference_image(GrDirectContext* context,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, std::move(view),
|
||||
ii.colorType(), kOpaque_SkAlphaType, nullptr);
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context),
|
||||
kNeedNewImageUniqueID,
|
||||
std::move(view),
|
||||
ii.colorInfo());
|
||||
}
|
||||
|
||||
// Here we're converting from a matrix that is intended for UVs to a matrix that is intended
|
||||
|
@ -324,8 +324,9 @@ static sk_sp<SkImage> wrap_proxy_in_image(GrRecordingContext* context, GrSurface
|
||||
SkColorType colorType, SkAlphaType alphaType,
|
||||
sk_sp<SkColorSpace> colorSpace) {
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context),
|
||||
kNeedNewImageUniqueID, std::move(view), colorType, alphaType,
|
||||
std::move(colorSpace));
|
||||
kNeedNewImageUniqueID,
|
||||
std::move(view),
|
||||
SkColorInfo(colorType, alphaType, std::move(colorSpace)));
|
||||
}
|
||||
|
||||
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
|
||||
// than expected backing texture (unlikely) or the 'fit' of the SurfaceProxy needs
|
||||
// to be tightened (if it is deferred).
|
||||
sk_sp<SkImage> img =
|
||||
sk_sp<SkImage>(new SkImage_Gpu(sk_ref_sp(canvas->recordingContext()),
|
||||
this->uniqueID(), fView, this->colorType(),
|
||||
fAlphaType, fColorSpace));
|
||||
sk_sp<SkImage> img = sk_sp<SkImage>(
|
||||
new SkImage_Gpu(sk_ref_sp(canvas->recordingContext()),
|
||||
this->uniqueID(),
|
||||
fView,
|
||||
SkColorInfo(this->colorType(), fAlphaType, fColorSpace)));
|
||||
|
||||
canvas->drawImageRect(img, SkRect::Make(this->subset()), dst,
|
||||
sampling, paint, SkCanvas::kStrict_SrcRectConstraint);
|
||||
|
@ -178,9 +178,10 @@ sk_sp<SkImage> GrDirectContextPriv::testingOnly_getFontAtlasImage(GrMaskFormat f
|
||||
|
||||
SkColorType colorType = GrColorTypeToSkColorType(GrMaskFormatToColorType(format));
|
||||
SkASSERT(views[index].proxy()->priv().isExact());
|
||||
sk_sp<SkImage> image(new SkImage_Gpu(sk_ref_sp(fContext), kNeedNewImageUniqueID,
|
||||
views[index], colorType, kPremul_SkAlphaType, nullptr));
|
||||
return image;
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(fContext),
|
||||
kNeedNewImageUniqueID,
|
||||
views[index],
|
||||
SkColorInfo(colorType, kPremul_SkAlphaType, nullptr));
|
||||
}
|
||||
|
||||
void GrDirectContextPriv::testingOnly_purgeAllUnlockedResources() {
|
||||
|
@ -146,15 +146,10 @@ inline GrBackendFormat SkImage_Gpu::ProxyChooser::backendFormat() {
|
||||
SkImage_Gpu::SkImage_Gpu(sk_sp<GrImageContext> context,
|
||||
uint32_t uniqueID,
|
||||
GrSurfaceProxyView view,
|
||||
SkColorType ct,
|
||||
SkAlphaType at,
|
||||
sk_sp<SkColorSpace> colorSpace)
|
||||
SkColorInfo info)
|
||||
: INHERITED(std::move(context),
|
||||
view.proxy()->backingStoreDimensions(),
|
||||
uniqueID,
|
||||
ct,
|
||||
at,
|
||||
std::move(colorSpace))
|
||||
SkImageInfo::Make(view.proxy()->backingStoreDimensions(), std::move(info)),
|
||||
uniqueID)
|
||||
, fChooser(view.detachProxy())
|
||||
, fSwizzle(view.swizzle())
|
||||
, fOrigin(view.origin()) {
|
||||
@ -172,13 +167,11 @@ SkImage_Gpu::SkImage_Gpu(sk_sp<GrDirectContext> dContext,
|
||||
sk_sp<GrSurfaceProxy> stableCopy,
|
||||
sk_sp<GrRenderTask> copyTask,
|
||||
int volatileSrcTargetCount,
|
||||
SkColorInfo colorInfo)
|
||||
SkColorInfo info)
|
||||
: INHERITED(std::move(dContext),
|
||||
volatileSrc.proxy()->backingStoreDimensions(),
|
||||
kNeedNewImageUniqueID,
|
||||
colorInfo.colorType(),
|
||||
colorInfo.alphaType(),
|
||||
colorInfo.refColorSpace())
|
||||
SkImageInfo::Make(volatileSrc.proxy()->backingStoreDimensions(),
|
||||
std::move(info)),
|
||||
kNeedNewImageUniqueID)
|
||||
, fChooser(std::move(stableCopy),
|
||||
volatileSrc.detachProxy(),
|
||||
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<SkColorSpace> targetCS,
|
||||
GrDirectContext* direct) const {
|
||||
SkColorInfo info(targetCT, this->alphaType(), std::move(targetCS));
|
||||
if (!fContext->priv().matches(direct)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto info = this->imageInfo().makeColorType(targetCT).makeColorSpace(targetCS);
|
||||
auto surfaceFillContext = GrSurfaceFillContext::MakeWithFallback(direct,
|
||||
std::move(info),
|
||||
SkBackingFit::kExact);
|
||||
auto surfaceFillContext = GrSurfaceFillContext::MakeWithFallback(
|
||||
direct,
|
||||
GrImageInfo(info, this->dimensions()),
|
||||
SkBackingFit::kExact);
|
||||
if (!surfaceFillContext) {
|
||||
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 colorFP = GrColorSpaceXformEffect::Make(std::move(texFP),
|
||||
this->colorSpace(), this->alphaType(),
|
||||
targetCS.get(), this->alphaType());
|
||||
SkASSERT(colorFP);
|
||||
|
||||
this->imageInfo().colorInfo(),
|
||||
info);
|
||||
surfaceFillContext->fillWithFP(std::move(colorFP));
|
||||
SkASSERT(surfaceFillContext->asTextureProxy());
|
||||
|
||||
targetCT = GrColorTypeToSkColorType(surfaceFillContext->colorInfo().colorType());
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(direct), kNeedNewImageUniqueID,
|
||||
surfaceFillContext->readSurfaceView(), targetCT,
|
||||
this->alphaType(), std::move(targetCS));
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(direct),
|
||||
kNeedNewImageUniqueID,
|
||||
surfaceFillContext->readSurfaceView(),
|
||||
std::move(info));
|
||||
}
|
||||
|
||||
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,
|
||||
kNeedNewImageUniqueID,
|
||||
std::move(view),
|
||||
this->colorType(),
|
||||
this->alphaType(),
|
||||
std::move(newCS));
|
||||
this->imageInfo().colorInfo().makeColorSpace(std::move(newCS)));
|
||||
}
|
||||
|
||||
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,
|
||||
const GrBackendTexture& backendTex,
|
||||
GrColorType colorType, GrSurfaceOrigin origin,
|
||||
SkAlphaType at, sk_sp<SkColorSpace> colorSpace,
|
||||
GrColorType colorType,
|
||||
GrSurfaceOrigin origin,
|
||||
SkAlphaType at,
|
||||
sk_sp<SkColorSpace> colorSpace,
|
||||
GrWrapOwnership ownership,
|
||||
sk_sp<GrRefCntedCallback> releaseHelper) {
|
||||
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);
|
||||
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(rContext), kNeedNewImageUniqueID, std::move(view),
|
||||
GrColorTypeToSkColorType(colorType), at, std::move(colorSpace));
|
||||
SkColorInfo info(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,
|
||||
@ -448,8 +447,10 @@ sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrRecordingContext* rContext,
|
||||
SkColorType ct = GrCompressionTypeToSkColorType(type);
|
||||
|
||||
GrSurfaceProxyView view(std::move(proxy), origin, GrSwizzle::RGBA());
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(rContext), kNeedNewImageUniqueID, std::move(view),
|
||||
ct, at, std::move(cs));
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(rContext),
|
||||
kNeedNewImageUniqueID,
|
||||
std::move(view),
|
||||
SkColorInfo(ct, at, std::move(cs)));
|
||||
}
|
||||
|
||||
sk_sp<SkImage> SkImage::MakeFromTexture(GrRecordingContext* rContext,
|
||||
@ -529,8 +530,10 @@ sk_sp<SkImage> SkImage::MakeTextureFromCompressed(GrDirectContext* direct, sk_sp
|
||||
|
||||
SkColorType colorType = GrCompressionTypeToSkColorType(type);
|
||||
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(direct), kNeedNewImageUniqueID, std::move(view),
|
||||
colorType, kOpaque_SkAlphaType, nullptr);
|
||||
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(direct),
|
||||
kNeedNewImageUniqueID,
|
||||
std::move(view),
|
||||
SkColorInfo(colorType, kOpaque_SkAlphaType, nullptr));
|
||||
}
|
||||
|
||||
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);
|
||||
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
|
||||
sk_sp<GrImageContext> ctx(GrImageContextPriv::MakeForPromiseImage(std::move(threadSafeProxy)));
|
||||
return sk_make_sp<SkImage_Gpu>(std::move(ctx), kNeedNewImageUniqueID, std::move(view),
|
||||
colorType, alphaType, std::move(colorSpace));
|
||||
return sk_make_sp<SkImage_Gpu>(std::move(ctx),
|
||||
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);
|
||||
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),
|
||||
kNeedNewImageUniqueID,
|
||||
framebufferView,
|
||||
colorType,
|
||||
pixmap.alphaType(),
|
||||
pixmap.refColorSpace());
|
||||
std::move(colorInfo));
|
||||
if (!image) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -23,18 +23,10 @@ class SkBitmap;
|
||||
|
||||
class SkImage_Gpu final : public SkImage_GpuBase {
|
||||
public:
|
||||
SkImage_Gpu(sk_sp<GrImageContext>, uint32_t uniqueID, GrSurfaceProxyView, SkColorType,
|
||||
SkAlphaType, sk_sp<SkColorSpace>);
|
||||
SkImage_Gpu(sk_sp<GrImageContext> context,
|
||||
uint32_t uniqueID,
|
||||
GrSurfaceProxyView view,
|
||||
SkColorInfo info)
|
||||
: SkImage_Gpu(std::move(context),
|
||||
uniqueID,
|
||||
std::move(view),
|
||||
info.colorType(),
|
||||
info.alphaType(),
|
||||
info.refColorSpace()) {}
|
||||
SkColorInfo info);
|
||||
|
||||
static sk_sp<SkImage> MakeWithVolatileSrc(sk_sp<GrRecordingContext> rContext,
|
||||
GrSurfaceProxyView volatileSrc,
|
||||
|
@ -28,9 +28,8 @@
|
||||
#include "src/image/SkImage_Gpu.h"
|
||||
#include "src/image/SkReadPixelsRec.h"
|
||||
|
||||
SkImage_GpuBase::SkImage_GpuBase(sk_sp<GrImageContext> context, SkISize size, uint32_t uniqueID,
|
||||
SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs)
|
||||
: INHERITED(SkImageInfo::Make(size, ct, at, std::move(cs)), uniqueID)
|
||||
SkImage_GpuBase::SkImage_GpuBase(sk_sp<GrImageContext> context, SkImageInfo info, uint32_t uniqueID)
|
||||
: INHERITED(std::move(info), uniqueID)
|
||||
, fContext(std::move(context)) {}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -53,8 +53,7 @@ public:
|
||||
sk_sp<GrRefCntedCallback> releaseHelper);
|
||||
|
||||
protected:
|
||||
SkImage_GpuBase(sk_sp<GrImageContext>, SkISize size, uint32_t uniqueID, SkColorType,
|
||||
SkAlphaType, sk_sp<SkColorSpace>);
|
||||
SkImage_GpuBase(sk_sp<GrImageContext>, SkImageInfo, uint32_t uniqueID);
|
||||
|
||||
sk_sp<GrImageContext> fContext;
|
||||
|
||||
|
@ -39,14 +39,16 @@ SkImage_GpuYUVA::SkImage_GpuYUVA(sk_sp<GrImageContext> context,
|
||||
GrYUVATextureProxies proxies,
|
||||
sk_sp<SkColorSpace> imageColorSpace)
|
||||
: INHERITED(std::move(context),
|
||||
proxies.yuvaInfo().dimensions(),
|
||||
uniqueID,
|
||||
kAssumedColorType,
|
||||
// If an alpha channel is present we always use kPremul. This is because,
|
||||
// although the planar data is always un-premul, the final interleaved RGB image
|
||||
// is/would-be premul.
|
||||
proxies.yuvaInfo().hasAlpha() ? kPremul_SkAlphaType : kOpaque_SkAlphaType,
|
||||
std::move(imageColorSpace))
|
||||
SkImageInfo::Make(proxies.yuvaInfo().dimensions(),
|
||||
kAssumedColorType,
|
||||
// If an alpha channel is present we always use kPremul. This
|
||||
// is because, although the planar data is always un-premul,
|
||||
// the final interleaved RGBA sample produced in the shader
|
||||
// is premul (and similar if flattened via asView).
|
||||
proxies.yuvaInfo().hasAlpha() ? kPremul_SkAlphaType
|
||||
: kOpaque_SkAlphaType,
|
||||
std::move(imageColorSpace)),
|
||||
uniqueID)
|
||||
, fYUVAProxies(std::move(proxies)) {
|
||||
// The caller should have checked this, just verifying.
|
||||
SkASSERT(fYUVAProxies.isValid());
|
||||
@ -57,11 +59,8 @@ SkImage_GpuYUVA::SkImage_GpuYUVA(sk_sp<GrImageContext> context,
|
||||
const SkImage_GpuYUVA* image,
|
||||
sk_sp<SkColorSpace> targetCS)
|
||||
: INHERITED(std::move(context),
|
||||
image->dimensions(),
|
||||
kNeedNewImageUniqueID,
|
||||
kAssumedColorType,
|
||||
image->alphaType(),
|
||||
std::move(targetCS))
|
||||
image->imageInfo().makeColorSpace(std::move(targetCS)),
|
||||
kNeedNewImageUniqueID)
|
||||
, fYUVAProxies(image->fYUVAProxies)
|
||||
// Since null fFromColorSpace means no GrColorSpaceXform, we turn a null
|
||||
// image->refColorSpace() into an explicit SRGB.
|
||||
|
@ -135,16 +135,16 @@ sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(const SkIRect* subset) {
|
||||
}
|
||||
|
||||
const SkImageInfo info = fDevice->imageInfo();
|
||||
sk_sp<SkImage> image;
|
||||
if (srcView.asTextureProxy()) {
|
||||
// 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());
|
||||
if (!srcView.asTextureProxy()) {
|
||||
return nullptr;
|
||||
}
|
||||
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) {
|
||||
@ -303,9 +303,10 @@ void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
|
||||
const SkImageInfo info = fDevice->imageInfo();
|
||||
GrSurfaceProxyView view(std::move(srcProxy), sdc->origin(), sdc->readSwizzle());
|
||||
sk_sp<SkImage> image;
|
||||
image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(canvasContext), kNeedNewImageUniqueID,
|
||||
std::move(view), info.colorType(), info.alphaType(),
|
||||
info.refColorSpace());
|
||||
image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(canvasContext),
|
||||
kNeedNewImageUniqueID,
|
||||
std::move(view),
|
||||
info.colorInfo());
|
||||
canvas->drawImage(image.get(), x, y, sampling, paint);
|
||||
return true;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user