GrPaint.cpp revision 9513143efa734bef0c1a0c7f945022572dbc8518
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/GrPorterDuffXferProcessor.h" 13#include "effects/GrSimpleTextureEffect.h" 14 15void GrPaint::addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { 16 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); 17} 18 19void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { 20 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); 21} 22 23void GrPaint::addColorTextureProcessor(GrTexture* texture, 24 const SkMatrix& matrix, 25 const GrTextureParams& params) { 26 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); 27} 28 29void GrPaint::addCoverageTextureProcessor(GrTexture* texture, 30 const SkMatrix& matrix, 31 const GrTextureParams& params) { 32 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); 33} 34 35bool GrPaint::isOpaque() const { 36 return this->getOpaqueAndKnownColor(NULL, NULL); 37} 38 39bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const { 40 GrColor tempColor = 0; 41 uint32_t colorComps = 0; 42 if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) { 43 if (kRGBA_GrColorComponentFlags == colorComps) { 44 *color = tempColor; 45 return true; 46 } 47 } 48 return false; 49} 50 51void GrPaint::resetStages() { 52 fColorStages.reset(); 53 fCoverageStages.reset(); 54 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); 55} 56 57bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor, 58 uint32_t* solidColorKnownComponents) const { 59 60 GrProcOptInfo coverageProcInfo; 61 coverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->numCoverageStages(), 62 0xFFFFFFFF, kRGBA_GrColorComponentFlags, true); 63 GrProcOptInfo colorProcInfo; 64 colorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), fColor, 65 kRGBA_GrColorComponentFlags, false); 66 67 return fXPFactory->getOpaqueAndKnownColor(colorProcInfo, coverageProcInfo, solidColor, 68 solidColorKnownComponents); 69} 70 71