From b2d77e4d7458145ef4825c28323d9fbbb6b003ac Mon Sep 17 00:00:00 2001 From: reed Date: Tue, 14 Oct 2014 08:26:33 -0700 Subject: [PATCH] add gamma value to deviceproperties BUG=skia: Review URL: https://codereview.chromium.org/652273002 --- src/core/SkDevice.cpp | 2 +- src/core/SkDeviceProperties.h | 24 +++++++++++++++++++----- src/core/SkPaint.cpp | 6 +++--- src/gpu/GrDistanceFieldTextContext.cpp | 8 ++++---- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 935d489892..0623f9909e 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -58,7 +58,7 @@ const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) { } void SkBaseDevice::setPixelGeometry(SkPixelGeometry geo) { - fLeakyProperties->fPixelGeometry = geo; + fLeakyProperties->setPixelGeometry(geo); } SkSurface* SkBaseDevice::newSurface(const SkImageInfo&, const SkSurfaceProps&) { return NULL; } diff --git a/src/core/SkDeviceProperties.h b/src/core/SkDeviceProperties.h index 11ecd65157..e79f21a235 100644 --- a/src/core/SkDeviceProperties.h +++ b/src/core/SkDeviceProperties.h @@ -14,13 +14,27 @@ struct SkDeviceProperties { enum InitType { kLegacyLCD_InitType }; - SkDeviceProperties(InitType) : fPixelGeometry(SkSurfacePropsDefaultPixelGeometry()) {} - SkDeviceProperties(SkPixelGeometry geo) : fPixelGeometry(geo) {} + SkDeviceProperties(InitType, float gamma = SK_GAMMA_EXPONENT) + : fGamma(gamma) + , fPixelGeometry(SkSurfacePropsDefaultPixelGeometry()) + {} + + SkDeviceProperties(SkPixelGeometry geo, float gamma = SK_GAMMA_EXPONENT) + : fGamma(gamma) + , fPixelGeometry(geo) + {} + + SkPixelGeometry pixelGeometry() const { return fPixelGeometry; } + float gamma() const { return fGamma; } + + void setPixelGeometry(SkPixelGeometry geo) { + fPixelGeometry = geo; + } + +private: + const float fGamma; SkPixelGeometry fPixelGeometry; - - // read-only attribute -- until we actually store a value (future CL) - float getGamma() const { return SK_GAMMA_EXPONENT; } }; #endif diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index a25ec1d333..2181a2574d 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -1469,7 +1469,7 @@ void SkScalerContext::MakeRec(const SkPaint& paint, flags |= SkScalerContext::kGenA8FromLCD_Flag; } else { SkPixelGeometry geometry = deviceProperties - ? deviceProperties->fPixelGeometry + ? deviceProperties->pixelGeometry() : SkSurfacePropsDefaultPixelGeometry(); switch (geometry) { case kUnknown_SkPixelGeometry: @@ -1520,13 +1520,13 @@ void SkScalerContext::MakeRec(const SkPaint& paint, rec->setDeviceGamma(SK_GAMMA_EXPONENT); rec->setPaintGamma(SK_GAMMA_EXPONENT); } else { - rec->setDeviceGamma(deviceProperties->getGamma()); + rec->setDeviceGamma(deviceProperties->gamma()); //For now always set the paint gamma equal to the device gamma. //The math in SkMaskGamma can handle them being different, //but it requires superluminous masks when //Ex : deviceGamma(x) < paintGamma(x) and x is sufficiently large. - rec->setPaintGamma(deviceProperties->getGamma()); + rec->setPaintGamma(deviceProperties->gamma()); } #ifdef SK_GAMMA_CONTRAST diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp index 183b83c3e6..04ad59b2c6 100755 --- a/src/gpu/GrDistanceFieldTextContext.cpp +++ b/src/gpu/GrDistanceFieldTextContext.cpp @@ -169,8 +169,8 @@ static void setup_gamma_texture(GrContext* context, const SkGlyphCache* cache, #else SkScalar contrast = 0.5f; #endif - SkScalar paintGamma = deviceProperties.getGamma(); - SkScalar deviceGamma = deviceProperties.getGamma(); + SkScalar paintGamma = deviceProperties.gamma(); + SkScalar deviceGamma = deviceProperties.gamma(); size = SkScalerContext::GetGammaLUTSize(contrast, paintGamma, deviceGamma, &width, &height); @@ -358,7 +358,7 @@ void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; flags |= fUseLCDText && ctm.rectStaysRect() ? kRectToRect_DistanceFieldEffectFlag : 0; - bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.fPixelGeometry); + bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry()); flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; // see if we need to create a new effect @@ -375,7 +375,7 @@ void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo flags)); } else { #ifdef SK_GAMMA_APPLY_TO_A8 - U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDeviceProperties.getGamma(), + U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDeviceProperties.gamma(), filteredColor); fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(fCurrTexture, params,