diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-05 19:04:13 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-05 19:04:13 +0000 |
commit | c7448cef098b835d6f9adf8a365fde9de076f178 (patch) | |
tree | 4d54ef27608b39bc67b15ef580e0aaa6c9bf9c66 /src/gpu | |
parent | ffca6ce0e20665624b764ca6977b5acfda30931f (diff) |
GrPaint encapsulation.
R=robertphillips@google.com
Review URL: https://codereview.appspot.com/6624052
git-svn-id: http://skia.googlecode.com/svn/trunk@5838 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrContext.cpp | 10 | ||||
-rw-r--r-- | src/gpu/GrDrawState.cpp | 16 | ||||
-rw-r--r-- | src/gpu/GrTextContext.cpp | 11 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 47 | ||||
-rw-r--r-- | src/gpu/effects/GrConfigConversionEffect.cpp | 1 |
5 files changed, 33 insertions, 52 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index d6e0b508eb..3e53c19ff8 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -613,13 +613,13 @@ void GrContext::drawPaint(const GrPaint& paint) { am.set(this, GrMatrix::I()); } // by definition this fills the entire clip, no need for AA - if (paint.fAntiAlias) { + if (paint.isAntiAlias()) { if (!tmpPaint.isValid()) { tmpPaint.set(paint); p = tmpPaint.get(); } GrAssert(p == tmpPaint.get()); - tmpPaint.get()->fAntiAlias = false; + tmpPaint.get()->setAntiAlias(false); } this->drawRect(*p, r); } @@ -736,7 +736,7 @@ void GrContext::drawRect(const GrPaint& paint, GrRect devRect = rect; GrMatrix combinedMatrix; bool useVertexCoverage; - bool needAA = paint.fAntiAlias && + bool needAA = paint.isAntiAlias() && !this->getRenderTarget()->isMultisampled(); bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix, &combinedMatrix, &devRect, @@ -1013,7 +1013,7 @@ void GrContext::drawOval(const GrPaint& paint, SkScalar strokeWidth) { GrAssert(strokeWidth <= 0); if (!isSimilarityTransformation(this->getMatrix()) || - !paint.fAntiAlias || + !paint.isAntiAlias() || rect.height() != rect.width()) { SkPath path; path.addOval(rect); @@ -1125,7 +1125,7 @@ void GrContext::internalDrawPath(const GrPaint& paint, const SkPath& path, GrDrawTarget* target = this->prepareToDraw(&paint, DEFAULT_BUFFERING); GrDrawState::AutoStageDisable atr(fDrawState); - bool prAA = paint.fAntiAlias && !this->getRenderTarget()->isMultisampled(); + bool prAA = paint.isAntiAlias() && !this->getRenderTarget()->isMultisampled(); // An Assumption here is that path renderer would use some form of tweaking // the src color (either the input alpha or in the frag shader) to implement diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp index bd6e2685bb..f798cda59c 100644 --- a/src/gpu/GrDrawState.cpp +++ b/src/gpu/GrDrawState.cpp @@ -31,18 +31,18 @@ void GrDrawState::setFromPaint(const GrPaint& paint) { this->disableStage(s); } - this->setColor(paint.fColor); + this->setColor(paint.getColor()); - this->setState(GrDrawState::kDither_StateBit, paint.fDither); - this->setState(GrDrawState::kHWAntialias_StateBit, paint.fAntiAlias); + this->setState(GrDrawState::kDither_StateBit, paint.isDither()); + this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); - if (paint.fColorMatrixEnabled) { + if (paint.isColorMatrixEnabled()) { this->enableState(GrDrawState::kColorMatrix_StateBit); - this->setColorMatrix(paint.fColorMatrix); + this->setColorMatrix(paint.getColorMatrix()); } else { this->disableState(GrDrawState::kColorMatrix_StateBit); } - this->setBlendFunc(paint.fSrcBlendCoeff, paint.fDstBlendCoeff); - this->setColorFilter(paint.fColorFilterColor, paint.fColorFilterXfermode); - this->setCoverage(paint.fCoverage); + this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); + this->setColorFilter(paint.getColorFilterColor(), paint.getColorFilterMode()); + this->setCoverage(paint.getCoverage()); } diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp index 5c8b9e50d3..c245401d9a 100644 --- a/src/gpu/GrTextContext.cpp +++ b/src/gpu/GrTextContext.cpp @@ -38,22 +38,21 @@ void GrTextContext::flushGlyphs() { drawState->createTextureEffect(kGlyphMaskStage, fCurrTexture, params); if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { - if (kOne_GrBlendCoeff != fPaint.fSrcBlendCoeff || - kISA_GrBlendCoeff != fPaint.fDstBlendCoeff || + if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || + kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || fPaint.hasColorStage()) { GrPrintf("LCD Text will not draw correctly.\n"); } // setup blend so that we get mask * paintColor + (1-mask)*dstColor - drawState->setBlendConstant(fPaint.fColor); + drawState->setBlendConstant(fPaint.getColor()); drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); // don't modulate by the paint's color in the frag since we're // already doing it via the blend const. drawState->setColor(0xffffffff); } else { // set back to normal in case we took LCD path previously. - drawState->setBlendFunc(fPaint.fSrcBlendCoeff, - fPaint.fDstBlendCoeff); - drawState->setColor(fPaint.fColor); + drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlendCoeff()); + drawState->setColor(fPaint.getColor()); } int nGlyphs = fCurrVertex / 4; diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index a792977ff8..b0b5ed0453 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -510,9 +510,8 @@ inline bool skPaint2GrPaintNoShader(SkGpuDevice* dev, SkGpuDevice::SkAutoCachedTexture* act, GrPaint* grPaint) { - grPaint->fDither = skPaint.isDither(); - grPaint->fAntiAlias = skPaint.isAntiAlias(); - grPaint->fCoverage = 0xFF; + grPaint->setDither(skPaint.isDither()); + grPaint->setAntiAlias(skPaint.isAntiAlias()); SkXfermode::Coeff sm = SkXfermode::kOne_Coeff; SkXfermode::Coeff dm = SkXfermode::kISA_Coeff; @@ -526,17 +525,16 @@ inline bool skPaint2GrPaintNoShader(SkGpuDevice* dev, #endif } } - grPaint->fSrcBlendCoeff = sk_blend_to_grblend(sm); - grPaint->fDstBlendCoeff = sk_blend_to_grblend(dm); + grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); if (justAlpha) { uint8_t alpha = skPaint.getAlpha(); - grPaint->fColor = GrColorPackRGBA(alpha, alpha, alpha, alpha); + grPaint->setColor(GrColorPackRGBA(alpha, alpha, alpha, alpha)); // justAlpha is currently set to true only if there is a texture, // so constantColor should not also be true. GrAssert(!constantColor); } else { - grPaint->fColor = SkColor2GrColor(skPaint.getColor()); + grPaint->setColor(SkColor2GrColor(skPaint.getColor())); GrAssert(!grPaint->isColorStageEnabled(kShaderTextureIdx)); } SkColorFilter* colorFilter = skPaint.getColorFilter(); @@ -544,24 +542,17 @@ inline bool skPaint2GrPaintNoShader(SkGpuDevice* dev, SkXfermode::Mode filterMode; SkScalar matrix[20]; SkBitmap colorTransformTable; - grPaint->resetColorFilter(); // TODO: SkColorFilter::asCustomStage() if (colorFilter != NULL && colorFilter->asColorMode(&color, &filterMode)) { - grPaint->fColorMatrixEnabled = false; if (!constantColor) { - grPaint->fColorFilterColor = SkColor2GrColor(color); - grPaint->fColorFilterXfermode = filterMode; + grPaint->setXfermodeColorFilter(filterMode, SkColor2GrColor(color)); } else { SkColor filtered = colorFilter->filterColor(skPaint.getColor()); - grPaint->fColor = SkColor2GrColor(filtered); + grPaint->setColor(SkColor2GrColor(filtered)); } } else if (colorFilter != NULL && colorFilter->asColorMatrix(matrix)) { - grPaint->fColorMatrixEnabled = true; - memcpy(grPaint->fColorMatrix, matrix, sizeof(matrix)); - grPaint->fColorFilterXfermode = SkXfermode::kDst_Mode; + grPaint->setColorMatrix(matrix); } else if (colorFilter != NULL && colorFilter->asComponentTable(&colorTransformTable)) { - grPaint->resetColorFilter(); - // pass NULL because the color table effect doesn't use tiling or filtering. GrTexture* texture = act->set(dev, colorTransformTable, NULL); GrSamplerState* colorSampler = grPaint->colorSampler(kColorFilterTextureIdx); @@ -895,18 +886,16 @@ bool drawWithGPUMaskFilter(GrContext* context, const SkPath& path, context->clear(NULL, 0); GrPaint tempPaint; - tempPaint.reset(); - tempPaint.fAntiAlias = grp->fAntiAlias; - if (tempPaint.fAntiAlias) { + if (grp->isAntiAlias()) { + tempPaint.setAntiAlias(true); // AA uses the "coverage" stages on GrDrawTarget. Coverage with a dst // blend coeff of zero requires dual source blending support in order // to properly blend partially covered pixels. This means the AA // code path may not be taken. So we use a dst blend coeff of ISA. We // could special case AA draws to a dst surface with known alpha=0 to // use a zero dst coeff when dual source blending isn't available. - tempPaint.fSrcBlendCoeff = kOne_GrBlendCoeff; - tempPaint.fDstBlendCoeff = kISC_GrBlendCoeff; + tempPaint.setBlendFunc(kOne_GrBlendCoeff, kISC_GrBlendCoeff); } // Draw hard shadow to pathTexture with path topleft at origin 0,0. context->drawPath(tempPaint, path, pathFillType, &offset); @@ -928,18 +917,15 @@ bool drawWithGPUMaskFilter(GrContext* context, const SkPath& path, (GrSingleTextureEffect, (pathTexture)))->unref(); if (SkMaskFilter::kInner_BlurType == blurType) { // inner: dst = dst * src - paint.fSrcBlendCoeff = kDC_GrBlendCoeff; - paint.fDstBlendCoeff = kZero_GrBlendCoeff; + paint.setBlendFunc(kDC_GrBlendCoeff, kZero_GrBlendCoeff); } else if (SkMaskFilter::kSolid_BlurType == blurType) { // solid: dst = src + dst - src * dst // = (1 - dst) * src + 1 * dst - paint.fSrcBlendCoeff = kIDC_GrBlendCoeff; - paint.fDstBlendCoeff = kOne_GrBlendCoeff; + paint.setBlendFunc(kIDC_GrBlendCoeff, kOne_GrBlendCoeff); } else if (SkMaskFilter::kOuter_BlurType == blurType) { // outer: dst = dst * (1 - src) // = 0 * src + (1 - src) * dst - paint.fSrcBlendCoeff = kZero_GrBlendCoeff; - paint.fDstBlendCoeff = kISC_GrBlendCoeff; + paint.setBlendFunc(kZero_GrBlendCoeff, kISC_GrBlendCoeff); } context->drawRect(paint, srcRect); } @@ -1059,8 +1045,7 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, SkScalar hairlineCoverage; if (SkDrawTreatAsHairline(paint, *draw.fMatrix, &hairlineCoverage)) { doFill = false; - grPaint.fCoverage = SkScalarRoundToInt(hairlineCoverage * - grPaint.fCoverage); + grPaint.setCoverage(SkScalarRoundToInt(hairlineCoverage * grPaint.getCoverage())); } // If we have a prematrix, apply it to the path, optimizing for the case @@ -1520,7 +1505,6 @@ void apply_custom_stage(GrContext* context, GrMatrix sampleM; sampleM.setIDiv(srcTexture->width(), srcTexture->height()); GrPaint paint; - paint.reset(); paint.colorSampler(0)->reset(sampleM); paint.colorSampler(0)->setCustomStage(stage); context->drawRect(paint, rect); @@ -1707,7 +1691,6 @@ bool SkGpuDevice::filterImage(SkImageFilter* filter, const SkBitmap& src, } GrPaint paint; - paint.reset(); GrTexture* texture; // We assume here that the filter will not attempt to tile the src. Otherwise, this cache lookup diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp index 3af0979be9..b9c9f63ae3 100644 --- a/src/gpu/effects/GrConfigConversionEffect.cpp +++ b/src/gpu/effects/GrConfigConversionEffect.cpp @@ -176,7 +176,6 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context // We then verify that two reads produced the same values. GrPaint paint; - paint.reset(); SkAutoTUnref<GrCustomStage> pmToUPMStage1(SkNEW_ARGS(GrConfigConversionEffect, (dataTex, false, *pmToUPMRule))); |