aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar brianosman <brianosman@google.com>2016-07-22 06:26:11 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-22 06:26:11 -0700
commit396fcdba14a0101ed43dcc3863585bf50c4ed6cc (patch)
tree2aaf20c22567931dd16dbe7f1779c0709d2bc62e /src
parenta5ba329c81dd6e21f8d610b56416d9f45259fa42 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrContext.cpp4
-rw-r--r--src/gpu/GrSurface.cpp9
-rw-r--r--src/gpu/GrSurfacePriv.h5
-rw-r--r--src/gpu/SkGpuDevice.h12
-rw-r--r--src/gpu/SkGr.cpp25
-rw-r--r--src/gpu/SkGrPriv.h2
-rw-r--r--src/image/SkImage_Gpu.cpp19
-rw-r--r--src/image/SkImage_Gpu.h5
8 files changed, 23 insertions, 58 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 6bb3ea6a2c..5a5173c530 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -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;
diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp
index 47fa394788..6dc90a3d1a 100644
--- a/src/gpu/GrSurface.cpp
+++ b/src/gpu/GrSurface.cpp
@@ -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) {
diff --git a/src/gpu/GrSurfacePriv.h b/src/gpu/GrSurfacePriv.h
index bff411edf3..f2ba7baca4 100644
--- a/src/gpu/GrSurfacePriv.h
+++ b/src/gpu/GrSurfacePriv.h
@@ -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.
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index 811175937c..7e646a13f1 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -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;
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index ef3a39bc61..452218f517 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -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,
diff --git a/src/gpu/SkGrPriv.h b/src/gpu/SkGrPriv.h
index ab77dc1e79..7188856ce8 100644
--- a/src/gpu/SkGrPriv.h
+++ b/src/gpu/SkGrPriv.h
@@ -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
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index fa697cd4b9..c331a295ce 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -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);
diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h
index 0e9169d8d0..5faaa7526b 100644
--- a/src/image/SkImage_Gpu.h
+++ b/src/image/SkImage_Gpu.h
@@ -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) {