blob: d9182d2704c508d7eb35b90f6a426d6342b0e37c [file] [log] [blame]
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrPaint.h"
#include "GrXferProcessor.h"
#include "effects/GrCoverageSetOpXP.h"
#include "effects/GrPorterDuffXferProcessor.h"
#include "effects/GrSimpleTextureEffect.h"
void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) {
this->setXPFactory(GrPorterDuffXPFactory::Get(mode));
}
void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage));
}
void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy,
sk_sp<GrColorSpaceXform> colorSpaceXform,
const SkMatrix& matrix) {
this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy),
std::move(colorSpaceXform),
matrix));
}
void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy,
sk_sp<GrColorSpaceXform> colorSpaceXform,
const SkMatrix& matrix,
const GrSamplerParams& params) {
this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy),
std::move(colorSpaceXform),
matrix, params));
}
void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy,
const SkMatrix& matrix) {
this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy),
nullptr, matrix));
}
void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy,
const SkMatrix& matrix,
const GrSamplerParams& params) {
this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy),
nullptr, matrix, params));
}
bool GrPaint::isConstantBlendedColor(GrColor* constantColor) const {
// This used to do a more sophisticated analysis but now it just explicitly looks for common
// cases.
static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc);
static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear);
if (kClear == fXPFactory) {
*constantColor = GrColor_TRANSPARENT_BLACK;
return true;
}
if (this->numColorFragmentProcessors()) {
return false;
}
if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) {
*constantColor = fColor.toGrColor();
return true;
}
return false;
}