Cleanup of code that converts from GPU-backed resources to SkImageInfo
Functions like GrMakeInfoFromTexture encouraged incorrect code to be written. Similarly, the ability to construct an info from any GrSurface was never going to be correct. Luckily, the only client of that had all of the correct parameters much higher on the stack (and dictated or replaced most of the properties of the returned info anyway). With this, I can finally remove the color space as an output of the pixel config -> color type conversion, which was never going to be correct. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2173513002 Review-Url: https://codereview.chromium.org/2173513002
This commit is contained in:
parent
a5ba329c81
commit
396fcdba14
@ -137,7 +137,6 @@ public:
|
||||
|
||||
protected:
|
||||
// Methods made available via GrSurfacePriv
|
||||
SkImageInfo info(SkAlphaType) const;
|
||||
bool savePixels(const char* filename);
|
||||
bool hasPendingRead() const;
|
||||
bool hasPendingWrite() const;
|
||||
|
@ -84,9 +84,4 @@ GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality pain
|
||||
const SkMatrix& localM,
|
||||
bool* doBicubic);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque,
|
||||
sk_sp<SkColorSpace> colorSpace = nullptr);
|
||||
|
||||
#endif
|
||||
|
@ -238,7 +238,7 @@ void GrContext::flush(int flagsBitfield) {
|
||||
bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes,
|
||||
const void* inPixels, size_t outRowBytes, void* outPixels) {
|
||||
SkSrcPixelInfo srcPI;
|
||||
if (!GrPixelConfigToColorAndColorSpace(srcConfig, &srcPI.fColorType, nullptr)) {
|
||||
if (!GrPixelConfigToColorType(srcConfig, &srcPI.fColorType)) {
|
||||
return false;
|
||||
}
|
||||
srcPI.fAlphaType = kUnpremul_SkAlphaType;
|
||||
@ -509,7 +509,7 @@ bool GrContext::readSurfacePixels(GrSurface* src,
|
||||
// Perform umpremul conversion if we weren't able to perform it as a draw.
|
||||
if (unpremul) {
|
||||
SkDstPixelInfo dstPI;
|
||||
if (!GrPixelConfigToColorAndColorSpace(dstConfig, &dstPI.fColorType, nullptr)) {
|
||||
if (!GrPixelConfigToColorType(dstConfig, &dstPI.fColorType)) {
|
||||
return false;
|
||||
}
|
||||
dstPI.fAlphaType = kUnpremul_SkAlphaType;
|
||||
|
@ -116,15 +116,6 @@ bool GrSurface::readPixels(int left, int top, int width, int height,
|
||||
rowBytes, pixelOpsFlags);
|
||||
}
|
||||
|
||||
SkImageInfo GrSurface::info(SkAlphaType alphaType) const {
|
||||
SkColorType colorType;
|
||||
sk_sp<SkColorSpace> colorSpace;
|
||||
if (!GrPixelConfigToColorAndColorSpace(this->config(), &colorType, &colorSpace)) {
|
||||
sk_throw();
|
||||
}
|
||||
return SkImageInfo::Make(this->width(), this->height(), colorType, alphaType, colorSpace);
|
||||
}
|
||||
|
||||
// TODO: This should probably be a non-member helper function. It might only be needed in
|
||||
// debug or developer builds.
|
||||
bool GrSurface::savePixels(const char* filename) {
|
||||
|
@ -32,11 +32,6 @@ public:
|
||||
int* left, int* top, int* width, int* height,
|
||||
const void** data,
|
||||
size_t* rowBytes);
|
||||
/**
|
||||
* Derive a SkImageInfo from the surface's descriptor. The caller must provide the alpha type as
|
||||
* GrSurface has no equivalent.
|
||||
*/
|
||||
SkImageInfo info(SkAlphaType alphaType) const { return fSurface->info(alphaType); }
|
||||
|
||||
/**
|
||||
* Write the contents of the surface to a PNG. Returns true if successful.
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define SkGpuDevice_DEFINED
|
||||
|
||||
#include "SkGr.h"
|
||||
#include "SkGrPriv.h"
|
||||
#include "SkBitmap.h"
|
||||
#include "SkDevice.h"
|
||||
#include "SkPicture.h"
|
||||
@ -82,10 +83,13 @@ public:
|
||||
GrDrawContext* accessDrawContext() override;
|
||||
|
||||
SkImageInfo imageInfo() const override {
|
||||
SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
|
||||
SkImageInfo info = fRenderTarget->surfacePriv().info(at).makeWH(fSize.fWidth,
|
||||
fSize.fHeight);
|
||||
return info;
|
||||
SkColorType colorType;
|
||||
if (!GrPixelConfigToColorType(fRenderTarget->config(), &colorType)) {
|
||||
colorType = kUnknown_SkColorType;
|
||||
}
|
||||
return SkImageInfo::Make(fSize.fWidth, fSize.fHeight, colorType,
|
||||
fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType,
|
||||
sk_ref_sp(fDrawContext->getColorSpace()));
|
||||
}
|
||||
|
||||
void drawPaint(const SkDraw&, const SkPaint& paint) override;
|
||||
|
@ -462,10 +462,8 @@ GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, const SkCol
|
||||
return kUnknown_GrPixelConfig;
|
||||
}
|
||||
|
||||
bool GrPixelConfigToColorAndColorSpace(GrPixelConfig config, SkColorType* ctOut,
|
||||
sk_sp<SkColorSpace>* csOut) {
|
||||
bool GrPixelConfigToColorType(GrPixelConfig config, SkColorType* ctOut) {
|
||||
SkColorType ct;
|
||||
sk_sp<SkColorSpace> cs = nullptr;
|
||||
switch (config) {
|
||||
case kAlpha_8_GrPixelConfig:
|
||||
ct = kAlpha_8_SkColorType;
|
||||
@ -487,11 +485,9 @@ bool GrPixelConfigToColorAndColorSpace(GrPixelConfig config, SkColorType* ctOut,
|
||||
break;
|
||||
case kSRGBA_8888_GrPixelConfig:
|
||||
ct = kRGBA_8888_SkColorType;
|
||||
cs = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
|
||||
break;
|
||||
case kSBGRA_8888_GrPixelConfig:
|
||||
ct = kBGRA_8888_SkColorType;
|
||||
cs = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
|
||||
break;
|
||||
case kRGBA_half_GrPixelConfig:
|
||||
ct = kRGBA_F16_SkColorType;
|
||||
@ -502,9 +498,6 @@ bool GrPixelConfigToColorAndColorSpace(GrPixelConfig config, SkColorType* ctOut,
|
||||
if (ctOut) {
|
||||
*ctOut = ct;
|
||||
}
|
||||
if (csOut) {
|
||||
*csOut = cs;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -741,22 +734,6 @@ bool SkPaintToGrPaintWithTexture(GrContext* context,
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque,
|
||||
sk_sp<SkColorSpace> colorSpace) {
|
||||
#ifdef SK_DEBUG
|
||||
const GrSurfaceDesc& desc = tex->desc();
|
||||
SkASSERT(w <= desc.fWidth);
|
||||
SkASSERT(h <= desc.fHeight);
|
||||
#endif
|
||||
const GrPixelConfig config = tex->config();
|
||||
SkColorType ct = kUnknown_SkColorType;
|
||||
SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
|
||||
if (!GrPixelConfigToColorAndColorSpace(config, &ct, nullptr)) {
|
||||
ct = kUnknown_SkColorType;
|
||||
}
|
||||
return SkImageInfo::Make(w, h, ct, at, std::move(colorSpace));
|
||||
}
|
||||
|
||||
GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality,
|
||||
const SkMatrix& viewM,
|
||||
const SkMatrix& localM,
|
||||
|
@ -102,7 +102,7 @@ bool SkPaintToGrPaintWithTexture(GrContext* context,
|
||||
|
||||
GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo&, const GrCaps&);
|
||||
|
||||
bool GrPixelConfigToColorAndColorSpace(GrPixelConfig, SkColorType*, sk_sp<SkColorSpace>*);
|
||||
bool GrPixelConfigToColorType(GrPixelConfig, SkColorType*);
|
||||
|
||||
/**
|
||||
* If the compressed data in the SkData is supported (as a texture format, this returns
|
||||
|
@ -43,6 +43,14 @@ extern void SkTextureImageApplyBudgetedDecision(SkImage* image) {
|
||||
}
|
||||
}
|
||||
|
||||
SkImageInfo SkImage_Gpu::onImageInfo() const {
|
||||
SkColorType ct;
|
||||
if (!GrPixelConfigToColorType(fTexture->config(), &ct)) {
|
||||
ct = kUnknown_SkColorType;
|
||||
}
|
||||
return SkImageInfo::Make(fTexture->width(), fTexture->height(), ct, fAlphaType, fColorSpace);
|
||||
}
|
||||
|
||||
static SkImageInfo make_info(int w, int h, bool isOpaque, sk_sp<SkColorSpace> colorSpace) {
|
||||
return SkImageInfo::MakeN32(w, h, isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType,
|
||||
std::move(colorSpace));
|
||||
@ -316,17 +324,10 @@ sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const {
|
||||
}
|
||||
|
||||
sk_sp<SkImage> SkImage::makeNonTextureImage() const {
|
||||
GrTexture* texture = as_IB(this)->peekTexture();
|
||||
if (!texture) {
|
||||
if (!this->isTextureBacked()) {
|
||||
return sk_ref_sp(const_cast<SkImage*>(this));
|
||||
}
|
||||
SkColorType ct;
|
||||
sk_sp<SkColorSpace> cs;
|
||||
if (!GrPixelConfigToColorAndColorSpace(texture->config(), &ct, &cs)) {
|
||||
return nullptr;
|
||||
}
|
||||
SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
|
||||
auto info = SkImageInfo::Make(this->width(), this->height(), ct, at, cs);
|
||||
SkImageInfo info = as_IB(this)->onImageInfo();
|
||||
size_t rowBytes = info.minRowBytes();
|
||||
size_t size = info.getSafeSize(rowBytes);
|
||||
auto data = SkData::MakeUninitialized(size);
|
||||
|
@ -27,10 +27,7 @@ public:
|
||||
SkBudgeted);
|
||||
~SkImage_Gpu() override;
|
||||
|
||||
SkImageInfo onImageInfo() const override {
|
||||
return GrMakeInfoFromTexture(fTexture, fTexture->width(), fTexture->height(), isOpaque(),
|
||||
fColorSpace);
|
||||
}
|
||||
SkImageInfo onImageInfo() const override;
|
||||
|
||||
void applyBudgetDecision() const {
|
||||
if (SkBudgeted::kYes == fBudgeted) {
|
||||
|
Loading…
Reference in New Issue
Block a user