Pass in a SkColorType into SkImage_Gpu ctor.

This allows us to get rid of using the GrPixelConfig on proxy to create
the SkColorType

Bug: skia:6718
Change-Id: I1758b79152fa1e8a1796e55d19f5e8ca0b0e8b7b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/264396
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Greg Daniel 2020-01-14 14:39:00 -05:00 committed by Skia Commit-Bot
parent e4720c6864
commit 1d17543133
10 changed files with 85 additions and 72 deletions

View File

@ -139,10 +139,10 @@ static sk_sp<SkImage> make_reference_image(GrContext* context,
}
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
GrColorType::kRGBA_8888);
GrColorType::kRGBA_8888);
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, kOpaque_SkAlphaType,
std::move(view), nullptr);
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, std::move(view),
ii.colorType(), kOpaque_SkAlphaType, nullptr);
}
// Here we're converting from a matrix that is intended for UVs to a matrix that is intended

View File

@ -289,8 +289,9 @@ protected:
// No API to draw a GrTexture directly, so we cheat and create a private image subclass
sk_sp<SkImage> texImage(new SkImage_Gpu(sk_ref_sp(canvas->getGrContext()),
image->uniqueID(), kPremul_SkAlphaType,
std::move(view), image->refColorSpace()));
image->uniqueID(), std::move(view),
image->colorType(), image->alphaType(),
image->refColorSpace()));
canvas->drawImage(texImage.get(), x, y);
}

View File

@ -1292,6 +1292,30 @@ static constexpr GrPixelConfig GrCompressionTypeToPixelConfig(SkImage::Compressi
SkUNREACHABLE;
}
// In general we try to not mix CompressionType and ColorType, but currently SkImage still requires
// an SkColorType even for CompressedTypes so we need some conversion.
static constexpr SkColorType GrCompressionTypeToSkColorType(SkImage::CompressionType compression) {
switch (compression) {
case SkImage::CompressionType::kNone: return kUnknown_SkColorType;
case SkImage::CompressionType::kETC2_RGB8_UNORM: return kRGB_888x_SkColorType;
case SkImage::CompressionType::kBC1_RGB8_UNORM: return kRGB_888x_SkColorType;
}
SkUNREACHABLE;
}
static constexpr GrColorType GrMaskFormatToColorType(GrMaskFormat format) {
switch (format) {
case kA8_GrMaskFormat:
return GrColorType::kAlpha_8;
case kA565_GrMaskFormat:
return GrColorType::kBGR_565;
case kARGB_GrMaskFormat:
return GrColorType::kRGBA_8888;
}
SkUNREACHABLE;
}
/**
* Ref-counted object that calls a callback from its destructor.
*/

View File

@ -368,7 +368,8 @@ sk_sp<SkSpecialImage> SkSpecialImage::CopyFromRaster(const SkIRect& subset,
#if SK_SUPPORT_GPU
///////////////////////////////////////////////////////////////////////////////
static sk_sp<SkImage> wrap_proxy_in_image(GrRecordingContext* context, sk_sp<GrTextureProxy> proxy,
SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace) {
SkColorType colorType, SkAlphaType alphaType,
sk_sp<SkColorSpace> colorSpace) {
// CONTEXT TODO: remove this use of 'backdoor' to create an SkImage
// TODO: Once SkSpecialImage stores a GrSurfaceProxyView instead of a proxy, use that to create
// the view here.
@ -376,8 +377,8 @@ static sk_sp<SkImage> wrap_proxy_in_image(GrRecordingContext* context, sk_sp<GrT
const GrSwizzle& swizzle = proxy->textureSwizzle();
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context->priv().backdoor()),
kNeedNewImageUniqueID, alphaType,
std::move(view), std::move(colorSpace));
kNeedNewImageUniqueID, std::move(view), colorType, alphaType,
std::move(colorSpace));
}
class SkSpecialImage_Gpu : public SkSpecialImage_Base {
@ -423,7 +424,8 @@ public:
// to be tightened (if it is deferred).
sk_sp<SkImage> img =
sk_sp<SkImage>(new SkImage_Gpu(sk_ref_sp(canvas->getGrContext()), this->uniqueID(),
fAlphaType, std::move(view), fColorSpace));
std::move(view), this->colorType(), fAlphaType,
fColorSpace));
canvas->drawImageRect(img, this->subset(),
dst, paint, SkCanvas::kStrict_SrcRectConstraint);
@ -504,7 +506,8 @@ public:
*subset == SkIRect::MakeSize(fTextureProxy->dimensions())) {
fTextureProxy->priv().exactify(false);
// The existing GrTexture is already tight so reuse it in the SkImage
return wrap_proxy_in_image(fContext, fTextureProxy, fAlphaType, fColorSpace);
return wrap_proxy_in_image(fContext, fTextureProxy, this->colorType(), fAlphaType,
fColorSpace);
}
sk_sp<GrTextureProxy> subsetProxy(
@ -517,12 +520,14 @@ public:
SkASSERT(subsetProxy->priv().isExact());
// MDB: this is acceptable (wrapping subsetProxy in an SkImage) bc Copy will
// return a kExact-backed proxy
return wrap_proxy_in_image(fContext, std::move(subsetProxy), fAlphaType, fColorSpace);
return wrap_proxy_in_image(fContext, std::move(subsetProxy), this->colorType(),
fAlphaType, fColorSpace);
}
fTextureProxy->priv().exactify(true);
return wrap_proxy_in_image(fContext, fTextureProxy, fAlphaType, fColorSpace);
return wrap_proxy_in_image(fContext, fTextureProxy, this->colorType(), fAlphaType,
fColorSpace);
}
sk_sp<SkSurface> onMakeTightSurface(SkColorType colorType, const SkColorSpace* colorSpace,

View File

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

View File

@ -22,20 +22,6 @@ GrAtlasManager::GrAtlasManager(GrProxyProvider* proxyProvider, GrStrikeCache* gl
GrAtlasManager::~GrAtlasManager() = default;
static GrColorType mask_format_to_gr_color_type(GrMaskFormat format) {
switch (format) {
case kA8_GrMaskFormat:
return GrColorType::kAlpha_8;
case kA565_GrMaskFormat:
return GrColorType::kBGR_565;
case kARGB_GrMaskFormat:
return GrColorType::kRGBA_8888;
default:
SkDEBUGFAIL("unsupported GrMaskFormat");
return GrColorType::kAlpha_8;
}
}
void GrAtlasManager::freeAll() {
for (int i = 0; i < kMaskFormatCount; ++i) {
fAtlases[i] = nullptr;
@ -141,7 +127,7 @@ void GrAtlasManager::dump(GrContext* context) const {
#else
filename.printf("fontcache_%d%d%d.png", gDumpCount, i, pageIdx);
#endif
auto ct = mask_format_to_gr_color_type(AtlasIndexToMaskFormat(i));
auto ct = GrMaskFormatToColorType(AtlasIndexToMaskFormat(i));
save_pixels(context, views[pageIdx], ct, filename.c_str());
}
}
@ -164,7 +150,7 @@ void GrAtlasManager::setAtlasDimensionsToMinimum_ForTesting() {
bool GrAtlasManager::initAtlas(GrMaskFormat format) {
int index = MaskFormatToAtlasIndex(format);
if (fAtlases[index] == nullptr) {
GrColorType grColorType = mask_format_to_gr_color_type(format);
GrColorType grColorType = GrMaskFormatToColorType(format);
SkISize atlasDimensions = fAtlasConfig.atlasDimensions(format);
SkISize plotDimensions = fAtlasConfig.plotDimensions(format);

View File

@ -45,18 +45,10 @@
#include "src/gpu/gl/GrGLTexture.h"
#include "src/image/SkImage_Gpu.h"
static SkColorType proxy_color_type(GrSurfaceProxy* proxy) {
SkColorType colorType;
if (!GrPixelConfigToColorType(proxy->config(), &colorType)) {
colorType = kUnknown_SkColorType;
}
return colorType;
}
SkImage_Gpu::SkImage_Gpu(sk_sp<GrContext> context, uint32_t uniqueID, SkAlphaType at,
GrSurfaceProxyView view, sk_sp<SkColorSpace> colorSpace)
SkImage_Gpu::SkImage_Gpu(sk_sp<GrContext> context, uint32_t uniqueID, GrSurfaceProxyView view,
SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> colorSpace)
: INHERITED(std::move(context), view.proxy()->backingStoreDimensions(), uniqueID,
proxy_color_type(view.proxy()), at, colorSpace)
ct, at, colorSpace)
, fView(std::move(view)) {}
SkImage_Gpu::~SkImage_Gpu() {}
@ -103,13 +95,14 @@ sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(GrRecordingContext* con
}
// MDB: this call is okay bc we know 'renderTargetContext' was exact
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, this->alphaType(),
renderTargetContext->readSurfaceView(), std::move(targetCS));
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID,
renderTargetContext->readSurfaceView(), targetCT,
this->alphaType(), std::move(targetCS));
}
sk_sp<SkImage> SkImage_Gpu::onReinterpretColorSpace(sk_sp<SkColorSpace> newCS) const {
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, this->alphaType(), fView,
std::move(newCS));
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, fView, this->colorType(),
this->alphaType(), std::move(newCS));
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -136,8 +129,8 @@ static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx,
GrSwizzle swizzle = ctx->priv().caps()->getReadSwizzle(proxy->backendFormat(), colorType);
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, at, std::move(view),
std::move(colorSpace));
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, std::move(view),
GrColorTypeToSkColorType(colorType), at, std::move(colorSpace));
}
sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrContext* ctx,
@ -165,8 +158,11 @@ sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrContext* ctx,
return nullptr;
}
CompressionType type = caps->compressionType(tex.getBackendFormat());
SkColorType ct = GrCompressionTypeToSkColorType(type);
GrSurfaceProxyView view(std::move(proxy), origin, GrSwizzle::RGBA());
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, at, std::move(view),
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, std::move(view), ct, at,
std::move(cs));
}
@ -231,8 +227,10 @@ sk_sp<SkImage> SkImage::MakeFromCompressed(GrContext* context, sk_sp<SkData> dat
SkASSERT(proxy->textureSwizzle() == GrSwizzle());
GrSurfaceProxyView view(std::move(proxy));
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, kOpaque_SkAlphaType,
std::move(view), nullptr);
SkColorType colorType = GrCompressionTypeToSkColorType(type);
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, std::move(view),
colorType, kOpaque_SkAlphaType, nullptr);
}
sk_sp<SkImage> SkImage_Gpu::ConvertYUVATexturesToRGB(GrContext* ctx, SkYUVColorSpace yuvColorSpace,
@ -259,10 +257,11 @@ sk_sp<SkImage> SkImage_Gpu::ConvertYUVATexturesToRGB(GrContext* ctx, SkYUVColorS
return nullptr;
}
SkColorType ct = GrColorTypeToSkColorType(renderTargetContext->colorInfo().colorType());
SkAlphaType at = GetAlphaTypeFromYUVAIndices(yuvaIndices);
// MDB: this call is okay bc we know 'renderTargetContext' was exact
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, at,
renderTargetContext->readSurfaceView(),
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID,
renderTargetContext->readSurfaceView(), ct, at,
renderTargetContext->colorInfo().refColorSpace());
}
@ -388,8 +387,7 @@ sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopyWithExternalBackend(
}
static sk_sp<SkImage> create_image_from_producer(GrContext* context, GrTextureProducer* producer,
SkAlphaType at, uint32_t id,
GrMipMapped mipMapped) {
uint32_t id, GrMipMapped mipMapped) {
// TODO: have texture producer return a GrSurfaceProxyView
sk_sp<GrTextureProxy> proxy(producer->refTextureProxy(mipMapped));
if (!proxy) {
@ -398,8 +396,9 @@ static sk_sp<SkImage> create_image_from_producer(GrContext* context, GrTexturePr
GrSurfaceOrigin origin = proxy->origin();
const GrSwizzle& swizzle = proxy->textureSwizzle();
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), id, at, std::move(view),
sk_ref_sp(producer->colorSpace()));
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), id, std::move(view),
GrColorTypeToSkColorType(producer->colorType()),
producer->alphaType(), sk_ref_sp(producer->colorSpace()));
}
sk_sp<SkImage> SkImage::makeTextureImage(GrContext* context, GrMipMapped mipMapped) const {
@ -419,20 +418,17 @@ sk_sp<SkImage> SkImage::makeTextureImage(GrContext* context, GrMipMapped mipMapp
}
GrTextureAdjuster adjuster(context, std::move(proxy), this->imageInfo().colorInfo(),
this->uniqueID());
return create_image_from_producer(context, &adjuster, this->alphaType(),
this->uniqueID(), mipMapped);
return create_image_from_producer(context, &adjuster, this->uniqueID(), mipMapped);
}
if (this->isLazyGenerated()) {
GrImageTextureMaker maker(context, this, kDisallow_CachingHint);
return create_image_from_producer(context, &maker, this->alphaType(),
this->uniqueID(), mipMapped);
return create_image_from_producer(context, &maker, this->uniqueID(), mipMapped);
}
if (const SkBitmap* bmp = as_IB(this)->onPeekBitmap()) {
GrBitmapTextureMaker maker(context, *bmp);
return create_image_from_producer(context, &maker, this->alphaType(),
this->uniqueID(), mipMapped);
return create_image_from_producer(context, &maker, this->uniqueID(), mipMapped);
}
return nullptr;
}
@ -491,8 +487,8 @@ sk_sp<SkImage> SkImage_Gpu::MakePromiseTexture(GrContext* context,
}
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(backendFormat, grColorType);
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, alphaType,
std::move(view), std::move(colorSpace));
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, std::move(view),
colorType, alphaType, std::move(colorSpace));
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -623,8 +619,8 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(backendFormat, grColorType);
GrSurfaceProxyView view(std::move(proxy), surfaceOrigin, swizzle);
sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, at,
view, cs);
sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, view,
colorType, at, cs);
if (!image) {
return nullptr;
}

View File

@ -23,7 +23,7 @@ struct SkYUVAIndex;
class SkImage_Gpu : public SkImage_GpuBase {
public:
SkImage_Gpu(sk_sp<GrContext>, uint32_t uniqueID, SkAlphaType, GrSurfaceProxyView,
SkImage_Gpu(sk_sp<GrContext>, uint32_t uniqueID, GrSurfaceProxyView, SkColorType, SkAlphaType,
sk_sp<SkColorSpace>);
~SkImage_Gpu() override;

View File

@ -159,8 +159,8 @@ sk_sp<SkImage> SkImage_GpuBase::onMakeSubset(GrRecordingContext* context,
GrSurfaceProxyView view(std::move(copyProxy), currView.origin(), currView.swizzle());
// MDB: this call is okay bc we know 'sContext' was kExact
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, this->alphaType(),
std::move(view), this->refColorSpace());
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, std::move(view),
this->colorType(), this->alphaType(), this->refColorSpace());
}
bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,

View File

@ -123,8 +123,8 @@ sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(const SkIRect* subset) {
// above copy creates a kExact surfaceContext.
SkASSERT(srcProxy->priv().isExact());
GrSurfaceProxyView view(std::move(srcProxy), rtc->origin(), rtc->readSwizzle());
image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, info.alphaType(),
std::move(view), info.refColorSpace());
image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, std::move(view),
info.colorType(), info.alphaType(), info.refColorSpace());
}
return image;
}
@ -258,8 +258,8 @@ void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPai
const SkImageInfo info = fDevice->imageInfo();
GrSurfaceProxyView view(std::move(srcProxy), rtc->origin(), rtc->readSwizzle());
sk_sp<SkImage> image;
image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, info.alphaType(),
std::move(view), info.refColorSpace());
image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, std::move(view),
info.colorType(), info.alphaType(), info.refColorSpace());
canvas->drawImage(image, x, y, paint);
return true;
};