Home | History | Annotate | Download | only in gpu
      1 
      2 /*
      3  * Copyright 2013 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 #include "GrPaint.h"
     10 
     11 #include "GrProcOptInfo.h"
     12 #include "effects/GrCoverageSetOpXP.h"
     13 #include "effects/GrPorterDuffXferProcessor.h"
     14 #include "effects/GrSimpleTextureEffect.h"
     15 
     16 GrPaint::GrPaint()
     17     : fAntiAlias(false)
     18     , fDither(false)
     19     , fColor(GrColor_WHITE) {
     20 }
     21 
     22 void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
     23     fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
     24 }
     25 
     26 void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
     27     this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
     28 }
     29 
     30 void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
     31     this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
     32 }
     33 
     34 void GrPaint::addColorTextureProcessor(GrTexture* texture,
     35                                        const SkMatrix& matrix,
     36                                        const GrTextureParams& params) {
     37     this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
     38 }
     39 
     40 void GrPaint::addCoverageTextureProcessor(GrTexture* texture,
     41                                           const SkMatrix& matrix,
     42                                           const GrTextureParams& params) {
     43     this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
     44 }
     45 
     46 bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const {
     47     GrProcOptInfo coverageProcInfo;
     48     coverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->numCoverageStages(),
     49                                            0xFFFFFFFF, kRGBA_GrColorComponentFlags, true);
     50     GrProcOptInfo colorProcInfo;
     51     colorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), fColor,
     52                                         kRGBA_GrColorComponentFlags, false);
     53 
     54     GrXPFactory::InvariantOutput output;
     55     fXPFactory->getInvariantOutput(colorProcInfo, coverageProcInfo, &output);
     56 
     57     if (kRGBA_GrColorComponentFlags == output.fBlendedColorFlags &&
     58         0xFF == GrColorUnpackA(output.fBlendedColor)) {
     59         *color = output.fBlendedColor;
     60         return true;
     61     }
     62     return false;
     63 }
     64