gfx/skia/trunk/src/gpu/GrPaint.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/GrPaint.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,123 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2013 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +#include "GrPaint.h"
    1.13 +
    1.14 +#include "GrBlend.h"
    1.15 +#include "effects/GrSimpleTextureEffect.h"
    1.16 +
    1.17 +void GrPaint::addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) {
    1.18 +    GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix);
    1.19 +    this->addColorEffect(effect)->unref();
    1.20 +}
    1.21 +
    1.22 +void GrPaint::addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matrix) {
    1.23 +    GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix);
    1.24 +    this->addCoverageEffect(effect)->unref();
    1.25 +}
    1.26 +
    1.27 +void GrPaint::addColorTextureEffect(GrTexture* texture,
    1.28 +                                    const SkMatrix& matrix,
    1.29 +                                    const GrTextureParams& params) {
    1.30 +    GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params);
    1.31 +    this->addColorEffect(effect)->unref();
    1.32 +}
    1.33 +
    1.34 +void GrPaint::addCoverageTextureEffect(GrTexture* texture,
    1.35 +                                       const SkMatrix& matrix,
    1.36 +                                       const GrTextureParams& params) {
    1.37 +    GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params);
    1.38 +    this->addCoverageEffect(effect)->unref();
    1.39 +}
    1.40 +
    1.41 +bool GrPaint::isOpaque() const {
    1.42 +    return this->getOpaqueAndKnownColor(NULL, NULL);
    1.43 +}
    1.44 +
    1.45 +bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const {
    1.46 +    GrColor tempColor;
    1.47 +    uint32_t colorComps;
    1.48 +    if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) {
    1.49 +        if (kRGBA_GrColorComponentFlags == colorComps) {
    1.50 +            *color = tempColor;
    1.51 +            return true;
    1.52 +        }
    1.53 +    }
    1.54 +    return false;
    1.55 +}
    1.56 +
    1.57 +bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor,
    1.58 +                                     uint32_t* solidColorKnownComponents) const {
    1.59 +
    1.60 +    // TODO: Share this implementation with GrDrawState
    1.61 +
    1.62 +    GrColor coverage = GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage);
    1.63 +    uint32_t coverageComps = kRGBA_GrColorComponentFlags;
    1.64 +    int count = fCoverageStages.count();
    1.65 +    for (int i = 0; i < count; ++i) {
    1.66 +        (*fCoverageStages[i].getEffect())->getConstantColorComponents(&coverage, &coverageComps);
    1.67 +    }
    1.68 +    if (kRGBA_GrColorComponentFlags != coverageComps || 0xffffffff != coverage) {
    1.69 +        return false;
    1.70 +    }
    1.71 +
    1.72 +    GrColor color = fColor;
    1.73 +    uint32_t colorComps = kRGBA_GrColorComponentFlags;
    1.74 +    count = fColorStages.count();
    1.75 +    for (int i = 0; i < count; ++i) {
    1.76 +        (*fColorStages[i].getEffect())->getConstantColorComponents(&color, &colorComps);
    1.77 +    }
    1.78 +
    1.79 +    SkASSERT((NULL == solidColor) == (NULL == solidColorKnownComponents));
    1.80 +
    1.81 +    GrBlendCoeff srcCoeff = fSrcBlendCoeff;
    1.82 +    GrBlendCoeff dstCoeff = fDstBlendCoeff;
    1.83 +    GrSimplifyBlend(&srcCoeff, &dstCoeff, color, colorComps, 0, 0, 0);
    1.84 +
    1.85 +    bool opaque = kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoeff);
    1.86 +    if (NULL != solidColor) {
    1.87 +        if (opaque) {
    1.88 +            switch (srcCoeff) {
    1.89 +                case kZero_GrBlendCoeff:
    1.90 +                    *solidColor = 0;
    1.91 +                    *solidColorKnownComponents = kRGBA_GrColorComponentFlags;
    1.92 +                    break;
    1.93 +
    1.94 +                case kOne_GrBlendCoeff:
    1.95 +                    *solidColor = color;
    1.96 +                    *solidColorKnownComponents = colorComps;
    1.97 +                    break;
    1.98 +
    1.99 +                // The src coeff should never refer to the src and if it refers to dst then opaque
   1.100 +                // should have been false.
   1.101 +                case kSC_GrBlendCoeff:
   1.102 +                case kISC_GrBlendCoeff:
   1.103 +                case kDC_GrBlendCoeff:
   1.104 +                case kIDC_GrBlendCoeff:
   1.105 +                case kSA_GrBlendCoeff:
   1.106 +                case kISA_GrBlendCoeff:
   1.107 +                case kDA_GrBlendCoeff:
   1.108 +                case kIDA_GrBlendCoeff:
   1.109 +                default:
   1.110 +                    GrCrash("srcCoeff should not refer to src or dst.");
   1.111 +                    break;
   1.112 +
   1.113 +                // TODO: update this once GrPaint actually has a const color.
   1.114 +                case kConstC_GrBlendCoeff:
   1.115 +                case kIConstC_GrBlendCoeff:
   1.116 +                case kConstA_GrBlendCoeff:
   1.117 +                case kIConstA_GrBlendCoeff:
   1.118 +                    *solidColorKnownComponents = 0;
   1.119 +                    break;
   1.120 +            }
   1.121 +        } else {
   1.122 +            solidColorKnownComponents = 0;
   1.123 +        }
   1.124 +    }
   1.125 +    return opaque;
   1.126 +}

mercurial