Revert "Construct GPU SkImages with SkColorType, don't infer from GrPixelConfig"
This reverts commit 384f6e35b1a9716f58e584498749c40f23fe6690.
Reason for revert: bot breakage
Original change's description:
> Construct GPU SkImages with SkColorType, don't infer from GrPixelConfig
>
> Bug: skia:6718
>
> Change-Id: I8828939427481ea7780a66fc0fed8e9909baba9b
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/245156
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Brian Salomon <bsalomon@google.com>
TBR=egdaniel@google.com,bsalomon@google.com
Change-Id: Ib52b457bfc4b323ce06ee5359d9e9ab580aff6ea
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:6718
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/245166
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/gm/flippity.cpp b/gm/flippity.cpp
index ca0ca42..c9e4f19 100644
--- a/gm/flippity.cpp
+++ b/gm/flippity.cpp
@@ -137,8 +137,8 @@
return nullptr;
}
- return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, bm.colorType(),
- bm.alphaType(), bm.refColorSpace(), std::move(proxy));
+ return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, kOpaque_SkAlphaType,
+ std::move(proxy), nullptr);
}
// Here we're converting from a matrix that is intended for UVs to a matrix that is intended
diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp
index c3ab85f..f916ca7 100644
--- a/gm/image_pict.cpp
+++ b/gm/image_pict.cpp
@@ -268,8 +268,9 @@
}
static void draw_as_tex(SkCanvas* canvas, SkImage* image, SkScalar x, SkScalar y) {
- auto texImage = image->makeTextureImage(canvas->getGrContext());
- if (!texImage) {
+ sk_sp<GrTextureProxy> proxy(as_IB(image)->asTextureProxyRef(
+ canvas->getGrContext(), GrSamplerState::ClampBilerp(), nullptr));
+ if (!proxy) {
// show placeholder if we have no texture
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
@@ -280,6 +281,11 @@
canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), paint);
return;
}
+
+ // 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(proxy), image->refColorSpace()));
canvas->drawImage(texImage.get(), x, y);
}
diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h
index 7a37704..2603c1a 100644
--- a/include/private/GrTypesPriv.h
+++ b/include/private/GrTypesPriv.h
@@ -1397,14 +1397,6 @@
SkUNREACHABLE;
}
-static constexpr GrColorType GrClosestColorTypeToCompressionType(
- SkImage::CompressionType compression) {
- switch (compression) {
- case SkImage::kETC1_CompressionType: return GrColorType::kRGB_888x;
- }
- SkUNREACHABLE;
-}
-
static constexpr GrPixelConfig GrColorTypeToPixelConfig(GrColorType colorType) {
switch (colorType) {
case GrColorType::kUnknown: return kUnknown_GrPixelConfig;
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index fa2da57..a21c4f2 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -368,10 +368,11 @@
#if SK_SUPPORT_GPU
///////////////////////////////////////////////////////////////////////////////
static sk_sp<SkImage> wrap_proxy_in_image(GrRecordingContext* context, sk_sp<GrTextureProxy> proxy,
- SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs) {
+ SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace) {
// CONTEXT TODO: remove this use of 'backdoor' to create an SkImage
- return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context->priv().backdoor()), kNeedNewImageUniqueID, ct,
- at, std::move(cs), std::move(proxy));
+ return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context->priv().backdoor()),
+ kNeedNewImageUniqueID, alphaType,
+ std::move(proxy), std::move(colorSpace));
}
class SkSpecialImage_Gpu : public SkSpecialImage_Base {
@@ -403,15 +404,16 @@
void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override {
SkRect dst = SkRect::MakeXYWH(x, y,
this->subset().width(), this->subset().height());
+
// TODO: In this instance we know we're going to draw a sub-portion of the backing
// texture into the canvas so it is okay to wrap it in an SkImage. This poses
// some problems for full deferral however in that when the deferred SkImage_Gpu
// 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->getGrContext()), this->uniqueID(),
- this->colorType(), fAlphaType, fColorSpace, fTextureProxy));
+ sk_sp<SkImage> img =
+ sk_sp<SkImage>(new SkImage_Gpu(sk_ref_sp(canvas->getGrContext()), this->uniqueID(),
+ fAlphaType, fTextureProxy, fColorSpace));
canvas->drawImageRect(img, this->subset(),
dst, paint, SkCanvas::kStrict_SrcRectConstraint);
@@ -493,8 +495,7 @@
fTextureProxy->height() == subset->height()) {
fTextureProxy->priv().exactify(false);
// The existing GrTexture is already tight so reuse it in the SkImage
- return wrap_proxy_in_image(fContext, fTextureProxy, this->colorType(), fAlphaType,
- fColorSpace);
+ return wrap_proxy_in_image(fContext, fTextureProxy, fAlphaType, fColorSpace);
}
sk_sp<GrTextureProxy> subsetProxy(
@@ -507,14 +508,12 @@
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), this->colorType(),
- fAlphaType, fColorSpace);
+ return wrap_proxy_in_image(fContext, std::move(subsetProxy), fAlphaType, fColorSpace);
}
fTextureProxy->priv().exactify(true);
- return wrap_proxy_in_image(fContext, fTextureProxy, this->colorType(), fAlphaType,
- fColorSpace);
+ return wrap_proxy_in_image(fContext, fTextureProxy, fAlphaType, fColorSpace);
}
sk_sp<SkSurface> onMakeTightSurface(SkColorType colorType, const SkColorSpace* colorSpace,
diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp
index a1d85d9..5507b43 100644
--- a/src/gpu/GrContextPriv.cpp
+++ b/src/gpu/GrContextPriv.cpp
@@ -289,16 +289,9 @@
return nullptr;
}
- SkColorType ct = kUnknown_SkColorType;
- switch (format) {
- case kA8_GrMaskFormat: ct = kAlpha_8_SkColorType; break;
- case kA565_GrMaskFormat: ct = kRGB_565_SkColorType; break;
- case kARGB_GrMaskFormat: ct = kRGBA_8888_SkColorType; break;
- }
-
SkASSERT(proxies[index]->priv().isExact());
- sk_sp<SkImage> image(new SkImage_Gpu(sk_ref_sp(fContext), kNeedNewImageUniqueID, ct,
- kPremul_SkAlphaType, nullptr, proxies[index]));
+ sk_sp<SkImage> image(new SkImage_Gpu(sk_ref_sp(fContext), kNeedNewImageUniqueID,
+ kPremul_SkAlphaType, proxies[index], nullptr));
return image;
}
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index ba5f3df..4730194 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -48,13 +48,22 @@
#include "src/gpu/gl/GrGLTexture.h"
#include "src/image/SkImage_Gpu.h"
-SkImage_Gpu::SkImage_Gpu(sk_sp<GrContext> context, uint32_t uniqueID, SkColorType ct,
- SkAlphaType at, sk_sp<SkColorSpace> colorSpace,
- sk_sp<GrTextureProxy> proxy)
+static SkColorType proxy_color_type(GrTextureProxy* 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,
+ sk_sp<GrTextureProxy> proxy, sk_sp<SkColorSpace> colorSpace)
: INHERITED(std::move(context), proxy->worstCaseWidth(), proxy->worstCaseHeight(), uniqueID,
- ct, at, colorSpace)
+ proxy_color_type(proxy.get()), at, colorSpace)
, fProxy(std::move(proxy)) {}
+SkImage_Gpu::~SkImage_Gpu() {}
+
GrSemaphoresSubmitted SkImage_Gpu::onFlush(GrContext* context, const GrFlushInfo& info) {
if (!context || !fContext->priv().matches(context) || fContext->abandoned()) {
return GrSemaphoresSubmitted::kNo;
@@ -97,15 +106,14 @@
return nullptr;
}
- auto actualCT = GrColorTypeToSkColorType(renderTargetContext->colorSpaceInfo().colorType());
// MDB: this call is okay bc we know 'renderTargetContext' was exact
- return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, actualCT, this->alphaType(),
- std::move(targetCS), renderTargetContext->asTextureProxyRef());
+ return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, this->alphaType(),
+ renderTargetContext->asTextureProxyRef(), std::move(targetCS));
}
sk_sp<SkImage> SkImage_Gpu::onReinterpretColorSpace(sk_sp<SkColorSpace> newCS) const {
- return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, this->colorType(),
- this->alphaType(), std::move(newCS), fProxy);
+ return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, this->alphaType(), fProxy,
+ std::move(newCS));
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -129,9 +137,8 @@
if (!proxy) {
return nullptr;
}
- return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID,
- GrColorTypeToSkColorType(colorType), at, std::move(colorSpace),
- std::move(proxy));
+ return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, at, std::move(proxy),
+ std::move(colorSpace));
}
sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx,
@@ -190,9 +197,9 @@
if (!proxy) {
return nullptr;
}
- auto ct = GrColorTypeToSkColorType(GrClosestColorTypeToCompressionType(type));
- return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, ct,
- kOpaque_SkAlphaType, nullptr, std::move(proxy));
+
+ return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, kOpaque_SkAlphaType,
+ std::move(proxy), nullptr);
}
sk_sp<SkImage> SkImage_Gpu::ConvertYUVATexturesToRGB(GrContext* ctx, SkYUVColorSpace yuvColorSpace,
@@ -220,11 +227,10 @@
}
SkAlphaType at = GetAlphaTypeFromYUVAIndices(yuvaIndices);
- auto ct = GrColorTypeToSkColorType(renderTargetContext->colorSpaceInfo().colorType());
// MDB: this call is okay bc we know 'renderTargetContext' was exact
- return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, ct, at,
- renderTargetContext->colorSpaceInfo().refColorSpace(),
- renderTargetContext->asTextureProxyRef());
+ return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, at,
+ renderTargetContext->asTextureProxyRef(),
+ renderTargetContext->colorSpaceInfo().refColorSpace());
}
sk_sp<SkImage> SkImage::MakeFromYUVATexturesCopy(GrContext* ctx,
@@ -359,9 +365,8 @@
if (!proxy) {
return nullptr;
}
- auto ct = GrColorTypeToSkColorType(producer->colorType());
- return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), id, ct, at,
- sk_ref_sp(producer->colorSpace()), std::move(proxy));
+ return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), id, at, std::move(proxy),
+ sk_ref_sp(producer->colorSpace()));
}
sk_sp<SkImage> SkImage::makeTextureImage(GrContext* context, GrMipMapped mipMapped) const {
@@ -452,8 +457,8 @@
if (!proxy) {
return nullptr;
}
- return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, colorType, alphaType,
- std::move(colorSpace), std::move(proxy));
+ return sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, alphaType,
+ std::move(proxy), std::move(colorSpace));
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -582,8 +587,8 @@
sk_sp<SkColorSpace> cs = pixmap.refColorSpace();
SkAlphaType at = pixmap.alphaType();
- sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID,
- colorType, at, cs, proxy);
+ sk_sp<SkImage> image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, at,
+ proxy, cs);
if (!image) {
return nullptr;
}
diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h
index 9749d81..71f3b14 100644
--- a/src/image/SkImage_Gpu.h
+++ b/src/image/SkImage_Gpu.h
@@ -22,8 +22,9 @@
class SkImage_Gpu : public SkImage_GpuBase {
public:
- SkImage_Gpu(sk_sp<GrContext>, uint32_t uniqueID, SkColorType, SkAlphaType, sk_sp<SkColorSpace>,
- sk_sp<GrTextureProxy>);
+ SkImage_Gpu(sk_sp<GrContext>, uint32_t uniqueID, SkAlphaType, sk_sp<GrTextureProxy>,
+ sk_sp<SkColorSpace>);
+ ~SkImage_Gpu() override;
GrSemaphoresSubmitted onFlush(GrContext*, const GrFlushInfo&) override;
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index 2d70262..4c3761a 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -27,6 +27,8 @@
: INHERITED(SkImageInfo::Make(width, height, ct, at, std::move(cs)), uniqueID)
, fContext(std::move(context)) {}
+SkImage_GpuBase::~SkImage_GpuBase() {}
+
//////////////////////////////////////////////////////////////////////////////////////////////////
#if GR_TEST_UTILS
@@ -124,8 +126,8 @@
}
// MDB: this call is okay bc we know 'sContext' was kExact
- return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, this->colorType(),
- this->alphaType(), this->refColorSpace(), std::move(copyProxy));
+ return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, this->alphaType(),
+ std::move(copyProxy), this->refColorSpace());
}
bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
diff --git a/src/image/SkImage_GpuBase.h b/src/image/SkImage_GpuBase.h
index 200393d..c78f799 100644
--- a/src/image/SkImage_GpuBase.h
+++ b/src/image/SkImage_GpuBase.h
@@ -20,6 +20,10 @@
class SkImage_GpuBase : public SkImage_Base {
public:
+ SkImage_GpuBase(sk_sp<GrContext>, int width, int height, uint32_t uniqueID, SkColorType,
+ SkAlphaType, sk_sp<SkColorSpace>);
+ ~SkImage_GpuBase() override;
+
GrContext* context() const final { return fContext.get(); }
bool getROPixels(SkBitmap*, CachingHint) const final;
@@ -74,9 +78,6 @@
using PromiseImageTextureDoneProc = SkDeferredDisplayListRecorder::PromiseImageTextureDoneProc;
protected:
- SkImage_GpuBase(sk_sp<GrContext>, int width, int height, uint32_t uniqueID, SkColorType,
- SkAlphaType, sk_sp<SkColorSpace>);
-
using PromiseImageApiVersion = SkDeferredDisplayListRecorder::PromiseImageApiVersion;
// Helper for making a lazy proxy for a promise image. The PromiseDoneProc we be called,
// if not null, immediately if this function fails. Othwerwise, it is installed in the
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 64af022..8968f0a 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -122,9 +122,8 @@
// The renderTargetContext coming out of SkGpuDevice should always be exact and the
// above copy creates a kExact surfaceContext.
SkASSERT(srcProxy->priv().isExact());
- image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, info.colorType(),
- info.alphaType(), info.refColorSpace(),
- std::move(srcProxy));
+ image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, info.alphaType(),
+ std::move(srcProxy), info.refColorSpace());
}
return image;
}
@@ -246,9 +245,8 @@
// of drawing a texture proxy.
const SkImageInfo info = fDevice->imageInfo();
sk_sp<SkImage> image;
- image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, info.colorType(),
- info.alphaType(), info.refColorSpace(),
- std::move(srcProxy));
+ image = sk_make_sp<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID, info.alphaType(),
+ std::move(srcProxy), info.refColorSpace());
canvas->drawImage(image, x, y, paint);
return true;
};