aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar brianosman <brianosman@google.com>2016-06-06 13:10:58 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-06-06 13:10:58 -0700
commit982eb7f377a0c771345276558072deb2fcea0d3e (patch)
tree02ae878610160d6b6c91629424aaf895e5f17497 /src/gpu
parentdc27a648d2ff23b2e96232c00c15976c46e1d48d (diff)
Add new SkSourceGammaTreatment enum, used in situations like mipmap construction, where we need to know if we should respect (vs. ignore) the gamma encoding of sRGB tagged images. Plumb that extensively.
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrImageIDTextureAdjuster.cpp11
-rw-r--r--src/gpu/GrImageIDTextureAdjuster.h4
-rw-r--r--src/gpu/GrTextureParamsAdjuster.cpp24
-rw-r--r--src/gpu/GrTextureParamsAdjuster.h19
-rw-r--r--src/gpu/SkGpuDevice.cpp26
-rw-r--r--src/gpu/SkGpuDevice_drawTexture.cpp8
-rw-r--r--src/gpu/SkGr.cpp20
-rw-r--r--src/gpu/SkGrPriv.h2
8 files changed, 73 insertions, 41 deletions
diff --git a/src/gpu/GrImageIDTextureAdjuster.cpp b/src/gpu/GrImageIDTextureAdjuster.cpp
index 21c2f33358..4ff3ed5d95 100644
--- a/src/gpu/GrImageIDTextureAdjuster.cpp
+++ b/src/gpu/GrImageIDTextureAdjuster.cpp
@@ -81,7 +81,8 @@ GrBitmapTextureMaker::GrBitmapTextureMaker(GrContext* context, const SkBitmap& b
}
}
-GrTexture* GrBitmapTextureMaker::refOriginalTexture(bool willBeMipped) {
+GrTexture* GrBitmapTextureMaker::refOriginalTexture(bool willBeMipped,
+ SkSourceGammaTreatment gammaTreatment) {
GrTexture* tex = nullptr;
if (fOriginalKey.isValid()) {
@@ -91,7 +92,7 @@ GrTexture* GrBitmapTextureMaker::refOriginalTexture(bool willBeMipped) {
}
}
if (willBeMipped) {
- tex = GrGenerateMipMapsAndUploadToTexture(this->context(), fBitmap);
+ tex = GrGenerateMipMapsAndUploadToTexture(this->context(), fBitmap, gammaTreatment);
}
if (!tex) {
tex = GrUploadBitmapToTexture(this->context(), fBitmap);
@@ -130,8 +131,10 @@ GrImageTextureMaker::GrImageTextureMaker(GrContext* context, SkImageCacherator*
}
}
-GrTexture* GrImageTextureMaker::refOriginalTexture(bool willBeMipped) {
- return fCacher->lockTexture(this->context(), fOriginalKey, fClient, fCachingHint, willBeMipped);
+GrTexture* GrImageTextureMaker::refOriginalTexture(bool willBeMipped,
+ SkSourceGammaTreatment gammaTreatment) {
+ return fCacher->lockTexture(this->context(), fOriginalKey, fClient, fCachingHint, willBeMipped,
+ gammaTreatment);
}
void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) {
diff --git a/src/gpu/GrImageIDTextureAdjuster.h b/src/gpu/GrImageIDTextureAdjuster.h
index ad5e671b73..d516fc592c 100644
--- a/src/gpu/GrImageIDTextureAdjuster.h
+++ b/src/gpu/GrImageIDTextureAdjuster.h
@@ -55,7 +55,7 @@ public:
GrBitmapTextureMaker(GrContext* context, const SkBitmap& bitmap);
protected:
- GrTexture* refOriginalTexture(bool willBeMipped) override;
+ GrTexture* refOriginalTexture(bool willBeMipped, SkSourceGammaTreatment) override;
void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) override;
@@ -80,7 +80,7 @@ protected:
// able to efficiently produce a "stretched" texture natively (e.g. picture-backed)
// GrTexture* generateTextureForParams(const CopyParams&) override;
- GrTexture* refOriginalTexture(bool willBeMipped) override;
+ GrTexture* refOriginalTexture(bool willBeMipped, SkSourceGammaTreatment) override;
void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override;
void didCacheCopy(const GrUniqueKey& copyKey) override;
diff --git a/src/gpu/GrTextureParamsAdjuster.cpp b/src/gpu/GrTextureParamsAdjuster.cpp
index a91ba8a5e3..076750ee5a 100644
--- a/src/gpu/GrTextureParamsAdjuster.cpp
+++ b/src/gpu/GrTextureParamsAdjuster.cpp
@@ -158,6 +158,7 @@ GrTexture* GrTextureAdjuster::refCopy(const CopyParams& copyParams) {
}
GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrTextureParams& params,
+ SkSourceGammaTreatment gammaTreatment,
SkIPoint* outOffset) {
GrTexture* texture = this->originalTexture();
GrContext* context = texture->getContext();
@@ -373,7 +374,8 @@ const GrFragmentProcessor* GrTextureAdjuster::createFragmentProcessor(
const SkRect& origConstraintRect,
FilterConstraint filterConstraint,
bool coordsLimitedToConstraintRect,
- const GrTextureParams::FilterMode* filterOrNullForBicubic) {
+ const GrTextureParams::FilterMode* filterOrNullForBicubic,
+ SkSourceGammaTreatment gammaTreatment) {
SkMatrix textureMatrix = origTextureMatrix;
const SkIRect* contentArea = this->contentAreaOrNull();
@@ -392,7 +394,7 @@ const GrFragmentProcessor* GrTextureAdjuster::createFragmentProcessor(
if (filterOrNullForBicubic) {
params.setFilterMode(*filterOrNullForBicubic);
}
- SkAutoTUnref<GrTexture> texture(this->refTextureSafeForParams(params, nullptr));
+ SkAutoTUnref<GrTexture> texture(this->refTextureSafeForParams(params, gammaTreatment, nullptr));
if (!texture) {
return nullptr;
}
@@ -431,7 +433,8 @@ const GrFragmentProcessor* GrTextureAdjuster::createFragmentProcessor(
//////////////////////////////////////////////////////////////////////////////
-GrTexture* GrTextureMaker::refTextureForParams(const GrTextureParams& params) {
+GrTexture* GrTextureMaker::refTextureForParams(const GrTextureParams& params,
+ SkSourceGammaTreatment gammaTreatment) {
CopyParams copyParams;
bool willBeMipped = params.filterMode() == GrTextureParams::kMipMap_FilterMode;
@@ -441,7 +444,7 @@ GrTexture* GrTextureMaker::refTextureForParams(const GrTextureParams& params) {
if (!fContext->getGpu()->makeCopyForTextureParams(this->width(), this->height(), params,
&copyParams)) {
- return this->refOriginalTexture(willBeMipped);
+ return this->refOriginalTexture(willBeMipped, gammaTreatment);
}
GrUniqueKey copyKey;
this->makeCopyKey(copyParams, &copyKey);
@@ -452,7 +455,7 @@ GrTexture* GrTextureMaker::refTextureForParams(const GrTextureParams& params) {
}
}
- GrTexture* result = this->generateTextureForParams(copyParams, willBeMipped);
+ GrTexture* result = this->generateTextureForParams(copyParams, willBeMipped, gammaTreatment);
if (!result) {
return nullptr;
}
@@ -469,7 +472,8 @@ const GrFragmentProcessor* GrTextureMaker::createFragmentProcessor(
const SkRect& constraintRect,
FilterConstraint filterConstraint,
bool coordsLimitedToConstraintRect,
- const GrTextureParams::FilterMode* filterOrNullForBicubic) {
+ const GrTextureParams::FilterMode* filterOrNullForBicubic,
+ SkSourceGammaTreatment gammaTreatment) {
const GrTextureParams::FilterMode* fmForDetermineDomain = filterOrNullForBicubic;
if (filterOrNullForBicubic && GrTextureParams::kMipMap_FilterMode == *filterOrNullForBicubic &&
@@ -490,7 +494,7 @@ const GrFragmentProcessor* GrTextureMaker::createFragmentProcessor(
// Bicubic doesn't use filtering for it's texture accesses.
params.reset(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMode);
}
- SkAutoTUnref<GrTexture> texture(this->refTextureForParams(params));
+ SkAutoTUnref<GrTexture> texture(this->refTextureForParams(params, gammaTreatment));
if (!texture) {
return nullptr;
}
@@ -506,9 +510,9 @@ const GrFragmentProcessor* GrTextureMaker::createFragmentProcessor(
filterOrNullForBicubic);
}
-GrTexture* GrTextureMaker::generateTextureForParams(const CopyParams& copyParams,
- bool willBeMipped) {
- SkAutoTUnref<GrTexture> original(this->refOriginalTexture(willBeMipped));
+GrTexture* GrTextureMaker::generateTextureForParams(const CopyParams& copyParams, bool willBeMipped,
+ SkSourceGammaTreatment gammaTreatment) {
+ SkAutoTUnref<GrTexture> original(this->refOriginalTexture(willBeMipped, gammaTreatment));
if (!original) {
return nullptr;
}
diff --git a/src/gpu/GrTextureParamsAdjuster.h b/src/gpu/GrTextureParamsAdjuster.h
index c02f5b34f7..5f0f2715be 100644
--- a/src/gpu/GrTextureParamsAdjuster.h
+++ b/src/gpu/GrTextureParamsAdjuster.h
@@ -64,7 +64,8 @@ public:
const SkRect& constraintRect,
FilterConstraint filterConstraint,
bool coordsLimitedToConstraintRect,
- const GrTextureParams::FilterMode* filterOrNullForBicubic) = 0;
+ const GrTextureParams::FilterMode* filterOrNullForBicubic,
+ SkSourceGammaTreatment) = 0;
virtual ~GrTextureProducer() {}
@@ -127,14 +128,16 @@ public:
outOffset will be the top-left corner of the subset if a copy is not made. Otherwise,
the copy will be tight to the contents and outOffset will be (0, 0). If the copy's size
does not match subset's dimensions then the contents are scaled to fit the copy.*/
- GrTexture* refTextureSafeForParams(const GrTextureParams&, SkIPoint* outOffset);
+ GrTexture* refTextureSafeForParams(const GrTextureParams&, SkSourceGammaTreatment,
+ SkIPoint* outOffset);
const GrFragmentProcessor* createFragmentProcessor(
const SkMatrix& textureMatrix,
const SkRect& constraintRect,
FilterConstraint,
bool coordsLimitedToConstraintRect,
- const GrTextureParams::FilterMode* filterOrNullForBicubic) override;
+ const GrTextureParams::FilterMode* filterOrNullForBicubic,
+ SkSourceGammaTreatment) override;
protected:
/** The whole texture is content. */
@@ -167,14 +170,15 @@ public:
/** Returns a texture that is safe for use with the params. If the size of the returned texture
does not match width()/height() then the contents of the original must be scaled to fit
the texture. */
- GrTexture* refTextureForParams(const GrTextureParams&);
+ GrTexture* refTextureForParams(const GrTextureParams&, SkSourceGammaTreatment);
const GrFragmentProcessor* createFragmentProcessor(
const SkMatrix& textureMatrix,
const SkRect& constraintRect,
FilterConstraint filterConstraint,
bool coordsLimitedToConstraintRect,
- const GrTextureParams::FilterMode* filterOrNullForBicubic) override;
+ const GrTextureParams::FilterMode* filterOrNullForBicubic,
+ SkSourceGammaTreatment) override;
protected:
GrTextureMaker(GrContext* context, int width, int height, bool isAlphaOnly)
@@ -185,7 +189,7 @@ protected:
* Return the maker's "original" texture. It is the responsibility of the maker to handle any
* caching of the original if desired.
*/
- virtual GrTexture* refOriginalTexture(bool willBeMipped) = 0;
+ virtual GrTexture* refOriginalTexture(bool willBeMipped, SkSourceGammaTreatment) = 0;
/**
* Return a new (uncached) texture that is the stretch of the maker's original.
@@ -197,7 +201,8 @@ protected:
* Subclass may override this if they can handle creating the texture more directly than
* by copying.
*/
- virtual GrTexture* generateTextureForParams(const CopyParams&, bool willBeMipped);
+ virtual GrTexture* generateTextureForParams(const CopyParams&, bool willBeMipped,
+ SkSourceGammaTreatment);
GrContext* context() const { return fContext; }
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 406dedb0a7..81e955d702 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -80,21 +80,23 @@ public:
AutoBitmapTexture(GrContext* context,
const SkBitmap& bitmap,
const GrTextureParams& params,
+ SkSourceGammaTreatment gammaTreatment,
GrTexture** texture) {
SkASSERT(texture);
- *texture = this->set(context, bitmap, params);
+ *texture = this->set(context, bitmap, params, gammaTreatment);
}
GrTexture* set(GrContext* context,
const SkBitmap& bitmap,
- const GrTextureParams& params) {
+ const GrTextureParams& params,
+ SkSourceGammaTreatment gammaTreatment) {
// Either get the texture directly from the bitmap, or else use the cache and
// remember to unref it.
if (GrTexture* bmpTexture = bitmap.getTexture()) {
fTexture.reset(nullptr);
return bmpTexture;
} else {
- fTexture.reset(GrRefCachedBitmapTexture(context, bitmap, params));
+ fTexture.reset(GrRefCachedBitmapTexture(context, bitmap, params, gammaTreatment));
return fTexture.get();
}
}
@@ -260,7 +262,8 @@ void SkGpuDevice::drawSpriteWithFilter(const SkDraw& draw, const SkBitmap& bitma
GrTexture* texture;
// draw sprite neither filters nor tiles.
- AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), &texture);
+ AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(),
+ SkSourceGammaTreatment::kRespect, &texture);
if (!texture) {
return;
}
@@ -1165,7 +1168,9 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
bitmap.height() <= fContext->caps()->maxTileSize()));
GrTexture* texture;
- AutoBitmapTexture abt(fContext, bitmap, params, &texture);
+ SkSourceGammaTreatment gammaTreatment = this->surfaceProps().isGammaCorrect()
+ ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
+ AutoBitmapTexture abt(fContext, bitmap, params, gammaTreatment, &texture);
if (nullptr == texture) {
return;
}
@@ -1264,7 +1269,8 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
GrTexture* texture;
// draw sprite neither filters nor tiles.
- AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), &texture);
+ AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(),
+ SkSourceGammaTreatment::kRespect, &texture);
if (!texture) {
return;
}
@@ -1520,15 +1526,17 @@ void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* produc
}
static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_FilterMode;
+ bool gammaCorrect = this->surfaceProps().isGammaCorrect();
+ SkSourceGammaTreatment gammaTreatment = gammaCorrect
+ ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
SkAutoTUnref<const GrFragmentProcessor> fp(
producer->createFragmentProcessor(SkMatrix::I(),
SkRect::MakeIWH(producer->width(), producer->height()),
GrTextureProducer::kNo_FilterConstraint, true,
- &kMode));
+ &kMode, gammaTreatment));
GrPaint grPaint;
if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, fp,
- producer->isAlphaOnly(),
- this->surfaceProps().isGammaCorrect(), &grPaint)) {
+ producer->isAlphaOnly(), gammaCorrect, &grPaint)) {
return;
}
diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp
index 5eecf43e83..4ba3c8df9c 100644
--- a/src/gpu/SkGpuDevice_drawTexture.cpp
+++ b/src/gpu/SkGpuDevice_drawTexture.cpp
@@ -201,15 +201,19 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer,
}
textureMatrix = &tempMatrix;
}
+ bool gammaCorrect = this->surfaceProps().isGammaCorrect();
+ SkSourceGammaTreatment gammaTreatment = gammaCorrect
+ ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
SkAutoTUnref<const GrFragmentProcessor> fp(producer->createFragmentProcessor(
- *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect, filterMode));
+ *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect, filterMode,
+ gammaTreatment));
if (!fp) {
return;
}
GrPaint grPaint;
if (!SkPaintToGrPaintWithTexture(fContext, paint, viewMatrix, fp, producer->isAlphaOnly(),
- this->surfaceProps().isGammaCorrect(), &grPaint)) {
+ gammaCorrect, &grPaint)) {
return;
}
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 60736da572..fb2916daff 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -329,7 +329,8 @@ void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix
pixelRef->addGenIDChangeListener(new Invalidator(key));
}
-GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& bitmap)
+GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& bitmap,
+ SkSourceGammaTreatment gammaTreatment)
{
GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps());
if (kIndex_8_SkColorType != bitmap.colorType() && !bitmap.readyToDraw()) {
@@ -403,11 +404,13 @@ GrTexture* GrUploadMipMapToTexture(GrContext* ctx, const SkImageInfo& info,
}
GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap,
- const GrTextureParams& params) {
+ const GrTextureParams& params,
+ SkSourceGammaTreatment gammaTreatment) {
if (bitmap.getTexture()) {
- return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params, nullptr);
+ return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params, gammaTreatment,
+ nullptr);
}
- return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params);
+ return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params, gammaTreatment);
}
///////////////////////////////////////////////////////////////////////////////
@@ -519,8 +522,10 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
if (shaderProcessor) {
shaderFP = *shaderProcessor;
} else if (const SkShader* shader = skPaint.getShader()) {
+ SkSourceGammaTreatment gammaTreatment = allowSRGBInputs
+ ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
aufp.reset(shader->asFragmentProcessor(context, viewM, nullptr,
- skPaint.getFilterQuality()));
+ skPaint.getFilterQuality(), gammaTreatment));
shaderFP = aufp;
if (!shaderFP) {
return false;
@@ -689,10 +694,13 @@ bool SkPaintToGrPaintWithTexture(GrContext* context,
SkAutoTUnref<const GrFragmentProcessor> shaderFP;
if (textureIsAlphaOnly) {
if (const SkShader* shader = paint.getShader()) {
+ SkSourceGammaTreatment gammaTreatment = allowSRGBInputs
+ ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
shaderFP.reset(shader->asFragmentProcessor(context,
viewM,
nullptr,
- paint.getFilterQuality()));
+ paint.getFilterQuality(),
+ gammaTreatment));
if (!shaderFP) {
return false;
}
diff --git a/src/gpu/SkGrPriv.h b/src/gpu/SkGrPriv.h
index ac21669bd8..290c056a42 100644
--- a/src/gpu/SkGrPriv.h
+++ b/src/gpu/SkGrPriv.h
@@ -124,7 +124,7 @@ GrPixelConfig GrIsCompressedTextureDataSupported(GrContext* ctx, SkData* data,
*/
GrTexture* GrUploadBitmapToTexture(GrContext*, const SkBitmap&);
-GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext*, const SkBitmap&);
+GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext*, const SkBitmap&, SkSourceGammaTreatment);
/**
* Creates a new texture for the pixmap.